######## SGX SDK Settings ######## SGX_SDK ?= /opt/intel/sgxsdk SGX_DEBUG ?= 1 SGX_MODE ?= SIM SGX_ARCH ?= x64 ifeq ($(shell getconf LONG_BIT), 32) SGX_ARCH := x86 else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32) SGX_ARCH := x86 endif ifeq ($(SGX_ARCH), x86) SGX_COMMON_CFLAGS := -m32 SGX_LIBRARY_PATH := $(SGX_SDK)/lib SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x86/sgx_sign SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r else SGX_COMMON_CFLAGS := -m64 SGX_LIBRARY_PATH := $(SGX_SDK)/lib64 SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x64/sgx_sign SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r endif ifeq ($(SGX_DEBUG), 1) ifeq ($(SGX_PRERELEASE), 1) $(error Cannot set SGX_DEBUG and SGX_PRERELEASE at the same time!!) endif endif ifeq ($(SGX_DEBUG), 1) SGX_COMMON_CFLAGS += -O0 -g else SGX_COMMON_CFLAGS += -O2 endif ######## App Settings ######## ifneq ($(SGX_MODE), HW) Urts_Library_Name := sgx_urts_sim Uae_Service_Library_Name := sgx_uae_service_sim else Urts_Library_Name := sgx_urts Uae_Service_Library_Name := sgx_uae_service endif App_Include_Paths := -I$(SGX_SDK)/include App_C_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(App_Include_Paths) # Three configuration modes - Debug, prerelease, release # Debug - Macro DEBUG enabled. # Prerelease - Macro NDEBUG and EDEBUG enabled. # Release - Macro NDEBUG enabled. ifeq ($(SGX_DEBUG), 1) App_C_Flags += -DDEBUG -UNDEBUG -UEDEBUG else ifeq ($(SGX_PRERELEASE), 1) App_C_Flags += -DNDEBUG -DEDEBUG -UDEBUG else App_C_Flags += -DNDEBUG -UEDEBUG -UDEBUG endif App_Cpp_Flags := $(App_C_Flags) -std=c++11 App_Link_Flags := $(SGX_COMMON_CFLAGS) -L$(SGX_LIBRARY_PATH) -l$(Urts_Library_Name) -lpthread -l$(Uae_Service_Library_Name) ######## Enclave Settings ######## ifneq ($(SGX_MODE), HW) Trts_Library_Name := sgx_trts_sim Service_Library_Name := sgx_tservice_sim Crypto_Library_Name := sgx_tcrypto else Trts_Library_Name := sgx_trts Service_Library_Name := sgx_tservice Crypto_Library_Name := sgx_tcrypto_opt endif Enclave_Include_Paths := -I$(SGX_SDK)/include -I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/stdc++ Enclave_C_Flags := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden -fpie -fstack-protector $(Enclave_Include_Paths) Enclave_Cpp_Flags := $(Enclave_C_Flags) -std=c++03 -nostdinc++ Enclave_Link_Flags := $(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 -lsgx_tstdc -lsgx_tcxx -lsgx_tkey_exchange -l$(Crypto_Library_Name) -l$(Service_Library_Name) -Wl,--end-group \ -Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \ -Wl,-pie,-eenclave_entry -Wl,--export-dynamic \ -Wl,--defsym,__ImageBase=0 \ ifeq ($(SGX_MODE), HW) ifneq ($(SGX_DEBUG), 1) ifneq ($(SGX_PRERELEASE), 1) Build_Mode = HW_RELEASE endif endif endif define DEFAULT_ENCLAVE_CONFIG 0 0 0x40000 0x100000 1 1 0 0 0xFFFFFFFF endef export DEFAULT_ENCLAVE_CONFIG ######## node-secureworker ######## all: @echo 'Run "npm run build" or "make enclave".' node: Makefile build/Release/secureworker_internal.node enclave-autoexec/autoexec.js %_u.c %_u.h: %.edl cd $( $@ ######## enclave building ######## # Example: # # make enclave SCRIPTS='tests/main.js another/script.js' ENCLAVE_KEY='key.pem' ENCLAVE_OUTPUT='enclave-main.so' # # Scripts will be exposed as "main.js" and "script.js" inside the enclave (their basename). # Enclave key will be generated for you, if it does not yet exist. # If you do not provide ENCLAVE_OUTPUT, enclave will be output to "build/enclave.so". ENCLAVE_OUTPUT ?= build/enclave.so ENCLAVE_OUTPUT_UNSIGNED ?= $(addsuffix $(addprefix .unsigned,$(suffix $(ENCLAVE_OUTPUT))),$(basename $(ENCLAVE_OUTPUT))) ENCLAVE_CONFIG ?= build/enclave.config.xml ENCLAVE_KEY ?= key.pem # A rule to check if output from generate-scripts-table changed based on SCRIPTS. Quietly. scripts/scripts-table.c.changed: scripts/generate-scripts-table.sh always-rebuild @scripts/generate-scripts-table.sh enclave-autoexec/autoexec.js ${SCRIPTS} > $@.tmp @[ -e $@ ] && diff -q $@ $@.tmp > /dev/null || cp $@.tmp $@ @rm -f $@.tmp scripts/scripts-table.c: scripts/generate-scripts-table.sh scripts/scripts-table.c.changed @if [ -z "${SCRIPTS}" ]; then echo "You have to pass list of SCRIPTS to build into the enclave: make enclave SCRIPTS='worker1.js worker2.js'"; exit 1; fi scripts/generate-scripts-table.sh enclave-autoexec/autoexec.js ${SCRIPTS} > $@ # A rule to check if output from generate-scripts-data changed based on SCRIPTS. Quietly. scripts/scripts-binary.as.changed: scripts/generate-scripts-data.sh always-rebuild @scripts/generate-scripts-data.sh enclave-autoexec/autoexec.js ${SCRIPTS} > $@.tmp @[ -e $@ ] && diff -q $@ $@.tmp > /dev/null || cp $@.tmp $@ @rm -f $@.tmp scripts/scripts-binary.as: scripts/generate-scripts-data.sh scripts/scripts-binary.as.changed @if [ -z "${SCRIPTS}" ]; then echo "You have to pass list of SCRIPTS to build into the enclave: make enclave SCRIPTS='worker1.js worker2.js'"; exit 1; fi scripts/generate-scripts-data.sh enclave-autoexec/autoexec.js ${SCRIPTS} > $@ scripts/scripts-binary.o: scripts/scripts-binary.as enclave-autoexec/autoexec.js $(SCRIPTS) as $< -o $@ scripts/scripts-table.o: scripts/scripts-table.c scripts/scripts.h %_t.c %_t.h: %.edl cd $( $@ enclave: node Makefile build ${ENCLAVE_OUTPUT} .PHONY: all build always-rebuild .SECONDARY: duk_enclave/duk_enclave_t.c duk_enclave/duk_enclave_t.h duk_enclave/duk_enclave_u.c duk_enclave/duk_enclave_u.h .PRECIOUS: %.key %.config.xml