-
Notifications
You must be signed in to change notification settings - Fork 32
support optionally validating SGXType #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Freax13
wants to merge
4
commits into
google:main
Choose a base branch
from
Freax13:feature/sgx-type
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -17,11 +17,15 @@ package validate | |||||
|
|
||||||
| import ( | ||||||
| "bytes" | ||||||
| "crypto/x509" | ||||||
| "encoding/binary" | ||||||
| "encoding/hex" | ||||||
| "encoding/pem" | ||||||
| "errors" | ||||||
| "fmt" | ||||||
|
|
||||||
| "github.com/google/go-tdx-guest/abi" | ||||||
| "github.com/google/go-tdx-guest/pcs" | ||||||
| ccpb "github.com/google/go-tdx-guest/proto/checkconfig" | ||||||
| pb "github.com/google/go-tdx-guest/proto/tdx" | ||||||
| vr "github.com/google/go-tdx-guest/verify" | ||||||
|
|
@@ -50,6 +54,7 @@ const ( | |||||
| type Options struct { | ||||||
| HeaderOptions HeaderOptions | ||||||
| TdQuoteBodyOptions TdQuoteBodyOptions | ||||||
| PCKOptions PCKOptions | ||||||
| } | ||||||
|
|
||||||
| // HeaderOptions represents validation options for a TDX attestation Quote Header. | ||||||
|
|
@@ -88,6 +93,12 @@ type TdQuoteBodyOptions struct { | |||||
| AnyMrTd [][]byte | ||||||
| } | ||||||
|
|
||||||
| // PCKOptions represents validation options for the PCK certificate in side a TDX attestation. | ||||||
| type PCKOptions struct { | ||||||
| // SgxType is the expected SGXType. Not checked if nil. | ||||||
| SgxType *pcs.SGXType | ||||||
| } | ||||||
|
|
||||||
| func lengthCheck(name string, length int, value []byte) error { | ||||||
| if value != nil && len(value) != length { | ||||||
| return fmt.Errorf("option %q length is %d. Want %d", name, len(value), length) | ||||||
|
|
@@ -163,6 +174,10 @@ func PolicyToOptions(policy *ccpb.Policy) (*Options, error) { | |||||
| AnyMrTd: policy.GetTdQuoteBodyPolicy().GetAnyMrTd(), | ||||||
| }, | ||||||
| } | ||||||
| if policy.PckPolicy != nil && policy.PckPolicy.SgxType != nil { | ||||||
| value := pcs.SGXType(*policy.PckPolicy.SgxType) | ||||||
| opts.PCKOptions.SgxType = &value | ||||||
| } | ||||||
| if err := checkOptionsLengths(opts); err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
|
|
@@ -315,6 +330,32 @@ func validateTdAttributes(value []byte, fixed1, fixed0 uint64) error { | |||||
| return nil | ||||||
| } | ||||||
|
|
||||||
| func validatePck(quote *pb.QuoteV4, opts *PCKOptions) error { | ||||||
| // Extract the PCK | ||||||
| certChainBytes := quote.GetSignedData().GetCertificationData().GetQeReportCertificationData().GetPckCertificateChainData().GetPckCertChain() | ||||||
| if certChainBytes == nil { | ||||||
| return errors.New("PCK certificate chain is empty") | ||||||
| } | ||||||
| pck, rem := pem.Decode(certChainBytes) | ||||||
| if pck == nil || len(rem) == 0 || pck.Type != "CERTIFICATE" { | ||||||
| return errors.New("incomplete PCK Certificate chain found, should contain 3 concatenated PEM-formatted 'CERTIFICATE'-type block (PCK Leaf Cert||Intermediate CA Cert||Root CA Cert)") | ||||||
| } | ||||||
| pckCert, err := x509.ParseCertificate(pck.Bytes) | ||||||
| if err != nil { | ||||||
| return fmt.Errorf("could not interpret PCK leaf certificate DER bytes: %v", err) | ||||||
| } | ||||||
|
|
||||||
| // Validate the PCK. | ||||||
| exts, err := pcs.PckCertificateExtensions(pckCert) | ||||||
| if err != nil { | ||||||
| return fmt.Errorf("could not get PCK certificate extensions: %v", err) | ||||||
| } | ||||||
| if opts.SgxType != nil && *opts.SgxType != exts.SGXType { | ||||||
| return fmt.Errorf("PCK extension SGXType is %d. Expect %d", *opts.SgxType, exts.SGXType) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
| return nil | ||||||
| } | ||||||
|
|
||||||
| // TdxQuote validates fields of the protobuf representation of an attestation Quote | ||||||
| // against expectations depending on supported quote formats - QuoteV4. | ||||||
| // Does not check the attestation certificates or signature. | ||||||
|
|
@@ -342,6 +383,7 @@ func tdxQuoteV4(quote *pb.QuoteV4, options *Options) error { | |||||
| minVersionCheck(quote, options), | ||||||
| validateXfam(quote.GetTdQuoteBody().GetXfam(), xfamFixed1, xfamFixed0), | ||||||
| validateTdAttributes(quote.GetTdQuoteBody().GetTdAttributes(), tdAttributesFixed1, tdAttributesFixed0), | ||||||
| validatePck(quote, &options.PCKOptions), | ||||||
| ) | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite familiar with the "SGXType" concept. Is it something Intel defined? Can you provide a link to it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is a concept by Intel. The values are defined in Intel® SGX PCK Certificate and Certificate Revocation List Profile Specification 1.5, 1.3.5 Intel® SGX PCK Certificate, SGX Type:
The difference between
SGXTypeScalableandSGXTypeScalableWithIntegrityis explained in the Intel® Trust Domain Extensions white paper, 02. Intel TDX – Technical Explanation:and Intel® Trust Domain Extensions white paper, 02. Intel TDX – Technical Explanation, E. REMOTE ATTESTATION:
I wasn't able to find any docs that directly state that the SGX type is the field recording this platform configuration difference, but I was able to confirm this experimentally by generating two quotes, one on a platform with logical integrity and one on a platform with cryptographic integrity, and comparing the values.