@@ -107,13 +107,15 @@ static cert_key_id_pair_t cdi_1_key_ids = {
107107 .cert = & cdi_1_pubkey_id ,
108108};
109109static ecdsa_p256_public_key_t curr_pubkey = {.x = {0 }, .y = {0 }};
110+ static ecdsa_p256_public_key_t uds_pubkey = {.x = {0 }, .y = {0 }};
110111static perso_blob_t perso_blob_to_host ; // Perso data device => host.
111112static perso_blob_t perso_blob_from_host ; // Perso data host => device.
112113
113114/**
114115 * Certificates flash info page layout.
115116 */
116117static uint8_t all_certs [8192 ];
118+ static size_t uds_offset ;
117119static size_t cdi_0_offset ;
118120static size_t cdi_1_offset ;
119121static cert_flash_info_layout_t cert_flash_layout [] = {
@@ -367,6 +369,7 @@ static status_t hash_certificate(const flash_ctrl_info_page_t *page,
367369 if (size ) {
368370 * size = obj_size ;
369371 }
372+
370373 return OK_STATUS ();
371374}
372375
@@ -456,6 +459,7 @@ static status_t personalize_gen_dice_certificates(ujson_t *uj) {
456459 curr_cert_size = kUdsMaxTbsSizeBytes ;
457460 TRY (otbn_boot_cert_ecc_p256_keygen (kDiceKeyUds , & uds_pubkey_id ,
458461 & curr_pubkey ));
462+ memcpy (& uds_pubkey , & curr_pubkey , sizeof (ecdsa_p256_public_key_t ));
459463 TRY (otbn_boot_attestation_key_save (kDiceKeyUds .keygen_seed_idx ,
460464 kDiceKeyUds .type ,
461465 * kDiceKeyUds .keymgr_diversifier ));
@@ -468,9 +472,11 @@ static status_t personalize_gen_dice_certificates(ujson_t *uj) {
468472 all_certs , & curr_cert_size ));
469473 // DO NOT CHANGE THE "UDS" STRING BELOW with modifying the `dice_cert_names`
470474 // collection in sw/host/provisioning/ft_lib/src/lib.rs.
471- TRY (perso_tlv_push_cert_to_perso_blob ("UDS" , /*needs_endorsement=*/ true,
472- all_certs , curr_cert_size ,
473- & perso_blob_to_host ));
475+ uds_offset = perso_blob_to_host .next_free ;
476+ TRY (perso_tlv_push_cert_to_perso_blob (
477+ "UDS" ,
478+ /*needs_endorsement=*/ kDiceCertFormat == kDiceCertFormatX509TcbInfo ,
479+ all_certs , curr_cert_size , & perso_blob_to_host ));
474480 LOG_INFO ("Generated UDS certificate." );
475481
476482 // Generate CDI_0 keys and cert.
@@ -628,14 +634,24 @@ static status_t personalize_endorse_certificates(ujson_t *uj) {
628634 // LTV object.
629635 perso_tlv_cert_obj_t block ;
630636
631- // Exract the UDS cert perso LTV object.
632- TRY (extract_next_cert (& next_cert , & free_room ));
633-
634- // Extract the two CDI cert perso LTV objects which were endorsed on-device
635- // and sent to the host.
636- size_t cdi_offsets [] = {cdi_0_offset , cdi_1_offset };
637- for (size_t i = 0 ; i < ARRAYSIZE (cdi_offsets ); i ++ ) {
638- size_t offset = cdi_offsets [i ];
637+ // CWT DICE doesn't need host to endorse any certificate for it, so all
638+ // payload are in the "perso_blob_to_host".
639+ // Default to this setting, and move to X509 setting if the flag is set.
640+ size_t cert_offsets [3 ] = {uds_offset , cdi_0_offset , cdi_1_offset };
641+ size_t cert_offsets_count = 3 ;
642+ if (kDiceCertFormat == kDiceCertFormatX509TcbInfo ) {
643+ // Exract the UDS cert perso LTV object.
644+ TRY (extract_next_cert (& next_cert , & free_room ));
645+ // Extract the two CDI cert perso LTV objects which were endorsed on-device
646+ // and sent to the host.
647+ cert_offsets [0 ] = cert_offsets [1 ];
648+ cert_offsets [1 ] = cert_offsets [2 ];
649+ cert_offsets_count = 2 ;
650+ }
651+ // Extract the cert perso LTV objects which were endorsed on-device and send
652+ // to the host.
653+ for (size_t i = 0 ; i < cert_offsets_count ; i ++ ) {
654+ size_t offset = cert_offsets [i ];
639655 TRY (perso_tlv_get_cert_obj (perso_blob_to_host .body + offset ,
640656 sizeof (perso_blob_to_host .body ) - offset ,
641657 & block ));
@@ -782,7 +798,15 @@ bool test_main(void) {
782798 .certgen_inputs = & certgen_inputs ,
783799 .perso_blob_to_host = & perso_blob_to_host ,
784800 .cert_flash_layout = cert_flash_layout ,
785- .flash_ctrl_handle = & flash_ctrl_state };
801+ .flash_ctrl_handle = & flash_ctrl_state ,
802+ .uds_pubkey = & uds_pubkey ,
803+ .uds_pubkey_id = & uds_pubkey_id ,
804+ .otp_creator_sw_cfg_measurement = & otp_creator_sw_cfg_measurement ,
805+ .otp_owner_sw_cfg_measurement = & otp_owner_sw_cfg_measurement ,
806+ .otp_rot_creator_auth_codesign_measurement =
807+ & otp_rot_creator_auth_codesign_measurement ,
808+ .otp_rot_creator_auth_state_measurement =
809+ & otp_rot_creator_auth_state_measurement };
786810 CHECK_STATUS_OK (personalize_extension_pre_cert_endorse (& pre_endorse ));
787811
788812 CHECK_STATUS_OK (personalize_endorse_certificates (& uj ));
0 commit comments