]> git.proxmox.com Git - swtpm.git/blob - tests/test_tpm2_ibmtss2
tests: Use the IBM TSS2 v1.6.0's test suite
[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 ROOT=${abs_top_builddir:-$(pwd)/..}
8 TESTDIR=${abs_top_testdir:-$(dirname "$0")}
9 ABSTESTDIR=$(cd ${TESTDIR} &>/dev/null;echo ${PWD})
10
11 SWTPM_SERVER_PORT=65426
12 SWTPM_SERVER_NAME=127.0.0.1
13 SWTPM_CTRL_PORT=65427
14 SWTPM_INTERFACE=socket+socket
15
16 function cleanup() {
17 pid=${SWTPM_PID}
18 if [ -n "$pid" ]; then
19 kill_quiet -9 $pid
20 fi
21 if [ -n ${WORKDIR} ]; then
22 rm -rf ${WORKDIR}
23 fi
24 }
25
26 trap "cleanup" EXIT
27
28 source ${TESTDIR}/common
29 WORKDIR=$(mktemp -d)
30
31 REGLOG=${WORKDIR}/reglog
32
33 SWTPM_SERVER_NO_DISCONNECT="1" run_swtpm ${SWTPM_INTERFACE} \
34 --tpm2 \
35 --tpmstate dir=${WORKDIR} \
36 --flags not-need-init
37
38 pushd ${WORKDIR} &>/dev/null
39
40 git clone https://git.code.sf.net/p/ibmtpm20tss/tss ibmtpm20tss-tss
41
42 pushd ibmtpm20tss-tss &>/dev/null
43
44 git checkout tags/v1.6.0
45 if [ $? -ne 0 ]; then
46 echo "'Git checkout' failed."
47 exit 1
48 fi
49
50 # A v1.6.0 bug work-around:
51 pushd utils/regtests &>/dev/null
52 # We cannot run the EK certificate tests since rootcerts.txt points to
53 # files we do not have
54 for line in 303 304 305 405 406 407 543 544 545; do
55 sed -i "${line}s/./\#\0/" testcredential.sh
56 done
57 for line in 727 728;do
58 sed -i "${line}s/./\#\0/" testunseal.sh
59 done
60 # We do not run the UEFI tests
61 sed -i '2 i exit 0' testevent.sh
62 popd &>/dev/null
63
64 autoreconf --force --install
65 unset CFLAGS LDFLAGS LIBS
66 ./configure --disable-tpm-1.2
67 make -j4
68
69 pushd utils
70
71 rsa3072=$(run_swtpm_ioctl ${SWTPM_INTERFACE} --info 4 |
72 sed -n 's/.*"RSAKeySizes":\[\([0-9,]*\)\].*/\1/p' |
73 grep 3072)
74 if [ -z "$rsa3072" ]; then
75 echo "Modifying test cases related to RSA 3072 keys."
76
77 patch -p2 < "${ABSTESTDIR}/patches/ibmtss2_1.6_rsa2048only.patch"
78 if [ $? -ne 0 ]; then
79 echo "Patching of testsuite failed"
80 exit 1
81 fi
82 else
83 echo "swtpm/libtpms support RSA 3072 bit keys"
84 fi
85
86 sed -i 's/export CRYPTOLIBRARY.*/export CRYPTOLIBRARY=openssl/' reg.sh
87
88 # Adjust test suite to TPM 2.0 revision libtpms is implementing
89 revision=$(run_swtpm_ioctl ${SWTPM_INTERFACE} --info 1 |
90 sed 's/.*,"revision":\([^\}]*\).*/\1/')
91 echo "Libtpms implements TPM 2.0 revision ${revision}."
92 if [ $revision -lt 155 ]; then
93 echo "Removing revision 155 test cases."
94 for t in regtests/testattest155.sh regtests/testx509.sh
95 do
96 rm "${t}"
97 touch "${t}"
98 chmod 777 "${t}"
99 done
100 # CAP_ACT was introduced later than 155
101 for line in 123 124 125; do
102 sed -i "${line}s/./\#\0/" regtests/testgetcap.sh
103 done
104 fi
105
106 export TPM_SERVER_NAME=127.0.0.1
107 export TPM_INTERFACE_TYPE=socsim
108 export TPM_COMMAND_PORT=${SWTPM_SERVER_PORT}
109 export TPM_PLATFORM_PORT=${SWTPM_CTRL_PORT}
110
111 export SWTPM_IOCTL
112
113 cat <<_EOF_ > powerup
114 #!/usr/bin/env bash
115 \${SWTPM_IOCTL} -i --tcp \${TPM_SERVER_NAME}:\${TPM_PLATFORM_PORT}
116 exit \$?
117 _EOF_
118 chmod 755 powerup
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