You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@teaclave.apache.org by ms...@apache.org on 2019/12/13 22:13:11 UTC

[incubator-teaclave] branch master updated: [test] Exclude test code in normal build (#151)

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 e8e2098  [test] Exclude test code in normal build (#151)
e8e2098 is described below

commit e8e2098857374937b9fdfee353946005b332cf43
Author: Pei Wang <wa...@baidu.com>
AuthorDate: Fri Dec 13 14:13:02 2019 -0800

    [test] Exclude test code in normal build (#151)
---
 .drone.yml                                         | 24 +++++++++----------
 CMakeLists.txt                                     | 13 ++++++++++-
 cmake/MesaTEEGenVars.cmake                         |  2 +-
 cmake/MesaTEEUtils.cmake                           | 11 ++++++++-
 cmake/UtilTargets.cmake                            |  9 ++++++--
 cmake/scripts/sgx_link_sign.sh                     |  3 ---
 mesatee_core/build.rs                              | 27 ----------------------
 mesatee_core/src/rpc/sgx/mod.rs                    | 25 ++++++--------------
 .../tms/sgx_trusted_lib/src/data_store.rs          |  2 +-
 mesatee_services/tms/sgx_trusted_lib/src/sgx.rs    |  6 +++--
 10 files changed, 54 insertions(+), 68 deletions(-)

diff --git a/.drone.yml b/.drone.yml
index 51519aa..79cb30c 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -7,7 +7,7 @@ steps:
   commands:
   - . /root/.cargo/env
   - mkdir -p build
-  - cd build && cmake -DCMAKE_BUILD_TYPE=Debug ..
+  - cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DTEST_MODE=ON ..
 - name: check
   image: mesalocklinux/mesatee-build-ubuntu-1804:0.1.1
   commands:
@@ -58,7 +58,7 @@ steps:
   commands:
   - . /root/.cargo/env
   - mkdir -p build
-  - cd build && cmake ..
+  - cd build && cmake -DTEST_MODE=ON ..
 - name: check
   image: mesalocklinux/mesatee-build-ubuntu-1804:0.1.1
   commands:
@@ -109,7 +109,7 @@ steps:
   commands:
   - . /root/.cargo/env
   - mkdir -p build
-  - cd build && cmake ..
+  - cd build && cmake -DTEST_MODE=ON ..
 - name: check
   image: mesalocklinux/mesatee-build-ubuntu-1804:0.1.1
   commands:
@@ -119,7 +119,7 @@ steps:
   image: mesalocklinux/mesatee-build-ubuntu-1804:0.1.1
   commands:
   - . /root/.cargo/env
-  - cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DRUSTFLAGS="-D warnings" -DSGX_MODE=SW .. && make VERBOSE=1 -j2
+  - cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DRUSTFLAGS="-D warnings" -DSGX_SIM_MODE=ON .. && make VERBOSE=1 -j2
 - name: sgx-test
   image: mesalocklinux/mesatee-build-ubuntu-1804:0.1.1
   commands:
@@ -154,7 +154,7 @@ steps:
   commands:
   - . /root/.cargo/env
   - mkdir -p build
-  - cd build && cmake ..
+  - cd build && cmake -DTEST_MODE=YES ..
 - name: check
   image: mesalocklinux/mesatee-build-ubuntu-1804:0.1.1
   commands:
@@ -164,7 +164,7 @@ steps:
   image: mesalocklinux/mesatee-build-ubuntu-1804:0.1.1
   commands:
   - . /root/.cargo/env
-  - cd build && cmake -DRUSTFLAGS="-D warnings" -DSGX_MODE=SW .. && make VERBOSE=1 -j2
+  - cd build && cmake -DRUSTFLAGS="-D warnings" -DSGX_SIM_MODE=ON .. && make VERBOSE=1 -j2
 - name: sgx-test
   image: mesalocklinux/mesatee-build-ubuntu-1804:0.1.1
   commands:
@@ -200,7 +200,7 @@ steps:
   commands:
   - . /root/.cargo/env
   - mkdir -p build
-  - cd build && cmake -DCMAKE_BUILD_TYPE=Debug ..
+  - cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DTEST_MODE=ON ..
 - name: check
   image: mesalocklinux/mesatee-build-ubuntu-1604:0.1.1
   commands:
@@ -251,7 +251,7 @@ steps:
   commands:
   - . /root/.cargo/env
   - mkdir -p build
-  - cd build && cmake ..
+  - cd build && cmake -DTEST_MODE=ON ..
 - name: check
   image: mesalocklinux/mesatee-build-ubuntu-1604:0.1.1
   commands:
@@ -302,7 +302,7 @@ steps:
   commands:
   - . /root/.cargo/env
   - mkdir -p build
-  - cd build && cmake ..
+  - cd build && cmake -DTEST_MODE=ON ..
 - name: check
   image: mesalocklinux/mesatee-build-ubuntu-1604:0.1.1
   commands:
@@ -312,7 +312,7 @@ steps:
   image: mesalocklinux/mesatee-build-ubuntu-1604:0.1.1
   commands:
   - . /root/.cargo/env
-  - cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DRUSTFLAGS="-D warnings" -DSGX_MODE=SW .. && make VERBOSE=1 -j2
+  - cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DRUSTFLAGS="-D warnings" -DSGX_SIM_MODE=ON .. && make VERBOSE=1 -j2
 - name: sgx-test
   image: mesalocklinux/mesatee-build-ubuntu-1604:0.1.1
   commands:
@@ -357,7 +357,7 @@ steps:
   image: mesalocklinux/mesatee-build-ubuntu-1604:0.1.1
   commands:
   - . /root/.cargo/env
-  - cd build && cmake -DRUSTFLAGS="-D warnings" -DSGX_MODE=SW .. && make VERBOSE=1 -j2
+  - cd build && cmake -DRUSTFLAGS="-D warnings" -DSGX_SIM_MODE=ON -DTEST_MODE=ON .. && make VERBOSE=1 -j2
 - name: sgx-test
   image: mesalocklinux/mesatee-build-ubuntu-1604:0.1.1
   commands:
@@ -419,7 +419,7 @@ steps:
   commands:
   - . /root/.cargo/env
   - mkdir -p build
-  - cd build && cmake -DCMAKE_BUILD_TYPE=DEBUG -DCOV=1 ..
+  - cd build && cmake -DCMAKE_BUILD_TYPE=DEBUG -DCOV=ON -DTEST_MODE=ON ..
 - name: check
   image: mesalocklinux/mesatee-build-ubuntu-1804:0.1.1
   commands:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 59e81b2..5146388 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,12 +9,23 @@ init_submodules()
 
 # ====== VARIABLES FOR CMAKE -D{VAR}=VAL CONFIGURATION BEGIN ======
 SET_STRVAR_FROM_ENV_OR(SGX_SDK "/opt/sgxsdk" "Path of SGX SDK")
-SET_STRVAR_FROM_ENV_OR(SGX_MODE "HW" "Mode of SGX, HW or SW")
 SET_STRVAR_FROM_ENV_OR(RUSTFLAGS "" "Rust flags")
 SET_STRVAR_FROM_ENV_OR(MESATEE_CMAKE_DBG "" "set to turn on debug message for cmake")
 set(MESAPY_VERSION 2b7ea38773d337d106c613a239661a60a4fa7528)
 option(COV "Turn on/off coverage" OFF)
 option(OFFLINE "Turn on/off cargo offline" ON)
+option(TEST_MODE "Turn on/off test mode" OFF)
+option(SGX_SIM_MODE "Turn on/off sgx simulation mode" OFF)
+
+if(TEST_MODE)
+    set(RUSTFLAGS "${RUSTFLAGS} --cfg test_mode")
+endif()
+if(SGX_SIM_MODE)
+    set(RUSTFLAGS "${RUSTFLAGS} --cfg sgx_sim")
+    set(SGX_MODE "SW")
+else()
+    set(SGX_MODE "HW")
+endif()
 # ======= VARIABLES FOR CMAKE -D{VAR}=VAL CONFIGURATION END =======
 
 # =============== VARIABLES FOR MANUAL CHANGE BEGIN ===============
diff --git a/cmake/MesaTEEGenVars.cmake b/cmake/MesaTEEGenVars.cmake
index 832128a..3fe3d19 100644
--- a/cmake/MesaTEEGenVars.cmake
+++ b/cmake/MesaTEEGenVars.cmake
@@ -59,7 +59,7 @@ if (CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
         check_exe_dependencies(lcov llvm-cov)
         set(SGX_ENCLAVE_FEATURES -Z package-features --features "mesalock_sgx cov")
         set(CARGO_INCREMENTAL 0)
-        set(RUSTFLAGS "-D warnings -Zprofile -Ccodegen-units=1 \
+        set(RUSTFLAGS "${RUSTFLAGS} -D warnings -Zprofile -Ccodegen-units=1 \
 -Cllvm_args=-inline-threshold=0 -Coverflow-checks=off -Zno-landing-pads")
     endif()
 else()
diff --git a/cmake/MesaTEEUtils.cmake b/cmake/MesaTEEUtils.cmake
index 34ef486..2d412de 100644
--- a/cmake/MesaTEEUtils.cmake
+++ b/cmake/MesaTEEUtils.cmake
@@ -151,6 +151,12 @@ function(add_sgx_build_target sgx_lib_path pkg_name)
 
     set(_target_name ${SGXLIB_PREFIX}-${_module_name})
 
+    if(_module_name STREQUAL "functional_test")
+        set(_enclave_info "/dev/null")
+    else()
+        set(_enclave_info "${MESATEE_OUT_DIR}/${_module_name}_enclave_info.txt")
+    endif()
+
     add_custom_target(${_target_name} ALL
         COMMAND ${CMAKE_COMMAND} -E env ${MESATEE_COMMON_ENVS} RUSTFLAGS=${RUSTFLAGS}
             ${MT_SCRIPT_DIR}/cargo_build_ex.sh -p ${pkg_name}
@@ -158,7 +164,10 @@ function(add_sgx_build_target sgx_lib_path pkg_name)
         COMMAND ${CMAKE_COMMAND} -E env ${TARGET_SGXLIB_ENVS} SGX_COMMON_CFLAGS=${STR_SGX_COMMON_CFLAGS}
             CUR_MODULE_NAME=${_module_name} CUR_MODULE_PATH=${sgx_lib_path} CUR_INSTALL_DIR=${_copy_dir} ${MT_SCRIPT_DIR}/sgx_link_sign.sh
         ${_depends}
-        COMMENT "Building ${_target_name}"
+        COMMAND echo ${_module_name} > ${_enclave_info}
+        COMMAND grep -m1 -A2 "mrsigner->value" ${MESATEE_OUT_DIR}/${_module_name}.enclave.meta.txt >> ${_enclave_info}
+        COMMAND grep -m1 -A2 "body.enclave_hash" ${MESATEE_OUT_DIR}/${_module_name}.enclave.meta.txt >> ${_enclave_info}
+        COMMENT "Building ${_target_name}, enclave info to ${ENCLAVE_INFO}"
         WORKING_DIRECTORY ${MT_SGXLIB_TOML_DIR}
     )
 endfunction()
diff --git a/cmake/UtilTargets.cmake b/cmake/UtilTargets.cmake
index b3f14ac..8d1351c 100644
--- a/cmake/UtilTargets.cmake
+++ b/cmake/UtilTargets.cmake
@@ -24,8 +24,13 @@ add_custom_target(check
     DEPENDS prep
 )
 
-add_custom_target(sgx-test
-    COMMAND ${MESATEE_COMMON_ENVS} ${MT_SCRIPT_DIR}/sgx_test.sh)
+if(TEST_MODE)
+    add_custom_target(sgx-test
+        COMMAND ${MESATEE_COMMON_ENVS} ${MT_SCRIPT_DIR}/sgx_test.sh)
+else()
+    add_custom_target(sgx-test
+        COMMAND echo "Note: Testing is not enabled in this build. Run cmake again with -DTEST_MODE=ON")
+endif()
 
 add_custom_target(cov
     COMMAND ${MESATEE_COMMON_ENVS} ${MT_SCRIPT_DIR}/gen_cov.sh
diff --git a/cmake/scripts/sgx_link_sign.sh b/cmake/scripts/sgx_link_sign.sh
index bf569ab..a594930 100755
--- a/cmake/scripts/sgx_link_sign.sh
+++ b/cmake/scripts/sgx_link_sign.sh
@@ -38,6 +38,3 @@ ${SGX_ENCLAVE_SIGNER} sign -key ${MESATEE_PROJECT_ROOT}/keys/enclave_signing_key
     -out ${CUR_INSTALL_DIR}/${CUR_MODULE_NAME}.enclave.signed.so \
     -config ${MESATEE_PROJECT_ROOT}/${CUR_MODULE_PATH}/Enclave.config.xml \
     -dumpfile ${CUR_MODULE_NAME}.enclave.meta.txt > /dev/null 2>&1
-echo ${CUR_MODULE_NAME} > ${CUR_MODULE_NAME}_enclave_info.txt
-grep -m1 -A2 "mrsigner->value" ${CUR_MODULE_NAME}.enclave.meta.txt >> ${CUR_MODULE_NAME}_enclave_info.txt
-grep -m1 -A2 "body.enclave_hash" ${CUR_MODULE_NAME}.enclave.meta.txt >> ${CUR_MODULE_NAME}_enclave_info.txt
diff --git a/mesatee_core/build.rs b/mesatee_core/build.rs
deleted file mode 100644
index 0f866c7..0000000
--- a/mesatee_core/build.rs
+++ /dev/null
@@ -1,27 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-use std::env;
-
-fn main() {
-    let is_sim = env::var("SGX_MODE").unwrap_or_else(|_| "HW".to_string());
-
-    match is_sim.as_ref() {
-        "HW" => {}
-        _ => println!("cargo:rustc-cfg=sgx_sim"),
-    }
-}
diff --git a/mesatee_core/src/rpc/sgx/mod.rs b/mesatee_core/src/rpc/sgx/mod.rs
index 6e91a01..68fbacc 100644
--- a/mesatee_core/src/rpc/sgx/mod.rs
+++ b/mesatee_core/src/rpc/sgx/mod.rs
@@ -149,6 +149,12 @@ impl EnclaveAttr {
             Ok(quote) => quote,
         };
 
+        // Enclave measures are not tested in test mode since we have
+        // a dedicated test enclave not known to production enclaves
+        if cfg!(test_mode) {
+            return (self.quote_checker)(&quote);
+        }
+
         let this_mr_signer = &quote.body.report_body.mr_signer;
         let this_mr_enclave = &quote.body.report_body.mr_enclave;
 
@@ -156,24 +162,7 @@ impl EnclaveAttr {
             mr_signer == this_mr_signer && mr_enclave == this_mr_enclave
         });
 
-        if !checksum_match {
-            info!("sgx enclave measure mismatch. try matching with functional_test");
-
-            use crate::config::ENCLAVE_IDENTITIES;
-
-            // TODO: For testing, an enclave called functional_test will communicate
-            // with each MesaTEE component. We have to explicitly add its measures into
-            // the whitelist. Ideally, this piece of code should not materialize in
-            // release build. Find a way to make this configurable.
-            let (test_mr_signer, test_mr_enclave) =
-                ENCLAVE_IDENTITIES.get("functional_test").unwrap();
-            if this_mr_signer != test_mr_signer || this_mr_enclave != test_mr_enclave {
-                error!("sgx enclave measure mismatch");
-                return false;
-            }
-        }
-
-        (self.quote_checker)(&quote)
+        checksum_match && (self.quote_checker)(&quote)
     }
 }
 
diff --git a/mesatee_services/tms/sgx_trusted_lib/src/data_store.rs b/mesatee_services/tms/sgx_trusted_lib/src/data_store.rs
index 45fa41d..93adf5e 100644
--- a/mesatee_services/tms/sgx_trusted_lib/src/data_store.rs
+++ b/mesatee_services/tms/sgx_trusted_lib/src/data_store.rs
@@ -106,7 +106,7 @@ pub fn add_task(task_id: &str, task_info: &TaskInfo) -> Result<()> {
 }
 
 // For API Test, called by enclave_init
-pub fn add_test_infomation() {
+pub fn add_test_information() {
     let fake_task = TaskInfo {
         user_id: "fake".to_string(),
         collaborator_list: Vec::new(),
diff --git a/mesatee_services/tms/sgx_trusted_lib/src/sgx.rs b/mesatee_services/tms/sgx_trusted_lib/src/sgx.rs
index 0181d4c..dd87b0f 100644
--- a/mesatee_services/tms/sgx_trusted_lib/src/sgx.rs
+++ b/mesatee_services/tms/sgx_trusted_lib/src/sgx.rs
@@ -25,7 +25,6 @@ use mesatee_core::Result;
 use env_logger;
 use std::backtrace::{self, PrintFormat};
 
-use crate::data_store::add_test_infomation;
 use crate::tms_external::TMSExternalEnclave;
 use crate::tms_internal::TMSInternalEnclave;
 
@@ -47,7 +46,10 @@ fn handle_init_enclave(_args: &InitEnclaveInput) -> Result<InitEnclaveOutput> {
     );
     mesatee_core::rpc::sgx::prelude();
 
-    add_test_infomation();
+    if cfg!(test_mode) {
+        crate::data_store::add_test_information();
+    }
+
     Ok(InitEnclaveOutput::default())
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org