@@ -10,7 +10,10 @@ package attestation
10
10
import "C"
11
11
12
12
import (
13
+ "bytes"
14
+ "encoding/json"
13
15
"errors"
16
+ "math"
14
17
"unsafe"
15
18
16
19
"github.com/edgelesssys/ego/attestation/tcbstatus"
@@ -24,6 +27,8 @@ func ParseClaims(claims uintptr, claimsLength uintptr) (Report, error) {
24
27
func parseClaims (claims []C.oe_claim_t ) (Report , error ) {
25
28
report := Report {TCBStatus : tcbstatus .Unknown }
26
29
hasAttributes := false
30
+ var tcbInfo []byte
31
+ var tcbInfoIndex uint = math .MaxUint
27
32
28
33
for _ , claim := range claims {
29
34
switch C .GoString (claim .name ) {
@@ -46,12 +51,17 @@ func parseClaims(claims []C.oe_claim_t) (Report, error) {
46
51
report .TCBStatus = tcbstatus .Status (claimUint (claim ))
47
52
case C .OE_CLAIM_SGX_REPORT_DATA :
48
53
report .Data = claimBytes (claim )
54
+ case C .OE_CLAIM_SGX_TCB_INFO :
55
+ tcbInfo = claimBytes (claim )
56
+ case C .OE_CLAIM_SGX_TCB_INFO_INDEX :
57
+ tcbInfoIndex = claimUint (claim )
49
58
}
50
59
}
51
60
52
61
if ! hasAttributes {
53
62
return Report {}, errors .New ("missing attributes in report claims" )
54
63
}
64
+ report .TCBAdvisories , report .TCBAdvisoriesErr = getAdvisoriesFromTCBInfo (tcbInfo , tcbInfoIndex )
55
65
return report , nil
56
66
}
57
67
@@ -65,3 +75,22 @@ func claimUint(claim C.oe_claim_t) uint {
65
75
func claimBytes (claim C.oe_claim_t ) []byte {
66
76
return C .GoBytes (unsafe .Pointer (claim .value ), C .int (claim .value_size ))
67
77
}
78
+
79
+ func getAdvisoriesFromTCBInfo (tcbInfo []byte , tcbInfoIndex uint ) ([]string , error ) {
80
+ tcbInfo = bytes .Trim (tcbInfo , "\x00 " ) // claim from OE includes null terminator
81
+
82
+ var info struct {
83
+ TCBInfo struct {
84
+ TCBLevels []struct { AdvisoryIDs []string }
85
+ }
86
+ }
87
+ if err := json .Unmarshal (tcbInfo , & info ); err != nil {
88
+ return nil , err
89
+ }
90
+
91
+ levels := info .TCBInfo .TCBLevels
92
+ if uint (len (levels )) <= tcbInfoIndex {
93
+ return nil , errors .New ("invalid TCB info index" )
94
+ }
95
+ return levels [tcbInfoIndex ].AdvisoryIDs , nil
96
+ }
0 commit comments