blob: 722aaacb4433044abc1fa59aa1665b55e88e8b39 [file] [log] [blame]
Stefan Bergerd617dd62019-06-13 20:07:12 -04001#!/bin/bash
2
3# For the license, see the LICENSE file in the root directory.
4#set -x
5
6ROOT=${abs_top_builddir:-$(pwd)/..}
7TESTDIR=${abs_top_testdir:-$(dirname "$0")}
8
9VTPM_NAME="vtpm-test-tpm2-derived-keys"
10SWTPM_DEV_NAME="/dev/${VTPM_NAME}"
11SWTPM_INTERFACE=${SWTPM_INTERFACE:-cuse}
12
13tpmstatedir="$(mktemp -d)"
14if [ -z "$tpmstatedir" ]; then
15 echo "Could not create temporary directory"
16 exit 1
17fi
18
19SWTPM_CMD_UNIX_PATH=${tpmstatedir}/unix-cmd.sock
20SWTPM_CTRL_UNIX_PATH=${tpmstatedir}/unix-ctrl.sock
21
22function cleanup()
23{
24 pid=${SWTPM_PID}
25 if [ -n "$pid" ]; then
Stefan Bergerfd7a8122023-01-12 13:19:55 -050026 kill_quiet -9 "$pid"
Stefan Bergerd617dd62019-06-13 20:07:12 -040027 fi
Stefan Bergerfd7a8122023-01-12 13:19:55 -050028 rm -rf "$tpmstatedir"
Stefan Bergerd617dd62019-06-13 20:07:12 -040029}
30
31trap "cleanup" EXIT
32
Stefan Bergerfd7a8122023-01-12 13:19:55 -050033[ "${SWTPM_INTERFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
34source "${TESTDIR}/common"
Stefan Bergerd617dd62019-06-13 20:07:12 -040035
Stefan Bergerfd7a8122023-01-12 13:19:55 -050036TPM_PATH=$tpmstatedir
Stefan Bergerd617dd62019-06-13 20:07:12 -040037
38# copy all the state files
Stefan Bergerfd7a8122023-01-12 13:19:55 -050039cp "${TESTDIR}"/data/tpm2state1/* "${TPM_PATH}"
Stefan Bergerd617dd62019-06-13 20:07:12 -040040
Stefan Bergerfd7a8122023-01-12 13:19:55 -050041TPM_PATH=$TPM_PATH run_swtpm "${SWTPM_INTERFACE}" --tpm2
Stefan Bergerd617dd62019-06-13 20:07:12 -040042
Stefan Berger57043422023-01-26 11:06:26 -050043if ! kill_quiet -0 "${SWTPM_PID}"; then
Stefan Bergerd617dd62019-06-13 20:07:12 -040044 echo "Error: ${SWTPM_INTERFACE} TPM did not start."
45 exit 1
46fi
47
48# Create a key
49# @param1: reset (!= 0) TPM before creating key;
50# @param2: whether to send TPM2_Startup
51# @param3: command to send
52# @param4: expected return value
Stefan Bergerdfd36eb2020-02-25 21:34:21 -050053# @param5: allowed failure return value to skip test
Stefan Bergerd617dd62019-06-13 20:07:12 -040054function tx_cmd()
55{
56 local reset="$1"
57 local startup="$2"
58 local cmd="$3"
59 local exp="$4"
Stefan Bergerdfd36eb2020-02-25 21:34:21 -050060 local allowed_error="$5"
Stefan Bergerd617dd62019-06-13 20:07:12 -040061
62 local RES tmp
63
64 if [ "$reset" != "0" ]; then
Stefan Berger57043422023-01-26 11:06:26 -050065 if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -i; then
Stefan Bergerd617dd62019-06-13 20:07:12 -040066 echo "Error: Could not send TPM_INIT"
67 return 1
68 fi
69 fi
70 if [ "$startup" != "0" ]; then
Stefan Bergerfd7a8122023-01-12 13:19:55 -050071 RES=$(swtpm_cmd_tx "${SWTPM_INTERFACE}" '\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00')
Stefan Bergerd617dd62019-06-13 20:07:12 -040072 tmp=' 80 01 00 00 00 0a 00 00 00 00'
73 if [ "$RES" != "$tmp" ]; then
74 echo "Error: Did not get expected response from TPM2_Startup"
75 echo "expected: $tmp"
76 echo "received: $RES"
77 return 1
78 fi
Stefan Bergerd617dd62019-06-13 20:07:12 -040079 fi
80
Stefan Bergerfd7a8122023-01-12 13:19:55 -050081 RES=$(swtpm_cmd_tx "${SWTPM_INTERFACE}" "${cmd}")
Stefan Bergerdfd36eb2020-02-25 21:34:21 -050082 if [ "$RES" == "$allowed_error" ]; then
83 echo "Skip: Encountered allowed error response ($allowed_error)"
84 elif [ "$RES" != "$exp" ]; then
Stefan Bergerd617dd62019-06-13 20:07:12 -040085 echo "Error: Did not get expected return from creating key"
86 echo "expected: $exp"
87 echo "received: $RES"
88 return 1
89 fi
Stefan Bergerd617dd62019-06-13 20:07:12 -040090
91 return 0
92}
93
Stefan Bergerdfd36eb2020-02-25 21:34:21 -050094# Older versions of libtpms do not support TDES
95# So we may skip the test in case we hit this error
96error_unsupt_algo=' 80 01 00 00 00 0a 00 00 02 d6'
97
Stefan Bergerd617dd62019-06-13 20:07:12 -040098# Create a primary RSA key and expect a predictable return value
99# tsscreateprimary -hi e -v
100# -> creates key with handle 0x80 00 00 00
101test1_cmd='\x80\x02\x00\x00\x00\x43\x00\x00\x01\x31\x40\x00\x00\x0b\x00\x00'
102test1_cmd+='\x00\x09\x40\x00\x00\x09\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00'
103test1_cmd+='\x00\x00\x1a\x00\x01\x00\x0b\x00\x03\x04\x72\x00\x00\x00\x06\x00'
104test1_cmd+='\x80\x00\x43\x00\x10\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
105test1_cmd+='\x00\x00\x00'
106
107test1_exp=' 80 02 00 00 01 fa 00 00 00 00 80 00 00 00 00 00'
108test1_exp+=' 01 e3 01 1a 00 01 00 0b 00 03 04 72 00 00 00 06 00'
109test1_exp+=' 80 00 43 00 10 08 00 00 00 00 00 01 00 b5 0a c8 18'
110test1_exp+=' 00 01 82 b6 53 63 fc a1 ba 4d 13 d2 1e 05 63 08 bb'
111test1_exp+=' df b3 95 c5 e0 d7 42 f8 c4 21 f1 c7 df ac ee 57 e4'
112test1_exp+=' 3d 80 7b da 33 95 76 56 cc 73 df 0b 33 db 4b 3a f0'
113test1_exp+=' d1 80 86 a2 35 df a9 a7 82 4b 6d 1e 88 d7 e8 d9 73'
114test1_exp+=' 0b 6c d3 c5 ef b9 5c fb 92 69 d8 c0 d8 e9 a1 fa a3'
115test1_exp+=' 72 dc 6a 3e 8c c4 a7 8e 9f b8 f2 0e b3 64 e0 8c cb'
116test1_exp+=' f0 02 31 d1 b6 ee 2c de e7 c7 92 7e 34 b8 46 80 7e'
117test1_exp+=' f6 0a f9 b6 57 e0 91 51 18 27 5b fe 8a e7 22 d2 41'
118test1_exp+=' e1 e6 16 d6 04 e0 03 a9 1c be 5d 6b 37 a7 d7 03 45'
119test1_exp+=' 7e dc 96 ad 5d ea bb 99 c5 e1 07 a9 70 6f b2 89 d9'
120test1_exp+=' 4b c1 cc 01 fa df 6d 74 de ca f9 41 bf be 89 bd 53'
121test1_exp+=' 79 ee 28 8e ef 81 16 c2 d1 6d cf 10 49 06 23 ba b3'
122test1_exp+=' ab d7 27 fc 7c f2 6a f4 8a 75 5b de ea dc e9 33 0a'
123test1_exp+=' e8 d5 70 2b 5a 94 03 f7 5e 75 5d 76 08 3b 6e c1 2c'
124test1_exp+=' 1f cb 28 68 ab 82 87 49 70 96 96 56 ac d7 00 37 00'
125test1_exp+=' 00 00 00 00 20 e3 b0 c4 42 98 fc 1c 14 9a fb f4 c8'
126test1_exp+=' 99 6f b9 24 27 ae 41 e4 64 9b 93 4c a4 95 99 1b 78'
127test1_exp+=' 52 b8 55 01 00 10 00 04 40 00 00 0b 00 04 40 00 00'
128test1_exp+=' 0b 00 00 00 20 28 d0 26 fa fd 74 91 06 74 3e 27 c4'
129test1_exp+=' 28 05 51 58 5e 5d 17 66 8e b5 21 83 5e d6 01 27 ef'
130test1_exp+=' fc 05 d4 80 21 40 00 00 0b 00 40 dc 19 bf 88 fc 7b'
131test1_exp+=' d8 5c 0b 40 fb 0f ec b0 af 6b f1 46 3e 26 bf bf 74'
132test1_exp+=' 95 ec 0e 6f 60 b3 e7 dd 29 55 11 3f 9f ee 9f 75 27'
133test1_exp+=' d8 b5 4a 51 72 6e dc a1 68 a6 0a 6d d3 70 1f 0c 00'
134test1_exp+=' df 79 60 23 86 83 e0 00 22 00 0b 45 fe 98 72 0a c6'
135test1_exp+=' cf 0a ca 16 37 28 d9 e2 33 a9 d5 4f 5d b5 d3 78 bf'
136test1_exp+=' 40 20 60 b3 85 8d 41 ff c7 00 00 01 00 00'
137
138# Create a primary ECC key and expect a predictable return value
139# tsscreateprimary -hi e -ecc bnp256 -v
140# -> creates key with handle 0x80 00 00 00
141test2_cmd='\x80\x02\x00\x00\x00\x43\x00\x00\x01\x31\x40\x00\x00\x0b\x00\x00'
142test2_cmd+='\x00\x09\x40\x00\x00\x09\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00'
143test2_cmd+='\x00\x00\x1a\x00\x23\x00\x0b\x00\x03\x04\x72\x00\x00\x00\x06\x00'
144test2_cmd+='\x80\x00\x43\x00\x10\x00\x03\x00\x10\x00\x00\x00\x00\x00\x00\x00'
145test2_cmd+='\x00\x00\x00'
146
147test2_exp=' 80 02 00 00 01 3a 00 00 00 00 80 00 00 00 00 00 01 23'
148test2_exp+=' 00 5a 00 23 00 0b 00 03 04 72 00 00 00 06 00 80 00 43'
149test2_exp+=' 00 10 00 03 00 10 00 20 15 86 c2 64 96 e4 b1 07 83 17 de 90'
150test2_exp+=' da 9e df 61 42 e2 12 6b 94 48 c9 d9 bc e6 31 03 8e 8b fb 1f'
151test2_exp+=' 00 20 37 26 ca 32 f2 6d 75 cb 1f 5d e8 8e b6 3e 96 8e 10 a0'
152test2_exp+=' 1c df 55 91 4a 9b 50 a1 2a e6 a1 ee 32 45 00 37 00 00 00 00'
153test2_exp+=' 00 20 e3 b0 c4 42 98 fc 1c 14 9a fb f4 c8 99 6f b9 24 27 ae'
154test2_exp+=' 41 e4 64 9b 93 4c a4 95 99 1b 78 52 b8 55 01 00 10 00 04 40'
155test2_exp+=' 00 00 0b 00 04 40 00 00 0b 00 00 00 20 28 d0 26 fa fd 74 91'
156test2_exp+=' 06 74 3e 27 c4 28 05 51 58 5e 5d 17 66 8e b5 21 83 5e d6 01'
157test2_exp+=' 27 ef fc 05 d4 80 21 40 00 00 0b 00 40 99 3f 24 8d 87 28 fe'
158test2_exp+=' bb 5d 1b be fc 12 2c cd 4e 5b 03 22 7a 78 00 3b 64 76 ec 08'
159test2_exp+=' 11 2f 4c 36 7b 36 f7 83 1a 59 74 19 fe 52 45 81 f7 08 bc be'
160test2_exp+=' b0 e1 99 37 1a 3e 7b ba cb dc 3e 20 d8 51 82 45 24 00 22 00'
161test2_exp+=' 0b ac 4c a0 86 53 fa 68 b2 c9 54 f5 7e f7 c2 54 12 0a 08 03'
162test2_exp+=' de 8e 96 e1 f1 89 97 52 a8 1a fb 0b cc 00 00 01 00 00'
163
164# Create an AES key and expect a predictable return value
165# tsscreateloaded -hp 40000001 -rsa -des -v
166# -> creates key with handle 0x80 00 00 00
167test3_cmd='\x80\x02\x00\x00\x00\x35\x00\x00\x01\x91\x40\x00\x00\x01\x00\x00'
168test3_cmd+='\x00\x09\x40\x00\x00\x09\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00'
169test3_cmd+='\x00\x00\x12\x00\x25\x00\x0b\x00\x06\x04\x60\x00\x00\x00\x06\x00'
170test3_cmd+='\x80\x00\x43\x00\x00'
171
172test3_exp=' 80 02 00 00 00 71 00 00 00 00 80 00 00 00 00 00 00'
173test3_exp+=' 5a 00 00 00 32 00 25 00 0b 00 06 04 60 00 00 00 06 00 80'
174test3_exp+=' 00 43 00 20 b4 1c 16 e3 78 1e dc 6c 8a 84 ce 27 f1 f3 8c'
175test3_exp+=' 8c 67 fe ea 6e 1f 14 2d db 26 2e 16 dd 5c fb f0 fb 00 22'
176test3_exp+=' 00 0b d4 2a 69 2b 4c b7 31 e2 65 d4 14 61 10 aa 16 ec b2'
177test3_exp+=' 7f a3 27 15 1b 5c 7c 22 98 90 1f cd f2 9e bc 00 00 01 00'
178test3_exp+=' 00'
179
180# Create a TDES (0x03) key and expect a predictable return value
181# (tsscreateloaded does not support TDES)
182# -> creates key with handle 0x80 00 00 00
183test4_cmd='\x80\x02\x00\x00\x00\x35\x00\x00\x01\x91\x40\x00\x00\x01\x00\x00'
184test4_cmd+='\x00\x09\x40\x00\x00\x09\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00'
Stefan Bergerd3968392019-12-25 23:38:51 -0500185test4_cmd+='\x00\x00\x12\x00\x25\x00\x0b\x00\x06\x04\x60\x00\x00\x00\x03\x00'
186test4_cmd+='\x80\x00\x43\x00\x00' #^^^^ <- TDES
Stefan Bergerd617dd62019-06-13 20:07:12 -0400187
188test4_exp=' 80 02 00 00 00 71 00 00 00 00 80 00 00 00 00 00 00'
Stefan Bergerd3968392019-12-25 23:38:51 -0500189test4_exp+=' 5a 00 00 00 32 00 25 00 0b 00 06 04 60 00 00 00 03'
190test4_exp+=' 00 80 00 43 00 20 91 28 1c bc ac 9d d6 6d 29 33 82'
191test4_exp+=' 74 05 16 d4 ab 4c 6a 6c 95 cf 60 8e a8 69 43 1f e2'
192test4_exp+=' 37 13 67 eb 00 22 00 0b 9e 45 d0 46 1f 72 a7 eb 24'
193test4_exp+=' 67 cf 02 67 5a e1 ee bb ab 29 13 44 ba d1 e1 14 fd'
194test4_exp+=' 1f 73 33 db 5f 33 00 00 01 00 00'
Stefan Bergerd617dd62019-06-13 20:07:12 -0400195
Stefan Berger50a61bb2019-06-18 11:41:31 -0400196# Create a primary RSA key and expect a predictable return value
197# tsscreateprimary -hi e -dp -v
198# -> creates key with handle 0x80 00 00 00
199test5_cmd1='\x80\x02\x00\x00\x00\x3b\x00\x00\x01\x31\x40\x00\x00\x0b\x00\x00'
200test5_cmd1+='\x00\x09\x40\x00\x00\x09\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00'
201test5_cmd1+='\x00\x00\x12\x00\x08\x00\x0b\x00\x03\x04\x72\x00\x00\x00\x0a\x00'
202test5_cmd1+='\x0b\x00\x22\x00\x00\x00\x00\x00\x00\x00\x00'
203
204test5_exp1=' 80 02 00 00 01 12 00 00 00 00 80 00 00 00 00 00'
205test5_exp1+=' 00 fb 00 32 00 08 00 0b 00 03 04 72 00 00 00 0a'
206test5_exp1+=' 00 0b 00 22 00 20 5f bc a0 5c 6c b0 60 fe 76 c5'
207test5_exp1+=' 0f f2 0e eb e8 52 9f 2b e7 3b 06 6a b4 3f 88 6f'
208test5_exp1+=' 51 1f cd d8 c1 1f 00 37 00 00 00 00 00 20 e3 b0'
209test5_exp1+=' c4 42 98 fc 1c 14 9a fb f4 c8 99 6f b9 24 27 ae'
210test5_exp1+=' 41 e4 64 9b 93 4c a4 95 99 1b 78 52 b8 55 01 00'
211test5_exp1+=' 10 00 04 40 00 00 0b 00 04 40 00 00 0b 00 00 00'
212test5_exp1+=' 20 28 d0 26 fa fd 74 91 06 74 3e 27 c4 28 05 51'
213test5_exp1+=' 58 5e 5d 17 66 8e b5 21 83 5e d6 01 27 ef fc 05'
214test5_exp1+=' d4 80 21 40 00 00 0b 00 40 8e 6b 7d 82 b0 d4 6b'
215test5_exp1+=' 04 f3 9d a7 54 5d f3 5e 70 79 c3 7a 8c 5b 7a 08'
216test5_exp1+=' cb 03 62 24 47 1a e3 7d de 49 95 23 2b d7 69 6b'
217test5_exp1+=' 23 6b 2f b5 ed 35 ee 9d c4 01 3f 3b 37 db 2f ba'
218test5_exp1+=' a4 8f 80 68 f9 c1 d2 ff 70 00 22 00 0b 6a 1a f5'
219test5_exp1+=' 61 1c 58 6a 02 3f 3f 12 15 86 67 57 7e da fb 30'
220test5_exp1+=' 0a 6b 66 b4 68 99 77 46 f8 4c ea ef 8b 00 00 01'
221test5_exp1+=' 00 00'
222
223# Create a derived key with this primary key as parent:
224# createloaded -hp 80000000 -der -ecc bnp256 -den -kt f -kt p -v
225# -> creates key with handle 0x80 00 00 01
226test5_cmd2='\x80\x02\x00\x00\x00\x39\x00\x00\x01\x91\x80\x00\x00\x00\x00\x00'
227test5_cmd2+='\x00\x09\x40\x00\x00\x09\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00'
228test5_cmd2+='\x00\x00\x16\x00\x23\x00\x0b\x00\x02\x04\x52\x00\x00\x00\x10\x00'
229test5_cmd2+='\x10\x00\x10\x00\x10\x00\x00\x00\x00'
230
231test5_exp2+=' 80 02 00 00 00 95 00 00 00 00 80 00 00 01 00 00'
232test5_exp2+=' 00 7e 00 00 00 56 00 23 00 0b 00 02 04 52 00 00'
233test5_exp2+=' 00 10 00 10 00 10 00 10 00 20 af 79 72 26 52 4e'
234test5_exp2+=' 14 e7 99 c2 a4 49 60 2a 19 8e 78 0c 30 c5 6f 65'
235test5_exp2+=' f1 e6 26 3a 67 ee 5a df 3c 31 00 20 cd b5 62 59'
236test5_exp2+=' 83 2e ad 91 1c 81 83 3e 92 22 8e 9d d0 71 bf 65'
237test5_exp2+=' 5c bc 38 24 6a a7 07 e6 0d eb 9d d3 00 22 00 0b'
238test5_exp2+=' be 61 98 28 b4 ea 33 db b0 24 39 2d 9f b4 0b 71'
239test5_exp2+=' ab ff ed 4b 55 02 f0 4e 3e 66 41 91 73 96 25 b6'
240test5_exp2+=' 00 00 01 00 00'
241
Stefan Bergerd617dd62019-06-13 20:07:12 -0400242#
243# The issue is that 32bit TPMs produce different results than
244# 64bit TPMs. We only test 64bit TPMs with the above expected
Stefan Berger646ec442020-05-27 12:20:26 -0400245# return values. We also only test little endian
Stefan Bergerd617dd62019-06-13 20:07:12 -0400246#
Stefan Berger4931b932020-04-07 15:30:25 -0400247case "$(uname -s)" in
248Linux)
249 # Only 64bit apps will link with libs in /lib64/ dirs
Stefan Bergera4347af2024-01-08 12:28:11 -0500250 if grep -q -E "/lib64/" "/proc/${SWTPM_PID}/maps" && \
Stefan Berger4cad2bb2023-01-25 18:44:11 -0500251 lscpu | grep -q "Little Endian"; then
Stefan Berger4931b932020-04-07 15:30:25 -0400252 tx_cmd 1 0 "$test1_cmd" "$test1_exp" "" || exit 1 && echo "Test 1: OK"
253 tx_cmd 1 1 "$test2_cmd" "$test2_exp" "" || exit 1 && echo "Test 2: OK"
254 tx_cmd 1 1 "$test3_cmd" "$test3_exp" "" || exit 1 && echo "Test 3: OK"
255 tx_cmd 1 1 "$test4_cmd" "$test4_exp" "$error_unsupt_algo" || exit 1 && echo "Test 4: OK"
256 tx_cmd 1 1 "$test5_cmd1" "$test5_exp1" "" || exit 1
257 tx_cmd 0 0 "$test5_cmd2" "$test5_exp2" "" || exit 1 && echo "Test 5: OK"
258 else
Stefan Berger646ec442020-05-27 12:20:26 -0400259 echo "This test currently only runs with 64bit little endian swtpm. ${SWTPM_EXE} seems 32bit or big endian."
Stefan Berger4931b932020-04-07 15:30:25 -0400260 fi
Stefan Bergerd617dd62019-06-13 20:07:12 -0400261 ;;
262*)
Stefan Berger4931b932020-04-07 15:30:25 -0400263 echo "This test currently only runs on Linux"
264 ;;
Stefan Bergerd617dd62019-06-13 20:07:12 -0400265esac
266
Stefan Berger8e95c992019-06-18 16:23:12 -0400267# Get revision of TPM 2.0 implementation; we need >= 155 for subsequent tests
Stefan Bergerfd7a8122023-01-12 13:19:55 -0500268revision=$(run_swtpm_ioctl "${SWTPM_INTERFACE}" --info 1 |
Stefan Berger8e95c992019-06-18 16:23:12 -0400269 sed 's/.*,"revision":\([^\}]*\).*/\1/')
270
Stefan Berger57043422023-01-26 11:06:26 -0500271if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
Stefan Berger8e95c992019-06-18 16:23:12 -0400272 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
273 exit 1
274fi
275
Stefan Bergerfd7a8122023-01-12 13:19:55 -0500276if wait_process_gone "${SWTPM_PID}" 4; then
Stefan Berger8e95c992019-06-18 16:23:12 -0400277 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
278 exit 1
279fi
280
Stefan Bergerfd7a8122023-01-12 13:19:55 -0500281if [ "$revision" -lt 155 ]; then
Stefan Berger8e95c992019-06-18 16:23:12 -0400282 echo "Skipping next tests since libtpms implements TPM 2.0 revision $revision, but need >= 155"
283 exit 0
284fi
285
286# Repeat the tests for the 'fixed' CryptAdjustPrimeCandidate test, which works
287# on 32 bit and 64 bit machines and produces the same results
288
289echo "Testing new CryptAdjustPrimeCandidate implementation"
290
291# copy all the state files; the files need libtpms (0.8.0) with
Stefan Berger67152d32023-07-17 19:37:28 -0400292# TPM 2.0 revision 155; there the seeds are setup so that the fixed
Stefan Berger8e95c992019-06-18 16:23:12 -0400293# RSA key generation algorithm is used
Stefan Bergerfd7a8122023-01-12 13:19:55 -0500294cp -f "${TESTDIR}"/data/tpm2state4/* "${TPM_PATH}"
Stefan Berger8e95c992019-06-18 16:23:12 -0400295
Stefan Bergerfd7a8122023-01-12 13:19:55 -0500296TPM_PATH=$TPM_PATH run_swtpm "${SWTPM_INTERFACE}" --tpm2
Stefan Berger8e95c992019-06-18 16:23:12 -0400297
Stefan Berger57043422023-01-26 11:06:26 -0500298if ! kill_quiet -0 "${SWTPM_PID}"; then
Stefan Berger8e95c992019-06-18 16:23:12 -0400299 echo "Error: ${SWTPM_INTERFACE} TPM did not start."
300 exit 1
301fi
302
303test1_exp=' 80 02 00 00 01 fa 00 00 00 00 80 00 00 00 00 00 01 e3 01 1a 00 01 00 0b 00 03 04 72 00 00 00 06 00 80 00 43 00 10 08 00 00 00 00 00 01 00 9b ef 34 ef e5 b1 2a 2b bc 85 71 5c 59 a5 67 f2 fe 13 38 15 c0 45 68 05 b1 27 c3 ef 63 89 21 c0 13 39 47 6d 99 82 b1 7c 79 d9 b7 9f 50 1c 2c 05 22 c3 53 02 76 f1 9b 8c 61 31 0d af a5 c1 12 28 f6 2b 02 24 d8 b5 04 51 c8 74 38 95 00 a9 24 88 40 a8 7f ce 49 eb f9 bd 67 f1 96 a8 39 3e e6 af 8c 7d ae 29 48 dc e3 64 1a 54 58 70 30 9f ae 96 de f4 2e 79 b1 89 fd 81 8f 29 b7 01 ab 92 30 32 0f 2c e9 0c 4f 6b cd aa b1 2e d1 dc 91 b0 d0 13 50 07 89 52 57 ce af e2 cf 4a 01 c2 7d 04 35 01 0e 7b 3e 42 98 91 71 a6 65 ab f2 31 97 4f 70 9c f8 fe a9 d1 5b 1c be 8c fc b8 0f 84 cc a1 52 42 94 74 92 76 94 0b 8f b4 95 8c b8 1e d5 7d 58 d1 3a 7f 8b 22 50 fc 57 39 6e bb e5 29 c8 7c b1 6b dd 11 9d 3b 06 2c 63 e4 d5 55 56 93 8c e7 06 86 2b 15 91 33 7c b2 14 43 57 5b 94 11 77 f4 6c d9 00 37 00 00 00 00 00 20 e3 b0 c4 42 98 fc 1c 14 9a fb f4 c8 99 6f b9 24 27 ae 41 e4 64 9b 93 4c a4 95 99 1b 78 52 b8 55 01 00 10 00 04 40 00 00 0b 00 04 40 00 00 0b 00 00 00 20 28 d0 26 fa fd 74 91 06 74 3e 27 c4 28 05 51 58 5e 5d 17 66 8e b5 21 83 5e d6 01 27 ef fc 05 d4 80 21 40 00 00 0b 00 40 e7 23 e1 bb 81 90 bb 1f 1a 32 d7 bd 07 f5 40 ad 27 a8 cd 70 1a 17 d6 af b6 8f 86 6d 6f c1 5d 65 de 07 82 63 2a da ac 20 73 90 a0 f4 5f cd c8 61 84 79 5b 9d c0 19 98 62 94 fb 35 f0 5d 91 f5 21 00 22 00 0b 07 eb bd 34 07 3e 1e 20 d6 cb b6 ea 62 61 1a 12 4e 84 85 b5 bf 5e 1b bd f4 6b 93 6a 1d 5f 32 3b 00 00 01 00 00'
304test2_exp=' 80 02 00 00 01 3a 00 00 00 00 80 00 00 00 00 00 01 23 00 5a 00 23 00 0b 00 03 04 72 00 00 00 06 00 80 00 43 00 10 00 03 00 10 00 20 ff cc 72 69 28 1a fd 2a 2c 5d 12 8d 7a 9e 7c 3e 6f 86 8a d7 e5 93 a0 f0 de 01 30 50 94 51 31 8f 00 20 6b 15 ca 0d 9a 67 4a e9 b6 d0 23 d2 e5 98 71 be 83 b5 f7 66 3f 63 ca 95 e7 7a e7 44 c4 94 89 95 00 37 00 00 00 00 00 20 e3 b0 c4 42 98 fc 1c 14 9a fb f4 c8 99 6f b9 24 27 ae 41 e4 64 9b 93 4c a4 95 99 1b 78 52 b8 55 01 00 10 00 04 40 00 00 0b 00 04 40 00 00 0b 00 00 00 20 28 d0 26 fa fd 74 91 06 74 3e 27 c4 28 05 51 58 5e 5d 17 66 8e b5 21 83 5e d6 01 27 ef fc 05 d4 80 21 40 00 00 0b 00 40 fa bb 14 5e 67 43 43 64 c8 29 e9 9a 7c 81 5e ff 4a 29 bb 5e 72 75 03 5f 62 d2 6d 7a 90 0a 6e 6d 68 ef 83 9d df 77 1f 76 0f c8 0d 1d 86 be 62 09 0b 56 68 2a f3 92 11 b1 2d 35 03 82 d1 ea d9 8a 00 22 00 0b 5f 43 81 4d 6a ed b8 36 cf 2d 92 50 44 a4 8f 03 8a ad 08 32 f5 23 49 6f 85 76 8b 95 a4 37 18 8e 00 00 01 00 00'
305test3_exp=' 80 02 00 00 00 71 00 00 00 00 80 00 00 00 00 00 00 5a 00 00 00 32 00 25 00 0b 00 06 04 60 00 00 00 06 00 80 00 43 00 20 25 f3 2c cf 3d 14 ed 18 a9 ae 67 82 28 7b 3b 21 7c d1 f4 24 12 d1 74 d5 69 7d 73 1b 6d ae 45 04 00 22 00 0b c5 fa ae 5e 37 7a ad d0 78 4e 1b e5 63 9c 5b a8 17 03 82 cb a0 e8 ab 39 40 69 24 48 df 72 8b c8 00 00 01 00 00'
Stefan Bergerd3968392019-12-25 23:38:51 -0500306test4_exp=' 80 02 00 00 00 71 00 00 00 00 80 00 00 00 00 00 00 5a 00 00 00 32 00 25 00 0b 00 06 04 60 00 00 00 03 00 80 00 43 00 20 58 3a 75 c7 29 b6 df 2f 3c a1 1d 2a f3 79 ff aa 62 72 94 ec 4f c2 ad fa 5a 66 39 c3 4a 18 ad ae 00 22 00 0b 63 31 31 24 c4 61 f0 10 a4 46 53 85 c8 bd b3 d9 66 e4 4b a8 b9 bd 68 ad be 58 3e 10 09 20 66 dc 00 00 01 00 00'
Stefan Berger8e95c992019-06-18 16:23:12 -0400307test5_exp1=' 80 02 00 00 01 12 00 00 00 00 80 00 00 00 00 00 00 fb 00 32 00 08 00 0b 00 03 04 72 00 00 00 0a 00 0b 00 22 00 20 60 5c 90 40 d5 ef 80 59 70 f4 90 3e 43 7a ce 49 1e 06 06 f0 e9 79 39 e4 a0 a1 8b d5 12 ca 86 9a 00 37 00 00 00 00 00 20 e3 b0 c4 42 98 fc 1c 14 9a fb f4 c8 99 6f b9 24 27 ae 41 e4 64 9b 93 4c a4 95 99 1b 78 52 b8 55 01 00 10 00 04 40 00 00 0b 00 04 40 00 00 0b 00 00 00 20 28 d0 26 fa fd 74 91 06 74 3e 27 c4 28 05 51 58 5e 5d 17 66 8e b5 21 83 5e d6 01 27 ef fc 05 d4 80 21 40 00 00 0b 00 40 5a 84 8d d0 73 da 49 f6 76 84 6e d1 56 13 39 4d 4b 67 0a 68 97 71 c9 a4 92 a6 aa 6d 30 4b 19 6c 69 fc a7 d5 b9 5c 8f 5a af 0c f6 72 b9 85 c5 d4 0a 09 f8 f7 16 4d 11 bc 5d ec cc 48 02 15 ce 79 00 22 00 0b 04 13 09 39 42 b3 86 80 67 68 2a d7 27 e3 c7 44 1d 1c b6 65 23 c3 ee f0 b8 b8 b5 ff ee 49 1d 4b 00 00 01 00 00'
308test5_exp2=' 80 02 00 00 00 95 00 00 00 00 80 00 00 01 00 00 00 7e 00 00 00 56 00 23 00 0b 00 02 04 52 00 00 00 10 00 10 00 10 00 10 00 20 af 9f be fc c8 95 21 71 04 2d 7d db 3f 42 aa 54 cc 2f a0 cf 55 82 78 f4 3f 01 88 27 46 53 2c 88 00 20 dc ad 67 2f d1 ea 89 01 f5 27 1f 58 3f a5 da 52 85 50 98 d5 06 81 10 13 86 12 d7 23 55 12 ea 0c 00 22 00 0b 72 c2 60 3f c8 bb 79 ea 92 86 7e a3 df 57 8d 15 e3 f1 10 a2 f9 1c a6 80 41 c3 cf e1 fa 43 83 2f 00 00 01 00 00'
309
Stefan Bergerdfd36eb2020-02-25 21:34:21 -0500310tx_cmd 1 0 "$test1_cmd" "$test1_exp" "" || exit 1 && echo "Test 1: OK"
311tx_cmd 1 1 "$test2_cmd" "$test2_exp" "" || exit 1 && echo "Test 2: OK"
312tx_cmd 1 1 "$test3_cmd" "$test3_exp" "" || exit 1 && echo "Test 3: OK"
313tx_cmd 1 1 "$test4_cmd" "$test4_exp" "" || exit 1 && echo "Test 4: OK"
314tx_cmd 1 1 "$test5_cmd1" "$test5_exp1" "" || exit 1
315tx_cmd 0 0 "$test5_cmd2" "$test5_exp2" "" || exit 1 && echo "Test 5: OK"
Stefan Berger8e95c992019-06-18 16:23:12 -0400316
Stefan Berger57043422023-01-26 11:06:26 -0500317if ! run_swtpm_ioctl "${SWTPM_INTERFACE}" -s; then
Stefan Bergerd617dd62019-06-13 20:07:12 -0400318 echo "Error: Could not shut down the ${SWTPM_INTERFACE} TPM."
319 exit 1
320fi
321
Stefan Bergerfd7a8122023-01-12 13:19:55 -0500322if wait_process_gone "${SWTPM_PID}" 4; then
Stefan Bergerd617dd62019-06-13 20:07:12 -0400323 echo "Error: ${SWTPM_INTERFACE} TPM should not be running anymore."
324 exit 1
325fi
326
Stefan Berger4931b932020-04-07 15:30:25 -0400327exit 0