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