Skip to content

Commit 2057d4c

Browse files
committed
example-setup: updated scripts and vm
Signed-off-by: Simon Ott <simon.ott@aisec.fraunhofer.de>
1 parent 56ffdc3 commit 2057d4c

25 files changed

+177
-67
lines changed

bin/cmc-docker

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ uidn=$(id -un)
1111
gidn=$(id -gn)
1212

1313
name="cmc$(printf "%s" "${dir}" | tr '/' '-')"
14+
hostname="cmc-docker"
1415

1516
qgs_path="/var/run/tdx-qgs"
1617

@@ -24,6 +25,8 @@ if [[ -z "$(docker images -q ${name})" ]]; then
2425
docker build --no-cache --tag "${name}" -f "${dir}/example-setup/docker/cmc.dockerfile" .
2526
fi
2627

28+
test -c "/dev/tpm0" && tpm0="--device /dev/tpm0" || tpm0=""
29+
test -c "/dev/tpmrm0" && tpmrm0="--device /dev/tpmrm0" || tpmrm0=""
2730
test -c "/dev/kvm" && kvm="--device /dev/kvm" || kvm=""
2831
test -c "/dev/sev" && sev="--device /dev/sev" || sev=""
2932
test -c "/dev/sgx_enclave" && sgx_enclave="--device /dev/sgx_enclave" || sgx_enclave=""
@@ -35,12 +38,18 @@ if [[ -z "$(docker ps -aq -f name=${name})" ]]; then
3538
echo "Creating container ${name}.."
3639
docker create \
3740
--name "${name}" \
41+
--hostname "${hostname}" \
3842
-it \
3943
--mount type=bind,src="${dir}",dst="${dir}" \
44+
--mount type=bind,src=/sys/kernel/security,dst=/sys/kernel/security,ro \
45+
--cap-add SYS_ADMIN \
46+
--security-opt apparmor=unconfined \
47+
--security-opt seccomp=unconfined \
4048
--network "${name}" \
4149
-p 9955:9955 \
4250
-p 4443:4443 \
4351
${kvm} \
52+
${tpm0} ${tpmrm0} \
4453
${sev} \
4554
${sgx_enclave} \
4655
${sgx_provision} \
@@ -60,12 +69,10 @@ if [[ -z "$(docker ps -q -f name=${name})" ]]; then
6069
docker exec "${name}" chown "${uid}":"${gid}" /dev/sev || true
6170
docker exec "${name}" chown "${uid}":"${gid}" /dev/sgx_enclave || true
6271
docker exec "${name}" chown "${uid}":"${gid}" /dev/sgx_provision || true
63-
docker exec \
64-
--user "${uid}":"${gid}" \
65-
--env HOME="${HOME}" \
66-
--env PATH="/usr/bin:/usr/local/go/bin:$HOME/go/bin:${dir}/bin" \
67-
--workdir "${dir}/cmc" \
68-
"${name}" sh -c "go build ./... && go install ./..."
72+
# Required for reading measurement logs
73+
docker exec "${name}" sh -c \
74+
"u=\$(getent passwd ${uid} | cut -d: -f1) && \
75+
echo \"\$u ALL=(ALL) NOPASSWD:ALL\" > /etc/sudoers.d/\$u"
6976
fi
7077

7178
# Run specified command

bin/generate-app-manifest-tpm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ referenceValues=$("${mrtool[@]}" parse ima --mrs 10)
4545
json=$(cat "${input}/manifest.json")
4646

4747
# App Manifest: Insert reference values
48-
while IFS= read -r element; do
49-
json=$(echo "${json}" | jq --argjson element "${element}" '.referenceValues += [$element]')
50-
done < <(echo "${referenceValues}" | jq -c '.[]')
48+
json=$(jq -n --argjson base "$json" --slurpfile ver <(printf '%s' "$referenceValues") '$base | .referenceValues += $ver[0]')
49+
5150

5251
# App Manifest: Set other properties
5352
setjson "json" "name" "${name}"

bin/generate-metadata-container

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
trap '[ $? -eq 0 ] && exit 0; printf "%s failed\n" "$0"' EXIT
6+
dir="$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd -P)"
7+
source "${dir}/bin/utils.sh"
8+
9+
bin="${dir}/bin"
10+
11+
"${bin}/generate-image-description" "tpm-test-image"
12+
13+
"${bin}/generate-rtm-manifest-tpm"
14+
15+
"${bin}/generate-os-manifest-tpm"
16+
17+
"${bin}/generate-app-manifest-tpm"
18+
19+
"${bin}/generate-container-manifest" "docker" "ubuntu:24.04"

bin/generate-metadata-tpm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,3 @@ bin="${dir}/bin"
1515
"${bin}/generate-os-manifest-tpm"
1616

1717
"${bin}/generate-app-manifest-tpm"
18-
19-
"${bin}/generate-container-manifest" "docker" "ubuntu:24.04"

bin/generate-os-manifest-tpm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ json=$(echo "${json}" | jq ".details.os = \"${os}\"")
6868

6969
# Insert reference values in the OS Manifest
7070
json=$(echo "${json}" | jq 'del(.referenceValues[])')
71-
json=$(echo "${json}" | jq --argjson ver "${referenceValues}" '.referenceValues += $ver')
71+
json=$(jq -n --argjson base "$json" --slurpfile ver <(printf '%s' "$referenceValues") '$base | .referenceValues += $ver[0]')
7272

7373
# Save manifest
7474
echo "Writing ${out}/rtm.manifest.json"

bin/generate-rtm-manifest-tpm

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ mkdir -p "${out}"
3939

4040
echo "Using ${data} as directory for local data"
4141

42-
# Retrieve platform details
43-
set +e
44-
firmware="Lenovo"
45-
bootloader=$(grub-install --version)
46-
set -e
47-
4842
# Parse the values of the RTM PCRs from the kernel's binary bios measurements as reference values
4943
referenceValues=$("${mrtool[@]}" parse tpm --mrs 0,1,2,3,4,5,6,7)
5044

@@ -63,13 +57,9 @@ setjson "json" "description" "RTM Manifest"
6357
setarr "json" "baseLayers" "${name}"
6458
setjson "json" "certLevel" 3
6559

66-
# Insert platform details
67-
json=$(echo "${json}" | jq ".details.firmware = \"${firmware}\"")
68-
json=$(echo "${json}" | jq ".details.bootloader = \"${bootloader}\"")
69-
7060
# Replace existing reference values with new reference values in the RTM Manifest
7161
json=$(echo "${json}" | jq 'del(.referenceValues[])')
72-
json=$(echo "${json}" | jq --argjson ver "${referenceValues}" '.referenceValues += $ver')
62+
json=$(jq -n --argjson base "$json" --slurpfile ver <(printf '%s' "$referenceValues") '$base | .referenceValues += $ver[0]')
7363

7464
# Save the RTM manifest
7565
echo "Writing ${out}/rtm.manifest.json"

bin/setup-cmc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,21 @@ fi
6363
echo "Using CMC: ${cmc}"
6464
echo "Using ${data} as directory for local data"
6565

66-
# Build CMC
67-
echo "Building CMC"
66+
# Install CMC
67+
echo "Installing CMC"
68+
go install -C "${dir}/cmcd"
69+
go install -C "${dir}/cmcctl"
70+
go install -C "${dir}/provision/estserver"
71+
go install -C "${dir}/tools/mrtool"
72+
go install -C "${dir}/tools/metaconv"
73+
go install -C "${dir}/tools/metasign"
74+
go install -C "${dir}/tools/tdxtool"
75+
go install -C "${dir}/tools/snptool"
76+
go install -C "${dir}/tools/tdxtool"
77+
go install -C "${dir}/tools/cmcbackend"
78+
79+
# Build CMC to be present in local folders
80+
echo "Locally Building CMC"
6881
go build -C "${dir}/cmcd"
6982
go build -C "${dir}/cmcctl"
7083
go build -C "${dir}/provision/estserver"
@@ -74,6 +87,7 @@ go build -C "${dir}/tools/metasign"
7487
go build -C "${dir}/tools/tdxtool"
7588
go build -C "${dir}/tools/snptool"
7689
go build -C "${dir}/tools/tdxtool"
90+
go build -C "${dir}/tools/cmcbackend"
7791

7892
# Create a folder for the cmc configuration and metadata
7993
mkdir -p "${data}"

bin/vm-update-cmcd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ vm-ssh systemctl stop cmcd
1818
vm-ssh systemctl stop cmcctl
1919

2020
# Remove cmc internal folder to enforce generation of new certs
21-
vm-ssh rm -r /var/cmc/internal
21+
vm-ssh rm -rf /var/cmc/internal
2222

2323
# Copy new binaries into VM
2424
vm-scp cmcd/cmcd vm-ubuntu:/usr/bin/

bin/vm-update-metadata

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ fi
2727

2828
sign-metadata json
2929

30+
mkdir -p "${dir}/example-setup/vm-config/vm-metadata/"
31+
3032
cp "${dir}/data/metadata-signed/"* "${dir}/example-setup/vm-config/vm-metadata/"
3133
cp "${dir}/data/pki/ca.pem" "${dir}/example-setup/vm-config/metadata-ca.pem"
3234

3335
# Delete cmc internal data to enforce new certificate generation
34-
vm-ssh rm -r /var/cmc
36+
vm-ssh rm -rf /var/cmc
3537

3638
# Restarting cmcd is required for fetching the updated metadata
3739
vm-ssh systemctl restart cmcd

doc/run.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,49 +34,52 @@ The cmcctl can run the following commands, specified via the first parameter or
3434

3535
```sh
3636
# Start the EST server that supplies the certificates and metadata for the cmcd
37-
./estserver -config cmc-data/est-server-conf.json
37+
estserver -config example-setup/configs/installed/est-server-conf.json
3838
```
3939

4040
#### Run the cmcd
4141

4242
```sh
43-
# Build and run the cmcd
44-
./cmcd -config cmc-data/cmcd-conf.json
43+
# Run the cmcd
44+
cmcd -config example-setup/configs/installed/cmcd-conf.json
45+
46+
# NOTE: for setups that require root, e.g., to access the tpm, make sure the installed go binaries
47+
# are found:
48+
sudo env PATH="$HOME/go/bin:$PATH" cmcd -config example-setup/configs/installed/cmcd-conf.json
4549
```
4650

4751
#### Generate and Verify Attestation Reports
4852

4953
```sh
5054
# Run cmcctl to retrieve an attestation report (stored in current folder unless otherwise specified)
51-
./cmcctl -mode generate
55+
cmcctl generate -config example-setup/configs/installed/cmcctl-conf.json
5256

5357
# Run cmcctl to verify the attestation report (stored in current folder unless otherwise specified)
54-
./cmcctl -mode verify -ca cmc-data/pki/ca.pem
58+
cmcctl verify -config example-setup/configs/installed/cmcctl-conf.json
5559
```
5660

5761
#### Establish Attested TLS Connections
5862

5963
```sh
6064

6165
# Run an attested TLS server
62-
./cmcctl -mode listen -addr 0.0.0.0:4443 -ca cmc-data/pki/ca.pem -mtls
66+
cmcctl listen -config example-setup/configs/installed/cmcctl-conf.json -addr "$(hostname --fqdn):4443"
6367

6468
# Run an attested TLS client estblishing a mutually attested TLS connection to the server
65-
./cmcctl -mode dial -addr localhost:4443 -ca cmc-data/pki/ca.pem -mtls
69+
cmcctl dial -config example-setup/configs/installed/cmcctl-conf.json -addr "$(hostname --fqdn):4443"
6670
```
6771

6872
#### Establish Attested HTTPS Connections
6973

7074
```sh
7175
# Run two attested HTTPS servers
72-
./cmcctl -config cmcctl-config.json -addr 0.0.0.0:8081 -mode serve
76+
cmcctl serve -config example-setup/configs/installed/cmcctl-conf.json -addr "$(hostname --fqdn):8082"
7377

7478
# Perform multiple user-specified attested HTTPS requests to both servers. Each connection is
7579
# attested, while multiple requests to the same server use the established attested TLS connections
76-
./cmcctl \
77-
-config ../data/cmcctl-config.json \
78-
-addr https://localhost:8081/post,https://localhost:8082/post \
79-
-mode request \
80+
cmcctl request \
81+
-config example-setup/configs/installed/cmcctl-conf.json \
82+
-addr "https://$(hostname --fqdn):8082" \
8083
-method POST \
8184
-data "hello from attested HTTPS client" \
8285
-header "Content-Type: text/plain"

0 commit comments

Comments
 (0)