forked from confidential-containers/td-shim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_final.sh
81 lines (65 loc) · 2.86 KB
/
build_final.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
export CC_x86_64_unknown_none=clang
export AR_x86_64_unknown_none=llvm-ar
export CC=clang
export AR=llvm-ar
export AS=nasm
config_num=5
if [[ ! $PWD =~ td-shim$ ]];then
pushd ..
fi
final_boot_kernel() {
echo "Build final binary with boot-kernel support"
cargo image --release -o target/release/final-boot-kernel.bin
}
final_elf() {
echo final-elf
cargo --example-payload -o target/release/final-elf.bin
}
final_elf_test() {
echo "Build final binary with ELF format test td payload"
pushd tests
cargo build -p test-td-payload --target x86_64-unknown-none --release --features=main,tdx --no-default-features
popd
cargo run -p td-shim-tools --bin td-shim-strip-info -- -n test-td-payload --target x86_64-unknown-none
for ((i=1; i<=${config_num}; i++))
do
cargo image --release -t executable \
-p target/x86_64-unknown-none/release/test-td-payload \
--enroll-file F10E684E-3ABD-20E4-5932-8F973C355E57,tests/test-td-payload/config/test_config_${i}.json \
-o target/release/final-elf-test${i}.bin
done
}
final_elf_sb_test() {
echo "Build final binaries with ELF format td payload for secure boot test"
cargo build -p td-payload --target x86_64-unknown-none --release --bin example --features=tdx,start,cet-shstk,stack-guard
cargo run -p td-shim-tools --bin td-shim-strip-info -- -n example --target x86_64-unknown-none
cargo run -p td-shim-tools --bin td-shim-sign-payload -- -A ECDSA_NIST_P384_SHA384 data/sample-keys/ecdsa-p384-private.pk8 target/x86_64-unknown-none/release/example 1 1
echo "Build final binary with unsigned td payload"
cargo image --release -t executable --features secure-boot \
-p target/x86_64-unknown-none/release/example \
-H SHA384 \
--enroll-key data/sample-keys/ecdsa-p384-public.der \
-o target/release/final-elf-sb-unsigned.bin
echo "Build final binary with signed td payload and enroll uncorrect public key in CFV"
cargo image --release -t executable --features secure-boot \
-p target/x86_64-unknown-none/release/td-payload-signed \
-H SHA384 \
--enroll-key data/sample-keys/rsa-3072-public.der \
-o target/release/final-elf-sb-mismatch-pubkey.bin
echo "Build final binary with signed td payload and enroll correct public key in CFV"
cargo image --release -t executable --features secure-boot \
-p target/x86_64-unknown-none/release/td-payload-signed \
-H SHA384 \
--enroll-key data/sample-keys/ecdsa-p384-public.der \
-o target/release/final-elf-sb-normal.bin
}
./sh_script/preparation.sh
case "${1:-}" in
boot_kernel) final_boot_kernel ;;
pe) final_pe ;;
elf) final_elf ;;
elf_test) final_elf_test ;;
elf_sb_test) final_elf_sb_test ;;
*) final_boot_kernel && final_elf && final_elf_test && final_elf_sb_test;;
esac