From 000cd88756b53d267f17667e10d97b78b5a0ab4d Mon Sep 17 00:00:00 2001 From: duanbing Date: Thu, 6 Aug 2020 16:20:02 +0800 Subject: [PATCH] Get quote size dynamiclly --- src/Enclave.edl | 6 ++++++ .../src/util/sgx/sgx_attestation_agent.rs | 18 ++++++++++++++++-- src/pal/src/ocalls/attestation.c | 7 +++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Enclave.edl b/src/Enclave.edl index 48a620a0..cef9a2d6 100644 --- a/src/Enclave.edl +++ b/src/Enclave.edl @@ -208,5 +208,11 @@ enclave { ) propagate_errno; int occlum_ocall_tkill(int tid, int signum) propagate_errno; + + sgx_status_t occlum_ocall_sgx_calc_quote_size ( + [in, size=sig_rl_size] uint8_t * p_sig_rl, + uint32_t sig_rl_size, + [out] uint32_t* p_quote_size + ); }; }; diff --git a/src/libos/src/util/sgx/sgx_attestation_agent.rs b/src/libos/src/util/sgx/sgx_attestation_agent.rs index 6c6231b0..e11cd01c 100644 --- a/src/libos/src/util/sgx/sgx_attestation_agent.rs +++ b/src/libos/src/util/sgx/sgx_attestation_agent.rs @@ -112,6 +112,12 @@ impl InnerAgent { quote_buf_ptr: *mut u8, // Output quote_buf_len: u32, // Input ) -> sgx_status_t; + fn occlum_ocall_sgx_calc_quote_size( + p_retval: *mut sgx_status_t, + p_sig_rl: *const u8, + sig_rl_size: u32, + p_quote_size: *mut u32, + ) -> sgx_status_t; } // Prepare argments for OCall @@ -133,8 +139,16 @@ impl InnerAgent { let report = rsgx_create_report(&self.target_info, report_data) .map_err(|_e| errno!(EINVAL, "sgx_error"))?; let mut qe_report = sgx_report_t::default(); - // TODO: what if quote_buf is not big enough? - let mut quote_buf = [0_u8; 4096]; + let mut quote_len: u32 = 0; + let mut rt = Default::default(); + let status = unsafe { + occlum_ocall_sgx_calc_quote_size(&mut rt as _, sigrl_ptr, sigrl_size, &mut quote_len as _) + }; + assert!(status == sgx_status_t::SGX_SUCCESS); + if rt != sgx_status_t::SGX_SUCCESS { + return_errno!(EINVAL, "occlum_ocall_sgx_calc_quote_size failed"); + } + let mut quote_buf = vec![0_u8; quote_len as usize]; // Do OCall unsafe { diff --git a/src/pal/src/ocalls/attestation.c b/src/pal/src/ocalls/attestation.c index 73c5de54..7cac2070 100644 --- a/src/pal/src/ocalls/attestation.c +++ b/src/pal/src/ocalls/attestation.c @@ -45,3 +45,10 @@ sgx_status_t occlum_ocall_sgx_get_quote( real_quote_len); return ret; } + +sgx_status_t occlum_ocall_sgx_calc_quote_size ( + uint8_t *p_sig_rl, + uint32_t sig_rl_size, + uint32_t *p_quote_size) { + return sgx_calc_quote_size(p_sig_rl, sig_rl_size, p_quote_size); +}