Skip to content

Commit bb8c75c

Browse files
authored
Merge pull request #15 from deeglaze/consistent_product
Change variables to be more consistent with AMD's docs
2 parents 8f9bc86 + 75f1654 commit bb8c75c

File tree

10 files changed

+128
-128
lines changed

10 files changed

+128
-128
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ This function creates a file descriptor to the `/dev/sev-guest` device and
2727
returns an object that has methods encapsulating commands to the device. When
2828
done, remember to `Close()` the device.
2929

30-
### `func GetExtendedReport(d Device, userData [64]byte) (*pb.Attestation, error)`
30+
### `func GetExtendedReport(d Device, reportData [64]byte) (*pb.Attestation, error)`
3131

3232
This function takes an object implementing the `Device` interface (e.g., a
3333
`LinuxDevice`) and returns the protocol buffer representation of the attestation
@@ -91,7 +91,7 @@ This type contains three fields:
9191
certificate revocation list (CRL) and check for revocations.
9292
* `Getter HTTPSGetter`: must be non-`nil` if `CheckRevocations` is true.
9393
* `TrustedRoots map[string][]*AMDRootCerts`: if `nil`, uses the library's embedded certificates.
94-
Maps a platform name to all allowed root certifications for that platform (e.g., Milan).
94+
Maps a product name to all allowed root certifications for that product (e.g., Milan).
9595

9696
The `HTTPSGetter` interface consists of a single method `Get(url string)
9797
([]byte, error)` that should return the body of the HTTPS response.
@@ -101,7 +101,7 @@ The `HTTPSGetter` interface consists of a single method `Get(url string)
101101

102102
This type has 6 fields, the first 3 of which are mandatory:
103103

104-
* `Platform string`: the name of the platform this bundle is for (e.g., `"Milan"`).
104+
* `Product string`: the name of the product this bundle is for (e.g., `"Milan"`).
105105
* `AskX509 *x509.Certificate`: an X.509 representation of the AMD SEV Signer intermediate key (ASK)'s certificate.
106106
* `ArkX509 *x509.Certificate`: an X.509 representation of the AMD SEV Root key (ARK)'s certificate.
107107
* `AskSev *abi.AskCert`: if non-`nil`, will cross-check with
@@ -134,7 +134,7 @@ fields of an attestation report.
134134

135135
The fields that either can be skipped or must match the given value exactly are:
136136

137-
* `UserData` for the `REPORT_DATA` field
137+
* `ReportData` for the `REPORT_DATA` field
138138
* `HostData` for the `HOST_DATA` field
139139
* `ImageID` for the `IMAGE_ID` field
140140
* `FamilyID` for the `FAMILY_ID` field

client/client.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ func message(d Device, command uintptr, req *labi.SnpUserGuestRequest) error {
4646

4747
// GetRawReportAtVmpl requests for an attestation report at the given VMPL that incorporates the
4848
// given user data.
49-
func GetRawReportAtVmpl(d Device, userData [64]byte, vmpl int) ([]byte, error) {
49+
func GetRawReportAtVmpl(d Device, reportData [64]byte, vmpl int) ([]byte, error) {
5050
var snpReportRsp labi.SnpReportRespABI
5151
userGuestReq := labi.SnpUserGuestRequest{
5252
ReqData: &labi.SnpReportReqABI{
53-
UserData: userData,
54-
Vmpl: uint32(vmpl),
53+
ReportData: reportData,
54+
Vmpl: uint32(vmpl),
5555
},
5656
RespData: &snpReportRsp,
5757
}
@@ -62,35 +62,35 @@ func GetRawReportAtVmpl(d Device, userData [64]byte, vmpl int) ([]byte, error) {
6262
}
6363

6464
// GetRawReport requests for an attestation report at VMPL0 that incorporates the given user data.
65-
func GetRawReport(d Device, userData [64]byte) ([]byte, error) {
66-
return GetRawReportAtVmpl(d, userData, 0)
65+
func GetRawReport(d Device, reportData [64]byte) ([]byte, error) {
66+
return GetRawReportAtVmpl(d, reportData, 0)
6767
}
6868

6969
// GetReportAtVmpl gets an attestation report at the given VMPL into its protobuf representation.
70-
func GetReportAtVmpl(d Device, userData [64]byte, vmpl int) (*pb.Report, error) {
71-
data, err := GetRawReportAtVmpl(d, userData, vmpl)
70+
func GetReportAtVmpl(d Device, reportData [64]byte, vmpl int) (*pb.Report, error) {
71+
data, err := GetRawReportAtVmpl(d, reportData, vmpl)
7272
if err != nil {
7373
return nil, err
7474
}
7575
return abi.ReportToProto(data)
7676
}
7777

7878
// GetReport gets an attestation report at VMPL0 into its protobuf representation.
79-
func GetReport(d Device, userData [64]byte) (*pb.Report, error) {
80-
return GetReportAtVmpl(d, userData, 0)
79+
func GetReport(d Device, reportData [64]byte) (*pb.Report, error) {
80+
return GetReportAtVmpl(d, reportData, 0)
8181
}
8282

83-
// getExtendedReportIn issues a GetExtendedReport command to the sev-guest driver with userData
83+
// getExtendedReportIn issues a GetExtendedReport command to the sev-guest driver with reportData
8484
// input and certs as a destination for certificate data. If certs is empty, this function returns
8585
// the expected size of certs as its second result value. If certs is non-empty, this function
86-
// returns the signed attestation report containing userData and the certificate chain for the
86+
// returns the signed attestation report containing reportData and the certificate chain for the
8787
// report's endorsement key.
88-
func getExtendedReportIn(d Device, userData [64]byte, vmpl int, certs []byte) ([]byte, uint32, error) {
88+
func getExtendedReportIn(d Device, reportData [64]byte, vmpl int, certs []byte) ([]byte, uint32, error) {
8989
var snpReportRsp labi.SnpReportRespABI
9090
snpExtReportReq := labi.SnpExtendedReportReq{
9191
Data: labi.SnpReportReqABI{
92-
UserData: userData,
93-
Vmpl: uint32(vmpl),
92+
ReportData: reportData,
93+
Vmpl: uint32(vmpl),
9494
},
9595
Certs: certs,
9696
CertsLength: uint32(len(certs)),
@@ -122,13 +122,13 @@ func queryCertificateLength(d Device, vmpl int) (uint32, error) {
122122

123123
// GetRawExtendedReportAtVmpl requests for an attestation report that incorporates the given user
124124
// data at the given VMPL, and additional key certificate information.
125-
func GetRawExtendedReportAtVmpl(d Device, userData [64]byte, vmpl int) ([]byte, []byte, error) {
125+
func GetRawExtendedReportAtVmpl(d Device, reportData [64]byte, vmpl int) ([]byte, []byte, error) {
126126
length, err := queryCertificateLength(d, vmpl)
127127
if err != nil {
128128
return nil, nil, fmt.Errorf("error querying certificate length: %v", err)
129129
}
130130
certs := make([]byte, length)
131-
report, _, err := getExtendedReportIn(d, userData, vmpl, certs)
131+
report, _, err := getExtendedReportIn(d, reportData, vmpl, certs)
132132
if err != nil {
133133
return nil, nil, err
134134
}
@@ -137,13 +137,13 @@ func GetRawExtendedReportAtVmpl(d Device, userData [64]byte, vmpl int) ([]byte,
137137

138138
// GetRawExtendedReport requests for an attestation report that incorporates the given user data,
139139
// and additional key certificate information.
140-
func GetRawExtendedReport(d Device, userData [64]byte) ([]byte, []byte, error) {
141-
return GetRawExtendedReportAtVmpl(d, userData, 0)
140+
func GetRawExtendedReport(d Device, reportData [64]byte) ([]byte, []byte, error) {
141+
return GetRawExtendedReportAtVmpl(d, reportData, 0)
142142
}
143143

144144
// GetExtendedReportAtVmpl gets an extended attestation report at the given VMPL into a structured type.
145-
func GetExtendedReportAtVmpl(d Device, userData [64]byte, vmpl int) (*pb.Attestation, error) {
146-
reportBytes, certBytes, err := GetRawExtendedReportAtVmpl(d, userData, vmpl)
145+
func GetExtendedReportAtVmpl(d Device, reportData [64]byte, vmpl int) (*pb.Attestation, error) {
146+
reportBytes, certBytes, err := GetRawExtendedReportAtVmpl(d, reportData, vmpl)
147147
if err != nil {
148148
return nil, err
149149
}
@@ -161,8 +161,8 @@ func GetExtendedReportAtVmpl(d Device, userData [64]byte, vmpl int) (*pb.Attesta
161161
}
162162

163163
// GetExtendedReport gets an extended attestation report at VMPL0 into a structured type.
164-
func GetExtendedReport(d Device, userData [64]byte) (*pb.Attestation, error) {
165-
return GetExtendedReportAtVmpl(d, userData, 0)
164+
func GetExtendedReport(d Device, reportData [64]byte) (*pb.Attestation, error) {
165+
return GetExtendedReportAtVmpl(d, reportData, 0)
166166
}
167167

168168
// GuestFieldSelect represents which guest-provided information will be mixed into a derived key.

client/linuxabi/linux_abi.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ func (err SevEsErr) Error() string {
108108
// SnpReportReqABI is Linux's sev-guest ioctl abi for sending a GET_REPORT request. See
109109
// include/uapi/linux/sev-guest.h
110110
type SnpReportReqABI struct {
111-
// UserData to be included in the report
112-
UserData [64]uint8
111+
// ReportData to be included in the report
112+
ReportData [64]uint8
113113

114114
// Vmpl is the SEV-SNP VMPL level to be included in the report.
115115
// The kernel must have access to the corresponding VMPCK.

kds/kds.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,9 @@ func VcekCertificateExtensions(cert *x509.Certificate) (*VcekExtensions, error)
339339
return extensions, nil
340340
}
341341

342-
// ParsePlatformCertChain returns the DER-formatted certificates represented by the body
343-
// of the PlatformCertChain (cert_chain) endpoint, ASK and ARK in that order.
344-
func ParsePlatformCertChain(pems []byte) ([]byte, []byte, error) {
342+
// ParseProductCertChain returns the DER-formatted certificates represented by the body
343+
// of the ProductCertChain (cert_chain) endpoint, ASK and ARK in that order.
344+
func ParseProductCertChain(pems []byte) ([]byte, []byte, error) {
345345
checkForm := func(name string, b *pem.Block) error {
346346
if b == nil {
347347
return fmt.Errorf("could not find %s PEM block", name)
@@ -365,23 +365,23 @@ func ParsePlatformCertChain(pems []byte) ([]byte, []byte, error) {
365365
return askBlock.Bytes, arkBlock.Bytes, nil
366366
}
367367

368-
// platformBaseURL returns the base URL for all certificate queries within a particular platform.
369-
func platformBaseURL(name string) string {
368+
// productBaseURL returns the base URL for all certificate queries within a particular product.
369+
func productBaseURL(name string) string {
370370
return fmt.Sprintf("%s/vcek/v1/%s", kdsBaseURL, name)
371371
}
372372

373-
// PlatformCertChainURL returns the AMD KDS URL for retrieving the ARK and ASK
374-
// certificates on the given platform in PEM format.
375-
func PlatformCertChainURL(platform string) string {
376-
return fmt.Sprintf("%s/cert_chain", platformBaseURL(platform))
373+
// ProductCertChainURL returns the AMD KDS URL for retrieving the ARK and ASK
374+
// certificates on the given product in PEM format.
375+
func ProductCertChainURL(product string) string {
376+
return fmt.Sprintf("%s/cert_chain", productBaseURL(product))
377377
}
378378

379-
// VCEKCertURL returns the AMD KDS URL for retrieving the VCEK on a given platform
379+
// VCEKCertURL returns the AMD KDS URL for retrieving the VCEK on a given product
380380
// at a given TCB version. The hwid is the CHIP_ID field in an attestation report.
381-
func VCEKCertURL(platform string, hwid []byte, tcb TCBVersion) string {
381+
func VCEKCertURL(product string, hwid []byte, tcb TCBVersion) string {
382382
parts := DecomposeTCBVersion(tcb)
383383
return fmt.Sprintf("%s/%s?blSPL=%d&teeSPL=%d&snpSPL=%d&ucodeSPL=%d",
384-
platformBaseURL(platform),
384+
productBaseURL(product),
385385
hex.EncodeToString(hwid),
386386
parts.BlSpl,
387387
parts.TeeSpl,

testing/mocks.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ type GetReportResponse struct {
3232

3333
// Device represents a sev-guest driver implementation with pre-programmed responses to commands.
3434
type Device struct {
35-
isOpen bool
36-
UserDataRsp map[string]interface{}
37-
Keys map[string][]byte
38-
Certs []byte
39-
Signer *AmdSigner
35+
isOpen bool
36+
ReportDataRsp map[string]interface{}
37+
Keys map[string][]byte
38+
Certs []byte
39+
Signer *AmdSigner
4040
}
4141

4242
// Open changes the mock device's state to open.
@@ -58,9 +58,9 @@ func (d *Device) Close() error {
5858
}
5959

6060
func (d *Device) getReport(req *labi.SnpReportReqABI, rsp *labi.SnpReportRespABI, fwErr *uint64) (uintptr, error) {
61-
mockRspI, ok := d.UserDataRsp[hex.EncodeToString(req.UserData[:])]
61+
mockRspI, ok := d.ReportDataRsp[hex.EncodeToString(req.ReportData[:])]
6262
if !ok {
63-
return 0, fmt.Errorf("test error: no response for %v", req.UserData)
63+
return 0, fmt.Errorf("test error: no response for %v", req.ReportData)
6464
}
6565
mockRsp, ok := mockRspI.(*GetReportResponse)
6666
if !ok {

testing/test_cases.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import (
2424
labi "github.com/google/go-sev-guest/client/linuxabi"
2525
)
2626

27-
// userZeros defines a UserData example that is all zeros
27+
// userZeros defines a ReportData example that is all zeros
2828
var userZeros [64]byte
2929

30-
// userZeros1 defines a UserData example that is all zeros except the last byte is 1.
30+
// userZeros1 defines a ReportData example that is all zeros except the last byte is 1.
3131
var userZeros1 = [64]byte{
3232
0, 0, 0, 0, 0, 0, 0, 0,
3333
0, 0, 0, 0, 0, 0, 0, 0,
@@ -38,7 +38,7 @@ var userZeros1 = [64]byte{
3838
0, 0, 0, 0, 0, 0, 0, 0,
3939
0, 0, 0, 0, 0, 0, 0, 1}
4040

41-
// userZeros11 defines a UserData example that is all zeros except the last 2 bytes are both 1.
41+
// userZeros11 defines a ReportData example that is all zeros except the last 2 bytes are both 1.
4242
var userZeros11 = [64]byte{
4343
0, 0, 0, 0, 0, 0, 0, 0,
4444
0, 0, 0, 0, 0, 0, 0, 0,
@@ -91,15 +91,15 @@ var oneReport = `
9191
// We can't sign the report with AMD keys, and verification isn't the client's responsibility, so
9292
// we keep the signature zeros.
9393
// Similarly, we leave the randomly-generated fields zero.
94-
func TestRawReport(userData [64]byte) [labi.SnpReportRespReportSize]byte {
94+
func TestRawReport(reportData [64]byte) [labi.SnpReportRespReportSize]byte {
9595
var r [labi.SnpReportRespReportSize]byte
9696
// Set Version to 2
9797
binary.LittleEndian.PutUint32(r[0x00:0x04], 2)
9898
binary.LittleEndian.PutUint64(r[0x08:0x10], abi.SnpPolicyToBytes(abi.SnpPolicy{Debug: true}))
9999
// Signature algorithm ECC P-384 with SHA-384 is encoded as 1.
100100
binary.LittleEndian.PutUint32(r[0x34:0x38], 1)
101101
// Place user data in its report location.
102-
copy(r[0x50:0x90], userData[:])
102+
copy(r[0x50:0x90], reportData[:])
103103
return r
104104
}
105105

@@ -178,9 +178,9 @@ func TcDevice(tcs []TestCase, opts *DeviceOptions) (*Device, error) {
178178
}
179179
}
180180
return &Device{
181-
UserDataRsp: responses,
182-
Certs: certs,
183-
Signer: signer,
184-
Keys: opts.Keys,
181+
ReportDataRsp: responses,
182+
Certs: certs,
183+
Signer: signer,
184+
Keys: opts.Keys,
185185
}, nil
186186
}

validate/validate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import (
3434
type Options struct {
3535
// GuestPolicy is the maximum of acceptable guest policies.
3636
GuestPolicy abi.SnpPolicy
37-
// UserData is the expected REPORT_DATA field. Must be nil or 64 bytes long. Not checked if nil.
38-
UserData []byte
37+
// ReportData is the expected REPORT_DATA field. Must be nil or 64 bytes long. Not checked if nil.
38+
ReportData []byte
3939
// HostData is the expected HOST_DATA field. Must be nil or 32 bytes long. Not checked if nil.
4040
HostData []byte
4141
// ImageID is the expected IMAGE_ID field. Must be nil or 16 bytes long. Not checked if nil.
@@ -139,7 +139,7 @@ func validateByteField(option, field string, size int, given, required []byte) e
139139

140140
func validateVerbatimFields(report *spb.Report, options *Options) error {
141141
return multierr.Combine(
142-
validateByteField("UserData", "REPORT_DATA", abi.ReportDataSize, report.GetReportData(), options.UserData),
142+
validateByteField("ReportData", "REPORT_DATA", abi.ReportDataSize, report.GetReportData(), options.ReportData),
143143
validateByteField("HostData", "HOST_DATA", abi.HostDataSize, report.GetHostData(), options.HostData),
144144
validateByteField("FamilyID", "FAMILY_ID", abi.FamilyIDSize, report.GetFamilyId(), options.FamilyID),
145145
validateByteField("ImageID", "IMAGE_ID", abi.ImageIDSize, report.GetImageId(), options.ImageID),

0 commit comments

Comments
 (0)