diff --git a/internal/guest/snp/fake_report.go b/internal/guest/snp/fake_report.go index 3d012ab5ca..8ecfdc00ec 100644 --- a/internal/guest/snp/fake_report.go +++ b/internal/guest/snp/fake_report.go @@ -32,5 +32,5 @@ func FetchFakeSNPReport(hostData string) (Report, error) { if hostData != "" { copy(fakeRaw.HostData[:], hostData) } - return convertRawReport(&fakeRaw), nil + return fakeRaw.report(), nil } diff --git a/internal/guest/snp/report.go b/internal/guest/snp/report.go index 403a97e6f8..f15a2654e1 100644 --- a/internal/guest/snp/report.go +++ b/internal/guest/snp/report.go @@ -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. @@ -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) @@ -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