From: Stefan Berger <stefanb@linux.ibm.com>
To: Gary Lin <glin@suse.com>,
The development of GNU GRUB <grub-devel@gnu.org>
Cc: Daniel Kiper <daniel.kiper@oracle.com>,
mchang@suse.com, patrick.colp@oracle.com, jejb@linux.ibm.com,
Glenn Washburn <development@efficientek.com>
Subject: Re: [PATCH v4 08/12] tests/tpm2_key_protector_test: Simplify the NV index mode test
Date: Mon, 24 Mar 2025 10:21:00 -0400 [thread overview]
Message-ID: <b9e6b0c9-ebbf-4701-be41-3b9cb5050650@linux.ibm.com> (raw)
In-Reply-To: <20250321075908.10523-9-glin@suse.com>
On 3/21/25 3:59 AM, Gary Lin wrote:
> Since 'grub-protect' already supports NV index mode, tpm2_seal_nv() is
> replaced with one 'grub-protect' command to simplify the test script.
>
> 'tpm2_evictcontrol' is also replaced with 'grub-protect --tpm2-evict'.
>
> Signed-off-by: Gary Lin <glin@suse.com>
> ---
> tests/tpm2_key_protector_test.in | 108 +++++--------------------------
> 1 file changed, 15 insertions(+), 93 deletions(-)
>
> diff --git a/tests/tpm2_key_protector_test.in b/tests/tpm2_key_protector_test.in
> index a92e5f498..07477ba2a 100644
> --- a/tests/tpm2_key_protector_test.in
> +++ b/tests/tpm2_key_protector_test.in
> @@ -225,105 +225,22 @@ EOF
> fi
> }
>
> -tpm2_seal_nv () {
> - keyfile="$1"
> - nv_index="$2"
> - pcr_list="$3"
> -
> - primary_file=${tpm2testdir}/primary.ctx
> - session_file=${tpm2testdir}/session.dat
> - policy_file=${tpm2testdir}/policy.dat
> - keypub_file=${tpm2testdir}/key.pub
> - keypriv_file=${tpm2testdir}/key.priv
> - name_file=${tpm2testdir}/sealing.name
> - sealing_ctx_file=${tpm2testdir}/sealing.ctx
> -
> - # Since we don't run a resource manager on our swtpm instance, it has
> - # to flush the transient handles after tpm2_createprimary, tpm2_create
> - # and tpm2_load to avoid the potential out-of-memory (0x902) errors.
> - # Ref: https://github.com/tpm2-software/tpm2-tools/issues/1338#issuecomment-469689398
> -
> - # Create the primary object
> - tpm2_createprimary -Q -C o -g sha256 -G ecc -c "${primary_file}" || ret=$?
> - if [ "${ret}" -ne 0 ]; then
> - echo "Failed to create the primary object: ${ret}" >&2
> - return 1
> - fi
> - tpm2_flushcontext -t || ret=$?
> - if [ "${ret}" -ne 0 ]; then
> - echo "Failed to flush the transient handles: ${ret}" >&2
> - return 1
> - fi
> -
> - # Create the policy object
> - tpm2_startauthsession -S "${session_file}" || ret=$?
> - if [ "${ret}" -ne 0 ]; then
> - echo "Failed to start auth session: ${ret}" >&2
> - return 1
> - fi
> - tpm2_policypcr -Q -S "${session_file}" -l "${pcr_list}" -L "${policy_file}" || ret=$?
> - if [ "${ret}" -ne 0 ]; then
> - echo "Failed to create the policy object: ${ret}" >&2
> - return 1
> - fi
> - tpm2_flushcontext "${session_file}" || ret=$?
> - if [ "${ret}" -ne 0 ]; then
> - echo "Failed to flush the transient handles: ${ret}" >&2
> - return 1
> - fi
> -
> - # Seal the key into TPM
> - tpm2_create -Q \
> - -C "${primary_file}" \
> - -u "${keypub_file}" \
> - -r "${keypriv_file}" \
> - -L "${policy_file}" \
> - -i "${keyfile}" || ret=$?
> - if [ "${ret}" -ne 0 ]; then
> - echo "Failed to seal \"${keyfile}\": ${ret}" >&2
> - return 1
> - fi
> - tpm2_flushcontext -t || ret=$?
> - if [ "${ret}" -ne 0 ]; then
> - echo "Failed to flush the transient handles: ${ret}" >&2
> - return 1
> - fi
> -
> - tpm2_load -Q \
> - -C "${primary_file}" \
> - -u "${keypub_file}" \
> - -r "${keypriv_file}" \
> - -n "${name_file}" \
> - -c "${sealing_ctx_file}" || ret=$?
> - if [ "${ret}" -ne 0 ]; then
> - echo "Failed to load the sealed key into TPM: ${ret}" >&2
> - return 1
> - fi
> - tpm2_flushcontext -t || ret=$?
> - if [ "${ret}" -ne 0 ]; then
> - echo "Failed to flush the transient handles: ${ret}" >&2
> - return 1
> - fi
> -
> - tpm2_evictcontrol -Q -C o -c "${sealing_ctx_file}" ${nv_index} || ret=$?
> - if [ "${ret}" -ne 0 ]; then
> - echo "Failed to store the sealed key into ${nv_index}: ${ret}" >&2
> - return 1
> - fi
> -
> - return 0
> -}
> -
> tpm2_seal_unseal_nv() {
> nv_index="0x81000000"
> - pcr_list="sha256:0,1"
>
> grub_cfg=${tpm2testdir}/testcase.cfg
>
> # Seal the key into a NV index guarded by PCR 0 and 1
> - tpm2_seal_nv "${lukskeyfile}" ${nv_index} ${pcr_list} || ret=$?
> + grub-protect ${extra_opt} \
> + --tpm2-device="${tpm2dev}" \
> + --action=add \
> + --protector=tpm2 \
> + --tpm2-bank=sha256 \
> + --tpm2-pcrs=0,1 \
> + --tpm2-keyfile="${lukskeyfile}" \
> + --tpm2-nvindex="${nv_index}" || ret=$?
> if [ "${ret}" -ne 0 ]; then
> - echo "Failed to seal the secret key into ${nv_index}" >&2
> + echo "Failed to seal the secret key into ${nv_index}: ${ret}" >&2
> return 99
> fi
>
> @@ -340,7 +257,12 @@ EOF
> ${grubshell} --timeout=${timeout} --emu-opts="-t ${tpm2dev}" < "${grub_cfg}" > "${testoutput}" || ret=$?
>
> # Remove the object from the NV index
> - tpm2_evictcontrol -Q -C o -c "${nv_index}" || :
> + grub-protect \
> + --tpm2-device="${tpm2dev}" \
> + --protector=tpm2 \
> + --action=remove \
> + --tpm2-nvindex=${nv_index} \
> + --tpm2-evict || :
>
> if [ "${ret}" -eq 0 ]; then
> if ! grep -q "^${vtext}$" "${testoutput}"; then
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
next prev parent reply other threads:[~2025-03-24 14:21 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-21 7:58 [PATCH v4 00/12] TPM2 key protector follow-up patches Gary Lin via Grub-devel
2025-03-21 7:58 ` [PATCH v4 01/12] tpm2_key_protector: dump PCRs on policy fail Gary Lin via Grub-devel
2025-03-21 7:58 ` [PATCH v4 02/12] tpm2_key_protector: Add 'tpm2_dump_pcr' command Gary Lin via Grub-devel
2025-03-21 7:58 ` [PATCH v4 03/12] tss2: Fix the missing authCommand Gary Lin via Grub-devel
2025-03-21 7:59 ` [PATCH v4 04/12] tss2: Add TPM 2.0 NV index commands Gary Lin via Grub-devel
2025-03-21 7:59 ` [PATCH v4 05/12] tpm2_key_protector: Unseal key from a buffer Gary Lin via Grub-devel
2025-03-25 16:01 ` Daniel Kiper via Grub-devel
2025-03-26 7:54 ` Gary Lin via Grub-devel
2025-03-21 7:59 ` [PATCH v4 06/12] tpm2_key_protector: Support NV index handles Gary Lin via Grub-devel
2025-03-21 7:59 ` [PATCH v4 07/12] util/grub-protect: Support NV index mode Gary Lin via Grub-devel
2025-03-26 16:14 ` Daniel Kiper via Grub-devel
2025-03-21 7:59 ` [PATCH v4 08/12] tests/tpm2_key_protector_test: Simplify the NV index mode test Gary Lin via Grub-devel
2025-03-24 14:21 ` Stefan Berger [this message]
2025-03-26 16:16 ` Daniel Kiper via Grub-devel
2025-03-21 7:59 ` [PATCH v4 09/12] tests/tpm2_key_protector_test: Reset 'ret' on fail Gary Lin via Grub-devel
2025-03-24 13:48 ` Stefan Berger
2025-03-24 14:29 ` Vladimir 'phcoder' Serbinenko
2025-03-24 14:35 ` Stefan Berger
2025-03-25 7:18 ` Gary Lin via Grub-devel
2025-03-21 7:59 ` [PATCH v4 10/12] tests/tpm2_key_protector_test: Add more NV index mode tests Gary Lin via Grub-devel
2025-03-24 14:19 ` Stefan Berger
2025-03-21 7:59 ` [PATCH v4 11/12] docs: Update NV index mode of TPM2 key protector Gary Lin via Grub-devel
2025-03-21 7:59 ` [PATCH v4 12/12] INSTALL: Document the packages needed for TPM2 key protector tests Gary Lin via Grub-devel
2025-03-26 16:19 ` Daniel Kiper 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=b9e6b0c9-ebbf-4701-be41-3b9cb5050650@linux.ibm.com \
--to=stefanb@linux.ibm.com \
--cc=daniel.kiper@oracle.com \
--cc=development@efficientek.com \
--cc=glin@suse.com \
--cc=grub-devel@gnu.org \
--cc=jejb@linux.ibm.com \
--cc=mchang@suse.com \
--cc=patrick.colp@oracle.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.