Skip to content
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

attestation: log Validate errors #1027

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions internal/attestation/snp/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
"github.com/edgelesssys/contrast/internal/attestation"
"github.com/edgelesssys/contrast/internal/attestation/reportdata"
"github.com/edgelesssys/contrast/internal/oid"
"github.com/google/go-sev-guest/abi"
"github.com/google/go-sev-guest/proto/sevsnp"
"github.com/google/go-sev-guest/validate"
"github.com/google/go-sev-guest/verify"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
)

Expand Down Expand Up @@ -57,6 +57,13 @@ func (v *Validator) OID() asn1.ObjectIdentifier {
// Validate a TPM based attestation.
func (v *Validator) Validate(attDocRaw []byte, nonce []byte, peerPublicKey []byte) (err error) {
v.logger.Info("Validate called", "nonce", hex.EncodeToString(nonce))
defer func() {
if err != nil {
v.logger.Error("Validation failed", "error", err)
} else {
v.logger.Info("Validation successful")
}
}()

// Parse the attestation document.

Expand All @@ -68,11 +75,7 @@ func (v *Validator) Validate(attDocRaw []byte, nonce []byte, peerPublicKey []byt
if attestationData.Report == nil {
return fmt.Errorf("attestation missing report")
}
reportRaw, err := abi.ReportToAbiBytes(attestationData.Report)
if err != nil {
return fmt.Errorf("converting report to abi format: %w", err)
}
v.logger.Info("Report decoded", "reportRaw", hex.EncodeToString(reportRaw))
v.logger.Info("Report decoded", "report", protojson.MarshalOptions{Multiline: false}.Format(attestationData.Report))

// Report signature verification.

Expand All @@ -88,14 +91,11 @@ func (v *Validator) Validate(attDocRaw []byte, nonce []byte, peerPublicKey []byt
if err := validate.SnpAttestation(attestationData, v.validateOpts); err != nil {
return fmt.Errorf("validating report claims: %w", err)
}
v.logger.Info("Successfully validated report data")

if v.reportSetter != nil {
report := snpReport{report: attestationData.Report}
v.reportSetter.SetReport(report)
}

v.logger.Info("Validate finished successfully")
return nil
}

Expand Down
18 changes: 9 additions & 9 deletions internal/attestation/tdx/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
"github.com/edgelesssys/contrast/internal/attestation"
"github.com/edgelesssys/contrast/internal/attestation/reportdata"
"github.com/edgelesssys/contrast/internal/oid"
"github.com/google/go-tdx-guest/abi"
"github.com/google/go-tdx-guest/proto/tdx"
"github.com/google/go-tdx-guest/validate"
"github.com/google/go-tdx-guest/verify"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
)

Expand Down Expand Up @@ -79,6 +79,13 @@ func (v *Validator) Validate(attDocRaw []byte, nonce []byte, peerPublicKey []byt
// TODO(freax13): Validate the memory integrity mode (logical vs cryptographic) in the provisioning certificate.

v.logger.Info("Validate called", "nonce", hex.EncodeToString(nonce))
defer func() {
if err != nil {
v.logger.Error("Validation failed", "error", err)
} else {
v.logger.Info("Validation successful")
}
}()

// Parse the attestation document.

Expand All @@ -87,11 +94,7 @@ func (v *Validator) Validate(attDocRaw []byte, nonce []byte, peerPublicKey []byt
return fmt.Errorf("unmarshaling attestation: %w", err)
}

quoteRaw, err := abi.QuoteToAbiBytes(quote)
if err != nil {
return fmt.Errorf("converting quote to abi format: %w", err)
}
v.logger.Info("Quote decoded", "quoteRaw", hex.EncodeToString(quoteRaw))
v.logger.Info("Quote decoded", "quote", protojson.MarshalOptions{Multiline: false}.Format(quote))

// Build the verification options.

Expand Down Expand Up @@ -126,14 +129,11 @@ func (v *Validator) Validate(attDocRaw []byte, nonce []byte, peerPublicKey []byt
if err := validate.TdxQuote(quote, validateOpts); err != nil {
return fmt.Errorf("validating report data: %w", err)
}
v.logger.Info("Successfully validated report data")

if v.reportSetter != nil {
report := tdxReport{quote: quote}
v.reportSetter.SetReport(report)
}

v.logger.Info("Validate finished successfully")
return nil
}

Expand Down