-
Notifications
You must be signed in to change notification settings - Fork 112
/
quote.go
66 lines (57 loc) · 1.55 KB
/
quote.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
package quote
import (
"fmt"
"time"
"github.com/oasisprotocol/oasis-core/go/common"
"github.com/oasisprotocol/oasis-core/go/common/sgx"
"github.com/oasisprotocol/oasis-core/go/common/sgx/ias"
"github.com/oasisprotocol/oasis-core/go/common/sgx/pcs"
)
// Quote is an unverified SGX remote attestation quote, depending on the attestation scheme.
type Quote struct {
IAS *ias.AVRBundle `json:"ias,omitempty"`
PCS *pcs.QuoteBundle `json:"pcs,omitempty"`
}
// Verify verifies the SGX remote attestation quote.
func (q *Quote) Verify(policy *Policy, ts time.Time) (*sgx.VerifiedQuote, error) {
// Make sure exactly one quote kind is set.
if !common.ExactlyOneTrue(
q.IAS != nil,
q.PCS != nil,
) {
return nil, fmt.Errorf("exactly one quote kind must be set")
}
if policy == nil {
policy = &Policy{}
}
switch {
case q.IAS != nil:
// IAS.
avr, err := q.IAS.Open(policy.IAS, ias.IntelTrustRoots, ts)
if err != nil {
return nil, err
}
// Extract the original ISV quote.
isvQuote, err := avr.Quote()
if err != nil {
return nil, err
}
return &sgx.VerifiedQuote{
ReportData: isvQuote.Report.ReportData[:],
Identity: sgx.EnclaveIdentity{
MrEnclave: isvQuote.Report.MRENCLAVE,
MrSigner: isvQuote.Report.MRSIGNER,
},
}, nil
case q.PCS != nil:
// PCS.
return q.PCS.Verify(policy.PCS, ts)
default:
return nil, fmt.Errorf("exactly one quote kind must be set")
}
}
// Policy is the quote validity policy.
type Policy struct {
IAS *ias.QuotePolicy `json:"ias,omitempty"`
PCS *pcs.QuotePolicy `json:"pcs,omitempty"`
}