Commit Graph

3879 Commits

Author SHA1 Message Date
Daniel Zatovic
58385d68d8 Allow activation via keyslot context. 2023-08-15 17:42:31 +02:00
Ondrej Kozina
28e1c95c22 Allow priority ignore keyslots with specific token or keyslot specified. 2023-08-15 17:42:31 +02:00
Ondrej Kozina
6751b43424 Allow keyslot in internal LUKS2 token activation code.
Extends code so that later API may support LUKS2 device
activation via token with specified keyslot.

Also allows testing if specific token is able to unlock specific
keyslot.
2023-08-15 17:42:31 +02:00
Ondrej Kozina
50207333f1 Fix a bug in LUKS2 header wipe function with keyslots area.
When formating LUKS2 device with no keyslots area (it's valid
LUKS2 header) there's a bug in wipe routine that is supposed
to wipe LUKS2 keyslots area. When the keyslots area size is of
zero length it causes wipe function to erase whole data device
starting at defined data offset.
2023-08-15 15:23:28 +02:00
Ondrej Kozina
b65fb6072e Do not mention --new-keyfile option in luksChangeKey action man page. 2023-08-15 15:23:17 +02:00
sad-goldfish
a7821c3d9e Add algorithm specification warning to integritysetup.8.adoc. 2023-08-03 06:57:50 +00:00
Brandon Enright
01f1512730 Minor reencrypt man page typo fixes 2023-08-02 20:01:25 +00:00
Ondrej Kozina
ef46ded7b4 Add OPAL2 detached header tests. 2023-08-02 13:46:46 +02:00
Ondrej Kozina
28da4ed72d Make luksErase work with detached header.
For it to work correctly with LUKS2 OPAL we have to
set data device properly so it can erase OPAL locking
range (or revert via PSID).
2023-08-02 13:46:46 +02:00
Ondrej Kozina
e1d494c4e1 Fix LUKS2 OPAL deactivation when header is missing.
When no header is available but LUSK2_OPAL dm uuid
prefix is detected try to lock opal locking range
upon LUKS2 device deactivation (best effort only as
in crypt_suspend).
2023-08-02 13:46:46 +02:00
Ondrej Kozina
5cf9e28530 Do not set default data offset with LUKS2 OPAL detached header. 2023-08-01 16:39:27 +02:00
Ondrej Kozina
570d3ad4e4 Add support for suspend/resume with LUKS2 OPAL2 devices. 2023-08-01 16:39:27 +02:00
Ondrej Kozina
b60ffe9e06 Introduce LUKS2-OPAL private dm uuid prefix.
LUKS2 devices with configured HW OPAL encryption (any configuration)
get activated with private dm uuid prefix LUKS2-OPAL so that we
can properly detect devices with HW OPAL encryption even with
missing LUKS2 header (detached header). Internally LUKS2-OPAL
prefix matches LUKS2 device type.
2023-08-01 16:36:26 +02:00
Ondrej Kozina
fc04761cdc Check dm uuid matches LUKS metadata during crypt_suspend. 2023-08-01 16:36:24 +02:00
Ondrej Kozina
0a805d325c Do not reinitialize dm backend when not needed.
device-mapper backend gets initialized with crypt_device
structure and it cannot be NULL in crypt_suspend.
2023-07-26 15:38:14 +02:00
Ondrej Kozina
ad3013dfe4 Simplify crypt_get_hw_encryption_type internals.
Do not take into account cipher specification and rely
solely on segment type in LUKS2 metadata.
2023-07-18 16:29:19 +02:00
Milan Broz
7754660409 Fix leak of volume key in activation code error path. 2023-07-18 12:01:56 +02:00
Milan Broz
928061f1f0 Print better metadata dump and status info for OPAL segment. 2023-07-17 22:39:26 +01:00
Ondrej Kozina
4d487d5dcf Properly handle authenticated encryption on OPAL device. 2023-07-17 22:39:26 +01:00
Milan Broz
33bf0c6ae9 opal: Limit sector size to maximum 4096 bytes.
Some devices support 16k optiomal size, but dm-crypt
has limit 4k.
2023-07-17 22:39:26 +01:00
Luca Boccassi
b7c361df94 man: document OPAL support
Signed-off-by: Luca Boccassi <bluca@debian.org>
2023-07-17 22:39:26 +01:00
Ondrej Kozina
ace8b8578c Add OPAL2 basic test. 2023-07-17 22:39:26 +01:00
Luca Boccassi
decbe09fb3 cryptsetup: support for hw-opal in luksErase
Wipe and disable the segment. Also support the factory reset ioctl for
a complete wipe of the entire drive with a specific argument.

Signed-off-by: Luca Boccassi <bluca@debian.org>
2023-07-17 22:39:26 +01:00
Milan Broz
5716f959a7 Add crypt_get_hw_encryption_type API call. 2023-07-17 22:39:26 +01:00
Luca Boccassi
446ad76011 cryptsetup: add --hw-opal and --hw-opal-only
Signed-off-by: Luca Boccassi <bluca@debian.org>
Co-authored-by: Ondrej Kozina <okozina@redhat.com>
2023-07-17 22:39:26 +01:00
Luca Boccassi
b9cc0129c9 libcryptsetup: add OPAL type and params
Signed-off-by: Luca Boccassi <bluca@debian.org>
Co-authored-by: Ondrej Kozina <okozina@redhat.com>
2023-07-17 13:14:52 +02:00
Ludwig Nussel
fc4151f77e Fix option name in error output 2023-06-28 14:10:03 +02:00
Milan Broz
b8711faf92 Fix activation of LUKS2 with capi format cipher and kernel crypt name.
While activation of internal cipher algorithms (like aes-generic)
is disallowed, some old LUKS2 images can still use it.

Check the cipher in activate call, but allow to load LUKS2 metadata.
This can allow to add repair code easily and also allow luksDump.

Also fix segfault in reencrypt code for such a header.

Fixes: #820
2023-06-26 13:26:13 +02:00
Milan Broz
1f01eea60e Fix reencryption to fail properly for unknown cipher.
crypt_get_cipher and crypt_get_cipher mode can return NULL,
check it in advance.
2023-06-26 13:25:59 +02:00
Ondrej Kozina
10847d7100 Create optional reduced dm-integrity device.
This enables creating dm-integrity devices that
does not use all available space but only initial
part of the device.

This will be used with future hw-opal-crypt segment
where partion may be not aligned to locking range
alignment and needs to be reduced.

We dont't want to span dm-integrity device into
area not included in opal locking range.
2023-06-22 14:43:19 +00:00
Milan Broz
e13840c5cb tcrypt: Fix test in FIPS mode. 2023-06-22 16:41:33 +02:00
Milan Broz
9c5f555930 tcrypt: Support new Blake2 hash.
VeraCrypt 1.26.2 introduces support for Blake2 PRF for PBKDF2.
This patch adds support for cryptsetup.
2023-06-22 08:46:38 +00:00
Milan Broz
33a3d1ba7b tcrypt: use hash values as substring if limiting KDF check.
This allows to specify --hash sha or --hash blake2 to limit
KDF without need to specify full algorithm name
(similar to cipher where we already use substring match).
2023-06-22 08:46:38 +00:00
Milan Broz
53aa5f6c4f Fix init_by_name to allow unknown cipher format in dm-crypt as null context.
Deactivation code should deactivate dm-crypt device even if it is unknown
for libcryptsetup. Previous fix for cipher specification was too strict.

Let's allow initialization as null context, that allow status and
deactivate to be usable again.
2023-06-22 08:46:06 +00:00
Ondrej Kozina
2712882aa3 Add helper function to change segment size. 2023-06-06 13:44:44 +00:00
Milan Broz
5042ec2cd0 Use unconditionally sleep 1 in scsi_debug test 2023-06-04 11:59:05 +02:00
Ondrej Kozina
d6107bf241 Refactor json_segment_create_crypt helper.
Refactor crypt segment json helper body into
separate routine so that it can be reused later
in future hw-opal-crypt segment helper.
2023-05-29 11:09:04 +02:00
Ondrej Kozina
47ac021c03 Refactor LUKS2 encryption parameters verification.
Code verifying encryption parameters needs to be reusable
for new code that will be added later.

Also due to previous changes to data offset and metadata size
calculations, encryption parameters can now be verified at
single place without need to split it over crypt_format_luks2
routine.
2023-05-29 11:09:04 +02:00
Ondrej Kozina
969e67e743 Use defined constant for cipher_spec buffer size. 2023-05-29 11:09:04 +02:00
Ondrej Kozina
6a8fa14007 Move cipher parsing outside LUKS2 header generator function.
Let's make LUKS2_generate_hdr as clean as possible. Cipher
specification string can be constructed in upper layers.

This will make future LUKS2_generate_hdr extension easier.
2023-05-29 11:09:04 +02:00
Ondrej Kozina
fd91de82ad Move integrity fields in json_segment_create_crypt segment helper.
The integrity is optional parameter of dm-crypt segment definition.
Move the low level json code in appropriate json helper.

It will make adding new segment easier. The future hw-opal-crypt
segment will inherit all crypt fields.
2023-05-29 11:09:04 +02:00
Ondrej Kozina
926679f7f1 Refactor LUKS2 metadata parameters calculations.
Move all metadata size and data offset calculations
logic away from LUKS2_generate_hdr. The function
was meant to generate solely LUKS2 header on disk json
format.

The aim is to have all logic related data offset and metadata
size in one place available to be calculated in advance so
that we can easily extend the code.
2023-05-29 11:08:29 +02:00
Ondrej Kozina
11d8c58c72 Fix wrong return value from LUKS2_generate_hdr on error.
On rare occasion (low memory) the function could return success
even though LUKS2 json metadata could be assembled properly.
2023-05-24 17:46:19 +02:00
Daniel Zatovic
716cf78da6 CI: Add apt-get update to Debian jobs. 2023-05-24 13:20:41 +02:00
Milan Broz
dff9ee8c8c Also disallow active devices with internal kernel names.
The same problem fixed in commit 438cf1d1b3
is present in libdevmapper wrapper when parsing active device table.

The whole point of conversion was that non-authenticated modes
can be always represented in the old cipher-mode-iv format.
As the internal names contains dash, these are unsupported.

That said, the libdevmapper backend now correctly returns
full cipher specification including capi prefix for this case.

Init_by_name call now fails with incomplatible cipher definition error.
2023-05-02 15:42:21 +02:00
Milan Broz
80a001232f tests: Fix memory leak introduced in previous patches. 2023-05-02 14:52:17 +02:00
Milan Broz
841c681825 Workaround for oss-fuzz build. 2023-04-29 16:28:29 +02:00
Milan Broz
438cf1d1b3 Disallow use of internal kenrel crypto driver names in "capi" specification.
The common way to specify cipher mode in cryptsetup
is to use cipher-mode-iv notation (like aes-xts-plain64).
With introduction of authenticated ciphers we also allow "capi:<spec>"
notation that is directly used by dm-crypt (e.g. capi:xts(aes)-plain64).

CAPI specification was never intended to be used with internal
kernel crypto api names (with dash in algorithm name), actually the
whole parsing routine wrongly parses mode here now.

The code not checks if parsing wrongly separated the full cipher
string and effectively allowing only proper cipher names
(example of no longer supported string is capi:xts(ecb(aes-generic))-plain64).

Thanks to Jan Wichelmann, Luca Wilke and Thomas Eisenbarth from
University of Lübeck for noticing the problems with this code.

Fixes: #809
2023-04-25 18:56:31 +02:00
Milan Broz
91d8ab7f20 Add Aria cipher support and block size info.
Aria cipher is similar to AES and is supported
in Linux kernel crypto API in recent releases.
This patch just add support for internal info table.
(This will cause that it is used also for keyslot
encryption if specified as a cipher argument.)
2023-04-24 19:29:08 +02:00
Milan Broz
d173514b81 Do not decrease PBKDF parameters if a user forces them.
If a user explicitly specifies PBKDF parameters (like iterations,
used memory of threads), do not limit them, even if it can cause
resource exhaustion.

The only limits are hard limits per the PBKDF algorithm.

The force options were mostly used for decreasing parameters,
but it should work even opposite - despite the fact it can mean
shooting yourself in the foot (OOM).

Fixes: #812
2023-04-24 13:09:34 +02:00