diff --git a/rust-sgx-workspace/projects/ntc-tee-server/app/Enclave_u.c b/rust-sgx-workspace/projects/ntc-tee-server/app/Enclave_u.c index 8aa839e..e60db95 100644 --- a/rust-sgx-workspace/projects/ntc-tee-server/app/Enclave_u.c +++ b/rust-sgx-workspace/projects/ntc-tee-server/app/Enclave_u.c @@ -933,7 +933,7 @@ static const struct { (void*)Enclave_u_fstatat64_ocall, } }; -sgx_status_t append_data(sgx_enclave_id_t eid, sgx_status_t* retval, const uint8_t* some_string, size_t len) +sgx_status_t append_data(sgx_enclave_id_t eid, sgx_status_t* retval, const uint8_t* pool_one, size_t len) { sgx_status_t status; ms_append_data_t ms; diff --git a/rust-sgx-workspace/projects/ntc-tee-server/app/codegen/Enclave_u.c b/rust-sgx-workspace/projects/ntc-tee-server/app/codegen/Enclave_u.c index 8aa839e..446ab07 100644 --- a/rust-sgx-workspace/projects/ntc-tee-server/app/codegen/Enclave_u.c +++ b/rust-sgx-workspace/projects/ntc-tee-server/app/codegen/Enclave_u.c @@ -3,8 +3,10 @@ typedef struct ms_append_data_t { sgx_status_t ms_retval; - const uint8_t* ms_some_string; + const uint8_t* ms_pool_one; size_t ms_len; + const uint8_t* ms_pool_two; + size_t ms_len_two; } ms_append_data_t; typedef struct ms_t_global_init_ecall_t { @@ -933,12 +935,14 @@ static const struct { (void*)Enclave_u_fstatat64_ocall, } }; -sgx_status_t append_data(sgx_enclave_id_t eid, sgx_status_t* retval, const uint8_t* some_string, size_t len) +sgx_status_t append_data(sgx_enclave_id_t eid, sgx_status_t* retval, const uint8_t* pool_one, size_t len, const uint8_t* pool_two, size_t len_two) { sgx_status_t status; ms_append_data_t ms; - ms.ms_some_string = some_string; + ms.ms_pool_one = pool_one; ms.ms_len = len; + ms.ms_pool_two = pool_two; + ms.ms_len_two = len_two; status = sgx_ecall(eid, 0, &ocall_table_Enclave, &ms); if (status == SGX_SUCCESS && retval) *retval = ms.ms_retval; return status; diff --git a/rust-sgx-workspace/projects/ntc-tee-server/app/codegen/Enclave_u.h b/rust-sgx-workspace/projects/ntc-tee-server/app/codegen/Enclave_u.h index d2ec9fa..2ac6bda 100644 --- a/rust-sgx-workspace/projects/ntc-tee-server/app/codegen/Enclave_u.h +++ b/rust-sgx-workspace/projects/ntc-tee-server/app/codegen/Enclave_u.h @@ -246,7 +246,7 @@ int SGX_UBRIDGE(SGX_NOCONVENTION, u_dirfd_ocall, (int* error, void* dirp)); int SGX_UBRIDGE(SGX_NOCONVENTION, u_fstatat64_ocall, (int* error, int dirfd, const char* pathname, struct stat64_t* buf, int flags)); #endif -sgx_status_t append_data(sgx_enclave_id_t eid, sgx_status_t* retval, const uint8_t* some_string, size_t len); +sgx_status_t append_data(sgx_enclave_id_t eid, sgx_status_t* retval, const uint8_t* pool_one, size_t len, const uint8_t* pool_two, size_t len_two); sgx_status_t t_global_init_ecall(sgx_enclave_id_t eid, uint64_t id, const uint8_t* path, size_t len); sgx_status_t t_global_exit_ecall(sgx_enclave_id_t eid); diff --git a/rust-sgx-workspace/projects/ntc-tee-server/app/codegen/Enclave_u.rs b/rust-sgx-workspace/projects/ntc-tee-server/app/codegen/Enclave_u.rs index 6397a3b..3f10451 100644 --- a/rust-sgx-workspace/projects/ntc-tee-server/app/codegen/Enclave_u.rs +++ b/rust-sgx-workspace/projects/ntc-tee-server/app/codegen/Enclave_u.rs @@ -6,7 +6,9 @@ extern "C" { pub fn append_data( eid: sgx_enclave_id_t, retval: *mut sgx_status_t, - some_string: *const u8, + pool_one: *const u8, len: size_t, + pool_two: *const u8, + len_two: size_t, ) -> sgx_status_t; } diff --git a/rust-sgx-workspace/projects/ntc-tee-server/app/src/main.rs b/rust-sgx-workspace/projects/ntc-tee-server/app/src/main.rs index 5af2f31..76f7b6a 100644 --- a/rust-sgx-workspace/projects/ntc-tee-server/app/src/main.rs +++ b/rust-sgx-workspace/projects/ntc-tee-server/app/src/main.rs @@ -12,8 +12,10 @@ extern "C" { fn append_data( eid: sgx_enclave_id_t, retval: *mut sgx_status_t, - input_string: *const u8, - input_length: usize, + pool_one: *const u8, + pool_one_length: usize, + pool_two: *const u8, + pool_two_length: usize, ) -> sgx_status_t; } @@ -50,7 +52,81 @@ fn main() { }; // Update - send sealed binary data into enclave (from CosmosDB) - let input_string = String::from("Sending this string to the enclave then printing it\n"); + // Test pool 1 - Import existing data pool from CosmosDB + let pool_one = r#" + { + "pool": [ + { + "ID":1, + "Income":109748.717064175, + "Postal":41, + "WalletID":"9173f117-eaf5-443b-a405-c3d5e2aa5d99" + }, + { + "ID":2, + "Income":77356.0675380472, + "Postal":15, + "WalletID":"9f86ae7c-ac1c-4b8e-9daf-bd40ad13e157" + }, + { + "ID":3, + "Income":33746.4377853607, + "Postal":11, + "WalletID":"3e77ee27-b25b-4bcc-b9b8-d7107a633ae9" + }, + { + "ID":4, + "Income":37657.0518817567, + "Postal":48, + "WalletID":"67be8d2b-c31a-44b6-9cb0-6456072d3353" + }, + { + "ID":5, + "Income":27353.1866838295, + "Postal":5, + "WalletID":"412326e0-716a-4233-bae1-4cd199207893" + } + ] + } + "#; + + // Test pool 2 - Import append pool from CosmosDB (Temp data pool) + let pool_two = r#" + { + "pool": [ + { + "ID":6, + "Income":71540.129423949, + "Postal":34, + "WalletID":"dabcbe30-4ed0-4c3b-b6b3-aafb85312963" + }, + { + "ID":7, + "Income":7352.38903575921, + "Postal":41, + "WalletID":"fdcd0caa-48bf-446f-b00f-a90d646f55c3" + }, + { + "ID":8, + "Income":110742.078725787, + "Postal":7, + "WalletID":"f4f5cd1b-c2ad-4587-905d-47237ebdbd89" + }, + { + "ID":9, + "Income":129564.725166652, + "Postal":3, + "WalletID":"7e4e80c4-7e9b-4a6e-8d94-e4f72bde8233" + }, + { + "ID":10, + "Income":2964.80996131516, + "Postal":33, + "WalletID":"ecefdd47-aab3-4595-87f7-cf9bbef46a53" + } + ] + } + "#; let mut retval = sgx_status_t::SGX_SUCCESS; @@ -58,8 +134,10 @@ fn main() { append_data( enclave.geteid(), &mut retval, - input_string.as_ptr() as *const u8, - input_string.len(), + pool_one.as_ptr() as *const u8, + pool_one.len(), + pool_two.as_ptr() as *const u8, + pool_two.len(), ) }; diff --git a/rust-sgx-workspace/projects/ntc-tee-server/enclave/Enclave.edl b/rust-sgx-workspace/projects/ntc-tee-server/enclave/Enclave.edl index a7d8308..093eb62 100644 --- a/rust-sgx-workspace/projects/ntc-tee-server/enclave/Enclave.edl +++ b/rust-sgx-workspace/projects/ntc-tee-server/enclave/Enclave.edl @@ -3,7 +3,7 @@ enclave { from "sgx_backtrace.edl" import *; trusted { - public sgx_status_t append_data([in, size=len] const uint8_t* some_string, size_t len); + public sgx_status_t append_data([in, size=len] const uint8_t* pool_one, size_t len, [in, size=len_two] const uint8_t* pool_two, size_t len_two); }; untrusted { diff --git a/rust-sgx-workspace/projects/ntc-tee-server/enclave/codegen/Enclave_t.c b/rust-sgx-workspace/projects/ntc-tee-server/enclave/codegen/Enclave_t.c index f51b00d..ff0146d 100644 --- a/rust-sgx-workspace/projects/ntc-tee-server/enclave/codegen/Enclave_t.c +++ b/rust-sgx-workspace/projects/ntc-tee-server/enclave/codegen/Enclave_t.c @@ -29,8 +29,10 @@ typedef struct ms_append_data_t { sgx_status_t ms_retval; - const uint8_t* ms_some_string; + const uint8_t* ms_pool_one; size_t ms_len; + const uint8_t* ms_pool_two; + size_t ms_len_two; } ms_append_data_t; typedef struct ms_t_global_init_ecall_t { @@ -456,41 +458,65 @@ static sgx_status_t SGX_CDECL sgx_append_data(void* pms) sgx_lfence(); ms_append_data_t* ms = SGX_CAST(ms_append_data_t*, pms); sgx_status_t status = SGX_SUCCESS; - const uint8_t* _tmp_some_string = ms->ms_some_string; + const uint8_t* _tmp_pool_one = ms->ms_pool_one; size_t _tmp_len = ms->ms_len; - size_t _len_some_string = _tmp_len; - uint8_t* _in_some_string = NULL; + size_t _len_pool_one = _tmp_len; + uint8_t* _in_pool_one = NULL; + const uint8_t* _tmp_pool_two = ms->ms_pool_two; + size_t _tmp_len_two = ms->ms_len_two; + size_t _len_pool_two = _tmp_len_two; + uint8_t* _in_pool_two = NULL; - CHECK_UNIQUE_POINTER(_tmp_some_string, _len_some_string); + CHECK_UNIQUE_POINTER(_tmp_pool_one, _len_pool_one); + CHECK_UNIQUE_POINTER(_tmp_pool_two, _len_pool_two); // // fence after pointer checks // sgx_lfence(); - if (_tmp_some_string != NULL && _len_some_string != 0) { - if ( _len_some_string % sizeof(*_tmp_some_string) != 0) + if (_tmp_pool_one != NULL && _len_pool_one != 0) { + if ( _len_pool_one % sizeof(*_tmp_pool_one) != 0) { status = SGX_ERROR_INVALID_PARAMETER; goto err; } - _in_some_string = (uint8_t*)malloc(_len_some_string); - if (_in_some_string == NULL) { + _in_pool_one = (uint8_t*)malloc(_len_pool_one); + if (_in_pool_one == NULL) { status = SGX_ERROR_OUT_OF_MEMORY; goto err; } - if (memcpy_s(_in_some_string, _len_some_string, _tmp_some_string, _len_some_string)) { + if (memcpy_s(_in_pool_one, _len_pool_one, _tmp_pool_one, _len_pool_one)) { + status = SGX_ERROR_UNEXPECTED; + goto err; + } + + } + if (_tmp_pool_two != NULL && _len_pool_two != 0) { + if ( _len_pool_two % sizeof(*_tmp_pool_two) != 0) + { + status = SGX_ERROR_INVALID_PARAMETER; + goto err; + } + _in_pool_two = (uint8_t*)malloc(_len_pool_two); + if (_in_pool_two == NULL) { + status = SGX_ERROR_OUT_OF_MEMORY; + goto err; + } + + if (memcpy_s(_in_pool_two, _len_pool_two, _tmp_pool_two, _len_pool_two)) { status = SGX_ERROR_UNEXPECTED; goto err; } } - ms->ms_retval = append_data((const uint8_t*)_in_some_string, _tmp_len); + ms->ms_retval = append_data((const uint8_t*)_in_pool_one, _tmp_len, (const uint8_t*)_in_pool_two, _tmp_len_two); err: - if (_in_some_string) free(_in_some_string); + if (_in_pool_one) free(_in_pool_one); + if (_in_pool_two) free(_in_pool_two); return status; } diff --git a/rust-sgx-workspace/projects/ntc-tee-server/enclave/codegen/Enclave_t.h b/rust-sgx-workspace/projects/ntc-tee-server/enclave/codegen/Enclave_t.h index 9d5d35c..722dc1b 100644 --- a/rust-sgx-workspace/projects/ntc-tee-server/enclave/codegen/Enclave_t.h +++ b/rust-sgx-workspace/projects/ntc-tee-server/enclave/codegen/Enclave_t.h @@ -20,7 +20,7 @@ extern "C" { #endif -sgx_status_t append_data(const uint8_t* some_string, size_t len); +sgx_status_t append_data(const uint8_t* pool_one, size_t len, const uint8_t* pool_two, size_t len_two); void t_global_init_ecall(uint64_t id, const uint8_t* path, size_t len); void t_global_exit_ecall(void); diff --git a/rust-sgx-workspace/projects/ntc-tee-server/enclave/src/lib.rs b/rust-sgx-workspace/projects/ntc-tee-server/enclave/src/lib.rs index a0bc329..cb342dc 100644 --- a/rust-sgx-workspace/projects/ntc-tee-server/enclave/src/lib.rs +++ b/rust-sgx-workspace/projects/ntc-tee-server/enclave/src/lib.rs @@ -6,7 +6,6 @@ extern crate sgx_types; extern crate sgx_tstd as std; extern crate serde_json; -use std::io::{self, Write}; use std::slice; use std::string::String; use std::vec::Vec; @@ -15,89 +14,20 @@ use serde_json::Value; use sgx_types::sgx_status_t; /// # Safety -/// Caller needs to ensure that `some_string` points to a valid slice of length `some_len` +/// Caller needs to ensure that `pool_one` points to a valid slice of length `pool_one_len` +/// Caller needs to ensure that `pool_two` points to a valid slice of length `pool_two_len` #[no_mangle] -pub unsafe extern "C" fn append_data(some_string: *const u8, some_len: usize) -> sgx_status_t { - let str_slice = unsafe { slice::from_raw_parts(some_string, some_len) }; - let _ = io::stdout().write(str_slice); +pub unsafe extern "C" fn append_data(pool_one: *const u8, pool_one_len: usize, pool_two: *const u8, pool_two_len: usize) -> sgx_status_t { + let pool_1_slice = unsafe { slice::from_raw_parts(pool_one, pool_one_len) }; + // let _ = io::stdout().write(pool_1_slice); - println!("Message from the enclave"); + let pool_2_slice = unsafe { slice::from_raw_parts(pool_two, pool_two_len) }; + // let _ = io::stdout().write(pool_2_slice); - // Test pool 1 - Import existing data pool from CosmosDB - let json_pool_1 = r#" - { - "pool": [ - { - "ID":1, - "Income":109748.717064175, - "Postal":41, - "WalletID":"9173f117-eaf5-443b-a405-c3d5e2aa5d99" - }, - { - "ID":2, - "Income":77356.0675380472, - "Postal":15, - "WalletID":"9f86ae7c-ac1c-4b8e-9daf-bd40ad13e157" - }, - { - "ID":3, - "Income":33746.4377853607, - "Postal":11, - "WalletID":"3e77ee27-b25b-4bcc-b9b8-d7107a633ae9" - }, - { - "ID":4, - "Income":37657.0518817567, - "Postal":48, - "WalletID":"67be8d2b-c31a-44b6-9cb0-6456072d3353" - }, - { - "ID":5, - "Income":27353.1866838295, - "Postal":5, - "WalletID":"412326e0-716a-4233-bae1-4cd199207893" - } - ] - } - "#; + let json_pool_1 = std::str::from_utf8(&pool_1_slice).unwrap(); + let json_pool_2 = std::str::from_utf8(&pool_2_slice).unwrap(); - // Test pool 2 - Import append pool from CosmosDB (Temp data pool) - let json_pool_2 = r#" - { - "pool": [ - { - "ID":6, - "Income":71540.129423949, - "Postal":34, - "WalletID":"dabcbe30-4ed0-4c3b-b6b3-aafb85312963" - }, - { - "ID":7, - "Income":7352.38903575921, - "Postal":41, - "WalletID":"fdcd0caa-48bf-446f-b00f-a90d646f55c3" - }, - { - "ID":8, - "Income":110742.078725787, - "Postal":7, - "WalletID":"f4f5cd1b-c2ad-4587-905d-47237ebdbd89" - }, - { - "ID":9, - "Income":129564.725166652, - "Postal":3, - "WalletID":"7e4e80c4-7e9b-4a6e-8d94-e4f72bde8233" - }, - { - "ID":10, - "Income":2964.80996131516, - "Postal":33, - "WalletID":"ecefdd47-aab3-4595-87f7-cf9bbef46a53" - } - ] - } - "#; + println!("Message from the enclave"); //Remove let pool_1 = serde_json::from_str::(&json_pool_1).expect("JSON was not well-formatted"); let pool_2 = serde_json::from_str::(&json_pool_2).expect("JSON was not well-formatted");