Debian Codegraph @

tests/_test_tpm2_print_capabilities

raw
1 #!/bin/bash
2
3 # For the license, see the LICENSE file in the root directory.
4 #set -x
5
6 ROOT=${abs_top_builddir:-$(pwd)/..}
7 TESTDIR=${abs_top_testdir:-$(dirname "$0")}
8
9 PATH=$ROOT/src/swtpm:$PATH
10
11 source "${TESTDIR}/common"
12 [ "${SWTPM_IFACE}" == "cuse" ] && source "${TESTDIR}/test_cuse"
13
14 if ! msg="$(${SWTPM_EXE} "${SWTPM_IFACE}" --tpm2 --print-capabilities 2>&1)"; then
15 echo "Error: Could not pass --print-capabilities"
16 echo "${msg}"
17 exit 1
18 fi
19
20 if has_seccomp_support "${SWTPM_EXE}"; then
21 seccomp='"cmdarg-seccomp", '
22 fi
23 if [ "${SWTPM_IFACE}" != "cuse" ]; then
24 noncuse='"tpm-send-command-header", '
25 fi
26
27 # The rsa key size reporting is variable, so use a regex
28 exp='\{ "type": "swtpm", '\
29 '"features": \[( "tpm-1.2",)? "tpm-2.0", '${noncuse}'"flags-opt-startup", '\
30 '"flags-opt-disable-auto-shutdown", "ctrl-opt-terminate", '${seccomp}'"cmdarg-key-fd", '\
31 '"cmdarg-pwd-fd", "cmdarg-print-states", "cmdarg-chroot", "cmdarg-migration", '\
32 '"nvram-backend-dir", "nvram-backend-file"'\
33 '(, "rsa-keysize-1024")?(, "rsa-keysize-2048")?(, "rsa-keysize-3072")?, "cmdarg-profile", '\
34 '"cmdarg-print-profiles", "profile-opt-remove-disabled", "cmdarg-print-info", '\
35 '"tpmstate-opt-lock" \], '\
36 '"profiles": \{ "names": \[ [^]]*\], "algorithms": \{ [^\}]*\}, "commands": \{ [^\}]*\} }, '\
37 '"version": "[^"]*" \}'
38 if ! [[ ${msg} =~ ${exp} ]]; then
39 echo "Unexpected response from ${SWTPM_IFACE} TPM to --print-capabilities:"
40 echo "Actual : ${msg}"
41 echo "Expected : ${exp}"
42 exit 1
43 fi
44
45 echo "Test 1: OK"
46
47 if ! msg="$(${SWTPM_SETUP} --tpm2 --print-capabilities 2>&1)"; then
48 echo "Error: Could not pass --print-capabilities"
49 echo "${msg}"
50 exit 1
51 fi
52
53 # The are some variable parameters at the end, use regex
54 exp='\{ "type": "swtpm_setup", '\
55 '"features": \[( "tpm-1.2",)? "tpm-2.0", "cmdarg-keyfile-fd", "cmdarg-pwdfile-fd", '\
56 '"tpm12-not-need-root", "cmdarg-write-ek-cert-files", "cmdarg-create-config-files", '\
57 '"cmdarg-reconfigure-pcr-banks"(, "tpm2-rsa-keysize-2048")?(, "tpm2-rsa-keysize-3072")?, '\
58 '"cmdarg-profile", "cmdarg-profile-remove-disabled" \], '\
59 '"profiles": \[ [^]]*\], '\
60 '"version": "[^"]*" \}'
61 if ! [[ ${msg} =~ ${exp} ]]; then
62 echo "Unexpected response from ${SWTPM_SETUP} to --print-capabilities:"
63 echo "Actual : ${msg}"
64 echo "Expected : ${exp}"
65 exit 1
66 fi
67
68 echo "Test 2: OK"
69
70 # SWTPM_CERT may be run by valgrind
71 if [ -x "$(type -P "$(echo "${SWTPM_CERT}" | cut -d" " -f1)" )" ]; then
72 if ! msg="$(${SWTPM_CERT} --tpm2 --print-capabilities 2>&1)"; then
73 echo "Error: Could not pass --print-capabilities to ${SWTPM_CERT}"
74 echo "${msg}"
75 exit 1
76 fi
77
78 exp='\{ "type": "swtpm_cert", "features": \[ "cmdarg-signkey-pwd", "cmdarg-parentkey-pwd" \], "version": "[^"]*" \}'
79 if ! [[ "${msg}" =~ ${exp} ]]; then
80 echo "Unexpected response from ${SWTPM_CERT} to --print-capabilities:"
81 echo "Actual : ${msg}"
82 echo "Expected : ${exp}"
83 exit 1
84 fi
85
86 echo "Test 3: OK"
87 else
88 echo "Test 3: SKIP -- ${SWTPM_CERT} not found or not an executable"
89 fi
90
91 exit 0