From: Stefan Berger <[email protected]> Enable swtpm to start with a given profile by passing it to swtpm on the command line using
--profile name=<profile name> Remove any existing TPM 2 state file since applying a new profile to existing state would be refused by swtpm. Signed-off-by: Stefan Berger <[email protected]> Signed-off-by: Arun Menon <[email protected]> --- tests/qtest/tpm-tests.c | 6 +++--- tests/qtest/tpm-util.c | 9 ++++++++- tests/qtest/tpm-util.h | 3 ++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/qtest/tpm-tests.c b/tests/qtest/tpm-tests.c index 197714f8d9..f71d882990 100644 --- a/tests/qtest/tpm-tests.c +++ b/tests/qtest/tpm-tests.c @@ -43,7 +43,7 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx, return; } - succ = tpm_util_swtpm_start(src_tpm_path, &swtpm_pid, &addr, &error); + succ = tpm_util_swtpm_start(src_tpm_path, &swtpm_pid, &addr, NULL, &error); g_assert_true(succ); args = g_strdup_printf( @@ -91,11 +91,11 @@ void tpm_test_swtpm_migration_test(const char *src_tpm_path, } succ = tpm_util_swtpm_start(src_tpm_path, &src_tpm_pid, - &src_tpm_addr, &error); + &src_tpm_addr, NULL, &error); g_assert_true(succ); succ = tpm_util_swtpm_start(dst_tpm_path, &dst_tpm_pid, - &dst_tpm_addr, &error); + &dst_tpm_addr, NULL, &error); g_assert_true(succ); tpm_util_migration_start_qemu(&src_qemu, &dst_qemu, diff --git a/tests/qtest/tpm-util.c b/tests/qtest/tpm-util.c index 744592763f..cbba5b1c1f 100644 --- a/tests/qtest/tpm-util.c +++ b/tests/qtest/tpm-util.c @@ -212,7 +212,8 @@ bool tpm_util_swtpm_has_tpm2(void) } gboolean tpm_util_swtpm_start(const char *path, GPid *pid, - SocketAddress **addr, GError **error) + SocketAddress **addr, const char *profilename, + GError **error) { char *swtpm_argv_tpmstate = g_strdup_printf("dir=%s", path); char *swtpm_argv_ctrl = g_strdup_printf("type=unixio,path=%s/sock", @@ -222,11 +223,17 @@ gboolean tpm_util_swtpm_start(const char *path, GPid *pid, g_strdup("--tpmstate"), swtpm_argv_tpmstate, g_strdup("--ctrl"), swtpm_argv_ctrl, g_strdup("--tpm2"), + profilename ? g_strdup("--profile") : NULL, + profilename ? g_strdup_printf("name=%s", profilename) : NULL, NULL }; + g_autofree char *swtpm_state_file; gboolean succ; unsigned i; + swtpm_state_file = g_strdup_printf("%s/tpm2-00.permall", path); + g_unlink(swtpm_state_file); + *addr = g_new0(SocketAddress, 1); (*addr)->type = SOCKET_ADDRESS_TYPE_UNIX; (*addr)->u.q_unix.path = g_build_filename(path, "sock", NULL); diff --git a/tests/qtest/tpm-util.h b/tests/qtest/tpm-util.h index 681544e7d8..ca2d7d173f 100644 --- a/tests/qtest/tpm-util.h +++ b/tests/qtest/tpm-util.h @@ -41,7 +41,8 @@ void tpm_util_pcrread(QTestState *s, tx_func *tx, bool tpm_util_swtpm_has_tpm2(void); gboolean tpm_util_swtpm_start(const char *path, GPid *pid, - SocketAddress **addr, GError **error); + SocketAddress **addr, const char *profilename, + GError **error); void tpm_util_swtpm_kill(GPid pid); void tpm_util_migrate(QTestState *who, const char *uri); -- 2.53.0
