Write and Run a Program

This section demonstrates how to create a simple application using the Go language, and then run it in a secure enclave using the Anjuna SGX Runtime.

Is this example, we use Go 1.11. See the Go download page for information about how to get and install the Go 1.11 toolchain.

We assume that you’re familiar with how to write and compile Go applications. The following instructions assume that the Go 1.11 tools are already installed and properly configured.

Write the Program

Create a directory to contain your Go program. Inside it, create a file named hello.go and populate it with the following code:

package main

import "fmt"

func main() {
    fmt.Printf("Hello world\n")
}

Using the Go tools, build and then run hello.go:

$ go build hello.go
$ ./hello  # prints "Hello world" to the console

We’ve now built a working application. Next we can run it in a secure enclave using the Anjuna SGX Runtime:

$ anjuna-sgxrun ./hello

As in the example of the previous section, running the application with the Anjuna SGX Runtime produces considerable extra output as the Runtime creates and configures the secure enclave:

"hello.manifest.template.yaml" created
"hello.manifest.sgx" created
"hello.sig" created
Starting "hello" in Anjuna Runtime
+ exec Runtime/anjuna-runtime --dev hello
Anjuna Runtime version release-1.42.0005, Copyright (C) Anjuna Security, Inc. All rights reserved.
Enclave initialized:
    Enclave base address:       0x0000000000000000
    Enclave size:               2GB
    Maximum number of threads:  64
    Enclave attributes:         0x0000000000000007
    Enclave SSA frame size:     1
    Enclave MRSIGNER:           0x795659B2FB27F86EA0513559DC45737F310E9BAFF870E73C991A6A0EC40CD094
    Enclave MRENCLAVE:          0x5528E7EA78873EFCF58F23D0AEC224D2E739BAD69BDF34AF2CB0E4C0C8F67FEE
[worker_poll_loop] started. s_nworkers=1, worker_tid=30410 pid=30363

 +================================+
 |  Warning: running in DEV MODE  |
 +================================+


Hello world

In the end, though, we see the output of our application displayed.