Skip to content

Instantly share code, notes, and snippets.

@dnoliver
Last active May 13, 2021 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnoliver/b10a1f49c0d2fe2cffb7b9abdd80fb89 to your computer and use it in GitHub Desktop.
Save dnoliver/b10a1f49c0d2fe2cffb7b9abdd80fb89 to your computer and use it in GitHub Desktop.
Intel SGX

Intel SGX

Documentation

Development Environment

On Ubuntu 20.04

Check SGX Support:

root@sgx:~# cpuid -1 | grep -i sgx
      SGX: Software Guard Extensions supported = true
      SGX_LC: SGX launch config supported      = false
   SGX capability (0x12/0):
      SGX1 supported                         = true
      SGX2 supported                         = false
   SGX attributes (0x12/1):

Install Tools:

apt-get install -y curl git tmux

# Linux Kernel 5.9 supports FSGSBASE required by Graphene SGX 
cd /tmp/
wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.9/amd64/linux-headers-5.9.0-050900_5.9.0-050900.202010112230_all.deb
wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.9/amd64/linux-headers-5.9.0-050900-generic_5.9.0-050900.202010112230_amd64.deb
wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.9/amd64/linux-image-unsigned-5.9.0-050900-generic_5.9.0-050900.202010112230_amd64.deb
wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.9/amd64/linux-modules-5.9.0-050900-generic_5.9.0-050900.202010112230_amd64.deb
dpkg -i *.deb
systemctl reboot

# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
chmod +x get-docker.sh
./get-docker.sh
systemctl enable --now docker

# Get Intel SGX Drivers
apt-get install -y libssl-dev libcurl4-openssl-dev libprotobuf-dev
mkdir sgx-drivers
cd sgx-drivers/
curl https://download.01.org/intel-sgx/sgx-linux/2.13/distro/ubuntu20.04-server/driver_readme.txt -o driver_readme.txt
curl https://download.01.org/intel-sgx/sgx-linux/2.13/distro/ubuntu20.04-server/sgx_linux_x64_driver_1.41.bin -o sgx_linux_x64_driver_1.41.bin
curl https://download.01.org/intel-sgx/sgx-linux/2.13/distro/ubuntu20.04-server/sgx_linux_x64_driver_2.11.0_0373e2e.bin -o sgx_linux_x64_driver_2.11.0_0373e2e.bin

# DCAP Driver (Latest out of tree driver, requires Launch Config support)
apt-get install -y dkms
chmod +x sgx_linux_x64_driver_1.41.bin
./sgx_linux_x64_driver_1.41.bin

# OOT Driver (Legacy Driver, works without Launch Config support)
apt-get install -y build-essential
chmod +x sgx_linux_x64_driver_2.11.0_0373e2e.bin
./sgx_linux_x64_driver_2.11.0_0373e2e.bin

# PSW Packages
echo 'deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu focal main' | tee /etc/apt/sources.list.d/intel-sgx.list
curl https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | apt-key add -
apt-get update
apt-get install -y libsgx-launch libsgx-urts

# Allow process to map low portions of virtual memory, required if using OOT Driver with Graphene SGX
sysctl vm.mmap_min_addr=0

Or use Ansible: dnoliver/ansible-sgx

Software Development Kit

Sample Enclave Creation

Running on Simulator

Running in Virtual Machine

OpenEnclave Initiative

Graphene SGX

Alternatives

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment