Skip to content

Commit 5590896

Browse files
committed
Fixes API breaking changes.
Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
1 parent a7df622 commit 5590896

File tree

6 files changed

+558
-33
lines changed

6 files changed

+558
-33
lines changed

tss-esapi/src/abstraction/ak.rs

Lines changed: 44 additions & 4 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,
@@ -131,7 +133,7 @@ fn create_ak_public<IKC: IntoKeyCustomization>(
131133
key_builder.build()
132134
}
133135

134-
// extracts the hashing and sysmmetric algorithm from parent and constructs the correct DigestList for OR policy
136+
/// Extracts the hashing and symmetric algorithm from parent and constructs the correct DigestList for OR policy
135137
fn session_config(
136138
context: &mut Context,
137139
parent: KeyHandle,
@@ -228,8 +230,46 @@ 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.
234+
///
235+
/// <div class="warning">
236+
///
237+
/// The API of this function will be changed to that of [`create_ak_2`]
238+
/// in the next major version.
239+
///
240+
/// </div>
232241
pub fn create_ak<IKC: IntoKeyCustomization>(
242+
context: &mut Context,
243+
parent: KeyHandle,
244+
hash_alg: HashingAlgorithm,
245+
sign_alg: SignatureSchemeAlgorithm,
246+
ak_auth_value: Option<Auth>,
247+
key_customization: IKC,
248+
) -> Result<CreateKeyResult> {
249+
let key_alg = AsymmetricAlgorithm::try_from(sign_alg).map_err(|e| {
250+
// sign_alg is either HMAC or Null.
251+
error!("Could not retrieve asymmetric algorithm for provided signature scheme");
252+
e
253+
})?;
254+
create_ak_2(
255+
context,
256+
parent,
257+
hash_alg,
258+
AsymmetricAlgorithmSelection::try_from(key_alg)?,
259+
sign_alg,
260+
ak_auth_value,
261+
key_customization,
262+
)
263+
}
264+
265+
/// This creates an Attestation Key in the Endorsement hierarchy.
266+
///
267+
/// <div class="warning">
268+
///
269+
/// This function will be removed in the next major version.
270+
///
271+
/// </div>
272+
pub fn create_ak_2<IKC: IntoKeyCustomization>(
233273
context: &mut Context,
234274
parent: KeyHandle,
235275
hash_alg: HashingAlgorithm,

tss-esapi/src/abstraction/ek.rs

Lines changed: 57 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},
@@ -60,7 +60,36 @@ const AUTH_POLICY_B_SM3_256: [u8; 32] = [
6060
///
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
63+
///
64+
/// <div class="warning">
65+
///
66+
/// The API of this function will be changed to that of [`create_ek_public_from_default_template_2`]
67+
/// in the next major version.
68+
///
69+
/// </div>
6370
pub fn create_ek_public_from_default_template<IKC: IntoKeyCustomization>(
71+
alg: AsymmetricAlgorithm,
72+
key_customization: IKC,
73+
) -> Result<Public> {
74+
create_ek_public_from_default_template_2(
75+
AsymmetricAlgorithmSelection::try_from(alg)?,
76+
key_customization,
77+
)
78+
}
79+
80+
/// Get the [`Public`] representing a default Endorsement Key
81+
///
82+
/// **Note**: This only works for key algorithms specified in TCG EK Credential Profile for TPM Family 2.0.
83+
///
84+
/// Source: TCG EK Credential Profile for TPM Family 2.0; Level 0 Version 2.3 Revision 2
85+
/// Appendix B.3.3 and B.3.4
86+
///
87+
/// <div class="warning">
88+
///
89+
/// This function will be removed in the next major version.
90+
///
91+
/// </div>
92+
pub fn create_ek_public_from_default_template_2<IKC: IntoKeyCustomization>(
6493
alg: AsymmetricAlgorithmSelection,
6594
key_customization: IKC,
6695
) -> Result<Public> {
@@ -191,12 +220,38 @@ pub fn create_ek_public_from_default_template<IKC: IntoKeyCustomization>(
191220
}
192221

193222
/// Create the Endorsement Key object from the specification templates
223+
///
224+
/// <div class="warning">
225+
///
226+
/// The API of this function will be changed to that of [`create_ek_object_2`]
227+
/// in the next major version.
228+
///
229+
/// </div>
194230
pub fn create_ek_object<IKC: IntoKeyCustomization>(
231+
context: &mut Context,
232+
alg: AsymmetricAlgorithm,
233+
key_customization: IKC,
234+
) -> Result<KeyHandle> {
235+
create_ek_object_2(
236+
context,
237+
AsymmetricAlgorithmSelection::try_from(alg)?,
238+
key_customization,
239+
)
240+
}
241+
242+
/// Create the Endorsement Key object from the specification templates
243+
///
244+
/// <div class="warning">
245+
///
246+
/// This function will be removed in the next major version.
247+
///
248+
/// </div>
249+
pub fn create_ek_object_2<IKC: IntoKeyCustomization>(
195250
context: &mut Context,
196251
alg: AsymmetricAlgorithmSelection,
197252
key_customization: IKC,
198253
) -> Result<KeyHandle> {
199-
let ek_public = create_ek_public_from_default_template(alg, key_customization)?;
254+
let ek_public = create_ek_public_from_default_template_2(alg, key_customization)?;
200255

201256
Ok(context
202257
.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)