]> git.proxmox.com Git - swtpm.git/blame - tests/test_tpm2_ibmtss2
swtpm_setup: Add support for --reconfigure flag to change active PCR banks
[swtpm.git] / tests / test_tpm2_ibmtss2
CommitLineData
03c7fe45
SB
1#!/usr/bin/env bash
2
3if [ ${SWTPM_TEST_EXPENSIVE:-0} -eq 0 ]; then
4 exit 77
5fi
6
7ROOT=${abs_top_builddir:-$(pwd)/..}
8TESTDIR=${abs_top_testdir:-$(dirname "$0")}
605e823f 9ABSTESTDIR=$(cd ${TESTDIR} &>/dev/null;echo ${PWD})
03c7fe45 10
e78c9db2
SB
11PATCHESDIR=${ABSTESTDIR}/patches
12
03c7fe45 13SWTPM_SERVER_PORT=65426
3e7555c4 14SWTPM_SERVER_NAME=127.0.0.1
03c7fe45
SB
15SWTPM_CTRL_PORT=65427
16SWTPM_INTERFACE=socket+socket
17
18function cleanup() {
19 pid=${SWTPM_PID}
20 if [ -n "$pid" ]; then
21 kill_quiet -9 $pid
22 fi
23 if [ -n ${WORKDIR} ]; then
24 rm -rf ${WORKDIR}
25 fi
26}
27
28trap "cleanup" EXIT
29
30source ${TESTDIR}/common
c48dd1e2
MAL
31skip_test_no_tpm20 "${SWTPM_EXE}"
32
cce7503c 33WORKDIR="$(mktemp -d)" || exit 1
03c7fe45
SB
34
35REGLOG=${WORKDIR}/reglog
36
37SWTPM_SERVER_NO_DISCONNECT="1" run_swtpm ${SWTPM_INTERFACE} \
38 --tpm2 \
39 --tpmstate dir=${WORKDIR} \
40 --flags not-need-init
41
42pushd ${WORKDIR} &>/dev/null
43
44git clone https://git.code.sf.net/p/ibmtpm20tss/tss ibmtpm20tss-tss
45
4ba6012c 46pushd ibmtpm20tss-tss &>/dev/null
03c7fe45 47
4d4d24fb 48git checkout tags/v1.6.0
03c7fe45
SB
49if [ $? -ne 0 ]; then
50 echo "'Git checkout' failed."
51 exit 1
52fi
53
b91575e7
SB
54# To be able to apply the patches we need to to set some variables
55# for user that don't have this set up properly
56git config --local user.name test
57git config --local user.email test@test.test
58
4d4d24fb 59# A v1.6.0 bug work-around:
8415d39d
SB
60# We cannot run the EK certificate tests since rootcerts.txt points to
61# files we do not have
e78c9db2 62git am < ${PATCHESDIR}/0001-Deactivate-test-cases-accessing-rootcerts.txt.patch
8415d39d 63
e78c9db2
SB
64# Implement 'powerup' for swtpm
65git am < ${PATCHESDIR}/0002-Implement-powerup-for-swtpm.patch
4ba6012c 66
e78c9db2
SB
67# set CRYPTOLIBRARY=openssl
68git am < ${PATCHESDIR}/0003-Set-CRYPTOLIBRARY-to-openssl.patch
69
be6ba388
SB
70# Store and restore volatile state at every step
71git am < ${PATCHESDIR}/0004-Store-and-restore-volatile-state-at-every-step.patch
e78c9db2
SB
72
73# Disable 'Events' test
74git am < ${PATCHESDIR}/0005-Disable-tests-related-to-events.patch
8dc2415d 75
605e823f
SB
76rsa3072=$(run_swtpm_ioctl ${SWTPM_INTERFACE} --info 4 |
77 sed -n 's/.*"RSAKeySizes":\[\([0-9,]*\)\].*/\1/p' |
78 grep 3072)
79if [ -z "$rsa3072" ]; then
80 echo "Modifying test cases related to RSA 3072 keys."
e78c9db2 81 git am < ${PATCHESDIR}/0006-Disable-testing-with-RSA-3072.patch
605e823f 82else
468f7e61 83 echo "swtpm/libtpms support RSA 3072 bit keys"
605e823f
SB
84fi
85
8dc2415d
SB
86# Adjust test suite to TPM 2.0 revision libtpms is implementing
87revision=$(run_swtpm_ioctl ${SWTPM_INTERFACE} --info 1 |
88 sed 's/.*,"revision":\([^\}]*\).*/\1/')
89echo "Libtpms implements TPM 2.0 revision ${revision}."
90if [ $revision -lt 155 ]; then
e78c9db2
SB
91 echo "Removing revision 155 and later test cases."
92 git am < ${PATCHESDIR}/0007-Disable-rev155-test-cases.patch
93 git am < ${PATCHESDIR}/0008-Disable-x509-test-cases.patch
94 git am < ${PATCHESDIR}/0009-Disable-getcapability-TPM_CAP_ACT.patch
8dc2415d
SB
95fi
96
e78c9db2
SB
97autoreconf --force --install
98unset CFLAGS LDFLAGS LIBS
99./configure --disable-tpm-1.2
100make -j4
101
102pushd utils
103
3e7555c4 104export TPM_SERVER_NAME=127.0.0.1
a1c9aedd 105export TPM_INTERFACE_TYPE=socsim
03c7fe45
SB
106export TPM_COMMAND_PORT=${SWTPM_SERVER_PORT}
107export TPM_PLATFORM_PORT=${SWTPM_CTRL_PORT}
108
109export SWTPM_IOCTL
110
03c7fe45
SB
111./startup
112if [ $? -ne 0 ]; then
113 echo "Startup of TPM2 failed"
114 exit 1
115fi
116
117./reg.sh -a 2>&1 | tee ${REGLOG}
118
119ret=0
120
121if [ -n "$(grep -E "^ ERROR:" ${REGLOG})" ]; then
122 echo "There were test failures running the IBM TSS 2 tests"
123 grep -E "^ ERROR:" ${REGLOG} -B2 -A2
124 ret=1
125fi
126
127# Shut down
128run_swtpm_ioctl ${SWTPM_INTERFACE} -s
129if [ $? -ne 0 ]; then
130 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
131 ret=1
132fi
133
134if wait_process_gone ${SWTPM_PID} 4; then
135 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
136 ret=1
137fi
138
4ba6012c 139popd &>/dev/null
03c7fe45
SB
140popd &>/dev/null
141popd &>/dev/null
142
143[ $ret -eq 0 ] && echo "OK"
144
c48dd1e2 145exit $ret