Skip to content

Commit

Permalink
swtpm: Only display profile capabilities when --tpm2 is given
Browse files Browse the repository at this point in the history
Only display profile capabilities when --tpm2 is given since they are only
relevant when a TPM 2 is used.

Adjust test cases.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
  • Loading branch information
stefanberger committed Oct 23, 2024
1 parent 74a3d99 commit ab267bf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/swtpm/capabilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ int capabilities_print_json(bool cusetpm, TPMLIB_TPMVersion tpmversion)
const char *nvram_backend_dir = "\"nvram-backend-dir\", ";
const char *nvram_backend_file = "\"nvram-backend-file\"";
g_autofree gchar *profiles = NULL;
bool is_tpm2 = tpmversion == TPMLIB_TPM_VERSION_2;

/* ignore errors */
TPMLIB_ChooseTPMVersion(tpmversion);
Expand All @@ -255,7 +256,7 @@ int capabilities_print_json(bool cusetpm, TPMLIB_TPMVersion tpmversion)
if (ret < 0)
goto cleanup;

if (tpmversion == TPMLIB_TPM_VERSION_2) {
if (is_tpm2) {
ret = get_profiles(&profiles);
if (ret < 0)
goto cleanup;
Expand Down Expand Up @@ -290,9 +291,9 @@ int capabilities_print_json(bool cusetpm, TPMLIB_TPMVersion tpmversion)
nvram_backend_dir,
nvram_backend_file,
keysizecaps ? keysizecaps : "",
true ? ", \"cmdarg-profile\"" : "",
true ? ", \"cmdarg-print-profiles\"" : "",
true ? ", \"profile-opt-remove-disabled\"" : "",
is_tpm2 ? ", \"cmdarg-profile\"" : "",
is_tpm2 ? ", \"cmdarg-print-profiles\"" : "",
is_tpm2 ? ", \"profile-opt-remove-disabled\"" : "",
true ? ", \"cmdarg-print-info\"" : "",
true ? ", \"tpmstate-opt-lock\"" : "",
profiles ? profiles : ""
Expand Down
3 changes: 1 addition & 2 deletions tests/_test_print_capabilities
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ exp='\{ "type": "swtpm", '\
'"features": \[ "tpm-1.2",( "tpm-2.0",)? '${noncuse}'"flags-opt-startup", '\
'"flags-opt-disable-auto-shutdown", "ctrl-opt-terminate", '${seccomp}'"cmdarg-key-fd", '\
'"cmdarg-pwd-fd", "cmdarg-print-states", "cmdarg-chroot", "cmdarg-migration", '\
'"nvram-backend-dir", "nvram-backend-file", "cmdarg-profile", '\
'"cmdarg-print-profiles", "profile-opt-remove-disabled", "cmdarg-print-info", '\
'"nvram-backend-dir", "nvram-backend-file", "cmdarg-print-info", '\
'"tpmstate-opt-lock" \], '\
'"profiles": \{ \}, '\
'"version": "[^"]*" \}'
Expand Down

0 comments on commit ab267bf

Please sign in to comment.