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