Open sbellem opened 4 years ago
It is possible to build the SGX SDK from source, but it's not straightforward with the current toolchain. There are a few different ways to build the SDK, as per the documentation:
You can find the three flavors of tools and libraries generated in the build directory.
- This repository supports to build the Intel(R) SGX SDK with below three combinations:
USE_OPT_LIBS=0
--- build SDK using SGXSSL and open sourced String/MathUSE_OPT_LIBS=1
--- build SDK using optimized IPP crypto and open sourced String/MathUSE_OPT_LIBS=2
--- build SDK with no mitigation using SGXSSL and optimized String/MathUSE_OPT_LIBS=3
--- build SDK with no mitigation using IPP crypto and optimized String/Math
The default build usesUSE_OPT_LIBS=1
, if you directly type$ make sdk
as above. You can switch to the other build combinations instead by entering the following command:
The optimized libraries are prebuilt and downloaded by via download_prebuilt.sh
, which is invoked when running make preparation
, which is mentioned as a prerequisite in the documentation.
Download the source code and prepare the submodules and prebuilt binaries:
$ git clone https://github.com/intel/linux-sgx.git $ cd linux-sgx && make preparation
The above make preparation would trigger the script download_prebuilt.sh to download the prebuilt binaries. You may need to set an https proxy for the wget tool used by the script (such as export https_proxy=http://test-proxy:test-port)
In other words, there appears to be no way to build the SGX SDK from source without relying on prebuilt binaries as building blocks, at least as per the current Makefile
used to build the SDK:
# SDK requires prebuilt IPP libraries.
CHECK_OPT :=
ifeq ("$(wildcard $(LINUX_EXTERNAL_DIR)/ippcp_internal/lib/linux/intel64)", "")
CHECK_OPT := opt_check_failed
endif
.PHONY: opt_check_failed
opt_check_failed:
@echo "ERROR: Please run 'download_prebuilt.sh' to download the prebuilt optimized libraries before compiling."
@echo "Exiting......"
@exit -2
As seen in the above Makefile
excerpt, one important building block is the IPP Crypto library (at least for USE_OPT_LIBS=1
and USE_OPT_LIBS=3
, but the Makefile
requires it regardless of whatever option is used, which is perhaps because the SGX SSL lib also depends on the IPP Crypto to some extent (maybe just header files -- not sure)). Until not so long ago (not sure when) the version of the IPP Crypto library that was used was closed source. But now, (since not sure when), it is open source, and it's therefore possible to build the IPP Crypto library from source, and use the resulting binary and headers to build the SGX SDK. Moreover, the linux-sgx project offers a nix-based environment to reproduce some of the prebuilt binaries, one of which is the ipp-crypto lib. The provided environment and toolchain are however (at least from the point of view of this author) not straightforward to use to build the SGX SDK from source, with the built-from-source ipp-crypto lib. From the point of view of building enclaves based on the linux SGX SDK, and verifying the reproducibility of these enclaves, the current toolchain lacks a proper integration within the nixpkgs ecosystem such that new enclave applications can simply build from an existing SGX SDK that has already been packaged and is accessible from the curated registry of nix packages. Currently one has to rebuild the SGX SDK each time within their own environment. It should also be mentioned that building the IPP Crypto library from source, with all mitigations, may take more or less 2 hours (e.g. https://github.com/sbellem/sgx-ipp-crypto/actions/runs/937866336).
TODO: Describe how the ecosystem works, provides curated already built packages which saves time when writing a new derivation or package in the sense that instead of rebuilding all dependencies the already built dependencies are fetched from a registry of packages via "channels".
Helpful readings on nix channels, and custom channels:
The problem with the above is that building ipp-crypto from source can take 2 hours. So why not package it and distribute it?
draft
Despite the fact that the
linux-sgx
repository is open source at https://github.com/intel/linux-sgx, some of its components and dependencies are not open source.This issue aims to clarify what is open source and what is not and to understand the implications that this may have on audits.
Related issue: https://github.com/intel/linux-sgx/issues/363