22# SPDX-License-Identifier: Apache-2.0
33# Copyright 2021 Keylime Authors
44
5+ # Check that the script is running from inside the repository tree
6+ GIT_ROOT=$( git rev-parse --show-toplevel) || {
7+ echo " Please run this script from inside the rust-keylime repository tree"
8+ exit 1
9+ }
10+
11+ TESTS_DIR=" ${GIT_ROOT} /tests"
12+ TEST_DATA_DIR=" ${GIT_ROOT} /test-data"
13+ TPMDIR=" ${TEST_DATA_DIR} /tpm-state"
14+
15+ # These certificates are used for the keylime/device_id tests
16+ IAK_IDEVID_CERTS=" ${GIT_ROOT} /keylime/test-data/iak-idevid-certs"
17+
518# Store the old TCTI setting
619OLD_TCTI=$TCTI
720OLD_TPM2TOOLS_TCTI=$TPM2TOOLS_TCTI
@@ -11,14 +24,13 @@ set -euf -o pipefail
1124
1225echo " -------- Setting up Software TPM"
1326
14- # Create temporary directories
15- TEMPDIR=$( mktemp -d)
16- TPMDIR=" ${TEMPDIR} /tpmdir"
17- mkdir -p ${TPMDIR}
27+ if [[ ! -d " ${TPMDIR} " ]]; then
28+ mkdir -p " ${TPMDIR} "
29+ fi
1830
1931# Manufacture a new Software TPM
2032swtpm_setup --tpm2 \
21- --tpmstate ${TPMDIR} \
33+ --tpmstate " ${TPMDIR} " \
2234 --createek --decryption --create-ek-cert \
2335 --create-platform-cert \
2436 --lock-nvram \
@@ -29,7 +41,7 @@ swtpm_setup --tpm2 \
2941function start_swtpm {
3042 # Initialize the swtpm socket
3143 swtpm socket --tpm2 \
32- --tpmstate dir=${TPMDIR} \
44+ --tpmstate dir=" ${TPMDIR} " \
3345 --flags startup-clear \
3446 --ctrl type=tcp,port=2322 \
3547 --server type=tcp,port=2321 \
@@ -39,7 +51,7 @@ function start_swtpm {
3951
4052function stop_swtpm {
4153 # Stop swtpm if running
42- if [[ -n " $SWTPM_PID " ]]; then
54+ if [[ -n " ${ SWTPM_PID} " ]]; then
4355 echo " Stopping swtpm"
4456 kill $SWTPM_PID
4557 fi
@@ -72,6 +84,25 @@ RUST_BACKTRACE=1 cargo build
7284
7385echo " -------- Testing"
7486start_swtpm
87+
88+
89+ # Check that tpm2-openssl provider is available
90+ if openssl list -provider tpm2 -providers > /dev/null; then
91+ # If any IAK/IDevID related certificate is missing, re-generate them
92+ if [[ ( ! -f " ${IAK_IDEVID_CERTS} /iak.cert.pem" ) ||
93+ ( ! -f " ${IAK_IDEVID_CERTS} /iak.cert.der" ) ||
94+ ( ! -f " ${IAK_IDEVID_CERTS} /idevid.cert.pem" ) ||
95+ ( ! -f " ${IAK_IDEVID_CERTS} /idevid.cert.der" ) ||
96+ ( ! -f " ${IAK_IDEVID_CERTS} /ca-cert-chain.pem" ) ]]
97+ then
98+ # Remove any leftover from old certificates
99+ rm -rf " ${IAK_IDEVID_CERTS} "
100+ mkdir -p " ${IAK_IDEVID_CERTS} "
101+ echo " -------- Create IAK/IDevID certificates"
102+ " ${GIT_ROOT} /tests/generate-iak-idevid-certs.sh" -o " ${IAK_IDEVID_CERTS} "
103+ fi
104+ fi
105+
75106mkdir -p /var/lib/keylime
76107RUST_BACKTRACE=1 RUST_LOG=info \
77108KEYLIME_CONFIG=$PWD /keylime-agent.conf \
0 commit comments