Skip to content

Commit 24f56e8

Browse files
committed
[spm] Introduce UDS/EXT aliases for certificate key labels
This change introduces shorter, more stable aliases for certificate key labels used in the provisioning process. The aliases "UDS" (Unique Device Secret) and "EXT" (External) are now used by client applications. The SPM service is responsible for mapping these aliases to the underlying key labels ("SigningKey/Dice/v0" and "SigningKey/Ext/v0"). This provides a layer of abstraction, making the client-side implementation cleaner and less coupled to the internal naming scheme. Key changes: - `spm`: Translates "UDS" and "EXT" labels to their full counterparts during key retrieval and certificate endorsement. It now gracefully handles missing certificates by returning an empty subject key. - `ate`: The client library now accepts the key label directly from the caller instead of hardcoding a mapping. - `pa/loadtest`, `ate/test_programs/ft`: Updated to use the new "UDS" and "EXT" aliases. Signed-off-by: Miguel Osorio <miguelosorio@google.com>
1 parent 41c4ad5 commit 24f56e8

File tree

5 files changed

+55
-25
lines changed

5 files changed

+55
-25
lines changed

src/ate/ate_dll.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,7 @@ DLLEXPORT int EndorseCerts(ate_client_ptr client, const char *sku,
515515
return static_cast<int>(absl::StatusCode::kInvalidArgument);
516516
}
517517
std::string cert_label(req_params.key_label, req_params.key_label_size);
518-
if (cert_label == "UDS") {
519-
signing_params->set_key_label("SigningKey/Dice/v0");
520-
} else {
521-
signing_params->set_key_label("SigningKey/Ext/v0");
522-
}
518+
signing_params->set_key_label(cert_label);
523519

524520
// Only ECDSA keys are supported at this time.
525521
auto key = signing_params->mutable_ecdsa_params();

src/ate/test_programs/ft.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,18 +239,21 @@ int main(int argc, char **argv) {
239239
}
240240

241241
// Generate CA subject keys.
242-
constexpr size_t kNumIcas = 1;
243-
const char *kIcaCertLabels[] = {"SigningKey/Dice/v0"};
242+
constexpr size_t kNumIcas = 2;
243+
const char *kIcaCertLabels[] = {
244+
"UDS",
245+
"EXT",
246+
};
244247
ca_subject_key_t key_ids[kNumIcas];
245248
if (GetCaSubjectKeys(ate_client, absl::GetFlag(FLAGS_sku).c_str(),
246249
/*count=*/kNumIcas, kIcaCertLabels, key_ids) != 0) {
247250
LOG(ERROR) << "GetCaSubjectKeys failed.";
248251
return -1;
249252
}
250253
const ca_subject_key_t *kDiceCaSk = &key_ids[0];
251-
const ca_subject_key_t kExtCaSk = {0};
254+
const ca_subject_key_t *kExtCaSk = &key_ids[1];
252255
dut_spi_frame_t ca_key_ids_spi_frame;
253-
if (CaSubjectKeysToJson(kDiceCaSk, &kExtCaSk, &ca_key_ids_spi_frame) != 0) {
256+
if (CaSubjectKeysToJson(kDiceCaSk, kExtCaSk, &ca_key_ids_spi_frame) != 0) {
254257
LOG(ERROR) << "CaSubjectKeysToJson failed.";
255258
return -1;
256259
}

src/pa/loadtest.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func testOTGetCaSubjectKeys(ctx context.Context, numCalls int, skuName string, c
185185

186186
request := &pbp.GetCaSubjectKeysRequest{
187187
Sku: skuName,
188-
CertLabels: []string{"SigningKey/Dice/v0"},
188+
CertLabels: []string{"UDS"},
189189
}
190190

191191
// Send request to PA.
@@ -214,7 +214,7 @@ func testOTEndorseCerts(ctx context.Context, numCalls int, skuName string, c *cl
214214
Bundles: []*pbp.EndorseCertBundle{
215215
{
216216
KeyParams: &pbc.SigningKeyParams{
217-
KeyLabel: "SigningKey/Dice/v0",
217+
KeyLabel: "UDS",
218218
Key: &pbc.SigningKeyParams_EcdsaParams{
219219
EcdsaParams: &pbe.EcdsaParams{
220220
HashType: pbcommon.HashType_HASH_TYPE_SHA256,
@@ -425,7 +425,7 @@ func main() {
425425
ConfigDir: *configDir,
426426
HSMSOLibPath: *hsmSOLibPath,
427427
}
428-
certLabels := []string{"SigningKey/Dice/v0"}
428+
certLabels := []string{"UDS"}
429429
tbsCerts, _, err := tbsgen.BuildTestTBSCerts(opts, skuName, certLabels)
430430
if err != nil {
431431
log.Fatalf("failed to generate TBS certificates for SKU %q: %v", skuName, err)
@@ -446,7 +446,7 @@ func main() {
446446
},
447447
{
448448
testName: "OT:EndorseCerts",
449-
testFunc: NewEndorseCertTest(tbsCerts["SigningKey/Dice/v0"]),
449+
testFunc: NewEndorseCertTest(tbsCerts["UDS"]),
450450
},
451451
{
452452
testName: "OT:RegisterDevice",

src/spm/services/spm.go

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ type server struct {
6666
}
6767

6868
const (
69-
EKCertSerialNumberSize int = 10
70-
TokenSize int = 16
71-
BigEndian bool = true
72-
LittleEndian bool = false
69+
SubjectKeySize int = 10
70+
TokenSize int = 16
71+
BigEndian bool = true
72+
LittleEndian bool = false
7373
)
7474

7575
func generateSessionToken(n int) (string, error) {
@@ -298,10 +298,21 @@ func (s *server) GetCaSubjectKeys(ctx context.Context, request *pbp.GetCaSubject
298298
// Extract the subject key from each certificate.
299299
var subjectKeys [][]byte
300300
for _, label := range request.CertLabels {
301-
cert, ok := sku.Certs[label]
301+
var kl string
302+
if label == "UDS" {
303+
kl = "SigningKey/Dice/v0"
304+
} else {
305+
kl = "SigningKey/Ext/v0"
306+
}
307+
308+
cert, ok := sku.Certs[kl]
302309
if !ok {
303-
return nil, status.Errorf(codes.Internal, "unable to find cert %q in SKU configuration", label)
310+
emptySK := make([]byte, SubjectKeySize)
311+
log.Printf("SPM.GetCaSubjectKeys - unable to find cert %q in SKU configuration", kl)
312+
subjectKeys = append(subjectKeys, emptySK)
313+
continue
304314
}
315+
305316
subjectKeys = append(subjectKeys, cert.SubjectKeyId)
306317
}
307318

@@ -363,12 +374,26 @@ func (s *server) EndorseCerts(ctx context.Context, request *pbp.EndorseCertsRequ
363374

364375
var certs []*pbp.CertBundle
365376
for _, bundle := range request.Bundles {
366-
keyLabel, err := sku.Config.GetUnsafeAttribute(bundle.KeyParams.KeyLabel)
377+
if bundle.KeyParams == nil {
378+
return nil, status.Errorf(codes.InvalidArgument, "missing key params")
379+
}
380+
if bundle.Tbs == nil {
381+
return nil, status.Errorf(codes.InvalidArgument, "missing tbs data")
382+
}
383+
384+
var kl string
385+
if bundle.KeyParams.KeyLabel == "UDS" {
386+
kl = "SigningKey/Dice/v0"
387+
} else {
388+
kl = "SigningKey/Ext/v0"
389+
}
390+
391+
keyLabel, err := sku.Config.GetUnsafeAttribute(kl)
367392
if err != nil {
368-
return nil, status.Errorf(codes.Internal, "unable to find key label %q in SKU configuration: %v", bundle.KeyParams.KeyLabel, err)
393+
return nil, status.Errorf(codes.Internal, "unable to find key label %q in SKU configuration: %v", kl, err)
369394
}
370395

371-
caCert, ok := sku.Certs[bundle.KeyParams.KeyLabel]
396+
caCert, ok := sku.Certs[kl]
372397
if !ok {
373398
return nil, status.Errorf(codes.Internal, "unable to find cert %q in SKU configuration", bundle.KeyParams.KeyLabel)
374399
}

src/spm/services/testutils/tbsgen.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,13 @@ func BuildTestTBSCerts(opts skumgr.Options, skuName string, certLabels []string)
110110

111111
tbsCerts := make(map[string][]byte)
112112
pubKeys := make(map[string]crypto.PublicKey)
113-
for _, label := range certLabels {
113+
for _, kl := range certLabels {
114+
var label string
115+
if kl == "UDS" {
116+
label = "SigningKey/Dice/v0"
117+
} else {
118+
label = "SigningKey/Ext/v0"
119+
}
114120
issuerCert, ok := sku.Certs[label]
115121
if !ok {
116122
return nil, nil, fmt.Errorf("issuer certificate %q not found for SKU %q", label, skuName)
@@ -125,8 +131,8 @@ func BuildTestTBSCerts(opts skumgr.Options, skuName string, certLabels []string)
125131
if err != nil {
126132
return err
127133
}
128-
tbsCerts[label] = tbs
129-
pubKeys[label] = pub
134+
tbsCerts[kl] = tbs
135+
pubKeys[kl] = pub
130136
return nil
131137
}); err != nil {
132138
return nil, nil, fmt.Errorf("failed to generate TBS certificate: %w", err)

0 commit comments

Comments
 (0)