swtpm: report 'tpm-1.2' & 'tpm-2.0' in --print-capabilities

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau 2021-08-06 19:13:18 +04:00 committed by Stefan Berger
parent ccaf99f12c
commit da8752b1f7
3 changed files with 14 additions and 4 deletions

View File

@ -43,6 +43,7 @@
#include <string.h>
#include <libtpms/tpm_library.h>
#include <libtpms/tpm_error.h>
#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,

View File

@ -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}"

View File

@ -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}"