[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v23 27/33] tpm2_key_protector: Implement NV index
From: |
Gary Lin |
Subject: |
[PATCH v23 27/33] tpm2_key_protector: Implement NV index |
Date: |
Fri, 15 Nov 2024 15:34:55 +0800 |
From: Patrick Colp <patrick.colp@oracle.com>
Currently with the TPM2 protector, only SRK mode is supported and
NV index support is just a stub. Implement the NV index option.
Note: This only extends support on the unseal path. grub-protect
has not been updated. tpm2-tools can be used to insert a key into
the NV index.
An example of inserting a key using tpm2-tools:
# Get random key.
tpm2_getrandom 32 > key.dat
# Create primary object.
tpm2_createprimary -C o -g sha256 -G ecc -c primary.ctx
# Create policy object. `pcrs.dat` contains the PCR values to seal against.
tpm2_startauthsession -S session.dat
tpm2_policypcr -S session.dat -l sha256:7,11 -f pcrs.dat -L policy.dat
tpm2_flushcontext session.dat
# Seal key into TPM.
cat key.dat | tpm2_create -C primary.ctx -u key.pub -r key.priv -L policy.dat
-i-
tpm2_load -C primary.ctx -u key.pub -r key.priv -n sealing.name -c sealing.ctx
tpm2_evictcontrol -C o -c sealing.ctx 0x81000000
Then to unseal the key in grub, add this to grub.cfg:
tpm2_key_protector_init --mode=nv --nvindex=0x81000000 --pcrs=7,11
cryptomount -u <UUID> --protector tpm2
Signed-off-by: Patrick Colp <patrick.colp@oracle.com>
Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
---
.../commands/tpm2_key_protector/module.c | 23 +++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/grub-core/commands/tpm2_key_protector/module.c
b/grub-core/commands/tpm2_key_protector/module.c
index 6b4b5d460..74e79a545 100644
--- a/grub-core/commands/tpm2_key_protector/module.c
+++ b/grub-core/commands/tpm2_key_protector/module.c
@@ -973,11 +973,26 @@ tpm2_protector_srk_recover (const
tpm2_protector_context_t *ctx,
}
static grub_err_t
-tpm2_protector_nv_recover (const tpm2_protector_context_t *ctx __attribute__
((unused)),
- grub_uint8_t **key __attribute__ ((unused)),
- grub_size_t *key_size __attribute__ ((unused)))
+tpm2_protector_nv_recover (const tpm2_protector_context_t *ctx,
+ grub_uint8_t **key, grub_size_t *key_size)
{
- return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "NV Index mode is not
implemented yet");
+ TPM_HANDLE_t sealed_handle = ctx->nv;
+ tpm2key_policy_t policy_seq = NULL;
+ grub_err_t err;
+
+ /* Create a basic policy sequence based on the given PCR selection */
+ err = tpm2_protector_simple_policy_seq (ctx, &policy_seq);
+ if (err != GRUB_ERR_NONE)
+ goto exit;
+
+ err = tpm2_protector_unseal (policy_seq, sealed_handle, key, key_size);
+
+ exit:
+ grub_tpm2_flushcontext (sealed_handle);
+
+ grub_tpm2key_free_policy_seq (policy_seq);
+
+ return err;
}
static grub_err_t
--
2.43.0
- [PATCH v23 15/33] asn1_test: enable the testcase only when GRUB_LONG_MAX is larger than GRUB_INT_MAX, (continued)
- [PATCH v23 15/33] asn1_test: enable the testcase only when GRUB_LONG_MAX is larger than GRUB_INT_MAX, Gary Lin, 2024/11/15
- [PATCH v23 16/33] libtasn1: compile into asn1 module, Gary Lin, 2024/11/15
- [PATCH v23 17/33] asn1_test: test module for libtasn1, Gary Lin, 2024/11/15
- [PATCH v23 18/33] libtasn1: Add the documentation, Gary Lin, 2024/11/15
- [PATCH v23 19/33] key_protector: Add key protectors framework, Gary Lin, 2024/11/15
- [PATCH v23 20/33] tss2: Add TPM2 buffer handling functions, Gary Lin, 2024/11/15
- [PATCH v23 21/33] tss2: Add TPM2 types and Marshal/Unmarshal functions, Gary Lin, 2024/11/15
- [PATCH v23 25/33] util/grub-protect: Add new tool, Gary Lin, 2024/11/15
- [PATCH v23 28/33] cryptodisk: Fallback to passphrase, Gary Lin, 2024/11/15
- [PATCH v23 26/33] tpm2_key_protector: Support authorized policy, Gary Lin, 2024/11/15
- [PATCH v23 27/33] tpm2_key_protector: Implement NV index,
Gary Lin <=
- [PATCH v23 22/33] tss2: Add TPM2 Software Stack (TSS2) support, Gary Lin, 2024/11/15
- [PATCH v23 24/33] cryptodisk: Support key protectors, Gary Lin, 2024/11/15
- [PATCH v23 32/33] tests: Add tpm2_key_protector_test, Gary Lin, 2024/11/15
- [PATCH v23 31/33] tpm2_key_protector: Add grub-emu support, Gary Lin, 2024/11/15
- [PATCH v23 23/33] key_protector: Add TPM2 Key Protector, Gary Lin, 2024/11/15
- [PATCH v23 29/33] cryptodisk: wipe out the cached keys from protectors, Gary Lin, 2024/11/15
- [PATCH v23 30/33] diskfilter: look up cryptodisk devices first, Gary Lin, 2024/11/15
- [PATCH v23 33/33] docs: Document TPM2 key protector, Gary Lin, 2024/11/15
- Re: [PATCH v23 00/33] Automatic Disk Unlock with TPM2, Stefan Berger, 2024/11/19