Skip to content

Commit 046f466

Browse files
committed
Fixes API breaking changes.
Signed-off-by: Jesper Brynolf <[email protected]>
1 parent a7df622 commit 046f466

File tree

3 files changed

+72
-7
lines changed

3 files changed

+72
-7
lines changed

tss-esapi/src/abstraction/ak.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use crate::{
88
handles::{AuthHandle, KeyHandle, SessionHandle},
99
interface_types::{
1010
algorithm::{
11-
EccSchemeAlgorithm, HashingAlgorithm, PublicAlgorithm, RsaSchemeAlgorithm,
12-
SignatureSchemeAlgorithm,
11+
AsymmetricAlgorithm, EccSchemeAlgorithm, HashingAlgorithm, PublicAlgorithm,
12+
RsaSchemeAlgorithm, SignatureSchemeAlgorithm,
1313
},
1414
session_handles::PolicySession,
1515
},
@@ -21,6 +21,7 @@ use crate::{
2121
},
2222
Context, Error, Result, WrapperErrorKind,
2323
};
24+
use log::error;
2425
use std::convert::TryFrom;
2526

2627
// Source: TCG EK Credential Profile for TPM Family 2.0; Level 0 Version 2.5 Revision 2
@@ -56,6 +57,7 @@ const POLICY_C_SM3_256: [u8; 32] = [
5657
0x56, 0x99, 0xa3, 0xe3, 0x9f, 0xc3, 0x55, 0x1b, 0xfe, 0xff, 0xcf, 0x13, 0x2b, 0x49, 0xe1, 0x1d,
5758
];
5859

60+
/// Creates a Public object for an AK key.
5961
fn create_ak_public<IKC: IntoKeyCustomization>(
6062
key_alg: AsymmetricAlgorithmSelection,
6163
hash_alg: HashingAlgorithm,
@@ -228,8 +230,36 @@ pub fn load_ak(
228230
Ok(key_handle)
229231
}
230232

231-
/// This creates an Attestation Key in the Endorsement hierarchy
233+
/// This creates an Attestation Key in the Endorsement hierarchy.
232234
pub fn create_ak<IKC: IntoKeyCustomization>(
235+
context: &mut Context,
236+
parent: KeyHandle,
237+
hash_alg: HashingAlgorithm,
238+
sign_alg: SignatureSchemeAlgorithm,
239+
ak_auth_value: Option<Auth>,
240+
key_customization: IKC,
241+
) -> Result<CreateKeyResult> {
242+
let key_alg = AsymmetricAlgorithm::try_from(sign_alg).map_err(|e| {
243+
// sign_alg is either HMAC or Null.
244+
error!("Could not retrieve asymmetric algorithm for provided signature scheme");
245+
e
246+
})?;
247+
create_ak_2(
248+
context,
249+
parent,
250+
hash_alg,
251+
AsymmetricAlgorithmSelection::try_from(key_alg)?,
252+
sign_alg,
253+
ak_auth_value,
254+
key_customization,
255+
)
256+
}
257+
258+
/// This creates an Attestation Key in the Endorsement hierarchy.
259+
///
260+
/// # Details
261+
/// This is only replace the `create_ak` API in the next major version.
262+
pub fn create_ak_2<IKC: IntoKeyCustomization>(
233263
context: &mut Context,
234264
parent: KeyHandle,
235265
hash_alg: HashingAlgorithm,

tss-esapi/src/abstraction/ek.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
attributes::ObjectAttributesBuilder,
77
handles::{KeyHandle, NvIndexTpmHandle, TpmHandle},
88
interface_types::{
9-
algorithm::{HashingAlgorithm, PublicAlgorithm},
9+
algorithm::{AsymmetricAlgorithm, HashingAlgorithm, PublicAlgorithm},
1010
ecc::EccCurve,
1111
key_bits::RsaKeyBits,
1212
resource_handles::{Hierarchy, NvAuth},
@@ -61,6 +61,25 @@ const AUTH_POLICY_B_SM3_256: [u8; 32] = [
6161
/// Source: TCG EK Credential Profile for TPM Family 2.0; Level 0 Version 2.3 Revision 2
6262
/// Appendix B.3.3 and B.3.4
6363
pub fn create_ek_public_from_default_template<IKC: IntoKeyCustomization>(
64+
alg: AsymmetricAlgorithm,
65+
key_customization: IKC,
66+
) -> Result<Public> {
67+
create_ek_public_from_default_template_2(
68+
AsymmetricAlgorithmSelection::try_from(alg)?,
69+
key_customization,
70+
)
71+
}
72+
73+
/// Get the [`Public`] representing a default Endorsement Key
74+
///
75+
/// **Note**: This only works for key algorithms specified in TCG EK Credential Profile for TPM Family 2.0.
76+
///
77+
/// Source: TCG EK Credential Profile for TPM Family 2.0; Level 0 Version 2.3 Revision 2
78+
/// Appendix B.3.3 and B.3.4
79+
///
80+
/// # Details
81+
/// This is only replace the `create_ek_public_from_default_template` API in the next major version.
82+
pub fn create_ek_public_from_default_template_2<IKC: IntoKeyCustomization>(
6483
alg: AsymmetricAlgorithmSelection,
6584
key_customization: IKC,
6685
) -> Result<Public> {
@@ -192,11 +211,27 @@ pub fn create_ek_public_from_default_template<IKC: IntoKeyCustomization>(
192211

193212
/// Create the Endorsement Key object from the specification templates
194213
pub fn create_ek_object<IKC: IntoKeyCustomization>(
214+
context: &mut Context,
215+
alg: AsymmetricAlgorithm,
216+
key_customization: IKC,
217+
) -> Result<KeyHandle> {
218+
create_ek_object_2(
219+
context,
220+
AsymmetricAlgorithmSelection::try_from(alg)?,
221+
key_customization,
222+
)
223+
}
224+
225+
/// Create the Endorsement Key object from the specification templates
226+
///
227+
/// # Details
228+
/// This is only replace the `create_ek_object` API in the next major version.
229+
pub fn create_ek_object_2<IKC: IntoKeyCustomization>(
195230
context: &mut Context,
196231
alg: AsymmetricAlgorithmSelection,
197232
key_customization: IKC,
198233
) -> Result<KeyHandle> {
199-
let ek_public = create_ek_public_from_default_template(alg, key_customization)?;
234+
let ek_public = create_ek_public_from_default_template_2(alg, key_customization)?;
200235

201236
Ok(context
202237
.execute_with_nullauth_session(|ctx| {

tss-esapi/src/abstraction/transient/key_attestation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl TransientKeyContext {
152152
None,
153153
);
154154
Ok((
155-
ek::create_ek_object(
155+
ek::create_ek_object_2(
156156
&mut self.context,
157157
AsymmetricAlgorithmSelection::Rsa(RsaKeyBits::Rsa2048),
158158
None,
@@ -192,7 +192,7 @@ impl TransientKeyContext {
192192
}
193193

194194
fn get_ek_object_public(context: &mut crate::Context) -> Result<PublicKey> {
195-
let key_handle = ek::create_ek_object(
195+
let key_handle = ek::create_ek_object_2(
196196
context,
197197
AsymmetricAlgorithmSelection::Rsa(RsaKeyBits::Rsa2048),
198198
None,

0 commit comments

Comments
 (0)