Skip to content

Commit c359787

Browse files
tommychiu-githubtimothytrippel
authored andcommitted
[manuf,rom_ext] Update the parameters of perso_tlv_cert_obj_build
When building a perso_blob, the object type was decided by whether that object needs endorsement or not. It is not feasible when not only one certificate format needs to be supported by perso_fw and ROM_EXT. To remediate that it requires the specify the object format by the caller which needs to add one more parameter. Signed-off-by: Tommy Chiu <[email protected]>
1 parent 5626516 commit c359787

File tree

6 files changed

+31
-24
lines changed

6 files changed

+31
-24
lines changed

sw/device/silicon_creator/manuf/base/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ cc_library(
276276
"//sw/device/lib/base:status",
277277
"//sw/device/lib/testing/json:provisioning_data",
278278
"//sw/device/silicon_creator/lib:error",
279+
"//sw/device/silicon_creator/lib/cert",
279280
],
280281
)
281282

sw/device/silicon_creator/manuf/base/ft_personalize.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ static status_t personalize_gen_dice_certificates(ujson_t *uj) {
476476
TRY(perso_tlv_push_cert_to_perso_blob(
477477
"UDS",
478478
/*needs_endorsement=*/kDiceCertFormat == kDiceCertFormatX509TcbInfo,
479-
all_certs, curr_cert_size, &perso_blob_to_host));
479+
kDiceCertFormat, all_certs, curr_cert_size, &perso_blob_to_host));
480480
LOG_INFO("Generated UDS certificate.");
481481

482482
// Generate CDI_0 keys and cert.
@@ -495,8 +495,8 @@ static status_t personalize_gen_dice_certificates(ujson_t *uj) {
495495
// DO NOT CHANGE THE "CDI_0" STRING BELOW with modifying the `dice_cert_names`
496496
// collection in sw/host/provisioning/ft_lib/src/lib.rs.
497497
TRY(perso_tlv_push_cert_to_perso_blob("CDI_0", /*needs_endorsement=*/false,
498-
all_certs, curr_cert_size,
499-
&perso_blob_to_host));
498+
kDiceCertFormat, all_certs,
499+
curr_cert_size, &perso_blob_to_host));
500500
LOG_INFO("Generated CDI_0 certificate.");
501501

502502
// Generate CDI_1 keys and cert.
@@ -516,8 +516,8 @@ static status_t personalize_gen_dice_certificates(ujson_t *uj) {
516516
// DO NOT CHANGE THE "CDI_1" STRING BELOW with modifying the `dice_cert_names`
517517
// collection in sw/host/provisioning/ft_lib/src/lib.rs.
518518
TRY(perso_tlv_push_cert_to_perso_blob("CDI_1", /*needs_endorsement=*/false,
519-
all_certs, curr_cert_size,
520-
&perso_blob_to_host));
519+
kDiceCertFormat, all_certs,
520+
curr_cert_size, &perso_blob_to_host));
521521
LOG_INFO("Generated CDI_1 certificate.");
522522

523523
return OK_STATUS();

sw/device/silicon_creator/manuf/base/perso_tlv_data.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ rom_error_t perso_tlv_get_cert_obj(uint8_t *buf, size_t ltv_buf_size,
8282
return kErrorOk;
8383
}
8484

85-
rom_error_t perso_tlv_cert_obj_build(const char *name, bool needs_endorsement,
85+
rom_error_t perso_tlv_cert_obj_build(const char *name,
86+
const perso_tlv_object_type_t obj_type,
8687
const uint8_t *cert, size_t cert_size,
8788
uint8_t *buf, size_t *buf_size) {
8889
perso_tlv_object_header_t obj_header = 0;
@@ -107,14 +108,7 @@ rom_error_t perso_tlv_cert_obj_build(const char *name, bool needs_endorsement,
107108
return kErrorPersoTlvOutputBufTooSmall;
108109

109110
// Setup the perso LTV object header.
110-
if (needs_endorsement) {
111-
PERSO_TLV_SET_FIELD(Objh, Type, obj_header, kPersoObjectTypeX509Tbs);
112-
} else {
113-
// TODO(lowRISC/opentitan:#24281): should decide the obj_type by other
114-
// factor
115-
// PERSO_TLV_SET_FIELD(Objh, Type, obj_header, kPersoObjectTypeX509Cert);
116-
PERSO_TLV_SET_FIELD(Objh, Type, obj_header, kPersoObjectTypeCwtCert);
117-
}
111+
PERSO_TLV_SET_FIELD(Objh, Type, obj_header, obj_type);
118112
PERSO_TLV_SET_FIELD(Objh, Size, obj_header, obj_size);
119113

120114
// Setup the cert object header.
@@ -138,11 +132,20 @@ rom_error_t perso_tlv_cert_obj_build(const char *name, bool needs_endorsement,
138132

139133
status_t perso_tlv_push_cert_to_perso_blob(const char *name,
140134
bool needs_endorsement,
135+
const dice_cert_format_t dice_format,
141136
const uint8_t *cert,
142137
size_t cert_size, perso_blob_t *pb) {
143138
// Build the perso TLV cert object and push it to the perso blob.
144139
size_t obj_size = sizeof(pb->body) - pb->next_free;
145-
TRY(perso_tlv_cert_obj_build(name, needs_endorsement, cert, cert_size,
140+
perso_tlv_object_type_t obj_type = kPersoObjectTypeCwtCert;
141+
if (dice_format == kDiceCertFormatX509TcbInfo) {
142+
if (needs_endorsement) {
143+
obj_type = kPersoObjectTypeX509Tbs;
144+
} else {
145+
obj_type = kPersoObjectTypeX509Cert;
146+
}
147+
}
148+
TRY(perso_tlv_cert_obj_build(name, obj_type, cert, cert_size,
146149
pb->body + pb->next_free, &obj_size));
147150

148151
// Update the perso blob offset and object count.

sw/device/silicon_creator/manuf/base/perso_tlv_data.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "sw/device/lib/base/status.h"
1313
#include "sw/device/lib/testing/json/provisioning_data.h"
14+
#include "sw/device/silicon_creator/lib/cert/cert.h"
1415
#include "sw/device/silicon_creator/lib/error.h"
1516

1617
/**
@@ -184,8 +185,7 @@ rom_error_t perso_tlv_get_cert_obj(uint8_t *buf, size_t ltv_buf_size,
184185
* +----------------------------------------------+
185186
*
186187
* @param name The name of the certificate.
187-
* @param needs_endorsement Defines the type of the LTV object the certificate
188-
* is wrapped into (TBS or fully formed).
188+
* @param obj_type The object type that needs to encoded.
189189
* @param cert The binary certificate blob.
190190
* @param cert_size Size of the certificate blob in bytes.
191191
* @param[out] buf Output buffer to copy the data into.
@@ -194,7 +194,8 @@ rom_error_t perso_tlv_get_cert_obj(uint8_t *buf, size_t ltv_buf_size,
194194
* @return status of the operation.
195195
*/
196196
OT_WARN_UNUSED_RESULT
197-
rom_error_t perso_tlv_cert_obj_build(const char *name, bool needs_endorsement,
197+
rom_error_t perso_tlv_cert_obj_build(const char *name,
198+
const perso_tlv_object_type_t obj_type,
198199
const uint8_t *cert, size_t cert_size,
199200
uint8_t *buf, size_t *buf_size);
200201

@@ -206,6 +207,7 @@ rom_error_t perso_tlv_cert_obj_build(const char *name, bool needs_endorsement,
206207
* @param name The name of the certificate.
207208
* @param needs_endorsement Defines the type of the LTV object the certificate
208209
* is wrapped into (TBS or fully formed).
210+
* @param cert_format The format of the certificate.
209211
* @param cert The binary certificate blob.
210212
* @param cert_size Size of the certificate blob in bytes.
211213
* @param perso_blob Pointer to the `perso_blob_t` to copy the object to.
@@ -214,6 +216,7 @@ rom_error_t perso_tlv_cert_obj_build(const char *name, bool needs_endorsement,
214216
OT_WARN_UNUSED_RESULT
215217
status_t perso_tlv_push_cert_to_perso_blob(const char *name,
216218
bool needs_endorsement,
219+
const dice_cert_format_t cert_format,
217220
const uint8_t *cert,
218221
size_t cert_size, perso_blob_t *pb);
219222

sw/device/silicon_creator/manuf/base/tpm_personalize_ext.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ static status_t personalize_gen_tpm_ek_certificate(
8080
curr_cert_size = sizeof(cert_buffer);
8181
TRY(tpm_ek_tbs_cert_build(&tpm_key_ids, &curr_pubkey, cert_buffer,
8282
&curr_cert_size));
83-
return perso_tlv_push_cert_to_perso_blob("TPM EK", /*needs_endorsement=*/true,
84-
cert_buffer, curr_cert_size,
85-
perso_blob);
83+
return perso_tlv_push_cert_to_perso_blob(
84+
"TPM EK", /*needs_endorsement=*/true, kDiceCertFormatX509TcbInfo,
85+
cert_buffer, curr_cert_size, perso_blob);
8686
}
8787

8888
status_t personalize_extension_pre_cert_endorse(

sw/device/silicon_creator/rom_ext/rom_ext.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,9 @@ static rom_error_t dice_chain_push_cert(const char *name, const uint8_t *cert,
543543

544544
// Encode the certificate to the tail buffer.
545545
size_t cert_page_left = dice_chain_get_tail_size();
546-
HARDENED_RETURN_IF_ERROR(perso_tlv_cert_obj_build(
547-
name, /*needs_endorsement=*/false, cert, cert_size,
548-
dice_chain_get_tail_buffer(), &cert_page_left));
546+
HARDENED_RETURN_IF_ERROR(
547+
perso_tlv_cert_obj_build(name, kPersoObjectTypeX509Cert, cert, cert_size,
548+
dice_chain_get_tail_buffer(), &cert_page_left));
549549

550550
// Move the offset to the new tail.
551551
HARDENED_RETURN_IF_ERROR(perso_tlv_get_cert_obj(dice_chain_get_tail_buffer(),

0 commit comments

Comments
 (0)