-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathert.go
More file actions
153 lines (135 loc) · 4.83 KB
/
ert.go
File metadata and controls
153 lines (135 loc) · 4.83 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
Copyright (c) Edgeless Systems GmbH
SPDX-License-Identifier: BUSL-1.1
*/
package quote
import (
"bytes"
"fmt"
"strings"
"github.com/edgelesssys/marblerun/util"
"github.com/google/go-cmp/cmp"
)
// PackageProperties contains the enclave package-specific properties of an OpenEnclave quote
// Either UniqueID or SignerID, ProductID, and SecurityVersion should be specified.
type PackageProperties struct {
// Debug Flag of the Attributes.
Debug bool
// UniqueID is a hash of the enclave (MRENCLAVE).
UniqueID string
// SignerID is a hash of the enclave signer's public key (MRSIGNER).
SignerID string
// ProductID of the package (ISVPRODID).
ProductID *uint64
// SecurityVersion of the package (ISVSVN).
SecurityVersion *uint
// AcceptedTCBStatuses is a list of TCB levels an enclave is allowed to have.
AcceptedTCBStatuses []string
// AcceptedAdvisories is a list of open Intel Security Advisories an enclave is allowed to run on,
// when it reports an SWHardeningNeeded TCB status.
// An empty list allows all advisories.
AcceptedAdvisories []string
}
// InfrastructureProperties contains the infrastructure-specific properties of a SGX DCAP quote.
type InfrastructureProperties struct {
// CPUSVN is the processor model and firmware security version number.
// NOTE: the Intel manual states that CPUSVN "cannot be compared mathematically"
CPUSVN []byte
// QESVN is the quoting Enclave security version number.
QESVN *uint16
// PCESVN is the provisioning Certification Enclave security version number.
PCESVN *uint16
// RootCA is the Certificate of the root Certificate Authority (not optional).
RootCA []byte
}
// Equal returns true if both packages are equal.
func (p PackageProperties) Equal(other PackageProperties) bool {
if p.Debug != other.Debug || p.UniqueID != other.UniqueID || p.SignerID != other.SignerID {
return false
}
if p.ProductID == nil && other.ProductID != nil || p.ProductID != nil && other.ProductID == nil {
return false
}
if p.ProductID != nil && other.ProductID != nil && *p.ProductID != *other.ProductID {
return false
}
if p.SecurityVersion == nil && other.SecurityVersion != nil || p.SecurityVersion != nil && other.SecurityVersion == nil {
return false
}
if p.SecurityVersion != nil && other.SecurityVersion != nil && *p.SecurityVersion != *other.SecurityVersion {
return false
}
if !util.SliceEqualElements(p.AcceptedAdvisories, other.AcceptedAdvisories) ||
!util.SliceEqualElements(p.AcceptedTCBStatuses, other.AcceptedTCBStatuses) {
return false
}
return true
}
// IsCompliant checks if the given package properties comply with the requirements.
func (p PackageProperties) IsCompliant(given PackageProperties) bool {
if p.Debug != given.Debug {
return false
}
if len(p.UniqueID) > 0 && !strings.EqualFold(p.UniqueID, given.UniqueID) {
return false
}
if len(p.SignerID) > 0 && !strings.EqualFold(p.SignerID, given.SignerID) {
return false
}
if p.ProductID != nil && *p.ProductID != *given.ProductID {
return false
}
if p.SecurityVersion != nil && *p.SecurityVersion > *given.SecurityVersion {
return false
}
return true
}
// String returns a string representation of the package properties.
func (p PackageProperties) String() string {
values := []string{
fmt.Sprintf("Debug: %t", p.Debug),
}
if p.UniqueID != "" {
values = append(values, fmt.Sprintf("UniqueID: %q", p.UniqueID))
}
if p.SignerID != "" {
values = append(values, fmt.Sprintf("SignerID: %q", p.SignerID))
}
if p.ProductID != nil {
values = append(values, fmt.Sprintf("ProductID: %d", *p.ProductID))
}
if p.SecurityVersion != nil {
values = append(values, fmt.Sprintf("SecurityVersion: %d", *p.SecurityVersion))
}
if len(p.AcceptedTCBStatuses) > 0 {
values = append(values, fmt.Sprintf("AcceptedTCBStatuses: %v", p.AcceptedTCBStatuses))
}
if len(p.AcceptedAdvisories) > 0 {
values = append(values, fmt.Sprintf("AcceptedAdvisories: %v", p.AcceptedAdvisories))
}
return fmt.Sprintf("{%s}", strings.Join(values, ", "))
}
// Equal returns true if both infrastructures are equal.
func (p InfrastructureProperties) Equal(other InfrastructureProperties) bool {
if !bytes.Equal(p.CPUSVN, other.CPUSVN) || !bytes.Equal(p.RootCA, other.RootCA) {
return false
}
if p.QESVN == nil && other.QESVN != nil || p.QESVN != nil && other.QESVN == nil {
return false
}
if p.QESVN != nil && other.QESVN != nil && *p.QESVN != *other.QESVN {
return false
}
if p.PCESVN == nil && other.PCESVN != nil || p.PCESVN != nil && other.PCESVN == nil {
return false
}
if p.PCESVN != nil && other.PCESVN != nil && *p.PCESVN != *other.PCESVN {
return false
}
return true
}
// IsCompliant checks if the given infrastructure properties comply with the requirements.
func (p InfrastructureProperties) IsCompliant(given InfrastructureProperties) bool {
// TODO: implement proper logic including SVN comparison
return cmp.Equal(p, given)
}