You can find a sample app in the
hello-world directory of your SDK. You can use this app as a template
for your own if you want a quick start. We will cover:
- How to set up your machine.
- How to compile and run the sample app.
- How to write the sample app.
SGX enclaves can be used in one of four modes, in order of increasing realism:
- Mock: your enclave class is created in the host JVM and no native or SGX specific code is used. This provides a pure Java development experience.
- Simulation: an enclave is compiled to native machine code and loaded, but SGX hardware doesn't need to be present.
- Debug: the enclave is loaded using SGX hardware and drivers, but with a back door that allows debugger access to the memory.
- Release: the enclave is loaded using SGX hardware and drivers, and there's no back door. This is the real deal.
Only release mode locks out the host and provides the standard SGX security model.
Setting up your machine¶
For this tutorial you will need Java 8 or 11 (your choice). If you use IntelliJ IDEA the IDE can download both a JDK and the Gradle build system for you, so you don't need anything to get started except the IDE itself (the free Community Edition works fine).
Currently, we support developing enclaves on Windows, macOS and Linux. However, there are a few platform specific differences to be aware of.
Firstly, although you can develop and work on enclaves in the pure Java mock mode, to test against the embedded JVM you will need to install Docker. Enclaves are Linux shared libraries with special extensions, and this requires access to a Linux build environment. A build container will be constructed for you during the Gradle build process automatically, even on Windows and macOS! However Conclave won't actually install Docker for you. Grab it from their website, or on Linux, install it via your distribution.
Secondly, executing enclaves without using mock mode also requires Linux or a Linux container. Instructions are provided below to show you how to use Docker on Windows and macOS to run your entire application in "simulation mode". Alternatively, for day to day development the mock API is plenty sufficient and allows you to debug into enclave calls as well. Compiling a real enclave is only needed for integration testing against the embedded JVM, or real deployment.
Enclaves can run in simulation mode without requiring any special setup of Linux or SGX capable hardware. However you of course get no hardware protections. To run against real SGX hardware you must perform some additional machine setup.
Compiling the sample enclave¶
Step 1: Import the project
Step 2: Look at the Conclave SDK's top level directory
Step 3: Click "import" when notified that there's a Gradle build script
Step 4: If on Linux or Windows, double-click on
:host:assemble. This is the second
assemble in the screenshot below. Voila! You have just built your first enclave.
Now explore the
As normal with Gradle, the
assemble task has bundled the program into a zip, with startup scripts. These scripts are
nothing special - they just set up the classpath. You could also e.g. make a fat JAR if you want.
Selecting your mode¶
In the sample app, the
assemble task will build the app for simulation mode by default. Use the
argument to configure this. If you are using SGX hardware, you can build the app for debug mode with the command:
If working from inside IntelliJ, start the assemble task for the host project from the tree on the right hand side,
and then edit the created run config. Add the
-PenclaveMode=debug flag to the arguments section of the run config.
For release mode, the sample app has been configured (in the
build.gradle of the
enclave subproject) to use external
signing. This means it must be built in multiple stages:
1 2 3 4 5 6 7 8
See Enclave signing for more information.
Running the host¶
Just run the host app like any app - no special customisation or setup is required with Conclave! Here we will run a shell script generated by Gradle that starts the JVM:
1 2 3
Gradle can also create
.tar.gz files suitable for copying to the Linux host, fat JARs, WAR files for deployment into
servlet containers and various other ways to deploy your app. NB: At this time using the JPMS tool
jlink is not
If your Linux machine doesn't have SGX, you should see something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Testing on Windows and macOS¶
If you're on Windows or macOS you can test locally in simulation mode using a Docker container. On Linux you can of course just run the host directly.
This command should be run from the root of your Gradle project, e.g. the
hello-world directory of the conclave sdk.
This will give you a shell inside a Linux virtual machine.
You can then run:
You should see the following output:
You may want to create an IntelliJ launch configuration to incorporate the
Adjust the Docker command above to use
/bin/bash -c "mkdir -p run && tar xf host/build/distributions/host.tar -C run && ./run/host/bin/host"
and place it all in a .cmd batch file (Windows) or a .sh file (macOS). Use the "Shell script" launch
configuration type in IntelliJ, with this script (and its full path) as "Script path" and the
hello-world directory (and its full path)
as "Working Directory". Add the
host:assemble Gradle task in the "Before launch" section. You will then be able to click the run
icon in your IDE to build and start up the Java host app inside the Docker container.
Running the client¶
The host has loaded the enclave, obtained its remote attestation (the
EnclaveInstanceInfo object), printed it out,
asked the enclave to reverse a string and finally opened up a TCP port which will now listen for requests from remote
So, let's run the client app:
The client will connect to the host, download the
EnclaveInstanceInfo, check it, and then send an encrypted string
to reverse. The host will deliver this encrypted string to the enclave, and the enclave will send back to the client
the encrypted reversed response:
1 2 3 4
Aibohphobia is the fear of palindromes.
If you get stuck please contact email@example.com and ask for help!