Blame SOURCES/cryptsetup-Add-FIPS-related-error-message-in-keyslot-add-code.patch

38c00b
From 293abb5435e2b4bec7f8333fb11c88d5c1f45800 Mon Sep 17 00:00:00 2001
38c00b
From: Ondrej Kozina <okozina@redhat.com>
38c00b
Date: Mon, 5 Dec 2022 13:35:24 +0100
38c00b
Subject: [PATCH 3/3] Add FIPS related error message in keyslot add code.
38c00b
38c00b
Add hints on what went wrong when creating new LUKS
38c00b
keyslots. The hint is printed only in FIPS mode and
38c00b
when pbkdf2 failed with passphrase shorter than 8
38c00b
bytes.
38c00b
---
38c00b
 lib/luks1/keymanage.c           | 5 ++++-
38c00b
 lib/luks2/luks2_keyslot_luks2.c | 2 ++
38c00b
 2 files changed, 6 insertions(+), 1 deletion(-)
38c00b
38c00b
diff --git a/lib/luks1/keymanage.c b/lib/luks1/keymanage.c
38c00b
index de97b73c..225e84b8 100644
38c00b
--- a/lib/luks1/keymanage.c
38c00b
+++ b/lib/luks1/keymanage.c
0b2424
@@ -924,8 +924,11 @@ int LUKS_set_key(unsigned int keyIndex,
38c00b
 			hdr->keyblock[keyIndex].passwordSalt, LUKS_SALTSIZE,
38c00b
 			derived_key->key, hdr->keyBytes,
38c00b
 			hdr->keyblock[keyIndex].passwordIterations, 0, 0);
38c00b
-	if (r < 0)
38c00b
+	if (r < 0) {
38c00b
+		if (crypt_fips_mode() && passwordLen < 8)
38c00b
+			log_err(ctx, _("Invalid passphrase for PBKDF2 in FIPS mode."));
38c00b
 		goto out;
38c00b
+	}
38c00b
 
38c00b
 	/*
0b2424
 	 * AF splitting, the volume key stored in vk->key is split to AfKey
38c00b
diff --git a/lib/luks2/luks2_keyslot_luks2.c b/lib/luks2/luks2_keyslot_luks2.c
38c00b
index 78f74242..f480bcab 100644
38c00b
--- a/lib/luks2/luks2_keyslot_luks2.c
38c00b
+++ b/lib/luks2/luks2_keyslot_luks2.c
0b2424
@@ -265,6 +265,8 @@ static int luks2_keyslot_set_key(struct crypt_device *cd,
0b2424
 	free(salt);
38c00b
 	if (r < 0) {
38c00b
 		crypt_free_volume_key(derived_key);
38c00b
+		if (crypt_fips_mode() && passwordLen < 8 && !strcmp(pbkdf.type, "pbkdf2"))
38c00b
+			log_err(cd, _("Invalid passphrase for PBKDF2 in FIPS mode."));
38c00b
 		return r;
38c00b
 	}
38c00b
 
38c00b
-- 
38c00b
2.38.1
38c00b