Skip to content

Commit 8ec8381

Browse files
authored
Merge pull request #543 from Superhepper/fixing-features
Fixes problem with running tests needing features to be specified.
2 parents 938247b + 884f024 commit 8ec8381

File tree

8 files changed

+87
-120
lines changed

8 files changed

+87
-120
lines changed

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[workspace]
2-
members = ["tss-esapi", "tss-esapi-sys"]
2+
members = ["tss-esapi", "tss-esapi-sys"]
3+
resolver = "2"

tss-esapi/Cargo.toml

+13-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ rust-version = "1.66.0"
1515
[[example]]
1616
name = "hmac"
1717

18+
[[example]]
19+
name = "certify"
20+
required-features = ["abstraction"]
21+
1822
[dependencies]
1923
bitfield = "0.14"
20-
serde = { version = "1.0.115", features = ["derive"], optional = true, default-features = false }
24+
serde = { version = "1.0.115", features = [
25+
"derive",
26+
], optional = true, default-features = false }
2127
malloced = "1.3.1"
2228
log = "0.4.11"
2329
enumflags2 = "0.7.7"
@@ -40,6 +46,12 @@ getrandom = "0.2.11"
4046
env_logger = "0.9.0"
4147
sha2 = "0.10.1"
4248
serde_json = "^1.0.108"
49+
tss-esapi = { path = ".", features = [
50+
"integration-tests",
51+
"serde",
52+
"abstraction",
53+
] }
54+
4355

4456
[build-dependencies]
4557
semver = "1.0.7"

tss-esapi/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ The crate currently offers the following features:
2727
* `abstraction` (enabled by default) - provides a set of abstracted primitives
2828
on top of the basic Rust-native ESAPI API provided by the crate. This feature
2929
can be turned off to reduce the number of dependencies built.
30+
* `serde` - enable serde `Serialize`/`Deserialize` traits for types.
3031

3132
## Cross compiling
3233

tss-esapi/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub mod structures;
109109
pub mod tcti_ldr;
110110
pub mod traits;
111111
pub mod utils;
112-
112+
#[cfg(feature = "abstraction")]
113113
pub use abstraction::transient::TransientKeyContext;
114114
pub use context::Context;
115115
pub use error::{Error, Result, ReturnCode, WrapperErrorKind};

tss-esapi/tests/integration_tests/common/mod.rs

+8-29
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::{
88
};
99

1010
use tss_esapi::{
11-
abstraction::{cipher::Cipher, pcr::PcrData},
1211
attributes::ObjectAttributes,
1312
attributes::{NvIndexAttributesBuilder, ObjectAttributesBuilder, SessionAttributesBuilder},
1413
constants::SessionType,
@@ -234,9 +233,7 @@ pub fn create_ctx_with_session() -> Context {
234233
#[allow(dead_code)]
235234
pub fn decryption_key_pub() -> Public {
236235
utils::create_restricted_decryption_rsa_public(
237-
Cipher::aes_256_cfb()
238-
.try_into()
239-
.expect("Failed to create symmetric object"),
236+
SymmetricDefinitionObject::AES_256_CFB,
240237
RsaKeyBits::Rsa2048,
241238
RsaExponent::default(),
242239
)
@@ -278,16 +275,8 @@ pub fn get_pcr_policy_digest(
278275
.build()
279276
.expect("Failed to create PcrSelectionList");
280277

281-
let (_update_counter, pcr_selection_list_out, pcr_data) = context
278+
let (_update_counter, pcr_selection_list_out, read_pcr_digests) = context
282279
.pcr_read(pcr_selection_list.clone())
283-
.map(|(update_counter, read_pcr_selections, read_pcr_digests)| {
284-
(
285-
update_counter,
286-
read_pcr_selections.clone(),
287-
PcrData::create(&read_pcr_selections, &read_pcr_digests)
288-
.expect("Failed to create PcrData"),
289-
)
290-
})
291280
.expect("Failed to call pcr_read");
292281

293282
assert_eq!(pcr_selection_list, pcr_selection_list_out);
@@ -298,22 +287,12 @@ pub fn get_pcr_policy_digest(
298287
// values from the command rather than the values from a digest of the TPM PCR."
299288
//
300289
// "TPM2_Quote() and TPM2_PolicyPCR() digest the concatenation of PCR."
301-
let mut concatenated_pcr_values = [
302-
pcr_data
303-
.pcr_bank(HashingAlgorithm::Sha256)
304-
.unwrap()
305-
.get_digest(PcrSlot::Slot0)
306-
.unwrap()
307-
.as_bytes(),
308-
pcr_data
309-
.pcr_bank(HashingAlgorithm::Sha256)
310-
.unwrap()
311-
.get_digest(PcrSlot::Slot1)
312-
.unwrap()
313-
.as_bytes(),
314-
]
315-
.concat();
316-
290+
let mut concatenated_pcr_values = read_pcr_digests
291+
.value()
292+
.iter()
293+
.map(|v| v.as_bytes())
294+
.collect::<Vec<&[u8]>>()
295+
.concat();
317296
if mangle {
318297
concatenated_pcr_values[0] = 0x00;
319298
}

tss-esapi/tests/integration_tests/context_tests/tpm_commands/enhanced_authorization_ea_commands_tests.rs

+14-52
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ mod test_policy_pcr {
194194
use crate::common::create_ctx_without_session;
195195
use std::convert::TryFrom;
196196
use tss_esapi::{
197-
abstraction::pcr::PcrData,
198197
attributes::SessionAttributesBuilder,
199198
constants::SessionType,
200199
interface_types::{
@@ -237,16 +236,8 @@ mod test_policy_pcr {
237236
.build()
238237
.expect("Failed to create PcrSelectionList");
239238

240-
let (_update_counter, pcr_selection_list_out, pcr_data) = context
239+
let (_update_counter, pcr_selection_list_out, read_pcr_digests) = context
241240
.pcr_read(pcr_selection_list.clone())
242-
.map(|(update_counter, read_pcr_selections, read_pcr_digests)| {
243-
(
244-
update_counter,
245-
read_pcr_selections.clone(),
246-
PcrData::create(&read_pcr_selections, &read_pcr_digests)
247-
.expect("Failed to create PcrData"),
248-
)
249-
})
250241
.expect("Failed to call pcr_read");
251242

252243
assert_eq!(pcr_selection_list, pcr_selection_list_out);
@@ -258,22 +249,12 @@ mod test_policy_pcr {
258249
//
259250
// "TPM2_Quote() and TPM2_PolicyPCR() digest the concatenation of PCR."
260251
let concatenated_pcr_values = MaxBuffer::try_from(
261-
[
262-
pcr_data
263-
.pcr_bank(HashingAlgorithm::Sha256)
264-
.unwrap()
265-
.get_digest(PcrSlot::Slot0)
266-
.unwrap()
267-
.as_bytes(),
268-
pcr_data
269-
.pcr_bank(HashingAlgorithm::Sha256)
270-
.unwrap()
271-
.get_digest(PcrSlot::Slot1)
272-
.unwrap()
273-
.as_bytes(),
274-
]
275-
.concat()
276-
.to_vec(),
252+
read_pcr_digests
253+
.value()
254+
.iter()
255+
.map(|v| v.as_bytes())
256+
.collect::<Vec<&[u8]>>()
257+
.concat(),
277258
)
278259
.unwrap();
279260

@@ -679,7 +660,6 @@ mod test_policy_get_digest {
679660
use crate::common::create_ctx_without_session;
680661
use std::convert::TryFrom;
681662
use tss_esapi::{
682-
abstraction::pcr::PcrData,
683663
attributes::SessionAttributesBuilder,
684664
constants::SessionType,
685665
interface_types::{
@@ -723,16 +703,8 @@ mod test_policy_get_digest {
723703

724704
let trial_policy_session = PolicySession::try_from(trial_policy_auth_session)
725705
.expect("Failed to convert auth session into policy session");
726-
let (_update_counter, pcr_selection_list_out, pcr_data) = context
706+
let (_update_counter, pcr_selection_list_out, read_pcr_digests) = context
727707
.pcr_read(pcr_selection_list.clone())
728-
.map(|(update_counter, read_pcr_selections, read_pcr_digests)| {
729-
(
730-
update_counter,
731-
read_pcr_selections.clone(),
732-
PcrData::create(&read_pcr_selections, &read_pcr_digests)
733-
.expect("Failed to create PcrData"),
734-
)
735-
})
736708
.expect("Failed to call pcr_read");
737709

738710
assert_eq!(pcr_selection_list, pcr_selection_list_out);
@@ -744,22 +716,12 @@ mod test_policy_get_digest {
744716
//
745717
// "TPM2_Quote() and TPM2_PolicyPCR() digest the concatenation of PCR."
746718
let concatenated_pcr_values = MaxBuffer::try_from(
747-
[
748-
pcr_data
749-
.pcr_bank(HashingAlgorithm::Sha256)
750-
.unwrap()
751-
.get_digest(PcrSlot::Slot0)
752-
.unwrap()
753-
.as_bytes(),
754-
pcr_data
755-
.pcr_bank(HashingAlgorithm::Sha256)
756-
.unwrap()
757-
.get_digest(PcrSlot::Slot1)
758-
.unwrap()
759-
.as_bytes(),
760-
]
761-
.concat()
762-
.to_vec(),
719+
read_pcr_digests
720+
.value()
721+
.iter()
722+
.map(|v| v.as_bytes())
723+
.collect::<Vec<&[u8]>>()
724+
.concat(),
763725
)
764726
.unwrap();
765727

tss-esapi/tests/integration_tests/context_tests/tpm_commands/integrity_collection_pcr_tests.rs

+44-27
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ mod test_pcr_extend_reset {
44
use crate::common::create_ctx_with_session;
55
use std::convert::TryFrom;
66
use tss_esapi::{
7-
abstraction::pcr::PcrData,
87
handles::PcrHandle,
98
interface_types::algorithm::HashingAlgorithm,
109
structures::{Digest, DigestValues, PcrSelectionListBuilder, PcrSlot},
@@ -34,6 +33,12 @@ mod test_pcr_extend_reset {
3433
});
3534

3635
// Needs to have the length of associated with the hashing algorithm
36+
assert_eq!(read_pcr_selections.get_selections().len(), 2);
37+
assert_eq!(
38+
pcr_selection_list.get_selections(),
39+
read_pcr_selections.get_selections()
40+
);
41+
assert_eq!(read_pcr_digests.value().len(), 2);
3742
read_pcr_selections
3843
.get_selections()
3944
.iter()
@@ -73,8 +78,8 @@ mod test_pcr_extend_reset {
7378
});
7479

7580
// Read PCR contents
76-
let (_, read_pcr_selections_2, read_pcr_digests_2) =
77-
context.execute_without_session(|ctx| ctx.pcr_read(pcr_selection_list).unwrap());
81+
let (_, after_extend_read_pcr_selections, after_extend_read_pcr_digests) = context
82+
.execute_without_session(|ctx| ctx.pcr_read(pcr_selection_list.clone()).unwrap());
7883
// Needs to have the length of associated with the hashing algorithm
7984
/*
8085
Right Hand Side determined by:
@@ -87,11 +92,16 @@ mod test_pcr_extend_reset {
8792
>>> res = ["0x"+a+b for a,b in zip(it, it)]
8893
>>> ", ".join(res)
8994
*/
90-
91-
read_pcr_selections_2
95+
assert_eq!(after_extend_read_pcr_selections.get_selections().len(), 2);
96+
assert_eq!(
97+
pcr_selection_list.get_selections(),
98+
after_extend_read_pcr_selections.get_selections()
99+
);
100+
assert_eq!(after_extend_read_pcr_digests.value().len(), 2);
101+
after_extend_read_pcr_selections
92102
.get_selections()
93103
.iter()
94-
.zip(read_pcr_digests_2.value().iter())
104+
.zip(after_extend_read_pcr_digests.value().iter())
95105
.for_each(|(pcr_selection, digest)| {
96106
if pcr_selection.hashing_algorithm() == HashingAlgorithm::Sha1 {
97107
assert_eq!(digest.len(), 20);
@@ -121,28 +131,35 @@ mod test_pcr_extend_reset {
121131
context.execute_with_session(pcr_ses, |ctx| ctx.pcr_reset(PcrHandle::Pcr16).unwrap());
122132

123133
// Read PCR contents
124-
let pcr_selection_list = PcrSelectionListBuilder::new()
125-
.with_selection(HashingAlgorithm::Sha1, &[PcrSlot::Slot16])
126-
.with_selection(HashingAlgorithm::Sha256, &[PcrSlot::Slot16])
127-
.build()
128-
.expect("Failed to create PcrSelectionList for pcr_read call after pcr_reset");
129-
let pcr_data = context
134+
let (_, after_reset_read_pcr_selections_out, after_reset_read_pcr_digests) = context
130135
.execute_without_session(|ctx| {
131-
ctx.pcr_read(pcr_selection_list).map(
132-
|(_, read_pcr_selections, read_pcr_digests)| {
133-
PcrData::create(&read_pcr_selections, &read_pcr_digests)
134-
.expect("Failed to create PcrData")
135-
},
136-
)
137-
})
138-
.expect("Failed to call pcr_read");
139-
let pcr_sha1_bank = pcr_data.pcr_bank(HashingAlgorithm::Sha1).unwrap();
140-
let pcr_sha256_bank = pcr_data.pcr_bank(HashingAlgorithm::Sha256).unwrap();
141-
let pcr_sha1_value = pcr_sha1_bank.get_digest(PcrSlot::Slot16).unwrap();
142-
let pcr_sha256_value = pcr_sha256_bank.get_digest(PcrSlot::Slot16).unwrap();
143-
// Needs to have the length of associated with the hashing algorithm
144-
assert_eq!(pcr_sha1_value.as_bytes(), [0; 20]);
145-
assert_eq!(pcr_sha256_value.as_bytes(), [0; 32]);
136+
ctx.pcr_read(pcr_selection_list.clone())
137+
.expect("Failed to call pcr_read")
138+
});
139+
assert_eq!(
140+
after_reset_read_pcr_selections_out.get_selections().len(),
141+
2
142+
);
143+
assert_eq!(
144+
pcr_selection_list.get_selections(),
145+
after_reset_read_pcr_selections_out.get_selections()
146+
);
147+
assert_eq!(after_reset_read_pcr_digests.value().len(), 2);
148+
after_reset_read_pcr_selections_out
149+
.get_selections()
150+
.iter()
151+
.zip(after_reset_read_pcr_digests.value().iter())
152+
.for_each(|(pcr_selection, digest)| {
153+
if pcr_selection.hashing_algorithm() == HashingAlgorithm::Sha1 {
154+
assert_eq!(digest.len(), 20);
155+
assert_eq!(digest.as_bytes(), [0; 20]);
156+
} else if pcr_selection.hashing_algorithm() == HashingAlgorithm::Sha256 {
157+
assert_eq!(digest.len(), 32);
158+
assert_eq!(digest.as_bytes(), [0; 32]);
159+
} else {
160+
panic!("Read pcr selections contained unexpected HashingAlgorithm");
161+
}
162+
});
146163
}
147164
}
148165

tss-esapi/tests/integration_tests/context_tests/tpm_commands/symmetric_primitives_tests.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
// SPDX-License-Identifier: Apache-2.0
33
mod test_encrypt_decrypt_2 {
44
use crate::common::create_ctx_without_session;
5-
use std::convert::{TryFrom, TryInto};
5+
use std::convert::TryFrom;
66
use tss_esapi::{
7-
abstraction::cipher::Cipher,
87
attributes::ObjectAttributesBuilder,
98
interface_types::{
109
algorithm::{HashingAlgorithm, PublicAlgorithm, SymmetricMode},
@@ -14,7 +13,7 @@ mod test_encrypt_decrypt_2 {
1413
},
1514
structures::{
1615
Auth, InitialValue, MaxBuffer, PublicBuilder, RsaExponent, SensitiveData,
17-
SymmetricCipherParameters,
16+
SymmetricCipherParameters, SymmetricDefinitionObject,
1817
},
1918
};
2019
#[test]
@@ -34,9 +33,7 @@ mod test_encrypt_decrypt_2 {
3433
ctx.create_primary(
3534
Hierarchy::Owner,
3635
tss_esapi::utils::create_restricted_decryption_rsa_public(
37-
Cipher::aes_128_cfb()
38-
.try_into()
39-
.expect("Failed to convert from Cipher"),
36+
SymmetricDefinitionObject::AES_128_CFB,
4037
RsaKeyBits::Rsa2048,
4138
RsaExponent::default(),
4239
)
@@ -66,9 +63,7 @@ mod test_encrypt_decrypt_2 {
6663
.with_name_hashing_algorithm(HashingAlgorithm::Sha256)
6764
.with_object_attributes(symmetric_key_object_attributes)
6865
.with_symmetric_cipher_parameters(SymmetricCipherParameters::new(
69-
Cipher::aes_128_cfb()
70-
.try_into()
71-
.expect("Failed to create symmteric cipher parameters from cipher"),
66+
SymmetricDefinitionObject::AES_128_CFB,
7267
))
7368
.with_symmetric_cipher_unique_identifier(Default::default())
7469
.build()

0 commit comments

Comments
 (0)