tpm2: change tpm2_unseal() to accept Tpm2Context instead of device string

This matches the change to tpm2_seal(), which now accepts a Tpm2Context instead
of a device string.

This also allows using the same TPM context for sealing and unsealing, which
will be required by (future) test code when sealing/unsealing using a transient
key.
This commit is contained in:
Dan Streetman
2023-08-31 09:10:40 -04:00
parent 7014006906
commit db7fdf152b
6 changed files with 22 additions and 16 deletions

View File

@@ -80,7 +80,12 @@ int acquire_luks2_key(
return log_error_errno(r, "Failed to load PCR signature: %m");
}
r = tpm2_unseal(device,
_cleanup_(tpm2_context_unrefp) Tpm2Context *tpm2_context = NULL;
r = tpm2_context_new(device, &tpm2_context);
if (r < 0)
return log_error_errno(r, "Failed to create TPM2 context: %m");
r = tpm2_unseal(tpm2_context,
hash_pcr_mask,
pcr_bank,
pubkey, pubkey_size,

View File

@@ -129,8 +129,13 @@ int acquire_tpm2_key(
return log_error_errno(r, "Failed to load pcr signature: %m");
}
_cleanup_(tpm2_context_unrefp) Tpm2Context *tpm2_context = NULL;
r = tpm2_context_new(device, &tpm2_context);
if (r < 0)
return log_error_errno(r, "Failed to create TPM2 context: %m");
if (!(flags & TPM2_FLAGS_USE_PIN)) {
r = tpm2_unseal(device,
r = tpm2_unseal(tpm2_context,
hash_pcr_mask,
pcr_bank,
pubkey, pubkey_size,
@@ -177,7 +182,7 @@ int acquire_tpm2_key(
/* no salting needed, backwards compat with non-salted pins */
b64_salted_pin = TAKE_PTR(pin_str);
r = tpm2_unseal(device,
r = tpm2_unseal(tpm2_context,
hash_pcr_mask,
pcr_bank,
pubkey, pubkey_size,