From da8752b1f7135fbf812fd2bc9fb6ebbdf247d458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 6 Aug 2021 19:13:18 +0400 Subject: [PATCH] swtpm: report 'tpm-1.2' & 'tpm-2.0' in --print-capabilities MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau --- src/swtpm/capabilities.c | 12 +++++++++++- tests/_test_print_capabilities | 4 ++-- tests/_test_tpm2_print_capabilities | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/swtpm/capabilities.c b/src/swtpm/capabilities.c index beb3341..2a387e2 100644 --- a/src/swtpm/capabilities.c +++ b/src/swtpm/capabilities.c @@ -43,6 +43,7 @@ #include #include +#include #include "capabilities.h" #include "logging.h" @@ -122,19 +123,28 @@ int capabilities_print_json(bool cusetpm) #else const char *cmdarg_seccomp = ""; #endif + const char *with_tpm1 = ""; + const char *with_tpm2 = ""; char *keysizecaps = NULL; ret = get_rsa_keysize_caps(&keysizecaps); if (ret < 0) goto cleanup; + if (TPMLIB_ChooseTPMVersion(TPMLIB_TPM_VERSION_1_2) == TPM_SUCCESS) + with_tpm1 = "\"tpm-1.2\", "; + if (TPMLIB_ChooseTPMVersion(TPMLIB_TPM_VERSION_2) == TPM_SUCCESS) + with_tpm2 = "\"tpm-2.0\", "; + n = asprintf(&string, "{ " "\"type\": \"swtpm\", " "\"features\": [ " - "%s%s%s%s%s%s" + "%s%s%s%s%s%s%s%s" " ] " "}", + with_tpm1, + with_tpm2, !cusetpm ? "\"tpm-send-command-header\", ": "", !cusetpm ? "\"flags-opt-startup\", " : "", cmdarg_seccomp, diff --git a/tests/_test_print_capabilities b/tests/_test_print_capabilities index 6b7494c..3dc0b84 100755 --- a/tests/_test_print_capabilities +++ b/tests/_test_print_capabilities @@ -25,8 +25,8 @@ if [ "${SWTPM_IFACE}" != "cuse" ]; then noncuse='"tpm-send-command-header", "flags-opt-startup", ' fi -exp='{ "type": "swtpm", "features": [ '${noncuse}${seccomp}'"cmdarg-key-fd", "cmdarg-pwd-fd" ] }' -if [ "${msg}" != "${exp}" ]; then +exp='\{ "type": "swtpm", "features": \[ "tpm-1.2",( "tpm-2.0",)? '${noncuse}${seccomp}'"cmdarg-key-fd", "cmdarg-pwd-fd" \] \}' +if ! [[ ${msg} =~ ${exp} ]]; then echo "Unexpected response from ${SWTPM_IFACE} TPM to --print-capabilities:" echo "Actual : ${msg}" echo "Expected : ${exp}" diff --git a/tests/_test_tpm2_print_capabilities b/tests/_test_tpm2_print_capabilities index 4e36e23..17c63d2 100755 --- a/tests/_test_tpm2_print_capabilities +++ b/tests/_test_tpm2_print_capabilities @@ -26,7 +26,7 @@ if [ "${SWTPM_IFACE}" != "cuse" ]; then fi # The rsa key size reporting is variable, so use a regex -exp='\{ "type": "swtpm", "features": \[ '${noncuse}${seccomp}'"cmdarg-key-fd", "cmdarg-pwd-fd"(, "rsa-keysize-1024")?(, "rsa-keysize-2048")?(, "rsa-keysize-3072")? \] \}' +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")? \] \}' if ! [[ ${msg} =~ ${exp} ]]; then echo "Unexpected response from ${SWTPM_IFACE} TPM to --print-capabilities:" echo "Actual : ${msg}"