]> git.proxmox.com Git - swtpm.git/blob - tests/_test_tpm2_print_capabilities
swtpm*: report 'version' in --print-capabilities
[swtpm.git] / tests / _test_tpm2_print_capabilities
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 [ "${SWTPM_IFACE}" == "cuse" ] && source ${TESTDIR}/test_cuse
12 source ${TESTDIR}/common
13
14 msg="$(${SWTPM_EXE} ${SWTPM_IFACE} --tpm2 --print-capabilities 2>&1)"
15 if [ $? -ne 0 ]; then
16 echo "Error: Could not pass --print-capabilities"
17 echo "${msg}"
18 exit 1
19 fi
20
21 if has_seccomp_support "${SWTPM_EXE}"; then
22 seccomp='"cmdarg-seccomp", '
23 fi
24 if [ "${SWTPM_IFACE}" != "cuse" ]; then
25 noncuse='"tpm-send-command-header", "flags-opt-startup", '
26 fi
27
28 # The rsa key size reporting is variable, so use a regex
29 exp='\{ "type": "swtpm", "features": \[( "tpm-1.2",)? "tpm-2.0", '${noncuse}${seccomp}'"cmdarg-key-fd", "cmdarg-pwd-fd"(, "rsa-keysize-1024")?(, "rsa-keysize-2048")?(, "rsa-keysize-3072")? \], "version": "[^"]*" \}'
30 if ! [[ ${msg} =~ ${exp} ]]; then
31 echo "Unexpected response from ${SWTPM_IFACE} TPM to --print-capabilities:"
32 echo "Actual : ${msg}"
33 echo "Expected : ${exp}"
34 exit 1
35 fi
36
37 echo "Test 1: OK"
38
39 msg="$(${SWTPM_SETUP} --tpm2 --print-capabilities 2>&1)"
40 if [ $? -ne 0 ]; then
41 echo "Error: Could not pass --print-capabilities"
42 echo "${msg}"
43 exit 1
44 fi
45
46 # The are some variable parameters at the end, use regex
47 exp='\{ "type": "swtpm_setup", "features": \[ "cmdarg-keyfile-fd", "cmdarg-pwdfile-fd", "tpm12-not-need-root", "cmdarg-write-ek-cert-files"(, "tpm2-rsa-keysize-2048")?(, "tpm2-rsa-keysize-3072")? \], "version": "[^"]*" \}'
48 if ! [[ ${msg} =~ ${exp} ]]; then
49 echo "Unexpected response from ${SWTPM_SETUP} to --print-capabilities:"
50 echo "Actual : ${msg}"
51 echo "Expected : ${exp}"
52 exit 1
53 fi
54
55 echo "Test 2: OK"
56
57 # SWTPM_CERT may be run by valgrind
58 if [ -x "$(type -P $(echo "${SWTPM_CERT}" | cut -d" " -f1) )" ]; then
59 msg="$(${SWTPM_CERT} --tpm2 --print-capabilities 2>&1)"
60 if [ $? -ne 0 ]; then
61 echo "Error: Could not pass --print-capabilities to ${SWTPM_CERT}"
62 echo "${msg}"
63 exit 1
64 fi
65
66 exp='\{ "type": "swtpm_cert", "features": \[ "cmdarg-signkey-pwd", "cmdarg-parentkey-pwd" \], "version": "[^"]*" \}'
67 if ~ [[ "${msg}" =~ ${exp} ]]; then
68 echo "Unexpected response from ${SWTPM_CERT} to --print-capabilities:"
69 echo "Actual : ${msg}"
70 echo "Expected : ${exp}"
71 exit 1
72 fi
73
74 echo "Test 3: OK"
75 else
76 echo "Test 2: SKIP -- ${SWTPM_CERT} not found or not an executable"
77 fi
78
79 exit 0