Skip to content

Commit

Permalink
Merge pull request google#111 from google/endorse
Browse files Browse the repository at this point in the history
Allow certentry Validate to fail before error
  • Loading branch information
deeglaze authored Feb 22, 2024
2 parents 5c59951 + 83de68d commit 87a2ce5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
15 changes: 6 additions & 9 deletions validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/google/go-sev-guest/kds"
cpb "github.com/google/go-sev-guest/proto/check"
spb "github.com/google/go-sev-guest/proto/sevsnp"
"github.com/google/logger"
"go.uber.org/multierr"
)

Expand Down Expand Up @@ -633,18 +634,14 @@ func validateKeyKind(report *spb.Attestation) (*x509.Certificate, error) {
func certTableOptions(attestation *spb.Attestation, options map[string]*CertEntryOption) error {
extras := attestation.GetCertificateChain().GetExtras()
for key, opt := range options {
blob, ok := extras[key]
if !ok {
if opt.Kind == CertEntryRequire {
return fmt.Errorf("required certificate UUID %s not present in certificate table", key)
}
continue
}
if opt.Validate == nil {
return fmt.Errorf("invalid argument: option for %s missing Validate function", key)
}
if err := opt.Validate(attestation, blob); err != nil {
return err
if err := opt.Validate(attestation, extras[key]); err != nil {
if opt.Kind == CertEntryRequire {
return err
}
logger.Warningf("Missing cert entry for %s", key)
}
}
return nil
Expand Down
10 changes: 9 additions & 1 deletion validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,15 @@ func TestCertTableOptions(t *testing.T) {
PlatformInfo: &abi.SnpPlatformInfo{SMTEnabled: true},

CertTableOptions: map[string]*CertEntryOption{
"00000000-feee-feee-0000-000000000000": {Kind: CertEntryRequire, Validate: func(*spb.Attestation, []byte) error { return nil }},
"00000000-feee-feee-0000-000000000000": {
Kind: CertEntryRequire,
Validate: func(_ *spb.Attestation, blob []byte) error {
if blob == nil {
return fmt.Errorf("local data is required")
}
return nil
},
},
},
}); err == nil || !strings.Contains(err.Error(), "required") {
t.Errorf("SnpAttestation(_, &Options{CertTableOptions: require feee-feee}) = %v, want error to contain %s", err, "required")
Expand Down

0 comments on commit 87a2ce5

Please sign in to comment.