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.
This example uses Go 1.17.
See the Go download page
for information on getting and installing the Go 1.17 toolchain.
Do not use the apt
version of golang-go
, which installs an older, unsupported version of Go.
The instructions below assume that you are familiar with writing and compiling Go applications and that the Go 1.17 tools are already installed and properly configured.
Write the program
Create a directory to contain your Go program. In the directory, 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 run hello.go
:
$ go build hello.go
$ ./hello # prints "Hello world" to the console
You have now built a working application.
Next, you can run it in a secure enclave using the Anjuna SGX Runtime.
If you have not already done so, use your license
by putting the license file at /opt/anjuna/license.yaml
.
Then, run the following command:
$ anjuna-sgxrun ./hello
As in the example in the previous section, running the application with the Anjuna SGX Runtime produces considerable output as the Runtime creates and configures the secure enclave. Near the end, you can see the output of your application:
"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.51.0002, 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