1
2
3
4 package main
5
6 import (
7 "encoding/hex"
8 "flag"
9 "fmt"
10 "os"
11
12 "github.com/Microsoft/hcsshim/internal/tools/snp-report/fake"
13 "github.com/Microsoft/hcsshim/pkg/amdsevsnp"
14 )
15
16
17 func verboseReport(r amdsevsnp.Report) string {
18 fieldNameFmt := "%-20s"
19 pretty := ""
20 pretty += fmt.Sprintf(fieldNameFmt+"%08x\n", "Version", r.Version)
21 pretty += fmt.Sprintf(fieldNameFmt+"%08x\n", "GuestSVN", r.GuestSVN)
22 pretty += fmt.Sprintf(fieldNameFmt+"%016x\n", "Policy", r.Policy)
23 pretty += fmt.Sprintf(fieldNameFmt+"%s\n", "FamilyID", r.FamilyID)
24 pretty += fmt.Sprintf(fieldNameFmt+"%s\n", "ImageID", r.ImageID)
25 pretty += fmt.Sprintf(fieldNameFmt+"%08x\n", "VMPL", r.VMPL)
26 pretty += fmt.Sprintf(fieldNameFmt+"%08x\n", "SignatureAlgo", r.SignatureAlgo)
27 pretty += fmt.Sprintf(fieldNameFmt+"%016x\n", "PlatformVersion", r.PlatformVersion)
28 pretty += fmt.Sprintf(fieldNameFmt+"%016x\n", "PlatformInfo", r.PlatformInfo)
29 pretty += fmt.Sprintf(fieldNameFmt+"%08x\n", "AuthorKeyEn", r.AuthorKeyEn)
30 pretty += fmt.Sprintf(fieldNameFmt+"%s\n", "ReportData", r.ReportData)
31 pretty += fmt.Sprintf(fieldNameFmt+"%s\n", "Measurement", r.Measurement)
32 pretty += fmt.Sprintf(fieldNameFmt+"%x\n", "HostData", r.HostData)
33 pretty += fmt.Sprintf(fieldNameFmt+"%s\n", "IDKeyDigest", r.IDKeyDigest)
34 pretty += fmt.Sprintf(fieldNameFmt+"%s\n", "AuthorKeyDigest", r.AuthorKeyDigest)
35 pretty += fmt.Sprintf(fieldNameFmt+"%s\n", "ReportID", r.ReportID)
36 pretty += fmt.Sprintf(fieldNameFmt+"%s\n", "ReportIDMA", r.ReportIDMA)
37 pretty += fmt.Sprintf(fieldNameFmt+"%016x\n", "ReportTCB", r.ReportTCB)
38 pretty += fmt.Sprintf(fieldNameFmt+"%s\n", "ChipID", r.ChipID)
39 pretty += fmt.Sprintf(fieldNameFmt+"%s\n", "CommittedSVN", r.CommittedSVN)
40 pretty += fmt.Sprintf(fieldNameFmt+"%s\n", "CommittedVersion", r.CommittedVersion)
41 pretty += fmt.Sprintf(fieldNameFmt+"%s\n", "LaunchSVN", r.LaunchSVN)
42 pretty += fmt.Sprintf(fieldNameFmt+"%s\n", "Signature", r.Signature)
43 return pretty
44 }
45
46 func main() {
47 fakeReportFlag := flag.Bool(
48 "fake-report",
49 false,
50 "If true, don't issue an actual syscall to /dev/sev and return a fake predefined report",
51 )
52 hostDataFlag := flag.String(
53 "host-data",
54 "",
55 "Use together with 'fake-report', to set 'HostData' field of fake SNP report.",
56 )
57 reportDataFlag := flag.String(
58 "report-data",
59 "",
60 "Report data to use when fetching SNP attestation report",
61 )
62 binaryFmtFlag := flag.Bool(
63 "binary",
64 false,
65 "Fetch report in binary format",
66 )
67 verbosePrintFlag := flag.Bool(
68 "verbose",
69 false,
70 "Print report in a prettier format",
71 )
72
73 flag.Parse()
74
75 var reportBytes []byte
76 if *reportDataFlag != "" {
77 var err error
78 reportBytes, err = hex.DecodeString(*reportDataFlag)
79 if err != nil {
80 fmt.Printf("failed to decode report data:%s\n", err)
81 os.Exit(1)
82 }
83 }
84 if *binaryFmtFlag {
85 var binaryReport []byte
86 var err error
87 if *fakeReportFlag {
88 binaryReport, err = fake.FetchRawSNPReport()
89 } else {
90 binaryReport, err = amdsevsnp.FetchRawSNPReport(reportBytes)
91 }
92 if err != nil {
93 fmt.Println(err)
94 os.Exit(1)
95 }
96 fmt.Printf("%x\n", binaryReport)
97 os.Exit(0)
98 }
99
100 var report amdsevsnp.Report
101 var err error
102 if *fakeReportFlag {
103 report, err = fake.FetchSNPReport(*hostDataFlag)
104 } else {
105 report, err = amdsevsnp.FetchParsedSNPReport(reportBytes)
106 }
107 if err != nil {
108 fmt.Printf("failed to fetch SNP report: %s", err)
109 os.Exit(1)
110 }
111
112 if !*verbosePrintFlag {
113 fmt.Printf("%+v\n", report)
114 } else {
115 fmt.Println(verboseReport(report))
116 }
117 }
118
View as plain text