Skip to content

Commit c01cf01

Browse files
committed
PR feedback
Improved the tests to check for the exact response code expected. Improved the documentation on `MakeCredentialParams` to detail what the contents are meant for. Signed-off-by: Ionut Mihalcea <[email protected]>
1 parent d574d3c commit c01cf01

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

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

+15-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,22 @@ use std::convert::{TryFrom, TryInto};
1919

2020
#[derive(Debug)]
2121
/// Wrapper for the parameters needed by MakeCredential
22+
///
23+
/// The 3rd party requesting proof that the key is indeed backed
24+
/// by a TPM would perform a MakeCredential and would thus require
25+
/// `name` and `attesting_key_pub` as inputs for that operation.
26+
///
27+
/// `public` is not strictly needed, however it is returned as a
28+
/// convenience block of data. Since the MakeCredential operation
29+
/// bakes into the encrypted credential the identity of the key to
30+
/// be attested via its `name`, the correctness of the `name` must
31+
/// be verifiable by the said 3rd party. `public` bridges this gap:
32+
///
33+
/// * it includes all the public parameters of the attested key
34+
/// * can be hashed (in its marshaled form) with the name hash
35+
/// (found by unmarshaling it) to obtain `name`
2236
pub struct MakeCredParams {
23-
/// TPM name of the object
37+
/// TPM name of the object being attested
2438
pub name: Vec<u8>,
2539
/// Encoding of the public parameters of the object whose name
2640
/// will be included in the credential computations

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

+22-3
Original file line numberDiff line numberDiff line change
@@ -790,15 +790,22 @@ fn activate_credential_wrong_key() {
790790
drop(basic_ctx);
791791

792792
// Create a new Transient key context and activate the credential
793+
// Validation fails within the TPM because the credential HMAC is
794+
// associated with a different object (so the integrity check fails).
793795
let mut ctx = create_ctx();
794-
let _ = ctx
796+
let e = ctx
795797
.activate_credential(
796798
wrong_obj,
797799
None,
798800
cred.value().to_vec(),
799801
secret.value().to_vec(),
800802
)
801803
.unwrap_err();
804+
if let Error::Tss2Error(e) = e {
805+
assert_eq!(e.kind(), Some(Tss2ResponseCodeKind::Integrity));
806+
} else {
807+
panic!("Got crate error ({}) when expecting an error from TPM.", e);
808+
}
802809
}
803810

804811
#[test]
@@ -821,11 +828,23 @@ fn activate_credential_wrong_data() {
821828
params,
822829
};
823830

824-
let _ = ctx
831+
// No data (essentially wrong size)
832+
let e = ctx
825833
.activate_credential(obj.clone(), None, vec![], vec![])
826834
.unwrap_err();
835+
if let Error::Tss2Error(e) = e {
836+
assert_eq!(e.kind(), Some(Tss2ResponseCodeKind::Size));
837+
} else {
838+
panic!("Got crate error ({}) when expecting an error from TPM.", e);
839+
}
827840

828-
let _ = ctx
841+
// Correct size but gibberish
842+
let e = ctx
829843
.activate_credential(obj, None, vec![0xaa; 52], vec![0x55; 256])
830844
.unwrap_err();
845+
if let Error::Tss2Error(e) = e {
846+
assert_eq!(e.kind(), Some(Tss2ResponseCodeKind::Value));
847+
} else {
848+
panic!("Got crate error ({}) when expecting an error from TPM.", e);
849+
}
831850
}

0 commit comments

Comments
 (0)