qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Berger <stefanb@linux.vnet.ibm.com>
To: marcandre.lureau@gmail.com, qemu-devel@nongnu.org
Cc: dgilbert@redhat.com
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	[thread overview]
Message-ID: <272b1e45-c2ac-974a-fc8c-43a2f3963052@linux.vnet.ibm.com> (raw)
In-Reply-To: <1524155983-16705-1-git-send-email-stefanb@linux.vnet.ibm.com>

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 <stefanb@linux.vnet.ibm.com>
> ---
>   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 <stefanb@linux.vnet.ibm.com>
> + *   Marc-André Lureau <marcandre.lureau@redhat.com>
> + *
> + * 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	other threads:[~2018-04-19 16:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-19 16:39 [Qemu-devel] [PATCH] test: Add test cases that use the external swtpm with CRB interface Stefan Berger
2018-04-19 16:43 ` Stefan Berger [this message]
2018-04-20  9:13 ` Marc-André Lureau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=272b1e45-c2ac-974a-fc8c-43a2f3963052@linux.vnet.ibm.com \
    --to=stefanb@linux.vnet.ibm.com \
    --cc=dgilbert@redhat.com \
    --cc=marcandre.lureau@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).