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

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


The following commit(s) were added to refs/heads/develop by this push:
     new 69d767b  [file_agent] Provide ocall interface to execution service 
(#241)
69d767b is described below

commit 69d767b3d256b4c7b85288f2f18769e21ab4a88f
Author: Zhaofeng Chen <[email protected]>
AuthorDate: Wed Mar 18 23:12:30 2020 -0700

    [file_agent] Provide ocall interface to execution service (#241)
    
    * [file_agent] Customized ocalls for different encalves
    * [3rd_party] Vendor for teaclave_file_agent
    * [file_agent] Customized ocalls for different encalves
    * [clippy] Make clippy happy.
---
 CMakeLists.txt                                |  9 +++--
 cmake/TeaclaveGenVars.cmake                   |  3 +-
 cmake/TeaclaveUtils.cmake                     | 21 +++++++++--
 cmake/scripts/parse_cargo_packages.py         | 20 ++++++++++-
 cmake/scripts/prep.sh                         | 22 ++++++++----
 cmake/scripts/sgx_link_sign.sh                |  8 ++++-
 cmake/scripts/test.sh                         |  6 +++-
 binder/Enclave.edl => edls/Enclave_common.edl |  0
 file_agent/src/lib.rs => edls/Enclave_fa.edl  | 12 +++----
 file_agent/src/agent.rs                       | 50 ++++++---------------------
 file_agent/src/lib.rs                         |  1 -
 services/access_control/app/build.rs          |  2 +-
 services/authentication/app/build.rs          |  2 +-
 services/execution/app/Cargo.toml             |  1 +
 services/execution/app/build.rs               |  2 +-
 services/execution/app/src/main.rs            |  2 ++
 services/execution/enclave/Cargo.toml         |  4 +--
 services/execution/enclave/src/lib.rs         |  2 ++
 services/execution/enclave/src/service.rs     | 35 +++++++++++++++++++
 services/frontend/app/build.rs                |  2 +-
 services/management/app/build.rs              |  2 +-
 services/scheduler/app/build.rs               |  2 +-
 services/storage/app/build.rs                 |  2 +-
 tests/functional/app/build.rs                 |  2 +-
 tests/integration/app/build.rs                |  2 +-
 tests/unit/app/Cargo.toml                     |  1 +
 tests/unit/app/build.rs                       |  2 +-
 tests/unit/app/src/main.rs                    |  2 ++
 third_party/crates-io                         |  2 +-
 types/src/file_agent.rs                       | 35 +++++++++++++++++++
 types/src/lib.rs                              |  2 ++
 31 files changed, 182 insertions(+), 76 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7364cef..60de88c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -61,7 +61,9 @@ parse_cargo_packages(
   CATEGORIES
   SGX_LIB_CATEGORIES
   PKG_PATHS
-  SGX_LIB_PATHS)
+  SGX_LIB_PATHS
+  EDL_NAMES
+  EDL_LIB_NAMES)
 
 include(TeaclaveGenVars)
 
@@ -150,6 +152,7 @@ foreach(_i RANGE ${SGX_LIB_LAST_INDEX})
   list(GET SGX_LIBS ${_i} _pkg_name)
   list(GET SGX_LIB_PATHS ${_i} _pkg_path)
   list(GET SGX_LIB_CATEGORIES ${_i} _category)
+  list(GET EDL_LIB_NAMES ${_i} _edl_lib_name)
   add_sgx_build_target(
     ${_pkg_path}
     ${_pkg_name}
@@ -157,7 +160,9 @@ foreach(_i RANGE ${SGX_LIB_LAST_INDEX})
     prep
     pycomponent
     INSTALL_DIR
-    ${TEACLAVE_INSTALL_DIR}/${_category})
+    ${TEACLAVE_INSTALL_DIR}/${_category}
+    EDL_LIB_NAME
+    ${_edl_lib_name})
 endforeach()
 
 # Teaclave C SDK add_cargo_build_dylib_target(teaclave_sdk_c TARGET_NAME
diff --git a/cmake/TeaclaveGenVars.cmake b/cmake/TeaclaveGenVars.cmake
index 828be94..31dc5b0 100644
--- a/cmake/TeaclaveGenVars.cmake
+++ b/cmake/TeaclaveGenVars.cmake
@@ -30,7 +30,8 @@ set(MT_SCRIPT_DIR ${PROJECT_SOURCE_DIR}/cmake/scripts)
 set(MT_UNIX_TOML_DIR ${PROJECT_BINARY_DIR}/cmake_tomls/unix_app)
 set(MT_SGXLIB_TOML_DIR ${PROJECT_BINARY_DIR}/cmake_tomls/sgx_trusted_lib)
 set(MT_SGXAPP_TOML_DIR ${PROJECT_BINARY_DIR}/cmake_tomls/sgx_untrusted_app)
-set(MT_EDL_FILE ${PROJECT_SOURCE_DIR}/binder/Enclave.edl)
+set(MT_EDL_FILE ${PROJECT_SOURCE_DIR}/edls/Enclave_common.edl 
${PROJECT_SOURCE_DIR}/edls/Enclave_fa.edl)
+join_string("${MT_EDL_FILE}" " " MT_EDL_FILE)
 
 set(SGX_EDGER8R ${SGX_SDK}/bin/x64/sgx_edger8r)
 set(SGX_ENCLAVE_SIGNER ${SGX_SDK}/bin/x64/sgx_sign)
diff --git a/cmake/TeaclaveUtils.cmake b/cmake/TeaclaveUtils.cmake
index f05a38e..85b5bfc 100644
--- a/cmake/TeaclaveUtils.cmake
+++ b/cmake/TeaclaveUtils.cmake
@@ -148,7 +148,7 @@ endfunction()
 # dir] [EXTRA_CARGO_FLAGS flg...] )
 function(add_sgx_build_target sgx_lib_path pkg_name)
   set(options)
-  set(oneValueArgs INSTALL_DIR)
+  set(oneValueArgs INSTALL_DIR EDL_LIB_NAME)
   set(multiValueArgs DEPENDS EXTRA_CARGO_FLAGS)
   cmake_parse_arguments(MTEE "${options}" "${oneValueArgs}" "${multiValueArgs}"
                         ${ARGN})
@@ -165,6 +165,12 @@ function(add_sgx_build_target sgx_lib_path pkg_name)
     set(_copy_dir ${TEACLAVE_INSTALL_DIR})
   endif()
 
+  if(DEFINED MTEE_EDL_LIB_NAME)
+    set(_edl_lib_name ${MTEE_EDL_LIB_NAME})
+  else()
+    set(_edl_lib_name)
+  endif()
+
   rm_trailing_enclave(${pkg_name} pkg_name_no_enclave)
 
   set(_target_name ${SGXLIB_PREFIX}-${pkg_name_no_enclave})
@@ -191,7 +197,7 @@ function(add_sgx_build_target sgx_lib_path pkg_name)
       ${CMAKE_COMMAND} -E env ${TARGET_SGXLIB_ENVS}
       SGX_COMMON_CFLAGS=${STR_SGX_COMMON_CFLAGS} CUR_PKG_NAME=${pkg_name}
       CUR_PKG_PATH=${sgx_lib_path} CUR_INSTALL_DIR=${_copy_dir}
-      ${MT_SCRIPT_DIR}/sgx_link_sign.sh ${_depends}
+      ${MT_SCRIPT_DIR}/sgx_link_sign.sh ${_edl_lib_name} ${_depends}
     COMMAND
       cat ${TEACLAVE_OUT_DIR}/${pkg_name}.meta.txt | python
       ${MT_SCRIPT_DIR}/gen_enclave_info_toml.py ${pkg_name_no_enclave} >
@@ -279,7 +285,7 @@ endfunction()
 
 function(parse_cargo_packages pkg_names)
   set(options)
-  set(oneValueArgs CARGO_TOML_PATH PKG_PATHS CATEGORIES)
+  set(oneValueArgs CARGO_TOML_PATH PKG_PATHS CATEGORIES EDL_NAMES)
   set(multiValueArgs)
 
   cmake_parse_arguments(MTEE "${options}" "${oneValueArgs}" "${multiValueArgs}"
@@ -301,6 +307,15 @@ function(parse_cargo_packages pkg_names)
   string(REGEX REPLACE "\n" ";" _out_list ${_output})
   list(LENGTH _out_list LLEN)
 
+  if(DEFINED MTEE_EDL_NAMES)
+    list(GET _out_list 3 _edl_names)
+    string(REPLACE ":" ";" _edl_names ${_edl_names})
+    set(${MTEE_EDL_NAMES}
+        ${_edl_names}
+        PARENT_SCOPE)
+    dbg_message("${MTEE_EDL_NAMES}=${_edl_names}\n")
+  endif()
+
   if(DEFINED MTEE_CATEGORIES)
     list(GET _out_list 2 _categories)
     string(REPLACE ":" ";" _categories ${_categories})
diff --git a/cmake/scripts/parse_cargo_packages.py 
b/cmake/scripts/parse_cargo_packages.py
index d93ea0d..372b122 100644
--- a/cmake/scripts/parse_cargo_packages.py
+++ b/cmake/scripts/parse_cargo_packages.py
@@ -49,6 +49,7 @@ def parse_package_name(package_toml_path):
 
     return regex.findall(manifest)[0]
 
+
 def pkg_path_2_category(pkg_path):
     """
     Take pkg path and return its category.
@@ -70,6 +71,20 @@ def pkg_path_2_category(pkg_path):
         sys.exit(-1)
 
 
+DEFAULT_EDL_LIB = "Enclave_common_t"
+PKG_NAME_TO_EDL_LIB = {
+        "teaclave_unit_tests_enclave" : "Enclave_fa_t",
+        "teaclave_execution_service_enclave" : "Enclave_fa_t",
+    }
+
+    
+def pkg_name_2_edl_lib_name(pkg_name):
+    """
+    Take pkg_name and return its configured edl libary name, default is 
DEFAULT_EDL_LIB.
+    """
+    return PKG_NAME_TO_EDL_LIB.get(pkg_name, DEFAULT_EDL_LIB)
+
+
 def main():
     """parses Cargo.toml to generate a list of package to be built"""
     if len(sys.argv) < 3:
@@ -83,6 +98,7 @@ def main():
     pkg_names = []
     pkg_paths = []
     pkg_categories = []
+    edl_lib_names = []
 
     members = parse_members_for_workspace(toml_path)
     for pkg_path in members:
@@ -92,8 +108,10 @@ def main():
         pkg_names.append(pkg_name)
         pkg_paths.append(pkg_path)
         pkg_categories.append(pkg_path_2_category(pkg_path))
+        edl_lib_names.append(pkg_name_2_edl_lib_name(pkg_name))
 
-    out = [":".join(pkg_names), ":".join(pkg_paths), ":".join(pkg_categories)]
+    out = [":".join(pkg_names), ":".join(pkg_paths),
+           ":".join(pkg_categories), ":".join(edl_lib_names)]
     sys.stdout.write("\n".join(out))
 
 
diff --git a/cmake/scripts/prep.sh b/cmake/scripts/prep.sh
index 70ef2fe..820b137 100755
--- a/cmake/scripts/prep.sh
+++ b/cmake/scripts/prep.sh
@@ -7,6 +7,7 @@ REQUIRED_ENVS=("CMAKE_SOURCE_DIR" "CMAKE_BINARY_DIR"
 "TEACLAVE_SERVICE_INSTALL_DIR" "TEACLAVE_EXAMPLE_INSTALL_DIR" 
"TEACLAVE_BIN_INSTALL_DIR"
 "TEACLAVE_CLI_INSTALL_DIR" "TEACLAVE_DCAP_INSTALL_DIR" 
"TEACLAVE_LIB_INSTALL_DIR" "TEACLAVE_TEST_INSTALL_DIR"
 "TEACLAVE_AUDITORS_DIR" "TEACLAVE_EXAMPLE_AUDITORS_DIR" "DCAP" 
"TEACLAVE_SYMLINKS"
+"TEACLAVE_PROJECT_ROOT"
 )
 
 for var in "${REQUIRED_ENVS[@]}"; do
@@ -48,15 +49,22 @@ if [ ! -f ${TEACLAVE_OUT_DIR}/libpypy-c.a ] || [ ! -f 
${TEACLAVE_OUT_DIR}/${MESA
     tar xzf ${MESAPY_VERSION}-mesapy-sgx.tar.gz;
     cd -
 fi
-# build libEnclave_u.a & libEnclave_t.o
-if [ ! -f ${TEACLAVE_OUT_DIR}/libEnclave_u.a ]; then
+# build edl_libs
+if [ ! -f ${TEACLAVE_OUT_DIR}/libEnclave_common_u.a ]; then
     echo 'INFO: Start to build EDL.'
     ${SGX_EDGER8R} --untrusted ${MT_EDL_FILE} --search-path ${SGX_SDK}/include 
\
-        --search-path ${RUST_SGX_SDK}/edl --untrusted-dir ${TEACLAVE_OUT_DIR}
+        --search-path ${RUST_SGX_SDK}/edl --search-path 
${TEACLAVE_PROJECT_ROOT}/edls \
+        --untrusted-dir ${TEACLAVE_OUT_DIR}
     cd ${TEACLAVE_OUT_DIR}
-    ${CMAKE_C_COMPILER} ${SGX_UNTRUSTED_CFLAGS} -c Enclave_u.c -o 
libEnclave_u.o
-    ${CMAKE_AR} rcsD libEnclave_u.a libEnclave_u.o
+    ${CMAKE_C_COMPILER} ${SGX_UNTRUSTED_CFLAGS} -c Enclave_common_u.c -o 
libEnclave_common_u.o
+    ${CMAKE_AR} rcsD libEnclave_common_u.a libEnclave_common_u.o
+
+    ${CMAKE_C_COMPILER} ${SGX_UNTRUSTED_CFLAGS} -c Enclave_fa_u.c -o 
libEnclave_fa_u.o
+    ${CMAKE_AR} rcsD libEnclave_fa_u.a libEnclave_fa_u.o
+
     ${SGX_EDGER8R} --trusted ${MT_EDL_FILE} --search-path ${SGX_SDK}/include \
-        --search-path ${RUST_SGX_SDK}/edl --trusted-dir ${TEACLAVE_OUT_DIR}
-    ${CMAKE_C_COMPILER} ${SGX_TRUSTED_CFLAGS} -c Enclave_t.c -o libEnclave_t.o
+        --search-path ${RUST_SGX_SDK}/edl --search-path 
${TEACLAVE_PROJECT_ROOT}/edls \
+        --trusted-dir ${TEACLAVE_OUT_DIR}
+    ${CMAKE_C_COMPILER} ${SGX_TRUSTED_CFLAGS} -c Enclave_common_t.c -o 
libEnclave_common_t.o
+    ${CMAKE_C_COMPILER} ${SGX_TRUSTED_CFLAGS} -c Enclave_fa_t.c -o 
libEnclave_fa_t.o
 fi
diff --git a/cmake/scripts/sgx_link_sign.sh b/cmake/scripts/sgx_link_sign.sh
index 6e60e1a..f332b12 100755
--- a/cmake/scripts/sgx_link_sign.sh
+++ b/cmake/scripts/sgx_link_sign.sh
@@ -8,6 +8,12 @@ for var in "${REQUIRED_ENVS[@]}"; do
     [ -z "${!var}" ] && echo "Please set ${var}" && exit -1
 done
 
+if [ $# -eq 0 ]; then
+    echo "Missing args: \$edl_lib_name."
+    exit 1
+fi
+edl_lib_name="$1"
+
 LIBENCLAVE_PATH="${TRUSTED_TARGET_DIR}/${TARGET}/lib${CUR_PKG_NAME}.a"
 CONFIG_PATH="${TEACLAVE_PROJECT_ROOT}/${CUR_PKG_PATH}/Enclave.config.xml"
 SIGNED_PATH="${CUR_INSTALL_DIR}/${CUR_PKG_NAME}.signed.so"
@@ -21,7 +27,7 @@ if [ ! "$LIBENCLAVE_PATH" -nt "$SIGNED_PATH" ] \
 fi
 
 cd ${TEACLAVE_OUT_DIR}
-${CMAKE_C_COMPILER} libEnclave_t.o -o \
+${CMAKE_C_COMPILER} "lib${edl_lib_name}.o" -o \
     ${TEACLAVE_OUT_DIR}/${CUR_PKG_NAME}.so ${SGX_COMMON_CFLAGS} \
     -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles \
     -L${SGX_LIBRARY_PATH} -Wl,--whole-archive -l${Trts_Library_Name} \
diff --git a/cmake/scripts/test.sh b/cmake/scripts/test.sh
index 1b320c1..c903ea9 100755
--- a/cmake/scripts/test.sh
+++ b/cmake/scripts/test.sh
@@ -23,12 +23,16 @@ echo_title() {
 }
 
 run_unit_tests() {
+  trap cleanup ERR
   pushd ${TEACLAVE_TEST_INSTALL_DIR}
 
+  python ${TEACLAVE_PROJECT_ROOT}/tests/scripts/simple_http_server.py 6789 &
   echo_title "encalve unit tests"
   ./teaclave_unit_tests
 
   popd
+
+  cleanup
 }
 
 cleanup() {
@@ -54,7 +58,7 @@ run_integration_tests() {
         --target-dir ${TEACLAVE_TARGET_DIR}/untrusted
 
   popd
-  
+
   cleanup 
 }
 
diff --git a/binder/Enclave.edl b/edls/Enclave_common.edl
similarity index 100%
rename from binder/Enclave.edl
rename to edls/Enclave_common.edl
diff --git a/file_agent/src/lib.rs b/edls/Enclave_fa.edl
similarity index 82%
copy from file_agent/src/lib.rs
copy to edls/Enclave_fa.edl
index 9ff8d60..5cc1a81 100644
--- a/file_agent/src/lib.rs
+++ b/edls/Enclave_fa.edl
@@ -15,9 +15,9 @@
 // specific language governing permissions and limitations
 // under the License.
 
-#[macro_use]
-extern crate log;
-
-mod agent;
-pub use agent::ocall_handle_file_request;
-pub use agent::{FileAgentRequest, HandleFileCommand, HandleFileInfo};
+enclave {
+    from "Enclave_common.edl" import *;
+    untrusted {
+        uint32_t ocall_handle_file_request([in, size=buf_size] uint8_t 
*in_buf, uint32_t buf_size);
+    };
+};
diff --git a/file_agent/src/agent.rs b/file_agent/src/agent.rs
index 9c33fb9..933cb87 100644
--- a/file_agent/src/agent.rs
+++ b/file_agent/src/agent.rs
@@ -18,12 +18,12 @@
 use futures::future::join_all;
 use futures::TryFutureExt;
 use reqwest;
-use serde::{Deserialize, Serialize};
-use std::path::PathBuf;
 use tokio::io::AsyncWriteExt;
 use tokio_util::codec;
 use url::Url;
 
+use teaclave_types::{FileAgentRequest, HandleFileCommand, HandleFileInfo};
+
 async fn download_remote_input_to_file(
     presigned_url: Url,
     dest: impl AsRef<std::path::Path>,
@@ -80,41 +80,9 @@ async fn upload_output_file_to_remote(
     }
 }
 
-#[derive(Debug, Serialize, Deserialize)]
-pub struct HandleFileInfo {
-    local: PathBuf,
-    remote: url::Url,
-}
-impl HandleFileInfo {
-    pub fn new(local: impl AsRef<std::path::Path>, remote: &url::Url) -> Self {
-        HandleFileInfo {
-            local: local.as_ref().to_owned(),
-            remote: remote.to_owned(),
-        }
-    }
-}
-
-#[derive(Debug, Serialize, Deserialize)]
-pub enum HandleFileCommand {
-    Download,
-    Upload,
-}
-
-#[derive(Debug, Serialize, Deserialize)]
-pub struct FileAgentRequest {
-    pub cmd: HandleFileCommand,
-    pub info: Vec<HandleFileInfo>,
-}
-
-impl FileAgentRequest {
-    pub fn new(cmd: HandleFileCommand, info: Vec<HandleFileInfo>) -> Self {
-        FileAgentRequest { cmd, info }
-    }
-}
-
 async fn handle_download(info: HandleFileInfo) -> anyhow::Result<()> {
     anyhow::ensure!(
-        info.local.exists() == false,
+        !info.local.exists(),
         "[Download] Dest local file: {:?} already exists.",
         info.local
     );
@@ -159,7 +127,7 @@ async fn handle_upload(info: HandleFileInfo) -> 
anyhow::Result<()> {
                 .to_file_path()
                 .map_err(|e| anyhow::anyhow!("Cannot convert to path: {:?}", 
e))?;
             anyhow::ensure!(
-                dst.exists() == false,
+                !dst.exists(),
                 "[Download] Dest local file: {:?} already exist.",
                 dst
             );
@@ -199,8 +167,8 @@ fn handle_file_request(bytes: &[u8]) -> anyhow::Result<()> {
 
     let (task_results, errs): (Vec<_>, Vec<_>) = 
results.into_iter().partition(Result::is_ok);
 
-    error!("{:?}, errs: {:?}", task_results, errs);
-    if errs.len() > 0 {
+    debug!("{:?}, errs: {:?}", task_results, errs);
+    if !errs.is_empty() {
         anyhow::bail!("Spawned task join error!");
     }
     anyhow::ensure!(
@@ -211,8 +179,9 @@ fn handle_file_request(bytes: &[u8]) -> anyhow::Result<()> {
 }
 
 #[no_mangle]
-pub extern "C" fn ocall_handle_file_request(in_buf: *const u8, in_len: usize) 
-> u32 {
-    let input_buf: &[u8] = unsafe { std::slice::from_raw_parts(in_buf, in_len) 
};
+#[allow(clippy::not_unsafe_ptr_arg_deref)]
+pub extern "C" fn ocall_handle_file_request(in_buf: *const u8, in_len: u32) -> 
u32 {
+    let input_buf: &[u8] = unsafe { std::slice::from_raw_parts(in_buf, in_len 
as usize) };
     match handle_file_request(input_buf) {
         Ok(_) => 0,
         Err(_) => 1,
@@ -223,6 +192,7 @@ pub extern "C" fn ocall_handle_file_request(in_buf: *const 
u8, in_len: usize) ->
 mod tests {
     use super::*;
     use std::io::Write;
+    use std::path::PathBuf;
     use url::Url;
 
     #[test]
diff --git a/file_agent/src/lib.rs b/file_agent/src/lib.rs
index 9ff8d60..0dd97b2 100644
--- a/file_agent/src/lib.rs
+++ b/file_agent/src/lib.rs
@@ -20,4 +20,3 @@ extern crate log;
 
 mod agent;
 pub use agent::ocall_handle_file_request;
-pub use agent::{FileAgentRequest, HandleFileCommand, HandleFileInfo};
diff --git a/services/access_control/app/build.rs 
b/services/access_control/app/build.rs
index b92afb5..dfb54b2 100644
--- a/services/access_control/app/build.rs
+++ b/services/access_control/app/build.rs
@@ -36,7 +36,7 @@ fn main() {
     let out_dir = &PathBuf::from(out_path);
 
     println!("cargo:rustc-link-search=native={}", out_dir.display());
-    println!("cargo:rustc-link-lib=static=Enclave_u");
+    println!("cargo:rustc-link-lib=static=Enclave_common_u");
 
     let is_sim = match env::var("SGX_MODE") {
         Ok(ref v) if v == "SW" => true,
diff --git a/services/authentication/app/build.rs 
b/services/authentication/app/build.rs
index b92afb5..dfb54b2 100644
--- a/services/authentication/app/build.rs
+++ b/services/authentication/app/build.rs
@@ -36,7 +36,7 @@ fn main() {
     let out_dir = &PathBuf::from(out_path);
 
     println!("cargo:rustc-link-search=native={}", out_dir.display());
-    println!("cargo:rustc-link-lib=static=Enclave_u");
+    println!("cargo:rustc-link-lib=static=Enclave_common_u");
 
     let is_sim = match env::var("SGX_MODE") {
         Ok(ref v) if v == "SW" => true,
diff --git a/services/execution/app/Cargo.toml 
b/services/execution/app/Cargo.toml
index f2a34c8..819c8ea 100644
--- a/services/execution/app/Cargo.toml
+++ b/services/execution/app/Cargo.toml
@@ -17,5 +17,6 @@ libc        = { version = "0.2.66" }
 teaclave_binder            = { path = "../../../binder", features = ["app"] }
 teaclave_config            = { path = "../../../config" }
 teaclave_types             = { path = "../../../types" }
+teaclave_file_agent        = { path = "../../../file_agent" }
 
 sgx_types = { version = "1.1.0" }
diff --git a/services/execution/app/build.rs b/services/execution/app/build.rs
index b92afb5..3881e6a 100644
--- a/services/execution/app/build.rs
+++ b/services/execution/app/build.rs
@@ -36,7 +36,7 @@ fn main() {
     let out_dir = &PathBuf::from(out_path);
 
     println!("cargo:rustc-link-search=native={}", out_dir.display());
-    println!("cargo:rustc-link-lib=static=Enclave_u");
+    println!("cargo:rustc-link-lib=static=Enclave_fa_u");
 
     let is_sim = match env::var("SGX_MODE") {
         Ok(ref v) if v == "SW" => true,
diff --git a/services/execution/app/src/main.rs 
b/services/execution/app/src/main.rs
index d90122c..cb11098 100644
--- a/services/execution/app/src/main.rs
+++ b/services/execution/app/src/main.rs
@@ -26,6 +26,8 @@ use teaclave_types::TeeServiceResult;
 
 const PACKAGE_NAME: &str = env!("CARGO_PKG_NAME");
 
+pub use teaclave_file_agent::ocall_handle_file_request;
+
 fn register_signals(term: Arc<AtomicBool>) -> Result<()> {
     for signal in &[
         signal_hook::SIGTERM,
diff --git a/services/execution/enclave/Cargo.toml 
b/services/execution/enclave/Cargo.toml
index b282bf3..296b052 100644
--- a/services/execution/enclave/Cargo.toml
+++ b/services/execution/enclave/Cargo.toml
@@ -33,8 +33,8 @@ serde_json    = { version = "1.0.39" }
 serde         = { version = "1.0.92", features = ["derive"] }
 thiserror     = { version = "1.0.9" }
 gbdt          = { version = "0.1.0", features = ["input", "enable_training"] }
-uuid      = { version = "0.8.1", features = ["v4"] }
-url       = { version = "2.1.1", features = ["serde"]}
+uuid          = { version = "0.8.1", features = ["v4"] }
+url           = { version = "2.1.1", features = ["serde"]}
 
 teaclave_attestation           = { path = "../../../attestation" }
 teaclave_config                = { path = "../../../config" }
diff --git a/services/execution/enclave/src/lib.rs 
b/services/execution/enclave/src/lib.rs
index a21c37e..f4fcbfb 100644
--- a/services/execution/enclave/src/lib.rs
+++ b/services/execution/enclave/src/lib.rs
@@ -17,6 +17,7 @@
 
 #![cfg_attr(feature = "mesalock_sgx", no_std)]
 #[cfg(feature = "mesalock_sgx")]
+#[macro_use]
 extern crate sgx_tstd as std;
 
 #[cfg(feature = "mesalock_sgx")]
@@ -100,6 +101,7 @@ pub mod tests {
 
     pub fn run_tests() -> bool {
         run_tests!(
+            service::tests::test_ocall,
             service::tests::test_invoke_echo_function,
             service::tests::test_invoke_gbdt_training,
             service::tests::test_invoke_gbdt_prediction
diff --git a/services/execution/enclave/src/service.rs 
b/services/execution/enclave/src/service.rs
index 48430f4..24d64c4 100644
--- a/services/execution/enclave/src/service.rs
+++ b/services/execution/enclave/src/service.rs
@@ -101,13 +101,48 @@ mod test_mode {
 #[cfg(feature = "enclave_unit_test")]
 pub mod tests {
     use super::*;
+    use sgx_types::sgx_status_t::SGX_SUCCESS;
+    use sgx_types::*;
     use std::collections::HashMap;
     use std::convert::TryInto;
     use std::format;
+    use std::path::PathBuf;
     use std::vec;
     use teaclave_types::*;
     use url::Url;
     use uuid::Uuid;
+    extern "C" {
+        fn ocall_handle_file_request(
+            p_retval: *mut u32,
+            in_buf: *const u8,
+            in_len: u32,
+        ) -> sgx_status_t;
+    }
+
+    fn handle_file_request(bytes: Vec<u8>) -> anyhow::Result<()> {
+        let mut rt: u32 = 2;
+        let buf_len = bytes.len();
+        let res =
+            unsafe { ocall_handle_file_request(&mut rt as _, bytes.as_ptr() as 
_, buf_len as u32) };
+
+        anyhow::ensure!(res == SGX_SUCCESS, "ocall sgx_error = {:?}", res);
+        anyhow::ensure!(rt == 0, "ocall error = {:?}", rt);
+        Ok(())
+    }
+
+    pub fn test_ocall() {
+        let s = "http://localhost:6789/fixtures/functions/mesapy/input.txt";;
+        let url = Url::parse(s).unwrap();
+        let dest = PathBuf::from("/tmp/execution_input_test.txt");
+
+        let info = HandleFileInfo::new(&dest, &url);
+        let req = FileAgentRequest::new(HandleFileCommand::Download, 
vec![info]);
+
+        let bytes = serde_json::to_vec(&req).unwrap();
+
+        handle_file_request(bytes).unwrap();
+        std::untrusted::fs::remove_file(&dest).unwrap();
+    }
 
     pub fn test_invoke_gbdt_training() {
         let function_args = TeaclaveFunctionArguments::new(&hashmap!(
diff --git a/services/frontend/app/build.rs b/services/frontend/app/build.rs
index b92afb5..dfb54b2 100644
--- a/services/frontend/app/build.rs
+++ b/services/frontend/app/build.rs
@@ -36,7 +36,7 @@ fn main() {
     let out_dir = &PathBuf::from(out_path);
 
     println!("cargo:rustc-link-search=native={}", out_dir.display());
-    println!("cargo:rustc-link-lib=static=Enclave_u");
+    println!("cargo:rustc-link-lib=static=Enclave_common_u");
 
     let is_sim = match env::var("SGX_MODE") {
         Ok(ref v) if v == "SW" => true,
diff --git a/services/management/app/build.rs b/services/management/app/build.rs
index b92afb5..dfb54b2 100644
--- a/services/management/app/build.rs
+++ b/services/management/app/build.rs
@@ -36,7 +36,7 @@ fn main() {
     let out_dir = &PathBuf::from(out_path);
 
     println!("cargo:rustc-link-search=native={}", out_dir.display());
-    println!("cargo:rustc-link-lib=static=Enclave_u");
+    println!("cargo:rustc-link-lib=static=Enclave_common_u");
 
     let is_sim = match env::var("SGX_MODE") {
         Ok(ref v) if v == "SW" => true,
diff --git a/services/scheduler/app/build.rs b/services/scheduler/app/build.rs
index b92afb5..dfb54b2 100644
--- a/services/scheduler/app/build.rs
+++ b/services/scheduler/app/build.rs
@@ -36,7 +36,7 @@ fn main() {
     let out_dir = &PathBuf::from(out_path);
 
     println!("cargo:rustc-link-search=native={}", out_dir.display());
-    println!("cargo:rustc-link-lib=static=Enclave_u");
+    println!("cargo:rustc-link-lib=static=Enclave_common_u");
 
     let is_sim = match env::var("SGX_MODE") {
         Ok(ref v) if v == "SW" => true,
diff --git a/services/storage/app/build.rs b/services/storage/app/build.rs
index b92afb5..dfb54b2 100644
--- a/services/storage/app/build.rs
+++ b/services/storage/app/build.rs
@@ -36,7 +36,7 @@ fn main() {
     let out_dir = &PathBuf::from(out_path);
 
     println!("cargo:rustc-link-search=native={}", out_dir.display());
-    println!("cargo:rustc-link-lib=static=Enclave_u");
+    println!("cargo:rustc-link-lib=static=Enclave_common_u");
 
     let is_sim = match env::var("SGX_MODE") {
         Ok(ref v) if v == "SW" => true,
diff --git a/tests/functional/app/build.rs b/tests/functional/app/build.rs
index b92afb5..dfb54b2 100644
--- a/tests/functional/app/build.rs
+++ b/tests/functional/app/build.rs
@@ -36,7 +36,7 @@ fn main() {
     let out_dir = &PathBuf::from(out_path);
 
     println!("cargo:rustc-link-search=native={}", out_dir.display());
-    println!("cargo:rustc-link-lib=static=Enclave_u");
+    println!("cargo:rustc-link-lib=static=Enclave_common_u");
 
     let is_sim = match env::var("SGX_MODE") {
         Ok(ref v) if v == "SW" => true,
diff --git a/tests/integration/app/build.rs b/tests/integration/app/build.rs
index b92afb5..dfb54b2 100644
--- a/tests/integration/app/build.rs
+++ b/tests/integration/app/build.rs
@@ -36,7 +36,7 @@ fn main() {
     let out_dir = &PathBuf::from(out_path);
 
     println!("cargo:rustc-link-search=native={}", out_dir.display());
-    println!("cargo:rustc-link-lib=static=Enclave_u");
+    println!("cargo:rustc-link-lib=static=Enclave_common_u");
 
     let is_sim = match env::var("SGX_MODE") {
         Ok(ref v) if v == "SW" => true,
diff --git a/tests/unit/app/Cargo.toml b/tests/unit/app/Cargo.toml
index 5b43a97..5319795 100644
--- a/tests/unit/app/Cargo.toml
+++ b/tests/unit/app/Cargo.toml
@@ -12,6 +12,7 @@ log        = { version = "0.4.6" }
 env_logger = { version = "0.7.1" }
 anyhow     = { version = "1.0.26" }
 
+teaclave_file_agent        = { path = "../../../file_agent" }
 teaclave_binder            = { path = "../../../binder", features = ["app"] }
 teaclave_types             = { path = "../../../types" }
 
diff --git a/tests/unit/app/build.rs b/tests/unit/app/build.rs
index b92afb5..3881e6a 100644
--- a/tests/unit/app/build.rs
+++ b/tests/unit/app/build.rs
@@ -36,7 +36,7 @@ fn main() {
     let out_dir = &PathBuf::from(out_path);
 
     println!("cargo:rustc-link-search=native={}", out_dir.display());
-    println!("cargo:rustc-link-lib=static=Enclave_u");
+    println!("cargo:rustc-link-lib=static=Enclave_fa_u");
 
     let is_sim = match env::var("SGX_MODE") {
         Ok(ref v) if v == "SW" => true,
diff --git a/tests/unit/app/src/main.rs b/tests/unit/app/src/main.rs
index 95b545f..16fd76c 100644
--- a/tests/unit/app/src/main.rs
+++ b/tests/unit/app/src/main.rs
@@ -21,6 +21,8 @@ use teaclave_binder::proto::{ECallCommand, RunTestInput, 
RunTestOutput};
 use teaclave_binder::TeeBinder;
 use teaclave_types::TeeServiceResult;
 
+pub use teaclave_file_agent::ocall_handle_file_request;
+
 fn main() -> anyhow::Result<()> {
     env_logger::init();
     let tee = TeeBinder::new(env!("CARGO_PKG_NAME"))?;
diff --git a/third_party/crates-io b/third_party/crates-io
index 1203ee3..659ebc2 160000
--- a/third_party/crates-io
+++ b/third_party/crates-io
@@ -1 +1 @@
-Subproject commit 1203ee3e1ce444f34bfce9d6d970ad20aa73bf23
+Subproject commit 659ebc25178e946081f10a8482e7ab9f846e8795
diff --git a/types/src/file_agent.rs b/types/src/file_agent.rs
new file mode 100644
index 0000000..042fbcd
--- /dev/null
+++ b/types/src/file_agent.rs
@@ -0,0 +1,35 @@
+use serde::{Deserialize, Serialize};
+use std::path::PathBuf;
+use std::prelude::v1::*;
+
+#[derive(Debug, Serialize, Deserialize)]
+pub enum HandleFileCommand {
+    Download,
+    Upload,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct FileAgentRequest {
+    pub cmd: HandleFileCommand,
+    pub info: Vec<HandleFileInfo>,
+}
+
+impl FileAgentRequest {
+    pub fn new(cmd: HandleFileCommand, info: Vec<HandleFileInfo>) -> Self {
+        FileAgentRequest { cmd, info }
+    }
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct HandleFileInfo {
+    pub local: PathBuf,
+    pub remote: url::Url,
+}
+impl HandleFileInfo {
+    pub fn new(local: impl AsRef<std::path::Path>, remote: &url::Url) -> Self {
+        HandleFileInfo {
+            local: local.as_ref().to_owned(),
+            remote: remote.to_owned(),
+        }
+    }
+}
diff --git a/types/src/lib.rs b/types/src/lib.rs
index 969bb9a..7c1a01b 100644
--- a/types/src/lib.rs
+++ b/types/src/lib.rs
@@ -29,6 +29,8 @@ mod storage;
 pub use storage::Storable;
 mod task;
 pub use task::*;
+mod file_agent;
+pub use file_agent::*;
 
 /// Status for Ecall
 #[repr(C)]


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

Reply via email to