
GoTEE - example application
GoTEE 프레임워크는 권한(privileged) 및 비권한(unprivileged) 모드에서 TamaGo 기반 유니커널의 동시 인스턴스화를 구현하며, 유니커널들은 모니터 모드와 사용자 정의 시스템 콜을 통해 서로 상호 작용합니다.
이러한 기능을 통해 GoTEE는 TamaGo 기반 TEE(Trusted Execution Environment)를 구현하여, ARM TrustZone Secure World 또는 RISC-V Supervisor Execution Environment 내부의 베어 메탈 실행에 Go의 메모리 안전성, 편의성 및 기능을 제공합니다.
GoTEE는 GoTEE API를 구현하는 순수 Go, Rust 또는 C 기반 프리스탠딩(freestanding) Trusted Applet뿐만 아니라 ARM TrustZone Normal World 또는 RISC-V S-모드에서 실행할 수 있는 Linux와 같은 모든 운영 체제도 감독할 수 있습니다.
ARM 사용자 모드, TrustZone Normal World 또는 RISC-V Supervisor Mode를 위한 격리된 실행 컨텍스트
장애 감지를 위한 기회적 소프트 록스텝(Opportunistic soft lockstep)
Trusted OS 구현을 위한 API (Syscall, JSON-RPC 및 예외 처리기)
튜토리얼이 포함된 주요 문서는 프로젝트 위키에서 확인할 수 있습니다.
패키지 API 문서는 pkg.go.dev에서 확인할 수 있습니다.
다음 표는 현재 지원되는 SoC와 보드를 요약합니다.
TEE 용어에서 권한이 있는 유니커널은 일반적으로 Trusted OS라고 하며, 권한이 없는 유니커널은 Trusted Applet을 나타냅니다.
GoTEE 예제는 Trusted OS, Trusted Applet 및 Main OS로 작동하는 Go 유니커널의 동시 작동을 보여줍니다.
[!WARNING] Main OS는 "리치(rich)" OS(예: Linux)일 수 있으며, TamaGo는 단순히 자체 포함(self-contained) 예제를 위해 사용됩니다. Trusted Applet도 마찬가지로, 사용자 모드에서 실행되고 GoTEE API를 구현할 수 있는 모든 베어 메탈 애플리케이션(예: 프리스탠딩 C 또는 Rust 프로그램)이 될 수 있습니다.
빌드 시
trusted_applet_go를trusted_applet_rust로 교체하면 Rust 예제를 사용할 수 있습니다.
예제 Trusted OS/applet 조합은 서로 다른 권한 수준에서 세 개의 TamaGo 유니커널의 동시 실행에 대한 기본 테스트를 수행합니다:
Main OS는 모니터 콜(monitor call)로 제어권을 반환합니다.
Trusted Applet은 Trusted OS 메모리 읽기를 시도하기 전에 5초 동안 대기하며, 이 메모리 읽기는 슈퍼바이저가 처리하는 예외를 발생시켜 Trusted Applet을 종료합니다.
GoTEE syscall 인터페이스는 Trusted OS와 Trusted Applet 간의 통신을 위해 구현되어 있습니다.
USB armory Mk II에서 실행하면 예제 애플리케이션은 Ethernet over USB(ECM 프로토콜, Linux 및 macOS 호스트 지원)를 통해 SSH로 접근할 수 있습니다:
$ ssh [email protected]
tamago/arm • TEE security monitor (Secure World system/monitor)
allgptr # memory forensics of applet goroutines
csl # show config security levels (CSL)
csl <periph> <slave> <hex csl> # set config security level (CSL)
dbg # show ARM debug permissions
exit, quit # close session
gotee # TrustZone example w/ TamaGo unikernels
help # this help
linux <uSD|eMMC> # boot NonSecure USB armory Debian base image
lockstep <fault %> # tandem applet example w/ fault injection
peek <hex offset> <size> # memory display (use with caution)
poke <hex offset> <hex value> # memory write (use with caution)
reboot # reset device
sa # show security access (SA)
sa <id> <secure|nonsecure> # set security access (SA)
stack # stack trace of current goroutine
stackall # stack trace of all goroutines
>
[!NOTE] Non-secure 작동은 USB armory Debian base image 릴리스 20211129 이상만 지원됩니다.

예제는 QEMU 에뮬레이션에서도 실행할 수 있습니다.
[!NOTE] 에뮬레이션 실행은 QEMU의 완전한 TrustZone/PMP 지원 부족으로 부분적인 테스트만 수행합니다.
make qemu
...
> gotee
00:00:00 tamago/arm • TEE security monitor (Secure World system/monitor)
00:00:00 SM loaded applet addr:0x9c000000 entry:0x9c072740 size:4940275
00:00:00 SM loaded kernel addr:0x80000000 entry:0x8007100c size:4577643
00:00:00 SM waiting for applet and kernel
00:00:00 SM starting mode:USR sp:0x9e000000 pc:0x9c072740 ns:false
00:00:00 SM starting mode:SYS sp:0x00000000 pc:0x8007100c ns:true
00:00:00 tamago/arm (go1.19.1) • TEE user applet
00:00:00 tamago/arm (go1.19.1) • system/supervisor (Non-secure)
00:00:00 supervisor is about to yield back
00:00:00 SM stopped mode:SYS sp:0x8146bf54 lr:0x801937a4 pc:0x80193884 ns:true err:exit
00:00:00 applet obtained 16 random bytes from monitor: b4cc4764dd30291a52545b182313003c
00:00:00 applet requests echo via RPC: hello
00:00:00 applet received echo via RPC: hello
00:00:00 applet will sleep for 5 seconds
00:00:01 applet says 1 mississippi
...
00:00:05 applet says 5 mississippi
00:00:05 applet is about to read secure memory at 0x98010000
00:00:05 r0:98010000 r1:9c8240c0 r2:98010000 r3:00000000
00:00:05 r4:00000000 r5:00000000 r6:00000000 r7:9c86bec8
00:00:05 r8:00000007 r9:0000003d r10:9c8020f0 r11:9c342f41 cpsr:600001d7 (ABT)
00:00:05 r12:00000061 sp:9c86bf08 lr:9c1b1be8 pc:9c011330 spsr:600001d0 (USR)
00:00:05 SM stopped mode:USR sp:0x9c86bf08 lr:0x9c1b1be8 pc:0x9c011330 ns:false err:ABT
TamaGo 컴파일러는 Makefile에 의해 go tool로 자동 다운로드 및 컴파일됩니다.
또는 TAMAGO 환경 변수를 재정의하여 최신 바이너리 릴리스를 사용할 수 있습니다:
wget https://github.com/usbarmory/tamago-go/archive/refs/tags/latest.zip
unzip latest.zip
cd tamago-go-latest/src && ./all.bash
cd ../bin && export TAMAGO=`pwd`/go
예제 Trusted Applet 및 커널 실행 파일을 다음과 같이 빌드합니다:
git clone https://github.com/usbarmory/GoTEE-example
cd GoTEE-example && export TARGET=usbarmory && make nonsecure_os_go && make trusted_applet_go && make trusted_os
[!NOTE] Rust TA 예제의 경우
trusted_applet_go를trusted_applet_rust로 교체하세요. Rust nightly와armv7a-none-eabi툴체인이 필요합니다.
최종 실행 파일은 bin 하위 디렉터리에 생성되며, 네이티브 실행에는 trusted_os_usbarmory.imx를 사용해야 합니다.
다음과 같은 대상(TARGET)을 사용할 수 있습니다:
TARGET | 보드 | 실행 및 디버깅 |
|---|---|---|
usbarmory | USB armory Mk II | usbarmory |
대상(TARGET)은 네이티브 실행(위 표의 관련 문서 링크 참조)과 에뮬레이션 실행(예: make qemu)을 모두 지원합니다.
예제 Trusted Applet 및 커널 실행 파일을 다음과 같이 빌드합니다:
git clone https://github.com/usbarmory/GoTEE-example
cd GoTEE-example && export TARGET=sifive_u && make nonsecure_os_go && make trusted_applet_go && make trusted_os
[!NOTE] Rust TA 예제의 경우
trusted_applet_go를trusted_applet_rust로 교체하세요. Rust nightly와riscv64gc-unknown-none-elf툴체인이 필요합니다.
최종 실행 파일은 bin 하위 디렉터리에 생성됩니다.
사용 가능한 대상(TARGET):
TARGET | 보드 | 실행 및 디버깅 |
|---|---|---|
sifive_u | QEMU sifive_u | sifive_u |
이 대상은 에뮬레이션 실행(예: make qemu)으로만 테스트되었습니다.
Andrea Barisani
[email protected]
Andrej Rosano
[email protected]
GoTEE | https://github.com/usbarmory/GoTEE
저작권 (c) GoTEE 저자. 판권 소유.
이 소스 파일은 LICENSE 파일에 명시된 BSD 스타일 라이선스에 따라 배포됩니다.
| SoC | 보드 | SoC 패키지 | 보드 패키지 |
|---|
| NXP i.MX6ULZ | USB armory Mk II | imx6ul | usbarmory/mk2 |
| NXP i.MX6ULL | MCIMX6ULL-EVK | imx6ul | mx6ullevk |
| SiFive FU540 | QEMU sifive_u | fu540 | qemu/sifive_u |