Makefile 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. #
  2. # Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions
  6. # are met:
  7. #
  8. # * Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. # * Redistributions in binary form must reproduce the above copyright
  11. # notice, this list of conditions and the following disclaimer in
  12. # the documentation and/or other materials provided with the
  13. # distribution.
  14. # * Neither the name of Intel Corporation nor the names of its
  15. # contributors may be used to endorse or promote products derived
  16. # from this software without specific prior written permission.
  17. #
  18. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. #
  30. #
  31. ######## SGX SDK Settings ########
  32. SGX_MODE := HW
  33. SGX_ARCH := x64
  34. SGX_DEBUG := 1
  35. ifeq ($(shell getconf LONG_BIT), 32)
  36. SGX_ARCH := x86
  37. else ifeq ($(findstring -m32, $(CXXFLAGS)), -m32)
  38. SGX_ARCH := x86
  39. endif
  40. SGX_COMMON_CFLAGS := -m64
  41. SGX_LIBRARY_PATH := $(SGX_SDK)/lib64
  42. SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x64/sgx_sign
  43. SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r
  44. SGX_COMMON_CFLAGS += -O2
  45. ######## Library Settings ########
  46. #Integrating linux-sgx-ssl (adapted from the makefile for the TestApp in that repo)
  47. SGXSSL_PATH := /opt/intel/sgxssl/
  48. SGXSSL_LIBRARY_PATH := $(SGXSSL_PATH)/lib64
  49. SGXSSL_Crypto_Library := sgx_tsgxssl_crypto
  50. SGXSSL_SSL_Library := sgx_tsgxssl
  51. SgxSSL_Link_Libraries := -L$(SGXSSL_LIBRARY_PATH) -Wl,--whole-archive -l$(SGXSSL_SSL_Library) -Wl,--no-whole-archive -l$(SGXSSL_Crypto_Library)
  52. Security_Link_Flags := -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -pie
  53. SGXSSL_INCLUDE_PATH := $(SGXSSL_PATH)/include
  54. Trust_Lib_Name := libLocalAttestation_Trusted.a
  55. TrustLib_Include_Paths := -I$(SGX_SDK)/include -I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/libcxx -I$(SGX_SDK)/include/epid -I./Include -I./Decryptor
  56. TrustLib_Compile_Flags := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden -fpie -fstack-protector $(TrustLib_Include_Paths) -Wall
  57. TrustLib_Compile_Cxx_Flags := -std=c++11 -nostdinc++
  58. ######## App Settings ########
  59. Urts_Library_Name := sgx_urts
  60. App_Cpp_Files := $(wildcard App/*.cpp)
  61. App_Include_Paths := -I$(SGX_SDK)/include -I$(SGX_SDK)/include/ippcp -I./Include -I./LocalAttestationCode
  62. App_Compile_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(App_Include_Paths) -std=c++11 -Wall -DDEBUG -UNDEBUG -UEDEBUG
  63. App_Link_Flags := $(SGX_COMMON_CFLAGS) $(Security_Link_Flags) -L$(SGX_LIBRARY_PATH) -l$(Urts_Library_Name) -lsgx_uae_service -L$(SGXSSL_LIBRARY_PATH) -lsgx_usgxssl -lpthread -lprotobuf -lsgx_uae_service
  64. App_Cpp_Objects := App/App.o App/LocalAttestationUntrusted.o App/protobufLAInitiator.o App/protobufSgxLATransformsInitiator.o App/ProtobufLAMessages.pb.o #$(App_Cpp_Files:.cpp=.o)
  65. App_Name := app
  66. ######## Enclave Settings ########
  67. Decryptor_Version_Script := Decryptor/Decryptor.lds
  68. Trts_Library_Name := sgx_trts
  69. Service_Library_Name := sgx_tservice
  70. Crypto_Library_Name := sgx_tcrypto
  71. Enclave_Cpp_Files_2 := $(wildcard Decryptor/*.cpp)
  72. Enclave_Include_Paths := -I$(SGX_SDK)/include -I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/libcxx -I./LocalAttestationCode -I./Include
  73. CC_BELOW_4_9 := $(shell expr "`$(CC) -dumpversion`" \< "4.9")
  74. ifeq ($(CC_BELOW_4_9), 1)
  75. Enclave_Compile_Flags := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden -fpie -ffunction-sections -fdata-sections -fstack-protector -Wno-unused-variable -Wall
  76. else
  77. Enclave_Compile_Flags := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden -fpie -ffunction-sections -fdata-sections -fstack-protector-strong -Wno-unused-variable -Wall
  78. endif
  79. Enclave_Compile_Flags += $(Enclave_Include_Paths)
  80. # To generate a proper enclave, it is recommended to follow below guideline to link the trusted libraries:
  81. # 1. Link sgx_trts with the `--whole-archive' and `--no-whole-archive' options,
  82. # so that the whole content of trts is included in the enclave.
  83. # 2. For other libraries, you just need to pull the required symbols.
  84. # Use `--start-group' and `--end-group' to link these libraries.
  85. # Do NOT move the libraries linked with `--start-group' and `--end-group' within `--whole-archive' and `--no-whole-archive' options.
  86. # Otherwise, you may get some undesirable errors.
  87. Common_Enclave_Link_Flags := $(SGX_COMMON_CFLAGS) -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles \
  88. $(SgxSSL_Link_Libraries) $(Security_Link_Flags) \
  89. -Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive \
  90. -Wl,--start-group -L$(SGX_LIBRARY_PATH) -L. -L./Decryptor -L./LocalAttestationCode -lsgx_tstdc -lsgx_tcxx -l$(Crypto_Library_Name) -l$(Service_Library_Name) -Wl,--end-group \
  91. -Wl,-Bstatic -Wl,-Bsymbolic \
  92. -Wl,-pie,-eenclave_entry -Wl,--export-dynamic \
  93. -Wl,--defsym,__ImageBase=0 -Wl,--gc-sections
  94. Decryptor_Link_Flags := $(Common_Enclave_Link_Flags) -Wl,--version-script=$(Decryptor_Version_Script)
  95. Enclave_Cpp_Objects_2 := $(Enclave_Cpp_Files_2:.cpp=.o)
  96. Enclave_Name_2 := libDecryptor.so
  97. all: .config_$(Build_Mode)_$(SGX_ARCH) $(Trust_Lib_Name) $(UnTrustLib_Name) $(Enclave_Name_2) $(App_Name)
  98. .config_$(Build_Mode)_$(SGX_ARCH):
  99. @rm -rf .config_* $(App_Name) *.so *.a App/*.o Decryptor/*.o Decryptor/*_t.* Decryptor/*_u.* LocalAttestationCode/*.o LocalAttestationCode/*_t.* #Enclave3/*.o Enclave3/*_t.* Enclave3/*_u.*
  100. @touch .config_$(Build_Mode)_$(SGX_ARCH)
  101. ######## Library Objects ########
  102. LocalAttestationCode/LocalAttestationCode_t.c LocalAttestationCode/LocalAttestationCode_t.h : $(SGX_EDGER8R) LocalAttestationCode/LocalAttestationCode.edl
  103. @cd LocalAttestationCode && $(SGX_EDGER8R) --trusted ../LocalAttestationCode/LocalAttestationCode.edl --search-path $(SGX_SDK)/include
  104. @echo "GEN => $@"
  105. LocalAttestationCode/LocalAttestationCode_t.o: LocalAttestationCode/LocalAttestationCode_t.c
  106. @$(CC) $(TrustLib_Compile_Flags) -c $< -o $@
  107. @echo "CC <= $<"
  108. LocalAttestationCode/LocalAttestationTrustedWrapper.o: LocalAttestationCode/LocalAttestationTrustedWrapper.cpp LocalAttestationCode/LocalAttestationCode_t.h
  109. @$(CXX) $(TrustLib_Compile_Flags) $(TrustLib_Compile_Cxx_Flags) -c $< -o $@
  110. @echo "CC <= $<"
  111. LocalAttestationCode/LocalAttestationTrusted.o: LocalAttestationCode/LocalAttestationTrusted.cpp LocalAttestationCode/LocalAttestationCode_t.h
  112. @$(CXX) $(TrustLib_Compile_Flags) $(TrustLib_Compile_Cxx_Flags) -c $< -o $@
  113. @echo "CC <= $<"
  114. $(Trust_Lib_Name): LocalAttestationCode/LocalAttestationCode_t.o LocalAttestationCode/LocalAttestationTrustedWrapper.o LocalAttestationCode/LocalAttestationTrusted.o
  115. @$(AR) rcs $@ $^
  116. @echo "GEN => $@"
  117. CommonOpensslCode/Openssl_crypto.o: CommonOpensslCode/Openssl_crypto.cpp
  118. @$(CXX) -std=c++11 -nostdinc++ $(Enclave_Compile_Flags) -v -I$(SGXSSL_INCLUDE_PATH) -c $< -o $@
  119. @echo "CXX <= $<"
  120. ######## App Objects ########
  121. Include/Decryptor_u.h: $(SGX_EDGER8R) Decryptor/Decryptor.edl
  122. @cd Decryptor && $(SGX_EDGER8R) --use-prefix --untrusted ../Decryptor/Decryptor.edl --search-path $(SGX_SDK)/include --untrusted-dir ../Include/
  123. @echo "GEN => $@"
  124. App/Decryptor_u.c: $(SGX_EDGER8R) Decryptor/Decryptor.edl Include/Decryptor_u.h
  125. @cd App && $(SGX_EDGER8R) --use-prefix --untrusted ../Decryptor/Decryptor.edl --search-path $(SGX_SDK)/include
  126. @echo "GEN => $@"
  127. App/Decryptor_u.o: App/Decryptor_u.c
  128. @$(CC) $(App_Compile_Flags) -c $< -o $@
  129. @echo "CC <= $<"
  130. App/%.o: App/%.cpp Include/Decryptor_u.h
  131. @$(CXX) $(App_Compile_Flags) -c $< -o $@
  132. @echo "CXX <= $<"
  133. $(App_Name): App/App.o App/Sealing.o App/MainLogic.o App/PostLAMessaging.o App/LAResponder/LA.o App/LAResponder/Transforms.o App/PostLAMessaging.o App/PostLAMessages.pb.o App/ProtobufLAMessages.pb.o App/ProtobufMessageRW.o App/Decryptor_u.o
  134. @$(CXX) -Wl,--no-undefined $^ -o $@ $(App_Link_Flags)
  135. @echo "LINK => $@"
  136. ######### Crypto classes for enclave ############
  137. ######## Enclave Objects ########
  138. Decryptor/Decryptor_t.c: $(SGX_EDGER8R) Decryptor/Decryptor.edl
  139. @cd Decryptor && $(SGX_EDGER8R) --use-prefix --trusted ../Decryptor/Decryptor.edl --search-path $(SGX_SDK)/include
  140. @echo "GEN => $@"
  141. Decryptor/Decryptor_t.o: Decryptor/Decryptor_t.c
  142. @$(CC) $(Enclave_Compile_Flags) -c $< -o $@
  143. @echo "CC <= $<"
  144. Decryptor/%Box.o: Decryptor/%Box.cpp
  145. @$(CXX) -std=c++11 -nostdinc++ $(Enclave_Compile_Flags) -c $< -o $@
  146. @echo "CXX <= $<"
  147. Decryptor/ECDHKeypair.o: Decryptor/ECDHKeypair.cpp
  148. @$(CXX) -std=c++11 -nostdinc++ $(Enclave_Compile_Flags) -c $< -o $@
  149. @echo "CXX <= $<"
  150. Decryptor/DecryptorWrapper.o: Decryptor/DecryptorWrapper.cpp
  151. @$(CXX) -std=c++11 -nostdinc++ $(Enclave_Compile_Flags) -c $< -o $@
  152. @echo "CXX <= $<"
  153. Decryptor/Decryptor.o: Decryptor/Decryptor.cpp
  154. @$(CXX) -std=c++11 -nostdinc++ $(Enclave_Compile_Flags) -c $< -o $@
  155. @echo "CXX <= $<"
  156. Decryptor.so: Decryptor/Decryptor_t.o Decryptor/DecryptorWrapper.o Decryptor/Decryptor.o $(Trust_Lib_Name) Decryptor/HybridEncryptionBox.o Decryptor/ECDSASignatureBox.o Decryptor/SymmetricEncryptionBox.o Decryptor/ECDHKeypair.o CommonOpensslCode/Openssl_crypto.o
  157. @$(CXX) $^ -o $@ $(Decryptor_Link_Flags)
  158. @echo "LINK => $@"
  159. $(Enclave_Name_2): Decryptor.so
  160. @$(SGX_ENCLAVE_SIGNER) sign -key Decryptor/Decryptor_private.pem -enclave Decryptor.so -out $@ -config Decryptor/Decryptor.config.xml
  161. @echo "SIGN => $@"
  162. ######## Clean ########
  163. .PHONY: clean
  164. clean:
  165. @rm -rf .config_* $(App_Name) *.so *.a App/*.o App/LAResponder/*.o Decryptor/*.o Decryptor/*_t.* App/Decryptor_u.c Include/Decryptor_u.h LocalAttestationCode/*.o LocalAttestationCode/*_t.* CommonOpensslCode/*.o