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