Skip to content

Commit 421980a

Browse files
committed
Allow the setting more hierarchy auths in TKC
This commit expands the scope of the TransientKeyContextBuilder to adding more than one hierarchy auth value. This is needed for attesting keys with the default Endorsement Key which uses the Endorsement Hierarchy for authorization by default. Signed-off-by: Ionut Mihalcea <[email protected]>
1 parent 40059da commit 421980a

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use crate::{
3636

3737
use log::error;
3838
use serde::{Deserialize, Serialize};
39+
use std::collections::HashMap;
3940
use std::convert::{TryFrom, TryInto};
4041
use zeroize::Zeroize;
4142

@@ -532,10 +533,10 @@ impl TransientKeyContext {
532533
#[derive(Debug)]
533534
pub struct TransientKeyContextBuilder {
534535
tcti_name_conf: TctiNameConf,
535-
hierarchy: Hierarchy,
536536
root_key_size: u16, // TODO: replace with root key PUBLIC definition
537537
root_key_auth_size: usize,
538-
hierarchy_auth: Vec<u8>,
538+
root_hierarchy: Hierarchy,
539+
hierarchy_auth: HashMap<Hierarchy, Vec<u8>>,
539540
default_context_cipher: SymmetricDefinitionObject,
540541
session_hash_alg: HashingAlgorithm,
541542
}
@@ -545,10 +546,10 @@ impl TransientKeyContextBuilder {
545546
pub fn new() -> Self {
546547
TransientKeyContextBuilder {
547548
tcti_name_conf: TctiNameConf::Device(Default::default()),
548-
hierarchy: Hierarchy::Owner,
549+
root_hierarchy: Hierarchy::Owner,
549550
root_key_size: 2048,
550551
root_key_auth_size: 32,
551-
hierarchy_auth: Vec::new(),
552+
hierarchy_auth: HashMap::new(),
552553
default_context_cipher: SymmetricDefinitionObject::AES_256_CFB,
553554
session_hash_alg: HashingAlgorithm::Sha256,
554555
}
@@ -560,9 +561,15 @@ impl TransientKeyContextBuilder {
560561
self
561562
}
562563

564+
/// Set the auth values for any hierarchies that will be used
565+
pub fn with_hierarchy_auth(mut self, hierarchy: Hierarchy, auth: Vec<u8>) -> Self {
566+
let _ = self.hierarchy_auth.insert(hierarchy, auth);
567+
self
568+
}
569+
563570
/// Define which hierarchy will be used for the keys being managed.
564-
pub fn with_hierarchy(mut self, hierarchy: Hierarchy) -> Self {
565-
self.hierarchy = hierarchy;
571+
pub fn with_root_hierarchy(mut self, hierarchy: Hierarchy) -> Self {
572+
self.root_hierarchy = hierarchy;
566573
self
567574
}
568575

@@ -578,12 +585,6 @@ impl TransientKeyContextBuilder {
578585
self
579586
}
580587

581-
/// Input the authentication value of the working hierarchy.
582-
pub fn with_hierarchy_auth(mut self, hierarchy_auth: Vec<u8>) -> Self {
583-
self.hierarchy_auth = hierarchy_auth;
584-
self
585-
}
586-
587588
/// Define the cipher to be used within this context as a default.
588589
///
589590
/// Currently this default is used for:
@@ -624,7 +625,7 @@ impl TransientKeyContextBuilder {
624625
/// `Context::set_handle_auth`
625626
/// * if the root key authentication size is given greater than 32 or if the root key size is
626627
/// not 1024, 2048, 3072 or 4096, a `InvalidParam` wrapper error is returned
627-
pub fn build(self) -> Result<TransientKeyContext> {
628+
pub fn build(mut self) -> Result<TransientKeyContext> {
628629
if self.root_key_auth_size > 32 {
629630
return Err(Error::local_error(ErrorKind::WrongParamSize));
630631
}
@@ -640,9 +641,9 @@ impl TransientKeyContextBuilder {
640641
None
641642
};
642643

643-
if !self.hierarchy_auth.is_empty() {
644-
let auth_hierarchy = Auth::try_from(self.hierarchy_auth)?;
645-
context.tr_set_auth(self.hierarchy.into(), &auth_hierarchy)?;
644+
for (hierarchy, auth) in self.hierarchy_auth.drain() {
645+
let auth_hierarchy = Auth::try_from(auth)?;
646+
context.tr_set_auth(hierarchy.into(), &auth_hierarchy)?;
646647
}
647648

648649
let session = context
@@ -669,7 +670,7 @@ impl TransientKeyContextBuilder {
669670

670671
let root_key_handle = context
671672
.create_primary(
672-
self.hierarchy,
673+
self.root_hierarchy,
673674
&create_restricted_decryption_rsa_public(
674675
self.default_context_cipher,
675676
root_key_rsa_key_bits,

tss-esapi/src/interface_types/resource_handles.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::convert::TryFrom;
1313
///
1414
/// Enum describing the object hierarchies in a TPM 2.0.
1515
//////////////////////////////////////////////////////////////////////////////////
16-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1717
pub enum Hierarchy {
1818
Owner,
1919
Platform,

0 commit comments

Comments
 (0)