Skip to content

Commit 443c1c1

Browse files
tpm: Provider Build: Store Public Key information for the Root Key
A PasswordContext with no auth_value is stored. The private part of the KeyMaterial is empty. Signed-off-by: Tomás González <[email protected]>
1 parent e0d0092 commit 443c1c1

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/providers/tpm/mod.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ use crate::providers::ProviderIdentity;
1212
use derivative::Derivative;
1313
use log::{info, trace};
1414
use parsec_interface::operations::list_providers::Uuid;
15+
use parsec_interface::operations::psa_algorithm::Algorithm;
16+
use parsec_interface::operations::psa_key_attributes::{
17+
Attributes, Lifetime, Policy, Type, UsageFlags,
18+
};
1519
use parsec_interface::operations::{
1620
attest_key, can_do_crypto, prepare_key_attestation, psa_asymmetric_decrypt,
1721
psa_asymmetric_encrypt, psa_destroy_key, psa_export_public_key, psa_generate_key,
@@ -478,6 +482,45 @@ impl ProviderBuilder {
478482
format_error!("Error when verifying the Root Key's Name", e);
479483
return Err(e);
480484
}
485+
} else {
486+
let mut esapi_context = built_provider
487+
.esapi_context
488+
.lock()
489+
.expect("ESAPI Context lock poisoned");
490+
491+
let root_key_name = esapi_context.get_root_key_name().map_err(|e| {
492+
format_error!("Error getting the the Root Key's Name", e);
493+
std::io::Error::new(
494+
ErrorKind::InvalidData,
495+
"failed getting Root Key's Name",
496+
)
497+
})?;
498+
499+
let attributes = Attributes {
500+
lifetime: Lifetime::Persistent,
501+
key_type: Type::RsaPublicKey,
502+
bits: ROOT_KEY_SIZE as usize,
503+
policy: Policy {
504+
// Internal key, usage_flags information is not relevant
505+
usage_flags: UsageFlags::default(),
506+
// Internal key, permitted_algorithms information is not relevant
507+
permitted_algorithms: Algorithm::None,
508+
},
509+
};
510+
511+
built_provider
512+
.key_info_store
513+
.insert_key_info(
514+
root_key_identity,
515+
&(root_key_name.value().to_vec()),
516+
attributes,
517+
)
518+
.map_err(|_| {
519+
std::io::Error::new(
520+
ErrorKind::InvalidData,
521+
"Failed to insert Key Info in the Key Store",
522+
)
523+
})?;
481524
}
482525

483526
Ok(built_provider)

0 commit comments

Comments
 (0)