Skip to content

Commit 72dc419

Browse files
committed
Add function to extract PPID from quote
1 parent 32866d7 commit 72dc419

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

verify/verify.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,19 @@ func SupportedTcbLevelsFromCollateral(quote any, options *Options) (pcs.TcbLevel
14051405
}
14061406
}
14071407

1408+
// GetPPID extracts the PPID from the PCK certificate chain in the quote.
1409+
func GetPPID(quote any) (string, error) {
1410+
chain, err := ExtractChainFromQuote(quote)
1411+
if err != nil {
1412+
return "", err
1413+
}
1414+
exts, err := pcs.PckCertificateExtensions(chain.PCKCertificate)
1415+
if err != nil {
1416+
return "", err
1417+
}
1418+
return exts.PPID, nil
1419+
}
1420+
14081421
// tdxQuoteV4 verifies the QuoteV4 protobuf representation of an attestation quote's signature
14091422
// based on the quote's SignatureAlgo, provided the certificate chain is valid.
14101423
func tdxQuoteV4(ctx context.Context, quote *pb.QuoteV4, options *Options) error {

verify/verify_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,24 @@ func TestSupportedTcbLevelsFromCollateral(t *testing.T) {
932932
})
933933
}
934934

935+
func TestGetPPID(t *testing.T) {
936+
quote, err := abi.QuoteToProto(testdata.RawQuote)
937+
if err != nil {
938+
t.Fatal(err)
939+
}
940+
ppid, err := GetPPID(quote)
941+
if err != nil {
942+
t.Fatal(err)
943+
}
944+
// The PPID is bytes 89d... which is hex encoded in pcs.PckExtensions
945+
// In TestPckCertificateExtensions, expected ppidBytes is []byte{8, 157, 223, 219, 156, 3, 89, 200, 42, 59, 199, 113, 146, 57, 87, 78}
946+
// Hex: 089ddfdb9c0359c82a3bc7719239574e
947+
wantPPID := "089ddfdb9c0359c82a3bc7719239574e"
948+
if ppid != wantPPID {
949+
t.Errorf("GetPPID() = %q, want %q", ppid, wantPPID)
950+
}
951+
}
952+
935953
var rawTdxQuoteFuncs = map[string]func([]byte, *Options) error{
936954
"RawTdxQuote": RawTdxQuote,
937955
"RawTdxQuoteContext": func(quote []byte, options *Options) error {

0 commit comments

Comments
 (0)