Skip to content

Commit

Permalink
pr feedback: change to report()
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim An <maksiman@microsoft.com>
  • Loading branch information
anmaxvl committed Apr 1, 2022
1 parent 3e1ed0c commit d86bdfc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion internal/guest/snp/fake_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ func FetchFakeSNPReport(hostData string) (Report, error) {
if hostData != "" {
copy(fakeRaw.HostData[:], hostData)
}
return convertRawReport(&fakeRaw), nil
return fakeRaw.report(), nil
}
58 changes: 29 additions & 29 deletions internal/guest/snp/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,34 @@ type snpReport struct {
Signature [512]byte
}

func (sr *snpReport) report() Report {
return Report{
Version: sr.Version,
GuestSVN: sr.GuestSVN,
Policy: sr.Policy,
FamilyID: hex.EncodeToString(mirrorBytes(sr.FamilyID[:])[:]),
ImageID: hex.EncodeToString(mirrorBytes(sr.ImageID[:])[:]),
VMPL: sr.VMPL,
SignatureAlgo: sr.SignatureAlgo,
PlatformVersion: sr.PlatformVersion,
PlatformInfo: sr.PlatformInfo,
AuthorKeyEn: sr.AuthorKeyEn,
ReportData: hex.EncodeToString(sr.ReportData[:]),
Measurement: hex.EncodeToString(sr.Measurement[:]),
HostData: hex.EncodeToString(sr.HostData[:]),
IDKeyDigest: hex.EncodeToString(sr.IDKeyDigest[:]),
AuthorKeyDigest: hex.EncodeToString(sr.AuthorKeyDigest[:]),
ReportID: hex.EncodeToString(sr.ReportID[:]),
ReportIDMA: hex.EncodeToString(sr.ReportIDMA[:]),
ReportTCB: sr.ReportTCB,
ChipID: hex.EncodeToString(sr.ChipID[:]),
CommittedSVN: hex.EncodeToString(sr.CommittedSVN[:]),
CommittedVersion: hex.EncodeToString(sr.CommittedVersion[:]),
LaunchSVN: hex.EncodeToString(sr.LaunchSVN[:]),
Signature: hex.EncodeToString(sr.Signature[:]),
}
}

// msgReportResponse is the attestation response struct
// https://www.amd.com/system/files/TechDocs/56860.pdf
// MSG_REPORT_RSP Table 23.
Expand Down Expand Up @@ -255,34 +283,6 @@ func mirrorBytes(b []byte) []byte {
return b
}

func convertRawReport(rawReport *snpReport) Report {
return Report{
Version: rawReport.Version,
GuestSVN: rawReport.GuestSVN,
Policy: rawReport.Policy,
FamilyID: hex.EncodeToString(mirrorBytes(rawReport.FamilyID[:])[:]),
ImageID: hex.EncodeToString(mirrorBytes(rawReport.ImageID[:])[:]),
VMPL: rawReport.VMPL,
SignatureAlgo: rawReport.SignatureAlgo,
PlatformVersion: rawReport.PlatformVersion,
PlatformInfo: rawReport.PlatformInfo,
AuthorKeyEn: rawReport.AuthorKeyEn,
ReportData: hex.EncodeToString(rawReport.ReportData[:]),
Measurement: hex.EncodeToString(rawReport.Measurement[:]),
HostData: hex.EncodeToString(rawReport.HostData[:]),
IDKeyDigest: hex.EncodeToString(rawReport.IDKeyDigest[:]),
AuthorKeyDigest: hex.EncodeToString(rawReport.AuthorKeyDigest[:]),
ReportID: hex.EncodeToString(rawReport.ReportID[:]),
ReportIDMA: hex.EncodeToString(rawReport.ReportIDMA[:]),
ReportTCB: rawReport.ReportTCB,
ChipID: hex.EncodeToString(rawReport.ChipID[:]),
CommittedSVN: hex.EncodeToString(rawReport.CommittedSVN[:]),
CommittedVersion: hex.EncodeToString(rawReport.CommittedVersion[:]),
LaunchSVN: hex.EncodeToString(rawReport.LaunchSVN[:]),
Signature: hex.EncodeToString(rawReport.Signature[:]),
}
}

// FetchParsedSNPReport parses raw attestation response into proper structs.
func FetchParsedSNPReport(reportData string) (Report, error) {
rawBytes, err := FetchRawSNPReport(reportData)
Expand All @@ -295,7 +295,7 @@ func FetchParsedSNPReport(reportData string) (Report, error) {
if err := binary.Read(buf, binary.LittleEndian, &report); err != nil {
return Report{}, err
}
return convertRawReport(&report), nil
return report.report(), nil
}

// ValidateHostData fetches SNP report (if applicable) and validates `hostData` against
Expand Down

0 comments on commit d86bdfc

Please sign in to comment.