summaryrefslogtreecommitdiff
path: root/src/cryptsetup/cryptsetup-tpm2.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-08-19 16:16:03 +0200
committerLennart Poettering <lennart@poettering.net>2022-08-19 16:30:37 +0200
commit8de8ec88da2a0008752a08bc6886fa1c1d885776 (patch)
tree52fa01585a7a31f556647f41a0d8a841152cc9a5 /src/cryptsetup/cryptsetup-tpm2.c
parent4436081e9d2fbc9cde7045472a22689b1c9dbb74 (diff)
downloadsystemd-8de8ec88da2a0008752a08bc6886fa1c1d885776.tar.gz
tpm2-util: also add helper for parsing PCR arrays
Diffstat (limited to 'src/cryptsetup/cryptsetup-tpm2.c')
-rw-r--r--src/cryptsetup/cryptsetup-tpm2.c22
1 files changed, 5 insertions, 17 deletions
diff --git a/src/cryptsetup/cryptsetup-tpm2.c b/src/cryptsetup/cryptsetup-tpm2.c
index b84d64def8..c715c8f232 100644
--- a/src/cryptsetup/cryptsetup-tpm2.c
+++ b/src/cryptsetup/cryptsetup-tpm2.c
@@ -185,7 +185,7 @@ int find_tpm2_auto_data(
for (token = start_token; token < sym_crypt_token_max(CRYPT_LUKS2); token++) {
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
- JsonVariant *w, *e;
+ JsonVariant *w;
int ks;
r = cryptsetup_get_token_as_json(cd, token, "systemd-tpm2", &v);
@@ -203,25 +203,13 @@ int find_tpm2_auto_data(
}
w = json_variant_by_key(v, "tpm2-pcrs");
- if (!w || !json_variant_is_array(w))
+ if (!w)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"TPM2 token data lacks 'tpm2-pcrs' field.");
- assert(pcr_mask == 0);
- JSON_VARIANT_ARRAY_FOREACH(e, w) {
- uint64_t u;
-
- if (!json_variant_is_number(e))
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
- "TPM2 PCR is not a number.");
-
- u = json_variant_unsigned(e);
- if (u >= TPM2_PCRS_MAX)
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
- "TPM2 PCR number out of range.");
-
- pcr_mask |= UINT32_C(1) << u;
- }
+ r = tpm2_parse_pcr_json_array(w, &pcr_mask);
+ if (r < 0)
+ return log_error_errno(r, "Failed to parse TPM2 PCR mask: %m");
if (search_pcr_mask != UINT32_MAX &&
search_pcr_mask != pcr_mask) /* PCR mask doesn't match what is configured, ignore this entry */