attestation.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // Package attestation holds the results of verified remote attestation
  2. // evidence, shared by the verifiers in its subpackages and by the code that
  3. // stores them, sends them to webhooks and gives them to certificate templates.
  4. //
  5. // The verifiers return what the evidence binds, for example the report data of
  6. // a TDX quote or the nonces of an attestation token, and leave the binding rule
  7. // to their callers, since each protocol binds evidence differently.
  8. //
  9. // This package has no dependencies outside the standard library, so packages
  10. // that only describe results, such as webhook, can import it without pulling in
  11. // the verifiers' dependencies.
  12. package attestation
  13. import (
  14. "errors"
  15. "fmt"
  16. )
  17. // Format is the format of attestation evidence.
  18. type Format string
  19. const (
  20. // FormatTDX is an Intel TDX quote.
  21. FormatTDX Format = "tdx"
  22. // FormatSEVSNP is an AMD SEV-SNP attestation report.
  23. FormatSEVSNP Format = "sev-snp"
  24. // FormatConfidentialSpace is a Google Cloud Attestation token for a
  25. // Confidential Space workload.
  26. FormatConfidentialSpace Format = "confidential-space"
  27. )
  28. // Validate returns an error if the format is not supported.
  29. func (f Format) Validate() error {
  30. switch f {
  31. case FormatTDX, FormatSEVSNP, FormatConfidentialSpace:
  32. return nil
  33. default:
  34. return fmt.Errorf("attestation format %q is not supported", f)
  35. }
  36. }
  37. // Result is verified attestation evidence. Binary values are hex encoded.
  38. // Exactly one of TDX, SEVSNP and ConfidentialSpace is set, as Format says.
  39. type Result struct {
  40. // Format is the format of the evidence.
  41. Format Format `json:"format"`
  42. // MediaType is the media type the evidence was sent with, if any.
  43. MediaType string `json:"mediaType,omitempty"`
  44. // Evidence is the evidence as it was sent, so that a relying party can
  45. // verify it again.
  46. Evidence []byte `json:"evidence,omitempty"`
  47. TDX *TDX `json:"tdx,omitempty"`
  48. SEVSNP *SEVSNP `json:"sevSnp,omitempty"`
  49. ConfidentialSpace *ConfidentialSpace `json:"confidentialSpace,omitempty"`
  50. }
  51. // TDX holds the measurements and attributes of a verified Intel TDX quote.
  52. type TDX struct {
  53. MRTD string `json:"mrtd"`
  54. RTMRs []string `json:"rtmrs"`
  55. MRSeam string `json:"mrSeam"`
  56. MRConfigID string `json:"mrConfigId"`
  57. MROwner string `json:"mrOwner"`
  58. MROwnerConfig string `json:"mrOwnerConfig"`
  59. TDAttributes string `json:"tdAttributes"`
  60. XFAM string `json:"xfam"`
  61. TEETCBSVN string `json:"teeTcbSvn"`
  62. // FMSPC identifies the platform's family, model and configuration in
  63. // the PCK certificate.
  64. FMSPC string `json:"fmspc"`
  65. // TCBStatus is the TDX TCB status from Intel's collateral, for example
  66. // UpToDate.
  67. TCBStatus string `json:"tcbStatus,omitempty"`
  68. }
  69. // SEVSNP holds the measurements and attributes of a verified AMD SEV-SNP
  70. // attestation report.
  71. type SEVSNP struct {
  72. Measurement string `json:"measurement"`
  73. HostData string `json:"hostData"`
  74. IDKeyDigest string `json:"idKeyDigest"`
  75. AuthorKeyDigest string `json:"authorKeyDigest"`
  76. FamilyID string `json:"familyId"`
  77. ImageID string `json:"imageId"`
  78. GuestSVN uint32 `json:"guestSvn"`
  79. Policy uint64 `json:"policy"`
  80. VMPL uint32 `json:"vmpl"`
  81. CurrentTCB uint64 `json:"currentTcb"`
  82. ReportedTCB uint64 `json:"reportedTcb"`
  83. LaunchTCB uint64 `json:"launchTcb"`
  84. ChipID string `json:"chipId"`
  85. // SigningKey is the key that signed the report, "vcek" or "vlek".
  86. SigningKey string `json:"signingKey"`
  87. // Product is the AMD product line, for example Milan.
  88. Product string `json:"product"`
  89. }
  90. // ConfidentialSpace holds the claims of a verified Google Cloud Attestation
  91. // token for a Confidential Space workload.
  92. type ConfidentialSpace struct {
  93. // Claims are all the claims of the token.
  94. Claims map[string]any `json:"claims"`
  95. // SignerSerialNumber is the serial number of the certificate that signed
  96. // the token.
  97. SignerSerialNumber string `json:"signerSerialNumber,omitempty"`
  98. }
  99. // ErrInvalidEvidence is matched, with errors.Is, by the errors of evidence that
  100. // is malformed, fails verification or does not meet a verifier's requirements.
  101. // Other errors, such as a failure to fetch collateral, are the verifier's.
  102. var ErrInvalidEvidence = errors.New("invalid attestation evidence")
  103. type invalidError struct {
  104. err error
  105. }
  106. func (e *invalidError) Error() string { return e.err.Error() }
  107. func (e *invalidError) Unwrap() []error { return []error{ErrInvalidEvidence, e.err} }
  108. // Invalid marks err as an error of the evidence, so that it matches
  109. // ErrInvalidEvidence. It returns nil if err is nil.
  110. func Invalid(err error) error {
  111. if err == nil {
  112. return nil
  113. }
  114. return &invalidError{err: err}
  115. }
  116. // Invalidf formats an error of the evidence, which matches ErrInvalidEvidence.
  117. func Invalidf(format string, args ...any) error {
  118. return &invalidError{err: fmt.Errorf(format, args...)}
  119. }