cryptsetup: Report mismatching TPM token error separately

When we enroll two UKIs with different PCR pub keys into one LUKS slot/
token each, then we can encounter the wrong one and should report it
with a clearer error than the generic "Failed to unseal secret using
TPM2".
So when we don't have the right signature, report this as separate
error.
This commit is contained in:
Kai Lüke
2026-07-10 08:07:47 +02:00
committed by Kai Lüke
parent 924552cfba
commit 58d38f6360
4 changed files with 10 additions and 3 deletions
@@ -26,7 +26,7 @@ _public_ const char *cryptsetup_token_version(void) {
static int log_debug_open_error(struct crypt_device *cd, int r) {
if (r == -EAGAIN)
return crypt_log_debug_errno(cd, r, "TPM2 device not found.");
if (r == -ENXIO)
if (r == -ENOSTR)
return crypt_log_debug_errno(cd, r, "No matching TPM2 token data found.");
return crypt_log_debug_errno(cd, r, TOKEN_NAME " open failed: %m.");
@@ -119,6 +119,8 @@ int acquire_luks2_key(
return log_error_errno(r, "TPM is in dictionary attack lock-out mode.");
if (ERRNO_IS_NEG_TPM2_UNSEAL_BAD_PCR(r))
return log_error_errno(r, "TPM policy does not match current system state. Either system has been tempered with or policy out-of-date: %m");
if (r == -ENOSTR)
return log_error_errno(r, "No signature for current PCR policy in TPM2 signature JSON, token does not apply to current boot state: %m");
if (r < 0)
return log_error_errno(r, "Failed to unseal secret using TPM2: %m");