Blame SOURCES/cryptsetup-2.5.0-Fix-test-passphrase-when-device-in-reencryption.patch

4fc88f
diff -rupN cryptsetup-2.3.7.old/man/cryptsetup.8 cryptsetup-2.3.7/man/cryptsetup.8
4fc88f
--- cryptsetup-2.3.7.old/man/cryptsetup.8	2022-02-24 15:58:37.968167423 +0100
4fc88f
+++ cryptsetup-2.3.7/man/cryptsetup.8	2022-02-24 17:06:25.326217548 +0100
4fc88f
@@ -321,7 +321,7 @@ the command prompts for it interactively
4fc88f
 \-\-keyfile\-size, \-\-readonly, \-\-test\-passphrase,
4fc88f
 \-\-allow\-discards, \-\-header, \-\-key-slot, \-\-master\-key\-file, \-\-token\-id,
4fc88f
 \-\-token\-only, \-\-disable\-keyring, \-\-disable\-locks, \-\-type, \-\-refresh,
4fc88f
-\-\-serialize\-memory\-hard\-pbkdf].
4fc88f
+\-\-serialize\-memory\-hard\-pbkdf, \-\-unbound].
4fc88f
 .PP
4fc88f
 \fIluksSuspend\fR <name>
4fc88f
 .IP
4fc88f
@@ -1409,10 +1409,14 @@ aligned to page size and page-cache init
4fc88f
 integrity tag.
4fc88f
 .TP
4fc88f
 .B "\-\-unbound"
4fc88f
-
4fc88f
 Creates new or dumps existing LUKS2 unbound keyslot. See \fIluksAddKey\fR or
4fc88f
 \fIluksDump\fR actions for more details.
4fc88f
 
4fc88f
+When used in \fIluksOpen\fR action (allowed only together with
4fc88f
+\-\-test\-passphrase parameter), it allows to test passphrase for unbound LUKS2
4fc88f
+keyslot. Otherwise, unbound keyslot passphrase can be tested only when specific
4fc88f
+keyslot is selected via \-\-key\-slot parameter.
4fc88f
+
4fc88f
 .TP
4fc88f
 .B "\-\-tcrypt\-hidden"
4fc88f
 .B "\-\-tcrypt\-system"
4fc88f
diff -rupN cryptsetup-2.3.7.old/src/cryptsetup.c cryptsetup-2.3.7/src/cryptsetup.c
4fc88f
--- cryptsetup-2.3.7.old/src/cryptsetup.c	2022-02-24 15:58:37.969167429 +0100
4fc88f
+++ cryptsetup-2.3.7/src/cryptsetup.c	2022-02-24 17:10:30.947561638 +0100
4fc88f
@@ -230,7 +230,7 @@ static void _set_activation_flags(uint32
4fc88f
 		*flags |= CRYPT_ACTIVATE_IGNORE_PERSISTENT;
4fc88f
 
4fc88f
 	/* Only for LUKS2 but ignored elsewhere */
4fc88f
-	if (opt_test_passphrase)
4fc88f
+	if (opt_test_passphrase && (opt_unbound || (opt_key_slot != CRYPT_ANY_SLOT)))
4fc88f
 		*flags |= CRYPT_ACTIVATE_ALLOW_UNBOUND_KEY;
4fc88f
 
4fc88f
 	if (opt_serialize_memory_hard_pbkdf)
4fc88f
@@ -4021,6 +4021,17 @@ int main(int argc, const char **argv)
4fc88f
 		_("Option --tcrypt-hidden, --tcrypt-system or --tcrypt-backup is supported only for TCRYPT device."),
4fc88f
 		poptGetInvocationName(popt_context));
4fc88f
 
4fc88f
+	if (opt_unbound && !strcmp(aname, "open") && device_type &&
4fc88f
+	    strncmp(device_type, "luks", 4))
4fc88f
+		usage(popt_context, EXIT_FAILURE,
4fc88f
+		_("Option --unbound is allowed only for open of luks device."),
4fc88f
+		poptGetInvocationName(popt_context));
4fc88f
+
4fc88f
+	if (opt_unbound && !opt_test_passphrase && !strcmp(aname, "open"))
4fc88f
+		usage(popt_context, EXIT_FAILURE,
4fc88f
+		_("Option --unbound cannot be used without --test-passphrase."),
4fc88f
+		poptGetInvocationName(popt_context));
4fc88f
+
4fc88f
 	if (opt_tcrypt_hidden && opt_allow_discards)
4fc88f
 		usage(popt_context, EXIT_FAILURE,
4fc88f
 		_("Option --tcrypt-hidden cannot be combined with --allow-discards."),
4fc88f
@@ -4103,9 +4114,9 @@ int main(int argc, const char **argv)
4fc88f
 		      _("Keyslot specification is required."),
4fc88f
 		      poptGetInvocationName(popt_context));
4fc88f
 
4fc88f
-	if (opt_unbound && strcmp(aname, "luksAddKey") && strcmp(aname, "luksDump"))
4fc88f
+	if (opt_unbound && strcmp(aname, "luksAddKey") && strcmp(aname, "luksDump") && strcmp(aname, "open"))
4fc88f
 		usage(popt_context, EXIT_FAILURE,
4fc88f
-		      _("Option --unbound may be used only with luksAddKey and luksDump actions."),
4fc88f
+		      _("Option --unbound may be used only with luksAddKey, luksDump and open actions."),
4fc88f
 		      poptGetInvocationName(popt_context));
4fc88f
 
4fc88f
 	if (opt_refresh && strcmp(aname, "open"))
4fc88f
diff -rupN cryptsetup-2.3.7.old/tests/compat-test2 cryptsetup-2.3.7/tests/compat-test2
4fc88f
--- cryptsetup-2.3.7.old/tests/compat-test2	2022-02-24 15:58:38.013167680 +0100
4fc88f
+++ cryptsetup-2.3.7/tests/compat-test2	2022-02-24 17:23:23.035760517 +0100
4fc88f
@@ -696,7 +696,7 @@ $CRYPTSETUP luksOpen -S 5 -d $KEY1 $LOOP
4fc88f
 # otoh it should be allowed to test for proper passphrase
4fc88f
 prepare "" new
4fc88f
 echo $PWD1 | $CRYPTSETUP open -S1 --test-passphrase $HEADER_KEYU || fail
4fc88f
-echo $PWD1 | $CRYPTSETUP open --test-passphrase $HEADER_KEYU || fail
4fc88f
+echo $PWD1 | $CRYPTSETUP open --unbound --test-passphrase $HEADER_KEYU || fail
4fc88f
 echo $PWD1 | $CRYPTSETUP open -S1 $HEADER_KEYU $DEV_NAME 2>/dev/null && fail
4fc88f
 [ -b /dev/mapper/$DEV_NAME ] && fail
4fc88f
 echo $PWD1 | $CRYPTSETUP open $HEADER_KEYU $DEV_NAME 2>/dev/null && fail
4fc88f
@@ -705,7 +705,7 @@ echo $PWD0 | $CRYPTSETUP open -S1 --test
4fc88f
 $CRYPTSETUP luksKillSlot -q $HEADER_KEYU 0
4fc88f
 $CRYPTSETUP luksDump $HEADER_KEYU | grep -q "0: luks2" && fail
4fc88f
 echo $PWD1 | $CRYPTSETUP open -S1 --test-passphrase $HEADER_KEYU || fail
4fc88f
-echo $PWD1 | $CRYPTSETUP open --test-passphrase $HEADER_KEYU || fail
4fc88f
+echo $PWD1 | $CRYPTSETUP open --unbound --test-passphrase $HEADER_KEYU || fail
4fc88f
 echo $PWD1 | $CRYPTSETUP open -S1 $HEADER_KEYU $DEV_NAME 2>/dev/null && fail
4fc88f
 
4fc88f
 prepare "[28] Detached LUKS header" wipe
4fc88f
@@ -952,11 +952,9 @@ echo $PWD3 | $CRYPTSETUP -q luksAddKey -
4fc88f
 # do not allow to replace keyslot by unbound slot
4fc88f
 echo $PWD1 | $CRYPTSETUP -q luksAddKey -S5 --unbound -s 32 $LOOPDEV 2>/dev/null && fail
4fc88f
 echo $PWD2 | $CRYPTSETUP -q open $LOOPDEV $DEV_NAME 2> /dev/null && fail
4fc88f
-echo $PWD2 | $CRYPTSETUP -q open $LOOPDEV --test-passphrase || fail
4fc88f
 echo $PWD2 | $CRYPTSETUP -q open -S2 $LOOPDEV $DEV_NAME 2> /dev/null && fail
4fc88f
 echo $PWD2 | $CRYPTSETUP -q open -S2 $LOOPDEV --test-passphrase || fail
4fc88f
 echo $PWD1 | $CRYPTSETUP -q open $LOOPDEV $DEV_NAME 2> /dev/null && fail
4fc88f
-echo $PWD1 | $CRYPTSETUP -q open $LOOPDEV --test-passphrase || fail
4fc88f
 # check we're able to change passphrase for unbound keyslot
4fc88f
 echo -e "$PWD2\n$PWD3" | $CRYPTSETUP luksChangeKey $FAST_PBKDF_OPT -S 2 $LOOPDEV || fail
4fc88f
 echo $PWD3 | $CRYPTSETUP open --test-passphrase $FAST_PBKDF_OPT -S 2 $LOOPDEV || fail