Skip to content
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a0679fe
Initial commit - RV setup works!
papa Jan 9, 2024
b72b110
Added TPM fields in the EnclaveReport struct
neeluk7 Mar 20, 2024
aea3c5b
Added the rest of Tyche-side support for TPM attestation
neeluk7 Mar 20, 2024
1b5d35c
Modified Tyche calls to support TPM attestation
neeluk7 Mar 20, 2024
1bbc3dd
Sample application showing TPM attestation verification
neeluk7 Mar 20, 2024
4ef675f
Forgot build tools for RoT enclave
neeluk7 Mar 20, 2024
6d3bce2
Added TPM signature verification on Tychools's side
neeluk7 Mar 20, 2024
c1dd64e
Compile successful after rebase
neeluk7 Mar 22, 2024
6e64adf
Added modular tags for x86 compilation and a tpm-riscv comman in the …
neeluk7 Mar 27, 2024
661be47
Added RISC-V launch with TPM support. Added TPM attestation to Manifest
neeluk7 Apr 1, 2024
a91c69a
Added the rest of Tyche-side support for TPM attestation
neeluk7 Mar 20, 2024
8b98d9e
Added TPM signature verification on Tychools's side
neeluk7 Mar 20, 2024
32af8e1
Added modular tags for x86 compilation and a tpm-riscv comman in the …
neeluk7 Mar 27, 2024
0fd444d
Examples work after rebase. RoT example needs to be fixed.
neeluk7 Apr 2, 2024
f5846ea
Fixed rot_enclave example to match simple_enclave behavior
neeluk7 Apr 4, 2024
db093d6
Removed unused dependency
neeluk7 Apr 4, 2024
b41021c
Modularized if-else ladder into another file for RISC-V attestation
neeluk7 Apr 4, 2024
04e7281
Fixed justfile
neeluk7 Apr 9, 2024
9e78954
Fixed call number in rot_enclave example
neeluk7 Apr 9, 2024
5cdbc5e
Passed TPM information from OSBI to Tyche
neeluk7 Apr 17, 2024
3d34f22
Added changes after rebase
neeluk7 Apr 17, 2024
a534797
Added to allow unused_imports to bypass the static mutable warning
neeluk7 Apr 17, 2024
8372d8e
Fix memory leak on x86_64 patforms
CharlyCst Apr 30, 2024
994a067
Fixing compilation error for linux
aghosn May 2, 2024
8aed19b
Changes made according to PR review comments
neeluk7 Jun 5, 2024
40c40a4
Added output to file for PCR digest check
neeluk7 Jun 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions C/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ update_disk:
echo "Building tychools"
cargo build --manifest-path $(TYCHOOLS_PATH)/Cargo.toml --release --target=riscv64gc-unknown-linux-gnu --config target.riscv64gc-unknown-linux-gnu.linker=\"riscv64-unknown-linux-gnu-gcc\"
make ARCH=riscv -B -C libraries/sdktyche/example/simple-enclave install_disk
make ARCH=riscv -B -C libraries/sdktyche/example/enclave_rot_riscv install_disk
cp scripts/riscv64_install_drivers.sh /tmp/ubuntu_riscv_mount/tyche
cp scripts/run_eapp.sh /tmp/ubuntu_riscv_mount/tyche
cp $(TYCHOOLS_RISCV_PATH)/tychools $(PROGRAMGS_PATH)/tychools
Expand Down
3 changes: 3 additions & 0 deletions C/build_riscv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
make ARCH=riscv ubuntu_mount || exit
make ARCH=riscv update_disk
make ARCH=riscv ubuntu_umount
4 changes: 4 additions & 0 deletions C/libraries/sdktyche/example/enclave_rot_riscv/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
app
enclave
simple_enclave
enclave_iso
139 changes: 139 additions & 0 deletions C/libraries/sdktyche/example/enclave_rot_riscv/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
all: rot_enclave

GCC ?=gcc
KVM ?=1

ifeq ($(ARCH), riscv)
GCC = riscv64-unknown-linux-gnu-gcc
KVM = 0
endif

ifeq ($(KVM), 1)
LOADER_BACKEND = -DRUN_WITH_KVM=1
endif


## ————————————————————————————————— Paths —————————————————————————————————— ##
LIB_PATH=../../../
LIB_DRIVER=../../../../../linux/drivers/tyche/libraries/
DRIVERS_PATH=../../../../../linux/drivers/
LINKER_SCRIPT=../../../../../configs/riscv-linker-script-domain.x

## ——————————————————————————————— Libraries ———————————————————————————————— ##
SDK=$(LIB_PATH)/sdktyche
DLL_LIB= $(LIB_DRIVER)/dll
CAPA_LIB=$(LIB_DRIVER)/capabilities
COMMON_LIB=$(LIB_DRIVER)/common
ELF64=$(LIB_PATH)/elf64
PTS=$(LIB_PATH)/pts
DRIVER=$(DRIVERS_PATH)/tyche
CONTALLOC=$(DRIVERS_PATH)/contalloc

## ——————————————————————— Untrusted code and headers ——————————————————————— ##
CODE_UNTRUSTED=$(wildcard untrusted/*.c)
HDRS_UNTRUSTED=$(wildcard include/*.h)

## ———————————————————————— Trusted code and headers ———————————————————————— ##
CODE_TRUSTED=$(wildcard trusted/*.c)
HDRS_TRUSTED=$(wildcard include/*.h)

## ———————————————————————— Runtime code and headers ———————————————————————— ##
ifeq ($(ARCH), x86)
CODE_RUNTIME = $(wildcard $(SDK)/runtime/*.c) $(wildcard $(SDK)/runtime/asm.S)
HDRS_RUNTIME = $(wildcard $(SDK)/include/*.h)
else ifeq ($(ARCH), riscv)
CODE_RUNTIME = $(wildcard $(SDK)/runtime/*.c) $(wildcard $(SDK)/runtime/riscv_asm.S)
HDRS_RUNTIME = $(wildcard $(SDK)/include/*.h)
endif
# ———————————————————————— Code capabilities library ————————————————————————— #
CODE_CAPAS=$(wildcard $(CAPA_LIB)/src/*.c)
## ———————————————————————— Loader code and headers ————————————————————————— ##
CODE_LOADER=$(wildcard $(SDK)/loader/*.c) $(wildcard $(SDK)/loader/*.S)
HDRS_LOADER=$(wildcard $(SDK)/include/*.h)

ifeq ($(KVM), 1)
CODE_LOADER+=$(SDK)/loader/backends/back_kvm.c
else
CODE_LOADER+=$(SDK)/loader/backends/back_tyche.c
endif

## ————————————————————————— ELF64 code and headers ————————————————————————— ##
CODE_ELF64=$(wildcard $(ELF64)/src/*.c)
HDRS_ELF64=$(wildcard $(ELF64)/include/*.h)

## —————————————————————— Page table code and headers ——————————————————————— ##
CODE_PTS=$(wildcard $(PTS)/src/*.c)
HDRS_PTS=$(wildcard $(PTS)/include/*.h)

## —————————————————————— Application code and headers —————————————————————— ##
CODE_APP=$(CODE_ELF64) $(CODE_PTS) $(CODE_LOADER) $(CODE_UNTRUSTED)
HDRS_APP=$(HDRS_ELF64) $(HDRS_PTS) $(HDRS_LOADER) $(HDRS_UNTRUSTED)

## ———————————————————————— Enclave code and headers ———————————————————————— ##
CODE_ENCLAVE=$(CODE_RUNTIME) $(CODE_TRUSTED) $(CODE_CAPAS)
HDRS_ENCLAVE=$(HDRS_RUNTIME) $(HDRS_TRUSTED)

## ———————————————————————————————— Includes ———————————————————————————————— ##
COMMON_INCLUDES = -Iinclude -I$(CAPA_LIB)/include -I$(COMMON_LIB)/include -I$(DLL_LIB)/include -I$(SDK)/include
APP_INCLUDES = $(COMMON_INCLUDES) -I$(ELF64)/include -I$(PTS)/include -I$(DRIVER)/include

ifeq ($(KVM), 1)
APP_INCLUDES+=-I$(CONTALLOC)/include
endif

ifeq ($(ARCH), riscv)
APP_INCLUDES+=-pthread
endif

## ————————————————————— Configuration for the install —————————————————————— ##
ifeq ($(ARCH), riscv)
DISK_PATH ?= /tmp/ubuntu_riscv_mount/tyche/programs
endif

TYCHOOLS_PATH ?= ../../../../../crates/tychools/

## ———————————————————————————————— Targets ————————————————————————————————— ##

app: $(CODE_APP) $(HDRS_APP)
$(GCC) -DTYCHE_USER_SPACE=1 $(LOADER_BACKEND) -g $(APP_INCLUDES) -o $@ $(CODE_APP)


ifeq ($(ARCH), riscv)

enclave: $(CODE_ENCLAVE) $(HDRS_ENCLAVE)
echo "riscv"
echo $(GCC)
$(GCC) -DTYCHE_USER_SPACE=2 -DTYCHE_ENCLAVE=1 -DCONFIG_RISCV=1 -g $(COMMON_INCLUDES) -nostdlib -static -o $@ $(CODE_ENCLAVE) -Wl,--section-start=.data=0x16000

rot_iso: app enclave
cargo -C $(TYCHOOLS_PATH) install --path . --locked
tychools instrument -s manifests/rot_iso.json --riscv-enabled
chmod +x rot_iso
rm app enclave

rot_enclave: app enclave
cargo -Z unstable-options -C $(TYCHOOLS_PATH) install --path . --locked
tychools instrument -s manifests/default.json --riscv-enabled
chmod +x rot_enclave
rm app enclave

attestation_enclave: app enclave
echo "Building attestation enclave for RISCV with TPM RoT"
cargo -Z unstable-options -C $(TYCHOOLS_PATH) install --path . --locked
tychools instrument -s manifests/default.json --riscv-enabled
chmod +x rot_enclave
tychools instrument -s manifests/rot_iso.json --riscv-enabled
chmod +x rot_iso
rm app enclave
endif

install_disk: all
mkdir -p $(DISK_PATH)
cp -t $(DISK_PATH) rot_enclave
cp -t $(DISK_PATH) rot_iso

.PHONY: clean

clean:
rm rot_enclave
rm rot_iso
35 changes: 35 additions & 0 deletions C/libraries/sdktyche/example/enclave_rot_riscv/README.md
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this one hasn't been modified since being fetched from simple enclave. ^ ^
Maybe it could be edited to replace the simple enclave explanation with rot enclave explanation and same for the sample output too?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add the sample output for when TPM fields are set to zero?

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Simple Enclave Example


## How to run

This application runs by default or if you type:

```
./simple_enclave
```

### What it does

The application loads the enclave and performs two calls to it, printing two different messages.

### Sample output

```
dev@tyche:/tyche/programs$ ./simple_enclave
[LOG @../../..//sdktyche/loader/lib.c:269 parse_domain] Parsed tychools binary
[LOG @untrusted/main.c:92 main] The binary enclave has been loaded!
[LOG @untrusted/main.c:100 main] Calling the enclave, good luck!
[LOG @untrusted/main.c:49 hello_world] Executing HELLO_WORLD enclave

[ERROR | capa_engine::domain] Removing from a core in which the domains was NOT executing
[LOG @untrusted/main.c:56 hello_world] First enclave message:
Hello World!

[LOG @untrusted/main.c:63 hello_world] Second enclave message:
Bye Bye! :)!

[LOG @untrusted/main.c:70 hello_world] All done!
[LOG @untrusted/main.c:106 main] Done, have a good day!

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef __INCLUDE_ENCLAVE_APP_H__
#define __INCLUDE_ENCLAVE_APP_H__

/// Configuration for the enclave.
/// This allows to select which example to run via shared memory.
typedef struct {
/// arguments for this application.
void* args;
} config_t;

typedef unsigned long long nonce_t;
typedef unsigned long long phys_offset_t;
#define PUB_KEY_SIZE 32
#define SIGNED_DATA_SIZE 64
#define TPM_ATTESTATION_SIZE 129
#define TPM_SIGNATURE_SIZE 384
#define TPM_MODULUS_SIZE 384
#define SUPPOSED_ATTESTATION_SIZE 993
#define CALC_REPORT 0
#define READ_REPORT 1
/// Hello world argument.
typedef struct {
char reply[30];
unsigned long long report_size;
nonce_t nonce;
char pub_key[PUB_KEY_SIZE];
char signed_enclave_data[SIGNED_DATA_SIZE];
char tpm_signature[TPM_SIGNATURE_SIZE];
char tpm_modulus[TPM_MODULUS_SIZE];
char tpm_attestation[TPM_ATTESTATION_SIZE];
} __attribute__((__packed__)) hello_world_t;


#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"untrusted_bin": {
"path": "app"
},
"kern_bin": {
"path":"enclave",
"ops":[
{
"AddSegment":{
"size":8192,
"tpe":"KernelStackConf",
"write":true,"exec":false
}
},
{
"AddSegment":{
"start": 3145728,
"size":8192,
"tpe":"KernelShared",
"write":true,
"exec":false
}
}
]
},
"generate_pts": true,
"output": "rot_enclave"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"kern_bin": {
"path":"enclave",
"ops":[
{
"AddSegment":{
"size":8192,
"tpe":"KernelStackConf",
"write":true,"exec":false
}
},
{
"AddSegment":{
"start": 3145728,
"size":8192,
"tpe":"KernelShared",
"write":true,
"exec":false
}
}
]
},
"generate_pts": true,
"output": "rot_iso"
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally don't include the binaries and they are rebuilt locally by everyone so we may not end up facing any environment configuration/portability issues ^ ^
Could we please remove these? :)

Binary file not shown.
Binary file not shown.
Loading