1
+ use std:: time:: SystemTime ;
2
+
1
3
use crate :: errors:: Error ;
2
4
use attestation_report:: DCAPQuote ;
3
5
use crypto:: Address ;
4
6
use dcap_rs:: types:: collaterals:: IntelCollateral ;
5
7
use dcap_rs:: types:: quotes:: version_3:: QuoteV3 ;
6
8
use dcap_rs:: utils:: cert:: { extract_sgx_extension, parse_certchain, parse_pem} ;
9
+ use dcap_rs:: utils:: quotes:: version_3:: verify_quote_dcapv3;
7
10
use keymanager:: EnclaveKeyManager ;
8
11
use lcp_types:: Time ;
9
12
use log:: * ;
10
13
use sgx_types:: { sgx_qe_get_quote, sgx_qe_get_quote_size, sgx_quote3_error_t, sgx_report_t} ;
11
14
12
- const INTEL_ROOT_CA : & ' static [ u8 ] =
15
+ const INTEL_ROOT_CA : & [ u8 ] =
13
16
include_bytes ! ( "../assets/Intel_SGX_Provisioning_Certification_RootCA.der" ) ;
14
17
15
18
pub fn run_dcap_ra (
@@ -23,8 +26,24 @@ pub fn run_dcap_ra(
23
26
)
24
27
} ) ?;
25
28
let raw_quote = rsgx_qe_get_quote ( & ek_info. report ) . unwrap ( ) ;
29
+ info ! ( "Successfully get the quote: {}" , hex:: encode( & raw_quote) ) ;
30
+
26
31
let quote = QuoteV3 :: from_bytes ( & raw_quote) ;
27
- println ! ( "Successfully get the quote: {:?}" , quote) ;
32
+
33
+ let collateral = get_collateral (
34
+ "https://api.trustedservices.intel.com/" ,
35
+ "https://certificates.trustedservices.intel.com/" ,
36
+ & quote,
37
+ ) ;
38
+ let output = verify_quote_dcapv3 (
39
+ & quote,
40
+ & collateral,
41
+ SystemTime :: now ( )
42
+ . duration_since ( SystemTime :: UNIX_EPOCH )
43
+ . unwrap ( )
44
+ . as_secs ( ) ,
45
+ ) ;
46
+ info ! ( "DCAP RA output: {:?}" , output) ;
28
47
29
48
let current_time = Time :: now ( ) ;
30
49
key_manager
@@ -54,7 +73,7 @@ fn rsgx_qe_get_quote(app_report: &sgx_report_t) -> Result<Vec<u8>, sgx_quote3_er
54
73
}
55
74
}
56
75
57
- async fn get_collateral ( pccs_url : & str , quote : & QuoteV3 ) -> IntelCollateral {
76
+ fn get_collateral ( pccs_url : & str , certs_service_url : & str , quote : & QuoteV3 ) -> IntelCollateral {
58
77
let base_url = format ! ( "{}/sgx/certification/v4" , pccs_url. trim_end_matches( '/' ) ) ;
59
78
info ! ( "base_url: {}" , base_url) ;
60
79
assert_eq ! (
@@ -63,73 +82,58 @@ async fn get_collateral(pccs_url: &str, quote: &QuoteV3) -> IntelCollateral {
63
82
) ;
64
83
let certchain_pems = parse_pem ( & quote. signature . qe_cert_data . cert_data ) . unwrap ( ) ;
65
84
let certchain = parse_certchain ( & certchain_pems) ;
85
+ assert_eq ! ( certchain. len( ) , 3 , "QE Cert chain must have 3 certs" ) ;
66
86
67
87
// get the pck certificate, and check whether issuer common name is valid
68
88
let pck_cert = & certchain[ 0 ] ;
69
89
70
90
// get the SGX extension
71
- let sgx_extensions = extract_sgx_extension ( & pck_cert) ;
91
+ let sgx_extensions = extract_sgx_extension ( pck_cert) ;
72
92
let fmspc = hex:: encode_upper ( sgx_extensions. fmspc ) ;
73
93
74
- let client = reqwest:: Client :: new ( ) ;
75
94
let mut collateral = IntelCollateral :: new ( ) ;
76
95
{
77
- let res = client
78
- . get ( format ! ( "{base_url}/tcb?fmspc={fmspc}" ) )
79
- . send ( )
80
- . await
81
- . unwrap ( ) ;
96
+ let res = reqwest:: blocking:: get ( format ! ( "{base_url}/tcb?fmspc={fmspc}" ) ) . unwrap ( ) ;
82
97
let issuer_chain = extract_raw_certs (
83
98
get_header ( & res, "TCB-Info-Issuer-Chain" )
84
99
. unwrap ( )
85
100
. as_bytes ( ) ,
86
101
)
87
102
. unwrap ( ) ;
88
103
collateral. set_sgx_tcb_signing_der ( & issuer_chain[ 0 ] ) ;
89
- collateral. set_tcbinfo_bytes ( res. bytes ( ) . await . unwrap ( ) . as_ref ( ) ) ;
104
+ collateral. set_tcbinfo_bytes ( res. bytes ( ) . unwrap ( ) . as_ref ( ) ) ;
90
105
}
91
106
92
107
{
93
- let res = client
94
- . get ( format ! ( "{base_url}/qe/identity" ) )
95
- . send ( )
96
- . await
97
- . unwrap ( ) ;
98
- collateral. set_qeidentity_bytes ( res. bytes ( ) . await . unwrap ( ) . as_ref ( ) ) ;
108
+ let res = reqwest:: blocking:: get ( format ! ( "{base_url}/qe/identity" ) ) . unwrap ( ) ;
109
+ collateral. set_qeidentity_bytes ( res. bytes ( ) . unwrap ( ) . as_ref ( ) ) ;
99
110
}
100
111
collateral. set_intel_root_ca_der ( INTEL_ROOT_CA ) ;
101
112
102
113
{
103
- let res = client
104
- . get ( "https://certificates.trustedservices.intel.com/IntelSGXRootCA.der" )
105
- . send ( )
106
- . await
107
- . unwrap ( ) ;
108
- let crl = res. bytes ( ) . await . unwrap ( ) ;
109
- collateral. set_sgx_intel_root_ca_crl_der ( & crl) ;
114
+ let res = reqwest:: blocking:: get ( format ! (
115
+ "{}/IntelSGXRootCA.der" ,
116
+ certs_service_url. trim_end_matches( '/' )
117
+ ) )
118
+ . unwrap ( ) ;
119
+ collateral. set_sgx_intel_root_ca_crl_der ( res. bytes ( ) . unwrap ( ) . as_ref ( ) ) ;
110
120
}
111
121
112
122
{
113
- let res = client
114
- . get ( format ! ( "{base_url}/pckcrl?ca=processor&encoding=der" ) )
115
- . send ( )
116
- . await
117
- . unwrap ( ) ;
118
- collateral. set_sgx_processor_crl_der ( res. bytes ( ) . await . unwrap ( ) . as_ref ( ) ) ;
123
+ let res =
124
+ reqwest:: blocking:: get ( format ! ( "{base_url}/pckcrl?ca=processor&encoding=der" ) ) . unwrap ( ) ;
125
+ collateral. set_sgx_processor_crl_der ( res. bytes ( ) . unwrap ( ) . as_ref ( ) ) ;
119
126
}
120
127
{
121
- let res = client
122
- . get ( format ! ( "{base_url}/pckcrl?ca=platform&encoding=der" ) )
123
- . send ( )
124
- . await
125
- . unwrap ( ) ;
126
- collateral. set_sgx_platform_crl_der ( res. bytes ( ) . await . unwrap ( ) . as_ref ( ) ) ;
128
+ let res =
129
+ reqwest:: blocking:: get ( format ! ( "{base_url}/pckcrl?ca=platform&encoding=der" ) ) . unwrap ( ) ;
130
+ collateral. set_sgx_platform_crl_der ( res. bytes ( ) . unwrap ( ) . as_ref ( ) ) ;
127
131
}
128
132
129
133
collateral
130
134
}
131
135
132
- fn get_header ( res : & reqwest:: Response , name : & str ) -> Result < String , String > {
136
+ fn get_header ( res : & reqwest:: blocking :: Response , name : & str ) -> Result < String , String > {
133
137
let value = res
134
138
. headers ( )
135
139
. get ( name)
@@ -151,22 +155,24 @@ fn extract_raw_certs(cert_chain: &[u8]) -> Result<Vec<Vec<u8>>, Error> {
151
155
152
156
#[ cfg( test) ]
153
157
mod tests {
154
- use std:: time:: SystemTime ;
155
-
156
- use dcap_rs:: utils:: quotes:: version_3:: verify_quote_dcapv3;
157
-
158
158
use super :: * ;
159
+ use dcap_rs:: { constants:: SGX_TEE_TYPE , utils:: quotes:: version_3:: verify_quote_dcapv3} ;
160
+ use std:: time:: SystemTime ;
159
161
160
162
#[ test]
161
163
fn test_quote ( ) {
162
164
QuoteV3 :: from_bytes ( & get_test_quote ( ) ) ;
163
165
}
164
166
165
- #[ tokio :: test]
166
- async fn test_dcap_collateral ( ) {
167
+ #[ test]
168
+ fn test_dcap_collateral ( ) {
167
169
let quote = get_test_quote ( ) ;
168
170
let quote = QuoteV3 :: from_bytes ( & quote) ;
169
- let collateral = get_collateral ( "https://api.trustedservices.intel.com/" , & quote) . await ;
171
+ let collateral = get_collateral (
172
+ "https://api.trustedservices.intel.com/" ,
173
+ "https://certificates.trustedservices.intel.com/" ,
174
+ & quote,
175
+ ) ;
170
176
let output = verify_quote_dcapv3 (
171
177
& quote,
172
178
& collateral,
@@ -175,7 +181,7 @@ mod tests {
175
181
. unwrap ( )
176
182
. as_secs ( ) ,
177
183
) ;
178
- println ! ( "{:?}" , output ) ;
184
+ assert_eq ! ( output . tee_type , SGX_TEE_TYPE ) ;
179
185
}
180
186
181
187
fn get_test_quote ( ) -> Vec < u8 > {
0 commit comments