Skip to content

Commit 6f1b80b

Browse files
authored
Merge pull request #323 from ionut-arm/customize-ak
Allow customizing AK public
2 parents 61bb20e + 69cf1e6 commit 6f1b80b

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

tss-esapi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tss-esapi"
3-
version = "7.0.0-beta.1"
3+
version = "7.0.0-beta.2"
44
authors = ["Parsec Project Contributors"]
55
edition = "2018"
66
description = "Rust-native wrapper around TSS 2.0 Enhanced System API"

tss-esapi/src/abstraction/ak.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn create_ak_public<IKC: IntoKeyCustomization>(
4949
}
5050
.build()?;
5151

52-
match key_alg {
52+
let key_builder = match key_alg {
5353
AsymmetricAlgorithm::Rsa => PublicBuilder::new()
5454
.with_public_algorithm(PublicAlgorithm::Rsa)
5555
.with_name_hashing_algorithm(hash_alg)
@@ -67,8 +67,7 @@ fn create_ak_public<IKC: IntoKeyCustomization>(
6767
.with_restricted(obj_attrs.restricted())
6868
.build()?,
6969
)
70-
.with_rsa_unique_identifier(PublicKeyRsa::default())
71-
.build(),
70+
.with_rsa_unique_identifier(PublicKeyRsa::default()),
7271
AsymmetricAlgorithm::Ecc => PublicBuilder::new()
7372
.with_public_algorithm(PublicAlgorithm::Ecc)
7473
.with_name_hashing_algorithm(hash_alg)
@@ -84,13 +83,20 @@ fn create_ak_public<IKC: IntoKeyCustomization>(
8483
.with_curve(EccCurve::NistP192)
8584
.with_key_derivation_function_scheme(KeyDerivationFunctionScheme::Null)
8685
.build()?,
87-
)
88-
.build(),
86+
),
8987
AsymmetricAlgorithm::Null => {
9088
// TODO: Figure out what to with Null.
91-
Err(Error::local_error(WrapperErrorKind::UnsupportedParam))
89+
return Err(Error::local_error(WrapperErrorKind::UnsupportedParam));
9290
}
93-
}
91+
};
92+
93+
let key_builder = if let Some(ref k) = key_customization {
94+
k.template(key_builder)
95+
} else {
96+
key_builder
97+
};
98+
99+
key_builder.build()
94100
}
95101

96102
/// This loads an Attestation Key previously generated under the Endorsement hierarchy

tss-esapi/src/constants/ecc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::convert::TryFrom;
1717
///
1818
/// # Details
1919
/// This corresponds to `TPM2_ECC_CURVE`
20-
#[derive(FromPrimitive, ToPrimitive, Debug, Copy, Clone, PartialEq, Eq)]
20+
#[derive(FromPrimitive, ToPrimitive, Debug, Copy, Clone, PartialEq, Eq, Hash)]
2121
#[repr(u16)]
2222
pub enum EccCurveIdentifier {
2323
NistP192 = TPM2_ECC_NIST_P192,

tss-esapi/tests/integration_tests/abstraction_tests/ak_tests.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use tss_esapi::{
1212
algorithm::{AsymmetricAlgorithm, HashingAlgorithm, SignatureSchemeAlgorithm},
1313
session_handles::PolicySession,
1414
},
15-
structures::{Auth, Digest, SymmetricDefinition},
15+
structures::{Auth, Digest, PublicBuilder, SymmetricDefinition},
1616
};
1717

1818
use crate::common::create_ctx_without_session;
@@ -143,14 +143,18 @@ fn test_create_and_use_ak() {
143143

144144
#[test]
145145
fn test_create_custom_ak() {
146-
struct StClearKeys;
147-
impl KeyCustomization for &StClearKeys {
146+
struct CustomizeKey;
147+
impl KeyCustomization for &CustomizeKey {
148148
fn attributes(
149149
&self,
150150
attributes_builder: ObjectAttributesBuilder,
151151
) -> ObjectAttributesBuilder {
152152
attributes_builder.with_st_clear(true)
153153
}
154+
155+
fn template(&self, template_builder: PublicBuilder) -> PublicBuilder {
156+
template_builder.with_name_hashing_algorithm(HashingAlgorithm::Sha1)
157+
}
154158
}
155159
let mut context = create_ctx_without_session();
156160

@@ -179,7 +183,7 @@ fn test_create_custom_ak() {
179183
HashingAlgorithm::Sha256,
180184
SignatureSchemeAlgorithm::RsaPss,
181185
Some(ak_auth),
182-
&StClearKeys,
186+
&CustomizeKey,
183187
)
184188
.unwrap();
185189

@@ -192,4 +196,9 @@ fn test_create_custom_ak() {
192196
att_key_without.out_public.object_attributes().0
193197
| tss_esapi::constants::tss::TPMA_OBJECT_STCLEAR
194198
);
199+
200+
assert_eq!(
201+
att_key.out_public.name_hashing_algorithm(),
202+
HashingAlgorithm::Sha1,
203+
);
195204
}

0 commit comments

Comments
 (0)