Skip to content

Commit 7cb961f

Browse files
authored
Merge pull request #95 from deeglaze/productdefaults
Fix SevProduct defaults for downstring testclient
2 parents 1a9dbbc + 6f2d2fe commit 7cb961f

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

testing/mocks.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
spb "github.com/google/go-sev-guest/proto/sevsnp"
2626
"github.com/pkg/errors"
2727
"golang.org/x/sys/unix"
28-
"google.golang.org/protobuf/types/known/wrapperspb"
2928
)
3029

3130
// GetReportResponse represents a mocked response to a command request.
@@ -144,10 +143,7 @@ func (d *Device) Ioctl(command uintptr, req any) (uintptr, error) {
144143
// Product returns the mocked product info or the default.
145144
func (d *Device) Product() *spb.SevProduct {
146145
if d.SevProduct == nil {
147-
return &spb.SevProduct{
148-
Name: spb.SevProduct_SEV_PRODUCT_MILAN,
149-
MachineStepping: &wrapperspb.UInt32Value{Value: 0},
150-
}
146+
return abi.DefaultSevProduct()
151147
}
152148
return d.SevProduct
153149
}

testing/test_cases.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/google/go-sev-guest/abi"
2424
labi "github.com/google/go-sev-guest/client/linuxabi"
2525
"github.com/google/go-sev-guest/kds"
26+
spb "github.com/google/go-sev-guest/proto/sevsnp"
2627
)
2728

2829
// userZeros defines a ReportData example that is all zeros
@@ -151,15 +152,22 @@ func CreateRawReport(opts *TestReportOptions) [labi.SnpReportRespReportSize]byte
151152

152153
// DeviceOptions specifies customizations for a fake sev-guest device.
153154
type DeviceOptions struct {
154-
Keys map[string][]byte
155-
Now time.Time
156-
Signer *AmdSigner
155+
Keys map[string][]byte
156+
Now time.Time
157+
Signer *AmdSigner
158+
Product *spb.SevProduct
157159
}
158160

159161
func makeTestCerts(opts *DeviceOptions) ([]byte, *AmdSigner, error) {
160162
signer := opts.Signer
163+
var productString string
164+
if opts.Product != nil {
165+
productString = kds.ProductString(opts.Product)
166+
} else {
167+
productString = kds.DefaultProductString()
168+
}
161169
if signer == nil {
162-
s, err := DefaultTestOnlyCertChain(kds.DefaultProductString(), opts.Now)
170+
s, err := DefaultTestOnlyCertChain(productString, opts.Now)
163171
if err != nil {
164172
return nil, nil, err
165173
}
@@ -250,5 +258,6 @@ func TcDevice(tcs []TestCase, opts *DeviceOptions) (*Device, error) {
250258
Certs: certs,
251259
Signer: signer,
252260
Keys: opts.Keys,
261+
SevProduct: opts.Product,
253262
}, nil
254263
}

verify/verify.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -687,17 +687,18 @@ func SnpAttestation(attestation *spb.Attestation, options *Options) error {
687687
// certificate chain.
688688
func fillInAttestation(attestation *spb.Attestation, options *Options) error {
689689
var productOverridden bool
690-
if options.Product != nil {
691-
attestation.Product = options.Product
692-
productOverridden = true
693-
} else if attestation.Product == nil {
694-
attestation.Product = abi.DefaultSevProduct()
690+
if attestation.Product == nil {
691+
if options.Product != nil {
692+
attestation.Product = options.Product
693+
} else {
694+
attestation.Product = abi.DefaultSevProduct()
695+
}
695696
productOverridden = true
696697
}
697698
if options.DisableCertFetching {
698699
return nil
699700
}
700-
product := kds.ProductString(options.Product)
701+
product := kds.ProductString(attestation.Product)
701702
getter := options.Getter
702703
if getter == nil {
703704
getter = trust.DefaultHTTPSGetter()
@@ -736,6 +737,8 @@ func fillInAttestation(attestation *spb.Attestation, options *Options) error {
736737
}
737738
}
738739
chain.VcekCert = vcek
740+
// An attempt was made with defaults or the option's product, so now use
741+
// the VCEK cert to determine the real product info.
739742
if productOverridden {
740743
cert, err := x509.ParseCertificate(vcek)
741744
if err != nil {
@@ -758,7 +761,10 @@ func fillInAttestation(attestation *spb.Attestation, options *Options) error {
758761
return ErrMissingVlek
759762
}
760763
}
761-
return nil
764+
765+
// Pass along the expected product information for VcekDER. fillInAttestation will ensure
766+
// that this is a noop if options.Product began as non-nil.
767+
return updateProductExpectation(&options.Product, attestation.Product)
762768
}
763769

764770
// GetAttestationFromReport uses AMD's Key Distribution Service (KDS) to download the certificate

0 commit comments

Comments
 (0)