This is an automated email from the ASF dual-hosted git repository.

mssun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave.git


The following commit(s) were added to refs/heads/master by this push:
     new a651983  [Fix] DCap service error. (#586)
a651983 is described below

commit a65198300a9f2b71c216bbb3e5020ec7e4ac94a4
Author: Zhaofeng Chen <[email protected]>
AuthorDate: Thu Dec 9 21:53:48 2021 -0800

    [Fix] DCap service error. (#586)
    
    Co-authored-by: Zhaofeng Chen <[email protected]>
---
 dcap/src/main.rs | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/dcap/src/main.rs b/dcap/src/main.rs
index 4db9f62..6b3bdac 100644
--- a/dcap/src/main.rs
+++ b/dcap/src/main.rs
@@ -151,6 +151,10 @@ impl<'r> response::Responder<'r> for 
QuoteVerificationResponse {
     }
 }
 
+lazy_static! {
+    static ref GLOBAL_MUTEX: std::sync::Mutex<i32> = 
std::sync::Mutex::new(0i32);
+}
+
 #[post(
     "/sgx/dev/attestation/v4/report",
     format = "application/json",
@@ -176,27 +180,31 @@ fn verify_quote(request: String) -> 
QuoteVerificationResponse {
         rng.fill_bytes(&mut nonce.rand);
         qve_report_info.nonce = nonce;
         let mut expiration_check_date: time_t = 0;
-        let ret = unsafe {
-            sgx_qv_verify_quote(
-                quote.as_ptr(),
-                quote.len() as _,
-                std::ptr::null() as _,
-                libc::time(&mut expiration_check_date),
-                &mut collateral_exp_status as _,
-                &mut quote_verification_result as _,
-                &mut qve_report_info as _,
-                0,
-                std::ptr::null_mut(),
-            )
+
+        let ret = {
+            let _lock = GLOBAL_MUTEX.lock();
+            unsafe {
+                sgx_qv_verify_quote(
+                    quote.as_ptr(),
+                    quote.len() as _,
+                    std::ptr::null() as _,
+                    libc::time(&mut expiration_check_date),
+                    &mut collateral_exp_status as _,
+                    &mut quote_verification_result as _,
+                    &mut qve_report_info as _,
+                    0,
+                    std::ptr::null_mut(),
+                )
+            }
         };
 
         if ret != sgx_quote3_error_t::SGX_QL_SUCCESS {
-            eprintln!("sgx_qv_verify_quote fialed: {:?}", ret);
+            eprintln!("sgx_qv_verify_quote failed: {:?}", ret);
             return QuoteVerificationResponse::BadRequest;
         };
 
         if collateral_exp_status != 0 {
-            eprintln!("collateral_exp_status fialed: {:?}", 
collateral_exp_status);
+            eprintln!("collateral_exp_status failed: {:?}", 
collateral_exp_status);
             return QuoteVerificationResponse::BadRequest;
         }
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to