Skip to content

Commit 897217e

Browse files
committed
ak: fixup session configuration
1 parent bfce000 commit 897217e

File tree

1 file changed

+7
-72
lines changed
  • tss-esapi/src/abstraction

1 file changed

+7
-72
lines changed

tss-esapi/src/abstraction/ak.rs

Lines changed: 7 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -14,47 +14,14 @@ use crate::{
1414
session_handles::PolicySession,
1515
},
1616
structures::{
17-
Auth, CreateKeyResult, DigestList, EccPoint, EccScheme, KeyDerivationFunctionScheme,
18-
Private, Public, PublicBuilder, PublicEccParametersBuilder, PublicKeyRsa,
19-
PublicRsaParametersBuilder, RsaExponent, RsaScheme, SymmetricDefinitionObject,
17+
Auth, CreateKeyResult, EccPoint, EccScheme, KeyDerivationFunctionScheme, Private, Public,
18+
PublicBuilder, PublicEccParametersBuilder, PublicKeyRsa, PublicRsaParametersBuilder,
19+
RsaExponent, RsaScheme, SymmetricDefinitionObject,
2020
},
2121
Context, Error, Result, WrapperErrorKind,
2222
};
2323
use std::convert::TryFrom;
2424

25-
// Source: TCG EK Credential Profile for TPM Family 2.0; Level 0 Version 2.5 Revision 2
26-
// Section B.6
27-
const POLICY_A_SHA384: [u8; 48] = [
28-
0x8b, 0xbf, 0x22, 0x66, 0x53, 0x7c, 0x17, 0x1c, 0xb5, 0x6e, 0x40, 0x3c, 0x4d, 0xc1, 0xd4, 0xb6,
29-
0x4f, 0x43, 0x26, 0x11, 0xdc, 0x38, 0x6e, 0x6f, 0x53, 0x20, 0x50, 0xc3, 0x27, 0x8c, 0x93, 0x0e,
30-
0x14, 0x3e, 0x8b, 0xb1, 0x13, 0x38, 0x24, 0xcc, 0xb4, 0x31, 0x05, 0x38, 0x71, 0xc6, 0xdb, 0x53,
31-
];
32-
const POLICY_A_SHA512: [u8; 64] = [
33-
0x1e, 0x3b, 0x76, 0x50, 0x2c, 0x8a, 0x14, 0x25, 0xaa, 0x0b, 0x7b, 0x3f, 0xc6, 0x46, 0xa1, 0xb0,
34-
0xfa, 0xe0, 0x63, 0xb0, 0x3b, 0x53, 0x68, 0xf9, 0xc4, 0xcd, 0xde, 0xca, 0xff, 0x08, 0x91, 0xdd,
35-
0x68, 0x2b, 0xac, 0x1a, 0x85, 0xd4, 0xd8, 0x32, 0xb7, 0x81, 0xea, 0x45, 0x19, 0x15, 0xde, 0x5f,
36-
0xc5, 0xbf, 0x0d, 0xc4, 0xa1, 0x91, 0x7c, 0xd4, 0x2f, 0xa0, 0x41, 0xe3, 0xf9, 0x98, 0xe0, 0xee,
37-
];
38-
const POLICY_A_SM3_256: [u8; 32] = [
39-
0xc6, 0x7f, 0x7d, 0x35, 0xf6, 0x6f, 0x3b, 0xec, 0x13, 0xc8, 0x9f, 0xe8, 0x98, 0x92, 0x1c, 0x65,
40-
0x1b, 0x0c, 0xb5, 0xa3, 0x8a, 0x92, 0x69, 0x0a, 0x62, 0xa4, 0x3c, 0x00, 0x12, 0xe4, 0xfb, 0x8b,
41-
];
42-
const POLICY_C_SHA384: [u8; 48] = [
43-
0xd6, 0x03, 0x2c, 0xe6, 0x1f, 0x2f, 0xb3, 0xc2, 0x40, 0xeb, 0x3c, 0xf6, 0xa3, 0x32, 0x37, 0xef,
44-
0x2b, 0x6a, 0x16, 0xf4, 0x29, 0x3c, 0x22, 0xb4, 0x55, 0xe2, 0x61, 0xcf, 0xfd, 0x21, 0x7a, 0xd5,
45-
0xb4, 0x94, 0x7c, 0x2d, 0x73, 0xe6, 0x30, 0x05, 0xee, 0xd2, 0xdc, 0x2b, 0x35, 0x93, 0xd1, 0x65,
46-
];
47-
const POLICY_C_SHA512: [u8; 64] = [
48-
0x58, 0x9e, 0xe1, 0xe1, 0x46, 0x54, 0x47, 0x16, 0xe8, 0xde, 0xaf, 0xe6, 0xdb, 0x24, 0x7b, 0x01,
49-
0xb8, 0x1e, 0x9f, 0x9c, 0x7d, 0xd1, 0x6b, 0x81, 0x4a, 0xa1, 0x59, 0x13, 0x87, 0x49, 0x10, 0x5f,
50-
0xba, 0x53, 0x88, 0xdd, 0x1d, 0xea, 0x70, 0x2f, 0x35, 0x24, 0x0c, 0x18, 0x49, 0x33, 0x12, 0x1e,
51-
0x2c, 0x61, 0xb8, 0xf5, 0x0d, 0x3e, 0xf9, 0x13, 0x93, 0xa4, 0x9a, 0x38, 0xc3, 0xf7, 0x3f, 0xc8,
52-
];
53-
const POLICY_C_SM3_256: [u8; 32] = [
54-
0x2d, 0x4e, 0x81, 0x57, 0x8c, 0x35, 0x31, 0xd9, 0xbd, 0x1c, 0xdd, 0x7d, 0x02, 0xba, 0x29, 0x8d,
55-
0x56, 0x99, 0xa3, 0xe3, 0x9f, 0xc3, 0x55, 0x1b, 0xfe, 0xff, 0xcf, 0x13, 0x2b, 0x49, 0xe1, 0x1d,
56-
];
57-
5825
fn create_ak_public<IKC: IntoKeyCustomization>(
5926
key_alg: AsymmetricAlgorithmSelection,
6027
hash_alg: HashingAlgorithm,
@@ -134,29 +101,11 @@ fn create_ak_public<IKC: IntoKeyCustomization>(
134101
fn session_config(
135102
context: &mut Context,
136103
parent: KeyHandle,
137-
) -> Result<(HashingAlgorithm, SymmetricDefinitionObject, DigestList)> {
104+
) -> Result<(HashingAlgorithm, SymmetricDefinitionObject)> {
138105
let parent_hash_alg = context.read_public(parent)?.0.name_hashing_algorithm();
139106
let parent_symmetric = context.read_public(parent)?.0.symmetric_algorithm()?;
140107

141-
let mut policy_digests = DigestList::new();
142-
143-
match parent_hash_alg {
144-
HashingAlgorithm::Sha384 => {
145-
policy_digests.add(POLICY_A_SHA384.into())?;
146-
policy_digests.add(POLICY_C_SHA384.into())?
147-
}
148-
HashingAlgorithm::Sha512 => {
149-
policy_digests.add(POLICY_A_SHA512.into())?;
150-
policy_digests.add(POLICY_C_SHA512.into())?
151-
}
152-
HashingAlgorithm::Sm3_256 => {
153-
policy_digests.add(POLICY_A_SM3_256.into())?;
154-
policy_digests.add(POLICY_C_SM3_256.into())?
155-
}
156-
_ => (),
157-
};
158-
159-
Ok((parent_hash_alg, parent_symmetric, policy_digests))
108+
Ok((parent_hash_alg, parent_symmetric))
160109
}
161110

162111
/// This loads an Attestation Key previously generated under the Endorsement hierarchy
@@ -167,7 +116,7 @@ pub fn load_ak(
167116
private: Private,
168117
public: Public,
169118
) -> Result<KeyHandle> {
170-
let (parent_hash_alg, parent_symmetric, policy_digests) = session_config(context, parent)?;
119+
let (parent_hash_alg, parent_symmetric) = session_config(context, parent)?;
171120

172121
let policy_auth_session = context
173122
.start_auth_session(
@@ -209,13 +158,6 @@ pub fn load_ak(
209158
)
210159
})?;
211160

212-
if !policy_digests.is_empty() {
213-
ctx.policy_or(
214-
PolicySession::try_from(policy_auth_session)?,
215-
policy_digests,
216-
)?
217-
}
218-
219161
ctx.execute_with_session(Some(policy_auth_session), |ctx| {
220162
ctx.load(parent, private, public)
221163
})
@@ -240,7 +182,7 @@ pub fn create_ak<IKC: IntoKeyCustomization>(
240182
key_customization: IKC,
241183
) -> Result<CreateKeyResult> {
242184
let ak_pub = create_ak_public(key_alg, hash_alg, sign_alg, key_customization)?;
243-
let (parent_hash_alg, parent_symmetric, policy_digests) = session_config(context, parent)?;
185+
let (parent_hash_alg, parent_symmetric) = session_config(context, parent)?;
244186

245187
let policy_auth_session = context
246188
.start_auth_session(
@@ -282,13 +224,6 @@ pub fn create_ak<IKC: IntoKeyCustomization>(
282224
)
283225
})?;
284226

285-
if !policy_digests.is_empty() {
286-
ctx.policy_or(
287-
PolicySession::try_from(policy_auth_session)?,
288-
policy_digests,
289-
)?
290-
};
291-
292227
ctx.execute_with_session(Some(policy_auth_session), |ctx| {
293228
ctx.create(parent, ak_pub, ak_auth_value, None, None, None)
294229
})

0 commit comments

Comments
 (0)