Skip to content

Commit

Permalink
Merge pull request #37 from deeglaze/getroot
Browse files Browse the repository at this point in the history
Add missing changes from PR#36
  • Loading branch information
deeglaze authored Feb 7, 2023
2 parents 08d1c7c + 252b6a5 commit c8c29ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
15 changes: 12 additions & 3 deletions testing/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package client

import (
"fmt"
"testing"

"github.com/google/go-sev-guest/client"
Expand Down Expand Up @@ -75,18 +76,26 @@ func GetSevGuest(tcs []test.TestCase, opts *test.DeviceOptions, tb testing.TB) (
if err != nil {
tb.Fatalf("Failed to open SEV guest device: %v", err)
}
kdsImpl := test.GetKDS(tb)

badSnpRoot := make(map[string][]*trust.AMDRootCerts)
for product, rootCerts := range trust.DefaultRootCerts {
// Supplement the defaults with the missing x509 certificates.
pc, err := trust.GetProductChain(product, kdsImpl)
if err != nil {
tb.Fatalf("failed to get product chain for %q: %v", product, err)
}
fmt.Printf("Making bad root %s %v", product, rootCerts)
// By flipping the ASK and ARK, we ensure that the attestation will never verify.
badSnpRoot[product] = []*trust.AMDRootCerts{{
Product: product,
ProductCerts: &trust.ProductCerts{
Ark: rootCerts.ProductCerts.Ask,
Ask: rootCerts.ProductCerts.Ark,
Ark: pc.Ask,
Ask: pc.Ark,
},
AskSev: rootCerts.ArkSev,
ArkSev: rootCerts.AskSev,
}}
}
return client, nil, badSnpRoot, test.GetKDS(tb)
return client, nil, badSnpRoot, kdsImpl
}
7 changes: 6 additions & 1 deletion verify/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
cpb "github.com/google/go-sev-guest/proto/check"
spb "github.com/google/go-sev-guest/proto/sevsnp"
"github.com/google/go-sev-guest/verify/trust"
"github.com/google/logger"
"github.com/pborman/uuid"
"github.com/pkg/errors"
"go.uber.org/multierr"
Expand Down Expand Up @@ -380,7 +381,7 @@ func validateVcekCertificateProductSpecifics(r *trust.AMDRootCerts, cert *x509.C
if err := ValidateVcekCertIssuer(r, cert.Issuer); err != nil {
return err
}
if err := cert.CheckSignatureFrom(r.ProductCerts.Ask); err != nil {
if _, err := cert.Verify(*r.X509Options()); err != nil {
return fmt.Errorf("error verifying VCEK certificate: %v (%v)", err, r.ProductCerts.Ask.IsCA)
}
// VCEK is not expected to have a CRL link.
Expand All @@ -402,6 +403,7 @@ func VcekDER(vcek []byte, ask []byte, ark []byte, options *Options) (*x509.Certi
roots := options.TrustedRoots
product := vcekProductMap[exts.ProductName]
if len(roots) == 0 {
logger.Warning("Using embedded AMD certificates for SEV-SNP attestation root of trust")
root := &trust.AMDRootCerts{
Product: product,
// Require that the root matches embedded root certs.
Expand Down Expand Up @@ -512,6 +514,9 @@ func RootOfTrustToOptions(rot *cpb.RootOfTrust) (*Options, error) {
// SnpAttestation verifies the protobuf representation of an attestation report's signature based
// on the report's SignatureAlgo, provided the certificate chain is valid.
func SnpAttestation(attestation *spb.Attestation, options *Options) error {
if options == nil {
return fmt.Errorf("options cannot be nil")
}
// Make sure we have the whole certificate chain if we're allowed.
if !options.DisableCertFetching {
if err := fillInAttestation(attestation, options.Getter); err != nil {
Expand Down

0 comments on commit c8c29ca

Please sign in to comment.