Skip to content
Permalink
Browse files

Generate *_enclave.so instead of *.enclave.so for the convenience of (#…

  • Loading branch information
rdzhou authored and mssun committed Dec 21, 2019
1 parent ba888c4 commit 2d43429a24ed61d5d7f19e1ae40f5b84353ade71
@@ -119,9 +119,8 @@ 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)
sgxlib_pkgname_2_modname(${_pkg_name} _mod_name)
add_sgx_build_target(${_pkg_path} ${_pkg_name}
DEPENDS prep "${SGXAPP_PREFIX}-${_mod_name}" pycomponent
DEPENDS prep pycomponent
INSTALL_DIR ${MESATEE_INSTALL_DIR}/${_category}
)
endforeach()
@@ -24,8 +24,8 @@ function(init_submodules)
)
endfunction()

macro(sgxlib_pkgname_2_modname pkg_name mod_name)
string(REGEX REPLACE "_enclave$" "" ${mod_name} ${pkg_name})
macro(rm_trailing_enclave src_str dest_name)
string(REGEX REPLACE "_enclave$" "" ${dest_name} ${src_str})
endmacro()

# add_cargo_build_target(package_name
@@ -122,7 +122,7 @@ function(add_cargo_build_dylib_target package_name)
)
endfunction()

# add_sgx_build_target(sgx_lib_path
# add_sgx_build_target(sgx_lib_path pkg_name
# [DEPENDS [dep]...]
# [INSTALL_DIR dir]
# [EXTRA_CARGO_FLAGS flg...]
@@ -146,25 +146,24 @@ function(add_sgx_build_target sgx_lib_path pkg_name)
set(_copy_dir ${MESATEE_INSTALL_DIR})
endif()

# remove trailing "_enclave" to get _module_name
sgxlib_pkgname_2_modname(${pkg_name} _module_name)
rm_trailing_enclave(${pkg_name} pkg_name_no_enclave)

set(_target_name ${SGXLIB_PREFIX}-${_module_name})
set(_target_name ${SGXLIB_PREFIX}-${pkg_name_no_enclave})

if(_module_name STREQUAL "functional_test")
if(pkg_name_no_enclave STREQUAL "functional_test")
set(_enclave_info "/dev/null")
else()
set(_enclave_info "${MESATEE_OUT_DIR}/${_module_name}_enclave_info.toml")
set(_enclave_info "${MESATEE_OUT_DIR}/${pkg_name}_info.toml")
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}
--target-dir ${TRUSTED_TARGET_DIR} ${CARGO_BUILD_FLAGS} ${SGX_ENCLAVE_FEATURES} ${MTEE_EXTRA_CARGO_FLAGS}
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
CUR_PKG_NAME=${pkg_name} CUR_PKG_PATH=${sgx_lib_path} CUR_INSTALL_DIR=${_copy_dir} ${MT_SCRIPT_DIR}/sgx_link_sign.sh
${_depends}
COMMAND cat ${MESATEE_OUT_DIR}/${_module_name}.enclave.meta.txt | python ${MT_SCRIPT_DIR}/gen_enclave_info_toml.py ${_module_name} > ${_enclave_info}
COMMAND cat ${MESATEE_OUT_DIR}/${pkg_name}.meta.txt | python ${MT_SCRIPT_DIR}/gen_enclave_info_toml.py ${pkg_name_no_enclave} > ${_enclave_info}
COMMENT "Building ${_target_name}, enclave info to ${_enclave_info}"
WORKING_DIRECTORY ${MT_SGXLIB_TOML_DIR}
)
@@ -201,7 +200,7 @@ function(generate_env_file)
list(FILTER envs INCLUDE REGEX "MESATEE_PROJECT_ROOT|MESATEE_CFG_DIR|\
MESATEE_BUILD_CFG_DIR|MESATEE_OUT_DIR|MESATEE_AUDITORS_DIR")
# add extra env vars
list(APPEND envs "MESATEE_TEST_MODE=1" "RUST_LOG=info" "RUST_BACKTRACE=1")
list(APPEND envs "RUST_LOG=info" "RUST_BACKTRACE=1")
join_string("${envs}" "\nexport " env_file)
string(PREPEND env_file "export ")
string(APPEND env_file "\n")
@@ -17,6 +17,7 @@ add_custom_target(check
COMMAND RUSTUP_TOOLCHAIN=${RUSTUP_TOOLCHAIN} find ${MESATEE_PROJECT_ROOT}
-path ${MESATEE_PROJECT_ROOT}/third_party -prune -o
-path ${MESATEE_PROJECT_ROOT}/.git -prune -o
-path ${MESATEE_BUILD_ROOT} -prune -o
-name "*.rs" -exec rustfmt --check {} +
COMMENT "Checking the format of every .rs file"
DEPENDS prep
@@ -1,17 +1,18 @@
#!/bin/bash
set -e
REQUIRED_ENVS=("CMAKE_C_COMPILER" "CUR_MODULE_NAME" "CUR_MODULE_PATH"
REQUIRED_ENVS=("CMAKE_C_COMPILER" "CUR_PKG_NAME" "CUR_PKG_PATH"
"CUR_INSTALL_DIR" "MESATEE_OUT_DIR" "MESATEE_PROJECT_ROOT" "Service_Library_Name"
"SGX_COMMON_CFLAGS" "SGX_ENCLAVE_SIGNER" "SGX_LIBRARY_PATH" "TARGET" "Trts_Library_Name"
"TRUSTED_TARGET_DIR")
for var in "${REQUIRED_ENVS[@]}"; do
[ -z "${!var}" ] && echo "Please set ${var}" && exit -1
done

LIBENCLAVE_PATH="${TRUSTED_TARGET_DIR}/${TARGET}/lib${CUR_MODULE_NAME}_enclave.a"
CONFIG_PATH="${MESATEE_PROJECT_ROOT}/${CUR_MODULE_PATH}/Enclave.config.xml"
SIGNED_PATH="${CUR_INSTALL_DIR}/${CUR_MODULE_NAME}.enclave.signed.so"
CUR_ENCLAVE_INFO_PATH="${MESATEE_OUT_DIR}/${CUR_MODULE_NAME}_enclave_info.toml"
LIBENCLAVE_PATH="${TRUSTED_TARGET_DIR}/${TARGET}/lib${CUR_PKG_NAME}.a"
CONFIG_PATH="${MESATEE_PROJECT_ROOT}/${CUR_PKG_PATH}/Enclave.config.xml"
SIGNED_PATH="${CUR_INSTALL_DIR}/${CUR_PKG_NAME}.signed.so"
CUR_ENCLAVE_INFO_PATH="${MESATEE_OUT_DIR}/${CUR_PKG_NAME}_info.toml"

if [ ! "$LIBENCLAVE_PATH" -nt "$SIGNED_PATH" ] \
&& [ ! "$CONFIG_PATH" -nt "$SIGNED_PATH" ] \
&& [ ! "$SIGNED_PATH" -nt "$CUR_ENCLAVE_INFO_PATH" ]; then
@@ -20,21 +21,21 @@ if [ ! "$LIBENCLAVE_PATH" -nt "$SIGNED_PATH" ] \
fi
cd ${MESATEE_OUT_DIR}
${CMAKE_C_COMPILER} libEnclave_t.o -o \
${MESATEE_OUT_DIR}/${CUR_MODULE_NAME}.enclave.so ${SGX_COMMON_CFLAGS} \
${MESATEE_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} \
-Wl,--no-whole-archive -Wl,--start-group \
-l${Service_Library_Name} -lsgx_tprotected_fs -lsgx_tkey_exchange \
-lsgx_tstdc -lsgx_tcxx -lsgx_tservice -lsgx_tcrypto \
-L${MESATEE_OUT_DIR} -lpycomponent ffi.o -lpypy-c -lsgx_tlibc_ext -lffi \
-L${TRUSTED_TARGET_DIR}/${TARGET} -l${CUR_MODULE_NAME}_enclave -Wl,--end-group \
-L${TRUSTED_TARGET_DIR}/${TARGET} -l${CUR_PKG_NAME} -Wl,--end-group \
-Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \
-Wl,-pie,-eenclave_entry -Wl,--export-dynamic \
-Wl,--defsym,__ImageBase=0 \
-Wl,--gc-sections \
-Wl,--version-script=${MESATEE_PROJECT_ROOT}/cmake/scripts/Enclave.lds
${SGX_ENCLAVE_SIGNER} sign -key ${MESATEE_PROJECT_ROOT}/keys/enclave_signing_key.pem \
-enclave ${CUR_MODULE_NAME}.enclave.so \
-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
-enclave ${CUR_PKG_NAME}.so \
-out ${CUR_INSTALL_DIR}/${CUR_PKG_NAME}.signed.so \
-config ${MESATEE_PROJECT_ROOT}/${CUR_PKG_PATH}/Enclave.config.xml \
-dumpfile ${CUR_PKG_NAME}.meta.txt > /dev/null 2>&1
@@ -95,6 +95,5 @@ help set the variables. Below is the description for the environment variables:
* ``MESATEE_BUILD_CFG_DIR``: directory containing the compile time config
* `MESATEE_SOTRAGE_DIR`: directory for TDFS data storage, default is `/tmp`
* ``MESATEE_AUDITORS_DIR``: directory containing auditors' public keys and endorsement to TEE enclaves (digital signatures)
* ``MESATEE_TEST_MODE``: whether executing in testing mode
* ``RUST_LOG``: logging levels
* ``RUST_BACKTRACE``: whether to enable backtrace logging on crash
@@ -57,15 +57,12 @@ pub mod config;
#[cfg(feature = "mesalock_sgx")]
pub fn init_service(name: &str) -> Result<()> {
use std::backtrace;
env_logger::init();

debug!("Enclave [{}]: Initializing...", name);

env_logger::init();
if backtrace::enable_backtrace(
format!("{}.enclave.signed.so", name),
backtrace::PrintFormat::Full,
)
.is_err()
if backtrace::enable_backtrace(format!("{}.signed.so", name), backtrace::PrintFormat::Full)
.is_err()
{
error!("Cannot enable backtrace");
return Err(Error::from(ErrorKind::ECallError));
@@ -31,7 +31,7 @@ use teaclave_binder::TeeBinder;
fn main() -> Result<()> {
env_logger::init();

let tee = match TeeBinder::new("acs", 1) {
let tee = match TeeBinder::new(env!("CARGO_PKG_NAME"), 1) {
Ok(r) => {
info!("Init TEE Successfully!");
r
@@ -31,7 +31,7 @@ use teaclave_binder::TeeBinder;
fn main() -> Result<()> {
env_logger::init();

let tee = match TeeBinder::new("fns", 1) {
let tee = match TeeBinder::new(env!("CARGO_PKG_NAME"), 1) {
Ok(r) => {
info!("Init TEE Successfully!");
r
@@ -34,7 +34,7 @@ use mesatee_core::prelude::*;
fn main() -> Result<()> {
env_logger::init();

let tee = match TeeBinder::new("tms", 1) {
let tee = match TeeBinder::new(env!("CARGO_PKG_NAME"), 1) {
Ok(r) => {
info!("Init TEE Successfully!");
r
@@ -28,7 +28,7 @@ use mesatee_core::ipc::protos::ECallCommand;
use mesatee_core::ipc::IpcSender;
use mesatee_core::Result;

static ENCLAVE_FILE_SUFFIX: &str = "enclave.signed.so";
static ENCLAVE_FILE_SUFFIX: &str = "_enclave.signed.so";

use std::sync::Arc;
#[derive(Clone)]
@@ -100,7 +100,7 @@ fn init_enclave(enclave_name: &str, debug_launch: i32) -> Result<SgxEnclave> {
misc_select: 0,
};

let enclave_file = format!("{}.{}", enclave_name, ENCLAVE_FILE_SUFFIX);
let enclave_file = format!("{}{}", enclave_name, ENCLAVE_FILE_SUFFIX);

let enclave = SgxEnclave::create(
enclave_file,
@@ -58,7 +58,7 @@ fn test_from_unstrusted() {
}

fn test_in_tee() -> Result<()> {
let tee = match TeeBinder::new("functional_test", 1) {
let tee = match TeeBinder::new(env!("CARGO_PKG_NAME"), 1) {
Ok(r) => {
info!("Init TEE Successfully!");
r

0 comments on commit 2d43429

Please sign in to comment.
You can’t perform that action at this time.