@@ -129,16 +129,20 @@ var (
129
129
}
130
130
)
131
131
132
- // TCBVersion represents the SEV-SNP TCB_VERSION
133
- type TCBVersion struct {
132
+ // TCBVersion is a 64-bit bitfield of different security patch levels of AMD firmware and microcode.
133
+ // Deprecated: use TCBVersionStruct instead
134
+ type TCBVersion uint64
135
+
136
+ // TCBVersionStruct represents the SEV-SNP TCB_VERSION
137
+ type TCBVersionStruct struct {
134
138
// Version identifies the version of this structure as defined in V[C,L]EK x509 certificate extensions
135
139
Version uint8
136
140
// TCB is a 64-bit bitfield of different security patch levels of AMD firmware and microcode.
137
141
TCB uint64
138
142
}
139
143
140
144
// String returns the version of the TCB in string format
141
- func (v TCBVersion ) String () string {
145
+ func (v TCBVersionStruct ) String () string {
142
146
switch v .Version {
143
147
case TCBStructVersion0 :
144
148
return fmt .Sprintf ("Milan or Genoa TCB: 0x%x" , v .TCB )
@@ -149,6 +153,14 @@ func (v TCBVersion) String() string {
149
153
}
150
154
}
151
155
156
+ func TCBVersionStructFromTCBVersion (v TCBVersion ) TCBVersionStruct {
157
+ return TCBVersionStruct {Version : TCBStructVersion0 , TCB : uint64 (v )}
158
+ }
159
+
160
+ func TCBVersionStructToTCBVersion (v TCBVersionStruct ) uint64 {
161
+ return v .TCB
162
+ }
163
+
152
164
// Extensions represents the information stored in the KDS-specified x509 extensions of a V{C,L}EK
153
165
// certificate.
154
166
type Extensions struct {
@@ -158,9 +170,11 @@ type Extensions struct {
158
170
// Primary vs secondary is irrelevant to verification. The length of this
159
171
// field depends on the TCB version; 64 bytes for version 0 and
160
172
// 8 bytes for version 1
161
- HWID []byte
162
- TCBVersion TCBVersion
163
- CspID string
173
+ HWID []byte
174
+ // Deprecated: use TCBVersionStruct instead
175
+ TCBVersion TCBVersion
176
+ TCBVersionStruct TCBVersionStruct
177
+ CspID string
164
178
}
165
179
166
180
func oidTokdsOID (id asn1.ObjectIdentifier ) (kdsOID , error ) {
@@ -250,10 +264,8 @@ type TCBParts struct {
250
264
FmcSpl uint8
251
265
}
252
266
253
- // ComposeTCBParts returns an SEV-SNP TCB_VERSION from OID mapping values. The spl4-spl7 fields are
254
- // reserved, but the KDS specification designates them as 4 byte-sized fields.
255
- func ComposeTCBParts (parts TCBParts ) (TCBVersion , error ) {
256
- tcbVersion := TCBVersion {}
267
+ func composeTCBPartsToTCBVersionStruct (parts TCBParts ) (TCBVersionStruct , error ) {
268
+ tcbVersion := TCBVersionStruct {}
257
269
// Only UcodeSpl may be 0-255. All others must be 0-127.
258
270
check127 := func (name string , value uint8 ) error {
259
271
if value > 127 {
@@ -298,9 +310,26 @@ func ComposeTCBParts(parts TCBParts) (TCBVersion, error) {
298
310
return tcbVersion , nil
299
311
}
300
312
301
- // DecomposeTCBVersion interprets the byte components of the AMD representation of the
302
- // platform security patch levels into a struct.
303
- func DecomposeTCBVersion (tcb TCBVersion ) TCBParts {
313
+ // ComposeTCBParts returns an SEV-SNP TCB_VERSION from OID mapping values. The spl4-spl7 fields are
314
+ // reserved, but the KDS specification designates them as 4 byte-sized fields.
315
+ // Deprecated: use ComposeTCBPartsToTCBVersionStruct instead
316
+ func ComposeTCBParts (parts TCBParts ) (TCBVersion , error ) {
317
+ tcb , err := composeTCBPartsToTCBVersionStruct (parts )
318
+ if err != nil {
319
+ return TCBVersion (0 ), err
320
+ }
321
+
322
+ return TCBVersion (tcb .TCB ), nil
323
+ }
324
+
325
+ // ComposeTCBPartsToTCBVersionStruct returns an SEV-SNP TCB_VERSION from OID mapping
326
+ // values as a TCBVersionStruct. The spl4-spl7 fields are reserved, but the
327
+ // KDS specification designates them as 4 byte-sized fields.
328
+ func ComposeTCBPartsToTCBVersionStruct (parts TCBParts ) (TCBVersionStruct , error ) {
329
+ return composeTCBPartsToTCBVersionStruct (parts )
330
+ }
331
+
332
+ func decomposeTCBVersionStruct (tcb TCBVersionStruct ) TCBParts {
304
333
switch tcb .Version {
305
334
case TCBStructVersion1 :
306
335
return TCBParts {
@@ -326,6 +355,34 @@ func DecomposeTCBVersion(tcb TCBVersion) TCBParts {
326
355
}
327
356
}
328
357
358
+ // DecomposeTCBVersion interprets the byte components of the AMD representation of the
359
+ // platform security patch levels into a struct.
360
+ // Deprecated: use DecomposeTCBVersionStruct instead
361
+ func DecomposeTCBVersion (tcb TCBVersion ) TCBParts {
362
+ parts , _ := DecomposeTCBVersionStruct (tcb )
363
+ return parts
364
+ }
365
+
366
+ // DecomposeTCBVersionStruct accepts SEV-SNP TCB version as TCBVersion,
367
+ // TCBVersionStruct or uint64 and decodes various security patch
368
+ // levels from them.
369
+ func DecomposeTCBVersionStruct (t interface {}) (TCBParts , error ) {
370
+ var tcb TCBVersionStruct
371
+
372
+ switch v := t .(type ) {
373
+ case TCBVersionStruct :
374
+ tcb = v
375
+ case TCBVersion :
376
+ tcb = TCBVersionStructFromTCBVersion (v )
377
+ case uint64 :
378
+ tcb = TCBVersionStruct {Version : TCBStructVersion0 , TCB : v }
379
+ default :
380
+ return TCBParts {}, fmt .Errorf ("unsupported TCB type: %v" , t )
381
+ }
382
+
383
+ return decomposeTCBVersionStruct (tcb ), nil
384
+ }
385
+
329
386
// TCBPartsLE returns true iff all TCB components of tcb0 are <= the corresponding tcb1 components.
330
387
func TCBPartsLE (tcb0 , tcb1 TCBParts ) bool {
331
388
return (tcb0 .UcodeSpl <= tcb1 .UcodeSpl ) &&
@@ -473,7 +530,7 @@ func kdsOidMapToExtensions(exts map[kdsOID]*pkix.Extension) (*Extensions, error)
473
530
}
474
531
}
475
532
476
- tcb , err := ComposeTCBParts (TCBParts {
533
+ tcb , err := ComposeTCBPartsToTCBVersionStruct (TCBParts {
477
534
Version : result .StructVersion ,
478
535
BlSpl : blspl ,
479
536
SnpSpl : snpspl ,
@@ -488,7 +545,8 @@ func kdsOidMapToExtensions(exts map[kdsOID]*pkix.Extension) (*Extensions, error)
488
545
if err != nil {
489
546
return nil , err
490
547
}
491
- result .TCBVersion = tcb
548
+ result .TCBVersion = TCBVersion (tcb .TCB )
549
+ result .TCBVersionStruct = tcb
492
550
return & result , nil
493
551
}
494
552
@@ -603,10 +661,14 @@ func ProductCertChainURL(s abi.ReportSigner, productLine string) string {
603
661
return fmt .Sprintf ("%s/cert_chain" , productBaseURL (s , productLine ))
604
662
}
605
663
606
- // VCEKCertURL returns the AMD KDS URL for retrieving the VCEK on a given product
664
+ // VCEKCertQuery returns the AMD KDS URL for retrieving the VCEK on a given product
607
665
// at a given TCB version. The hwid is the CHIP_ID field in an attestation report.
608
- func VCEKCertURL (productLine string , hwid []byte , tcb TCBVersion ) string {
609
- parts := DecomposeTCBVersion (tcb )
666
+ func VCEKCertQuery (productLine string , hwid []byte , tcb TCBVersionStruct ) (string , error ) {
667
+ parts , err := DecomposeTCBVersionStruct (tcb )
668
+ if err != nil {
669
+ return "" , err
670
+ }
671
+
610
672
switch parts .Version {
611
673
case TCBStructVersion1 :
612
674
hwidv1 := hwid [0 :TCBHwIDLenVersion1 ]
@@ -618,7 +680,7 @@ func VCEKCertURL(productLine string, hwid []byte, tcb TCBVersion) string {
618
680
parts .SnpSpl ,
619
681
parts .UcodeSpl ,
620
682
parts .FmcSpl ,
621
- )
683
+ ), nil
622
684
default :
623
685
return fmt .Sprintf ("%s/%s?blSPL=%d&teeSPL=%d&snpSPL=%d&ucodeSPL=%d" ,
624
686
productBaseURL (abi .VcekReportSigner , productLine ),
@@ -627,14 +689,26 @@ func VCEKCertURL(productLine string, hwid []byte, tcb TCBVersion) string {
627
689
parts .TeeSpl ,
628
690
parts .SnpSpl ,
629
691
parts .UcodeSpl ,
630
- )
692
+ ), nil
631
693
}
632
694
}
633
695
634
- // VLEKCertURL returns the GET URL for retrieving a VLEK certificate, but without the necessary
696
+ // VCEKCertURL returns the AMD KDS URL for retrieving the VCEK on a given product
697
+ // at a given TCB version. The hwid is the CHIP_ID field in an attestation report.
698
+ // Deprecated: use VCEKCertQuery instead
699
+ func VCEKCertURL (productLine string , hwid []byte , tcb TCBVersion ) string {
700
+ url , _ := VCEKCertQuery (productLine , hwid , TCBVersionStructFromTCBVersion (tcb ))
701
+ return url
702
+ }
703
+
704
+ // VLEKCertQuery returns the GET URL for retrieving a VLEK certificate, but without the necessary
635
705
// CSP secret in the HTTP headers that makes the request validate to the KDS.
636
- func VLEKCertURL (productLine string , tcb TCBVersion ) string {
637
- parts := DecomposeTCBVersion (tcb )
706
+ func VLEKCertQuery (productLine string , tcb TCBVersionStruct ) (string , error ) {
707
+ parts , err := DecomposeTCBVersionStruct (tcb )
708
+ if err != nil {
709
+ return "" , err
710
+ }
711
+
638
712
switch parts .Version {
639
713
case TCBStructVersion1 :
640
714
return fmt .Sprintf ("%s/cert?blSPL=%d&teeSPL=%d&snpSPL=%d&ucodeSPL=%d&fmcSPL=%d" ,
@@ -644,18 +718,26 @@ func VLEKCertURL(productLine string, tcb TCBVersion) string {
644
718
parts .SnpSpl ,
645
719
parts .UcodeSpl ,
646
720
parts .FmcSpl ,
647
- )
721
+ ), nil
648
722
default :
649
723
return fmt .Sprintf ("%s/cert?blSPL=%d&teeSPL=%d&snpSPL=%d&ucodeSPL=%d" ,
650
724
productBaseURL (abi .VlekReportSigner , productLine ),
651
725
parts .BlSpl ,
652
726
parts .TeeSpl ,
653
727
parts .SnpSpl ,
654
728
parts .UcodeSpl ,
655
- )
729
+ ), nil
656
730
}
657
731
}
658
732
733
+ // VLEKCertURL returns the GET URL for retrieving a VLEK certificate, but without the necessary
734
+ // CSP secret in the HTTP headers that makes the request validate to the KDS.
735
+ // Deprecated: use VLEKCertQuery instead
736
+ func VLEKCertURL (productLine string , tcb TCBVersion ) string {
737
+ url , _ := VLEKCertQuery (productLine , TCBVersionStructFromTCBVersion (tcb ))
738
+ return url
739
+ }
740
+
659
741
// VCEKCert represents the attestation report components represented in a KDS VCEK certificate
660
742
// request URL.
661
743
type VCEKCert struct {
@@ -788,7 +870,7 @@ func parseTCBURL(u *url.URL, tcbVersion uint8) (uint64, error) {
788
870
setter (uint8 (number ))
789
871
}
790
872
}
791
- tcb , err := ComposeTCBParts (parts )
873
+ tcb , err := ComposeTCBPartsToTCBVersionStruct (parts )
792
874
if err != nil {
793
875
return 0 , fmt .Errorf ("invalid AMD KDS TCB arguments: %v" , err )
794
876
}
0 commit comments