
Go 신뢰 실행 환경 (TEE)
GoTEE 프레임워크는 TamaGo 기반 유니커널을 권한(privileged) 및 비권한(unprivileged) 모드로 동시에 인스턴스화하며, 각 유니커널은 모니터 모드와 커스텀 시스템 콜을 통해 서로 상호작용합니다.
이러한 기능을 통해 GoTEE는 TamaGo 기반 TEE(Trusted Execution Environment)를 구현하여, ARM TrustZone Secure World 또는 RISC-V Supervisor Execution Environment 내 베어 메탈 실행에 Go의 메모리 안전성, 편의성 및 기능을 제공합니다.
GoTEE는 GoTEE API를 구현하는 순수 Go, Rust 또는 C 기반 프리스탠딩 Trusted Applet뿐만 아니라, Linux처럼 ARM TrustZone Normal World 또는 RISC-V S-모드에서 실행할 수 있는 모든 운영 체제도 감독할 수 있습니다.
ARM 사용자 모드, TrustZone Normal World 또는 RISC-V Supervisor Mode를 위한 격리된 실행 컨텍스트
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는 Linux 등 '리치(rich)' OS라면 무엇이든 될 수 있으며, TamaGo는 단지 자체 완결형 예제를 위해 사용됩니다. Trusted Applet도 마찬가지로, 사용자 모드에서 실행되고 GoTEE API를 구현할 수 있는 모든 베어 메탈 애플리케이션이 될 수 있으며, 예를 들어 프리스탠딩 C 또는 Rust 프로그램이 있습니다.
빌드 시
trusted_applet_go를trusted_applet_rust로 대체하면 Rust 예제를 사용할 수 있습니다.
예제의 Trusted OS/애플릿 조합은 서로 다른 권한 수준에서 세 개의 TamaGo 유니커널이 동시에 실행되는 것을 기본적으로 테스트합니다:
Main OS는 모니터 콜로 제어권을 반환합니다.
Trusted Applet은 5초간 대기한 후 Trusted OS 메모리 읽기를 시도하며, 이로 인해 슈퍼바이저가 처리하는 예외가 발생하여 Trusted Applet이 종료됩니다.
Trusted OS와 Trusted Applet 간 통신을 위해 GoTEE syscall 인터페이스가 구현되어 있습니다.
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
>
예제는 gotee 명령으로 실행할 수 있으며, 실제 하드웨어 주변장치를 사용하여 TrustZone 제한이 적용되기 전과 후의 동작을 보여주기 위해 Main OS를 두 번 생성합니다.
또한 linux 명령을 사용하여 USB armory Debian 베이스 이미지를 비보안(Non-secure) 메인 OS로 실행할 수 있습니다.
[!NOTE] 비보안 운영은 USB armory Debian 베이스 이미지 릴리스 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 컴파일러를 빌드합니다(또는 최신 바이너리 릴리스를 사용하세요):
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 | 보드 | 실행 및 디버깅 |
|---|---|---|
usbarmory | USB armory Mk II | usbarmory |
이 타깃들은 네이티브 실행(위 표의 관련 문서 링크 참조)과 에뮬레이션 실행(예: 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 | 보드 | 실행 및 디버깅 |
|---|---|---|
sifive_u | QEMU sifive_u | sifive_u |
이 타깃은 에뮬레이션 실행(예: make qemu)으로만 테스트되었습니다.
Andrea Barisani
[email protected]
Andrej Rosano
[email protected]
GoTEE | https://github.com/usbarmory/GoTEE
Copyright (c) The GoTEE authors. All Rights Reserved.
이 소스 파일들은 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 |