| 1 |
package cmd |
| 2 |
|
| 3 |
import ( |
| 4 |
tabi "github.com/google/go-tdx-guest/abi" |
| 5 |
"github.com/google/go-tdx-guest/validate" |
| 6 |
tv "github.com/google/go-tdx-guest/verify" |
| 7 |
) |
| 8 |
|
| 9 |
// verifyTdxOpts allows for customizing the functionality of VerifyAttestation's TDX verification. |
| 10 |
type verifyTdxOpts struct { |
| 11 |
Validation *validate.Options |
| 12 |
Verification *tv.Options |
| 13 |
} |
| 14 |
|
| 15 |
// tdxDefaultValidateOpts returns a default validation policy for TDX attestation quote on GCE. |
| 16 |
func tdxDefaultValidateOpts(tdxNonce []byte) *validate.Options { |
| 17 |
policy := &validate.Options{HeaderOptions: validate.HeaderOptions{}, |
| 18 |
TdQuoteBodyOptions: validate.TdQuoteBodyOptions{}} |
| 19 |
policy.TdQuoteBodyOptions.ReportData = make([]byte, tabi.ReportDataSize) |
| 20 |
copy(policy.TdQuoteBodyOptions.ReportData, tdxNonce) |
| 21 |
return policy |
| 22 |
} |
| 23 |
|
| 24 |
// verifyTdxAttestation checks that the TDX attestation quote is valid. The TEE-specific attestation |
| 25 |
// quote is extracted from the Attestation protobuf. At a granular level, this quote is fetched via |
| 26 |
// go-tdx-guest's GetQuote client API. |
| 27 |
// Supported quote formats - QuoteV4. |
| 28 |
func verifyTdxAttestation(tdxAttestationQuote any, opts *verifyTdxOpts) error { |
| 29 |
// Check that the quote contains valid signature and certificates. Do not check revocations. |
| 30 |
if err := tv.TdxQuote(tdxAttestationQuote, opts.Verification); err != nil { |
| 31 |
return err |
| 32 |
} |
| 33 |
// Check that the fields of the quote are acceptable |
| 34 |
return validate.TdxQuote(tdxAttestationQuote, opts.Validation) |
| 35 |
} |