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

Update go-sev-guest version and API use #445

Merged
merged 1 commit into from
May 31, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 26 additions & 26 deletions client/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ func (k *Key) getCertificateChain(client *http.Client) ([][]byte, error) {
return nil, fmt.Errorf("max certificate chain length (%v) exceeded", maxCertChainLength)
}

// SevSnpDevice encapsulates the SEV-SNP attestation device to add its attestation report
// SevSnpQuoteProvider encapsulates the SEV-SNP attestation device to add its attestation report
// to a pb.Attestation.
type SevSnpDevice struct {
Device sg.Device
type SevSnpQuoteProvider struct {
QuoteProvider sg.QuoteProvider
}

// TdxDevice encapsulates the TDX attestation device to add its attestation quote
Expand All @@ -156,20 +156,10 @@ type TdxQuoteProvider struct {
QuoteProvider tg.QuoteProvider
}

// CreateSevSnpDevice opens the SEV-SNP attestation driver and wraps it with behavior
// that allows it to add an attestation report to pb.Attestation.
func CreateSevSnpDevice() (*SevSnpDevice, error) {
d, err := sg.OpenDevice()
if err != nil {
return nil, err
}
return &SevSnpDevice{Device: d}, nil
}

// AddAttestation will get the SEV-SNP attestation report given opts.TEENonce with
// associated certificates and add them to `attestation`. If opts.TEENonce is empty,
// then uses contents of opts.Nonce.
func (d *SevSnpDevice) AddAttestation(attestation *pb.Attestation, opts AttestOpts) error {
func (d *SevSnpQuoteProvider) AddAttestation(attestation *pb.Attestation, opts AttestOpts) error {
var snpNonce [sabi.ReportDataSize]byte
if len(opts.TEENonce) == 0 {
copy(snpNonce[:], opts.Nonce)
Expand All @@ -178,7 +168,11 @@ func (d *SevSnpDevice) AddAttestation(attestation *pb.Attestation, opts AttestOp
} else {
copy(snpNonce[:], opts.TEENonce)
}
extReport, err := sg.GetExtendedReport(d.Device, snpNonce)
raw, err := d.QuoteProvider.GetRawQuote(snpNonce)
if err != nil {
return err
}
extReport, err := sabi.ReportCertsToProto(raw)
if err != nil {
return err
}
Expand All @@ -188,17 +182,24 @@ func (d *SevSnpDevice) AddAttestation(attestation *pb.Attestation, opts AttestOp
return nil
}

// Close will free the device handle held by the SevSnpDevice. Calling more
// than once has no effect.
func (d *SevSnpDevice) Close() error {
if d.Device != nil {
err := d.Device.Close()
d.Device = nil
return err
}
// Close is a no-op.
func (d *SevSnpQuoteProvider) Close() error {
return nil
}

// CreateSevSnpQuoteProvider creates the SEV-SNP quote provider and wraps it with behavior
// that allows it to add an attestation quote to pb.Attestation.
func CreateSevSnpQuoteProvider() (TEEDevice, error) {
qp, err := sg.GetQuoteProvider()
if err != nil {
return nil, err
}
if !qp.IsSupported() {
return nil, fmt.Errorf("sev-snp attestation reports not available")
}
return &SevSnpQuoteProvider{QuoteProvider: qp}, nil
}

// CreateTdxDevice opens the TDX attestation driver and wraps it with behavior
// that allows it to add an attestation quote to pb.Attestation.
// Deprecated: TdxDevice is deprecated, and use of CreateTdxQuoteProvider is
Expand Down Expand Up @@ -319,11 +320,10 @@ func getTEEAttestationReport(attestation *pb.Attestation, opts AttestOpts) error
}

// Try SEV-SNP.
if device, err := CreateSevSnpDevice(); err == nil {
if sevqp, err := CreateSevSnpQuoteProvider(); err == nil {
// Don't return errors if the attestation collection fails, since
// the user didn't specify a TEEDevice.
device.AddAttestation(attestation, opts)
device.Close()
sevqp.AddAttestation(attestation, opts)
return nil
}

Expand Down
9 changes: 4 additions & 5 deletions client/attest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func TestKeyAttestGetCertificateChainConditions(t *testing.T) {
}
}

func TestSevSnpDevice(t *testing.T) {
func TestSevSnpQuoteProvider(t *testing.T) {
rwc := test.GetTPM(t)
defer CheckedClose(t, rwc)

Expand All @@ -227,7 +227,7 @@ func TestSevSnpDevice(t *testing.T) {
copy(someNonce64[:], someNonce)
var nonce64 [64]byte
copy(nonce64[:], []byte("noncey business"))
sevTestDevice, _, _, _ := testclient.GetSevGuest([]sgtest.TestCase{
sevTestQp, _, _, _ := testclient.GetSevQuoteProvider([]sgtest.TestCase{
{
Input: someNonce64,
Output: sgtest.TestRawReport(someNonce64),
Expand All @@ -237,7 +237,6 @@ func TestSevSnpDevice(t *testing.T) {
Output: sgtest.TestRawReport(nonce64),
},
}, &sgtest.DeviceOptions{Now: time.Now()}, t)
defer sevTestDevice.Close()

testcases := []struct {
name string
Expand All @@ -250,7 +249,7 @@ func TestSevSnpDevice(t *testing.T) {
opts: AttestOpts{
Nonce: someNonce,
CertChainFetcher: localClient,
TEEDevice: &SevSnpDevice{sevTestDevice},
TEEDevice: &SevSnpQuoteProvider{sevTestQp},
},
wantReportData: someNonce64,
},
Expand All @@ -259,7 +258,7 @@ func TestSevSnpDevice(t *testing.T) {
opts: AttestOpts{
Nonce: someNonce,
CertChainFetcher: localClient,
TEEDevice: &SevSnpDevice{sevTestDevice},
TEEDevice: &SevSnpQuoteProvider{sevTestQp},
TEENonce: nonce64[:],
},
wantReportData: nonce64,
Expand Down
2 changes: 1 addition & 1 deletion cmd/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ hardware and guarantees a fresh quote.
// Add logic to open other hardware devices when required.
switch teeTechnology {
case SevSnp:
attestOpts.TEEDevice, err = client.CreateSevSnpDevice()
attestOpts.TEEDevice, err = client.CreateSevSnpQuoteProvider()
if err != nil {
return fmt.Errorf("failed to open %s device: %v", SevSnp, err)
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/attest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,11 @@ func TestSevAttestTeeNonceFail(t *testing.T) {
}

// TEENonce with length less than 64 bytes.
sevTestDevice, _, _, _ := sgtestclient.GetSevGuest([]sgtest.TestCase{
sevTestQp, _, _, _ := sgtestclient.GetSevQuoteProvider([]sgtest.TestCase{
{
Input: [64]byte{1, 2, 3, 4},
},
}, &sgtest.DeviceOptions{Now: time.Now()}, t)
defer sevTestDevice.Close()

ak, err := client.AttestationKeyRSA(rwc)
if err != nil {
Expand All @@ -324,7 +323,7 @@ func TestSevAttestTeeNonceFail(t *testing.T) {
attestopts := client.AttestOpts{
Nonce: []byte{1, 2, 3, 4},
TEENonce: []byte{1, 2, 3, 4},
TEEDevice: &client.SevSnpDevice{Device: sevTestDevice},
TEEDevice: &client.SevSnpQuoteProvider{QuoteProvider: sevTestQp},
}
_, err = ak.Attest(attestopts)
if err == nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/containerd/containerd v1.7.16
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/golang/protobuf v1.5.4
github.com/google/go-sev-guest v0.9.3
github.com/google/go-sev-guest v0.11.1
github.com/google/go-tdx-guest v0.3.1
github.com/google/go-tpm v0.9.0
github.com/google/go-tpm-tools v0.4.4
Expand Down
4 changes: 2 additions & 2 deletions cmd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ github.com/google/go-licenses v0.0.0-20210329231322-ce1d9163b77d/go.mod h1:+TYOm
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-replayers/grpcreplay v0.1.0/go.mod h1:8Ig2Idjpr6gifRd6pNVggX6TC1Zw6Jx74AKp7QNH2QE=
github.com/google/go-replayers/httpreplay v0.1.0/go.mod h1:YKZViNhiGgqdBlUbI2MwGpq4pXxNmhJLPHQ7cv2b5no=
github.com/google/go-sev-guest v0.9.3 h1:GOJ+EipURdeWFl/YYdgcCxyPeMgQUWlI056iFkBD8UU=
github.com/google/go-sev-guest v0.9.3/go.mod h1:hc1R4R6f8+NcJwITs0L90fYWTsBpd1Ix+Gur15sqHDs=
github.com/google/go-sev-guest v0.11.1 h1:gnww4U8fHV5DCPz4gykr1s8SEX1fFNcxCBy+vvXN24k=
github.com/google/go-sev-guest v0.11.1/go.mod h1:qBOfb+JmgsUI3aUyzQoGC13Kpp9zwLeWvuyXmA9q77w=
github.com/google/go-tdx-guest v0.3.1 h1:gl0KvjdsD4RrJzyLefDOvFOUH3NAJri/3qvaL5m83Iw=
github.com/google/go-tdx-guest v0.3.1/go.mod h1:/rc3d7rnPykOPuY8U9saMyEps0PZDThLk/RygXm04nE=
github.com/google/go-tpm v0.9.0 h1:sQF6YqWMi+SCXpsmS3fd21oPy/vSddwZry4JnmltHVk=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.20
require (
github.com/google/go-attestation v0.5.1
github.com/google/go-cmp v0.6.0
github.com/google/go-sev-guest v0.9.3
github.com/google/go-sev-guest v0.11.1
github.com/google/go-tdx-guest v0.3.1
github.com/google/go-tpm v0.9.0
github.com/google/logger v1.1.1
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ github.com/google/go-licenses v0.0.0-20210329231322-ce1d9163b77d/go.mod h1:+TYOm
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-replayers/grpcreplay v0.1.0/go.mod h1:8Ig2Idjpr6gifRd6pNVggX6TC1Zw6Jx74AKp7QNH2QE=
github.com/google/go-replayers/httpreplay v0.1.0/go.mod h1:YKZViNhiGgqdBlUbI2MwGpq4pXxNmhJLPHQ7cv2b5no=
github.com/google/go-sev-guest v0.9.3 h1:GOJ+EipURdeWFl/YYdgcCxyPeMgQUWlI056iFkBD8UU=
github.com/google/go-sev-guest v0.9.3/go.mod h1:hc1R4R6f8+NcJwITs0L90fYWTsBpd1Ix+Gur15sqHDs=
github.com/google/go-sev-guest v0.11.1 h1:gnww4U8fHV5DCPz4gykr1s8SEX1fFNcxCBy+vvXN24k=
github.com/google/go-sev-guest v0.11.1/go.mod h1:qBOfb+JmgsUI3aUyzQoGC13Kpp9zwLeWvuyXmA9q77w=
github.com/google/go-tdx-guest v0.3.1 h1:gl0KvjdsD4RrJzyLefDOvFOUH3NAJri/3qvaL5m83Iw=
github.com/google/go-tdx-guest v0.3.1/go.mod h1:/rc3d7rnPykOPuY8U9saMyEps0PZDThLk/RygXm04nE=
github.com/google/go-tpm v0.9.0 h1:sQF6YqWMi+SCXpsmS3fd21oPy/vSddwZry4JnmltHVk=
Expand Down Expand Up @@ -1237,6 +1237,7 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
2 changes: 1 addition & 1 deletion launcher/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ require (
github.com/google/certificate-transparency-go v1.1.2 // indirect
github.com/google/go-attestation v0.5.1 // indirect
github.com/google/go-configfs-tsm v0.2.2 // indirect
github.com/google/go-sev-guest v0.9.3 // indirect
github.com/google/go-sev-guest v0.11.1 // indirect
github.com/google/go-tdx-guest v0.3.1 // indirect
github.com/google/go-tspi v0.3.0 // indirect
github.com/google/logger v1.1.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions launcher/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ github.com/google/go-licenses v0.0.0-20210329231322-ce1d9163b77d/go.mod h1:+TYOm
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-replayers/grpcreplay v0.1.0/go.mod h1:8Ig2Idjpr6gifRd6pNVggX6TC1Zw6Jx74AKp7QNH2QE=
github.com/google/go-replayers/httpreplay v0.1.0/go.mod h1:YKZViNhiGgqdBlUbI2MwGpq4pXxNmhJLPHQ7cv2b5no=
github.com/google/go-sev-guest v0.9.3 h1:GOJ+EipURdeWFl/YYdgcCxyPeMgQUWlI056iFkBD8UU=
github.com/google/go-sev-guest v0.9.3/go.mod h1:hc1R4R6f8+NcJwITs0L90fYWTsBpd1Ix+Gur15sqHDs=
github.com/google/go-sev-guest v0.11.1 h1:gnww4U8fHV5DCPz4gykr1s8SEX1fFNcxCBy+vvXN24k=
github.com/google/go-sev-guest v0.11.1/go.mod h1:qBOfb+JmgsUI3aUyzQoGC13Kpp9zwLeWvuyXmA9q77w=
github.com/google/go-tdx-guest v0.3.1 h1:gl0KvjdsD4RrJzyLefDOvFOUH3NAJri/3qvaL5m83Iw=
github.com/google/go-tdx-guest v0.3.1/go.mod h1:/rc3d7rnPykOPuY8U9saMyEps0PZDThLk/RygXm04nE=
github.com/google/go-tpm v0.9.0 h1:sQF6YqWMi+SCXpsmS3fd21oPy/vSddwZry4JnmltHVk=
Expand Down
5 changes: 2 additions & 3 deletions server/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -972,16 +972,15 @@ func TestVerifyAttestationWithSevSnp(t *testing.T) {
altNonce := []byte("alternate secret nonce")
var nonce64 [64]byte
copy(nonce64[:], altNonce)
sevTestDevice, goodSnpRoot, badSnpRoot, kdsGetter := testclient.GetSevGuest([]sgtest.TestCase{
sevTestQp, goodSnpRoot, badSnpRoot, kdsGetter := testclient.GetSevQuoteProvider([]sgtest.TestCase{
{
Input: nonce64,
Output: sgtest.TestRawReport(nonce64),
},
}, &sgtest.DeviceOptions{Now: time.Now()}, t)
defer sevTestDevice.Close()
attestation, err := ak.Attest(client.AttestOpts{
Nonce: nonce,
TEEDevice: &client.SevSnpDevice{Device: sevTestDevice},
TEEDevice: &client.SevSnpQuoteProvider{QuoteProvider: sevTestQp},
TEENonce: nonce64[:],
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion verifier/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
github.com/google/certificate-transparency-go v1.1.2 // indirect
github.com/google/go-attestation v0.5.1 // indirect
github.com/google/go-configfs-tsm v0.2.2 // indirect
github.com/google/go-sev-guest v0.9.3 // indirect
github.com/google/go-sev-guest v0.11.1 // indirect
github.com/google/go-tdx-guest v0.3.1 // indirect
github.com/google/go-tspi v0.3.0 // indirect
github.com/google/logger v1.1.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions verifier/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ github.com/google/go-licenses v0.0.0-20210329231322-ce1d9163b77d/go.mod h1:+TYOm
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-replayers/grpcreplay v0.1.0/go.mod h1:8Ig2Idjpr6gifRd6pNVggX6TC1Zw6Jx74AKp7QNH2QE=
github.com/google/go-replayers/httpreplay v0.1.0/go.mod h1:YKZViNhiGgqdBlUbI2MwGpq4pXxNmhJLPHQ7cv2b5no=
github.com/google/go-sev-guest v0.9.3 h1:GOJ+EipURdeWFl/YYdgcCxyPeMgQUWlI056iFkBD8UU=
github.com/google/go-sev-guest v0.9.3/go.mod h1:hc1R4R6f8+NcJwITs0L90fYWTsBpd1Ix+Gur15sqHDs=
github.com/google/go-sev-guest v0.11.1 h1:gnww4U8fHV5DCPz4gykr1s8SEX1fFNcxCBy+vvXN24k=
github.com/google/go-sev-guest v0.11.1/go.mod h1:qBOfb+JmgsUI3aUyzQoGC13Kpp9zwLeWvuyXmA9q77w=
github.com/google/go-tdx-guest v0.3.1 h1:gl0KvjdsD4RrJzyLefDOvFOUH3NAJri/3qvaL5m83Iw=
github.com/google/go-tdx-guest v0.3.1/go.mod h1:/rc3d7rnPykOPuY8U9saMyEps0PZDThLk/RygXm04nE=
github.com/google/go-tpm v0.9.0 h1:sQF6YqWMi+SCXpsmS3fd21oPy/vSddwZry4JnmltHVk=
Expand Down