/
type.go
93 lines (81 loc) · 2.99 KB
/
type.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"fmt"
"strconv"
)
type QuoteReport struct {
ID string `json:"id"`
Timestamp string `json:"timestamp"`
Version int `json:"version"`
IsvEnclaveQuoteStatus string `json:"isvEnclaveQuoteStatus"`
PlatformInfoBlob string `json:"platformInfoBlob"`
IsvEnclaveQuoteBody string `json:"isvEnclaveQuoteBody"`
}
//TODO: add more origin field if needed
type QuoteReportData struct {
version int
signType int
reportBody QuoteReportBody
}
//TODO: add more origin filed if needed
type QuoteReportBody struct {
mrEnclave string
mrSigner string
reportData string
}
type PlatformInfoBlob struct {
Sgx_epid_group_flags uint8 `json:"sgx_epid_group_flags"`
Sgx_tcb_evaluation_flags uint32 `json:"sgx_tcb_evaluation_flags"`
Pse_evaluation_flags uint32 `json:"pse_evaluation_flags"`
Latest_equivalent_tcb_psvn string `json:"latest_equivalent_tcb_psvn"`
Latest_pse_isvsvn string `json:"latest_pse_isvsvn"`
Latest_psda_svn string `json:"latest_psda_svn"`
Xeid uint32 `json:"xeid"`
Gid uint32 `json:"gid"`
Sgx_ec256_signature_t SGXEC256Signature `json:"sgx_ec256_signature_t"`
}
type SGXEC256Signature struct {
Gx string `json:"gx"`
Gy string `json:"gy"`
}
// directly read from []byte
func parseReport(quoteBytes []byte, quoteHex string) *QuoteReportData {
qrData := &QuoteReportData{reportBody: QuoteReportBody{}}
qrData.version = int(quoteBytes[0])
qrData.signType = int(quoteBytes[2])
qrData.reportBody.mrEnclave = quoteHex[224:288]
qrData.reportBody.mrSigner = quoteHex[352:416]
qrData.reportBody.reportData = quoteHex[736:864]
return qrData
}
// directly read from []byte
func parsePlatform(piBlobByte []byte) *PlatformInfoBlob {
piBlob := &PlatformInfoBlob{Sgx_ec256_signature_t: SGXEC256Signature{}}
piBlob.Sgx_epid_group_flags = uint8(piBlobByte[0])
piBlob.Sgx_tcb_evaluation_flags = computeDec(piBlobByte[1:3])
piBlob.Pse_evaluation_flags = computeDec(piBlobByte[3:5])
piBlob.Latest_equivalent_tcb_psvn = bytesToString(piBlobByte[5:23])
piBlob.Latest_pse_isvsvn = bytesToString(piBlobByte[23:25])
piBlob.Latest_psda_svn = bytesToString(piBlobByte[25:29])
piBlob.Xeid = computeDec(piBlobByte[29:33])
piBlob.Gid = computeDec(piBlobByte[33:37])
piBlob.Sgx_ec256_signature_t.Gx = bytesToString(piBlobByte[37:69])
piBlob.Sgx_ec256_signature_t.Gy = bytesToString(piBlobByte[69:])
return piBlob
}
func computeDec(piBlobSlice []byte) uint32 {
var hexString string
for i := len(piBlobSlice)-1; i >= 0; i-- {
hexString += fmt.Sprintf("%02x", piBlobSlice[i])
}
s, _ := strconv.ParseInt(hexString, 16, 32)
return uint32(s)
}
func bytesToString(byteSlice []byte) string {
var byteString string
for i := 0; i < len(byteSlice); i++ {
byteString += strconv.Itoa(int(byteSlice[i])) + ", "
}
byteString = "[" + byteString[:len(byteString)-2] + "]"
return byteString
}