Fixes for non-default TPM PCR banks
cover Fixes for non-default TPM PCR banks
There are two bugs when using the TPM PCR banks other than the default SHA256 PCR bank:
1) Key unsealing failure
2) Dumping the wrong PCR bank
This patch set fixes the above two bugs and adds the tests for SHA384 PCR bank.
Gary Lin (3):
grub-protect: Fix the hash algorithm of PCR digest
tpm2_key_protector: Dump the PCR bank for key unsealing tests/tpm2_key_protector_test: Add tests for SHA384 PCR bank
.../commands/tpm2_key_protector/module.c | 11 ++++-- tests/tpm2_key_protector_test.in | 34 +++++++++++++++++-- util/grub-protect.c | 2 +- 3 files changed, 41 insertions(+), 6 deletions(-)
Signature · 7 lines
2.43.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 1/3 grub-protect: Fix the hash algorithm of PCR digest
For "tpm2_key_protector" and "grub-protect", 'SHA256' is chosen as the hash algorithm for the TPM session. However, grub-protect mistakenly used the hash algorithm of the PCR bank to calculate PCR digest. If the user chose a PCR bank other than 'SHA256", "grub-protect" created a non-SHA256 PCR digest to seal the key. But, "tpm2_key_protector" expects a SHA256 PCR digest to the TPM unsealing session, so it would fail due to digest mismatch.
This commit fixes the hash algorithm of PCR digest in grub-protect to avoid the potential unsealing failure.
Ref: https://github.com/lcp/grub2/issues/4
--- util/grub-protect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
util/grub-protect.c +1 -1
@@ -483,7 +483,7 @@ protect_tpm2_get_policy_digest (protect_args_t *args, TPM2B_DIGEST_t *digest) } pcr_concat.size = pcr_concat_len; - rc =grub_tpm2_hash (NULL , &pcr_concat, args->tpm2_bank,TPM_RH_NULL , &pcr_digest,NULL ,NULL ); + rc =grub_tpm2_hash (NULL , &pcr_concat,TPM_ALG_SHA256 ,TPM_RH_NULL , &pcr_digest,NULL ,NULL );if (rc !=TPM_RC_SUCCESS ) {fprintf (stderr,"Failed to generate PCR digest (TPM2_Hash: 0x%x)\n" , rc);
Signature · 7 lines
2.43.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 1/3] grub-protect: Fix the hash algorithm of PCR digest
Quoted 8 lines · Gary Lin
For "
tpm2_key_protector" and "grub-protect", 'SHA256' is chosen as the hash algorithm for the TPM session. However, grub-protect mistakenly used the hash algorithm of the PCR bank to calculate PCR digest. If the user chose a PCR bank other than 'SHA256", "grub-protect" created a non-SHA256 PCR digest to seal the key. But, "tpm2_key_protector" expects a SHA256 PCR digest to the TPM unsealing session, so it would fail due to digest mismatch.
Quoted 6 lines
This commit fixes the hash algorithm of PCR digest in grub-protect to avoid the potential unsealing failure.
Ref: https://github.com/lcp/grub2/issues/4
Signed-off-by Gary Lin <[email protected]>
Quoted 9 lines
--- util/grub-protect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)util/grub-protect.c +0
-0
util/grub-protect.c protect_tpm2_get_policy_digest (protect_args_t *args, TPM2B_DIGEST_t *digest) · line 489
Quoted 8 lines
util/grub-protect.c +1
-1@@ -483,7 +483,7 @@ protect_tpm2_get_policy_digest (protect_args_t *args, TPM2B_DIGEST_t *digest) } pcr_concat.size = pcr_concat_len; - rc =grub_tpm2_hash (NULL , &pcr_concat, args->tpm2_bank,TPM_RH_NULL , &pcr_digest,NULL ,NULL ); + rc =grub_tpm2_hash (NULL , &pcr_concat,TPM_ALG_SHA256 ,TPM_RH_NULL , &pcr_digest,NULL ,NULL );if (rc !=TPM_RC_SUCCESS ) {fprintf (stderr,"Failed to generate PCR digest (TPM2_Hash: 0x%x)\n" , rc);
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 1/3] grub-protect: Fix the hash algorithm of PCR digest
In reply to Gary Lin via Grub-develQuoted 8 lines · Gary Lin via Grub-devel
For "
tpm2_key_protector" and "grub-protect", 'SHA256' is chosen as the hash algorithm for the TPM session. However, grub-protect mistakenly used the hash algorithm of the PCR bank to calculate PCR digest. If the user chose a PCR bank other than 'SHA256", "grub-protect" created a non-SHA256 PCR digest to seal the key. But, "tpm2_key_protector" expects a SHA256 PCR digest to the TPM unsealing session, so it would fail due to digest mismatch.
Quoted 6 lines
This commit fixes the hash algorithm of PCR digest in grub-protect to avoid the potential unsealing failure.
Ref: https://github.com/lcp/grub2/issues/4
Signed-off-by Gary Lin <[email protected]>
Quoted 20 lines
--- util/grub-protect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)util/grub-protect.c +1
-1@@ -483,7 +483,7 @@ protect_tpm2_get_policy_digest (protect_args_t *args, TPM2B_DIGEST_t *digest) } pcr_concat.size = pcr_concat_len; - rc =grub_tpm2_hash (NULL , &pcr_concat, args->tpm2_bank, TPM_RH_NULL, &pcr_digest, NULL, NULL); + rc =grub_tpm2_hash (NULL , &pcr_concat,TPM_ALG_SHA256 ,TPM_RH_NULL , &pcr_digest,NULL ,NULL );if (rc != TPM_RC_SUCCESS) { fprintf (stderr, "Failed to generate PCR digest (TPM2_Hash:
Quoted 1 line
0x%x)\n", rc);
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 2/3 tpm2_key_protector: Dump the PCR bank for key unsealing
In reply to Gary Lin via Grub-develTPM 2.0 Key File format stores the PCR selection in the parameters for 'TPM2_PolicyPCR' and it already contains the selected PCR bank. Currently, "tpm2_key_protector" dumped the PCR bank specified by the '--bank' option, and it may not be the PCR bank for key unsealing.
To dump the real PCR bank for key unsealing, this commit records the PCR bank used by 'TPM2_PolicyPCR' and dumps PCR values from that bank when necessary.
--- grub-core/commands/tpm2_key_protector/module.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
grub-core/commands/tpm2_key_protector/module.c +9 -2
@@ -162,6 +162,8 @@ static tpm2_protector_context_t tpm2_protector_ctx = {0};static grub_command_t tpm2_dump_pcr_cmd; +static TPM_ALG_ID_t tpm2_dump_bank; +static grub_err_t tpm2_protector_srk_read_file (const char *filepath,void **buffer,grub_size_t *buffer_size) {
@@ -654,6 +656,9 @@ tpm2_protector_policypcr (TPMI_SH_AUTH_SESSION_t session, struct grub_tpm2_buffeif (cmd_buf->error !=0 )return grub_error (GRUB_ERR_BAD_ARGUMENT ,"failed to unmarshal commandPolicy for TPM2_PolicyPCR" ); +/* Record the chosen PCR bank */ + tpm2_dump_bank = pcr_sel.pcrSelections[0 ].hash; + rc =grub_tpm2_policypcr (session,NULL , &pcr_digest, &pcr_sel,NULL );if (rc !=TPM_RC_SUCCESS )return grub_error (GRUB_ERR_BAD_DEVICE ,"failed to submit PCR policy (TPM2_PolicyPCR: 0x%x)" , rc);
@@ -1091,7 +1096,7 @@ tpm2_protector_key_from_buffer (const tpm2_protector_context_t *ctx,if (dump_pcr == true) {grub_printf ("PCR Mismatch! Check firmware and bootloader before typing passphrase!\n" ); -tpm2_protector_dump_pcr (ctx->bank); +tpm2_protector_dump_pcr (tpm2_dump_bank); } exit2:
@@ -1151,7 +1156,7 @@ tpm2_protector_load_persistent (const tpm2_protector_context_t *ctx, TPM_HANDLE_if (dump_pcr == true) {grub_printf ("PCR Mismatch! Check firmware and bootloader before typing passphrase!\n" ); -tpm2_protector_dump_pcr (ctx->bank); +tpm2_protector_dump_pcr (tpm2_dump_bank); } exit:
@@ -1273,6 +1278,8 @@ tpm2_protector_check_args (tpm2_protector_context_t *ctx)if (ctx->bank ==TPM_ALG_ERROR ) ctx->bank =TPM_ALG_SHA256 ; + tpm2_dump_bank = ctx->bank; +if (ctx->pcr_count ==0 ) { ctx->pcrs[0 ] =7 ;
Signature · 7 lines
2.43.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 2/3] tpm2_key_protector: Dump the PCR bank for key unsealing
Quoted 56 lines · Gary Lin
TPM 2.0 Key File format stores the PCR selection in the parameters for '
TPM2_PolicyPCR' and it already contains the selected PCR bank. Currently, "tpm2_key_protector" dumped the PCR bank specified by the '--bank' option, and it may not be the PCR bank for key unsealing.To dump the real PCR bank for key unsealing, this commit records the PCR bank used by '
TPM2_PolicyPCR' and dumps PCR values from that bank when necessary.Signed-off-by Gary Lin <[email protected]>--- grub-core/commands/tpm2_key_protector/module.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)grub-core/commands/tpm2_key_protector/module.c +7
-2@@ -162,6 +162,8 @@ static tpm2_protector_context_t tpm2_protector_ctx = {0};static grub_command_t tpm2_dump_pcr_cmd; +static TPM_ALG_ID_t tpm2_dump_bank; +static grub_err_t tpm2_protector_srk_read_file (const char *filepath,void **buffer,grub_size_t *buffer_size) {@@ -654,6 +656,9 @@ tpm2_protector_policypcr (TPMI_SH_AUTH_SESSION_t session, struct grub_tpm2_buffeif (cmd_buf->error !=0 )return grub_error (GRUB_ERR_BAD_ARGUMENT ,"failed to unmarshal commandPolicy for TPM2_PolicyPCR" ); +/* Record the chosen PCR bank */ + tpm2_dump_bank = pcr_sel.pcrSelections[0 ].hash; + rc =grub_tpm2_policypcr (session,NULL , &pcr_digest, &pcr_sel,NULL );if (rc !=TPM_RC_SUCCESS )return grub_error (GRUB_ERR_BAD_DEVICE ,"failed to submit PCR policy (TPM2_PolicyPCR: 0x%x)" , rc);@@ -1091,7 +1096,7 @@ tpm2_protector_key_from_buffer (const tpm2_protector_context_t *ctx,if (dump_pcr == true) {grub_printf ("PCR Mismatch! Check firmware and bootloader before typing passphrase!\n" ); -tpm2_protector_dump_pcr (ctx->bank); +tpm2_protector_dump_pcr (tpm2_dump_bank); } exit2:@@ -1151,7 +1156,7 @@ tpm2_protector_load_persistent (const tpm2_protector_context_t *ctx, TPM_HANDLE_if (dump_pcr == true) {grub_printf ("PCR Mismatch! Check firmware and bootloader before typing passphrase!\n" ); -tpm2_protector_dump_pcr (ctx->bank); +tpm2_protector_dump_pcr (tpm2_dump_bank); } exit:
grub-core/commands/tpm2_key_protector/module.c tpm2_protector_check_args (tpm2_protector_context_t *ctx) · line 1285
Quoted 8 lines
grub-core/commands/tpm2_key_protector/module.c +2
-0@@ -1273,6 +1278,8 @@ tpm2_protector_check_args (tpm2_protector_context_t *ctx)if (ctx->bank ==TPM_ALG_ERROR ) ctx->bank =TPM_ALG_SHA256 ; + tpm2_dump_bank = ctx->bank; +if (ctx->pcr_count ==0 ) { ctx->pcrs[0 ] =7 ;
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 2/3] tpm2_key_protector: Dump the PCR bank for key unsealing
In reply to Gary Lin via Grub-develQuoted 10 lines · Gary Lin via Grub-devel
TPM 2.0 Key File format stores the PCR selection in the parameters for '
TPM2_PolicyPCR' and it already contains the selected PCR bank. Currently, "tpm2_key_protector" dumped the PCR bank specified by the '--bank' option, and it may not be the PCR bank for key unsealing.To dump the real PCR bank for key unsealing, this commit records the PCR bank used by '
TPM2_PolicyPCR' and dumps PCR values from that bank when necessary.Signed-off-by Gary Lin <[email protected]>
Quoted 65 lines
--- grub-core/commands/tpm2_key_protector/module.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)grub-core/commands/tpm2_key_protector/module.c +2
-0@@ -162,6 +162,8 @@ static tpm2_protector_context_t tpm2_protector_ctx = {0 };static grub_command_t tpm2_dump_pcr_cmd; +static TPM_ALG_ID_t tpm2_dump_bank; + static grub_err_t tpm2_protector_srk_read_file (const char *filepath, void **buffer,
grub_size_t*buffer_size)
{grub-core/commands/tpm2_key_protector/module.c +0
-0@@ -654,6 +656,9 @@ tpm2_protector_policypcr (TPMI_SH_AUTH_SESSION_tsession, struct
grub_tpm2_buffe
if (cmd_buf->error!= 0)
returngrub_error(GRUB_ERR_BAD_ARGUMENT, "failed to unmarshal
commandPolicy forTPM2_PolicyPCR");grub-core/commands/tpm2_key_protector/module.c +3
-0+/* Record the chosen PCR bank */ + tpm2_dump_bank = pcr_sel.pcrSelections[0 ].hash; + rc = grub_tpm2_policypcr (session, NULL, &pcr_digest, &pcr_sel,NULL);
if (rc !=TPM_RC_SUCCESS)
returngrub_error(GRUB_ERR_BAD_DEVICE, "failed to submit PCR
policy (TPM2_PolicyPCR: 0x%x)", rc);grub-core/commands/tpm2_key_protector/module.c +1
-1@@ -1091,7 +1096,7 @@ tpm2_protector_key_from_buffer (const tpm2_protector_context_t *ctx, if (dump_pcr == true) { grub_printf ("PCR Mismatch! Check firmware and bootloader before typing passphrase!\n"); - tpm2_protector_dump_pcr (ctx->bank); + tpm2_protector_dump_pcr (tpm2_dump_bank); }exit2:
grub-core/commands/tpm2_key_protector/module.c +0
-0@@ -1151,7 +1156,7 @@ tpm2_protector_load_persistent (const
tpm2_protector_context_t*ctx,TPM_HANDLE_
if (dump_pcr== true)
{
grub_printf("PCR Mismatch! Check firmware and bootloader
before typing passphrase!\n");grub-core/commands/tpm2_key_protector/module.c +3
-1-tpm2_protector_dump_pcr (ctx->bank); +tpm2_protector_dump_pcr (tpm2_dump_bank); } exit:@@ -1273,6 +1278,8 @@ tpm2_protector_check_args (tpm2_protector_context_t *ctx)if (ctx->bank ==TPM_ALG_ERROR ) ctx->bank =TPM_ALG_SHA256 ; + tpm2_dump_bank = ctx->bank; +if (ctx->pcr_count ==0 ) {
Quoted 1 line
ctx->pcrs[0] = 7;
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 3/3 tests/tpm2_key_protector_test: Add tests for SHA384 PCR bank
In reply to Gary Lin via Grub-develAdd a few more tests to seal and unseal the key with the SHA384 PCR bank instead of the default SHA256 PCR bank.
--- tests/tpm2_key_protector_test.in | 34 +++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-)
tests/tpm2_key_protector_test.in +31 -3
@@ -136,16 +136,28 @@ done # Export the TCTI variable for tpm2-tools export TPM2TOOLS_TCTI="device:${tpm2dev}" +# Check if the sha384 bank is available +if [ "$(tpm2_getcap pcrs | grep sha384)" != "" ]; then + with_sha384=true +fi + # Extend PCR 0 tpm2_pcrextend 0:sha256=$(echo "test0" | sha256sum | cut -d ' ' -f 1) || exit 99 +if [ "${with_sha384}" = "true" ]; then + tpm2_pcrextend 0:sha384=$(echo "test0" | sha384sum | cut -d ' ' -f 1) || exit 99 +fi # Extend PCR 1 tpm2_pcrextend 1:sha256=$(echo "test1" | sha256sum | cut -d ' ' -f 1) || exit 99 +if [ "${with_sha384}" = "true" ]; then + tpm2_pcrextend 1:sha384=$(echo "test1" | sha384sum | cut -d ' ' -f 1) || exit 99 +fi tpm2_seal_unseal() { srk_alg="$1" handle_type="$2" srk_test="$3" + pcr_bank="$4" grub_srk_alg=${srk_alg}
@@ -164,13 +176,17 @@ tpm2_seal_unseal() { extra_opt="${extra_opt} --tpm2-asymmetric=${srk_alg}" fi + if [ "${pcr_bank}" = "" ]; then + pcr_bank="sha256" + fi + # Seal the password with grub-protect grub-protect ${extra_opt} \ --tpm2-device="${tpm2dev}" \ --action=add \ --protector=tpm2 \ --tpm2key \ - --tpm2-bank=sha256 \ + --tpm2-bank="${pcr_bank}" \ --tpm2-pcrs=0,1 \ --tpm2-keyfile="${lukskeyfile}" \ --tpm2-outfile="${sealedkey}" || ret=$?
@@ -228,6 +244,7 @@ EOF tpm2_seal_unseal_nv() { handle_type="$1" key_type="$2" + pcr_bank="$3" extra_opt="" extra_grub_opt=""
@@ -238,10 +255,14 @@ tpm2_seal_unseal_nv() { nv_index="0x81000000" fi + if [ "${pcr_bank}" = "" ]; then + pcr_bank="sha256" + fi + if [ "$key_type" = "tpm2key" ]; then extra_opt="--tpm2key" else - extra_grub_opt="--pcrs=0,1" + extra_grub_opt="--pcrs=0,1 -b ${pcr_bank}" fi grub_cfg=${tpm2testdir}/testcase.cfg
@@ -251,7 +272,7 @@ tpm2_seal_unseal_nv() { --tpm2-device="${tpm2dev}" \ --action=add \ --protector=tpm2 \ - --tpm2-bank=sha256 \ + --tpm2-bank="${pcr_bank}" \ --tpm2-pcrs=0,1 \ --tpm2-keyfile="${lukskeyfile}" \ --tpm2-nvindex="${nv_index}" || ret=$?
@@ -300,6 +321,9 @@ srktests+=("RSA persistent no_fallback_srk") srktests+=("ECC persistent no_fallback_srk") srktests+=("RSA transient fallback_srk") srktests+=("ECC transient fallback_srk") +if [ "${with_sha384}" = "true" ]; then + srktests+=("default transient no_fallback_srk sha384") +fi exit_status=0
@@ -322,6 +346,10 @@ declare -a nvtests=() nvtests+=("persistent raw") nvtests+=("nvindex raw") nvtests+=("nvindex tpm2key") +if [ "${with_sha384}" = "true" ]; then + nvtests+=("persistent raw sha384") + nvtests+=("nvindex tpm2key sha384") +fi for i in "${!nvtests[@]}"; do tpm2_seal_unseal_nv ${nvtests[$i]} || ret=$?
Signature · 7 lines
2.43.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 3/3] tests/tpm2_key_protector_test: Add tests for SHA384 PCR bank
Quoted 28 lines · Gary Lin
Add a few more tests to seal and unseal the key with the SHA384 PCR bank instead of the default SHA256 PCR bank.
Signed-off-by Gary Lin <[email protected]>--- tests/tpm2_key_protector_test.in | 34 +++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-)tests/tpm2_key_protector_test.in +8
-0@@ -136,16 +136,28 @@ done # Export the TCTI variable for tpm2-tools export TPM2TOOLS_TCTI="device:${tpm2dev}" +# Check if the sha384 bank is available +if [ "$(tpm2_getcap pcrs | grep sha384)" != "" ]; then + with_sha384=true +fi + # Extend PCR 0 tpm2_pcrextend 0:sha256=$(echo "test0" | sha256sum | cut -d ' ' -f 1) || exit 99 +if [ "${with_sha384}" = "true" ]; then + tpm2_pcrextend 0:sha384=$(echo "test0" | sha384sum | cut -d ' ' -f 1) || exit 99 +fi # Extend PCR 1
tests/tpm2_key_protector_test.in done · line 160
Quoted 10 lines
tests/tpm2_key_protector_test.in +4
-0tpm2_pcrextend 1:sha256=$(echo "test1" | sha256sum | cut -d ' ' -f 1) || exit 99 +if [ "${with_sha384}" = "true" ]; then + tpm2_pcrextend 1:sha384=$(echo "test1" | sha384sum | cut -d ' ' -f 1) || exit 99 +fi tpm2_seal_unseal() { srk_alg="$1" handle_type="$2" srk_test="$3" + pcr_bank="$4"
I would now adjust all existing callers to pass a 4th argument "" so that the number of arguments match.
tests/tpm2_key_protector_test.in tpm2_seal_unseal() { · line 182
Quoted 11 lines
tests/tpm2_key_protector_test.in +4
-0grub_srk_alg=${srk_alg}@@ -164,13 +176,17 @@ tpm2_seal_unseal() { extra_opt="${extra_opt} --tpm2-asymmetric=${srk_alg}" fi + if [ "${pcr_bank}" = "" ]; then + pcr_bank="sha256" + fi +
To avoid this the 4th argument should probably be "sha256" for all existing callers.
Quoted 12 lines
tests/tpm2_key_protector_test.in +1
-1# Seal the password with grub-protect grub-protect ${extra_opt} \ --tpm2-device="${tpm2dev}" \ --action=add \ --protector=tpm2 \ --tpm2key \ - --tpm2-bank=sha256 \ + --tpm2-bank="${pcr_bank}" \ --tpm2-pcrs=0,1 \ --tpm2-keyfile="${lukskeyfile}" \ --tpm2-outfile="${sealedkey}" || ret=$?
tests/tpm2_key_protector_test.in EOF · line 247
Quoted 4 lines
tests/tpm2_key_protector_test.in +1
-0@@ -228,6 +244,7 @@ EOF tpm2_seal_unseal_nv() { handle_type="$1" key_type="$2" + pcr_bank="$3"
Same comments here...
tests/tpm2_key_protector_test.in tpm2_seal_unseal_nv() { · line 261
Quoted 11 lines
tests/tpm2_key_protector_test.in +4
-0extra_opt="" extra_grub_opt=""@@ -238,10 +255,14 @@ tpm2_seal_unseal_nv() { nv_index="0x81000000" fi + if [ "${pcr_bank}" = "" ]; then + pcr_bank="sha256" + fi +
... and here.
Quoted 28 lines
tests/tpm2_key_protector_test.in +5
-2if [ "$key_type" = "tpm2key" ]; then extra_opt="--tpm2key" else - extra_grub_opt="--pcrs=0,1" + extra_grub_opt="--pcrs=0,1 -b ${pcr_bank}" fi grub_cfg=${tpm2testdir}/testcase.cfg@@ -251,7 +272,7 @@ tpm2_seal_unseal_nv() { --tpm2-device="${tpm2dev}" \ --action=add \ --protector=tpm2 \ - --tpm2-bank=sha256 \ + --tpm2-bank="${pcr_bank}" \ --tpm2-pcrs=0,1 \ --tpm2-keyfile="${lukskeyfile}" \ --tpm2-nvindex="${nv_index}" || ret=$?@@ -300,6 +321,9 @@ srktests+=("RSA persistent no_fallback_srk") srktests+=("ECC persistent no_fallback_srk") srktests+=("RSA transient fallback_srk") srktests+=("ECC transient fallback_srk") +if [ "${with_sha384}" = "true" ]; then + srktests+=("default transient no_fallback_srk sha384") +fi exit_status=0
tests/tpm2_key_protector_test.in declare -a nvtests=() · line 355
Quoted 10 lines
tests/tpm2_key_protector_test.in +4
-0@@ -322,6 +346,10 @@ declare -a nvtests=() nvtests+=("persistent raw") nvtests+=("nvindex raw") nvtests+=("nvindex tpm2key") +if [ "${with_sha384}" = "true" ]; then + nvtests+=("persistent raw sha384") + nvtests+=("nvindex tpm2key sha384") +fi for i in "${!nvtests[@]}"; do tpm2_seal_unseal_nv ${nvtests[$i]} || ret=$?
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 3/3] tests/tpm2_key_protector_test: Add tests for SHA384 PCR bank
Quoted 33 lines · Stefan Berger
Quoted 30 lines · Gary Lin
Add a few more tests to seal and unseal the key with the SHA384 PCR bank instead of the default SHA256 PCR bank.
Signed-off-by Gary Lin <[email protected]>--- tests/tpm2_key_protector_test.in | 34 +++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-)tests/tpm2_key_protector_test.in +11
-0@@ -136,16 +136,28 @@ done # Export the TCTI variable for tpm2-tools export TPM2TOOLS_TCTI="device:${tpm2dev}" +# Check if the sha384 bank is available +if [ "$(tpm2_getcap pcrs | grep sha384)" != "" ]; then + with_sha384=true +fi + # Extend PCR 0 tpm2_pcrextend 0:sha256=$(echo "test0" | sha256sum | cut -d ' ' -f 1) || exit 99 +if [ "${with_sha384}" = "true" ]; then + tpm2_pcrextend 0:sha384=$(echo "test0" | sha384sum | cut -d ' ' -f 1) || exit 99 +fi # Extend PCR 1 tpm2_pcrextend 1:sha256=$(echo "test1" | sha256sum | cut -d ' ' -f 1) || exit 99 +if [ "${with_sha384}" = "true" ]; then + tpm2_pcrextend 1:sha384=$(echo "test1" | sha384sum | cut -d ' ' -f 1) || exit 99 +fi
Quoted 9 lines
tests/tpm2_key_protector_test.in done · line 160
Quoted 5 lines
tests/tpm2_key_protector_test.in +1
-0tpm2_seal_unseal() { srk_alg="$1" handle_type="$2" srk_test="$3" + pcr_bank="$4"I would now adjust all existing callers to pass a 4th argument "" so that the number of arguments match.
I was thinking about minimizing the diff, but adding the 4th argument is better in the long run.
Will fix that in v2.
Thanks,
Gary Lin
Quoted 68 lines
tests/tpm2_key_protector_test.in tpm2_seal_unseal() { · line 181
Quoted 8 lines
tests/tpm2_key_protector_test.in +4
-0grub_srk_alg=${srk_alg}@@ -164,13 +176,17 @@ tpm2_seal_unseal() { extra_opt="${extra_opt} --tpm2-asymmetric=${srk_alg}" fi + if [ "${pcr_bank}" = "" ]; then + pcr_bank="sha256" + fi +To avoid this the 4th argument should probably be "sha256" for all existing callers.
Quoted 12 lines
tests/tpm2_key_protector_test.in +1
-1# Seal the password with grub-protect grub-protect ${extra_opt} \ --tpm2-device="${tpm2dev}" \ --action=add \ --protector=tpm2 \ --tpm2key \ - --tpm2-bank=sha256 \ + --tpm2-bank="${pcr_bank}" \ --tpm2-pcrs=0,1 \ --tpm2-keyfile="${lukskeyfile}" \ --tpm2-outfile="${sealedkey}" || ret=$?tests/tpm2_key_protector_test.in EOF · line 247
Quoted 4 lines
tests/tpm2_key_protector_test.in +1
-0@@ -228,6 +244,7 @@ EOF tpm2_seal_unseal_nv() { handle_type="$1" key_type="$2" + pcr_bank="$3"Same comments here...
tests/tpm2_key_protector_test.in tpm2_seal_unseal_nv() { · line 260
Quoted 9 lines
tests/tpm2_key_protector_test.in +4
-0extra_opt="" extra_grub_opt=""@@ -238,10 +255,14 @@ tpm2_seal_unseal_nv() { nv_index="0x81000000" fi + if [ "${pcr_bank}" = "" ]; then + pcr_bank="sha256" + fi +... and here.
Quoted 26 lines
tests/tpm2_key_protector_test.in +5
-2if [ "$key_type" = "tpm2key" ]; then extra_opt="--tpm2key" else - extra_grub_opt="--pcrs=0,1" + extra_grub_opt="--pcrs=0,1 -b ${pcr_bank}" fi grub_cfg=${tpm2testdir}/testcase.cfg@@ -251,7 +272,7 @@ tpm2_seal_unseal_nv() { --tpm2-device="${tpm2dev}" \ --action=add \ --protector=tpm2 \ - --tpm2-bank=sha256 \ + --tpm2-bank="${pcr_bank}" \ --tpm2-pcrs=0,1 \ --tpm2-keyfile="${lukskeyfile}" \ --tpm2-nvindex="${nv_index}" || ret=$?@@ -300,6 +321,9 @@ srktests+=("RSA persistent no_fallback_srk") srktests+=("ECC persistent no_fallback_srk") srktests+=("RSA transient fallback_srk") srktests+=("ECC transient fallback_srk") +if [ "${with_sha384}" = "true" ]; then + srktests+=("default transient no_fallback_srk sha384") +fi exit_status=0@@ -322,6 +346,10 @@ declare -a nvtests=() nvtests+=("persistent raw")
Quoted 9 lines
tests/tpm2_key_protector_test.in declare -a nvtests=() · line 355
Quoted 8 lines
tests/tpm2_key_protector_test.in +4
-0nvtests+=("nvindex raw") nvtests+=("nvindex tpm2key") +if [ "${with_sha384}" = "true" ]; then + nvtests+=("persistent raw sha384") + nvtests+=("nvindex tpm2key sha384") +fi for i in "${!nvtests[@]}"; do tpm2_seal_unseal_nv ${nvtests[$i]} || ret=$?
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 3/3] tests/tpm2_key_protector_test: Add tests for SHA384 PCR bank
In reply to Gary Lin via Grub-develQuoted 4 lines · Gary Lin via Grub-devel
Add a few more tests to seal and unseal the key with the SHA384 PCR bank instead of the default SHA256 PCR bank.
Signed-off-by Gary Lin <[email protected]>
Quoted 104 lines
--- tests/tpm2_key_protector_test.in | 34 +++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-)tests/tpm2_key_protector_test.in +5
-0@@ -136,16 +136,28 @@ done # Export the TCTI variable for tpm2-tools export TPM2TOOLS_TCTI="device:${tpm2dev}" +# Check if the sha384 bank is available +if [ "$(tpm2_getcap pcrs | grep sha384)" != "" ]; then + with_sha384=true +fi + # Extend PCR 0 tpm2_pcrextend 0:sha256=$(echo "test0" | sha256sum | cut -d ' ' -f 1)|| exit 99
tests/tpm2_key_protector_test.in +3
-1+if [ "${with_sha384}" = "true" ]; then + tpm2_pcrextend 0:sha384=$(echo "test0" | sha384sum | cut -d ' ' -f 1) || exit 99 +fi # Extend PCR 1 tpm2_pcrextend 1:sha256=$(echo "test1" | sha256sum | cut -d ' ' -f 1)|| exit 99
tests/tpm2_key_protector_test.in +19
-4+if [ "${with_sha384}" = "true" ]; then + tpm2_pcrextend 1:sha384=$(echo "test1" | sha384sum | cut -d ' ' -f 1) || exit 99 +fi tpm2_seal_unseal() { srk_alg="$1" handle_type="$2" srk_test="$3" + pcr_bank="$4" grub_srk_alg=${srk_alg}@@ -164,13 +176,17 @@ tpm2_seal_unseal() { extra_opt="${extra_opt} --tpm2-asymmetric=${srk_alg}" fi + if [ "${pcr_bank}" = "" ]; then + pcr_bank="sha256" + fi + # Seal the password with grub-protect grub-protect ${extra_opt} \ --tpm2-device="${tpm2dev}" \ --action=add \ --protector=tpm2 \ --tpm2key \ - --tpm2-bank=sha256 \ + --tpm2-bank="${pcr_bank}" \ --tpm2-pcrs=0,1 \ --tpm2-keyfile="${lukskeyfile}" \ --tpm2-outfile="${sealedkey}" || ret=$?@@ -228,6 +244,7 @@ EOF tpm2_seal_unseal_nv() { handle_type="$1" key_type="$2" + pcr_bank="$3" extra_opt="" extra_grub_opt=""@@ -238,10 +255,14 @@ tpm2_seal_unseal_nv() { nv_index="0x81000000" fi + if [ "${pcr_bank}" = "" ]; then + pcr_bank="sha256" + fi + if [ "$key_type" = "tpm2key" ]; then extra_opt="--tpm2key" else - extra_grub_opt="--pcrs=0,1" + extra_grub_opt="--pcrs=0,1 -b ${pcr_bank}" fi grub_cfg=${tpm2testdir}/testcase.cfg@@ -251,7 +272,7 @@ tpm2_seal_unseal_nv() { --tpm2-device="${tpm2dev}" \ --action=add \ --protector=tpm2 \ - --tpm2-bank=sha256 \ + --tpm2-bank="${pcr_bank}" \ --tpm2-pcrs=0,1 \ --tpm2-keyfile="${lukskeyfile}" \ --tpm2-nvindex="${nv_index}" || ret=$?@@ -300,6 +321,9 @@ srktests+=("RSA persistent no_fallback_srk") srktests+=("ECC persistent no_fallback_srk") srktests+=("RSA transient fallback_srk") srktests+=("ECC transient fallback_srk") +if [ "${with_sha384}" = "true" ]; then + srktests+=("default transient no_fallback_srk sha384") +fi exit_status=0
tests/tpm2_key_protector_test.in declare -a nvtests=() · line 355
Quoted 10 lines
tests/tpm2_key_protector_test.in +4
-0@@ -322,6 +346,10 @@ declare -a nvtests=() nvtests+=("persistent raw") nvtests+=("nvindex raw") nvtests+=("nvindex tpm2key") +if [ "${with_sha384}" = "true" ]; then + nvtests+=("persistent raw sha384") + nvtests+=("nvindex tpm2key sha384") +fi for i in "${!nvtests[@]}"; do tpm2_seal_unseal_nv ${nvtests[$i]} || ret=$?
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel