@@ -15,7 +15,16 @@ use crate::registration::attestation::create_attestation_report;
1515use crate :: registration:: cert:: verify_quote_status;
1616
1717#[ 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;
1928
2029#[ cfg( not( feature = "epid_whitelist_disabled" ) ) ]
2130use crate :: registration:: cert:: check_epid_gid_is_whitelisted;
@@ -35,11 +44,37 @@ pub unsafe extern "C" fn ecall_check_patch_level(
3544 panic ! ( "unimplemented" )
3645}
3746
38- /// # Safety
39- /// Don't forget to check the input length of api_key_len
40- #[ no_mangle]
4147#[ 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 ] ,
4378 api_key : * const u8 ,
4479 api_key_len : u32 ,
4580) -> NodeAuthResult {
@@ -51,29 +86,14 @@ pub unsafe extern "C" fn ecall_check_patch_level(
5186
5287 let api_key_slice = slice:: from_raw_parts ( api_key, api_key_len as usize ) ;
5388
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+ } ;
7797
7898 let payload: String = serde_json:: to_string ( & signed_report)
7999 . map_err ( |_| {
@@ -151,3 +171,26 @@ pub unsafe extern "C" fn ecall_check_patch_level(
151171 _ => NodeAuthResult :: Success ,
152172 }
153173}
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