grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
From: Gary Lin via Grub-devel <grub-devel@gnu.org>
To: Stefan Berger <stefanb@linux.ibm.com>
Cc: Gary Lin <glin@suse.com>,
	The development of GNU GRUB <grub-devel@gnu.org>,
	Hernan Gatta <hegatta@linux.microsoft.com>,
	Daniel Axtens <dja@axtens.net>,
	Daniel Kiper <daniel.kiper@oracle.com>,
	shkhisti@microsoft.com, jaskaran.khurana@microsoft.com,
	christopher.co@microsoft.com, daniel.mihai@microsoft.com,
	jaredz@redhat.com, development@efficientek.com,
	jejb@linux.ibm.com, mchang@suse.com, patrick.colp@oracle.com
Subject: Re: [PATCH v10 20/20] tests: Add tpm2_test
Date: Mon, 15 Apr 2024 14:42:49 +0800	[thread overview]
Message-ID: <20240415064249.xsjdnzcl7ripxpno@GaryLaptop> (raw)
In-Reply-To: <c505d720-8399-4cff-a70f-edf531de2fd1@linux.ibm.com>

On Fri, Apr 12, 2024 at 12:09:36PM -0400, Stefan Berger wrote:
> 
> 
> On 4/9/24 04:30, Gary Lin via Grub-devel wrote:
> > For the tpm2 module, the TCG2 command submission function is the only
> > difference between the a QEMU instance and grub-emu. To test TPM key
> > unsealing with a QEMU instance, it requires an extra OS image to invoke
> > grub-protect to seal the LUKS key, rather than a simple grub-shell rescue
> > CD image. On the other hand, grub-emu can share the emulated TPM device
> > with the host, so that we can seal the LUKS key on host and test key
> > unsealing with grub-emu.
> > 
> > This test script firstly creates a simple LUKS image to be loaded as a
> > loopback device in grub-emu. Then an emulated TPM device is created by
> > swtpm_cuse and PCR 0 and 1 are extended.
> 
> My concern here would be that distros for example don't build swtpm with the
> CUSE interface but build it with the socket and chardev interfaces. If you
> don't want users to have to build their own version of swtpm then I would
> suggest to use either 'swtpm chardev' with the vtpm_proxy module (it is
> quite commonly available on recent distros) or 'swtpm socket'.
> 
> The chardev usage is for example described here and should be least involved
> to convert to:
> 
> https://github.com/stefanberger/swtpm/wiki/Using-the-Intel-TSS-with-swtpm#character-device-using-tpm_vtpm_proxy
> 
> You could start it like this with UnixIO control port (needs adjustment to
> swtpm_ioctl in your code).
> 
> swtpm chardev --vtpm-proxy --tpmstate dir=/tmp/myvtpm --tpm2 --ctrl
> type=unixio,path=/tmp/myvtpm/ctrl --flags startup-clear --daemon > logfile
> 
> No need to run 'swtpm_ioctl -i' and tpm2_startup with the startup-clear
> passed.
> 
> One of my test cases determines the created device (/dev/tpmXYZ) like this:
> 
> for ((i = 0; i < 200; i ++)); do
>         if [ -z "${TPM_DEVICE}" ]; then
>                 TPM_DEVICE=$(sed -n 's,.*\(/dev/tpm[0-9]\+\).*,\1,p'
> "logfile")
>                 if [ -n "${TPM_DEVICE}" ]; then
>                         echo "Using ${TPM_DEVICE}."
>                 fi
>         fi
>         if [ -n "${TPM_DEVICE}" ]; then
>                 [ -c "${TPM_DEVICE}" ] && break
>         fi
>         sleep 0.1
> done
> 
> shutdown: sudo swtpm_ioctl -s --unix /tmp/myvtpm/ctrl
> 
> 
> Otherwise you could use the socket version described here:
> 
> https://github.com/stefanberger/swtpm/wiki/Using-the-Intel-TSS-with-swtpm#socket-interface
> 
> It needs the swtpm tcti as a dependency, though.
> 
Thanks for the suggestion. Using 'swtpm socket' requires additional changes
to grub-emu and grub-protect. To minimize the impact, I'd convert the test
script to use 'swtpm chardev'.

Gary Lin

>    Stefan
> 
> > 
> > There are several test cases in the script to test various settings. Each
> > test case uses grub-protect to seal the LUKS password against PCR 0 and
> > PCR 1. Then grub-emu is launched to load the LUKS image, try to mount
> > the image with tpm2_key_protector_init and cryptomount, and verify the
> > result.
> > 
> > Based on the idea from Michael Chang.
> > 
> > Cc: Michael Chang <mchang@suse.com>
> > Signed-off-by: Gary Lin <glin@suse.com>

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

  reply	other threads:[~2024-04-15  6:43 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-09  8:30 [PATCH v10 00/20] Automatic Disk Unlock with TPM2 Gary Lin via Grub-devel
2024-04-09  8:30 ` [PATCH v10 01/20] posix_wrap: tweaks in preparation for libtasn1 Gary Lin via Grub-devel
2024-04-09  8:30 ` [PATCH v10 02/20] libtasn1: import libtasn1-4.19.0 Gary Lin via Grub-devel
2024-04-09  8:30 ` [PATCH v10 03/20] libtasn1: disable code not needed in grub Gary Lin via Grub-devel
2024-04-09  8:30 ` [PATCH v10 04/20] libtasn1: changes for grub compatibility Gary Lin via Grub-devel
2024-04-09  8:30 ` [PATCH v10 05/20] libtasn1: fix the potential buffer overrun Gary Lin via Grub-devel
2024-04-09  8:30 ` [PATCH v10 06/20] libtasn1: compile into asn1 module Gary Lin via Grub-devel
2024-04-09  8:30 ` [PATCH v10 07/20] asn1_test: test module for libtasn1 Gary Lin via Grub-devel
2024-04-09  8:30 ` [PATCH v10 08/20] libtasn1: Add the documentation Gary Lin via Grub-devel
2024-04-09  8:30 ` [PATCH v10 09/20] key_protector: Add key protectors framework Gary Lin via Grub-devel
2024-04-09  8:30 ` [PATCH v10 10/20] tpm2: Add TPM Software Stack (TSS) Gary Lin via Grub-devel
2024-04-09 15:32   ` Stefan Berger
2024-04-10  6:44     ` Gary Lin via Grub-devel
2024-04-09  8:30 ` [PATCH v10 11/20] key_protector: Add TPM2 Key Protector Gary Lin via Grub-devel
2024-04-09  8:30 ` [PATCH v10 12/20] cryptodisk: Support key protectors Gary Lin via Grub-devel
2024-04-09  8:30 ` [PATCH v10 13/20] util/grub-protect: Add new tool Gary Lin via Grub-devel
2024-04-09  8:30 ` [PATCH v10 14/20] tpm2: Support authorized policy Gary Lin via Grub-devel
2024-04-09  8:30 ` [PATCH v10 15/20] tpm2: Implement NV index Gary Lin via Grub-devel
2024-04-09  8:30 ` [PATCH v10 16/20] cryptodisk: Fallback to passphrase Gary Lin via Grub-devel
2024-04-09  8:30 ` [PATCH v10 17/20] cryptodisk: wipe out the cached keys from protectors Gary Lin via Grub-devel
2024-04-09  8:30 ` [PATCH v10 18/20] diskfilter: look up cryptodisk devices first Gary Lin via Grub-devel
2024-04-09  8:30 ` [PATCH v10 19/20] tpm2: Enable tpm2 module for grub-emu Gary Lin via Grub-devel
2024-04-09  8:30 ` [PATCH v10 20/20] tests: Add tpm2_test Gary Lin via Grub-devel
2024-04-12 16:09   ` Stefan Berger
2024-04-15  6:42     ` Gary Lin via Grub-devel [this message]
2024-04-12  6:35 ` [PATCH v10 00/20] Automatic Disk Unlock with TPM2 Gary Lin via Grub-devel

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=20240415064249.xsjdnzcl7ripxpno@GaryLaptop \
    --to=grub-devel@gnu.org \
    --cc=christopher.co@microsoft.com \
    --cc=daniel.kiper@oracle.com \
    --cc=daniel.mihai@microsoft.com \
    --cc=development@efficientek.com \
    --cc=dja@axtens.net \
    --cc=glin@suse.com \
    --cc=hegatta@linux.microsoft.com \
    --cc=jaredz@redhat.com \
    --cc=jaskaran.khurana@microsoft.com \
    --cc=jejb@linux.ibm.com \
    --cc=mchang@suse.com \
    --cc=patrick.colp@oracle.com \
    --cc=shkhisti@microsoft.com \
    --cc=stefanb@linux.ibm.com \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).