@@ -15,7 +15,16 @@ use crate::registration::attestation::create_attestation_report;
15
15
use crate :: registration:: cert:: verify_quote_status;
16
16
17
17
#[ cfg( feature = "SGX_MODE_HW" ) ]
18
- use crate :: registration:: offchain:: get_attestation_report_dcap;
18
+ use crate :: registration:: attestation:: get_quote_ecdsa_untested;
19
+
20
+ #[ cfg( feature = "SGX_MODE_HW" ) ]
21
+ use crate :: registration:: attestation:: verify_quote_ecdsa;
22
+
23
+ #[ cfg( feature = "SGX_MODE_HW" ) ]
24
+ use enclave_utils:: storage:: write_to_untrusted;
25
+
26
+ #[ cfg( feature = "SGX_MODE_HW" ) ]
27
+ use crate :: sgx_types:: sgx_ql_qv_result_t;
19
28
20
29
#[ cfg( not( feature = "epid_whitelist_disabled" ) ) ]
21
30
use crate :: registration:: cert:: check_epid_gid_is_whitelisted;
@@ -35,11 +44,37 @@ pub unsafe extern "C" fn ecall_check_patch_level(
35
44
panic ! ( "unimplemented" )
36
45
}
37
46
38
- /// # Safety
39
- /// Don't forget to check the input length of api_key_len
40
- #[ no_mangle]
41
47
#[ cfg( feature = "SGX_MODE_HW" ) ]
42
- pub unsafe extern "C" fn ecall_check_patch_level (
48
+ unsafe fn check_patch_level_dcap ( pub_k : & [ u8 ; 32 ] ) -> NodeAuthResult {
49
+ match get_quote_ecdsa_untested ( pub_k) {
50
+ Ok ( ( vec_quote, vec_coll) ) => {
51
+ match verify_quote_ecdsa ( & vec_quote, & vec_coll, 0 ) {
52
+ Ok ( r) => {
53
+ if r. 1 != sgx_ql_qv_result_t:: SGX_QL_QV_RESULT_OK {
54
+ println ! ( "WARNING: {}" , r. 1 ) ;
55
+ }
56
+
57
+ println ! ( "DCAP attestation obtained and verified ok" ) ;
58
+ return NodeAuthResult :: Success ;
59
+ }
60
+ Err ( e) => {
61
+ println ! ( "DCAP quote obtained, but failed to verify it: {}" , e) ;
62
+
63
+ let _ = write_to_untrusted ( & vec_quote, "dcap_quote.bin" ) ;
64
+ let _ = write_to_untrusted ( & vec_coll, "dcap_collateral.bin" ) ;
65
+ }
66
+ } ;
67
+ }
68
+ Err ( e) => {
69
+ println ! ( "Failed to obtain DCAP attestation: {}" , e) ;
70
+ }
71
+ }
72
+ NodeAuthResult :: InvalidCert
73
+ }
74
+
75
+ #[ cfg( feature = "SGX_MODE_HW" ) ]
76
+ unsafe fn check_patch_level_epid (
77
+ pub_k : & [ u8 ; 32 ] ,
43
78
api_key : * const u8 ,
44
79
api_key_len : u32 ,
45
80
) -> NodeAuthResult {
@@ -51,29 +86,14 @@ pub unsafe extern "C" fn ecall_check_patch_level(
51
86
52
87
let api_key_slice = slice:: from_raw_parts ( api_key, api_key_len as usize ) ;
53
88
54
- // CREATE THE ATTESTATION REPORT
55
- // generate temporary key for attestation
56
- let temp_key_result = enclave_crypto:: KeyPair :: new ( ) . unwrap ( ) ;
57
-
58
- let res_dcap = unsafe { get_attestation_report_dcap ( & temp_key_result) } ;
59
- if res_dcap. is_ok ( ) {
60
- println ! ( "DCAP attestation ok" ) ;
61
- return NodeAuthResult :: Success ;
62
- }
63
-
64
- let signed_report = match create_attestation_report (
65
- & temp_key_result. get_pubkey ( ) ,
66
- SIGNATURE_TYPE ,
67
- api_key_slice,
68
- None ,
69
- true ,
70
- ) {
71
- Ok ( r) => r,
72
- Err ( _e) => {
73
- error ! ( "Error creating attestation report" ) ;
74
- return NodeAuthResult :: InvalidCert ;
75
- }
76
- } ;
89
+ let signed_report =
90
+ match create_attestation_report ( pub_k, SIGNATURE_TYPE , api_key_slice, None , true ) {
91
+ Ok ( r) => r,
92
+ Err ( _e) => {
93
+ error ! ( "Error creating attestation report" ) ;
94
+ return NodeAuthResult :: InvalidCert ;
95
+ }
96
+ } ;
77
97
78
98
let payload: String = serde_json:: to_string ( & signed_report)
79
99
. map_err ( |_| {
@@ -151,3 +171,26 @@ pub unsafe extern "C" fn ecall_check_patch_level(
151
171
_ => NodeAuthResult :: Success ,
152
172
}
153
173
}
174
+
175
+ /// # Safety
176
+ /// Don't forget to check the input length of api_key_len
177
+ #[ no_mangle]
178
+ #[ cfg( feature = "SGX_MODE_HW" ) ]
179
+ pub unsafe extern "C" fn ecall_check_patch_level (
180
+ api_key : * const u8 ,
181
+ api_key_len : u32 ,
182
+ ) -> NodeAuthResult {
183
+ let temp_key_result = enclave_crypto:: KeyPair :: new ( ) . unwrap ( ) ;
184
+
185
+ let res1 = check_patch_level_dcap ( & temp_key_result. get_pubkey ( ) ) ;
186
+ let res2 = check_patch_level_epid ( & temp_key_result. get_pubkey ( ) , api_key, api_key_len) ;
187
+
188
+ println ! ( "DCAP attestation: {}" , res1) ;
189
+ println ! ( "EPID attestation: {}" , res2) ;
190
+
191
+ if NodeAuthResult :: Success == res1 {
192
+ return res1;
193
+ }
194
+
195
+ res2
196
+ }
0 commit comments