Skip to content

Commit e6231d9

Browse files
Merge pull request #1 from acompany-develop/imamura/initial-impl
feat: initial implementation of RAFW-NE
2 parents 403bed6 + 0fa374b commit e6231d9

22 files changed

+1579
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
3+
target/
4+
debug/

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[workspace]
2+
resolver = "3"
3+
members = [
4+
"client",
5+
"enclave",
6+
"proxy",
7+
]

Makefile

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
SHELL := /bin/bash
2+
3+
.PHONY: help setup-docker setup-nitro-cli setup-client build-enclave build-proxy build-client run-enclave run-proxy run-client terminate-enclave
4+
5+
ENCLAVE_CID ?= 16
6+
ENCLAVE_MEMORY ?= 512
7+
ENCLAVE_CPU_COUNT ?= 2
8+
9+
SERVER_IP ?= 127.0.0.1
10+
SERVER_PORT ?= 8080
11+
12+
help:
13+
@echo "Targets:"
14+
@echo " help Show this help message"
15+
@echo " For Parent VM:"
16+
@echo " setup-docker Install Docker (requires Ubuntu + sudo) for Parent VM"
17+
@echo " setup-nitro-cli Install Nitro Enclaves Driver and CLI for Parent VM"
18+
@echo " build-enclave Build enclave Docker image and create EIF file"
19+
@echo " build-proxy Build vsock proxy"
20+
@echo " run-enclave Run Nitro Enclave"
21+
@echo " run-proxy Run vsock proxy"
22+
@echo " terminate-enclave Terminate Nitro Enclave"
23+
@echo " For Client:"
24+
@echo " setup-client Install Rust and AWS Nitro Enclaves root certificate"
25+
@echo " build-client Build client application"
26+
@echo " run-client Run client"
27+
28+
setup-docker:
29+
@echo "Running scripts/setup-docker.sh"
30+
@bash ./scripts/setup-docker.sh
31+
32+
setup-nitro-cli:
33+
@echo "Running scripts/setup-nitro-cli.sh"
34+
@bash ./scripts/setup-nitro-cli.sh
35+
36+
setup-client:
37+
@echo "Running scripts/setup-client.sh"
38+
@bash ./scripts/setup-client.sh
39+
40+
build-enclave:
41+
@echo "Building Docker image"
42+
@docker build -t rafwne-enclave ./enclave
43+
@echo "Creating EIF file"
44+
@nitro-cli build-enclave --docker-uri rafwne-enclave --output-file ./enclave/rafwne-enclave.eif
45+
46+
build-proxy:
47+
@echo "Building vsock proxy"
48+
@cargo build -p rafwne-proxy -r
49+
50+
build-client:
51+
@echo "Building client crate (release)"
52+
@cargo build -p rafwne-client -r
53+
54+
run-enclave:
55+
@echo "Running Nitro Enclave"
56+
@nitro-cli run-enclave --eif-path ./enclave/rafwne-enclave.eif --memory $(ENCLAVE_MEMORY) --cpu-count $(ENCLAVE_CPU_COUNT) --enclave-cid $(ENCLAVE_CID)
57+
58+
run-proxy:
59+
@echo "Running vsock proxy"
60+
@cargo run --release -p rafwne-proxy -- --ip $(SERVER_IP) --port $(SERVER_PORT) --cid $(ENCLAVE_CID)
61+
62+
run-client:
63+
@echo "Running client"
64+
@cargo run --release -p rafwne-client
65+
66+
terminate-enclave:
67+
@echo "Terminating Nitro Enclave"
68+
@ENCLAVE_ID="$$(nitro-cli describe-enclaves | jq -r '.[] | select(.State == "RUNNING" and .EnclaveCID == $(ENCLAVE_CID)) | .EnclaveID' | head -n1)"; \
69+
if [ -z "$$ENCLAVE_ID" ]; then \
70+
echo "ERROR: running enclave with CID=$(ENCLAVE_CID) not found"; \
71+
nitro-cli describe-enclaves; \
72+
exit 1; \
73+
fi; \
74+
echo "Enclave ID: $$ENCLAVE_ID"; \
75+
nitro-cli terminate-enclave --enclave-id "$$ENCLAVE_ID"; \
76+
echo "Enclave terminated"

README.md

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,144 @@
11
# Remote Attestation Framework for AWS Nitro Enclaves
2+
![MSRV](https://img.shields.io/badge/MSRV-1.90.0-blue)
3+
4+
This repository demonstrates a simple end-to-end flow against an AWS Nitro Enclave: **ECDH key exchange & attestation verification → confidential computation (example: adding two integers)**.
5+
6+
- **Parent VM**: An AWS EC2 instance (Ubuntu 24.04) with Nitro Enclaves enabled. Runs the Enclave and the vsock proxy.
7+
- **Client**: Can run on any machine, but this README assumes you run it on the Parent VM (localhost).
8+
9+
## Tested environment (detailed)
10+
11+
### Parent VM (AWS EC2)
12+
13+
- **Instance type**: `c5.xlarge`
14+
- vCPUs: 4
15+
- Memory: 8 GiB
16+
- CPU arch: `x86_64`
17+
- **AMI**: Ubuntu Server 24.04 LTS
18+
- AMI ID: `ami-06e3c045d79fd65d9`
19+
- **Storage**: 64 GiB `gp3`
20+
- **Kernel**: 6.14.0-1018-aws
21+
- **Nitro Enclaves**: Enabled
22+
- **Nitro Enclaves CLI / driver**: v1.4.4
23+
- **Rust toolchain**: v1.90.0
24+
25+
### Enclave
26+
27+
- **OS**: Ubuntu 24.04
28+
- **Allocated vCPUs**: 2
29+
- **Allocated Memory**: 512 MiB
30+
- **OS**: Ubuntu 24.04
31+
- **Rust toolchain**: v1.90.0
32+
33+
### Client
34+
35+
- Ran on the same Parent VM (localhost).
36+
37+
## Architecture
38+
39+
- `enclave/`: Enclave application (listens on vsock `port=5000`)
40+
- `proxy/`: **untrusted** HTTP → vsock proxy (listens on HTTP `ip:port`, forwards to vsock `port=5000`)
41+
- `client/`: Client app (POSTs JSON to the proxy, verifies attestation, then calls the confidential computing API)
42+
43+
## Quick start (all on the Parent VM)
44+
45+
Clone the repository:
46+
47+
```bash
48+
git clone <THIS_REPOSITORY>
49+
cd <THIS_REPOSITORY>
50+
```
51+
52+
### 1. Parent VM setup (Ubuntu 24.04)
53+
54+
```bash
55+
make setup-docker
56+
make setup-nitro-cli
57+
```
58+
59+
### 2. Client setup (this README runs it on the Parent VM)
60+
61+
```bash
62+
make setup-client
63+
```
64+
65+
### 3. Build the Enclave image and copy PCRs into `client-configs.json`
66+
67+
```bash
68+
make build-enclave
69+
```
70+
71+
When you run `make build-enclave`, PCR measurements are printed like this (example):
72+
73+
```text
74+
Enclave Image successfully created.
75+
{
76+
"Measurements": {
77+
"HashAlgorithm": "Sha384 { ... }",
78+
"PCR0": "...",
79+
"PCR1": "...",
80+
"PCR2": "..."
81+
}
82+
}
83+
```
84+
85+
Copy **PCR0/1/2** into `"PCRs"` in `client-configs.json`.
86+
87+
### 4. Build the vsock proxy
88+
89+
```bash
90+
make build-proxy
91+
```
92+
93+
### 5. Start the Enclave
94+
95+
```bash
96+
make run-enclave
97+
```
98+
99+
### 6. Start the vsock proxy
100+
101+
```bash
102+
make run-proxy
103+
```
104+
105+
### 7. Build and run the client
106+
107+
```bash
108+
make build-client
109+
make run-client
110+
```
111+
112+
After ECDH key exchange and attestation verification, the client calls the Enclave’s “add two integers” API and then closes the session.
113+
114+
### 8. Stop the Enclave
115+
116+
```bash
117+
make terminate-enclave
118+
```
119+
120+
## Configuration
121+
122+
### Change Enclave Memory / vCPU Allocation
123+
124+
- **Update Makefile variables**
125+
- `ENCLAVE_MEMORY`(MiB)
126+
- `ENCLAVE_CPU_COUNT`
127+
- **Update allocator config**
128+
- Update `/etc/nitro_enclaves/allocator.yaml` accordingly
129+
- **Restart the allocator**
130+
```bash
131+
sudo systemctl restart nitro-enclaves-allocator.service
132+
```
133+
134+
### Change Proxy IP / port
135+
136+
- Update `SERVER_IP` / `SERVER_PORT` in `Makefile`
137+
- Update `"server-ip"` / `"server-port"` in `client-configs.json`
138+
139+
If you run the client from a different machine, allow inbound access to `SERVER_PORT` in the Parent VM security group / firewall rules.
140+
141+
### Client configuration (`client-configs.json`)
142+
143+
- `"PCRs"`: Expected PCR values. Copy from `make build-enclave` output PCR[0-2].
144+
- `"print-attestation-json"`: Print the attestation document payload as JSON if `true`

client-configs.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
{
3+
"server-ip": "127.0.0.1",
4+
"server-port": 8080,
5+
"PCRs": {
6+
"0": "ae091d48b468539560a6cb7649fbc70ef5866d20ac82898f7b77eb359c2c23e4ccf2107d9d4d10a198ee7fc1d5541ef3",
7+
"1": "0343b056cd8485ca7890ddd833476d78460aed2aa161548e4e26bedf321726696257d623e8805f3f605946b3d8b0c6aa",
8+
"2": "7c2b87a4ca3c0cb43d39434b6717806fecd302be3fa742c1a30835ede59799c8cce2eb93e16c7d7dfb8e25fa22c730f5"
9+
},
10+
"print-attestation-json": true
11+
}

client/Cargo.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "rafwne-client"
3+
version = "0.1.0"
4+
edition = "2024"
5+
rust-version = "1.90.0"
6+
7+
[dependencies]
8+
anyhow = "1.0.100"
9+
aws-nitro-enclaves-cose = "0.5.2"
10+
aws-lc-rs = "1.15.4"
11+
base64 = "0.22.1"
12+
hex = "0.4.3"
13+
openssl = "0.10.75"
14+
p256 = { version = "0.13.2", features = ["ecdh"] }
15+
serde = { version = "1.0.228", features = ["derive"] }
16+
serde_bytes = "0.11.19"
17+
serde_json = "1.0.149"
18+
serde_cbor = "0.11.2"
19+
ureq = "3.1.4"
20+
x509-parser = "0.18.0"
21+
p384 = { version = "0.13.1", features = ["ecdsa", "sha384"] }

0 commit comments

Comments
 (0)