Skip to content

Commit c4e089b

Browse files
committed
support optionally validating PCK configuration
Signed-off-by: Markus Rudy <mr@edgeless.systems>
1 parent e664a3f commit c4e089b

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

validate/validate.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ type TdQuoteBodyOptions struct {
101101
type PCKOptions struct {
102102
// SgxType is the expected SGXType. Not checked if nil.
103103
SgxType *pcs.SGXType
104+
105+
// PCK certificate configuration items.
106+
107+
// SMTEnabled is the expected SMTEnabled status in the PCK configuration section. Not checked if nil.
108+
SMTEnabled *bool
109+
// DynamicPlatform is the expected DynamicPlatform status in the PCK configuration section. Not checked if nil.
110+
DynamicPlatform *bool
111+
// CachedKeys is the expected CachedKeys status in the PCK configuration section. Not checked if nil.
112+
CachedKeys *bool
104113
}
105114

106115
func lengthCheck(name string, length int, value []byte) error {
@@ -366,6 +375,15 @@ func validatePck(quote *pb.QuoteV4, opts *PCKOptions) error {
366375
if opts.SgxType != nil && *opts.SgxType != exts.SGXType {
367376
return fmt.Errorf("PCK extension SGXType is %d. Expect %d", *opts.SgxType, exts.SGXType)
368377
}
378+
if opts.SMTEnabled != nil && *opts.SMTEnabled != exts.Configuration.SMTEnabled {
379+
return fmt.Errorf("PCK extension SMTEnabled is %v. Expect %v", exts.Configuration.SMTEnabled, *opts.SMTEnabled)
380+
}
381+
if opts.DynamicPlatform != nil && *opts.DynamicPlatform != exts.Configuration.DynamicPlatform {
382+
return fmt.Errorf("PCK extension DynamicPlatform is %v. Expect %v", exts.Configuration.DynamicPlatform, *opts.DynamicPlatform)
383+
}
384+
if opts.CachedKeys != nil && *opts.CachedKeys != exts.Configuration.CachedKeys {
385+
return fmt.Errorf("PCK extension CachedKeys is %v. Expect %v", exts.Configuration.CachedKeys, *opts.CachedKeys)
386+
}
369387
return nil
370388
}
371389

validate/validate_test.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ func TestTdxQuote(t *testing.T) {
7575
0xeb, 0x74, 0x6, 0xa3, 0x8d, 0x1e, 0xed, 0x31, 0x3b, 0x98, 0x7a, 0x46, 0x7d, 0xac, 0xea, 0xd6,
7676
0xf0, 0xc8, 0x7a, 0x6d, 0x76, 0x6c, 0x66, 0xf6, 0xf2, 0x9f, 0x8a, 0xcb, 0x28, 0x1f, 0x11, 0x13}
7777
sgxType := pcs.SGXTypeScalable
78+
smtEnabled := true
79+
dynamicPlatform := true
80+
cachedKeys := false
7881

7982
mknonce := func(front []byte) []byte {
8083
result := make([]byte, 64)
@@ -143,7 +146,10 @@ func TestTdxQuote(t *testing.T) {
143146
EnableTdDebugCheck: true,
144147
},
145148
PCKOptions: PCKOptions{
146-
SgxType: &sgxType,
149+
SgxType: &sgxType,
150+
SMTEnabled: &smtEnabled,
151+
DynamicPlatform: &dynamicPlatform,
152+
CachedKeys: &cachedKeys,
147153
},
148154
},
149155
},
@@ -308,6 +314,30 @@ func TestTdxQuote(t *testing.T) {
308314
},
309315
wantErr: "PCK extension SGXType",
310316
},
317+
{
318+
name: "Test incorrect SMTEnabled",
319+
quote: quote12345,
320+
opts: &Options{
321+
PCKOptions: PCKOptions{SMTEnabled: toPtr(false)},
322+
},
323+
wantErr: "PCK extension SMTEnabled",
324+
},
325+
{
326+
name: "Test incorrect DynamicPlatform",
327+
quote: quote12345,
328+
opts: &Options{
329+
PCKOptions: PCKOptions{DynamicPlatform: toPtr(false)},
330+
},
331+
wantErr: "PCK extension DynamicPlatform",
332+
},
333+
{
334+
name: "Test incorrect CachedKeys",
335+
quote: quote12345,
336+
opts: &Options{
337+
PCKOptions: PCKOptions{CachedKeys: toPtr(true)},
338+
},
339+
wantErr: "PCK extension CachedKeys",
340+
},
311341
}
312342

313343
for _, tc := range tests {
@@ -317,3 +347,7 @@ func TestTdxQuote(t *testing.T) {
317347
}
318348
}
319349
}
350+
351+
func toPtr[A any](a A) *A {
352+
return &a
353+
}

0 commit comments

Comments
 (0)