qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] test: Add test cases that use the external swtp


From: Stefan Berger
Subject: Re: [Qemu-devel] [PATCH] test: Add test cases that use the external swtpm with CRB interface
Date: Thu, 19 Apr 2018 12:43:37 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0

On 04/19/2018 12:39 PM, Stefan Berger wrote:
Add a test program for testing the CRB with the external swtpm.

The 1st test case extends a PCR and reads back the value and compares
it against an expected return packet.

The 2nd test case repeats the 1st test case and then migrates the
external swtpm's state along with the VM state to a destination
QEMU and swtpm and checks that the PCR has the expected value now.

I had previously posted this patch but had to make two fixes:


Signed-off-by: Stefan Berger <address@hidden>
---
  tests/Makefile.include     |   3 +
  tests/tpm-crb-swtpm-test.c | 247 +++++++++++++++++++++++++++++++++++++++++++++
  tests/tpm-util.c           | 186 ++++++++++++++++++++++++++++++++++
  tests/tpm-util.h           |  36 +++++++
  4 files changed, 472 insertions(+)
  create mode 100644 tests/tpm-crb-swtpm-test.c
  create mode 100644 tests/tpm-util.c
  create mode 100644 tests/tpm-util.h
diff --git a/tests/tpm-util.c b/tests/tpm-util.c
new file mode 100644
index 0000000..9072b6e
--- /dev/null
+++ b/tests/tpm-util.c
@@ -0,0 +1,186 @@
+/*
+ * QTest TPM utilities
+ *
+ * Copyright (c) 2018 IBM Corporation
+ * Copyright (c) 2018 Red Hat, Inc.
+ *
+ * Authors:
+ *   Stefan Berger <address@hidden>
+ *   Marc-André Lureau <address@hidden>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+
+#include "hw/acpi/tpm.h"
+#include "libqtest.h"
+#include "tpm-util.h"
+
+void tpm_util_crb_transfer(QTestState *s,
+                           const unsigned char *req, size_t req_size,
+                           unsigned char *rsp, size_t rsp_size)
+{
+    uint64_t caddr = qtest_readq(s, TPM_CRB_ADDR_BASE + A_CRB_CTRL_CMD_LADDR);
+    uint64_t raddr = qtest_readq(s, TPM_CRB_ADDR_BASE + A_CRB_CTRL_RSP_ADDR);
+
+    qtest_writeb(s, TPM_CRB_ADDR_BASE + A_CRB_LOC_CTRL, 1);

^^^ Requesting access to the locality is new, which is now required due to a recent addition in the CRB emulation.

+
+    qtest_memwrite(s, caddr, req, req_size);
+
[...]
+    g_assert_cmpmem(buffer, exp_resp_size, exp_resp, exp_resp_size);
+}
+
+static gboolean tpm_util_swtpm_has_tpm2(void)
This function is new to read the help screen of swtpm to check whether it supports --tpm2, which is currently ionly supported n a preview branch.

+{
+    gint stdout;
+    gboolean succ;
+    unsigned i;
+    char buffer[10240];
+    ssize_t n;
+    gchar *swtpm_argv[] = {
+        g_strdup("swtpm"), g_strdup("socket"), g_strdup("--help"), NULL
+    };
+
+    succ = g_spawn_async_with_pipes(NULL, swtpm_argv, NULL,
+                                    G_SPAWN_SEARCH_PATH, NULL, NULL, NULL,
+                                    NULL, &stdout, NULL, NULL);
+    if (!succ) {
+        goto cleanup;
+    }
+
+    n = read(stdout, buffer, sizeof(buffer) - 1);
+    if (n < 0) {
+        goto cleanup;
+    }
+    buffer[n] = 0;
+    if (!strstr(buffer, "--tpm2")) {
+        succ = false;
+    }
+
+ cleanup:
+    for (i = 0; swtpm_argv[i]; i++) {
+        g_free(swtpm_argv[i]);
+    }
+
+    return succ;
+}
+




reply via email to

[Prev in Thread] Current Thread [Next in Thread]