@@ -78,9 +78,9 @@ use tokio::{
7878} ;
7979use tss_esapi:: {
8080 handles:: KeyHandle ,
81- interface_types:: algorithm:: AsymmetricAlgorithm ,
81+ interface_types:: algorithm:: { AsymmetricAlgorithm , HashingAlgorithm } ,
8282 interface_types:: resource_handles:: Hierarchy ,
83- structures:: { Auth , PublicBuffer } ,
83+ structures:: { Auth , Data , Digest , MaxBuffer , PublicBuffer } ,
8484 traits:: Marshall ,
8585 Context ,
8686} ;
@@ -278,6 +278,24 @@ async fn main() -> Result<()> {
278278 config. agent . tpm_signing_alg . as_ref ( ) ,
279279 ) ?;
280280
281+ let ( asym_alg, name_alg) = tpm:: get_idevid_template (
282+ config. agent . iak_idevid_template . as_str ( ) ,
283+ config. agent . iak_idevid_asymmetric_alg . as_str ( ) ,
284+ config. agent . iak_idevid_name_alg . as_str ( ) ,
285+ ) ?;
286+
287+ let ( iak, idevid) = if config. agent . enable_iak_idevid {
288+ let idevid = ctx. create_idevid ( asym_alg, name_alg) ?;
289+ info ! ( "IDevID created." ) ;
290+ // Flush after creating to make room for AK and EK and IAK
291+ ctx. as_mut ( ) . flush_context ( idevid. handle . into ( ) ) ?;
292+ let iak = ctx. create_iak ( asym_alg, name_alg) ?;
293+ info ! ( "IAK created." ) ;
294+ ( Some ( iak) , Some ( idevid) )
295+ } else {
296+ ( None , None )
297+ } ;
298+
281299 // Gather EK values and certs
282300 let ek_result = match config. agent . ek_handle . as_ref ( ) {
283301 "" => ctx. create_ek ( tpm_encryption_alg, None ) ?,
@@ -385,6 +403,26 @@ async fn main() -> Result<()> {
385403
386404 info ! ( "Agent UUID: {}" , agent_uuid) ;
387405
406+ let ( attest, signature) = if config. agent . enable_iak_idevid {
407+ let qualifying_data = config. agent . uuid . as_bytes ( ) ;
408+ let ( attest, signature) = ctx. certify_credential_with_iak (
409+ Data :: try_from ( qualifying_data) . unwrap ( ) , //#[allow_ci]
410+ ak_handle,
411+ iak. as_ref ( ) . unwrap ( ) . handle , //#[allow_ci]
412+ ) ?;
413+ info ! ( "AK certified with IAK." ) ;
414+
415+ // // For debugging certify(), the following checks the generated signature
416+ // let max_b = MaxBuffer::try_from(attest.clone().marshall()?)?;
417+ // let (hashed_attest, _) = ctx.inner.hash(max_b, HashingAlgorithm::Sha256, Hierarchy::Endorsement,)?;
418+ // println!("{:?}", hashed_attest);
419+ // println!("{:?}", signature);
420+ // println!("{:?}", ctx.inner.verify_signature(iak.as_ref().unwrap().handle, hashed_attest, signature.clone())?); //#[allow_ci]
421+ ( Some ( attest) , Some ( signature) )
422+ } else {
423+ ( None , None )
424+ } ;
425+
388426 // Generate key pair for secure transmission of u, v keys. The u, v
389427 // keys are two halves of the key used to decrypt the workload after
390428 // the Identity and Integrity Quotes sent by the agent are validated
@@ -497,18 +535,60 @@ async fn main() -> Result<()> {
497535
498536 {
499537 // Request keyblob material
500- let keyblob = registrar_agent:: do_register_agent (
501- config. agent . registrar_ip . as_ref ( ) ,
502- config. agent . registrar_port ,
503- & agent_uuid,
504- & PublicBuffer :: try_from ( ek_result. public . clone ( ) ) ?. marshall ( ) ?,
505- ek_result. ek_cert ,
506- & PublicBuffer :: try_from ( ak. public ) ?. marshall ( ) ?,
507- mtls_cert,
508- config. agent . contact_ip . as_ref ( ) ,
509- config. agent . contact_port ,
510- )
511- . await ?;
538+ let keyblob = if config. agent . enable_iak_idevid {
539+ let ( Some ( iak) , Some ( idevid) , Some ( attest) , Some ( signature) ) =
540+ ( iak, idevid, attest, signature)
541+ else {
542+ error ! (
543+ "IDevID and IAK are enabled but could not be generated"
544+ ) ;
545+ return Err ( Error :: Configuration (
546+ "IDevID and IAK are enabled but could not be generated"
547+ . to_string ( ) ,
548+ ) ) ;
549+ } ;
550+ registrar_agent:: do_register_agent (
551+ config. agent . registrar_ip . as_ref ( ) ,
552+ config. agent . registrar_port ,
553+ & agent_uuid,
554+ & PublicBuffer :: try_from ( ek_result. public . clone ( ) ) ?
555+ . marshall ( ) ?,
556+ ek_result. ek_cert ,
557+ & PublicBuffer :: try_from ( ak. public ) ?. marshall ( ) ?,
558+ Some (
559+ & PublicBuffer :: try_from ( iak. public . clone ( ) ) ?
560+ . marshall ( ) ?,
561+ ) ,
562+ Some (
563+ & PublicBuffer :: try_from ( idevid. public . clone ( ) ) ?
564+ . marshall ( ) ?,
565+ ) ,
566+ Some ( attest. marshall ( ) ?) ,
567+ Some ( signature. marshall ( ) ?) ,
568+ mtls_cert,
569+ config. agent . contact_ip . as_ref ( ) ,
570+ config. agent . contact_port ,
571+ )
572+ . await ?
573+ } else {
574+ registrar_agent:: do_register_agent (
575+ config. agent . registrar_ip . as_ref ( ) ,
576+ config. agent . registrar_port ,
577+ & agent_uuid,
578+ & PublicBuffer :: try_from ( ek_result. public . clone ( ) ) ?
579+ . marshall ( ) ?,
580+ ek_result. ek_cert ,
581+ & PublicBuffer :: try_from ( ak. public ) ?. marshall ( ) ?,
582+ None ,
583+ None ,
584+ None ,
585+ None ,
586+ mtls_cert,
587+ config. agent . contact_ip . as_ref ( ) ,
588+ config. agent . contact_port ,
589+ )
590+ . await ?
591+ } ;
512592
513593 info ! ( "SUCCESS: Agent {} registered" , & agent_uuid) ;
514594
0 commit comments