Compare commits

...

1462 Commits

Author SHA1 Message Date
Milan Broz
a8105ef9bb Version 2.8.0-rc1. 2025-06-16 14:10:18 +02:00
Milan Broz
96787457e1 Add 2.8.0-rc1 Release notes. 2025-06-16 11:38:13 +02:00
Antonio Ceballos
849bd0d2f3 po: update es.po (from translationproject.org) 2025-06-15 10:47:31 +02:00
Petr Pisar
f866a663b0 po: update cs.po (from translationproject.org) 2025-06-15 10:47:31 +02:00
Milan Broz
bac868b392 Fix message translation (missing macro). 2025-06-09 10:13:26 +02:00
Marián Haburaj
7ed0934892 po: add sk.po (from translationproject.org) 2025-06-05 14:23:13 +02:00
Yuri Chornoivan
6db3fa33e1 po: update uk.po (from translationproject.org) 2025-06-05 14:20:44 +02:00
Remus-Gabriel Chelu
255336b309 po: update ro.po (from translationproject.org) 2025-06-05 14:20:44 +02:00
Hiroshi Takekawa
084b1d2984 po: update ja.po (from translationproject.org) 2025-06-05 14:20:44 +02:00
Frédéric Marchal
d0b582bbd6 po: update fr.po (from translationproject.org) 2025-06-05 14:20:44 +02:00
Roland Illig
b84ffc4ff4 po: update de.po (from translationproject.org) 2025-06-05 14:20:44 +02:00
Milan Broz
c7f3f32ec9 Avoid zero-length read in read_lseek_blockwise
Found by Valgrind. Similar fix already exists
for write_lseek_blockwise.
2025-06-04 14:07:24 +02:00
Milan Broz
f221de22b6 Fix libcryptsetup version. 2025-06-03 11:41:30 +02:00
Milan Broz
ff4aa8e5e7 Fix typo in Readme. 2025-06-03 10:17:28 +02:00
Milan Broz
efc6f847ee Update kernel.org links to use CDN. 2025-06-03 09:54:49 +02:00
Milan Broz
30ede1be36 Test version 2.8.0-rc0. 2025-06-03 09:21:07 +02:00
Josef Andersson
98323a93a8 po: update sv.po (from translationproject.org) 2025-06-03 09:06:31 +02:00
Yuri Kozlov
700047c84f po: update ru.po (from translationproject.org) 2025-06-03 09:06:31 +02:00
Ondrej Kozina
10ab6be262 Allow --reduce-device-size and --device-size in encrypt action.
Fixes: #822
2025-06-02 17:10:02 +02:00
Ondrej Kozina
ad30673dc5 Clarify structure assignement in tests.
Makes code more obvious.
2025-06-02 17:09:08 +02:00
Ondrej Kozina
773ac1ce55 Support encryption with reduced device size and data shift.
The only mising bit in library is a check if reduced data
size is smaller than real device size minus data shift.
2025-06-02 17:08:43 +02:00
Ondrej Kozina
ed50d30e7e Decouple data device size from reencryption operation data size.
Encryption with data shift and moved segment used to change
data size attribute later than necessary. Make it obvious in
upper layers.
2025-06-02 17:05:38 +02:00
Ondrej Kozina
5973694311 Correctly suffix device related variables.
We introduced _bytes and _sectors variables some time ago.
2025-06-02 17:05:03 +02:00
Milan Broz
b81c84bd8f Do not allow null cipher for LUKS2 keyslot even in conversion. 2025-06-02 13:58:33 +02:00
Milan Broz
8d7ee84006 tests: Silence repair warning on intentionally wiped image 2025-05-29 13:55:56 +02:00
Milan Broz
21e0680abf Disallow conversion to LUKS1 if capi string is specified.
While it works, it is a bug and we block it already in luksFormat.
2025-05-29 13:55:56 +02:00
Milan Broz
bd03054c38 tests: Add capi LUKS1 non-root test.
note: there should be much larger coverage of non-root operations.
2025-05-29 13:55:56 +02:00
Milan Broz
e136a0a40a Support capi format in crypt_storage wrapper.
Fixes: #944
2025-05-29 13:55:56 +02:00
Milan Broz
5b3ff3c0a7 Explicitly disallow capi format for LUKS2 keyslot encryption
NO functional change as it fails in IV check anyway, but the
code should not reach this funtion at all.
2025-05-29 13:55:56 +02:00
Milan Broz
c3414b8221 tests: detect failure of crypt_decode_key 2025-05-28 15:09:44 +02:00
Milan Broz
9f8667922c tests: Fix length of decoded key
As the following patch would detect a failure here.
2025-05-28 15:09:44 +02:00
Milan Broz
949c4ad0f1 tests: Fix typo in test key definition.
Code used a partially uninitialized key here.
2025-05-28 15:09:44 +02:00
Milan Broz
55c44cd3fd Fix warning for hidden global variable
The requirements_flags is a global array, do not
name a local variable the same (CodeQL fix).
2025-05-28 14:05:30 +02:00
Ondrej Kozina
ca7c4c8b15 test: Fix KeyslotContextAndKeyringLink test
The test was wrongly expecting results based on a mistake
in keyring utilities. The internal function extracting
volume key from kernel keyring was by mistake returning
-ENOENT (error code internaly used to signal the keyslot
context can not be used for unlocking key) even though
the kernel key was in fact unreachable and therefor
the volume key could not be read.

In short never expect device activation will pass
when one of passed keyslot contexts is invalid. The fact
that sometimes only one keyslot context is needed and
the invalid second context should not be needed is not
good practice.
2025-05-27 16:25:22 +02:00
Ondrej Kozina
a6c9c28208 Return -EINVAL if keyslot context can not access keyring key. 2025-05-27 16:24:27 +02:00
Ondrej Kozina
b6f43890f2 Add better errno hint in debug message. 2025-05-27 14:27:14 +02:00
Ondrej Kozina
c735c71ca1 keyring_find_key_id_by_name does not return negative values on error.
It returns 0 on error even if keyring support is compiled out.

There are valid negative constants for thread keyring, process keyring,
etc.
2025-05-27 14:27:14 +02:00
Ondrej Kozina
f3557f0765 find_key_by_type_and_desc must return 0 on error. 2025-05-27 14:27:14 +02:00
Milan Broz
5a2ca129b9 tests: Fix interactive query
In some situations (like under valgrind) test interactively asks
for confirmation, avoid it by using batch mode.
2025-05-27 13:43:20 +02:00
Milan Broz
5755f210ac doc: Do not wrap line for packages list and suggest netcat-openbsd for Debian.
The netcat package no longer exists in Debian.
2025-05-27 13:42:44 +02:00
Milan Broz
ccf7d6b197 tests: Do not use --key-size for --hw-opal-only format
This option is ignored and only produces warning
"OPAL hw-only encryption does not support --cipher and --key-size, options ignored."
2025-05-27 13:42:08 +02:00
Milan Broz
19d67d3c62 Fix integer and double types in keyslot checker.
To avoid theoretical overflows detected by Coverity.
2025-05-27 11:41:42 +02:00
Ondrej Kozina
cf630f578d Create underlying TCRYPT devices with CRYPT_SUBDEV prefix.
Create lower level TCRYPT device (underneath the toplevel one)
with CRYPT_SUBDEV prefix so that in later release we
can use general dependecies deactivation code.

The newly activated stacked TCRYPT devices will not correctly
deactivate with older pre 2.8.0 release.
2025-05-26 15:41:41 +02:00
Ondrej Kozina
12eb040943 Create dm-integrity with CRYPT_SUBDEV prefix.
When activating dm-integrity device underneath dm-crypt
with LUKS2 authenticated encryption mode, annotate the
device correctly with CRYPT_SUBDEV prefix. This will help
us to clearly identify dependent device underneath LUKS2 top
level device and we can unify the deactivation code in future
releases.

We have general code deactivating dependent devices already for
LUKS2 reencrytion.

Deactivating newly created devices with pre 2.8.0 cryptsetup
will issue warning about missing devices but the deactivation
will succeed.
2025-05-26 15:35:41 +02:00
Milan Broz
880bbfab4d Use free physical memory check for pbkdf only on small systems.
This hack tries to workaround situation when small VMs without swap
causes OOM. This hack will be removed one day completely...

Also remove confusing warning about possible crash.
With OpenSSL Argon2 backend this behaves much better, but it still
can cause OOM instead od returning ENOMEM.
Anyway, the warning message causes more problems that it solves.

Fixes: #896
2025-05-26 12:45:09 +02:00
Milan Broz
e6f6ee9291 Do not allow PBKDF benchmark over maximum allowed threads.
Unfortunatelly the benchmark function cannot return
corrected parallel cost, so it must fail.

Note that some backends (like OpenSSL) also limits maximal thread count,
so currently it was clapped at 4 for luksFormat and 8 for benchmark.

This patch set it all to PBKDF internal parallel limit.
2025-05-26 11:30:37 +02:00
Milan Broz
6b832b8d03 Add keyslot check code.
This patch adds keyslot randomness analysis to cryptsetup repair command
to check for a detectable corruption of binary area.

It uses Chi2 analysis. This check basically replaces external keyslot
checker program.
2025-05-22 16:09:50 +02:00
Milan Broz
f29337aa9f Define opaques crypt_device struct in local header. 2025-05-22 16:09:50 +02:00
Milan Broz
f5bbc499d4 Move LUKS_STRIPES definition to macros definitions.
To be used in repair code later.
2025-05-22 16:09:50 +02:00
Milan Broz
4fd3db5e93 Fix cryptsetup repair to use header device and UUID spec. 2025-05-22 16:09:50 +02:00
Milan Broz
cbf6fa9d07 Fix external slot checker to work with LUKS2. 2025-05-22 16:09:50 +02:00
Milan Broz
9e4a31887e ci: retry update for Ubuntu repos 2025-05-22 16:08:45 +02:00
Milan Broz
680567615a tests: add LUKS2 integrity tests 2025-05-22 14:53:27 +02:00
Milan Broz
24b126252b tests: add integritysetup inline tags tests 2025-05-22 14:53:21 +02:00
Milan Broz
324926e2d8 LUKS2: support Inline tags format and activation for integrity protection 2025-05-22 14:53:16 +02:00
Milan Broz
3ec14c8668 Move (and rename) UUID helpers to libdevmapper source. 2025-05-22 14:53:12 +02:00
Milan Broz
d967c9aaf0 Unify checking for LUKS2 intermediate device.
Use dm_get_active_iname that should be used on all places.

This function return integrioty device name if it shoudl be
maintained by LUKS2 context directly.

Code must not touch other devices that it does not own.
2025-05-22 14:53:03 +02:00
Milan Broz
352cda0302 integrity: Detect PI/DIF capable devices in inline mode.
And print better error if not.
2025-05-22 14:48:56 +02:00
Milan Broz
006ebd832f integrity: support Inline tags format and activation
Support inline format in API with crypt_format_inline().

Add --integrity-inline option to integritysetup.
2025-05-22 14:48:56 +02:00
Milan Broz
49ccafe38a integrity: Add inline flag to API
Process new dm-integrity flag (hw inline mode).
2025-05-22 14:48:56 +02:00
Milan Broz
29fcd88d86 integrity: Support superblock V6
This one include inline flag support.
2025-05-22 14:48:56 +02:00
Milan Broz
c4ce270568 Avoid false positive for static scan (integer overflow).
Avoid adding signed type to unsigned one.
2025-05-22 10:31:22 +02:00
Milan Broz
8440e59b7b Fix possible integer overflow (for unused variable). 2025-05-22 10:31:22 +02:00
Milan Broz
465043300d Check for unbound keyslot in convert.
The type cannot be converted to LUKS1 if there is an unbound keyslot.

It is already covered by digest count check, but in some specific
use cases the explicit check can catch a new problem.
2025-05-20 18:24:01 +02:00
Milan Broz
50b762ab94 Add note to man page for LUKS convert requirements. 2025-05-20 18:23:55 +02:00
Milan Broz
11dd8d318c Add debug messages for incompatible LUKS1 conversion.
If LUKS2 keyslot is not compatible, print debug message with more
specific info.

Fixes: #850
2025-05-20 18:23:48 +02:00
Milan Broz
e5c2892cd5 cryptsetup: Adjust XTS keys size also if cipher is specified with capi: prefix.
Fixes: #776
2025-05-20 16:58:14 +02:00
Ondrej Kozina
bd2f7eb671 Harden digest verification when adding new unbound key.
While adding new unbound key there is a check whether the
passed key parameter matches current volume key or not. If it
matches the existing volume key we handle the LUKS2 keyslot
addition as an ordinary LUKS2 keyslot (not unbound).

If the check failed we continued with the operation of adding
LUKS2 unbound keyslot. But we did not check if the error
was not a more general issue for example with in-memory metadata.

Let's contine with the operation only if the return code is
expected -EPERM (not matching digest) or -ENOENT (not matching any
existing unbound key).
2025-05-20 16:57:45 +02:00
Milan Broz
a39a0d00e5 Do not use pagesize as fallback for block size.
Device must process MAX_SECTOR_SIZE as it is encryption
block size, so if it does not work with this value, it will
fail anyway.

Fixes: #943
2025-05-20 16:44:06 +02:00
Milan Broz
9484eee48a Move wipe debug message and add alignment info. 2025-05-20 16:44:06 +02:00
Ondrej Kozina
5689fb46e7 Add error message for missing volume key.
Add specific error message when user does not provide
all necessary volume keys via --volume-key-file or
--volume-key-keyring parameters.
2025-05-20 15:29:14 +02:00
Ondrej Kozina
4d5aa29955 Add tests for reencryption by keyslot context in CLI. 2025-05-20 15:29:14 +02:00
Ondrej Kozina
ad21502d06 Extend options for initializing reencrypiton from cli.
This patch extends available options for LUKS2 reencryption
initialization.

When no specific keyslot is selected by --key-slot option, all active
keyslots needs to be refreshed. With current patch user does not
have to provide passphrase via interactive prompt when token is
available and can unlock assigned keyslot. Only keyslots not assigned
to tokens (and unlocked by tokens) must be provided with passphrase.

Furthermore user may directly narrow down selection of keyslots
suitable for reencryption by specifying either --token-id, --token-type
or --token-only option. In that case only keyslots associated to the
specific token (--token-id) or specific type (--token-type) or any token
specified in LUKS2 metadata (--token-only) will be used for
reencryption and refreshed with new volume key. All other keyslots will
not be refreshed and will be erased after reencryption is finished. The token
association will be carried over to refreshed keyslots.

The third new method available in this patch is support for reencryption
by passing volume keys directly. The LUKS2 device may be reencrypted
by passing volume keys by --volume-key-file, --new-volume-key-file,
--volume-key-keyring or --new-volume-key-keyring options. With this
options user may reencrypt device with no active keyslots. If there's
any active keyslot and volume keys are passed directly user may enforce
volume key based reencryption by passing --force-no-keyslots option.
If --force-no-keyslots option is passed all active keyslots will be
erased after reencryption operation is finished and the device may be
unlocked only by passing new volume key directly.

Fixes: #774, #780.
2025-05-20 15:29:14 +02:00
Ondrej Kozina
0dc630b911 Allow reencryption resume by new methods.
The reencryption operation can now be resumed
using tokens or by specifying volume keys
directly.
2025-05-20 15:29:14 +02:00
Ondrej Kozina
cbcb8c6ee3 Allow device in reencryption to be activated by volume keys in files.
Allow to use up to two --volume-key-file options (paired with
two --key-size options) for device in-reencryption activation.
2025-05-20 15:29:14 +02:00
Ondrej Kozina
5a84dc87e3 Return -ENOENT if digest is missing.
If there is no digest associated with segment,
for example during reencryption mode encrypt initialization,
return -ENOENT in LUKS2_digest_verify_by_segment.
2025-05-20 15:29:14 +02:00
Ondrej Kozina
1a7e89c55d Allow crypt_reencrypt_init_by_keyslot_contexts with no active keyslots.
With this commit reencryption can run without any active
keyslot containing current (or optional future) volume key.

In such case new volume key must be provided via CRYPT_KC_TYPE_KEY
keyslot context and by adding CRYPT_REENCRYPT_CREATE_NEW_DIGEST flag in
reencryption parameters during reencryption initialization in
crypt_reencrypt_init_by_keyslot_contexts.

The new flag can not be combined with CRYPT_REENCRYPT_RESUME_ONLY
flag.
2025-05-20 15:29:14 +02:00
Ondrej Kozina
804ee74a46 Reduce memory allocations in vk keyring keyslot context. 2025-05-20 15:29:14 +02:00
Ondrej Kozina
b497306934 Add method in keyslot_context to get stored key size.
Only applicable for CRYPT_KC_TYPE_KEY and
CRYPT_KC_TYPE_VK_KEYRING.
2025-05-20 15:29:14 +02:00
Ondrej Kozina
6c74b6f9c8 Update crypt_keyring_get_key_by_name debug message. 2025-05-20 15:29:14 +02:00
Ondrej Kozina
548de244c5 Add internal helper to get key size by key description. 2025-05-20 15:29:14 +02:00
Ondrej Kozina
0363ea7c57 Add utils keyring helper to get keyring key size by id. 2025-05-20 15:29:14 +02:00
Ondrej Kozina
ae2a7cfc33 Use crypt_get_old_volume_key_size in action reencrypt. 2025-05-20 15:21:44 +02:00
Ondrej Kozina
4e94c8d809 Add crypt_get_old_volume_key_size API.
It allows to get former (old) volume key size
from LUKS2 device in reencryption state when
there's at least one keyslot containing encrypted
volume key.
2025-05-20 15:21:44 +02:00
Milan Broz
3dcb532bd3 verity: Check hash device size in advance
Let's check block device size required for Merkle tree and superblock.
If it is a file, allocate the size in advance with fallocate.

This should print better error message if hash device is too small.

Fixes: #808
2025-05-20 14:59:09 +02:00
Milan Broz
02a48caf7e Print better error message for unsupported LUKS2 AEAD device resize.
Fixes: #804
2025-05-15 15:49:28 +02:00
Milan Broz
bc6c3092fa ci: call dnf clean all before install 2025-05-12 14:30:36 +02:00
Ondrej Kozina
0cf87a4151 Add support for --decrypt init by keyslot contexts. 2025-05-12 11:46:16 +02:00
Ondrej Kozina
cf29d51589 Refactor activation by volume key(s) in helper routine. 2025-05-12 11:46:16 +02:00
Ondrej Kozina
8fcd8a78d8 Make changes in token unlock for further changes in reencrypt action.
The token preference condition is moved outside the
try_token_unlock routine body.
2025-05-12 11:46:16 +02:00
Ondrej Kozina
5f48657f4d Move try_token_unlock to luks utils.
and rename it to luks_try_token_unlock.
2025-05-12 11:46:16 +02:00
Ondrej Kozina
4493d9ad3e Switch reencrypt --encrypt initialization to keyslot context.
This allows to simplify init_keyslot_context and we can only
pass single pointer from luksFormat routine.
2025-05-12 11:46:16 +02:00
Ondrej Kozina
9f0dd9cc4c Move init_keyslot_context in luks utils.
and rename it to luks_init_keyslot_context.
2025-05-12 11:46:16 +02:00
Ondrej Kozina
261bef3409 Fix mistake in reencryption change detection logic.
There's no reason to have bool variable for
key size change specifically.
2025-05-12 11:46:16 +02:00
Ondrej Kozina
ff7a21eb94 Refactor get_adjusted_key_size. 2025-05-12 11:46:16 +02:00
Ondrej Kozina
48683f7316 Fix memory leak on error path in luksAddKey. 2025-05-12 10:25:01 +02:00
Ondrej Kozina
e48d5b6d19 Verify volume key passed by kernel keyring.
Verify volume key passed by --volume-key-keyring before
trying to add new keyslot.
2025-05-12 10:25:01 +02:00
Ondrej Kozina
723ad6afdf Print error message in cryptetup cli.
Prints "Volume key does not match the volume" when
passed VK's digest does match the stored one.
2025-05-12 10:25:01 +02:00
Ondrej Kozina
79d8a8b840 Drop error message about mismatching volume key.
crypt_activate_by_keyslot_context() returns -EPERM
when key was passed either by CRYPT_KC_TYPE_KEY or
CRYPT_KC_TYPE_VK_KEYRING and does not match the digest
stored in metadata.

Sometimes caller might want to verify if the passed
keyslot contexts matches the effective volume key
or not without the error message. It can be
printed from command line tools when needed.
2025-05-12 10:25:01 +02:00
Milan Broz
5f8cab5d4a FAQ: add volume key example.
And remove requests for private mails.
2025-05-11 21:20:44 +02:00
Milan Broz
dd68e53082 ci: check FIPS mode without fips-mode-setup 2025-05-01 17:27:36 +02:00
Milan Broz
9153c9c3c0 Fix unused PIM query actions list. 2025-04-29 08:16:26 +02:00
Ondrej Kozina
c1b5e412c9 Drop unreachable error message.
LUKS2_reencrypt_status can not return CRYPT_REENCRYPT_INVALID.
2025-04-27 14:14:13 +02:00
Ondrej Kozina
fa84cb8a55 Fix LUKS2_config_get_requirements prototype.
It never returns any error. Make it void.
2025-04-27 14:14:13 +02:00
Milan Broz
221d6ac345 ci: disable rhel10-fips job
Someone decided to remove fips-mode-setup instead
of providing backward compatibility (and just set fips=1).

Upstream is not a RH testbed, remove this job.
2025-04-27 14:09:45 +02:00
Milan Broz
d2fc31da28 ci: update compiler versions 2025-04-27 11:21:30 +02:00
Milan Broz
8b14558b94 ci: Run lintian and codespell. 2025-04-27 11:21:30 +02:00
Milan Broz
e936d4395b Opal: limit PSID keyfile read if not set otherwise
PSID length is de-facto always 32 alphanumeric characters.

Limit the read of PSID from keyfile to this limit
(if not set by explicit size option).

This eliminates mistakes when the keyfile contains EOL characters.

Also, some OPAL drives accepts PSID with any suffix, this patch
unifies processing (it works everywhere the same).
2025-04-22 15:30:38 +02:00
Milan Broz
b166747fee ci: Run rawhide csmock.
Switch to rawhide version of csmock.
2025-03-25 22:54:16 +01:00
Milan Broz
3e114bcb1e Fix warning about NULL argument in setsockopt()
This should fix a warning produced by scan-build-20

warning: The 4th argument to 'setsockopt' is NULL but should
not be NULL [unix.StdCLibraryFunctions]
2025-03-24 13:46:59 +01:00
Milan Broz
1df9a4c566 Fix dirfd() handling.
Detected by scan-build-20.
2025-03-24 13:46:59 +01:00
Milan Broz
7f0724f46c Opal2: Do not use IOC_OPAL_ERASE_LR
The IOC_OPAL_ERASE_LR uses Erase method, that is defined only
in Single user mode (SUM) and works only on SUM-enabled LRs.

As we do not use SUM yet, this always fails.

Moreover, Erase has many side effects - it resets user password to ""
and disables locking for LR.

We already use fallback to IOC_OPAL_SECURE_ERASE_LR, which is GenKey
method (defined in Core spec) that must be always available.
It effectively regenerates the LR encryption key.
2025-03-24 12:34:43 +01:00
Milan Broz
c8420de4d6 tests: Disable csmock jobs
We have to switch to an open alternative, cmsock update no longer works.
Disable it for now.
2025-03-24 12:34:11 +01:00
Mingye Wang (Artoria2e5)
a0b4ae7e27 po: update zh_CN.po (from translationproject.org) 2025-03-23 14:42:57 +01:00
Мирослав Николић
4b39379c5b po: update sr.po (from translationproject.org) 2025-03-23 14:42:57 +01:00
Milan Broz
70f0938fff tests: disable broken OPAL HW
This NVMe is crashing kernel now.
2025-03-20 14:04:16 +01:00
Ondrej Kozina
fbb8d2e910 Revert "Add temporary workaround for broken kernels since 6.14-rc3."
This reverts commit b2da80909a.

The kernel 6.14-rc7 was already release including the proper fix.
2025-03-20 10:03:41 +01:00
Milan Broz
9e6fcefefc Remove redundant --verify-passphrase in man.
Fixes: #938
2025-03-09 20:23:12 +01:00
Vojtech Trefny
bf5d56d804 tests: Add a BITLK test image with two recovery passphrases
It is possible to add multiple recovery passphrases to a BitLocker
device so we should make sure we check both key slots when trying
to activate the device.
2025-03-09 11:23:48 +01:00
Ondrej Kozina
c1b7ad8979 Fix the debug message for too large json data during write. 2025-03-07 15:44:41 +01:00
Ondrej Kozina
fcf266667b Add validation tests for json area in non compact version.
The non compact json area may contiain whitespace characters
in between json object key and value (e.g.: {"key":   "the_value"}).

For LUKS2 write optimization we need to check and do regression testing
for the case where LUKS2 metadata would contain valid LUKS2 json area in
non compact format. The test is meant to verify if the write optimization
does not leave invalid characters beyond valid and properly terminated
LUKS2 json area.
2025-03-07 15:44:41 +01:00
Ondrej Kozina
cb0f568932 Optimize LUKS2 metadata writes.
LUKS2 supports several jsom area length configurations. With
the largest size supported in megabytes we do not want to write full
metadata area unconditionaly (current code) with every metadata
update. This might generate noticeble overhead with LUKS2
reencryption.

With this patch we write only the real used json area
length plus necessary padding to overwrite remaining previous
metadata stored on the disk.

During LUKS2 format and LUKS2 autorecovery we always overwrite
whole json metadata area no matter the used size.
2025-03-07 15:44:41 +01:00
Ondrej Kozina
000f03ad31 Switch to crypt_jobj_to_string_on_disk().
Use single function when we require json format
string representation for on disk format.
2025-03-07 15:44:41 +01:00
Ondrej Kozina
07e8628940 Add helper to unify json string format.
Add a single function to use when generating
json format string representation for on disk
storage purposes so that it can be easily
reused when needed.
2025-03-07 15:44:41 +01:00
Milan Broz
fdb179ea8b verity: Avoid false positive unititialized warning. 2025-03-07 14:43:57 +01:00
Ondrej Kozina
b91aee46c1 Use lower level code for droping signature from kernel keyring.
We do not need to used crypt_unlink_key_by_description_from_thread_keyring
since it also sets some additional parameters unrelated to dm-verity
signatures.

Also it's useless to search kernel key by description when
we have the key id.
2025-03-06 17:17:36 +01:00
Ondrej Kozina
eccccfd9b5 Fix drop of volume key from kernel keyring on crypt_suspend.
We do not have to query device-mapper subsystem
twice in order to get volume key description in kernel keyring.

Also there was a bug that wrongly used kernel key type set by function
supposed to set custom user key type used only when linking volume key
in arbitrary kernel keyring on caller demand.
2025-03-06 17:17:36 +01:00
Ondrej Kozina
2dc886053f Drop unused temporary volume key helpers. 2025-03-06 17:17:36 +01:00
Ondrej Kozina
0a6ee8633a Switch to volume key keyring helpers.
And do not access volume key internals bearing
information whether the key payload was uploaded
in kernel keyring or not.
2025-03-06 17:17:36 +01:00
Ondrej Kozina
15c4a410fd Add volume key helpers for manipulating kernel keys. 2025-03-06 17:17:36 +01:00
Ondrej Kozina
5615488196 Refactor and unify naming conventions for internal keyring helpers.
Functions related to uploading/unlinking volume keys in user
requested kernel keyrings are named as follows:

crypt_single_volume_key_load_in_custom_keyring
crypt_volume_key_load_in_custom_keyring
crypt_unlink_key_from_custom_keyring

helpers for unlinking LUKS2 volume keys from thread keyring:

crypt_unlink_key_from_thread_keyring
crypt_unlink_key_by_description_from_thread_keyring
2025-03-06 17:17:36 +01:00
Ondrej Kozina
c9edd942e8 Remove keyring_add_key_to_custom_keyring function.
The was identical function in keyring utilities already,
except the function name.
2025-03-06 17:17:36 +01:00
Milan Broz
d792de66d5 Fix typo in comment. 2025-03-06 17:16:25 +01:00
Vojtech Trefny
848f16bb5e man: Fix link for --allow-discards option explanation
--allow-discards is documented only in open and refresh man pages
not in luksFormat.
2025-03-06 17:15:41 +01:00
Vojtech Trefny
8573eb515d Fix docstring for crypt_persistent_flags_set
Add all persistent flags and use full name of the flags.
2025-03-06 17:14:11 +01:00
Ondrej Kozina
b2da80909a Add temporary workaround for broken kernels since 6.14-rc3.
The kernel 6.14-rc3 introduced regretion with 1f47ed294a2bd577d5a

The commit changed how errors are propagated and with it OPAL2 devices
no longer returns -EIO on IO to locker region.

Revert this patch after the kernel gets fixed.
2025-03-06 14:23:46 +01:00
Ondrej Kozina
db57571906 Test invalid --luks2-keyslots-size value.
The test was supposed to check if invalid --luks2-keyslots-size
metadata value will trigger failure.

The 128MiB was valid value and the test failed only due to smaller
test device size.

(In case of OPAL2 device it spanned into locked region.)
2025-03-06 14:23:22 +01:00
Milan Broz
93bc8997ea tests: Fix targets/kernel version detection
It is really not a good idea to check minor version without
checking major version is not lower first.

Also try to prepare for situation when major target versions
increases.
2025-02-19 13:50:24 +01:00
nl6720
52c63b5de1 Note the need to omit separator characters from the PSID 2025-02-19 12:42:27 +02:00
Milan Broz
dded9b3305 veritysetup: Support --error-as-corruption option.
The panic/restart_on_error options were introduces in kernel 6.12.

As it does not make sense to set these flags without
data corruption handling, only one option error-as-corruption
is implemented that must be used in combination with
panic/restart on corruption.
2025-02-16 20:53:35 +01:00
Milan Broz
41b8b02ccf verity: Add support for restart/panic on error flag.
Introduced in kernel 6.12.
2025-02-16 20:53:35 +01:00
Milan Broz
7ee0b02967 Make test libdevmapper flags 64bit. 2025-02-16 20:52:37 +01:00
Milan Broz
a3455befe7 Sync libdevmapper flags in tests. 2025-02-16 20:52:37 +01:00
Milan Broz
f07854ab4f Make libdevmapper internal flags 64bit. 2025-02-16 20:52:37 +01:00
Milan Broz
c497945ab3 Make internal dm_flags 64bit. 2025-02-16 20:52:37 +01:00
Ondrej Kozina
036ed52999 Remove volume key internals from internal API. 2025-02-16 18:00:20 +00:00
Ondrej Kozina
1bec71dbe1 Add temporary helpers to indicate uploaded volume key.
To be removed later when we add clear implementation
to hide access to volume key uploaded attribute.
2025-02-16 18:00:20 +00:00
Ondrej Kozina
9e0bcedbaa Harden LUKS2 volume key compare helper. 2025-02-16 18:00:20 +00:00
Milan Broz
6123ea2e0b Add strict compare volume key comparison for non-LUKS2 devices.
[Modified by Ondrej Kozina]
2025-02-16 18:00:20 +00:00
Ondrej Kozina
f421ec0800 Simplify volume key compare helper.
Since we can now identify volume key not containing
real key data we can make _compare_volume_key more
comprehensible.
2025-02-16 18:00:20 +00:00
Ondrej Kozina
843fac813f Indicate volume key with initialized key content.
volume key does not have to always contain properly
initialized key content (binary buffer). Add helper
to notify callers about it.
2025-02-16 18:00:20 +00:00
Ondrej Kozina
6ee76934fa Harden and limit access to volume key internals.
The volume key structure may often be in configuration
where 'key' member does not contain real data. Some
examples:

- volume key acquired by querring device-mapper where key
  was originaly passed by kernel keyring reference.

- volume key allocated by crypt_alloc_volume_key(size, NULL)

With this patch access to internal 'uninitialized' data result
in failed assert().

For use cases where key data are not needed (keyring reference wrapper,
key length info only) we do not have to allocate and lock the safe
buffer in memory.

Further improvements might to completely hide the volume key internals
and access only via setter and getter functions.
2025-02-16 18:00:20 +00:00
Ondrej Kozina
f86ab28ad6 Add crypt_safe_alloc_size helper.
Returns size of the payload. Zero means error.
2025-02-16 18:00:20 +00:00
Ondrej Kozina
54d937dfc7 Switch away from accessing volume key internals directly.
Switch current code to use following volume key helpers
for accessing internal properties:

crypt_volume_key_length(), crypt_volume_key_get_key(),
crypt_volume_key_description() and crypt_volume_key_kernel_key_type()

Remaining direct access to volume key internals will be dealt with in
later commits since it requires some further changes.
2025-02-16 18:00:20 +00:00
Ondrej Kozina
fd9be9e777 Add severeal helpers (get methods) for volume key.
crypt_volume_key_length() for key length
crypt_volume_key_get_key() to access key data (if initialized)
crypt_volume_key_description() for kernel key description
crypt_volume_key_kernel_key_type() for kernel keyring key type
2025-02-16 18:00:20 +00:00
Milan Broz
63f7dc739b fuzz: Better log from installation script
Print last commit from each git repo.
Also use master branch for zlib.
2025-02-15 14:57:19 +01:00
Milan Broz
a2b2c6a8ae Add workaround for memory sanitizer that cannot recognize explicit_bzero.
Otherwise it produces a lot of false positives in OSS-Fuzz.
2025-02-08 15:06:36 +01:00
Milan Broz
3899484be8 fuzz: Fix use of PWD variable.
The PWD variable is set by bash itself on every cd command,
rename it so it works as expected.
2025-02-08 15:06:33 +01:00
Ondrej Kozina
a965a88992 Add const to pointer in blob_serialize() function.
the data is read-only in this context.
2025-02-06 11:41:30 +01:00
Ondrej Kozina
88b3da6042 Use new crypt_generate_volume_key to generate weaker keys.
There were two different use cases for weaker keys:

1) empty keys (zero filled buffer)
2) weak 'random' keys not sucking entropy while being generated

Those key types must not be used to encrypt real data. It's used either
to check cipher can be configured sucessfully on the system or as
a fake envelope during metadata repair.
2025-02-06 11:41:26 +01:00
Ondrej Kozina
1326dfbac1 Add generic crypt_generate_volume_key function.
So that we can generate keys with different 'quality'
attribute at one place.
2025-02-06 11:37:04 +01:00
Ondrej Kozina
4f90213a5b Drop redundant member initialization in volume key.
The memory is already initialized to zeroes after allocation.
2025-02-06 11:30:18 +01:00
Ondrej Kozina
5ee549de1e Remove volume_key struct from fvault2 code.
No volume_key feature is used in the code and it
will make further changes easier.
2025-02-06 11:30:18 +01:00
Ondrej Kozina
e9073e6b19 Add keyring key type in volume key comparison function. 2025-02-06 11:30:18 +01:00
Ondrej Kozina
dc75deff51 Drop bogus usage of vk->uploaded.
The volume key uploaded attribute is respected only with
regard to volume keys uploaded in the thread keyring in logon key type.

Here the uploaded attribute was set for volume keys uploaded in
custom user keyrings in custome key descriptions.
2025-02-06 11:21:42 +01:00
Ondrej Kozina
ab9d4fec3b Do not parse emtpy '-' key string with null ciphers.
The loop is not entered but for later patche lets make
it obvious it is not needed.
2025-02-06 11:21:42 +01:00
Ondrej Kozina
da84c79a5b Use crypt_volume_key_next helper in bitlk. 2025-02-06 11:21:42 +01:00
Ondrej Kozina
a321068e8d Add compile_commands.json file to .gitignore.
The file is used to describe project compilation independent
of build system in use.

It can also help LSP servers to improve code suggestions since
it can see how the project is configured and respect, for example,
content of config.h file.
2025-02-04 16:13:08 +01:00
Milan Broz
e257def910 Remove redundant check for dm-integrity mapping table params section.
The dm-integrity table always contains number of feature arguments
(since introduction in kernel 4.12).

Moreover, the code already dereferences params field, so the test
make no sense.

Found by CodeQL check.
2025-01-28 13:03:10 +00:00
Milan Broz
c9008528f9 tests: Remove function xx() bashism.
Posix does not use function keyword, moreover, we use it inconsistently.
2025-01-27 20:43:33 +01:00
Milan Broz
3d535dcf31 tests: Add trap for segfault and sigabrt
If bash test script uses a pattern that test that command should fail
  command && fail
(IOW fail function is called only if command exited successfully),
it can mask potential segfault, as it return non-zero exit code.

Fix it by using trap for scripts that uses this pattern.

The same applies for SIGABRT (abort() call).
2025-01-27 20:42:25 +01:00
Milan Broz
a45fb0a90d Do not include dlfcn.h if external token support is disabled.
Fixes: #925
2025-01-27 12:33:52 +00:00
Milan Broz
06c0f03c9f Add a note regarding use of #if for config.h processing. 2025-01-27 11:05:08 +00:00
Milan Broz
c6a7849090 Use #if for password quality libs defines. 2025-01-27 11:05:08 +00:00
Milan Broz
29741d91e6 Use #if in bitops.h. 2025-01-27 11:05:08 +00:00
Milan Broz
1e441bf75c Use #if for rest of defines. 2025-01-27 11:05:08 +00:00
Milan Broz
d9404821a6 Use #if for HAVE_BLKID_* defines. 2025-01-27 11:05:08 +00:00
Milan Broz
e5405f2fd8 Use #if for HAVE*_H defines. 2025-01-27 11:05:08 +00:00
Milan Broz
37d52876b9 Use #if for other ENABLE* options. 2025-01-27 11:05:08 +00:00
Milan Broz
ff81791308 Use #if for ENABLE_AF_ALG. 2025-01-27 11:05:08 +00:00
Milan Broz
c21c746eff Use #if for USE_UDEV. 2025-01-27 11:05:08 +00:00
Milan Broz
bb304f45bd Use #if for KERNEL_KEYRING. 2025-01-27 11:05:08 +00:00
Milan Broz
f64f6fb9e8 opal: Fix error table offset
The error table was partially wrong (for codes >0x0b)

Let's use exact enum codes according to TCG Core spec (5.1.5).

This also fixes CodeQL warning.
2025-01-27 11:04:25 +00:00
Milan Broz
5c795885c5 opal: update copyright 2025-01-27 11:04:25 +00:00
Milan Broz
6a8f88ea99 Fix leaks detected by Coverity. 2025-01-27 09:11:40 +00:00
Milan Broz
7ffa8ee28a Fix integer cast for sector_size.
Found by Coverity scan.
2025-01-27 09:11:40 +00:00
Milan Broz
2691514547 Print message about reaching maximal interactive passphrase to error output.
Reaching maximal keyfile size is already reported as error.

Note that interactive really means user entering password.

For all other us there is keyfile processing.

Related: #933
2025-01-26 10:10:27 +01:00
Milan Broz
36574dd114 Avoid if (not NULL) free().
This fixes some COdeQL warnings.
2025-01-16 15:54:09 +01:00
Milan Broz
8364178b38 Update copyright year. 2025-01-15 23:09:36 +01:00
Milan Broz
2a880f838a ci: Update and fix GitHub actions 2025-01-15 17:07:18 +01:00
Milan Broz
e6208a12b5 ci: Update CodeQL GitHub CI config 2025-01-15 15:06:06 +01:00
Milan Broz
b54e5ce9f0 ci: Fix GitHub CI build 2025-01-15 15:03:10 +01:00
Milan Broz
bfae421c52 bitlk: Clarify activation error message if clear key is present.
Fixes: #929
2025-01-15 13:35:29 +01:00
Milan Broz
33ebb36f71 tests: check for xxd binary in validation test 2024-12-23 22:07:09 +01:00
Gabi Falk
64fb1c1b26 tests/compat-test: Adjust test for compatibility with passwdqc
Unlike libpwquality, passwdqc does not consider 'compatkey' a strong
password and rejects 512 character long passwords.

Closes: https://gitlab.com/cryptsetup/cryptsetup/-/issues/928
Signed-off-by: Gabi Falk <gabifalk@gmx.com>
2024-12-22 16:00:00 +00:00
Milan Broz
b18cefcc71 Detect out of memory in KDF in keyslot derivation.
For OpenSSL and gcrypt we can detect that Argon2 failed on malloc,
report it to user (and return ENOMEM instead of EINVAL).
2024-12-12 22:45:21 +00:00
Milan Broz
7cabaa5d70 pbkdf: Do not allow memory cost that cannot be used in size_t
For 32bit platforms size_t is 32bit integer and unfortunately
our maximum hard limit overflows by 1.

Stop validation if this happens (it cannot be passed to malloc()
and similar functions anyway).

There should be no compatibility change, as such memory
is not allocatable on 32bit anyway.
Other platforms have 64bit size_t.
2024-12-12 22:45:21 +00:00
Milan Broz
b201a62987 Add a note about OPAL PSID sensitivity to manual pages. 2024-12-12 22:44:35 +00:00
Milan Broz
f8788f347e Mark all sizes in status and dump output in the correct units.
NOTE: This is possibly an incompatible change as it changes text output.

Since the support of --sector-size option, the description "sectors"
became ambiguous as it usually means 512-byte sectors (device-mapper unit).

Major confusion occurs when the sector size is 4096 bytes while units display
is in 512-bytes.

Unfortunately, there is no clear compatible way, so this patch adds
[512-byte units] marker and also additional byte size value.

All other fields that display units are changed to use the "[units]" format.

The integrity format is also unified with the common style with ':' as a separator.

Fixes: #884.
2024-12-12 15:56:00 +00:00
Milan Broz
ea39aecba3 Add integrity key tests. 2024-12-03 20:28:07 +01:00
Milan Broz
5eda5f6a38 Fix compatibility for older dmcrypt without integrity_key_size
For older kernel an default HMAC key size we must not set
integrity_key_size option.
2024-12-03 20:28:00 +01:00
Milan Broz
b5672053f5 Use real integrity key size in format operation.
For now, we used zeroed key for dm-integrity format, as there was not
data area. In future, there can be wrapped key scheme, that will require
to setup real key even in this situation.

This patch modifies the integrity format flow that the real key is used
during format.

Mostly based on code from Ingo Franzki <ifranzki@linux.ibm.com>
2024-12-03 20:27:16 +01:00
Milan Broz
491f31c4d4 Add --integrity-key-size option to cryptsetup.
This patch adds support for --integrity-key-size option that can be used
to setup non-standard HMAC integrity key size.
2024-12-03 20:25:54 +01:00
Milan Broz
7b5ac650e5 Allow specific integrity key size.
This patch add support for setting of integrity key size
for LUKS2 devices.

It adds new (optional) JSON "key_size" attribute in segment.integrity JSON object.
If not set, the code use hash length size (backward compatible).

For LUKS2, we do not allow smaller keys than 128 bits.

Mostly based on code from Ingo Franzki <ifranzki@linux.ibm.com>
2024-12-03 20:25:54 +01:00
Milan Broz
ff3e2c6a43 libdevmapper: Support dm-crypt integrity_key_size option
This patch implement support for setting specific integrity key size
option in dm-crypt, available since dm-crypt version 1.28.0.

This can be used for setting non-standard HMAC key length.

Mostly based on code from Ingo Franzki <ifranzki@linux.ibm.com>
2024-12-03 20:25:54 +01:00
Ondrej Kozina
1bea029cef Lock volume key structure in memory.
This was probably oversight in original commit
introducing support for selective memory locking
on sensitive data only.

Fixes: db65a5ceac
2024-12-03 13:33:59 +01:00
Milan Broz
ecb1326e0e CI: Disable annocheck run.
It is currently broken.
2024-11-29 10:18:45 +01:00
Milan Broz
690c22ac7b Switch isLUKS() testing order to avoid static analysis scan confusion.
There is no functional change in this patch except it avoids
strange confusion during some static tests.

The cd->type must be set in this function anyway.
2024-11-28 10:41:18 +01:00
Ondrej Kozina
9f1aee46d5 Rename 'keyring' member to 'keyring_key_type' in volume_key.
The keyring field is misleading since the
field indeed contains the type identification
id.
2024-11-27 12:24:59 +01:00
Milan Broz
82bee1c52d test: Skip trusted test if keyctl cannot load user key.
Some very old systems do not support -x option for keyctl,
skip the test in this case.
2024-11-26 12:20:00 +01:00
Milan Broz
0805cc025d test: Run keyring trusted/encrypted test in CI.
And install dependencies unconditionally.
2024-11-25 14:56:00 +01:00
Milan Broz
9d03e5987c Add trusted/encrypted keyring test (for plain format). 2024-11-25 14:55:55 +01:00
Milan Broz
768bca1df5 Support plain resize with keyring key. 2024-11-25 14:55:51 +01:00
Milan Broz
4b7920975c Support trusted & encrypted keyring for plain device. 2024-11-25 14:55:47 +01:00
Milan Broz
42e85571df Move keyring utilities to separate file. 2024-11-25 14:55:43 +01:00
Milan Broz
ae4b4ff4d7 Unlink only volume keys that were previously stored in keyring.
This is only preparation for an extension later, however, the volume
keys should not be unloaded unconditionally from keyring.

Note that all other places dropping keys already check that keys
were uploaded through key ID setting.
(And for suspend unconditional unlink make sense too.)
2024-11-25 13:20:36 +01:00
Milan Broz
9575dadc8b Store keyring type in volume key.
The key_decripion always contains only a key name,
keyring then contains type of keyring as defned un keyring utils.

For now, only LOGON type is used in commands, it will be extended later.
2024-11-25 13:19:42 +01:00
Milan Broz
6be70a0157 Do not include luks2/luks2_internal.h ouside of LUKS2 internal implementation.
The luks2_internal.h contains specific JSON implementations while
luks2.h is generic. Code outside of luks2/ dir should not use internals.

Also luks2.h includes functions prototypes that are used from setup.c.
2024-11-23 20:52:24 +01:00
Milan Broz
3acac6f8fc Print warning if some options were ignored for OPAL hw-only encryption.
As OPAL without sw encryption bupesses dm-crypt, many activation
options are ignored. Print at least message for user here.

Fixes: #920
2024-11-23 20:52:22 +01:00
Milan Broz
609277d957 Add a comment about wiping derived key in benchmark.
Fixes: #916
2024-11-23 20:52:19 +01:00
Ondrej Kozina
fb021bac3d Fix token assignement API.
There was a bug in both crypt_token_assign_keyslot and
crypt_token_unsassign_keyslot where CRYPT_ANY_TOKEN
special value could be passed in token parameter.

It would correctly assign/unassign all tokens to/from
the specified keyslot (or from any in case of CRYPT_ANY_SLOT),
but it returned -1 (CRYPT_ANY_TOKEN) which fited error return
values as per API documentation.

We fixed that by not supporting CRYPT_ANY_TOKEN since it does
not make much sense. It can be workarounded by iterating over
all available tokens and calling crypt_token_assign_keyslot or
crypt_token_unassign_keyslot accodingly.

Fixes: #914.
2024-11-15 15:24:14 +01:00
Milan Broz
c3972372b1 argon2: Avoid unitialized warning in cppcheck
Thsi patch avoids this cppcheck warning:

Error: CPPCHECK_WARNING (CWE-457): [#def1]
cryptsetup-main/lib/crypto_backend/argon2/blake2/blake2b.c:369: warning[uninitvar]: Uninitialized variable: out_buffer

It is a false positive, but wiping buffer is cheap a and similar approach is used
in other Argon2 implementations (OpenSSL).
2024-11-08 19:51:14 +00:00
Milan Broz
46289f92ff argon2: Avoid cppcheck integer oveflow warning
This patch avoid warning in constant-time base64 function:

Error: CPPCHECK_WARNING (CWE-190): [#def2]
cryptsetup-main/lib/crypto_backend/argon2/encoding.c:86: error[integerOverflow]: Signed integer overflow for expression ''0'-52'.

The (x + ('0' - 52)) can be rewritten to (x - (52 - '0')) with the same effect.
Similar solution used in https://github.com/pornin/CTTK/blob/master/src/base64.c
2024-11-08 19:51:14 +00:00
Ondrej Kozina
3c5aa4ef59 Remove unused code.
Due to complete shift to device activation via keyslot context,
remove all remaining internal code activating device by passphrase
or by token.
2024-11-08 15:46:28 +01:00
Ondrej Kozina
5e950924c3 Clarify unbound key parameter in verification routine. 2024-11-08 15:46:09 +01:00
Ondrej Kozina
76d66d6a01 Better name internal activation function. 2024-11-08 15:46:09 +01:00
Ondrej Kozina
ccbc53c169 Do not repeat volume keys upload in custom kernel keyring.
It is uploaded before call in to activation code.
2024-11-08 15:46:09 +01:00
Ondrej Kozina
61aaeaff5a On error drop crypt_key from kernel keyring. 2024-11-08 15:46:09 +01:00
Ondrej Kozina
dd3441621a Fix reencryption keys loading in kernel keyring.
Manage keys upload in kernel keyring (internal logon type for dm-crypt
segments) in single location in-before device activation.
2024-11-08 15:46:09 +01:00
Ondrej Kozina
d7512d738f Force reencryption keys verification after metadata reload.
After switching to reencryption by keyslot context,
the digest was not properly verified before crash recovery.
We need to reverify reencryption digest after metadata
reloads unconditionally.
2024-11-08 15:46:07 +01:00
Ondrej Kozina
6506d324ee Better name routine verifying any available digest.
also drop unused parameter from internal routine.
2024-11-08 14:09:08 +01:00
Ondrej Kozina
a93921c226 Avoid dereferencing NULL pointer. 2024-11-04 12:24:27 +01:00
Ondrej Kozina
f5b7a576b3 Do not dereference the context pointer before assert. 2024-11-04 12:24:20 +01:00
Milan Broz
c0449fc24e Revert "Do not call safe erase on benchmark data."
This reverts commit 17f0261024.

The password can be set by user through expeorted API, we should
not keep traces of derived key from a real password.
2024-11-01 12:59:25 +01:00
Ondrej Kozina
17f0261024 Do not call safe erase on benchmark data.
In both pbkdf2 and argon2* benchmark key variable
is pointer to benchmark data and does not need to be erased
safely as regular key data would need to.
2024-11-01 10:27:24 +01:00
Ondrej Kozina
6daefa8222 api-test: Use minimal key size 14 bytes (112 bits).
As per SP800-132 minimal key length is 112 bits. Use it
while testing unbound keys stored in LUKS2 keyslots.
Otherwise the test fails in FIPS mode.
2024-10-31 17:26:38 +00:00
Milan Broz
33ed0d587e Fix typos found by lintian. 2024-10-30 19:11:29 +01:00
Ondrej Kozina
f85c31677c Simplify bitlk activation by volume key.
Let's not copy volume key again when not necessary.
2024-10-30 16:13:49 +01:00
Ondrej Kozina
5b83ae8ec2 Enable fvault activation by keyslot context. 2024-10-30 13:28:56 +00:00
Ondrej Kozina
7db83f8fb3 Simplify fvault activation by volume key. 2024-10-30 13:28:56 +00:00
Ondrej Kozina
652835a1f8 Verify fvault2 key size in before activation by volume key. 2024-10-30 13:28:56 +00:00
Ondrej Kozina
00b89c4862 Export expected fvault2 volume key size. 2024-10-30 13:28:56 +00:00
Ondrej Kozina
305aa376b6 Add crypt_reencrypt_init_by_keyslot_context API test. 2024-10-30 13:25:57 +01:00
Ondrej Kozina
651a089f38 Add crypt_reencrypt_init_by_keyslot_context.
It allows initializing reencryption operation by
providing access to volume keys via keyslot context.
2024-10-30 13:25:57 +01:00
Ondrej Kozina
45af8de034 Allow shared activation of device in reencryption.
This would be regression when we later switch all internal
implementation to keyslot context.
2024-10-30 13:25:57 +01:00
Ondrej Kozina
0eccd6e194 Check also CRYPT_ANY_SLOT in LUKS2_keyslot_for_segment.
The function did not work properly if keyslot parameter
was set to CRYPT_ANY_SLOT and returned always error.

But it will be used later when we need to find if there's
at least one keyslot asigned to a specific segment.
2024-10-30 13:25:55 +01:00
Ondrej Kozina
4de453d6a5 Retain original error code when reading data from keyring.
If key description is not available we expect -ENOENT.
-EINVAL usually aborts all following effort to unlock
device/keyslot.
2024-10-29 13:26:35 +01:00
Milan Broz
66c1523163 ci: Make unreleased RHEL distro build optional. 2024-10-26 10:51:43 +02:00
Milan Broz
5f066777a1 ci: Print output for RHEL packages install. 2024-10-26 10:38:34 +02:00
Michal Privoznik
fb04611ff7 crypto_backend.h: Wrap APIs in extern C
It's a good practice to mark public APIs as extern "C" so that
projects written in C++ can use our library.

[mbroz] It is not public API in cryptsetup, but we use this backend
in other projects, this aligns the code changes.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2024-10-18 20:40:50 +02:00
Ondrej Kozina
b7cf60f229 Add regression test for decryption with datashift.
Test if decryption works when default segment
is assigned to volume key with digest id set
to non zero value.
2024-10-11 15:06:48 +02:00
Ondrej Kozina
81d8c12cbe Fix LUKS2 decryption when volume key digest id not zero.
During the initialization phase future moved data segments
were incorrectly assigned (hardcoded) to digest with id 0.

When the default segment was assigned to a different value,
the initialization failed and was aborted.

This patch fixes the issue by assigning intermediary segments
to corect digest id.

Reported-by: 谢致邦 (XIE Zhibang) <Yeking@Red54.com>
2024-10-11 14:55:08 +02:00
Ondrej Kozina
e19030915b Unify integer format parameter in prompt.
There was only single occurence of the prompt
message with %u. Let's use %d as anywhere else.
2024-10-09 11:15:56 +00:00
Ondrej Kozina
e4bf1f91b9 Properly block opal devices from deferred deactivation.
The check did not work properly for stacked dm_crypt over
hw opal devices.

Also it did not work at all for active dm mappings with
missing (or detached) LUKS2 metadata.
2024-10-09 09:57:49 +00:00
Ondrej Kozina
7c83d4e639 Simplify internal crypt_get_hdr for LUKS2 type. 2024-10-09 08:04:19 +00:00
Yiyuan Zhong
939b7c0a9e Mbed-TLS: implement PBKDF2
PBKDF2 has been implemented since 2.0.0 and a new API was introduced in 3.3.0
deprecating the old one. This implementation will use the new API if detected.
2024-10-08 20:21:21 +00:00
Milan Broz
443a555559 integrity: print debug message if superblock metadata read fails. 2024-10-08 12:22:46 +00:00
Milan Broz
79ef5bee86 Do not run direct-io read check on block devices.
Block devices must support direct-io. This check causes more problems
than it solves - for Opal locked device it disables direct-io
and we can later possible read wrong data (if kernel does not flush
cache).
2024-10-08 12:22:46 +00:00
Milan Broz
cd818156f6 Do not print debug message if device read check fails.
It really should not print "direct-io works" when it just failed :)
2024-10-08 12:22:46 +00:00
Milan Broz
faeb0c3483 Fix a possible segfault in deferred deactivation.
For device without a type code shoud not try to use
strcmp function.

This can happen for example if deferref flag is used
for device without proper DM-UUID where init_by_name
does not set know device type.

Thanks Clément Guérin for the report.

Fixes: #910
2024-10-08 13:08:18 +02:00
Milan Broz
d35fb1e671 ci: run vectors test when compiling crypto backends.
This should cost only few seconds but will verify
basic crypto backend operations as we do not run full testsuite
with all backends.
2024-10-04 21:57:09 +02:00
Ondrej Kozina
8ad28547ee Simplify keyslot context initialization code. 2024-09-29 19:14:56 +00:00
Jan Zerebecki
3c00305156 add warning to order luksChangeKey and reencrypt 2024-09-29 19:13:02 +00:00
Ondrej Kozina
31bf986084 Adapt cryptsetup to self-contained keyslot contexts. 2024-09-29 16:10:44 +00:00
Ondrej Kozina
6ef0650332 Rename internal keyslot context functions. 2024-09-29 16:10:44 +00:00
Ondrej Kozina
9311c923ca Make all keyslot context types fully self-contained.
Duplicate all dynamically allocated memory passed
keyslot context during initialization and make it
self contained.

Before current patch all pointers passed in keyslot
context initialization routines have to remain valid
for the duration of the keyslot context. Otherwise
memory violation could occur.

This patch fixes the issue in backward compatible
way so that we do not have to change API for all
keyslot contexts. As of now all dynamically allocated
memory can be freed right after keyslot context
initialization.
2024-09-29 16:10:44 +00:00
Eric Biggers
209e6167b5 Exclude cipher allocation time from benchmark
For each 1 MiB of data en/decrypted, 'cryptsetup benchmark' is setting
up a new AF_ALG socket, which involves 4 system calls and is included in
the data en/decryption time.  With high-speed ciphers (e.g. VAES
optimized AES-XTS) this can measure well over 10000 AF_ALG socket setups
per second.  This is not representative of dm-crypt, which only
allocates a cipher when the dm-crypt device is created.

Therefore, allocate the AF_ALG socket once, before doing the benchmark.

On AMD Ryzen 9 9950X this increases the 'cryptsetup benchmark' result of
AES-256-XTS slightly, from 14000 MiB/s to 14600 MiB/s.

Note that an in-kernel benchmark of the crypto API with the same block
size (65536 bytes) gives 34100 MiB/s, so AF_ALG still takes more time
than the en/decryption itself -- this cannot easily be addressed though.

Signed-off-by: Eric Biggers <ebiggers@google.com>
2024-09-17 10:31:10 -07:00
Milan Broz
b5f7176af1 CI: Install scsi_debug and other kernel modules for Ubuntu CI. 2024-09-12 10:20:21 +00:00
Ondrej Kozina
c0bf271bef Add crypt_safe_memcpy in reencrypt digest routine.
We copy volume keys for purpose of calculating LUKS2
reencryption digest. Add crypt_safe_memcpy in serialization
function as well.
2024-09-12 11:08:16 +02:00
Ondrej Kozina
41c72eaa65 Fix a bug in keyring keyslot context.
It always returned zero upon successful keyslot unlock
instead expected unlocked keyslot id.
2024-09-12 08:07:23 +00:00
Milan Broz
e48c74b77f Update Readme.md. 2024-09-03 11:54:48 +02:00
Milan Broz
46b8275ad9 Add 2.7.5 release notes. 2024-09-02 15:38:59 +02:00
Milan Broz
beef8e325a Fix clang undefined version error for ssh token
We use common libcryptsetup-token.sym version script that contain
all symbols, but some of them are optional.

As clang linker treats missing symbols as errors, the linker
phase for ssh token fails as optional cryptsetup_token_buffer_free
is not defined.
(Most of distros has this option still disabled, though).

As the sym file is also example for token authors, removing symbols
there is not an option. For clang, we can use --undefined-version option,
but it is not supported by other linkers, so it requires non-trivial
checks for usable LDFLAGS (for both autoconf and meson).

Instead, fix it by simply defining the symbol in ssh token, which
duplicates the internal libcryptsetup functionality.

Fixes: #830
2024-09-01 00:38:57 +02:00
Ondrej Kozina
63bb997b41 Abort online reencryption for misconfigured devices.
Hard abort is justified here. The online reencryption on
data devices that do not support O_DIRECT io flag is
dangerous and leads to data corruption. This should be
impossible to hit due to a patch that handles it
in initialization phase. Better safe than sorry.
2024-08-27 14:00:41 +00:00
Ondrej Kozina
9991cbc306 Harden online reencryption checks in initialization phase.
Verify the data device supports O_DIRECT io flag in
the initialization phase. Online reencryption is not
safe unless we can read and write the data in direct
mode.
2024-08-27 14:00:41 +00:00
Milan Broz
4cdd022ba4 Fix detection of direct-io with suspended devices.
Currently, direct-io is disabled if underlying device is suspended.

This was an unfortunate change, as it is part of data corruption
problem in online reenryption.

Let's relax the test to assume that suspended device
(suspended =>  must be a device-mapper device) supports direct-io.

The read test is still needed as some network based devices
misbehaves if opened with direct-io flag.
2024-08-27 12:13:54 +02:00
Ondrej Kozina
e4d25d18eb Remove needless double statements. 2024-08-26 17:40:04 +00:00
Milan Broz
3d89faca18 Fix return code for ssize_t.
The ssize_t must be defined in the range [-1, SSIZE_MAX].

The return value is overwritten to -EINVAL later anyway,
return -1 here to be on the safe side.

Fixes: #900
2024-08-26 16:39:10 +00:00
Ondrej Kozina
a42bd088b5 Add Ubuntu 24.04 runner. 2024-08-22 14:06:21 +00:00
Ondrej Kozina
aeada055d1 Return suspended status also for unknow target types.
This patch allows dm_status_suspended() to report if device
is suspended or not also for unknown target types from
libcryptsetup perspective (e.g.: dm-cache).
2024-08-22 13:53:23 +02:00
Ondrej Kozina
53198bdea9 Do not handle device as suspended on error.
Consider device is suspended only if dm_status_suspended return code
is true.

This function returned -EEXIST for dm devices with target types unknown
to libcryptsetup (for example dm-cache) and turned off O_DIRECT flag
for devices unexpectedly.

Turned out ignoring direct-io was a problem after all :).

Fixes: 0f51b5bacb (Do not run sector read check on suspended device.)
2024-08-22 13:42:13 +02:00
Milan Broz
da09835b6c Document reencryption process status callbak return code. 2024-08-13 09:14:00 +02:00
Vojtech Trefny
42f4a68705 Initialize crypto in crypt_format_luks2_opal
Without this random isn't initialized and crypt_format_luks2_opal
is aborted.
2024-08-07 10:28:17 +00:00
Milan Broz
d5fb76a3b4 CI: Fix backend test after change in previous commit
The same CFLAGS change need to be applied to backend test.
2024-08-04 12:29:02 +02:00
Daniel Zatovic
7c992fa09e CI: update Ubuntu container image and set compiler version 2024-07-31 14:07:13 +02:00
Milan Broz
35bf791e85 Version 2.7.4. 2024-07-30 14:14:22 +02:00
Milan Broz
0d4027291a Add Release notes for stable 2.7.4 version. 2024-07-30 12:38:28 +02:00
Milan Broz
e0852d21dd tests: workaround valgrind SIGPIPE
Parsing --debug output with quiet flag can produce SIGPIPE output
if running with valgrind wrapper, just workaround it with another
grep as used elsewhere.
2024-07-30 10:34:41 +02:00
Milan Broz
3a7794795f Always set cipher_mode even in crypt_parse_name_and_mode.
Othewrwise some tools like valgrind can see unitialized string.
2024-07-29 16:00:01 +02:00
Frédéric Marchal
8be7b01ba8 po: update fr.po (from translationproject.org) 2024-07-24 12:29:27 +02:00
Antonio Ceballos
2bcdb5127a po: update es.po (from translationproject.org) 2024-07-24 12:29:26 +02:00
Ondrej Kozina
002f73b360 Add --shared option in veritysetup open action.
The option allows data device to be used in multiple
DM table mappings and exclusive access is not checked
anymore in-before device activation.

It also allows correct concurrent verity device activation.
With --shared option if multiple processes compete for same DM
verity name using same underlying data device we can now guarantee
one process succeeds and all other fails with -EEXIST.
2024-07-24 09:39:21 +00:00
Ondrej Kozina
ec9b97a731 Fix shared activation for dm-verity devices.
CRYPT_ACTIVATE_SHARED flag was silently ignored
while activating dm-verity devices by libcryptsetup.
This was a bug.

DM verity shared activation is generaly safe (single mapped data device
in multiple DM verity tables) since all verity devices are
read only.

The CRYPT_ACTIVATE_SHARED flag also fixes a race condition
when multiple processes compete for the same DM device name
(all dm-verity) while using same backing data device.

The exclusive open check in-before verity activation could
fail DM table load for a process that otherwise successfully acquired
DM device name (succeed in creating the DM device). This could (in some
cases) result in all processes competening for the DM verity device
to fail and none would activate the DM verity device.
2024-07-24 09:39:21 +00:00
Milan Broz
5873a65183 Do not use O_EXCL for allocated backing loop device.
Exclusive flag is defined only when creating a file,
for opening existing file it is undefinded operation.

Remove it from crypt_loop_attach as it was wrong since
the initial commit.
2024-07-24 08:28:32 +00:00
Milan Broz
d88a97b1a0 libdevmapper: properly detect device busy failure for dm table devices
Due to internal retry-overengineering in libdevmapper, some dm-ioctl
failures can disappear. One such case is when there is a device
creation race and DM device is created but reload fails.
this can heppen because some block device used in table mapping is
already claimed (it needs exclusive access for bdev_open in kernel).

The kernel ioctl properly returns EBUSY, this errno is lost
in libdevmapper (dm_task_get_errno returns 0).

While this should be solved by libdevampper, we need some reliable
way on older systems to properly report "busy" error instead of
overloaded "invalid" error.

With modified reproducer (see check_concurrent in very compat test),
this situation can happen quite often.

This patch modifies dm_create_device to return ENODEV only if
dm-ioctl also reports no device (ENXIO); following dm status reports ENODEV
and also some referenced device is no longer accesible through stat().

In all other cases we return EBUSY. Command line translates EBUSY and EEXIST
to the same return vaules, for API users it now returns EBUSY instead
of generic EINVAL.

IOW, if device activation returns EEXIST or EBUSY, device-mapper
cannot create the device because it already exits (EEXIST) or some referenced
device is claimed by other subystem (EBUSY) and mapping table cannot be created.
2024-07-23 11:15:06 +00:00
Milan Broz
3dc5d50918 fuzz: Fix build as upstream xz repo has disabled cloning 2024-07-23 08:41:53 +02:00
Milan Broz
021e5c31fd Check for bad device-mapper name early
There is no need to unlock keyslot if the provided name
has wrong format. Let's check for length and '/' in name early.

Note that other commands could accept path to the device
as libdevmapper translate it to the name (status /dev/mapper/xxx).
Add early check only to activate commands.

It still can fail later because of mangled characters.

Fixes: #893
2024-07-16 08:05:13 +00:00
Milan Broz
624b7087b0 ci: fix backends job logic 2024-07-15 14:44:31 +02:00
Yiyuan Zhong
cb7b7fd863 Add Mbed-TLS crypto backend
Mbed-TLS is a tiny TLS implementation designed for embedded environment which
can greatly reduce the disk space requirement compared to OpenSSL. While we
already have crypto_kernel for this purpose and Mbed-TLS lacking hash/cipher
support can cause reduced functionality, there're situations where AF_ALG is
not available but we're fine with limited scenarios like LUKS2 only.
2024-07-14 17:12:03 +08:00
Milan Broz
4daf8ef0dc tests: skip reencryption test if non-AES ciphers fails in luksFormat 2024-07-12 21:08:05 +02:00
Milan Broz
2d041439bc tests: Print N/A visible in mode_test (LUKS2 userspace crypto) 2024-07-12 21:07:59 +02:00
Milan Broz
7fa19da140 tests: use crypto check tool in tests 2024-07-12 21:07:15 +02:00
Milan Broz
a9617c7c4a tests: Add crypto check program for crypto backend.
We use benchmark, but backend can implement different
set of ciphers than kernel crypto API.
2024-07-12 21:04:37 +02:00
Milan Broz
ce38d82025 Fix crypt_cipher_check_kernel to work with length-preserving modes too.
The check is currently used only with AEAD, but whould work also
with common block ciphers and modes.
2024-07-12 18:02:37 +00:00
Milan Broz
5e04a82e53 Fix wiping of hash struct in nss and nettle backend. 2024-07-12 16:38:56 +00:00
Milan Broz
3839e2bf98 Fix scan-build warnings in gcrypt backend 2024-07-12 16:38:56 +00:00
Milan Broz
8accd612a3 CI: Add fanalyzer and scan-build test for crypto backends 2024-07-12 16:38:56 +00:00
Frank Rehberger
fddec0f2d7 doc: build dependency update 2024-07-12 16:05:52 +00:00
Milan Broz
7a816abf82 TCRYPT: fix system encryption test if kernel does not support EFI partition
If kernel is mising CONFIG_EFI_PARTITION, the required partitons
are missing too.
Just skip the test if loop block device is not available.
2024-07-12 11:58:06 +00:00
Milan Broz
94f37efb57 Remove obsolete AC_PROG_GCC_TRADITIONAL macro.
As it causes warnings and does nothing for many years already.
2024-07-10 10:32:27 +02:00
Milan Broz
5fb6d711c1 Fix clang possible rh NULL dereference warning. 2024-07-10 09:48:10 +02:00
Milan Broz
b0be186f9e Fix leaked fd gcc analyzer warning.
These are actually false positives (fd 0 is always open as stdin),
but code is even more readable with this fix.
2024-07-10 09:48:08 +02:00
Milan Broz
b1cc660df3 Do not use assert() that depends on external data.
Just fail function. Also fixed gcc analyzer warning (leaked fd).
2024-07-10 09:48:05 +02:00
Milan Broz
35a9f08062 Fix warning about unitialized passwordLen.
THis is false positive, but fix is trivial.
2024-07-10 09:48:02 +02:00
Milan Broz
9c47812904 Use buffer functions and fix potential fd leak.
Use read/write buffer functions to avoid partial operation.

This also fixed leaked fd warning. Also fix error path
for context failure - if initialize_context() fails,
rc->log_fd is closed in context destructor, no need to close
it in open_log/parse_log.

Another fixed bug is in parse_log, where immediatelly after
creation we have to seek to the beginning of the file first.
2024-07-10 09:47:59 +02:00
Milan Broz
8b21b4b2ee Fix "allocated buffer size is not a multiple of the pointee's size" warning
No need to play games with void pointers, two separate functions are
much more readable.
2024-07-10 09:47:56 +02:00
Milan Broz
bf088de00f Update CI shared runner compiler versions. 2024-07-10 09:43:33 +02:00
Milan Broz
1423c6eac2 TCRYPT: make algorithms definitions static 2024-07-02 13:04:30 +00:00
Milan Broz
e5b430cdc1 TCRYPT: use bool instead of one bit integer 2024-07-02 13:04:30 +00:00
Milan Broz
a5e409c186 TCRYPT: update system encryption images and test. 2024-07-02 13:04:30 +00:00
Milan Broz
0cc686af59 TCRYPT: Clear mapping of system encrypted partitions.
TrueCrypt/VeraCrypt supports full system encryption (only a partition
table is not encrypted) or system partition encryption
(only a system partition is encrypted).
The metadata header then contains the offset and size of the encrypted area.
Cryptsetup needs to know the specific partition offset to calculate encryption parameters.
To properly map a partition, you must specify a real partition device so cryptsetup can calculate this offset.

As user can specify various combination, we need to determine the proper
IV and data offsets.

The logic for CRYPT_TCRYPT_SYSTEM_HEADER flag should be (in this order):
- if data device is a real partition, calculate offset from it.
- if --header is a real partition , calculate offset from it.
- if device is a real disk, try to search for partition using decrypted offset and size
(works only for system partition-only encryption).
- if data and metadata (header) device is the same, map whole encrypted area
(this is the ost confusing for user)
- if data and metadata (header) divice differs, expect data image contains
only partition (setting offset to 0, but using IV offset from header).

There are still situation that can end with wrong mapping, but user now has the option
to setup it properly.

Also this patch fixes use of stored encryption size in header,
so we do not map larger area.

Fixes:#889
2024-07-02 13:04:30 +00:00
Milan Broz
14fd0b5fc1 TCRYPT: Print all information from decrypted header.
Print also volume sizes (if present) and flags.
This inforamtion is useful mainly for setting systemd encryption
where size determines encrypted region.
2024-07-02 13:04:30 +00:00
Ondrej Kozina
9651d1f376 Fix a typo in valgrind test parameter. 2024-07-02 13:03:01 +00:00
Milan Broz
98b4243432 Add support for high-priority dm-crypt flag.
This patch add new --perf-high_priority cryptsetup option
for flga added in Linux kernel 6.10, dm-crypt target version 1.26.
2024-06-18 11:00:38 +00:00
Milan Broz
e32ea56b59 Update README for version 2.7.3. 2024-06-17 14:39:42 +02:00
Milan Broz
afee503e34 Add CONTRIBUTING.md file. 2024-06-17 11:52:56 +00:00
Milan Broz
7019f42ff1 Add release notes for 2.7.3. 2024-06-12 17:20:56 +02:00
Yuri Chornoivan
647b24f706 po: update uk.po (from translationproject.org) 2024-06-11 12:31:53 +02:00
Remus-Gabriel Chelu
0cff233af1 po: update ro.po (from translationproject.org) 2024-06-11 12:31:53 +02:00
Jakub Bogusz
8cb3b32070 po: update pl.po (from translationproject.org) 2024-06-11 12:31:53 +02:00
Hiroshi Takekawa
8109b10ea4 po: update ja.po (from translationproject.org) 2024-06-11 12:31:53 +02:00
Roland Illig
d9660cf221 po: update de.po (from translationproject.org) 2024-06-11 12:31:53 +02:00
Petr Pisar
29f1f71c67 po: update cs.po (from translationproject.org) 2024-06-11 12:31:53 +02:00
Daniel Zatovic
1d9a362113 CI: don't run parallel OPAL jobs 2024-06-07 13:56:46 +02:00
Daniel Zatovic
e92763a61c CI: run fips-mode-setup --check as a root 2024-06-07 13:52:50 +02:00
Daniel Zatovic
9bdb7fee34 CI: add RHEL10 runner 2024-06-07 12:21:32 +02:00
Milan Broz
51c672ea62 tests: Fix test numbers in compat-test2 again 2024-06-06 17:24:51 +00:00
Milan Broz
b19170e8fe Fix warning for printf argument. 2024-06-06 13:09:23 +02:00
Ondrej Kozina
97c5f47c94 Add opal test for detached header erase command. 2024-06-05 11:02:38 +02:00
Ondrej Kozina
494c510c34 Simplify LUKS2_wipe_header_areas.
For LUKS2 headers with non zero data offset LUKS2_wipe_header_areas
will always erase the smallest from following:

- metadata device size
- data offset value
- maximal LUKS2 metadata size (twice 2 MiBs json area including 128 MiB for
binary keyslot areas) even with detached header.

For zero value data offset (LUKS2 header can not be restored back to
data device), we erase up to smallest from the following values:

- metadata device size
- maximal LUKS2 metadata size (twice 2 MiBs json area including 128 MiB for
2024-06-05 10:49:08 +02:00
Milan Broz
2a13ef5dd8 Fix interactive query retry if LUKS2 unbound keyslot is present
If an unbound keyslot is present (e.g.. slot 0 usual slot, slot 1 unbound),
the query loop could return ENOENT (keyslot not valid for segment) and this
will stop epxected retry for slot quewry (--tries option).

If any previous slot rerutned EPERM (no valid passphrase), prefer
this return code.
2024-06-03 16:40:55 +00:00
Milan Broz
4708884d8c Allow "capi:" cipher format for benchmark command.
Note, currently AEAD modes are not supported.
2024-06-03 16:40:01 +00:00
Milan Broz
8f4a149ed3 Fix bad parsing of capi:xts(aes)-plain
Corrent logic confuses it with aes-plain (capi:xts(aes)-plain
does not work in luksFormat).
For CAPI format we need to skip this test.
2024-06-03 16:40:01 +00:00
Milan Broz
d590c74a0e Support aes-hctr2 mode.
The HCTR2 encryption was added to Linux kernel for fscrypt,
but as it is length-preserving mode (with sector tweak) it
can be easily used for disk encryption too.

As it need larger IV of size 32 bytes, we need to add exception
for aes-hctr2[-plain64] to be accepted in cryptsetup commands.

Fixes: #883
2024-06-03 16:39:06 +00:00
Milan Broz
1a6a611dff Reorganize license files.
This patch adds README.licensing describing used licenses.
The license text files are now in dosc/licenses.

The main COPYING document in root is the default license,
this also forces GitHub to properly identify default license.
2024-06-03 16:38:15 +00:00
Milan Broz
661f57def4 Use SPDX license identifiers.
This patch switches code to SPDX one-line license identifiers according to
https://spdx.dev/learn/handling-license-info/
and replacing long license text headers.

I used C++ format on the first line in style
// SPDX-License-Identifier: <id>
except exported libcryptsetup.h, when only C comments are used.

The only additional changes are:
- switch backend utf8.c from LGPL2+ to LGPL2.1+ (as in systemd)
- add some additional formatting lines.
2024-06-03 16:38:15 +00:00
Milan Broz
8448448aa2 Opal: Check for bogus logical size also in activation
For existing devices we only print warning, but the device is
probably completely misconfigured.
2024-06-03 11:14:27 +00:00
Milan Broz
329fa3c54e Opal: Require locking range attributes in range check function.
The check will be required mandatory in the next patch.
2024-06-03 11:14:27 +00:00
Milan Broz
1eb3df45dd Opal: Do not allow format if device and Opal logical block size disagrees
Some Opal devices contain a bug that device reports different logical
size for block device and Opal SED layer.

This can happen for NVMe after reformatting with different LBAF (512/4096).

We will not support such configuration as Opal then calculates sizes
differently for locking range (that could lead to data corruption or
a partially unecrypted area).
2024-06-03 11:14:27 +00:00
Daniel Zatovic
af99b9b9d9 CI: Add Samsung 980 PRO OPAL test on trantor machine 2024-05-30 16:30:01 +02:00
Milan Broz
6859993ea7 Fix string.h, strings.h and stdio.h include in crypto backend.
String.h and stdbool.h are already included in main backend header,
no need to include them again.

Stdio.h is missing for OpenSSL and NSS backed (for sprintf).

Strings.h is missing for cipher_generic, gcrypt and OpoenSSL (strcasecmp).

Fixes: #885
2024-05-23 06:29:47 +00:00
Milan Broz
bd8cfe1efb Mention need for possible PSID reset for some OPAL drives in man page.
Fixes: #879
2024-05-23 06:29:20 +00:00
Milan Broz
c2c1d59ff2 bitlk: Ignore TPM key metadata
Using TPM entry on Linux is impossible, as we will never have
the same PCRs, so we can quietly ignore these entries without
warnings.
2024-05-21 11:27:14 +02:00
Milan Broz
dca99f7dc1 bitlk: Ignore unknown VMK entry 24
This VMK value looks like a password hint (masked email?)
we can safely ignore it.

Fixes: #886
2024-05-21 11:25:06 +02:00
Milan Broz
9b822800b3 tests: Use only PBKDF2 in api-test-2 images (FIPS with OpenSSL 3.2+)
For compatimage2 also add keyslot 1 that uses Argon2id PBKDF2 to keep
check for compatibility on non-fips system.
2024-05-13 10:22:02 +00:00
Milan Broz
0d6d4e4255 tests: Use only PBKDF2 in luks2_keyslot_unassigned.img (FIPS with OpenSSL 3.2+) 2024-05-13 10:22:02 +00:00
Milan Broz
a8e5bb0ebe tests: Fix redundant test number in compat-test2 2024-05-13 10:22:02 +00:00
Milan Broz
aa69fc342a tests: Skip zoned test if kernel does not support it
Zoned block device support can be disabled (as in RHEL8),
skip particular test if scsi_Debug does not create device.
(Modprobe does not return any error code, just kernel message
as parameter is actually supported, but block layer lack
support for zoned device.)
2024-05-13 10:22:02 +00:00
Milan Broz
d0678c208d tests: Remove leftover debug parameter. 2024-05-13 10:22:02 +00:00
Milan Broz
c21ccd89e3 Add tests for --key-description and --new-key-description. 2024-05-10 10:56:20 +02:00
Milan Broz
0f20e14c67 Rename TOKEN to KEY_DESC to be used in different context later. 2024-05-10 10:55:03 +02:00
Milan Broz
1e58ad570e Add --key-description and --new-key-description for luksAddKey command. 2024-05-10 10:54:59 +02:00
Milan Broz
73975857a3 Add --key-description for luksResume command. 2024-05-10 10:54:55 +02:00
Milan Broz
3c79fd6c4b Add --key-description for open command. 2024-05-10 10:54:50 +02:00
Milan Broz
82118bdd5f Add --key-description for resize command. 2024-05-10 10:54:47 +02:00
Milan Broz
3e01e151f8 Add --key-description for luksFormat command. 2024-05-10 10:54:43 +02:00
Milan Broz
e085ae461f Add --key-description for luksDump command. 2024-05-10 10:54:37 +02:00
Milan Broz
4a40d79322 Fix --key-description actions and define --new-key-description. 2024-05-10 10:54:32 +02:00
Daniel Zatovic
ea32731e5b CI: make OPAL tests run at the end
Once OPAL tests run, the whole pipeline gets marked as uninterruptible
(because of the uninterruptible OPAL job). Therefore a duplicate
pipeline gets started on e.g. MR change. Move OPAL jobs to test-opal
stage which runs at the end.
2024-05-07 14:32:41 +00:00
Ondrej Kozina
42a073c0cb Use crypt_wipe to zero rest of data device. 2024-05-07 12:30:05 +00:00
Ondrej Kozina
738b9ee645 Use proper write_buffer in LUKS1 reencryption code.
The raw write() syscal may write less bytes than requested. We
have write_buffer in utils_io.c that handles it properly.
2024-05-07 12:30:05 +00:00
Ondrej Kozina
94ef8a7610 Use proper read_buffer function from utils.
Legacy LUKS1 reencryption used custom read buffer
function. Use implementation from utils_io instead.
2024-05-07 12:30:05 +00:00
Milan Broz
410a586284 Detect unsupported zoned devices for LUKS header device.
Zoned device cannot be written with direct-io
and cannot be used for LUKS header logic without
significant changes. Do not allow to use them for LUKS header
but allow it for data device, as dm-crypt supports it.

Fixes: #877
2024-05-03 14:03:47 +00:00
Milan Broz
40e5c7d095 Use crypt_safe_memcpy for operations with key. 2024-05-03 11:52:09 +00:00
Milan Broz
4322ddbcb3 Add crypt_safe_memcpy to libcryptsetup.h. 2024-05-03 11:52:09 +00:00
Milan Broz
7b3a341809 Use crypt_backend_memcpy in crypt backend for sensitive data. 2024-05-03 11:52:09 +00:00
Milan Broz
40e56e969c Use backend memory utils in safe memory functions. 2024-05-03 11:52:09 +00:00
Milan Broz
c5d4b845df Use zero_call_used_regs and noinline for backend memory utils and introduce crypt_backend_memcpy. 2024-05-03 11:52:09 +00:00
Milan Broz
aae5cba2b9 Add memutils.c for backend and move existing mem helpers there.
Also remove inline definitions.
2024-05-03 11:52:09 +00:00
Ondrej Kozina
bede116926 Fix various coverity issues.
Mostly INTEGER_OVERFLOW (CWE-190).
2024-05-03 11:58:35 +02:00
Milan Broz
33e26be58b Avoid divide by zero in uint64_mult_overflow.
This function is used with block size, where 0 does
not make sense, so failing the check is the simple way
to avoid sividion by zero.

In reality, this should never happen, but it was seen
in (unreproducible) fuzzing input.
2024-04-18 08:39:52 +02:00
Milan Broz
842d9e6e6e Update README for version 2.7.2. 2024-04-09 12:12:56 +02:00
Milan Broz
bc62204a41 Add warning about OPAL admin PIN to man page and release notes. 2024-04-09 10:46:13 +02:00
Milan Broz
4bd64eed82 Add 2.7.2 release notes. 2024-04-04 18:34:49 +00:00
Milan Broz
4b0ae54379 tests: print OPAL device parameters in test envirenment if specified 2024-04-04 18:34:19 +00:00
Daniel Zatovic
69920581a3 CI: add WD PC SN740 OPAL drive job 2024-04-04 14:49:27 +02:00
Antonio Ceballos
4bf6db5ce8 po: update es.po (from translationproject.org) 2024-04-04 14:08:50 +02:00
Ondrej Kozina
a89485924c Compile --disable-hw-opal variant. 2024-04-03 16:26:02 +00:00
Ondrej Kozina
0cbeb35a93 Do not check passphrase quality in-before erase.
The passphrase (Admin PIN) already exists and there's no
reason to check quiality of it.
2024-04-03 11:51:35 +00:00
Milan Broz
e17ec37341 Relicense older script to LGPL fro GPL2.0 only.
(As I am sole author here.)
2024-04-03 11:49:33 +00:00
Milan Broz
1ba758cde1 FAQ: update license version to CC BY-SA 4.0.
With email approval from Arno Wagner dated March 29, 2024:

 From: Arno Wagner
 To: Milan Broz
 Subject: Re: cryuptsetup FAQ license

  Hi Milan,

  fine for me. You can change it directly.

  Arno

  On Wed, Mar 27, 2024 at 13:38:36 CET, Milan Broz wrote:
  > Hi Arno,
  >
  > the FAQ in cryptsetup is licensed under CC-BY-SA-3.0 that is no longer a recent version - https://creativecommons.org/licenses/by-sa/3.0/
  >
  > I use CC-BY-SA-4.0 (https://creativecommons.org/licenses/by-sa/4.0/deed.en) for LUKS2 docs and think it is the best option for docs.
  >
  > Do you agree with updating the license to CC-BY-SA-4.0 for the FAQ.md file? (I, as coauthor, obviously agree :-)
  >
  > Thanks,
  > Milan
2024-04-03 11:49:33 +00:00
Ondrej Kozina
87bf39f71e Fix invalid assert for hw-opal data segment keys.
hw-opal segment does not receive volume key for data
encryption, unlike crypt segment or hw-opal-crypt segment.
It gets key encryption key that is passed to device fw which
later unlocks the locking range key sealed in the device.

The assert may be skipped while volume key is not set.

Fixes: #875.
2024-04-03 11:48:56 +00:00
Ondrej Kozina
1ae70b8c16 Fix data segment length compensation on misaligned partitions.
While properly calculated data segment needed compensation due to
misaligned partition (locking range had to be truncated),
we passed wrong value (original partition size) to LUKS2 metadata.

It has to use calculated locking range length in bytes.

Fixes: #873.
2024-04-02 14:21:01 +02:00
Daniel Zatovic
3d82771418 CI: make OPAL jobs uninterruptible 2024-03-26 16:09:22 +01:00
Ondrej Kozina
3e29dbe6f2 Add --hw-opal-factory-reset switch in erase options explicitly. 2024-03-26 12:01:27 +00:00
Ondrej Kozina
a462dbeb4e Check HW OPAL range parameters in proper units.
The opal_range_check_attributes_fd function expected both
offset and length parameters of a LR to be passed in sectors (512B).
During format we passed it wrongly in OPAL blocks which caused
bogus check provided OPAL block size was not 512B.

Fixes: #871.
2024-03-26 11:55:31 +01:00
Daniel Zatovic
8655093cb7 tests: run systemd tests using meson only when requested 2024-03-21 16:42:06 +01:00
Milan Broz
25b543d371 Update Readme for 2.7.1. 2024-03-07 15:53:23 +01:00
Milan Broz
6b3f9cd4bc tests: Fix Makefile * Meson to include all fs images. 2024-03-07 15:32:17 +01:00
Milan Broz
608e42c574 Update LUKS2 spec. 2024-03-07 15:26:54 +01:00
Milan Broz
143a76a5fa Add 2.7.1 release notes. 2024-03-07 15:23:15 +01:00
Milan Broz
9906bc40e1 test: Fix tests on RHEL7 clones (no keyring in dm-crypt). 2024-03-07 13:18:05 +00:00
Milan Broz
dc669a14d3 Add xfs V5 image to tests.
XFS V4 can be disabled in kernel, add image V5.

Minimal 300M xfs size avoided by using QA variables magic in format:
export TEST_DIR=1 TEST_DEV=1 QA_CHECK_FS=1 ; mkfs -t xfs ...
2024-03-07 11:30:21 +00:00
Ondrej Kozina
8819194281 tests: fix compat-test-opal bug for empty LUKS2 passphrase.
The bug was hidden due to previously contradicting condition.
2024-03-06 14:23:02 +01:00
Ondrej Kozina
5d6fbf7b53 tests: move luks1 decryption resume test.
It cannot be run in fips mode due to empty passphrase
is no longer allowed.
2024-03-06 13:10:34 +01:00
Ondrej Kozina
4347a01cce tests: fix fips mode detection contradiction in various tests. 2024-03-06 13:08:50 +01:00
Yuri Chornoivan
6525b40a7b po: update uk.po (from translationproject.org) 2024-03-06 09:51:20 +01:00
Remus-Gabriel Chelu
31573693a0 po: update ro.po (from translationproject.org) 2024-03-06 09:51:20 +01:00
Jakub Bogusz
accc9c0ee9 po: update pl.po (from translationproject.org) 2024-03-06 09:51:20 +01:00
Hiroshi Takekawa
5ec40f98ac po: update ja.po (from translationproject.org) 2024-03-06 09:51:20 +01:00
Frédéric Marchal
5eb9c8b27a po: update fr.po (from translationproject.org) 2024-03-06 09:51:20 +01:00
Roland Illig
eccd46206d po: update de.po (from translationproject.org) 2024-03-06 09:51:20 +01:00
Petr Pisar
8d6fc937da po: update cs.po (from translationproject.org) 2024-03-06 09:51:20 +01:00
Milan Broz
41755b71b6 Set devel version. 2024-03-06 09:51:10 +01:00
Ondrej Kozina
201a4b7d8b Add regression test for resuming LUKS1 decryption. 2024-03-05 14:58:02 +01:00
Ondrej Kozina
33b9a51fa8 Fix regression in LUKS1 decryption.
With removal of cryptsetup-reencrypt there was
a bug introduced that broke resuming interrupted
LUKS1 decryption operation. LUKS2 code was not
affected.
2024-03-05 14:58:02 +01:00
Milan Broz
9d38ea70e2 Require --debug log in bug report issue template. 2024-02-29 17:07:41 +00:00
Milan Broz
2cd0be9501 Allow all stable branches in GitHub actions. 2024-02-29 17:07:41 +00:00
Ondrej Kozina
5a0208cd06 Allow --link-vk-to-keyring with --test-passphrase option.
To make it possible to upload volume key in user specified kernel
keyring without need to (re)activate the device.
2024-02-29 16:25:17 +01:00
Ondrej Kozina
db635c428b Fix abort triggered by initializing decryption via --active-name.
The invalid test unfortunately hid an error in processing
of --active-name command line option.
2024-02-28 17:11:46 +01:00
Milan Broz
678b28989b Fix indentation in integritysetup man page and crypt description. 2024-02-22 20:58:35 +00:00
Milan Broz
82f37d7a10 Sort options in man pages alphabetically. 2024-02-22 20:58:35 +00:00
Milan Broz
cbf818a660 Fix JSON exampe in progress-frequency option. 2024-02-22 20:58:35 +00:00
Milan Broz
3ff8d55a8b Fix veritysetup man page typo. 2024-02-22 20:58:35 +00:00
Sergei Ilinykh
349572e69e Fix compilation with libargon2 argon when internal disabled
This fixes a regression introduced somewhere on the way to 2.7.0.
A specific set of options led to complete lack of Argon2
regardless of --enable-libargon2 option.
2024-02-22 20:43:35 +03:00
Daniel Zatovic
0725efefa7 CI: fix improper distro specification for 32-bit Debian.
The `variables` section is repeated for 32-bit Debian job. Therefore the
`DISTRO` environment variable is ignored and 64-bit distro name is
inherited from the `.debian-prep` job.
2024-02-22 16:50:46 +01:00
Daniel Zatovic
af35c93332 CI: don't store kernel log, only check for coredumps.
The kernel log is uploaded automatically by the custom executor, no need
to upload it from inside the VM (and /mnt/artifacts is not mounted in
the new CI scripts).
2024-02-22 11:41:37 +00:00
Daniel Zatovic
193f8ff595 CI: increase disk size for csmock job. 2024-02-22 11:41:37 +00:00
Daniel Zatovic
f91524dc63 CI: add OPAL jobs. 2024-02-22 11:41:37 +00:00
Daniel Zatovic
f8e79cdbe6 CI: update jobs for new CI infrastrucure 2024-02-22 11:41:37 +00:00
Ondrej Kozina
35cd898c63 Fix crypto vectors test in meson.
Otherwise it gets skipped in meson everytime.
2024-02-21 15:56:14 +01:00
Tobias Rosenkranz
91c1d2202a Skip test if keyctl is missing 2024-02-18 14:46:37 +01:00
Milan Broz
a6d9dc0a16 Do not require argon2.h if implemented natively in crypto library. 2024-02-13 12:38:00 +01:00
Ondrej Kozina
f681194b57 Fix mistake in crypt_set_keyring_to_link documentation.
The keyring_to_link_vk parameter must be prefixed by
either "%:" or "%keyring:" substrings provided caller
opted for text description of the target keyring.
2024-02-13 11:40:13 +01:00
Ondrej Kozina
fdac0d7ee2 cryptsetup.spec: drop libargon2 in favour of openssl implementation. 2024-02-12 10:43:47 +00:00
Milan Broz
b417154e71 Fix configure Argon2 OpenSSL detection to not compile internal Argon2.
Code is not called anyway, but should be completely disabled.
Note: there is intentionally no way to disable OpenSSL Argon2 if present.
2024-02-09 12:51:34 +01:00
Milan Broz
4dde8f078f Version 2.7.0. 2024-01-24 10:47:32 +01:00
Milan Broz
f11af15cd0 Fix local variable name that hides global one.
Found by CodeQL.
2024-01-23 20:22:11 +01:00
Milan Broz
bd0ef58b3a Update copyright notice to include 2024 year. 2024-01-23 16:10:44 +01:00
Ondrej Kozina
cbc7253400 Unify error code for missing key description.
Use -ESRCH for similar error code as with
crypt_activate_by_keyslot_context. Here it's not
confliciting with previous use for the very code but
let's make it easier and use same code for similar case.
2024-01-23 12:08:43 +01:00
Ondrej Kozina
35ec935cc2 Update API documentation for crypt_set_keyring_to_link.
The section about placeholder API no longer applies.
2024-01-23 12:03:39 +01:00
Ondrej Kozina
7eca077490 Replace code for missing key error in API.
While trying to activate device in LUKS2 reencryption
we originally used -ENOKEY error code for case
where one or more volume keys could not be unlocked or
were not provided direclty by (CRYPT_KC_TYPE_KEY or
CRYPT_KC_TYPE_VK_KEYRING) keyslot contexts.

We missed the fact the error code was already previously
used for signaling case when dm subsystem could not load
device table due to key in kernel keyring could not be
read from kernel. It's propagated by libdevmapper.

For it we replace -ENOKEY with -ESRCH for signaling the missing
keyslot context or volume key for devices in LUKS2 reencryption.
2024-01-23 11:55:12 +01:00
Ondrej Kozina
8dd3266599 tests: use per-test keyring for caching VKs. 2024-01-22 17:28:19 +01:00
Ondrej Kozina
135ed491d1 Do not drop keys from keyring on successfull reencryption recovery.
The key might be needed in activation of ordinary LUKS2 device
provided the recovery took place in before device activation
and actually finished LUKS2 device reencryption.

Fixes: #863.
2024-01-22 12:13:40 +01:00
Milan Broz
de1cd97fde Fix typo in verity test. 2024-01-20 19:01:25 +01:00
Milan Broz
f040f74f46 Fix autoconf valgrind test.
All environment variables are predefined in make run,
use it in $(VAR) from, as shell variables processing does not work here.
2024-01-20 10:56:22 +01:00
Daniel Zatovic
136ba21c65 Add tests for device activation using multiple VKs. 2024-01-19 16:26:30 +00:00
Daniel Zatovic
7fb98caa79 Allow activating multi key devices using VKs in keyring.
We already support activation of a device using a volume key in keyring.
However, in case of multi-key devices (i.e. device with reencryption
running) we need to supply two volume keys.
2024-01-19 16:26:30 +00:00
Daniel Zatovic
4321992561 Add tests for storing VK in keyring during resume. 2024-01-19 16:26:30 +00:00
Daniel Zatovic
f354a0b038 Add tests for storing multiple VKs in a custom keyring. 2024-01-19 16:26:30 +00:00
Daniel Zatovic
5814b39cdd Allow linking multiple VKs (also in reencryption).
If the device is in reencryption, it has two active volume keys. Linking
the VK to keyring is not supported for such devices, because the API
only counts with one key. This commit modifies the API
crypt_set_keyring_to_link to allow passing multiple keyring key names.
2024-01-19 16:26:30 +00:00
Milan Broz
e0eb4dad95 Fix tests to support --disable-keyring option.
Also remove unused function in test.
2024-01-19 13:40:25 +00:00
Antonio Ceballos
0ba3e3077c po: update es.po (from translationproject.org) 2024-01-19 12:59:50 +01:00
Petr Pisar
dfe241dc24 po: update cs.po (from translationproject.org) 2024-01-19 12:59:50 +01:00
Milan Broz
001f228059 LUKS2: add more sanity assignments to header code.
Ensure we do not return partial binary header and also
explicitly set header size to zero to silnce stupid
cppcheck warnings.
2024-01-17 21:25:30 +01:00
Milan Broz
89ee1ed656 LUKS2: add sanity check for hdr_size.
Simplify code a little bit for static analysis and also
ensure that even second LUKS2 header with wrong hdr_size is
always detected.
2024-01-17 21:25:27 +01:00
Milan Broz
cac3184da3 Add a few tainted data info for coverity to avoid warnings.
If sysconf is lying, then anything can happen.
But check for overflow anyway.

Device/partition offset overflow for IV can only cause
bad decryption (expected).
2024-01-17 21:25:00 +01:00
Milan Broz
b048a417b7 Silence false positive cppcheck warning. 2024-01-17 12:20:00 +01:00
Milan Broz
cfdb1b93af Fix signed (error) return from read in loop utils. 2024-01-17 12:19:55 +01:00
Milan Broz
d15447814a Use gcc 13 for GitHub actions. 2024-01-17 12:19:48 +01:00
Ondrej Kozina
912d410458 Fix some grammar issues suggested by auto-correction tools. 2024-01-16 09:55:06 +00:00
Ondrej Kozina
d730f45201 Update kernel keyring usage documentation. 2024-01-16 09:55:06 +00:00
Ondrej Kozina
605acab31a Fix some grammar issues suggested by auto-correction tools. 2024-01-15 12:30:32 +01:00
Ondrej Kozina
ebca40640d docs: Describe additional LUKS2 locks. 2024-01-15 12:22:43 +01:00
Ondrej Kozina
a50a39a192 tests: add in-place LUKS2 encryption api test.
Simple test for plaintext data placed at specified offset
(non zero offset relative to head of data device).
2024-01-05 14:22:07 +01:00
Ondrej Kozina
adc83f6dca tests: add helper for creating arbitrary linear mapping. 2024-01-05 14:22:07 +01:00
Ondrej Kozina
bd0768a42a Respect CRYPT_ACTIVATE_SHARED in reencryption. 2024-01-05 14:22:07 +01:00
Yuri Chornoivan
543d220bd4 po: update uk.po (from translationproject.org) 2024-01-05 09:48:54 +01:00
Remus-Gabriel Chelu
44490e3ee1 po: update ro.po (from translationproject.org) 2024-01-05 09:48:54 +01:00
Jakub Bogusz
4b2015eafd po: update pl.po (from translationproject.org) 2024-01-05 09:48:54 +01:00
Hiroshi Takekawa
65005b4cd3 po: update ja.po (from translationproject.org) 2024-01-05 09:48:54 +01:00
Frédéric Marchal
fae0d2c1f2 po: update fr.po (from translationproject.org) 2024-01-05 09:48:54 +01:00
Roland Illig
2c16a80113 po: update de.po (from translationproject.org) 2024-01-05 09:48:54 +01:00
Milan Broz
44c6a76b09 Add note for luksSuspend to man page.
It should not be expected that suspend operation wipes
possible plaintext data from memory.

Related: #855
2023-12-22 12:17:55 +01:00
Milan Broz
37a2750e4f Update cryptsetup.spec. 2023-12-20 18:25:51 +01:00
Krassy Boykinov
b5006a5404 man: Update authenticated encryption trim description and add references
790666ff (Add support for allow_discrads for dm-integrity., 2020-04-09)
added TRIM support for standalone dm-integrity volumes.
This change is now reflected in the cryptsetup(8) man page.
2023-12-20 14:56:08 +00:00
Milan Broz
3323690cbc Version 2.7.0-rc1. 2023-12-20 15:21:01 +01:00
Milan Broz
1a50de508c Fix doxygen tags for API docs. 2023-12-20 15:12:30 +01:00
Milan Broz
b47f423907 Update release notes for 2.7.0-rc1 and LUKS2 doc. 2023-12-20 15:12:24 +01:00
Daniel Zatovic
d1b32a3b64 Add keyring linking API placeholders for multi-key scenarios. 2023-12-20 14:02:07 +01:00
Milan Broz
f87f6226aa opal: Fix benign gcc warning for possible uninitialized value. 2023-12-19 13:40:29 +01:00
Milan Broz
cd576666fc opal: Do not verify passphrase by default on luksErase.
Verify passphrase should be default only when creatng
a new passphrase, here it will fail if the passphrase
is wrong.
2023-12-19 12:35:50 +01:00
Ondrej Kozina
6b1f13fd0f opal: add comments to all lockless opal calls. 2023-12-18 17:26:47 +00:00
Milan Broz
7db221e47e Report Argon2 crypto backend version in debug output
For Argon2 native code (gcrypt, OpenSSL) a flag in debug output is printed.

If libargon is used, then [cryptsetup libargon2] is printed
(embedded code) or [external libargon2] for dynamic external library.

 # Crypto backend (OpenSSL 3.0.11 19 Sep 2023 [default][legacy] [external libargon2])
or
 # Crypto backend (OpenSSL 3.0.11 19 Sep 2023 [default][legacy] [cryptsetup libargon2])

Fixes: #851
2023-12-17 11:53:38 +00:00
Milan Broz
e5511b1920 Use uppercase OPAL in messages. 2023-12-17 12:52:39 +01:00
Ondrej Kozina
0ca1e680db opal: add exclusive lock to avoid race.
Activating LUKS2 device with OPAL support is multistep process.

1) read LR state
2) unlock LR
3) activate dm device
4) in case step 3) failed lock the device
   if in step 1) the device was locked.

Otherwise, in case parallel activation happened on one device
the process that failed to map dm device (device already active)
could relock the LR afterwards and effectively break already active
device.

To avoid that we do steps 1) through 4) protected by exclusive
opal lock unique per data block device configured for use with
LUKS2 OPAL support.
2023-12-13 20:59:14 +00:00
Ondrej Kozina
2e978c8776 opal: do not always re-lock range on failed activation.
If activation fails due to already active dm mapping
we must not automatically re-lock the OPAL range since
it would break the original active device.
2023-12-13 20:59:14 +00:00
Ondrej Kozina
31027b9240 test: check if device remains usable after failed attempt to double activation. 2023-12-13 20:59:14 +00:00
Ondrej Kozina
1d0680ce95 Drop unused crypt_read_lock helper. 2023-12-13 20:58:13 +00:00
Ondrej Kozina
997ef242a2 opal: no need to export internal opal_enabled function. 2023-12-13 15:16:02 +01:00
Ondrej Kozina
b869822c8b opal: erase key cached in kernel when LR gets locked.
It affects only HW OPAL locking range KEK.

After unlocking opal locking range we cache the key in kernel
so that we do not have to pass the key again for locking the
range later (the OPAL std requires key for lock command).

Unfortunately the key remains cached in kernel even after we
lock the range on purpose during crypt_deactivate* or crypt_suspend.

This had 2 side effects:

1) key remained in system memory even though the LUKS device was
   inactive (and all keys should be erased from memory).

2) when system gets suspended the locking range got automatically
   unlocked later after system resume because the key caching is used
   primarly to automatically unlock locking ranges that got locked
   after system suspend (due to power cut off on storage device).

Since kernel does not directly support dropping cached keys we achieve
that by overwritting the original key structure with empty one.
2023-12-04 19:02:11 +00:00
Boyuan Yang
2d080580bd po: update zh_CN.po (from translationproject.org) 2023-12-04 20:01:31 +01:00
Yuri Chornoivan
e3c65d9a34 po: update uk.po (from translationproject.org) 2023-12-04 20:01:31 +01:00
Remus-Gabriel Chelu
818e35e71c po: update ro.po (from translationproject.org) 2023-12-04 20:01:31 +01:00
Jakub Bogusz
ba751970af po: update pl.po (from translationproject.org) 2023-12-04 20:01:31 +01:00
Hiroshi Takekawa
13fcbe139d po: update ja.po (from translationproject.org) 2023-12-04 20:01:31 +01:00
Frédéric Marchal
5ea325afcc po: update fr.po (from translationproject.org) 2023-12-04 20:01:31 +01:00
Roland Illig
cf523b95be po: update de.po (from translationproject.org) 2023-12-04 20:01:31 +01:00
Ondrej Kozina
0f642a8397 Add missing vectors tests in valgrind setup. 2023-12-04 09:33:21 +00:00
Ondrej Kozina
b653567e3e Simplify meson tests.
Valgrind tests is now run with:

meson test -C <build_dir> --setup=valgrind
2023-12-04 09:33:21 +00:00
Milan Broz
85d23dde79 Revert "tests: Temporarily disable veritysetup tasklet option test."
This reverts commit 0e44494aba.

Kernel fix is in mainline and on the way to stable kernels.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/md?id=2a695062a5a42aead8c539a344168d4806b3fda2
2023-11-30 14:53:42 +00:00
Milan Broz
5e7bd7a36b fuzz: Try to limit image size in crypt2_load_proto_plain_json_fuzz
It seems that we see a lot of out of space in fuzzer run,
so try to avoid writing excessive big images here.
2023-11-30 15:01:04 +01:00
Milan Broz
f725123e4a Version 2.7.0-rc0. 2023-11-29 09:50:27 +01:00
Milan Broz
e1ef5214e7 Fix some typos found by lintian. 2023-11-29 09:49:55 +01:00
Milan Broz
b44c2ce071 Update pot file. 2023-11-29 09:22:52 +01:00
Milan Broz
5d50617594 Tweak some error messages. 2023-11-29 09:21:01 +01:00
Milan Broz
cea9c2972e Add release notes for 2.7.0-rc0. 2023-11-28 18:53:45 +00:00
Milan Broz
1e9d31e0e4 Add hw_opal.c for translation. 2023-11-28 18:53:45 +00:00
Milan Broz
d3a8393476 Set version 2.7.0-rc0. 2023-11-28 18:53:45 +00:00
Milan Broz
70a151242f meson: fix meson_dist_convert script 2023-11-28 18:53:45 +00:00
Milan Broz
ec4e2faf14 Add missing files to autoconf make dist. 2023-11-28 18:53:45 +00:00
Ondrej Kozina
e4a845c51e Use proper integer constant in meson_options.txt
Unfortunately it creates decimal base constant when converting
to C define.

But the former implicit and deprecated conversion did it as well.
2023-11-28 18:52:57 +00:00
Ondrej Kozina
d64203a018 Override meson default prefix. 2023-11-28 18:52:57 +00:00
Milan Broz
c0dfd1178d Fix some coverity scan issues.
The read in kernel crypto backend is part of user crypto API
encryption call, we have to trust it here.

JSON fix is just one place where return code was not checked
for this particular function.
2023-11-28 18:52:25 +00:00
Milan Broz
b3f1f611cd Always print error message for invalid keyring definition.
Many cases quietly returned error without any error message.
2023-11-27 15:13:04 +01:00
Мирослав Николић
86498858fc po: update sr.po (from translationproject.org) 2023-11-26 12:34:21 +01:00
Yuri Kozlov
403d12d52c po: update ru.po (from translationproject.org) 2023-11-26 12:34:21 +01:00
Jakub Bogusz
fcf6f8febf po: update pl.po (from translationproject.org) 2023-11-26 12:34:21 +01:00
Antonio Ceballos
06d02f4766 po: update es.po (from translationproject.org) 2023-11-26 12:34:21 +01:00
Milan Broz
6262da3a11 fuzz: add missing flex (util-linux req.) to fix fuzzing build 2023-11-26 10:39:22 +01:00
Milan Broz
dfbb7752b5 tests: fail early if PSID reset does not work for device.
This should stop user from using wrong device for tests.
2023-11-22 15:48:48 +01:00
Milan Broz
6b2cf68713 Suspend and resume also dm-integrity device with AEAD.
Currently we suspend top-level device only.

With OPAL, the underlying device will start to return errors
once OPAL LR is locked.

If the dm-integrity device is not suspended, regular journal
flush corrupts the device (journal write failure),
corrupting data above it.

Suspending the whole stack should fix the issue.
2023-11-22 12:15:18 +01:00
Milan Broz
0f51b5bacb Do not run sector read check on suspended device.
This can affect status command, but later also device
stack with authenticated encryption (*_dif device).

Ignoring direct-io should not be problem here.
The logic shoudl be simplified in future anyway...
2023-11-21 22:44:16 +01:00
Milan Broz
d3cc5e846a Do not require init_done for some deive helpers.
It processes only name, no need to depend on real device
checks (for direct-io) etc.
2023-11-21 22:44:16 +01:00
Ondrej Kozina
722c77c883 Fix wrong key id set when resuming LUKS2 device.
If volume key digest id was not 0 it failed on assert
in LUKS2 resume path later.
2023-11-21 21:43:34 +00:00
Daniel Zatovic
20c8096cc8 CI: change TSS package name for Debian 12
Change package name from tpm2-tss-engine-dev (on Debian 11) to libtss2-dev (on Debian 12).
2023-11-20 11:28:56 +01:00
Ondrej Kozina
8c0a943e5c Drop fake_token_path symbol from tests.
It's no longer used.
2023-11-17 10:42:23 +01:00
Ondrej Kozina
5ef1878b34 Do not use fake-token-path in ssh and systemd plugin tests. 2023-11-17 10:42:23 +01:00
Ondrej Kozina
836e5e4539 Add --external-tokens-path parameter in cryptsetup. 2023-11-16 17:49:09 +01:00
Ondrej Kozina
0328d61f29 Add crypt_token_set_external_path API.
It can be used to override system library where
libcryptsetup looks for external token handlers (plugins).

The parameter is required to be absolute path and it is set
per process context.

Fixes: #846.
2023-11-16 17:49:06 +01:00
Ondrej Kozina
31f82fd37c Drop deprecated use of implicit meson setup command. 2023-11-15 19:22:27 +00:00
Ondrej Kozina
9ca46971f2 Fix systemd-test-plugin initialization.
check for .git subdirectory to decide if systemd
repository needs to be cloned.
2023-11-15 19:22:27 +00:00
Ondrej Kozina
7aeb1c3aea Fix fake systemd tpm path symbol.
The prototype for the function in systemd has changed.
Otrherwise the tests abort with SEGFAULT.
2023-11-15 19:22:27 +00:00
Ondrej Kozina
cf7874de4b compat-test-opal does not depend on differ util. 2023-11-15 18:41:02 +01:00
Ondrej Kozina
d82a1843ba Speed up compat-test-opal valgrind test.
By not testing cleanup routines repeatingly
for leaks.
2023-11-15 18:41:02 +01:00
Ondrej Kozina
9a5a3855a0 Enable valgrind tests in meson. 2023-11-15 18:40:44 +01:00
Ondrej Kozina
83bb3648e3 Fix invalid comparison of bool and int types in root meson.build. 2023-11-15 13:33:05 +01:00
Ondrej Kozina
564379618a Increase minimal meson version to 0.64
It's inital cryptsetup upstream release with
meson support so let's not pollute scripts
with if-then-else branching from the very
beginning.
2023-11-15 13:33:05 +01:00
Daniel Zatovic
04a20e9b7d CI: disable -Wdeclaration-after-statement warning 2023-11-15 12:15:19 +01:00
Daniel Zatovic
11ab2f0d9e Dont mix declarations with code.
Move asserts after declarations.
2023-11-15 12:11:10 +01:00
Daniel Zatovic
7d4628e379 Remove obsolate AC_C_CONST macro.
The AC_C_CONST test program fails to compile under latest clang with
-Wall -Werror, which results in erroneously defining "const" keyword to
an empty string. The AC_C_CONST is considered obsolate.
2023-11-15 10:21:04 +01:00
Daniel Zatovic
a176f29dc4 CI: don't use non-existent meson flag
An unknown -Dinternal-argon2=false flag was used, new meson version
fails when it gets unknown flag. Use the correct
-Dargon-implementation=internal flag instead.
2023-11-13 12:08:43 +01:00
Daniel Zatovic
a8168eb854 CI: switch compilation test to Ubuntu Lunar (23.04) 2023-11-13 12:08:43 +01:00
Daniel Zatovic
98f2b9c136 CI: switch Debian runner from 11 to 12 2023-11-13 12:08:43 +01:00
Milan Broz
0e44494aba tests: Temporarily disable veritysetup tasklet option test.
Kernel bug reporte here:
  https://lore.kernel.org/dm-devel/fa17b8d8-2d84-45c8-ac6a-1876f1f55a52@gmail.com/
2023-11-13 12:00:13 +01:00
Milan Broz
371cfc4394 tests: Clean up also dm-integrity device in OPAL test 2023-11-07 19:39:37 +01:00
Ondrej Kozina
860550b3c6 Fix memory leaks detected in compat-test-opal. 2023-11-07 09:58:53 +01:00
Milan Broz
2a9752b6c8 tests: Do not run OPAL test with valgrind if variables are not set
Otherwise it will break run with exit code 77.
2023-11-06 17:12:57 +00:00
Ondrej Kozina
4543a445a0 Add hint about missing OPAL support in kernel.
Unfortunately there is currently no way how
to make difference between device lacking SED OPAL support
state and kernel missing SED OPAL support via disabled interface
via configure option.
2023-11-06 17:12:31 +00:00
Ondrej Kozina
ee31159c68 Enable tests fixed with recent commits. 2023-11-06 16:49:28 +01:00
Ondrej Kozina
029d4bdd57 Abort LUKS2 reencryption early if OPAL device used. 2023-11-06 16:49:28 +01:00
Ondrej Kozina
89e0ef96c2 Add LUKS2 OPAL requirement flag. 2023-11-06 16:49:26 +01:00
Ondrej Kozina
f623eb2e99 Add more onlyLUKS helpers for convenience. 2023-11-06 14:47:41 +01:00
Ondrej Kozina
d09b27a170 Fix memory leak in kernel keyring keyslot context.
The leak occured only when the context instance was
used more than once.
2023-11-03 21:27:59 +00:00
Ondrej Kozina
abf7e3e359 Fix memleak in test.
By defining custom buffer free function in test token handler
the default call to free() gets skipped.
2023-11-03 21:27:59 +00:00
Ondrej Kozina
79444bc615 Fix memory leak in device context. 2023-11-03 21:27:59 +00:00
Ondrej Kozina
0154893ad5 Remove inital opal-test.
Test fully included in compat-test-opal.
2023-11-02 17:15:14 +01:00
Ondrej Kozina
b23e9f32f2 Add basic compat-opal-test.
The aim of the test is verify compatibility with
SW only LUKS2 devices for basic operations like
activation, deactivation, suspend, resume and
token based activation.
2023-11-02 17:15:14 +01:00
Ondrej Kozina
1b7211f013 Do not allow decryption on devices with unsupported parameters.
Most notably LUKS2 w/ authenticated encryption profile. OPAL restriction
will be added in later commits.
2023-11-02 17:15:14 +01:00
Ondrej Kozina
b9ba5ec14d Do not allow --integrity option in reencryption action. 2023-11-02 17:15:14 +01:00
Ondrej Kozina
af8c53a823 Move LUKS2 legacy reencryption flag check.
There's already routine meant for verification if LUKS2
can be reencrypted. So move the appropriate code there instead.
2023-11-02 17:15:14 +01:00
Ondrej Kozina
45ddc623bc Restrict --hw-opal options only to luksFormat action. 2023-11-02 17:15:14 +01:00
Ondrej Kozina
52b2dc5148 Fail early if OPAL is selected with LUKS1. 2023-11-02 17:15:14 +01:00
Ondrej Kozina
e6590e808a Dump OPAL key size in bits. 2023-11-02 17:15:14 +01:00
Ondrej Kozina
7d17b09d41 Do not fail format actions by interrupting device wipe.
otherwise luksFormat and (integrity) format actions return
error when interrupted by user on purpose.
2023-11-02 17:12:34 +01:00
Ondrej Kozina
fea8b82e8d Add missing exclusive open check in crypt_format_luks2_opal. 2023-10-31 11:13:58 +01:00
Ondrej Kozina
32fbac17b1 Improve cmd line options man pages related to SED OPAL. 2023-10-31 11:13:58 +01:00
Ondrej Kozina
4081037bdb Add --key-file support in luksErase action with LUKS2 opal. 2023-10-31 11:13:58 +01:00
Ondrej Kozina
f15b2ffdec Correctly erase opal lr when luksFormat action fails. 2023-10-31 11:13:56 +01:00
Milan Broz
800ec5d1ed fuzzing: Fix crypt2_load_fuzz to not touch const data
The crypt2_load_fuzz fuzzer needs to calculate LUKS2 header checksum
to speed up fuzzing. Currently we incorrectly touch const data input.

This patch
 - calculates only primary LUKS2 header checksum (ignores secondary header)
 - uses temporary struct for modified data
 - keps fuzzer going even with original data if checksum calc fails.

Hopefully solves unknown write issue in fuzzer (not real utils) on oss-fuzz.
2023-10-30 13:11:31 +01:00
Milan Broz
7b6feb20b4 crypto_backend: remove superfluous memset fot hash and hmac contexts
The crypto backend crypt_hash ans crypt_hmac structs usually
contain only pointers to internal crypto lib structures, no need
to wipe them explicitly as there are no sensitive data.
It is a crypto lib responsibility to remove sensitive data
in destructor.

Only nettle backend directly contains hash context, keep it there.

This should also fix mysterious crashes in fuzzer with misaligned memset.
2023-10-27 09:49:46 +00:00
Milan Broz
0c9258484a tests: fix oss-fuzz build
- xz now requires some configure options to build with sanitizer
- lvm2 official repository moved
2023-10-27 09:03:50 +02:00
Ondrej Kozina
385c0afebe Fix tests in FIPS mode.
In FIPS mode, if test passphrase is shorter
than 8 bytes, keyslot passphrase check routine
returns different error code (-EINVAL) than
expected (-EPERM).
2023-10-18 15:02:09 +02:00
Ondrej Kozina
1f007061d6 Respect keyslot id while activating device by token.
Also by using --test-passphrase option this patch allows
cryptsetup to check if specific token (--token-id) is
able to unlock specific keyslot (--key-slot/-S).

It uses recently added crypt_activate_by_keyslot_context
API.

Fixes: #784.
2023-10-16 17:23:32 +00:00
Lennart Poettering
20bfec91d8 libdevmapper: propagate key mgmt related kernel ioctl error on _dm_create_device()
Let's not make up synthetic errors if the kernel returns a useful error
to us, that tells us about key validity.

Specifically, if we try to activate a dm-verity device with a signed
root hash, it's import to know when we couldn't activate it due to the
signing key missing in the kernel keyring. The kernel reports a nice
error code in that case (ENOKEY), let's make sure this is propagated
back to clients.

To be on the safe side, this allowlists only the three key management
related error codes ENOKEY, EKEYREVOKED, EKEYEXPIRED and returns ENOKEY
for all of them. The kernel's DM stack traditionally wasn't very good
with returning useful error codes, hence the conservative approach.

This patch is not sufficient to fix this properly. There's a patch
needed to fix errno propagation also in libdevmapper:

https://gitlab.com/lvmteam/lvm2/-/merge_requests/3

With both patches applied we get correct error code reporting.

Fixes: #841
2023-10-16 14:37:51 +02:00
Ondrej Kozina
15c3a2a2a9 Check passphrase for user selected keyslot only.
When adding new keyslot we check if provided existing
passphrase is correct first.

Since user may now select specific existing keyslot
(to extract volume key) it's no use to check any
matching keyslot. Test passphrase only for user
specified keyslot.
2023-10-09 09:49:54 +00:00
Milan Broz
717bd0665d plain: Add note to man page about cipher options. 2023-10-05 10:31:44 +02:00
Milan Broz
8f442bc97a tests: Avoid new plain type warnings if missing options. 2023-10-05 10:31:41 +02:00
Milan Broz
84682f6271 plain: Set default cipher to aes-xts-plain64 and hash to sha256.
These are configurable in build time, to force default backward compatibility use
--with-plain-hash=ripemd160 --with-plain-cipher=aes --with-plain-mode=cbc-essiv:sha256
configure options.

Fixes #758.
2023-10-05 10:31:20 +02:00
Milan Broz
a18fe71d8d plain: Print warning if using default cipher ahd hash options.
Unlike LUKS, plain mode uses no metadata where configured.
As we need to upgrade algorithms form time to time because of security
reasons, warn user to specify these options explicitly.

Related #758.
2023-10-05 08:12:51 +00:00
Ondrej Kozina
593f22a9a8 Fix empty device name in reencryption prompt message.
While resuming LUKS2 reencryption operation for
device identified by active mapping (--active-name) the
prompt about ongoing operation did not use correct
variable to get device name in the message.
2023-10-04 16:13:09 +02:00
Ondrej Kozina
edc2505923 Close stdin in tests where not expected to be used. 2023-10-04 11:40:56 +02:00
Ondrej Kozina
1f5b229a0e Add test coverage for device activation.
Add tests for device activation by volume
key uploaded in kernel keyring where user
only pass key description with no key type
description. In this case we add 'user' type
by default and it was not tested properly.
2023-10-04 11:40:45 +02:00
Ondrej Kozina
742bb0693d Fix return value in vk description parser.
Always return 0 on success or predefined negative
errno otherwise.
2023-10-04 11:39:56 +02:00
Ondrej Kozina
a5e2a97b53 Fix a bug in vk description parsing helper.
Fix a path with default kernel key type assumed.
It did not check correctly for return value from
asprintf and would leak the allocated memory
instead.
2023-10-04 11:39:56 +02:00
Ondrej Kozina
0236b82802 Fix user vk description leak in open action. 2023-10-04 11:39:56 +02:00
Ondrej Kozina
cfe257e10e Fix devel/debug leftover in LUKS2 api test. 2023-10-02 14:45:21 +02:00
Daniel Zatovic
05d3cb9196 CI: fix annocheck and csmock runners 2023-10-02 11:07:02 +02:00
Ondrej Kozina
df9976e2a7 We do not need to wipe specific keyslot area only. 2023-09-29 11:30:53 +02:00
Ondrej Kozina
f0b556b2d4 Do not wipe keyslot area before in-place overwrite.
If LUKS2 keyslot area has to be overwritten (due to lack of free space),
do not wipe the affected area first. It will get overwritten anyway.
Originaly, in between the keyslot wipe and new key material write, pbkdf
calculation took place. The pbkdf calculation takes ~2 seconds by default
and it put the user in unnecesary risk of loosing the keysot data in case
of a crash.
2023-09-29 11:30:53 +02:00
Ondrej Kozina
ca0c9c765e Avoid overwritting LUKS2 keyslot area if possible.
With LUKS2 crypt_keyslot_change_by_passphrase() call
does not have to overwrite binary keyslot
area in-place when user asked for specific keyslot id.

If there's enough free space in keyslot binary area
we can write new keyslot material in the the free area
(identified temporarily by new keyslot id) and switch
pointers (json metadata) to point to the new keyslot area after
the keyslot area write is complete. The old keyslot
area gets deleted after the new area write is finished.

Otherwise we needlesly risk to lose the existing keyslot
if the operation gets interupted.

With this patch LUKS2 crypt_keyslot_change_by_passphrase()
overwrites existing keyslot (including keyslot area)
only if there's no free space and therefore in-place update
is necessary.

Fixes: #839.
2023-09-29 11:30:53 +02:00
Ondrej Kozina
57bd4e0e66 Make all returned kernel key ids key_serial_t type. 2023-09-27 19:37:35 +00:00
Ondrej Kozina
fde3e881fc Do not return -errno codes from keyring utilities.
Fixes: #838.
2023-09-27 19:37:35 +00:00
Ondrej Kozina
d011ba710c Drop unused kernel keyring code. 2023-09-27 19:37:35 +00:00
Ondrej Kozina
6296e8d4f8 Improve debug output for kernel keyring.
Add more context to possibly failing kernel keyring routines
in log debug output.

Mostly split debug output for errors while trying to search the kernel
key by description and errors while trying to read/unlink the key
by its id.
2023-09-27 19:37:35 +00:00
Ondrej Kozina
cdce1d96f0 Do not print kernel key sizes in debug output.
Fixes: #837.
2023-09-27 12:04:42 +02:00
Ondrej Kozina
305688d678 Correctly cleanup volume key from kernel keyring on error.
If requested operation fails we should remove volume key
previously linked in user requested kernel keyring.
2023-09-26 12:03:11 +02:00
Ondrej Kozina
f6c464844d Fix posible NULL dereference bug. 2023-09-25 18:59:09 +00:00
Ondrej Kozina
0404e65da8 Split volume key only if activating SED OPAL LUKS2. 2023-09-25 18:59:09 +00:00
Ondrej Kozina
2d54e0bc58 Drop unused and unreleased API. 2023-09-25 18:59:09 +00:00
Ondrej Kozina
05634f272c Drop setting kernel key permissions.
Libcryptsetup should not set such permissions. All
the issues it aims to solve can be workaround by
caller linking the key in appropriate keyring
first and moving it in final destination later.
2023-09-25 18:59:09 +00:00
Ondrej Kozina
51a1e218cf Split logic for uploading keys in kernel key service.
We can not link internal VK kernel key in custom user
keyring. There are two reasons for it:

The internal VK kernel key description can not be
acquired via API and it may change over time
(LUKS2 reencryption).

With recent SED OPAL support volume key becomes a 'blob'
containing up to two keys (dm-crypt key for SWE and key
for unlocking SED OPAL locking range). The internal
kernel key contains only dm-crypt (if required) but
custom user keyring needs to be provided with whole
volume key (blob).

Added user specified key description for the linked key
in custom user keyring. The linked key can be reached by
the specified description after successful activation (resume).
2023-09-25 18:59:09 +00:00
Ondrej Kozina
7ae109dccd Set correct volume key descripion when uploading key in keyring.
When key upload in kernel keyring is forced by CRYPT_ACTIVATE_KEYRING_KEY
flag it does not have to be the volume key assigned to default segment.
2023-09-25 18:59:09 +00:00
Ondrej Kozina
c16f644c9f Add helper utility to search only for keyrings. 2023-09-25 18:59:09 +00:00
Ondrej Kozina
748cff228d Rename internal keyring utilities. 2023-09-25 18:59:09 +00:00
Ondrej Kozina
f147c823ea Reduce code duplication in kernel keyring utilities. 2023-09-25 18:59:09 +00:00
Ondrej Kozina
c497d8baa9 Drop redundant request_key call. 2023-09-25 18:59:09 +00:00
Ondrej Kozina
4872a14830 Fix wrong return value on error in keyring utils.
keyring_link_key_to_keyring_key_type could accidentaly
mask an unreachable key and make it look that key was
succesfully linked in custome keyring when it was not.
2023-09-25 18:59:09 +00:00
Milan Broz
b0610e1f73 Do not set flush and lockfs for DM device if resize grows the device.
Resize operation (crypt_resize) changes only size, so it is safe to
not flush IO (and  freeze fs with lockfs) during suspend/resume cycle.

For dm-integrity there can be two suspend/resume cycles as the subsequesnt
call sets recalculating flag.

Based on patch from Yury Vostrikov <mon@unformed.ru>

Resolves: #832
2023-09-20 15:30:10 +02:00
Milan Broz
1c7dd08c63 Try to sort options alphabetically. 2023-09-12 22:13:02 +02:00
Milan Broz
6df6ac49bf Remove dot from some option descriptions. 2023-09-12 22:13:00 +02:00
Milan Broz
1c31b93e5c Add --disable-blkid CLI option.
To be used with luksFormat if blkid fails for unknown reason.
2023-09-12 22:09:06 +02:00
Milan Broz
1969b6be2f Print blkid scan failure.
If old util-linux is used, blkid scan can fail because disk
is already locked for OPAL.
Do the same for other internal blkid issue.

Also add some debug messages to be clear what's going on.
2023-09-12 15:39:13 +02:00
Milan Broz
464fe987f9 Opal: print descriptive error if format locks the drive.
Some chipsets will set write-protection for the *full* drive
even if only small locking range is used.

As LUKS header expect to be writable ehen Opal LR is locked,
this is incompatible with LUKS.

Moreover, device need to be PSID reset and reconnected to clear
the flag. (And kernel lies about write protection so we cannot
get BLROGET ioctl to detect it.)

At least print some warning when LUKS2 header cannot be
written after Opal LR setup.

This applies for all USB adapters/firmware  with RTL9210 chipset.
(Need experimental patch to enable Opal through USB.)
2023-08-29 11:36:47 +02:00
Milan Broz
ab71eff3b9 opal: Remove key length debug msg. 2023-08-29 11:36:43 +02:00
Milan Broz
9b768cd401 Opal: add debug of Opal ioctl calls
This should print non-sensitive info only, no key info.
2023-08-29 11:36:39 +02:00
Milan Broz
c417c70a78 Opal: open device read-only as it is enough for ioctl.
This also solves the problem of using PSID reset
on write-protected device (some controllers lock the drive).
2023-08-29 11:36:35 +02:00
Milan Broz
8c87958b3b Fix unused symbol warnings in tests.
And actually fix two real bugs...
2023-08-28 12:43:42 +02:00
Milan Broz
81574d0f14 Enable -Wunused-parameter in CI tests. 2023-08-28 12:42:37 +02:00
Milan Broz
eb4a3f2904 Fix unused parameter warning in password utils. 2023-08-28 12:42:37 +02:00
Milan Broz
f18d370b4a Fix signed/unsigned warning in gcrypt backend. 2023-08-28 12:42:37 +02:00
Milan Broz
f70bf71dff Fix unused parameter in crypto backend handlers. 2023-08-28 12:42:37 +02:00
Milan Broz
5628de1f65 Fix unused parameter in LUKS2 reencryption handlers. 2023-08-28 12:42:37 +02:00
Milan Broz
ffd630973b Fix unused parameter in LUKS2 external tokens handlers. 2023-08-28 12:42:37 +02:00
Milan Broz
95425d45dd Fix unused parameter in blkid handlers. 2023-08-28 12:42:37 +02:00
Milan Broz
b31863c052 Fix unused parameter in keyring handlers. 2023-08-28 12:42:37 +02:00
Milan Broz
e14316f132 Mark unused parameters. 2023-08-28 12:42:37 +02:00
Milan Broz
54ada7b8e3 keyring: Fix possible sscanf string overflow.
Found by CodeQL.
2023-08-26 20:26:18 +02:00
Ondrej Kozina
e43de57fac Switch crypt_activate_by_signed_key to keyslot context based activation.
It introduces new keyslot context type CRYPT_KC_TYPE_SIGNED_KEY.
2023-08-16 14:17:34 +02:00
Ondrej Kozina
e5bd99665e Split volume key verification and device activation.
It makes key verification easier and also allows digest
verification for keys not assigned to device segment
(unbound keys) for more keyslot context types (tokens).
2023-08-16 14:17:34 +02:00
Daniel Zatovic
1aab3afcba Allow activation, resume and luksAddKey using VK stored in keyring.
Add --volume-key-keyring option, which takes a name of a key in keyring,
which will be used as a VK during device activation. The key can be
specified in keyctl-compatible syntax "%<key_type>:<key_name>".
2023-08-16 14:17:34 +02:00
Daniel Zatovic
d0ef2d84be Add tests for linking VK to a keyring and changing VK type.
Test various combinations of arguments for the options
--link-vk-to-keyring and --volume-key-type. Add API tests for the
crypt_set_keyring_to_link and crypt_set_vk_keyring_type functions.
2023-08-16 14:17:29 +02:00
Daniel Zatovic
6bcd9ed52c Add keyslot_context for volume key stored in a keyring. 2023-08-16 12:29:29 +02:00
Daniel Zatovic
1f2dac34d0 Support specifying keyring and key using keyctl syntax.
When using the --link-vk-to-keyring option, allow specifying the keyring
using the same syntax as keyctl (see "man keyctl"). E.g. "@u" for user
keyring and "%:testring" for a user-created keyring.
2023-08-16 12:29:29 +02:00
Daniel Zatovic
a674fb968c Support specifying volume key keyring type.
Currently only logon keyring type is supported. Add --volume-key-type to
allow specifying arbitrary type for the volume key.
2023-08-16 12:29:29 +02:00
Daniel Zatovic
138da3e73a Allow linking VK to a user-specified keyring.
Add a new API crypt_set_keyring_to_link nad CLI option
--link-vk-to-keyring. This allows the user to specify ID of the keyring
where the VK should be linked.
2023-08-16 12:29:29 +02:00
Daniel Zatovic
1b25cc5ed7 Don't revoke volume key in keyring.
Just unlink it from thread keyring where it is linked. The key should
get destroyed automatically once the reference count goes to zero, so
the revoke is redundant (unless there's a bug in the kernel keyring).

Note: the explicit revoke would destroy the key even when it is linked
to a user specified keyring.
2023-08-16 12:29:29 +02:00
Daniel Zatovic
cb184bcbb8 Allow resume by keyslot context. 2023-08-16 12:29:29 +02:00
Daniel Zatovic
aea21309ed Add keyring keyslot_context. 2023-08-16 12:29:26 +02:00
Daniel Zatovic
e2c413e5a9 Add tests for activation by keyslot context 2023-08-15 17:42:31 +02:00
Ondrej Kozina
cfbba1819b Add new token activation API tests. 2023-08-15 17:42:31 +02:00
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
Milan Broz
9a92c6a677 Fix PBKDF vector test in FIPS mode.
Another example of FIPS theatre is that some vendors
implements hard limits for PBKDF attributes
(minimal password length, salt, etc).

This should be set by policy on another layer,
unfortunately someone apparently thinks it is a good idea
to harcode it to low-level crypto library directly.

This of course breaks some older test vectors
that use shorter attributes.

Just mark these and ignore possible API error in FIPS mode.
2023-04-20 23:20:47 +02:00
Milan Broz
6721d3a8b2 Use only half of detected free memory on systems without swap.
As tests shows, limiting used Argon2 memory to free memory on
systems without swap is still not enough.
Use just half of it, this should bring needed margin while
still use Argon2.

Note, for very-low memory constrained systems user should
avoid memory-hard PBKDF (IOW manually select PBKDF2), we
do not do this automatically.
2023-04-19 13:28:15 +00:00
Milan Broz
7893c33d71 Check for physical memory available also in PBKDF benchmark. 2023-04-19 13:28:15 +00:00
Milan Broz
23dd988545 Fix PBKDF2 vectors test for RHEL8 OpenSSL.
Seems someone clever had an idea to return hash output
through API size even the hash is actually not available
in FIPS mode.

Just check also hash init in this case (as we already
do elsewhere).
2023-04-19 10:55:35 +00:00
Ondrej Kozina
c81c3d1fc0 Remove unused code in reencryption. 2023-04-19 10:01:51 +02:00
Milan Broz
7859673bd2 Support OpenSSL 3.2 Argon2 implementation. 2023-04-19 07:16:08 +00:00
Milan Broz
34953cb10f Add support for Argon2 from libgcrypt.
Argon2 is available since version 1.10, but we need version
that allows empty passwords (1.11).
2023-04-19 07:15:35 +00:00
Vojtech Trefny
bc426bba67 bitlk: Fix segfaults when attempting to test volume key
Also clarify that checking the volume key is not possible for
BITLK in the docstring and man page.

Fixes: #810
2023-04-18 16:38:58 +02:00
Alex Xu (Hello71)
234ca010e2 Link only libcrypto from openssl
Reduces initramfs dependencies. libcrypto.pc is available in openssl
0.9.8+
2023-04-18 07:49:28 +00:00
Alex Xu (Hello71)
32febb4483 configure.ac: remove += bashism
Fixes: c1302555b7 ("Provide pkgconfig Require.private.")
2023-04-17 12:31:55 -04:00
Ondrej Kozina
b6eaa236bc Fix fips mode detection in gcrypt backend.
gcry_fips_mode_active must not be called before
gcry_check_version. Let's initialize backend in
before fips mode detection if it needs to.
2023-04-13 13:20:49 +00:00
Milan Broz
a617c23ccc Disable reencryption for DAX devices.
Device-mapper is not capable to stack DAX/non-DAX devices
in mapping table, so online reencryption cannot work.

Fixes: #760
2023-03-31 10:51:34 +00:00
Milan Broz
e4c2aa64b5 Detect DAX devices and and warn in LUKS format.
DAX / persistent memory devices do not provide atomic sector updates,
any single modification can corrupt the whole encryption block.
2023-03-31 10:51:34 +00:00
Milan Broz
2a2027ee3e Print message if device is not aligned to sector size.
If a partition is resized after format, activation could
fail when the device is not multiple of a sector size.

Print at least warning here as the message is only in syslog.

Related to Issue #807
2023-03-31 08:52:52 +00:00
Milan Broz
192ff16cd8 Fix fuzz tests build. 2023-03-18 11:16:22 +01:00
Milan Broz
17a0b1e2d3 Remove testing branch from CI script. 2023-03-10 18:09:24 +01:00
Milan Broz
c2045b9585 Update CodeQL config. 2023-03-10 11:41:51 +01:00
Milan Broz
9d5e45be54 Add header guard to ssh-utils.h. 2023-03-10 11:41:47 +01:00
Milan Broz
d4840d46e1 Do not overload global crc32 table name by a function parameter name. 2023-03-10 11:41:43 +01:00
Milan Broz
cca490a0b8 test: Do not overload global crypt_device variable name. 2023-03-10 11:41:33 +01:00
Milan Broz
a752e571ab reencrypt: fix checking of context name arguments. 2023-03-09 17:06:58 +01:00
Milan Broz
d209bb27b4 User more restrictive attributes for device file lock. 2023-03-09 16:55:46 +01:00
Milan Broz
ccf48bb28e tests: avoid possible overflow in multiplication
We need to operate in 64bits uint here.
2023-03-09 16:32:37 +01:00
Milan Broz
76c0a81318 tests: reserve one byte for trailing zero in global log buffer 2023-03-09 16:28:36 +01:00
Milan Broz
b297b59ba2 bitlk: avoid use ctime() with pointer to shared memory.
Use own buffer with ctime_r() is more secure.
2023-03-09 16:22:53 +01:00
Daniel Zatovic
f686fc7108 meson: Add dist hook only when asciidoctor is found.
Avoid attempting to use non-discovered program.
2023-03-09 14:40:26 +00:00
Ondrej Kozina
9a96e260aa Fix unlikely occurences of json_object leaks on error path.
In most cases it relates to error path triggering on general OOM.
2023-03-08 15:23:32 +01:00
Ondrej Kozina
cb177c5076 Improve code clarity a bit.
It also silences false positive warning with older compilers.
2023-03-08 15:23:32 +01:00
Ondrej Kozina
4ebc6a1616 Correct error paths in LUKS2 reencryption code path. 2023-03-08 15:23:25 +01:00
Ondrej Kozina
1c65c1c3d1 Add json_object_object_add_by_uint_by_ref helper.
Function is similar to json_object_object_add_by_uint but
it unsets *jobj_val_ref pointer if the function ends with
success.

It helps to create cleaner error patch and avoids eventual
double free corruption if **jobj_val_ref object changed
ownership.
2023-03-08 15:12:45 +01:00
Milan Broz
b12e9534c3 Replace LGTM with GitHub CodeQL.
Many warnings silenced for now.
2023-03-07 13:51:04 +01:00
Milan Broz
8b3162069e CI: move autogen.sh to specific build scripts.
It seems that autogen.sh is not called in some situations
(merge request updating configure scripts).

Let's move this directly before configure.
Also print disable-<feature> options to CI output.
2023-03-06 10:16:31 +00:00
Milan Broz
27f8e5c08f Print warning when keyslot requires more memory than available
This warning is displayed only if maximum memory was adjusted:
no swap, not enough memory, but is not printed if user set keyslot
memory cost above default limit intentionally.

In the latter case we have to check all available memory and guess
if swap is enough - this is not job af cryptsetup and also
it should not excessively parse any /sys files during keyslot open.
2023-03-04 20:06:11 +01:00
Milan Broz
899bad8c06 Try to avoid OOM killer on low-memory systems without swap.
Benchmark for memory-hard KDF is tricky, seems that relying
on maximum half of physical memory is not enough.

Let's allow only free physical available space if there is no swap.
This should not cause changes on normal systems, at least.
2023-03-04 20:06:11 +01:00
Milan Broz
62aa392205 Improve README.md.
Rebased changes from patch (MR !480) by Anthony D'Atri
(and some other minor changes).
2023-03-04 19:51:54 +01:00
Milan Broz
428c2f323b fuzz: Do not calculate checksum for too small headers.
LUKS2 header must be at least binary header size.
2023-03-03 20:24:37 +01:00
Milan Broz
045ed9d485 Update devel version. 2023-03-03 14:50:55 +01:00
Daniel Zatovic
114a13af84 Add support for meson build system.
For now, let's keep support for both - autotools and meson.
2023-03-03 13:49:47 +00:00
Milan Broz
9d5327c37b Fix sector_size display for non-LUKS2 crypt devices. 2023-02-21 08:32:39 +00:00
Milan Broz
1d109a114c Fix integrity info display for non-LUKS2 crypt devices. 2023-02-21 08:32:39 +00:00
Milan Broz
e455110c8e Fix crypt_init_by_name() for dm-crypt with integrity.
Initialization by name for dm-crypt with integrity is always
underlying device for dm-integrity target, not dm-integrity
device itself.

This fixes various problems like refresh command or
device printed in status command.

Fixes: #801
2023-02-21 08:32:39 +00:00
Daniel Zatovic
e244c8c543 CI: upgrade csmock image to RHEL 9. 2023-02-20 19:23:07 +01:00
Daniel Zatovic
384b7f2e94 fuzzing: Fix OSS-Fuzz static build script.
The scrip for building dependencies statically still builds popt as a
shared library. The libdevmapper library is installed manually, but
incorrectly (libdevmapper.pc is installed, but it should be
devmapper.pc).
2023-02-15 14:48:02 +01:00
wangzhiqiang
1f805cb35a Update file cryptsetup-ssh.c 2023-02-10 16:48:19 +00:00
wangzhiqiang
ec0efe7068 fix potential null pointer dereference.
Signed-off-by: wangzhiqiang <wangzhiqiang95@huawei.com>
2023-02-10 19:49:48 +08:00
Milan Broz
4fc619853d Version 2.6.1. 2023-02-09 17:12:17 +01:00
Milan Broz
72f799b393 Update Copyright year. 2023-02-09 17:11:18 +01:00
Milan Broz
5d622102c6 Some more cleanup of Release notes. 2023-02-09 13:43:29 +01:00
Ondrej Kozina
93c5013577 Clarify when cryptsetup asks for LUKS2 token PINs. 2023-02-09 12:40:50 +00:00
Milan Broz
83d3c04347 Reformat and cleanup README. 2023-02-09 12:28:53 +01:00
Milan Broz
53668a0203 Add 2.6.1 Release notes. 2023-02-08 17:05:34 +01:00
Yuri Chornoivan
fcf2ce9073 po: update uk.po (from translationproject.org) 2023-02-06 10:37:13 +01:00
Yuri Kozlov
9364fd5931 po: update ru.po (from translationproject.org) 2023-02-06 10:37:13 +01:00
Remus-Gabriel Chelu
f5253e6826 po: update ro.po (from translationproject.org) 2023-02-06 10:37:13 +01:00
Hiroshi Takekawa
f697444d14 po: update ja.po (from translationproject.org) 2023-02-06 10:37:13 +01:00
Frédéric Marchal
06b52c83b3 po: update fr.po (from translationproject.org) 2023-02-06 10:37:13 +01:00
Roland Illig
18a7427bad po: update de.po (from translationproject.org) 2023-02-06 10:37:13 +01:00
Petr Pisar
23dfb78823 po: update cs.po (from translationproject.org) 2023-02-06 10:37:13 +01:00
Milan Broz
5da3fd8622 Prepare 2.6.1-rc0 version. 2023-02-01 16:03:00 +01:00
Milan Broz
8b90d16762 Add fuzz patch file to tarball. 2023-02-01 16:02:26 +01:00
Milan Broz
31fe5ccd19 Update po/LINGUAS. 2023-02-01 15:57:27 +01:00
Remus-Gabriel Chelu
4339dd0bff po: add ro.po (from translationproject.org) 2023-02-01 15:54:12 +01:00
Temuri Doghonadze
7e6b8fc0d7 po: add ka.po (from translationproject.org) 2023-02-01 15:54:12 +01:00
Milan Broz
ace015a3e5 Fix OpenSSL < 2 crypto backend PBKDF2 possible iteration count overflow.
For OpenSSL2, we use PKCS5_PBKDF2_HMAC() function.
Unfortunately, the iteration count is defined as signed integer
(unlike unsigned in OpenSSL3 PARAMS KDF API).

This can lead to overflow and decreasing of actual iterations count.
In reality this can happen only if pbkdf-force-iterations is used.

This patch add check to INT_MAX if linked to older OpenSSL and
disallows such setting.

Note, this is misconception in OpenSSL2 API, cryptsetup internally
use uint32_t for iterations count.

Reported by wangzhiqiang <wangzhiqiang95@huawei.com> in cryptsetup list.
2023-02-01 13:12:02 +01:00
Daniel Zatovic
5ed0358f12 fuzzing: Fix protobuf fuzzer errors when using MSAN
Patch libprotobuf-mutator to unpoison buffers obtained from libfuzzer
via LLVMFuzzerMutate. This is required as libfuzzer is usually not
compiled with memory sanitizer support (not even in OSS-Fuzz project,
see https://github.com/google/oss-fuzz/issues/864). Therefore, we
manually mark the buffer as initialized using __msan_unpoison.

Fixes OSS-fuzz bug 52541, 52543 and 52533.
2023-01-31 23:45:34 +01:00
Milan Broz
5a33f1dc9a Add asciidoctor to compilation requirements in Readme. 2023-01-24 13:16:45 +01:00
Daniel Zatovic
ae80dc0e8e CI: add compilation tests with various disable options 2023-01-20 14:37:28 +00:00
Daniel Zatovic
3f6d5470e3 Fix compilation warning with disabled keyring. 2023-01-20 14:34:14 +01:00
Ondrej Kozina
4cd8d1efdb Fix api test on kernels with capi format support. 2023-01-19 11:50:48 +01:00
Milan Broz
48d6f85cc3 bitlk: fix printf debug message
Fixes Coverity warning.
2023-01-18 13:55:03 +01:00
Ondrej Kozina
5216002773 Use ISO C compliant inline assembly with supported compilers.
When compiled with enforced ISO C (e.g. -std=c11) 'asm' inline
does not compile (it's GNU extension). Use __asm__ inline assembly
with GCC and clang compliers instead.

Fixes: #786.
2023-01-18 08:59:58 +00:00
Milan Broz
482c819ea2 fvault2: fix compilatioon with very old uuid.h
UUID_STR_LEN is undefined for old headers, just
use internal definition (both are 37 bytes).
2023-01-17 13:32:29 +00:00
Milan Broz
0622b51634 verity: fix hash offset 64bit values
Hash offset is 64bit values, for some reason it is
used as size_t on one place. Fix it by properly use uint64_t.

Fixes: #792
2023-01-17 13:16:30 +01:00
Daniel Zatovic
7bbfccbbfa fuzzing: update script to build popt using CMake
Popt library removed support for autotools build system and can be built
only using CMake.
2023-01-11 14:02:47 +01:00
Milan Broz
7c25db5bf3 bitlk: fix possible leak of description
If metdata contains more than one description fields,
use just the first one.

Fixes OSS-fuzz bug 54682.
2022-12-30 13:47:20 +01:00
Milan Broz
034041a922 bitlk: clean formatting to use tabs 2022-12-29 01:02:24 +01:00
Milan Broz
776baf4ccc bitlk: fix use of startup BEK key on big-endian platform
The version and metadata size is stored as little-endian.
2022-12-29 01:02:20 +01:00
Milan Broz
d1a607e0b2 bitlk: harden parsing of metadata entries (for vmk and description entry)
For broken metadata BITLK format parsing can cause crash or out of memory
on several places.

Add better size checks to avoid parsing such a metadata.
Also be aware that entry_size can be smalle (so minus operation can underflow).

Also fix memory leak if FVEK entry is more than once in metadata
(just use the first entry and ignore others).
2022-12-29 01:02:05 +01:00
Milan Broz
1682e72bf5 bitlk: harden parsing of metadata entries
For broken metadata BITLK format parsing can cause crash or out of memory
on several places.

Add better size checks to avoid parsing such a metadata.

Fixes OSS-fuzz bug 54548,54553,54559.
2022-12-25 21:34:34 +01:00
Khem Raj
8e7f07841e Replace off64_t with off_t
AC_SYS_LARGEFILE autoconf macro is in use in configure script which will
add needed feature macros on commandline to enable 64bit off_t.

Also replace lseek64 with lseek, since it will be same when
_FILE_OFFSET_BITS=64 is defined on relevant platforms via AC_SYS_LARGEFILE

This fixes build with latest musl, where LFS64 interfaces are moved out
of _GNU_SOURCE feature test macros namespace [1]

[1] https://git.musl-libc.org/cgit/musl/commit/?id=25e6fee27f4a293728dd15b659170e7b9c7db9bc

Signed-off-by: Khem Raj <raj.khem@gmail.com>
2022-12-23 15:49:00 +01:00
David Flor
50e8879528 fuzzing: add new fuzzer for fuzzing multiple types at once
* added fuzz target 'crypt2_load_ondisk_fuzz' that tries to load fuzz input as LUKS1, FileVault2, BitLocker in that order.
* added dictionary for this fuzz target
* added fuzz target to relevant files
2022-12-23 15:00:01 +01:00
Ondrej Kozina
c18dcfaa0b Abort encryption when header and data devices are same.
If data device reduction is not requsted this led
to data corruption since LUKS metadata was written
over the data device.
2022-12-14 09:52:19 +01:00
Ondrej Kozina
be088b8de8 Enable crypt_header_is_detached for empty contexts.
Also changes few tests now expecting crypt_header_is_detached
works with empty contexts.
2022-12-14 09:52:19 +01:00
Milan Broz
de221b4ea7 Fix typo in comment. 2022-12-08 14:17:50 +01:00
Milan Broz
170161b9b6 Free all possible allocated params if crypt_load() fails.
If format load fails in some intermediate step, the internal
params struct can contain already set values.
While context is set still to none type, it can cause segfault
in releasing active_name.

(Found by fuzzing target processing crypt_load.)
2022-12-08 14:17:44 +01:00
Milan Broz
a649d734b6 Let crypt_set_null_type wipe whole context always.
We have to be sure that after setting new type some
union is not misused.
2022-12-08 13:02:18 +01:00
Milan Broz
15c998d523 Move crypt_free_type and allow force type override.
Will be used later on error path.
2022-12-08 13:02:18 +01:00
Ondrej Kozina
14eff9480d Change tests to use passphrases with minimal 8 chars length.
Skip tests that can not satisfy minimal test passphrase length:

- empty passphrase
- LUKS1 cipher_null tests (empty passphrase is mandatory)
- LUKS1 encryption
2022-12-08 11:03:09 +00:00
Ondrej Kozina
4621580802 Run PBKDF benchmark with 8 bytes long well-known passphrase. 2022-12-08 11:03:09 +00:00
Milan Broz
4bede447c8 Set devel version. 2022-12-08 11:48:28 +01:00
Milan Broz
b08212ea45 Version 2.6.0. 2022-11-28 12:27:33 +01:00
Milan Broz
5a976ad1d9 Do not log score from pwquality.
This information is really not needed in debug log.
2022-11-28 10:37:58 +01:00
Yuri Kozlov
0e4182874b po: update ru.po (from translationproject.org) 2022-11-27 23:20:25 +01:00
Milan Broz
487e85fdec Wipe buffers to be sure padding is always empty.
Detected by valgrind as writing unitialized data.
2022-11-27 23:18:36 +01:00
Milan Broz
32344d5a84 tests: fix reencryption-mangle test valgrind log name.
Use the same logic as in compat-test (just the line
number is the last one for cryptsetup_raw).
2022-11-27 21:02:49 +01:00
Milan Broz
ebb16a511c tests: fix list of valgrind tests
FVAULT2 test was missing; systemd test does not support valgrid yet.
2022-11-27 19:48:57 +01:00
Milan Broz
51200eb6da tests: do not require build tools for localtest in systemd plugin test
Fo localtest we use installed binaries, only checkprograms need to be build.
2022-11-24 16:37:38 +01:00
Milan Broz
119c57e00e tests: remove stray backslash in grep expression 2022-11-24 15:01:47 +01:00
Milan Broz
700b0f6e36 tests: do not run systemd plugin test without fake tpm path
We want to avoid touching real TPM during test.
2022-11-24 15:00:19 +01:00
Milan Broz
8fff498062 tests: compile fake_tpm_path util also for localtest
Otherwise TPM_PATH will not be used.
2022-11-24 14:54:18 +01:00
Milan Broz
2ef2f6017d Update release notes. 2022-11-24 13:49:27 +01:00
Ondrej Kozina
cdfa213ad0 Allocate internal buffer in LUKS2 keyring token with crypt_safe_alloc.
With changes in db65a5ceac and subsequent
drop of library memlock_all we should lock keyring key material buffer
in memory system memory as well.
2022-11-24 09:03:29 +00:00
Milan Broz
dab00bfd4f CI: use libsepol-dev for Debian based distros.
Seems libselpol1-dev is disappearing.
2022-11-23 11:57:59 +00:00
Ondrej Kozina
c018558f2d Remove unused define CRYPT_KC_TYPE_UNDEFINED.
The defined was not yet released in stable version.
2022-11-23 11:08:55 +01:00
Milan Broz
3633b81909 CI: fix GutHub action install script 2022-11-22 16:38:10 +01:00
Yuri Chornoivan
b23a02b05c po: update uk.po (from translationproject.org) 2022-11-22 16:17:48 +01:00
Jakub Bogusz
347c39ca97 po: update pl.po (from translationproject.org) 2022-11-22 16:17:48 +01:00
Hiroshi Takekawa
2d1f1833e8 po: update ja.po (from translationproject.org) 2022-11-22 16:17:48 +01:00
Frédéric Marchal
7f09ab67e2 po: update fr.po (from translationproject.org) 2022-11-22 16:17:48 +01:00
Roland Illig
f5fb1f1b94 po: update de.po (from translationproject.org) 2022-11-22 16:17:48 +01:00
Petr Pisar
005141554f po: update cs.po (from translationproject.org) 2022-11-22 16:17:48 +01:00
Ondrej Kozina
cd8f80b7ee Clarify type requirements in crypt_volume_key_get_by_keyslot_context. 2022-11-21 15:56:14 +01:00
Milan Broz
c7bbae01a6 Fix some strings for translations.
No need to translate debug strings.
Fix spaces in key slot queries.
2022-11-20 12:36:26 +01:00
Milan Broz
257bc80ae9 Version 2.6.0-rc0. 2022-11-18 22:32:47 +01:00
Milan Broz
6c2e64bf75 fvault2: fix typo 2022-11-18 22:25:31 +01:00
Milan Broz
942cea1803 Update pot file. 2022-11-18 22:22:06 +01:00
Milan Broz
e7eab5fec2 Prepare version 2.6.0-rc0. 2022-11-18 22:02:44 +01:00
Ondrej Kozina
b0779c6529 Fix --disable-luks2-reencryption configuration option. 2022-11-18 16:40:48 +01:00
Milan Broz
37d045df00 fvault2: add basic info to cryptsetup man page 2022-11-18 15:27:00 +01:00
Milan Broz
4b95f36804 Fix possible undefined use od preprocessor.
Mixing preprocessor #if and code is undefined behavior in general,
rewrite tools_package_version to not use it.
2022-11-18 14:50:34 +01:00
Milan Broz
faf3b27f51 fvault2: reduce debug log, do not print ignored metadata blocks 2022-11-18 14:31:25 +01:00
Josef Andersson
c85d1351ea po: update sv.po (from translationproject.org) 2022-11-18 14:25:40 +01:00
Мирослав Николић
3b18fe2b23 po: update sr.po (from translationproject.org) 2022-11-18 14:25:40 +01:00
Milan Broz
e96588b8b5 Check and allocate header early so wipe fails only for IO errors.
The device_check is done in header write functions,
but these are not recached in normal format path as wipe call
is called earlier.

Call the device check also from wipe function to get better error
description.

This situation happens for example when a block device is too small
(regular file can be enlarged by falloc(); block device cannot).
2022-11-18 13:03:52 +00:00
Milan Broz
c31494abc6 Print warning early if LUKS container is too small for activation.
Activation with header only fails too late (in device-mapper
call) while it is clear from the beginning that it cannot succeed.

Just add an early and better worded error.

Ignore this situation for block device (we have to call ioctl to get size).
The most common case is a file container here anyway.

For block devices it fails during activation later.
2022-11-18 13:03:52 +00:00
Milan Broz
819902a33a Add a better warning if luksFormat ends with image without any space for data.
Header write can call falloc() to increase image size, so we should
check data offset after header is written.

Also change wording to be less cryptic and describe what is the real problem.

Note that the code can be used this way to crate detached header (without
space for data), so it is not an error.
2022-11-18 13:03:52 +00:00
Daniel Zatovic
395beb635c Speed up tests using faster hash and PBKDF options.
Use faster SHA1 instead of SHA256 in reencryption test and pass fast
PBKDF options in mode-test.
2022-11-18 11:08:31 +00:00
Ondrej Kozina
81c56a8395 Move assert include in internal header files. 2022-11-16 16:54:33 +01:00
Milan Broz
3333f3e9bb Fix some warning detected by Coverity.
The FVAULT2 block is always 8192 bytes (for CRC), but used
struct is smaller. Let's not confuse struct size with whole block.
2022-11-15 10:47:22 +01:00
Milan Broz
b086430877 fvault2: Move messages to debug level and add more debug log. 2022-11-14 21:50:18 +01:00
Milan Broz
01f3f3e66c fvault2: volume size can be unsigned 64bit 2022-11-14 21:50:18 +01:00
Milan Broz
e37d8bdf91 fvault2: harden device offset check
Check if value overflows and do not allow reading
metadata block exceeding fixed offset.
2022-11-14 21:50:18 +01:00
Milan Broz
8b4a5e5931 fvault2: some more code cleanup. 2022-11-14 21:50:18 +01:00
Milan Broz
33d8d19408 fvault2: passphr -> passphrase 2022-11-14 21:50:18 +01:00
Milan Broz
9bb98d49c0 fvault2: some minor code reformatting changes. 2022-11-14 21:50:18 +01:00
Pavel Tobias
1c5fd5ae10 Fvault2: add basic error logs 2022-11-14 21:50:18 +01:00
Milan Broz
3d1b965c46 fvault2: fix --test-passphrase option 2022-11-14 21:50:18 +01:00
Milan Broz
2770273582 fvault2: test volume key dump 2022-11-14 21:50:18 +01:00
Milan Broz
f6b6e41951 fvault2: Add a basic man page. 2022-11-14 21:50:18 +01:00
Milan Broz
03059fae75 tests: add valgrind support to fvault2 test. 2022-11-14 21:50:18 +01:00
Pavel Tobias
ba9757b14b Fvault2: add basic test 2022-11-14 21:50:18 +01:00
Pavel Tobias
cd5bd1c773 Fvault2: store UUIDs in text format 2022-11-14 21:50:18 +01:00
Vojtech Trefny
a5c7bba6ee Add missing support for fvault2 commands 2022-11-14 21:50:18 +01:00
Vojtech Trefny
4bce6d5962 Show error when trying to run fvault2Dump on a non-fvault device 2022-11-14 21:50:18 +01:00
Pavel Tobias
cb9deaf354 Fvault2: implement open 2022-11-14 21:50:18 +01:00
Pavel Tobias
0ce5de9c1c Fvault2: implement dump 2022-11-14 21:50:18 +01:00
Pavel Tobias
35071c6d50 Fvault2: derive volume key 2022-11-14 21:50:18 +01:00
Pavel Tobias
af6ea01997 Fvault2: read all relevant metadata from device 2022-11-14 21:50:18 +01:00
Pavel Tobias
1d5d6d73a5 Add support for CRC-32C (Castagnoli polynomial) to lib/crypto_backend 2022-11-14 21:50:18 +01:00
Pavel Tobias
1ffc9d967c Fvault2: prepare module in libcryptsetup 2022-11-14 21:50:18 +01:00
Milan Broz
1f4c7a83f9 Annotate some functions to prevent Coverity tainted input error.
These errors are really annoying, just silence them.
2022-11-14 13:05:04 +00:00
Milan Broz
f312ba6256 Fix json_object_copy return value check.
Reported by Coverity scan.
2022-11-14 13:05:04 +00:00
Milan Broz
5186f49613 tests: fix compilation warnings with C18
Fix the function prototype and define GNU source definition to get strdup().
2022-11-13 19:40:50 +01:00
Milan Broz
616d3cd493 tests: do not require whirlpool hash for LUKS1 test
Just remove unsupported images before test and continue.
2022-11-13 19:40:48 +01:00
Milan Broz
cd2e22cb87 tests: rename systemd plugin test
So the logic works the same as ssh-test-plugin.
2022-11-13 19:40:45 +01:00
Milan Broz
54073ef65f tests: do not run api tests twice in valgrind run.
These are run already just few lines above :)
2022-11-13 19:40:31 +01:00
Milan Broz
3e7c1e46fd tests: add source file dependence for fake tokens 2022-11-08 14:19:19 +01:00
Milan Broz
ea05e4307e tests: check that *.so token helpers are compiled. 2022-11-08 14:19:15 +01:00
Milan Broz
f35b9cc99b tests: do not use global CFLAGS for fake token helper.
Dynamic librarties cannot be linked with sanitizers this way,
just ignore CFLAGS here.
2022-11-08 14:19:11 +01:00
Milan Broz
d4888fba86 tests: compile fake_systemd_tpm_path.so through Makefile
Also fix Makefile to include source in make dist.

Note: we must not use CFLAGS there because possible sanitizers
use will make the loaded library unusable in LD_PRELOAD.
2022-11-08 14:19:04 +01:00
Milan Broz
f9e778a2cd luks2: fix warning undefined shift
Explicitly set uint32_t for shift, found by clang undefined
sanitizer.
Undefine shift cannot happen in reality, though.
2022-11-07 17:30:14 +00:00
Milan Broz
69025faa24 tests: Remove stray \" in grep expression. 2022-11-07 17:30:14 +00:00
Milan Broz
871000fa05 Fix a memory leak in crypt_keyslot_add_by_key.
Found by clang address sanitizer.

Also rename the variable - i's no longer a bare pointer,
the vk also owns the memory [okozina].
2022-11-07 17:30:14 +00:00
Milan Broz
cb53c643c2 CI: fix Debian build as pkfconf and pkg-config cannot co-exit.
Install pkgconf that is more recent and provides pkg-config too.
2022-11-04 20:28:08 +01:00
daniel.zatovic
f771f9a694 CI: install dependencies when running systemd test
Also update Debian to version 11.
2022-11-04 11:00:31 +01:00
daniel.zatovic
9009a2de26 CI: disable systemd tests on unsupported distributions 2022-11-04 11:00:31 +01:00
daniel.zatovic
6a279e21c9 Link compiled systemd to local libcryptsetup. 2022-11-04 11:00:31 +01:00
Christoph Anton Mitterer
124367f365 Add howto for converting printed to raw volume key
Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
2022-11-03 18:40:20 +00:00
Ondrej Kozina
55c39d7d16 Port crypt_volume_key_get internals to keyslot context variant. 2022-11-03 15:56:37 +01:00
Ondrej Kozina
f7e2ed956b Add crypt_volume_key_get_by_keyslot_context.
Extends avaiable methods for retrieving device volume key.
The volume key now may be extracted using passphrase, keyfile
(passphrase in a file) or token (LUKS2 only).

For LUKS devices, it returns generated volume key after
sucessfull crypt_format where new volume key got generated.

Fixes: #777.
2022-11-03 15:56:37 +01:00
Ondrej Kozina
0e6264c53c Do not cache volume key in keyslot context.
First, there was a bug where passphrase based
keyslot contextets did not cache volume keys
properly and caused leaks.

Second, it causes problems when keyslot context
is used twice with different keyslot id, e.g.:
CRYPT_ANY_SLOT vs specific id, unbound key vs
volume key, etc.
2022-11-02 12:22:25 +01:00
Ondrej Kozina
01c16111d7 Fix copy/paste mistakes in API docs. 2022-11-02 09:49:49 +01:00
daniel.zatovic
49ab658c9c CI: build and run fuzzers only conditionally 2022-10-31 20:47:23 +00:00
Milan Broz
888c6321df Do not compile systemd if running as systemd test as non-root. 2022-10-27 14:47:30 +02:00
Milan Broz
20f8c09195 Fix make dist to include systemd plugin test. 2022-10-27 14:38:23 +02:00
daniel.zatovic
57d4c677bd CI: add systemd-tpm2 token integration test. 2022-10-26 15:19:25 +02:00
Milan Broz
cde7b90735 fuzzing: Build OpenSSL with no-shared options
The -static option always disables threads, we want to use no-shared
build option instead.
2022-10-22 10:10:34 +00:00
Ondrej Kozina
3e4c69a017 Fix internal crypt segment compare routine.
The function is supposed to check if manipulated
active dm-crypt device matches the on-disk metadata.
Unfortunately it did not take into account differences
between normal cipher specification (aes-xts-plain64)
and capi format specification (capi:xts(aes)-plain64).
The internal query function always converted capi format
in normal format and therefor failed if capi format was
used in metadata.

Fixes: #759.
2022-10-20 14:24:11 +02:00
Ondrej Kozina
19c15a652f Copy also integrity string in legacy mode.
So that it handles integrity string same as it does
with cipher string.
2022-10-20 14:24:11 +02:00
Ondrej Kozina
2390395150 Code cleanup.
Type cast is not needed here.
2022-10-20 14:24:11 +02:00
Ondrej Kozina
9a9ddc7d22 Move cipher_dm2c to crypto utilities.
(Gets renamed to crypt_capi_to_cipher)
2022-10-20 14:24:02 +02:00
Ondrej Kozina
3616da631f Fix cipher convert routines naming confusion.
The function names were in fact swaped.
2022-10-20 14:23:48 +02:00
daniel.zatovic
b380fa7494 CI: Add fuzzer jobs. 2022-10-19 10:07:03 +02:00
Milan Broz
23f49eca43 Silent new keyslot option warning in tests.
After we introduced --new-key-slot option, just use it and
avoid CLI warning.
2022-10-18 15:51:11 +02:00
Milan Broz
00baa92756 fuzzing: Yet another dependency fix.
Previous fix breaks make dist. Let's set dependency
on object file explicitly.
2022-10-14 15:02:03 +02:00
daniel.zatovic
8bbb018a01 CI: Add Ubuntu 18.04 32bit job. 2022-10-14 09:27:27 +00:00
Milan Broz
c464d61995 fuzzing: Fix dependence issue
This patch avoids a race when running parallel jobs.
2022-10-14 06:48:32 +00:00
Milan Broz
d260ca6680 Fix api-test with older kernel. 2022-10-13 16:08:08 +02:00
Milan Broz
d05a2a6c99 fuzzing: Force dependence for generated header. 2022-10-10 12:32:10 +02:00
Milan Broz
758a2974f5 fuzzing: Clean up includes. 2022-10-09 12:59:57 +02:00
Milan Broz
4b5e814094 fuzzing: Remove unused code.
Also use C comments style in C-only file.
2022-10-09 12:36:52 +02:00
Milan Broz
98f5e0538a fuzzing: use ftruncate() instead of seeking to end of the file 2022-10-09 12:36:24 +02:00
Milan Broz
f03180d06a fuzzing: Simplify converters and used common defines for exit code. 2022-10-09 12:36:09 +02:00
Milan Broz
39b94ae530 fuzzing: Simplify plain JSON fuzzer. 2022-10-09 12:35:58 +02:00
Milan Broz
3690d5f532 fuzzing: Simplify proto fuzzer. 2022-10-09 12:35:20 +02:00
Milan Broz
e595940637 fuzzing: LLVMFuzzerTestOneInput must always return 0.
Also simplify the fuzzer function.
2022-10-09 12:34:26 +02:00
Milan Broz
dab939c3c9 fuzzing: Fix possible overflow in crypt2_load_fuzz.
Fixes OSS-Fuzz 52201.
2022-10-08 20:13:24 +02:00
daniel.zatovic
cc276527c7 fuzzing: Disable assembly in openssl build
Sanitizers can not instrument openssl's assembly and wrongly report
buffers from openssl as uninitialized.
2022-10-06 23:23:06 +02:00
Milan Broz
27429daf5d Fix typo. 2022-10-05 09:49:55 +02:00
Milan Broz
b20821a520 Fuzzing: disable po4a in static library dependence build as it seems to freeze. 2022-10-04 23:42:07 +02:00
Milan Broz
46b465ff2e Use upstream git for protobuf-mutator as required patches are merged now. 2022-10-04 13:10:36 +02:00
Milan Broz
d8fd9caa6a Add missing files to Makefile.am (and reformat lists). 2022-10-04 13:00:38 +02:00
daniel.zatovic
dad11f97ce Copy only selected fuzzers to out directory. 2022-10-04 13:00:33 +02:00
daniel.zatovic
c06e853938 Fix missing prototypes by adding a header file. 2022-10-04 13:00:29 +02:00
daniel.zatovic
c35e4479d5 Update fuzzing README 2022-10-04 13:00:25 +02:00
daniel.zatovic
8585fb29eb Add dictionary for the plain JSON fuzzer. 2022-10-04 13:00:21 +02:00
daniel.zatovic
97b3926655 Fix potential integer underflow. 2022-10-04 13:00:18 +02:00
Milan Broz
a3f248df9b Fix some clang++ warnings. 2022-10-04 13:00:15 +02:00
Milan Broz
e1a84607cc Rework build of fuzzers.
- Do not require any libraries installed, download everything
from upstream git, statically compile (use include, libs and pkg-config
from local directory under tests/fuzz).
Script should work both from OSS-Fuzz and locally.

- Do not require local protobuf (only staticallly compiled, see above).

- Add README.md (TBD, still not finished).

- Fix make dist and distcheck.

- Remove common.[ch] as we can use internal function.
  This makes fuzzers also C++ only (remove CFLAGS from Makefile).
2022-10-04 13:00:10 +02:00
daniel.zatovic
2f4267ba81 Add plain JSON metadata fuzzing 2022-10-04 12:59:07 +02:00
daniel.zatovic
99e8ee6b7e Add checks for compiler when building fuzz targets. 2022-10-04 12:59:04 +02:00
daniel.zatovic
f58aff21a9 Add fuzz targets, custom mutator and fuzzing dictionary 2022-10-04 12:58:59 +02:00
Milan Broz
de8a27ae02 Print a visible error in LUKS2 if AF hash is not available.
In LUKS1 there is only one hash algorithm specification,
it cannot happen, that AF hash algorithm is not
available, as it is used immediately before in PBKDF2.

In LUKS2 this can be completely different algorithm, so
it make sense to print a visible warning for user.

For example, Whirlpool and RIPEMD160 is now in OpenSSL legacy
provider which can be unavailable, see #773.)

This patch adds a message only, the code already fails with -EINVAL.
2022-10-03 10:33:32 +02:00
Milan Broz
b9b08eba7c Fix function prototype (and build for 32bit system). 2022-10-03 09:57:40 +02:00
Milan Broz
82b56300cd Wrap some very long lines. 2022-10-01 22:35:57 +02:00
Milan Broz
9f8fe3da16 Fix some typos. 2022-10-01 22:35:52 +02:00
Ondrej Kozina
50803ebacb Switch existing keslot adding API to new extension. 2022-09-29 17:31:29 +02:00
Ondrej Kozina
5fce0c2ad1 Extend luksAddKey action options via crypt_keyslot_add_by_keyslot_context API.
In practice luksAddKey action does two operations. It unlocks existing
device volume key and stores unlocked volume key in a new keyslot.
Previously the options were limited to key files and passphrases.
With this patch user may combine freely following options:

To unlock keyslot with volume key user may:
- provide existing passphrase via interactive prompt (default method)
- use --key-file option to provide file with a valid passphrase to existing keyslot
- provide volume key directly via --volume-key-file
- unlock keyslot via all available LUKS2 tokens by --token-only
- unlock keyslot via specific token with --token-id
- unlock keyslot via specific token type by --token-type

To provide the passphrase for a new keyslot user may:
- provide existing passphrase via interactive prompt (default method)
- use --new-keyfile parameter or positional parameter to read the
  passphrase from file.
- use --new-token-id to select specific LUKS2 token to get passphrase
  for new keyslot. New keyslot is assigned to selected token id if
  operation is succesfull.

Fixes: #725.
2022-09-29 17:31:29 +02:00
Ondrej Kozina
2e29eb7906 cryptsetup-luksAddKey man page cleanup. 2022-09-22 17:45:20 +02:00
Ondrej Kozina
b867f0b578 Add new API for adding new LUKS keyslots.
The crypt_keyslot_add_by_keyslot_context & associated
helper functions allow more options when adding new
keyslot. For example there was no simple way of
adding new LUKS2 keyslot when the only active keyslot
could be unlocked by passphrase (KEK) provided by LUKS2 token
(plugin). Now all available options for unlocking keyslots
may also be used when creating new keyslot and it combine
as called needs.

The available methods (keyslot contexts) are:
passphrase, keyfile, key (binary representation) and LUSK2 token.
2022-09-21 17:36:28 +02:00
Milan Broz
1745fd5aea Fix missing va_end macro in test error path. 2022-09-19 12:46:42 +00:00
Ondrej Kozina
90ad841a45 Add cryptsetup token unassign action.
Allows removing token binding on specific keyslot.
2022-09-16 14:34:28 +02:00
Ondrej Kozina
0397cac878 Abort assigning tokens with invalid parameters earlier. 2022-09-16 13:30:39 +02:00
Ondrej Kozina
033ff34109 Enable adding unassigned luks2-keyring token in cryptsetup.
There was no easy way to add unassigned luks2-keyring token.
Reuse --unbound parameter for it.
2022-09-16 12:34:32 +02:00
Ondrej Kozina
0d61e4c20f Clarify --unbound usage in man pages. 2022-09-16 12:32:24 +02:00
Milan Broz
b4863897fe Fix verity-compat-test if running with different locale. 2022-09-06 21:55:37 +02:00
Ondrej Kozina
eac02f5605 Fix NULL key_description bug in luks2-keyring token.
json-c parser transforms NULL pointer into special '(null)' string.
While being technically correct it hides the fact user passed NULL
pointer in crypt_token_params_luks2_keyring structure. This bug
could be trigerred by calling crypt_token_luks2_keyring_set().
2022-09-01 15:38:49 +02:00
daniel.zatovic
94e8a7ca96 Fix valgrind in SSH token test. 2022-08-25 08:02:37 +00:00
Milan Broz
b183bb25e2 Add support for dm-verity try_verify_in_tasklet option.
Available since kernel 6.0.
2022-08-25 08:01:07 +00:00
Ondrej Kozina
09ac5321f4 Fix memory leak in ssh token example. 2022-08-23 15:53:25 +02:00
Milan Broz
c1302555b7 Provide pkgconfig Require.private.
While we do not completely provides static build on udev
systems, having theses modules in pkgconfig can be useful otherwise.
2022-08-23 12:06:07 +00:00
Ondrej Kozina
01c032df04 Do not reload LUKS2 metadata when not necessary.
Following API calls trigerred LUKS2 metadata reload
from storage in case of failure:

crypt_convert
crypt_keyslot_add_by_key
crypt_keyslot_add_by_keyfile_device_offset
crypt_keyslot_add_by_passphrase
crypt_keyslot_change_by_passphrase
crypt_reencrypt_init_by_keyring
crypt_reencrypt_init_by_passphrase

This patch replaces LUKS2 metadata reload with
backup LUKS2 metadata copy kept in memory that is updated on
each sucessfull metadata write and rolled back to it whenever
needed in any of those calls listed above.
2022-08-19 14:46:42 +02:00
Milan Broz
88d9524e6c Mark crypt_memory_lock() API call deprecated.
And remove its implementation.
2022-08-16 19:56:32 +02:00
Milan Broz
4b47091b85 Remove call to explicit memlockall from cryptsetup.
Memory with keys is now locked per range.
2022-08-16 19:56:28 +02:00
Milan Broz
b9bf657449 Set process priority only for PBKDF benchmark.
Do not increase priority for the whole run, only
increase it when we calculate PBKDF paramaters.
2022-08-16 19:56:24 +02:00
Milan Broz
21d87a246e Do not use safe_malloc for LUKS header backup.
The content of LUKS header is not a key material, no need
to lock memory for possibly big header and big memory area locks.

Just ensure we wipe buffer before release of memory.
2022-08-16 19:56:20 +02:00
Milan Broz
db65a5ceac Lock memory in crypt_safe alloc functions.
This patch locks all memory ranges in safe allocations.

While crypto backend can have some secure memory calls,
it is usually limited by intitial config.

For our use is enough to keep keys in memory and prevent
swapping it out.

If the lock fails (because of limits) we quietly
stay with plain malloc.
2022-08-16 19:56:00 +02:00
daniel.zatovic
132027bafa Force probe in tests instead of lsblk which can use udev cache. 2022-08-11 21:26:03 +02:00
daniel.zatovic
f6fd73aea5 Add FIPS checks before running tests in FIPS mode. 2022-08-10 11:37:25 +00:00
Ondrej Kozina
5b001b7962 Delegate FIPS mode detection to configured crypto backend.
System FIPS mode check is no longer dependent on /etc/system-fips
file. The change should be compatible with older distributions since
we now depend on crypto backend internal routine.

This commit affects only FIPS enabled systems (with FIPS enabled
builds). In case this causes any regression in current distributions
feel free to drop the patch.

For reference see https://bugzilla.redhat.com/show_bug.cgi?id=2080516
2022-08-10 10:53:39 +02:00
daniel.zatovic
429afe8fc3 Add valgrind support to more tests. 2022-08-10 07:45:13 +00:00
Milan Broz
abfb5e374f Remove leftover debug option in test. 2022-08-09 22:54:43 +02:00
daniel.zatovic
f8c79f9a95 Fix valgrind summary leak detection.
Currently, only 1-9 leaks are detected. More than 10 leaks are evaluated
as no leak.
2022-08-05 16:38:38 +02:00
Milan Broz
190e4fc033 Always update automake library files if autogen.sh is run.
Fixes: #761
2022-08-01 08:47:34 +00:00
Ondrej Kozina
093adfc5f9 Fix user defined moved segment size in LUKS2 decryption.
--hotzone-size argument was ignored in cases where actual data size
was less than original LUKS2 data offset.
2022-08-01 07:05:06 +00:00
Milan Broz
a009614191 Set devel version. 2022-07-30 09:29:00 +02:00
Milan Broz
75111d382b Version 2.5.0. 2022-07-28 17:32:33 +02:00
Yuri Kozlov
1cc6c82f21 po: update ru.po (from translationproject.org) 2022-07-28 17:32:04 +02:00
Frédéric Marchal
2c555bd4a0 po: update fr.po (from translationproject.org) 2022-07-28 17:32:04 +02:00
Roland Illig
3f3f5a6aab po: update de.po (from translationproject.org) 2022-07-28 17:32:04 +02:00
Ondrej Kozina
c6ed1becd7 Fix bogus conditions in tests.
Do not test for dm-crypt versions not supported
by upstream kernels.
2022-07-28 17:18:57 +02:00
Milan Broz
766ac108ec Fix option descriptions and lists mentioned in man pages. 2022-07-28 10:51:22 +00:00
Milan Broz
94e5d227ce Fix warning messages if some kernel option is not supported.
Thus was broken by commit
  "Check if DM create device failed in an early phase."
  10b1d6493e

Also we should set EINVAL if we detect unsuported option.
2022-07-28 10:50:55 +00:00
Ondrej Kozina
f96e19147c Add prompt for LUKS2 decryption with header export. 2022-07-28 12:50:13 +02:00
Ondrej Kozina
05dbf04d82 Add early warning for reencryption of image files. 2022-07-28 12:47:10 +02:00
Ondrej Kozina
b9b7c3a9bd Add detached header warning in reencrypt man page. 2022-07-28 10:41:20 +00:00
Ondrej Kozina
17e6d2053a Add mangle tests for LUKS2 decryption with datashift. 2022-07-28 07:57:36 +00:00
Ondrej Kozina
912109ae66 Improve reencryption parameters verification in cli.
Try to catch as many invalid parameters as possible
before entering library call.
2022-07-28 07:57:36 +00:00
Ondrej Kozina
25b877a403 Fix bug in reencryption parameters verification. 2022-07-28 07:57:36 +00:00
Milan Broz
8270b72bfc Use bool instead od int in LUKS1 reencryption context. 2022-07-27 12:01:11 +02:00
Milan Broz
9c0cdcc2f9 Do not use huge LUKS1 reencryption context on heap.
This will reduce cryptsetup tool size (~20kB at least).
2022-07-27 11:57:05 +02:00
Milan Broz
1e2cb2d419 Avoid using huge dummy context in LUKS1 reencryption check.
This struct is not needed at all, just use NULL.
2022-07-27 11:47:06 +02:00
Guilhem Moulin
3e178caeaf Document more supported options in cryptsetup-luksResume(8).
`cryptsetup luksResume --disable-external-tokens --keyfile-offset 123`
does work but these options weren't documented.
2022-07-21 02:29:05 +02:00
Guilhem Moulin
803957cd3e Add support for --key-slot in luksResume action. 2022-07-20 20:00:09 +02:00
Milan Broz
bf4bfeac8a Rename some tests to simplify localtest parsing. 2022-07-18 15:09:28 +02:00
Milan Broz
090dca635a Add ssh-test-plugin to localtest if RUN_SSH_PLUGIN_TEST is set. 2022-07-18 11:16:23 +02:00
Milan Broz
0369ffdcc1 Rename ssh plugin test to ssh-test-plugin.
So we can filter it out in local tests
(*-test means generic tests, *-test-plugin specific plugin tests).
2022-07-18 09:11:23 +02:00
Milan Broz
648a85ed3a Unify use of tabulators in tests. 2022-07-16 19:14:31 +00:00
Milan Broz
8f3884e0d7 Change default target for Makefile.localtest. 2022-07-16 19:14:31 +00:00
Guilhem Moulin
289d5e5891 Add unit-utils-crypt-test to Makefile.localtest's list of tests.
This requires (re-)building the executable with -DNO_CRYPTSETUP_PATH.
Only in that case do we allow the test to run under non-empty
$CRYPTSETUP_PATH.
2022-07-16 19:14:31 +00:00
Guilhem Moulin
b37d04975d Add compat-test-args to Makefile.localtest's list of tests. 2022-07-16 19:14:31 +00:00
Guilhem Moulin
6578dac2f9 Add blockwise-compat to Makefile.localtest's list of tests.
This requires (re-)building `unit-utils-io` with -DNO_CRYPTSETUP_PATH.
Only in that case do we allow the test to run under non-empty
$CRYPTSETUP_PATH.
2022-07-16 19:14:31 +00:00
Guilhem Moulin
dc5f284e42 blockwise-compat: Wait a bit so scsi_debug has a chance to fully initialize.
Similar to a76c96d361.  See also !386.
2022-07-16 19:14:31 +00:00
Guilhem Moulin
32149e4ee7 blockwise-compat: Make skip() exit with status 77.
This is mostly useful under TESTSUITE_NOSKIP=y.
2022-07-16 19:14:31 +00:00
Guilhem Moulin
0e4857ee81 unit-wipe-test: Make skip() exit with status 77.
This is mostly useful under TESTSUITE_NOSKIP=y.
2022-07-16 19:14:31 +00:00
Milan Broz
06dd06ea27 tests: allow unit-wipe-test to run with local tests. 2022-07-16 19:14:31 +00:00
Milan Broz
03eb8f860a tests: check for differ existence in compat-test. 2022-07-16 19:14:31 +00:00
Guilhem Moulin
fbcef71c41 Pass $(LDFLAGS) when building fake_token_path.so.
The Debian tooling sets ‘LDFLAGS = -Wl,-z,relro -Wl,-z,now’ and
complains when anything is built without hardened compiler/linker flags.

Granted this is a non-issue here since fake_token_path.so isn't included
in any binary package, but muting the false positive is arguably no
better fix than honoring $(LDFLAGS) during the build.
2022-07-16 13:51:11 +02:00
Milan Broz
8315ada3b0 Fix wipe unit test if direct-io not available.
If test is run in tmpfs, direct-io is not supported.

Thanks Guilhem Moulin for reporting the issue.
2022-07-15 21:50:21 +02:00
Yuri Chornoivan
782dae9292 po: update uk.po (from translationproject.org) 2022-07-15 20:15:48 +02:00
Jakub Bogusz
96c0544527 po: update pl.po (from translationproject.org) 2022-07-15 20:15:48 +02:00
Hiroshi Takekawa
cb7e2c6433 po: update ja.po (from translationproject.org) 2022-07-15 20:15:48 +02:00
Petr Pisar
f0da65cc63 po: update cs.po (from translationproject.org) 2022-07-15 20:15:48 +02:00
Guilhem Moulin
a76c96d361 unit-wipe-test: Wait a bit so scsi_debug has a chance to fully initialize.
On my test system `tests/unit-wipe-test` fails (as root) due to a race
condition in add_device():

	root@host:~# ./unit-wipe-test
	[1] Wipe full file [0/DIO][0][1048576/DIO][1048576][4194304/DIO][4194304][OK]
	[2] Wipe blocks in file [0/DIO][0][1048576/DIO][1048576][4194304/DIO][4194304][OK]
	[  105.828258] scsi_debug:sdebug_driver_probe: scsi_debug: trim poll_queues to 0. poll_q/nr_hw = (0/1)
	[  105.830450] scsi host2: scsi_debug: version 0191 [20210520]
	[  105.830450]   dev_size_mb=8, opts=0x0, submit_queues=1, statistics=0
	[  105.832924] scsi 2:0:0:0: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
	[  105.835417] scsi 2:0:0:0: Attached scsi generic sg1 type 0
	FAIL Cannot find /dev/.
	FAILED backtrace:
	48 ./unit-wipe-test
	144 main ./unit-wipe-test
	[  105.875131] sd 2:0:0:0: Power-on or device reset occurred
	[  105.876069] sd 2:0:0:0: [sda] 16384 512-byte logical blocks: (8.39 MB/8.00 MiB)
	[  105.877190] sd 2:0:0:0: [sda] Write Protect is off
	[  105.878002] sd 2:0:0:0: [sda] Write cache: enabled, read cache: enabled, supports DPO and FUA
	[  105.879619] sd 2:0:0:0: [sda] Optimal transfer size 524288 bytes
	[  105.914222] sd 2:0:0:0: [sda] Attached SCSI disk
	[  106.866296] sd 2:0:0:0: [sda] Synchronizing SCSI cache

Observe how the “Power-on or device reset occurred” event occurs only
after add_device() has returned.  Interestingly, for subsequent runs the
delay appears to be much shorter and doesn't trigger the race condition:

	root@host:~# ./unit-wipe-test
	[1] Wipe full file [0/DIO][0][1048576/DIO][1048576][4194304/DIO][4194304][OK]
	[2] Wipe blocks in file [0/DIO][0][1048576/DIO][1048576][4194304/DIO][4194304][OK]
	[  130.639855] scsi_debug:sdebug_driver_probe: scsi_debug: trim poll_queues to 0. poll_q/nr_hw = (0/1)
	[  130.641463] scsi host2: scsi_debug: version 0191 [20210520]
	[  130.641463]   dev_size_mb=8, opts=0x0, submit_queues=1, statistics=0
	[  130.643809] scsi 2:0:0:0: Direct-Access     Linux    scsi_debug       0191 PQ: 0 ANSI: 7
	[  130.645342] sd 2:0:0:0: Power-on or device reset occurred
	[  130.646364] sd 2:0:0:0: [sda] 16384 512-byte logical blocks: (8.39 MB/8.00 MiB)
	[  130.647585] sd 2:0:0:0: [sda] Write Protect is off
	[  130.648428] sd 2:0:0:0: Attached scsi generic sg1 type 0
	[  130.649339] sd 2:0:0:0: [sda] Write cache: enabled, read cache: enabled, supports DPO and FUA
	[  130.650763] sd 2:0:0:0: [sda] Optimal transfer size 524288 bytes
	[  130.682223] sd 2:0:0:0: [sda] Attached SCSI disk
	[3] Wipe full block device [0/DIO][0][1048576/DIO][1048576][4194304/DIO][4194304][OK]
	[4] Wipe blocks in block device [0/DIO][0][1048576/DIO][1048576][4194304/DIO][4194304][OK]
	[  137.858283] sd 2:0:0:0: [sda] Synchronizing SCSI cache

This commit adds an optional 2s delay if scsi_debug hasn't shown up in
sysfs after the modprobe call.
2022-07-15 18:13:37 +00:00
Guilhem Moulin
3106b4e2c1 More typo and spelling fixes.
Reported by `git ls-tree -rz --name-only | grep -Evz -e '\.(pdf|xz)$' -e
^po/ | xargs -r0 spellintian --`.  All changes are
documentation-related (comments, manuals, etc.) except for s/fial/fail/
in tests/unit-wipe-test.

The remaining entry are AFAICT all false positives, mostly annotations
such as `@param name name of xyz` or `struct foo foo`:

	$ git ls-tree -rz HEAD --name-only | grep -Evz -e '\.(pdf|xz)$' -e ^po/ | xargs -r0 spellintian --
	COPYING.LGPL: "GNU Library Public License" -> "GNU Library General Public License"
	autogen.sh: echo echo (duplicate word) -> echo
	configure.ac: fi fi (duplicate word) -> fi
	docs/v1.7.2-ReleaseNotes: option option (duplicate word) -> option
	lib/crypto_backend/cipher_check.c: block block (duplicate word) -> block
	lib/libcryptsetup.h: name name (duplicate word) -> name
	lib/libcryptsetup.h: type type (duplicate word) -> type
	lib/libcryptsetup.h: passphrase passphrase (duplicate word) -> passphrase
	lib/libcryptsetup.h: flags flags (duplicate word) -> flags
	lib/libcryptsetup.h: password password (duplicate word) -> password
	lib/libcryptsetup.h: salt salt (duplicate word) -> salt
	lib/libcryptsetup.h: keyslot keyslot (duplicate word) -> keyslot
	lib/libcryptsetup.h: priority priority (duplicate word) -> priority
	lib/libcryptsetup.h: offset offset (duplicate word) -> offset
	lib/libcryptsetup.h: length length (duplicate word) -> length
	lib/libcryptsetup.h: keyfile keyfile (duplicate word) -> keyfile
	lib/libcryptsetup.h: token token (duplicate word) -> token
	lib/libcryptsetup.h: cipher cipher (duplicate word) -> cipher
	lib/libcryptsetup.h: size size (duplicate word) -> size
	lib/luks2/luks2_json_metadata.c: long long (duplicate word) -> long
	lib/luks2/luks2_keyslot_luks2.c: AFEKSize AFEKSize (duplicate word) -> AFEKSize
	lib/luks2/luks2_reencrypt.c: alignment alignment (duplicate word) -> alignment
	lib/luks2/luks2_reencrypt_digest.c: ptr ptr (duplicate word) -> ptr
	lib/luks2/luks2_reencrypt_digest.c: buffer buffer (duplicate word) -> buffer
	lib/luks2/luks2_segment.c: min min (duplicate word) -> min
	lib/verity/verity_fec.c: blocks blocks (duplicate word) -> blocks
	man/cryptsetup.8.adoc: LUKS LUKS (duplicate word) -> LUKS
	scripts/cryptsetup.conf.in: root root (duplicate word) -> root
	src/Makemodule.am: endif endif (duplicate word) -> endif
	src/cryptsetup.c: long long (duplicate word) -> long
	src/utils_args.c: long long (duplicate word) -> long
	tests/compat-test2: fi fi (duplicate word) -> fi
	tests/device-test: echo echo (duplicate word) -> echo
	tests/differ.c: long long (duplicate word) -> long
	tests/loopaes-test: done done (duplicate word) -> done
	tests/luks2-integrity-test: aead aead (duplicate word) -> aead
	tests/luks2-reencryption-test: fi fi (duplicate word) -> fi
	tests/mode-test: done done (duplicate word) -> done
	tests/password-hash-test: cat cat (duplicate word) -> cat
	tests/password-hash-test: fi fi (duplicate word) -> fi
	tests/unit-wipe.c: long long (duplicate word) -> long
	tests/verity-compat-test: done done (duplicate word) -> done
	tests/verity-compat-test: fi fi (duplicate word) -> fi
	tokens/ssh/cryptsetup-ssh.c: argp argp (duplicate word) -> argp
	tokens/ssh/cryptsetup-ssh.c: arguments arguments (duplicate word) -> arguments

(Treated COPYING.LGPL as a false positive too since it's the exact text
from https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html .)
2022-07-15 16:35:02 +02:00
Guilhem Moulin
5d711c000f Fix minor spelling errors.
(Found by Lintian.)
2022-07-15 12:16:39 +02:00
Milan Broz
bf2e48e404 Version 2.5.0-rc1. 2022-07-14 16:00:01 +02:00
Ondrej Kozina
d943b2efb9 Clarify cryptsetup-open options in man page. 2022-07-14 13:51:37 +00:00
Milan Broz
02d5c5ce38 Add 2.5.0-rc1 Release Notes. 2022-07-14 14:10:33 +02:00
Milan Broz
bdc97ef389 Update cryptsetup.pot. 2022-07-14 14:09:45 +02:00
Milan Broz
6540ffd1a6 Fix spacing with man footer by adding space.
So it is always separate section.
2022-07-14 09:42:04 +02:00
Milan Broz
c7a8c9a620 Always regenerate man pages if source file changes. 2022-07-14 09:42:01 +02:00
Milan Broz
d96dcff883 Set 2.5.0-rc1 version. 2022-07-13 21:13:07 +02:00
Milan Broz
4034c548c2 Update LUKS2 on-disk description. 2022-07-13 21:13:07 +02:00
daniel.zatovic
8eff391a66 Regenerate manual pages using AsciiDoctor in spec file. 2022-07-13 21:08:17 +02:00
daniel.zatovic
dae6aa0384 Obsolete cryptsetup-reencrypt and add manual pages to spec file.
The cryptsetup-reencrypt utility is now replaced by reencrypt action.
New per-action manual pages have been added.
2022-07-13 21:08:15 +02:00
daniel.zatovic
a2afe0396f Split manual pages into per-action page and use AsciiDoc format
Use pre-generated man pages in make dist.

[Added fixes and updates from Ondrej Kozina and Milan Broz]
2022-07-13 21:08:02 +02:00
daniel.zatovic
fec2517386 CI: enable Asciidoctor 2022-07-13 16:03:35 +02:00
Ondrej Kozina
c413434715 Add error message for failed in-use auto-detect.
When reencrypting image files cryptsetup is unable to
detect reliably if image file is in use or not.

User must decide it explictly. Add error message that
references --force-offline-reencrypt to solve the issue
in non interactive mode.

(It will be replaced with early detection in before 2.5.0 final
release).
2022-07-13 10:56:17 +00:00
Milan Broz
aa126ac10a Remove dracut plugin that is obsolete and will not work with current reencrypt code. 2022-07-12 17:58:48 +00:00
Ondrej Kozina
56d4e9924e Add LUKS2 reencryption mangle tests. 2022-07-12 14:05:03 +02:00
Ondrej Kozina
a60fd0a81b Do not fail LUKS2 validation by newer online-reencrypt requirement.
Do not invalidate LUKS2 format when future online-reencrypt
requirement flag is encountered (by older releases).
But it must stop device from being activated, reencrypted
or modified.
2022-07-12 14:05:03 +02:00
Ondrej Kozina
af68e8a1da Check for multiple online reencrypt requirement flags.
Having multiple online-reencrypt requirements flags
candidate in config section should invalidate LUKS2
metadata.
2022-07-12 14:05:03 +02:00
Ondrej Kozina
13f6dfa61f Add proper version data to reencryption verification digest.
LUKS2 decryption requires new online-reencrypt version
flag (v3).

The verification digest performs coding
for version suffix in "online-reencrypt-v" flag string
as follows:

'v1' :  unused (no digest)
'v2' :  0x30 + 2   = 0x32 = '2'
'v3' :  0x30 + 3   = 0x33 = '3'
(...)
'v10':  0x30 + 10  = 0x3A = ':'
'v11':  0x30 + 11  = 0x3B = ';'
(...)
'v207': 0x30 + 207 = 0xFF
2022-07-12 14:03:25 +02:00
Ondrej Kozina
8493f6afd5 Change size of requirement version to 1 byte.
Mostly due to reencryption verification routine
currently expects only single byte of version
data to create digest from.
2022-07-12 13:54:24 +02:00
Milan Broz
1a55b69a0f Fix leak of dm target structure.
The dmd_source need to be cleared with dm_targets_free().
2022-07-07 09:17:13 +00:00
Milan Broz
914f621251 Do not use uninitialized memory for cipher check.
We do not care about the bufer content, but valgrind do, just wipe
the buffer before test.
2022-07-07 09:17:13 +00:00
Milan Broz
5904516122 Skip reencryption test if required ciphers are not available in userspace.
This happens for some very old systems like CentOS6 or own compiled
crypto libraries.
2022-07-05 15:08:43 +02:00
Milan Broz
4507ced868 Report failure if userspace cannot use specified cipher.
Reencryption require support both for kernel and userspace library.

If only kernel supports the copher, the error was quiet.
2022-07-05 15:07:33 +02:00
Milan Broz
b4603f1e28 Fix valgrind test in compat-test. 2022-07-04 14:34:04 +02:00
Petr Pisar
1c21c24f7b po: update cs.po (from translationproject.org) 2022-07-04 09:36:22 +02:00
Ondrej Kozina
0009d9532e Extend LUKS2 decryption with datashift API tests. 2022-06-30 11:21:38 +02:00
Ondrej Kozina
47cb9b0ee2 Fix copy&paste mistake in exclusive open comment. 2022-06-27 16:01:50 +02:00
Ondrej Kozina
0ffd105cb8 Harden LUKS2 decryption with datashift parameters.
Abort early if detached header is passed in API
by any chance.
2022-06-27 16:01:50 +02:00
Ondrej Kozina
24d498e393 Add debug message in LUKS2 reencryption initialization. 2022-06-27 16:01:50 +02:00
Ondrej Kozina
3c8b3201d7 Improve crypt_reencrypt_status return values.
Empty context or any non-LUKS types now returns
CRYPT_REENCRYPT_INVALID value.

For LUKS1 devices return CRYPT_REENCRYPT_NONE
(since any LUKS1 device in legacy reencryption
does not have valid LUKS1 header/metadata).
2022-06-27 16:01:50 +02:00
Ondrej Kozina
f531b567e0 Test reencryption initalization error path.
Test cli behaves properly when there's not enough
space in keyslots area for new unbound keyslot or
reencryption keyslot.

Fixes: #688.
2022-06-27 16:01:43 +02:00
Jakub Bogusz
7c76881921 po: update pl.po (from translationproject.org) 2022-06-24 15:19:10 +02:00
Milan Broz
f642417ed7 Add check to LUKS1 convert for segments count. 2022-06-23 07:24:27 +02:00
Milan Broz
1c1df24258 Clean up convert code style.
Remove FIXMEs and comment style.
2022-06-23 07:10:22 +02:00
Milan Broz
b3e8e1a9d4 Log visible error if convert fails due to validation check 2022-06-23 07:08:42 +02:00
Milan Broz
d22b003640 Fix possible keyslot area size overflow during convert to LUKS2
If keyslots are not sorted according to binary area offset,
the calculation of area size is wrong and can overflow
(LUKS1 does not store area size, only offset).

Let's just use function that calculates size from volume key size.
Images where keyslot areas are not aligned to 4k offset
are not supported anyway.

Fixes: #753
2022-06-23 07:06:38 +02:00
Ondrej Kozina
a485f44b57 Fix decryption with datashift initialization.
It did not work with --active-name option for
active LUKS2 devices.
2022-06-21 15:27:43 +02:00
Ondrej Kozina
f182d73001 Speed up reencryption tests.
By not testing repeatedly that 'wipe' test utility actually
wipes the device. This test is supposed to test reencryption
code.

I have left untouched already existing first time checks
for each data digest.
2022-06-21 10:47:42 +02:00
Yuri Chornoivan
05fc7b172d po: update uk.po (from translationproject.org) 2022-06-20 17:30:20 +02:00
Hiroshi Takekawa
66c5b52b42 po: update ja.po (from translationproject.org) 2022-06-20 17:30:20 +02:00
Frédéric Marchal
af3559a0f6 po: update fr.po (from translationproject.org) 2022-06-20 17:30:20 +02:00
Roland Illig
bcde337a42 po: update de.po (from translationproject.org) 2022-06-20 17:30:20 +02:00
Yuri Chornoivan
83103627b2 Fix minor typo.
Fixes: #752
2022-06-20 11:37:44 +00:00
Milan Broz
8f8703f1c3 Update cryptsetup.pot. 2022-06-17 19:58:31 +02:00
Milan Broz
857d17d210 Fix makefile to include wipe-test in dist tarball. 2022-06-17 19:57:31 +02:00
Milan Broz
62a3954c9d Add a debug message after crypt_load in error path. 2022-06-17 19:30:35 +02:00
Milan Broz
c72aecf86d Add comment to validation code. 2022-06-17 16:08:52 +02:00
Milan Broz
d9b66afe5e Replace json_bool with stdbool.
This is some relict from old code, just use bool, we already
require it elsewhere.
2022-06-17 16:04:31 +02:00
Milan Broz
18ada2b7de Check for interval overflow in LUKS2 validation code.
Invalid values that overflows in interval check were silently ignored.

Fix this by explictily adding check for interval overflow in keyslots
and segment validation.

Fixes: #748
2022-06-17 16:03:32 +02:00
Milan Broz
279490b622 Add test for keyslot area overflow during validation. 2022-06-17 16:03:32 +02:00
Milan Broz
dfd96d8a39 Report uint64 overflows and conversion errors in log debug during LUKS2 validate. 2022-06-17 16:03:30 +02:00
Milan Broz
ba9e36ceae Add empty string check to LUKS2 JSON validation.
Most of the LUKS2 fields cannot be empty,
add check for JSON validation for it to fail early.

Fixes: #746
2022-06-17 14:46:50 +02:00
Ondrej Kozina
f97af5dcfe Add LUKS2 decryption with datashift tests. 2022-06-17 13:48:15 +02:00
Ondrej Kozina
b4e9bca354 Enable LUKS2 decryption datashift support in cli.
Fixes: #669.
2022-06-17 13:48:12 +02:00
Ondrej Kozina
c36f9899cf Add support for LUKS2 decryption with datashift.
Adds support for LUKS2 decryption of devices with a
header put in the head of data device. During the initialization
header is exported to a file and first data segment
is moved to head of data device in place of original header.

The feature introduces several new resilience modes (combination
of existing modes datashift and "checksum" or "journal").
Where datashift resilience mode is applied for data moved towards
the first segment and first segment is decrypted in-place.

The mode is not backward compatible with prior LUKS2 reencryption
and therefor interrupted operation in progress can not be resumed
using older cryptsetup releases.

Fixes: #669.
2022-06-17 13:48:12 +02:00
Ondrej Kozina
f3a46b8e93 Check user provided correct passphrase before initializing decryption.
It would fail later anyway (due to wrong passphrase provided) but
it's better to stop sooner.
2022-06-17 13:48:12 +02:00
Ondrej Kozina
b84132c140 Wrap some long lines. 2022-06-17 13:48:12 +02:00
Ondrej Kozina
90ff707bff Move load_luks2_by_name helper. 2022-06-17 13:48:12 +02:00
Ondrej Kozina
f00d897240 Wipe unused area after reencryption with datashift in forward direction. 2022-06-17 13:48:12 +02:00
Ondrej Kozina
daa2b60d62 Sync signature wipes in tools_wipe_all_signutares. 2022-06-17 13:48:12 +02:00
Ondrej Kozina
4892b24d6a Add options parameters to tools_wipe_all_signatures routine. 2022-06-17 13:47:48 +02:00
Ondrej Kozina
369a18cd3b Rename sector size related variables. 2022-06-14 17:11:25 +02:00
Ondrej Kozina
2240e75bb9 Add proper error message for invalid device_size reencryption argument. 2022-06-14 15:31:52 +02:00
Ondrej Kozina
3a4e38736c Rename variable used to store total reencryption data size. 2022-06-14 15:31:52 +02:00
Ondrej Kozina
dff34a1251 Check datashift value against larger sector size.
For example it could cause an issue if misaligned to 4K sector
size during decryption.
2022-06-14 15:31:52 +02:00
Ondrej Kozina
c08aa21a93 Move datashift alignment verification to reencrypt_verify_resilience_params. 2022-06-14 15:31:52 +02:00
Ondrej Kozina
cbf82733ae Clarify error message about invalid datashift value. 2022-06-14 15:31:52 +02:00
Ondrej Kozina
75e429b8d1 Simplify LUKS2 sector_size helpers. 2022-06-14 15:31:52 +02:00
Ondrej Kozina
e23992d531 Fix bug in json_segment_get_sector_size.
Upper layers always expected 0 on error.
Due to this bug this function could cause
sector_size overflow when segment definition
did not contain 'sector_size' field ('linear').
2022-06-14 15:31:52 +02:00
Milan Broz
f881092bbc tcrypt: fix EPERM return code
If some kdf are not available, we incuidentally returned EINVAL
error code instead od EPERM.

This caused that error message is not correctly printed and also
retry count is not applied.

Fixes: #745.
2022-06-13 12:45:22 +02:00
Ondrej Kozina
ba37298e4f Add debug message in validation code for missing key digest. 2022-06-09 12:03:14 +02:00
Ondrej Kozina
98ca9c61d6 Add new internal state marking resilience type as not set. 2022-06-09 12:03:14 +02:00
Ondrej Kozina
ee5a7d19c9 Simplify reencrypt_update_flag usage due to version support. 2022-06-09 12:03:14 +02:00
Ondrej Kozina
7b4d5fe067 Provide routine for setting LUKS2 requirement with version. 2022-06-09 12:03:14 +02:00
Ondrej Kozina
07f8dfc46d Write updated LUKS2 reencrypt keyslot immediately. 2022-06-09 12:03:14 +02:00
Ondrej Kozina
99a3d328f0 Harden checksum resilience parameters verification. 2022-06-09 12:03:14 +02:00
Ondrej Kozina
e8ec3e1005 Allocate buffer for checksum resilience on-demand. 2022-06-09 12:03:14 +02:00
Ondrej Kozina
007e56727c Refactor reencrypt_recover_segment. 2022-06-09 12:03:14 +02:00
Ondrej Kozina
4de09ace8f Minor code refactoring in reencryption loop. 2022-06-09 12:03:14 +02:00
Ondrej Kozina
97b88d878e Refactor internal reencrypt_hotzone_protect_final.
Avoid passing whole reencryption context when not
needed.
2022-06-09 12:03:14 +02:00
Ondrej Kozina
b43ca18c64 Postpone reencryption dm segments refresh.
Refresh (and therefore suspend hotzone) reencryption dm
segments in-before actual hotzone reencryption takes place.

This commit shortens time window during which hotzone is
suspended. Also it avoids eventual deadlock if reencryption process
triggers page miss during storage wrapper reinitialization and required
data is stored in (previously) suspended hotzone (corner case).
2022-06-09 12:03:14 +02:00
Ondrej Kozina
0768d3be84 Cleanup existing assert usage in LUKS2 json code. 2022-06-09 12:03:14 +02:00
Ondrej Kozina
828cfdb6a2 Reduce code duplication in LUKS2 requirements handling. 2022-06-09 12:03:14 +02:00
Ondrej Kozina
582f2c3449 Replace memset with crypt_safe_memzero where reasonable.
Better safe than sorry.
2022-06-09 12:03:14 +02:00
Ondrej Kozina
bf0d0203e8 Add routine for erasing resilience structure. 2022-06-09 12:03:14 +02:00
Ondrej Kozina
b75a6d2b64 Properly update hash parameter for checksum resilience.
Checksum hash parameter obtained via API call can not be used directly.
It gets lost during subsequent call to crypt_reencrypt_init_by_* API
when library reloads crypt context.
2022-06-09 12:03:14 +02:00
Ondrej Kozina
450265c153 Separate reencryption params verification for update. 2022-06-09 12:03:14 +02:00
Ondrej Kozina
cfb54be9a3 Refactor reencrypt_length() function. 2022-06-09 12:03:14 +02:00
daniel.zatovic
828ddad7c2 CI: add Alpine Linux runner 2022-06-09 09:46:51 +00:00
Milan Broz
dd3fe9f5fd Check cipher before LUKS conversion to LUKS2.
There are some historic incompatibilities that are ignored
for LUKS1 but do not work for LUKS2.

Check the cipher before conversion through crypto backend.

Also it switches LUKS2_check_cipher to use userspace backend only
(this should be ok for the reencryption code that uses it too).

Fixes: #641
2022-06-09 08:50:15 +00:00
Ondrej Kozina
692bb8a455 Properly define uint32_t constants in API.
We do not change any value but it was not declared properly
and limit values had to be type cast to avoid compiler warnings
with strict options.
2022-06-07 11:30:34 +02:00
Milan Broz
6ac27f50ad Print output of symver attribute check in autoconf. 2022-06-06 07:29:38 +00:00
Milan Broz
93f90bf0f7 Do not report FIXME and empty blocks in LGTM. 2022-06-05 20:42:08 +02:00
Milan Broz
e921991ba5 Annotate LGTM TOCTOU condition.
The race here is not avoidable.
2022-06-05 20:38:22 +02:00
Milan Broz
4913de11fc Remove condition that is always true. 2022-06-05 20:29:52 +02:00
Milan Broz
82a6ae3c25 Remove condition that is always true. 2022-06-05 20:27:52 +02:00
Milan Broz
ddc8c9c441 Use %s for JSON progress print. 2022-06-05 20:26:20 +02:00
Milan Broz
fc49a258bd Add configuration file for lgtm analyser. 2022-06-04 22:30:22 +02:00
Ondrej Kozina
a1734e2d52 Revalidate LUKS2 reencrypt keyslot after update. 2022-05-26 12:13:06 +00:00
Ondrej Kozina
8f97d9b6e6 Do not refresh reencryption digest when not needed.
Due to commit 0113ac2d88
we recalculate reencryption digest whenever LUKS2 reencryption
keyslot gets updated. Until now we perform reencryption digest
refresh every time we call LUKS2_keyslot_reencrypt_update even
when no metadata was updated.

This improves on it and should speed up reencryption resume
process.
2022-05-26 12:13:06 +00:00
Ondrej Kozina
fa12a0a490 Add missing translation tag. 2022-05-26 12:13:06 +00:00
Ondrej Kozina
d9dad29149 Move LUKS2 reencrypt keyslot update procedure.
The LUKS2 reencrypt keyslot update process should
not be performed in crypt_reencrypt_run() loop where
data reencryption takes place.

The proper location is reencryption process initialization
when we validate reencryption metadata and decide if
new user provided resilience metadata are valid.
2022-05-26 12:13:06 +00:00
Ondrej Kozina
fc4b2cab25 Store proper resilience data in LUKS2 reencrypt initialization.
Prior to commit 0113ac2d88 it did
not matter what resilince metadata we stored during initialization.
So we stored 'none' type unless 'datashift' operation was initialized.

After the commit, it triggered reencryption metadata digest refresh
almost each time (except 'datashift') which was suboptimal.

By storing proper resilience type during reencryption initialization
we will avoid the needless reencryption digest refresh later (after
update optimization).
2022-05-26 12:13:06 +00:00
Ondrej Kozina
d9eff7ffd7 Test passed resilience parameter is not NULL. 2022-05-26 12:13:06 +00:00
Ondrej Kozina
2820626f5e Move LUKS2_keyslot_reencrypt_allocate function.
It does not fit internal LUKS2 keyslot API so
there's no need to hook it in it.
2022-05-26 12:13:06 +00:00
Ondrej Kozina
1cdb7da2ad Fix mem leaks on error path in reenc_keyslot_alloc. 2022-05-26 12:13:06 +00:00
Ondrej Kozina
e00eecf9ca Remove unused union member. 2022-05-26 12:13:06 +00:00
Ondrej Kozina
346f104f26 Move internal structure definition to internal header file. 2022-05-26 12:13:06 +00:00
Ondrej Kozina
082d23af92 Store data_shift value in rp structure.
data_shift value is part of recovery data
and should be stored in rp structure instead.
2022-05-26 12:13:06 +00:00
Ondrej Kozina
392b0136dc Store checksum protection data block size in rp structure.
The structure is supposed to store all data necessary to perform
reencryption crash recovery. The data block size stored
in LUKS2 metadata was missing and stored in reencryption top level handle
instead.
2022-05-26 12:13:06 +00:00
Ondrej Kozina
3a4ced84a6 Release lock on reencryption initialization error path. 2022-05-26 12:13:06 +00:00
Milan Broz
16c35d155a Fix error message for LUKS2 only cryptsetup commands.
Some cryptsetup commands requires LUKS2 device, but message
"not a LUKS device" is printed. Just change it to LUKS2.

Fixes: #741
2022-05-26 10:17:34 +02:00
Milan Broz
97a22c27dd Make crypt_load quiet if metadata is not detected.
Ths will allow automatic scan of known formats.

Errors are printed only if something is wrong with already detected metadata.

This change means that it is responsibility of the caller to print an error
message if needed.

Also fix some places without a message.

Fixes: #642
2022-05-26 10:17:32 +02:00
Milan Broz
bce9bd3a3b Use better error message for incompatible dm-integrity metadata.
If cryptsetup/integritysetup tool is too old, it can happen that
kernel dm-integrity uses more recent version of dm-integrity metadata.

Print (and also traslate) better error in this case.

Fixes: #667
2022-05-26 06:44:53 +00:00
Milan Broz
59692e3ca2 Add a test for LUKS2 integrity with detached header. 2022-05-26 06:44:53 +00:00
Milan Broz
39fda3bed1 Properly deactivate integrity device even if LUKS2 header is not available.
If LUKS2 is used with integrity protection, there is always a dm-integrity
device underneath.

We should deactivate the device if DM status return tag size (it means,
that dm-crypt uses dm-integrity DIF).

This allows "cryptsetup close <name>" peroperly remove both stacked devices
even if LUKS2 header is no longer available (like in detached header activation).
2022-05-26 06:44:53 +00:00
Milan Broz
2d2f230c9d Allow use of --header option for cryptsetup close.
This can have perhpas only one use - checking that
activated device has the same UUID.
2022-05-26 06:44:53 +00:00
Milan Broz
4dd514a12f Fix activation of LUKS2 device with integrity and detached header.
While the metadata device is detached header here, integrity
superblock is located on the data device.
For standalone integrity device it is diffferent
- data device contains only data and possible metadata device
contains integrity superblock and tag areas.

Fix it by checking metadata format.

Fixes: #609,#730
2022-05-26 06:44:53 +00:00
Milan Broz
7e6c48f67c integritysetup: mention and test xxhash64 non-crypto hash
Fast xxhash64 algoritm can be used for integrity protection.
Add implicit tag size (so user do not need to use --tag-size),
mention it in man page and add a test.

Fixes: #632
2022-05-24 14:36:25 +00:00
Milan Broz
360bd7f68d integritysetup: clarify format question message and man page if data device is used
If existing data device is used, user must specify --no-wipe option
otherwise data device is wiped.
(Tags then can be recalculated on activation with --integrity-recalculate option).

Fixes: #679
2022-05-24 14:36:25 +00:00
Vojtech Trefny
f1fd38c726 bitlk: Add warning when activating device with wrong size 2022-05-24 06:48:26 +00:00
Vojtech Trefny
795b37d128 bitlk: Add BitLocker volume size to dump 2022-05-24 06:48:26 +00:00
Milan Broz
5aa01da2b5 Fix two more lowercase ARG macro undefs. 2022-05-24 08:46:54 +02:00
Daniel Parks
3341bfd6c5 The ARG macro should be uppercased when undefining it
This isn't a bug right now, but it could be in the future if ARG is
used in a different context.
2022-05-23 17:26:48 +00:00
Vojtech Trefny
6c73057156 integrity: Fix integrity_key_size for algorithms without keys
INTEGRITY_key_size returns -EINVAL for algorithms without a key
and because crypt_params_integrity.integrity_key_size is an
unsigned integer we get key size 4294967274 instead of more
appropriate 0 for these algorithms.
2022-05-22 19:58:00 +02:00
Milan Broz
5d9e362553 Make CRYPT_WIPE_ENCRYPTED_ZERO obsolete.
It was never implemented (the idea was to speed up wipe), but
with the recent RNG performance changes it makes no longer sense.
2022-05-18 16:39:53 +02:00
Milan Broz
4d6e9e7c32 Add crypt_wipe unit test.
It uses simple C wrapper aroung crypt_wipe() libcryptsetup
and then bash test scripts wipung simple file and block device.
2022-05-18 16:39:48 +02:00
Milan Broz
227fdb7393 Fix init for util_wipe call.
It should init crypt, as it uses RNG.

Also it should fail early if no device is initialized.
2022-05-18 16:39:43 +02:00
Milan Broz
251eb37c4a Do not try to print NULL string in destructor. 2022-05-18 16:39:38 +02:00
Milan Broz
0009089855 Add ZEROOUT ioctl support for crypt_wipe.
For block devices we can use in-kernel BLKZEROOUT ioctl,
that should be faster in most cases.

This cannot be used for images in files.
2022-05-18 16:39:30 +02:00
Milan Broz
41d61df667 Set loopback sector size according to verity block sizes.
Verity block size has the same limits, so we can optimize
loop device this way.
2022-05-18 09:57:48 +00:00
Milan Broz
8945f3e9e2 Add per-keyslot options to man page.
Some options were missing for LUKS2 luksAddKey and luksChangeKey.

Fixes: #720
2022-05-17 14:37:24 +02:00
Milan Broz
8606865e15 Avoid using top_srcdir in SOURCES. 2022-05-11 09:36:26 +00:00
Milan Broz
9e7894081f Verity: dump device sizes.
Calculating device sizes for verity devices is a little bit tricky,
Data, hash and FEC can share devices or it can be a separate devices.

This patch prints used device sizes in veritysetup dump command,
but it requires that user specifies all values that are not stored
in superblock (like a FEC device and FEC roots).
2022-05-09 22:48:59 +02:00
Milan Broz
0c80ee6c28 Move verity dump to per-format directory. 2022-05-09 13:47:16 +02:00
Milan Broz
853abf53f5 Fix debug message for crypt_activate_by_signed_key.
If name is not uses, there are two spaces.
Also it is more readable now.
2022-05-09 13:46:58 +02:00
Milan Broz
3173595fc9 Avoid using bash arrays in verity test.
This will break on every small change (as in following patch).
Just grep the key word as used elsewhere.
2022-05-09 13:46:24 +02:00
Milan Broz
ede2a8a45f Add some basic UTF conversion function test.
Used only in bitlk format.
2022-05-03 15:48:09 +00:00
Milan Broz
6631033d8a Fix cryptsetup manpage to use PBKDF consitently.
Fixes: #738
2022-05-02 08:01:06 +02:00
Fabrice Fontaine
fe3878199c configure.ac: replace argp_usage check
Replace check for argp_usage by argp_parse as argp_usage is not used by
cryptsetup. Moreover, this will fix the following build failure raised
with argp-standalone in version 1.4.0 and
e7ff8d9787:

/home/autobuild/autobuild/instance-10/output-1/host/lib/gcc/i686-buildroot-linux-musl/10.3.0/../../../../i686-buildroot-linux-musl/bin/ld: tokens/ssh/cryptsetup_ssh-cryptsetup-ssh.o: in function `parse_opt':
cryptsetup-ssh.c:(.text+0x14c): undefined reference to `argp_state_help'
/home/autobuild/autobuild/instance-10/output-1/host/lib/gcc/i686-buildroot-linux-musl/10.3.0/../../../../i686-buildroot-linux-musl/bin/ld: tokens/ssh/cryptsetup_ssh-cryptsetup-ssh.o: in function `main':
cryptsetup-ssh.c:(.text+0x7db): undefined reference to `argp_parse'

Fixes:
 - http://autobuild.buildroot.org/results/cb3fdae4e0da603f304501f65127800346cb3915

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2022-04-28 17:24:35 +00:00
Milan Broz
2bf0f537f6 Add constant time memcmp and use it for comparing keys.
There is perhaps no problem now, but it is a good practise to use
constant time for key comaprison to avoid possible side channel
issues.
2022-04-28 15:19:23 +00:00
Milan Broz
4f44bb40b7 Do not print full help in CI clang scan_build. 2022-04-28 12:56:59 +00:00
Milan Broz
3ee0b37303 Use absolute path for compilers scripts.
Then make check-programs in tests directory works.
2022-04-28 12:56:59 +00:00
Milan Broz
a25d10407d Fix some scan build warnings for api-test-2. 2022-04-28 12:56:59 +00:00
Milan Broz
ae3ce2a207 Compile test also programs tests dir. 2022-04-28 12:56:59 +00:00
Milan Broz
2d8cdb2e35 Add unit test fo some functions in utils_crypt.c. 2022-04-28 08:11:58 +00:00
Milan Broz
ceed3c0c3b Introduce crypt_log_hex helper and use it for log_std output. 2022-04-28 08:11:58 +00:00
Milan Broz
e161cd1859 Add constant time crypt_bytes_to_hex helper and use it in libdevmapper.
Fixes: #736
2022-04-28 08:11:58 +00:00
Milan Broz
ff14c17de7 Use constant time conversion for crypt_hex_to_bytes.
We use hexa conversions for keys, avoid possible
leaks with cover channels by making these functions
constant time.
2022-04-28 08:11:58 +00:00
Ondrej Kozina
1ac6a58475 Simplify LUKS2_segment_first_unused_id(). 2022-04-27 11:50:48 +02:00
Ondrej Kozina
2dbd96ebbf Fix LUKS2_get_data_size function.
The function wrongly expected segment objects being
ordered (ascending order) in segments container.

The LUKS2 format never guaranteed that and it could
lead to wrong LUKS2 device size calculation in case
last segment (by key) was stored before any other segment
with fixed size.
2022-04-27 11:44:51 +02:00
Ondrej Kozina
a29f74b5ad Silent reencryption by volume key passed in file.
It emitted confusing error message. It's expected
new volume key would not match the existing one.
2022-04-26 05:46:01 +00:00
Ondrej Kozina
cc107ee20e Silent crypt_volume_key_verify call.
And moves the error message in tools instead.
2022-04-25 19:47:09 +00:00
Ondrej Kozina
c67db10c22 Do not allow sector size increase reencryption in offline mode.
The eventual logical block size increase on dm-crypt device above
filesystem block size may lead making fs unusable. Do not allow
offline reencryption when sector size increase is requested.

If users really want to perform it make them use existing
--force-offline-reencrypt option.
2022-04-25 12:18:33 +02:00
Ondrej Kozina
65a5943ee5 Check sb block size only if actual sector size gets increased. 2022-04-25 09:55:55 +02:00
Ondrej Kozina
5a8b95aa45 Clarify clean up path of empty dm_target structure. 2022-04-22 15:02:41 +00:00
Milan Broz
f391f4baf1 Fix memory leaks in integrity resize with keyed parameters.
The whole game with reallocating keys is not needed.

(Perhaps not even for crypt type, but that is not part of this patch).
2022-04-22 11:34:13 +02:00
Milan Broz
4cdcd908f4 Fix memory leak in integrity resize api-test. 2022-04-21 08:21:01 +00:00
Milan Broz
1d6a445e43 Fix integrity api-test.
The journal crypt is in wrong format (this never worked! :),
here it takes kernel syntax.
Also use CBC a CTR mode could be missing here.

Fox typo in key length caclulation.

Clear temporary dm devices after test, loop devices are reused.

If the first device format is ok, all subsequent cals should
be treated as an error.
2022-04-21 08:21:01 +00:00
Milan Broz
ed13852899 Fix reload integrity device.
The offset cannot be referenced from the crypt union for integrity type.

Keyring setting key works only for crypt devices.

Also reformat long lines.
2022-04-21 08:21:01 +00:00
Milan Broz
efc1590405 Fix formatting warning for a 32bit arch. 2022-04-21 08:21:01 +00:00
Milan Broz
4b1ba47ca1 Avoid compilation warning if configured with --disable-blkid. 2022-04-20 16:08:58 +00:00
Milan Broz
e4a0d25315 Fix missing batch option in test. 2022-04-20 16:08:58 +00:00
Milan Broz
81a63aca22 Fix tests if compiled with --disable-blkid.
Note that htere are some systems with blkid but without
blkid support for secondary LUKS2 header (CentOS6 for example).
2022-04-20 16:08:58 +00:00
Milan Broz
ebabf3ffee Add compile-in flag to program version output.
Then we can check if tools are compiled with a support for specific
extension/library.
2022-04-20 16:08:58 +00:00
Milan Broz
3363bad8c2 Speed-up tcrypt test.
We can limit hash and cipher to not scan all variants here.
2022-04-20 14:37:13 +00:00
Milan Broz
773fc0195f Fix typos found by codespell.
Thanks Dimitri Papadopoulos Orfanos for the patch.

Fixes: #734.
2022-04-20 14:37:13 +00:00
Milan Broz
d3ad18ad81 Add compile info to README.
This information was lost when we removed default automake INSTALL file.
2022-04-20 14:37:13 +00:00
Milan Broz
5c7858883c Remove cryptsetup-reencrypt version dump from tests. 2022-04-20 14:37:13 +00:00
Ondrej Kozina
c9da460b6c Do not allow dangerous sector size change during reencryption.
By changing encryption sector size during reencryption we may
increase effective logical block size for dm-crypt active device.

For example if hosted filesystem on encrypted data device
has block size set to 512 bytes and we increase dm-crypt logical
size durign reencryption to 4096 bytes it breaks the filesystem.

Do not allow encryption sector size to be increased over value
provided by fs superblock in BLOCK_SIZE property.

The check is applied while initialising LUKS2 device encryption
(reencrypt --encrypt/--new) or when initialising LUKS2 reencryption
on active dm-crypt device.

Note that this check cannot be applied on offline device (data device
is encrypted).
2022-04-19 13:27:37 +00:00
Ondrej Kozina
38d1f01b12 Add tools helper reporting blkid support. 2022-04-19 13:27:37 +00:00
Ondrej Kozina
624026a98f Refactor reencrypt_get_active_name helper. 2022-04-19 13:27:37 +00:00
Ondrej Kozina
f6452e1656 Add superblock BLOCK_SIZE detection in tools. 2022-04-19 13:27:37 +00:00
Ondrej Kozina
2388777763 Add option to probe only superblocks in blkid. 2022-04-19 13:27:37 +00:00
Ondrej Kozina
be5c5788d4 Add support for superblock BLOCK_SIZE property. 2022-04-19 13:27:37 +00:00
Milan Broz
f1eea3a4b3 Clean reencrypt status struct for API call.
This function should not return unitialized struct as there
is no indication that it failed and caller can access it.

Also fixes a Coverity warning.
2022-04-19 08:53:44 +00:00
Milan Broz
2857e10083 Fix UTF16 buffer overflow in bitlk volume key dump.
It is UTF16, so even the terminating character is char16_t.

(Found by gcc sanitizer.)
2022-04-17 13:59:03 +02:00
Milan Broz
99c4c3adbf Skip question if batch mode is set for volume key bitlk dump.
Other formats use the same logic.
2022-04-17 13:58:08 +02:00
Milan Broz
f34b3b27ec Do not use definitions in for cycle. 2022-04-15 21:44:52 +02:00
Milan Broz
ab6762b849 Fix possible missing uchar.h. 2022-04-15 21:43:45 +02:00
Milan Broz
3fbc480e32 Clean headers for utf8 wrapper. 2022-04-15 21:22:07 +02:00
Milan Broz
ce1c39dc54 Properly report if sectior size cannot be used for bitlk activation. 2022-04-15 21:02:52 +02:00
Milan Broz
9b60e2d959 Add some tests for invalid keyslot JSON objects. 2022-04-14 10:28:20 +00:00
Milan Broz
e89071e73f Fix keyslot JSON validation.
If keyslot JSON is corrupted (kdf,af,area objects),
validate function can crash.

Fix it by always using JSON type check.

Fixes: #731
2022-04-14 10:28:20 +00:00
Ondrej Kozina
dbd4dc1dc0 Speedup reencryption tests. 2022-04-13 16:23:01 +02:00
Ondrej Kozina
acd2601bd7 Drop unused code in lib/utils_blkid.c 2022-04-13 16:16:57 +02:00
Ondrej Kozina
d56ccc97b8 Detect broken LUKS metadata in-before encryption.
We should abort LUKS device in-place encryption
when target data device or metadata device
contain broken LUKS metadata (any version).
Filed crypt_load() call was not good enough check
because the call fails also when a device contains
LUKS metadata overlapping with other superblock
(e.g. LVM2 PV signature).

Let blkid decide if device contains broken LUKS
metadata or not.

Fixes: #723.
2022-04-11 11:38:56 +00:00
Ondrej Kozina
412de7dc25 Add suport for filtering only LUKS signatures. 2022-04-11 11:38:56 +00:00
Ondrej Kozina
8c350b65a3 Prepare tools_detect_signatures for new filter type. 2022-04-11 11:38:56 +00:00
Milan Broz
83ef36bd59 Add tests for LUKS2 JSON mangled top-level objects. 2022-04-09 21:27:09 +02:00
Milan Broz
c07cfa20de test generators: unify checksum check functions 2022-04-09 21:25:55 +02:00
Milan Broz
6d8587c137 test generators: unify kill header check functions 2022-04-09 21:25:55 +02:00
Milan Broz
d43b495f21 test generators: unify mangle & kill header functions 2022-04-09 21:25:55 +02:00
Milan Broz
e97238fb6d test generators: use one common cleanup function 2022-04-09 21:25:55 +02:00
Milan Broz
c9ead0482d test generators: use one common prepare function 2022-04-09 21:25:55 +02:00
daniel.zatovic
9c26a73d96 Validate JSON area root objects' types. 2022-04-07 15:29:05 +00:00
Ondrej Kozina
ea35573c82 Ask user for confirmation before resuming reencryption.
The prompt is not showed in batch mode or when user
explicitly asks for reencryption resume via --resume-only.
2022-04-07 13:50:09 +02:00
Ondrej Kozina
d3079c2fb3 Do not resume reencryption with conflicting parameters.
Do not resume reencryption operation with conflicting parameters.
For example if operation was initialized as --encrypt do not
allow resume with oposing parameter --decrypt and vice versa.

Also checks for conflicting --resilience parameters (datashift cannot
be changed after initialization).

Previously, conflicting reencryption parameters were silently ignored.
So, for example operation initialized with mode --encrypt and resumed
with mode --decrypt simply finished --encrypt operation and did not
report any error. This could lead to impresion different type of
operation was perfomed instead.

Fixes: #570.
2022-04-07 13:49:40 +02:00
Ondrej Kozina
b661452e3a Asks offline reencryption confirmation only with image files.
If auto-detection fails for other reason just return the
error. Users may now bypass active device auto-detection
with --force-offline-reencrypt option.
2022-04-07 11:51:41 +02:00
Ondrej Kozina
31c4afbc17 Add --force-offline-reencrypt option.
It can be used to enforce offline reencryption
in batch mode when data_device is regular file
and therefore cryptsetup cannot detect properly
active device dm name.

Also it may be useful when active device
auto-detection fails for some reason and user
has no other choice but inspect device holders
manually.
2022-04-06 22:59:37 +02:00
Ondrej Kozina
496a0e37c4 Active device auto-detection code cleanup. 2022-04-06 22:59:35 +02:00
Ondrej Kozina
8c04264fb3 Reduce code duplication in active device auto-detection. 2022-04-06 22:57:13 +02:00
Milan Broz
db1ff4cf88 Silence false positive Coverity warning.
The init_keyslot_passwords() allocates properly sized arrray here.
2022-03-30 17:53:14 +02:00
Milan Broz
3e4368feeb Use link to main branch. 2022-03-30 13:08:57 +02:00
Milan Broz
faee0e694f Use main branch in GitHub CI. 2022-03-30 13:07:55 +02:00
Milan Broz
7a38f16cef Use volume key in FAQ. 2022-03-29 19:06:38 +00:00
Milan Broz
08aa2ca242 Replace master on a few more places. 2022-03-29 19:06:38 +00:00
Milan Broz
3a56cf05bf Replace mk_ with vk_ name prefix. 2022-03-29 19:06:38 +00:00
Milan Broz
b6c36f50ba Replace name master with volume key.
And keep two tests for compatibility.
2022-03-29 19:06:38 +00:00
Milan Broz
b050448db9 Add aliases for --volume-key-file and --dump-volume-key-file. 2022-03-29 19:06:38 +00:00
Milan Broz
68796e12dd Replace OPT_MASTER_KEY_FILE_ID with OPT_VOLUME_KEY_FILE_ID. 2022-03-29 19:06:38 +00:00
Milan Broz
650c7e8b67 Enable csmock for merge requests. 2022-03-29 15:40:48 +00:00
Milan Broz
0dc18fba22 Fix a leak in error path.
Also fix a warning, all detected by Coverity scan.
2022-03-29 15:40:48 +00:00
Milan Broz
1116289de4 Try to load dm-integrity in api-test. 2022-03-29 14:17:53 +00:00
Milan Broz
1595fcf479 Do not run keyed integrity resize tests for older kernel. 2022-03-29 14:17:53 +00:00
Milan Broz
c4c1ca2224 Use batch mode for integrity resize test. 2022-03-29 14:17:53 +00:00
Ondrej Kozina
2b42968e92 Port cryptsetup --new option to CRYPT_ARG_ALIAS type. 2022-03-29 12:54:58 +02:00
Ondrej Kozina
e2a5af9e64 Add new argument type CRYPT_ARG_ALIAS.
It can be used to easily define option
aliases for command line utilities.
2022-03-29 12:54:15 +02:00
Milan Broz
e4ed545cbf Remove debug line from api-test. 2022-03-28 22:27:54 +02:00
Ondrej Kozina
65be641f20 Refactor LUKS reencryption. 2022-03-24 15:14:32 +00:00
Ondrej Kozina
ce55fa4d1c Refactor LUKS decryption. 2022-03-24 15:14:32 +00:00
Ondrej Kozina
92baacadad Refactor LUKS encryption.
It also adds hardened checks for accidental
nested device encryption.
2022-03-24 15:14:32 +00:00
Ondrej Kozina
2e59229e5a Add checks for some conflicting requests.
It also moves device load for reencryption purposes
further up in code path to better optimize the code
later.
2022-03-24 15:14:32 +00:00
Ondrej Kozina
3f42b69fc8 Add reencrypt_luks2_resume helper.
To be used later.
2022-03-24 15:14:32 +00:00
Ondrej Kozina
b10c0b6a02 Simplify load_luks2_by_name.
Also adds specific error messsage when device
is not actualy LUKS2.
2022-03-24 15:14:32 +00:00
Ondrej Kozina
f388662418 Remove 'type' argument from load_luks helper.
The code removal will help simplify further code
changes.
2022-03-24 15:14:32 +00:00
Ondrej Kozina
8bc10ee853 Rename luks2 reencryption initialization routines. 2022-03-24 15:14:32 +00:00
Ondrej Kozina
b663b9305c Add helper for checking data device type during encryption.
In case operation is invoked with --header parameter
check if data device does not already contain LUKS device
2022-03-24 15:14:32 +00:00
Ondrej Kozina
828555db97 Remove unused code in helper routine. 2022-03-24 15:14:32 +00:00
Ondrej Kozina
ba08f02a40 Move helper for LUKS2 auth. encryption detection. 2022-03-24 15:14:32 +00:00
Ondrej Kozina
a55b0530a4 Restrict --active-name to LUKS2 type only. 2022-03-24 15:14:32 +00:00
daniel.zatovic
a2f30ebd4c Display progress when wiping the end of resized device. 2022-03-24 11:38:16 +01:00
daniel.zatovic
d20d41c7a5 Add log messages, when kernel doesn't support resize. 2022-03-24 11:38:16 +01:00
daniel.zatovic
4eba55c73e Add tests for integritysetup resize action. 2022-03-24 11:38:16 +01:00
daniel.zatovic
29ddd68a0f Add API tests for resize of integrity volume. 2022-03-24 11:38:16 +01:00
daniel.zatovic
9707b71f98 Describe resize action in manual page. 2022-03-24 11:38:16 +01:00
daniel.zatovic
36cdda870b Add resize action to integritysetup.
Fixes: #594.
2022-03-24 11:38:16 +01:00
daniel.zatovic
9b8a872006 Add support for resizing raw integrity devices. 2022-03-24 11:38:16 +01:00
daniel.zatovic
45b808c186 Move checking for detached integrity metadata device.
To allow resizing integrity devices with detached metadata device, the
check has to be moved from _compare_integrity_devices to
_reload_device_with_integrity.
2022-03-24 11:38:16 +01:00
daniel.zatovic
87afb9d783 Remove size parameter comparison for integrity devices.
To support device resize, we can not compare the device size (it is
already not compared for crypt devices).
2022-03-24 11:38:16 +01:00
daniel.zatovic
86402a1102 Add API tests for refreshing integrity devices. 2022-03-24 11:38:16 +01:00
daniel.zatovic
64e7c3d3b1 Add support for refreshing integrity devices.
If the provided key is NULL, we load it from the active device. This is
always available, since keyring keys are not supported in kernel for
integrity devices.
2022-03-24 11:38:16 +01:00
daniel.zatovic
f6c1445c6b Add support for querying journal active devices for integrity and encryption keys. 2022-03-18 09:56:59 +00:00
Ondrej Kozina
f5724a30f9 Test nested encryption is not possible. 2022-03-17 19:07:10 +00:00
Ondrej Kozina
47f31205cf Do not allow nested encryption in LUKS reencrypt.
Try to avoid accidental nested encryption via
cryptsetup reencrypt --new/--encrypt command.

If detached header or data device is already reported
as LUKS1 or LUKS2 device operation gets aborted.

Fixes: #713.
2022-03-17 19:07:10 +00:00
Ondrej Kozina
5bd5462a9e Improve helpers for reencryption utilities.
Also clarifies some code path.
2022-03-17 19:07:10 +00:00
Ondrej Kozina
d1f0376c77 Decouple auth. encryption check from in-reencrypt detection. 2022-03-17 19:07:10 +00:00
Ondrej Kozina
dae91fd9ec Code reshuffle in-before some changes. 2022-03-17 19:07:10 +00:00
daniel.zatovic
df4ed89141 CI: disable updates. 2022-03-17 19:04:41 +00:00
Milan Broz
559012b6a7 Check dm-zero availability for bitlk type.
Bitlocker compatible mode uses dm-zero to mask metadata area,
device cannot be activated if dm-zero is not available.

Just add zero target check to device-mapper backend and
if activation fails, print a better error message here.

Fixes: #722
2022-03-16 12:21:30 +01:00
Milan Broz
6534e86c22 Update gitignore. 2022-03-15 13:12:27 +01:00
Milan Broz
70c1eb7352 Support make check-programs target from top level makefile.
Also fix genereated header dependence.
2022-03-15 13:07:10 +01:00
Ondrej Kozina
dee2fa7159 Prefer token PIN query before passphrase in some case.
When user provides --token-type or specific --token-id
prefer token PIN query over passphrase query (if token
handler responds with 'PIN needed').

Fixes: #670.
2022-03-14 17:34:41 +01:00
Ondrej Kozina
3af754b5eb Use proper function parameter in token pin helper. 2022-03-14 17:33:41 +01:00
Ondrej Kozina
3b85ab2dc1 Do not continue operation when interrupted in PIN prompt. 2022-03-14 14:04:36 +00:00
Ondrej Kozina
2a5483d8c3 Add progress function init before reencryption loop.
Otherwise elapsed time tracking is off and also breaks
speed estimation.
2022-03-07 12:35:38 +01:00
Ondrej Kozina
8340d0cb1a Remove useless condition in reencryption loop.
(always true)
2022-03-07 12:35:38 +01:00
Ondrej Kozina
3cd5d83ee9 Add --progress-json parameter to utilities.
Progress data can now be printed out in json format
suitable for machine processing.
2022-03-07 12:35:38 +01:00
Ondrej Kozina
6852c49d0c Merge progress functions into single routine. 2022-03-07 12:35:38 +01:00
Ondrej Kozina
63c79256e4 Refactor time diff calculation helper. 2022-03-07 12:35:38 +01:00
Ondrej Kozina
75622b332b Improve progress routine for cryptsetup utilities.
The progress routine is now fully translated and
prints out progress in following manner (examples):

Progress: 25,5%, ETA 00m31s, 7 GiB written, speed 838,6 MiB/s
Progress: 25,5%, ETA 20h11m31s, 7 GiB written, speed 24 KiB/s
Progress: 25,5%, ETA 06 days, 12 MiB written, speed 4 KiB/s

Also got rid of -lm dependency due to floor().

Fixes: #671.
2022-03-07 12:35:38 +01:00
Ondrej Kozina
c1e94abbab Move progress utilities in separate file. 2022-03-07 12:35:38 +01:00
Ondrej Kozina
1af7eefbc0 Minor time progress print out improvements.
Mostly moves float arithmetics in slow path and
also cleans up code a bit.
2022-03-07 12:35:37 +01:00
Milan Broz
bf4a039d50 Add a debug info if maximum interactive passphrase was read (possible trimmed).
If passphrase is read from a real terminal, there is maximum
interactive input length applied. This means that passphrase
can be trimmed in this case.

This patch adds debug log warning, if read does not detect
end of input (EOL or EOF) and the maximal input read is achieved.

We cannot say for sure if the next character is EOL without
actually reading it, debug warning should be enough in this case.

Fixes: #699
2022-02-25 14:14:03 +01:00
Milan Broz
0085985419 Fix gcc warnings in tests. 2022-02-24 20:28:29 +01:00
Milan Broz
12c35da768 Check all snprintf calls for returning values for tests. 2022-02-24 20:28:25 +01:00
Milan Broz
677e06c48a Check all snprintf calls for returning values. 2022-02-24 20:28:18 +01:00
Milan Broz
c27d6a89bb Add hint for false positive coverity warning. 2022-02-24 14:04:24 +01:00
Milan Broz
e5ce189db8 Add info about broken Intel QAT crypt drivers to FAQ. 2022-02-24 11:05:25 +01:00
Milan Broz
3407cbbad1 Add info about bug report to FAQ and add SECURITY.md file. 2022-02-23 22:20:09 +01:00
Milan Broz
2c91590d52 Add info about CVE-2021-4122 to FAQ. 2022-02-23 21:35:20 +01:00
Milan Broz
c5e500ea0f Add note about fake RAID and data corruption.
Fixes: #714
2022-02-23 21:27:05 +01:00
Milan Broz
5efe03ddd7 Update mailing list info in FAQ. 2022-02-23 21:08:34 +01:00
Ondrej Kozina
8ab41e0776 Improve debug messages while verifying reencryption metadata. 2022-02-23 15:00:11 +01:00
Ondrej Kozina
f671febe64 Add more tests for --test-passphrase parameter. 2022-02-23 15:00:11 +01:00
Ondrej Kozina
0a9f14c658 Fix --test-passphrase when device in reencryption.
Commit 0113ac2d broke test passphrase mode when
device was in LUKS2 reencryption.

Previously --test-passphrase parameter automatically raised
CRYPT_ACTIVATE_ALLOW_UNBOUND_KEY flag. It did not make sense
when users mostly want to test whether device can be activated by
provided passphrase or not. Raise the aforementioned flag only
if user requested it either by --unbound parameter or when
specific keyslot was selected.

Reported in: https://bugzilla.redhat.com/show_bug.cgi?id=2056439

Fixes: #716.
2022-02-23 15:00:08 +01:00
Ondrej Kozina
6b774e617b Remove unused funtion prototype and few useless comments. 2022-02-23 12:28:20 +01:00
Milan Broz
0d6b63a6a2 FAQ: Use relative links in chapter references. 2022-02-22 12:17:25 +01:00
Milan Broz
6018d2bcd8 Use markdown version of FAQ. 2022-02-22 12:03:37 +01:00
Ondrej Kozina
d5dbde5dd1 Clarify graceful reencryption interruption.
Currently it can be interrupted by both SIGINT and SIGTERM
signals.

Fixes: #715.
2022-02-21 11:38:57 +01:00
Milan Broz
ef7559bad9 Print output of verity test if concurrent check fails.
This tests randomly fails in CI, at least print output if this happens.
2022-02-21 10:13:38 +00:00
Milan Broz
e9e994fb0d Run some io to actually test dm-crypt flags. 2022-02-21 10:13:38 +00:00
Arno Wagner
c5d9f3f380 Typos, additional info on dd use. 2022-02-20 20:19:16 +00:00
Milan Broz
d23943f989 Fix old list archive link. 2022-02-17 19:58:55 +01:00
Milan Broz
b47b89adac Add new list info. 2022-02-17 19:56:00 +01:00
daniel.zatovic
452467661e Support --device-size option for plain devices. 2022-02-13 08:52:39 +00:00
Ondrej Kozina
bef46c950d Properly detect optimal encryption sector size.
Move code setting data device during format so that
we can properly detect optimal encryption sector size
for data device instead of metadata device (header).

Fixes: #708.
2022-02-09 15:43:25 +01:00
Milan Broz
5c323e9146 Remove ssh backgroud option causing spurious test failures.
The keyfile creation must be synchronous, otherwise following command
can fail ("SFTP server: No such file").
2022-02-08 22:12:35 +01:00
Milan Broz
33d8605924 Fix duplicate ssh plugin error message. 2022-02-08 22:12:31 +01:00
Vojtech Trefny
76086dbe95 ssh-plugin-test: Make the test fail if SSH setup fails
We should avoid silently skipping the test if there is something
wrong with the test itself. If we have all dependencies, the test
should be able to run.
2022-02-08 16:10:31 +01:00
Vojtech Trefny
7eb44f32a3 ssh-plugin-test: Copy SSH key manually instead of with ssh-copy-id
ssh-copy-id requires password authentication that might be disabled
on some cloud images. We can simply copy the key manually, because
everything runs on localhost anyway.

Fixes: #701
2022-02-08 16:10:08 +01:00
Milan Broz
cef0dc059a Add missing variable to run ssh plugin test. 2022-02-08 10:45:12 +01:00
Milan Broz
e4091fe8a5 Fix some benign warnings with gcc-12.
The string buffer is large enough, but gcc do not understant it.
Easy to avoid these warnings with a larger buffer here.
2022-02-06 18:03:49 +01:00
Milan Broz
685148af00 Enable new warnings (introduced in gcc-12). 2022-02-06 18:02:41 +01:00
Ondrej Kozina
8798aa0a75 Do not upload keys in keyring during offline reencryption.
Fixes: #696.
2022-02-05 10:29:55 +00:00
Ondrej Kozina
7ca1a233f1 Split reencrypt_verify_and_upload_keys function. 2022-02-05 10:29:55 +00:00
Ondrej Kozina
ab295b1159 Do not resume device when not suspended.
Abort action luksResume early if device is not suspended.
We would needlesly ask for passphrase or load cryptsetup
plugins only to fail later in crypt_resume_by_* API.
2022-02-04 13:41:24 +01:00
Ondrej Kozina
fea648cb1d Add support for crypt_resume_by_token_pin in cryptsetup. 2022-02-04 13:40:22 +01:00
Ondrej Kozina
ce6f6a48e8 Add crypt_resume_by_token_pin API. 2022-02-04 13:40:20 +01:00
Ondrej Kozina
416f1343fe Split LUKS2_activate_by_token. 2022-02-04 13:32:45 +01:00
Ondrej Kozina
388ba9f00d Add explicit tests for command failure in LUKS1 reencryption test. 2022-02-04 11:28:05 +01:00
Ondrej Kozina
e38a184907 Avoid partial read in luks1 reencryption loop.
Starting with kernel 5.17-rc there are some changes
in block layer aiming to block partial I/O in
O_DIRECT mode.
2022-02-04 11:28:05 +01:00
Milan Broz
f2dbab7043 Add more label/susbystem API tests. 2022-02-03 11:43:04 +01:00
Luca Boccassi
2938c1f077 Add crypt_get_label/subsystem
There's an API to set the label and subsystem, and they are
dumped with luksDump, but there's no programmatic interface
to query them.
2022-02-03 10:23:57 +00:00
Milan Broz
95d35ecf4b Allow CI rawhide runner to fail.
As there is often something broken (currently kernel), let's just
set it to allow_failure in CI.
2022-02-03 11:21:48 +01:00
Milan Broz
a1baa01ddd Set higher timeout for interactive tests.
Under heavy load 10 seconds is not enough, just use the same
values as when running under valgrind.
2022-02-03 08:05:11 +01:00
Ondrej Kozina
7ab7365020 Add check program for symver attribute.
Fixes: #709.
2022-02-02 21:30:48 +00:00
daniel.zatovic
43a636d809 CI: Detect core dumps generated during testing 2022-02-02 20:32:53 +00:00
Milan Broz
8531a8a753 Skip more tests if --disable-cryptsetup is used.
If there is no cryptsetup, some tests returns ok while noting was
tested in reality. Just mark them skipped.
2022-02-02 21:29:54 +01:00
Alyssa Ross
c0cef43a4e Skip cryptsetup tests when cryptsetup is disabled
If configured with --disable-cryptsetup (e.g. if only veritysetup is
required), these tests won't be able to run cryptsetup, so they need
to be skipped.
2022-02-02 16:51:49 +00:00
Ondrej Kozina
06b6542b28 Remove -Wno-attributes from -Wall tests.
It breaks compile time check for __attribute__((__symver__))
and it does not make sense either. Quoting gcc man page:

-Wno-attributes

Do not warn if an unexpected "__attribute__" is used, such as
unrecognized attributes, function attributes applied to variables,
etc. This does not stop errors for incorrect use of supported attributes.

Well, we do want to check for unsupported __attributes__ un our code,
right?
2022-02-02 15:05:09 +01:00
Milan Broz
03adc091ce Use tabs in SSH plugin test. 2022-01-29 12:07:38 +01:00
Milan Broz
f85921497c Remove loop device use from SSH plugin test. 2022-01-29 12:07:35 +01:00
Milan Broz
ab975bc1c4 Update copyright year.
And unify format in several places.
2022-01-29 10:43:02 +01:00
Milan Broz
0cb4f59006 Rename encrypt helper function to avoid clash with unistd prototype. 2022-01-29 10:21:06 +01:00
Ondrej Kozina
230b80404d Remove parameters annotated by __attribute__((unused)).
Attribute unused is useless and makes code imcomprehensible
when decorates internal functions not exposed via API.

Let's cleanup internal funtion prototypes whenever possible.
2022-01-28 17:27:00 +00:00
Alex Xu (Hello71)
46efbc0a36 argon2: Don't call _endthreadex/pthread_exit
Returning from the thread creation function is documented to be a valid
way of exiting a thread on both Windows and pthread systems. Removing
the explicit call avoids the need to install libgcc_s.so in initramfs
for glibc systems, and slightly reduces code size.

Upstream: https://github.com/P-H-C/phc-winner-argon2/pull/331
2022-01-28 15:06:08 +00:00
Milan Broz
903dae1b6c Enable clang and gcc cast-align[=strict] warning in CI. 2022-01-26 10:28:57 +00:00
Milan Broz
0b2c4187b0 Workaround clang alignment warnings (Wcast-align) when working with byt arrays.
This should silence similar warnings like
  warning: cast from 'char *' to 'struct xyz *' increases required alignment from 1 to X
when we try to calclulate byte pointer offsets in a buffer.
2022-01-26 10:28:57 +00:00
Milan Broz
c11a83bf0f Enable clang -Wextra and -Wsign-compare build in CI. 2022-01-26 10:28:57 +00:00
Milan Broz
a68eb60be9 Fix clang warnings for integer comparison. 2022-01-26 10:28:57 +00:00
daniel.zatovic
48872e9f2e CI: Save journalctl in artifacts. 2022-01-25 22:24:39 +01:00
daniel.zatovic
bb35a284e8 CI: Save dmesg in artifacts. 2022-01-25 22:24:33 +01:00
Vojtech Trefny
793b7cddaf bitlk: Fix coverity warnings introduced in 6e47fb6d 2022-01-24 17:54:54 +01:00
Ondrej Kozina
161eeb7473 Fix resource leaks in utils_reencrypt.c
Fixes: #703.
2022-01-24 16:29:35 +00:00
daniel.zatovic
71f33418d2 Add FIPS update again. 2022-01-24 12:04:23 +01:00
daniel.zatovic
f4e2daec94 Fix annocheck job. 2022-01-22 22:24:10 +01:00
Milan Broz
34f033b254 Do not use too small key in tests.
Apparently FIPS mode enforces somewhere minimal key size.
As 64bit key is no longer useful anyway, just remove it.

Apparently cipher_null is now more safer with the longer key,
isn't? :-)
2022-01-21 12:30:10 +01:00
Milan Broz
91db91352f Get rid of SHA1 in tests.
OpenSSL with FIPS provider now doesn't not support SHA1.
Kernel still does, but some operations fail anyway (we get
hash size from crypto backend).

Let's remove most of the SHA1 use in tests, SHA1 removal
will happen anyway.

The LUKS1 compatimage is regenerated with the same parameters,
just hash is switched to sha256 so we do not need to fix tests.
2022-01-21 12:29:36 +01:00
Milan Broz
05a237be2a Fix PBKDF benchmark in OpenSSL3 FIPS mode.
OpenSSL now enforces minimal parameters for PBKDF2 according to SP 800-132
key length (112 bits), minimal salt length (128 bits) and minimal number
of iterations (1000).

Our benchmark violates this, causeing cryptsetup misbehave for luksFormat.

Just inrease tet salt to 16 bytes here, it will little bit influence benchmark,
but there is no way back.
2022-01-21 09:47:13 +01:00
daniel.zatovic
cb9a204a98 Remove merge jobs and RHEL 9 FIPS package updates. 2022-01-20 15:10:17 +00:00
daniel.zatovic
bec18489c7 Add new RHEL and CentOS runners. 2022-01-20 15:10:17 +00:00
Milan Broz
f596e48cc4 Increase timeout for interactive input test. 2022-01-20 14:37:31 +01:00
Vojtech Trefny
ae213537ba utf8: Fix clang null pointer dereference warning 2022-01-20 13:01:05 +01:00
Milan Broz
c4e60a7037 Use only default flags for test CI compilation. 2022-01-20 11:27:04 +01:00
Milan Broz
12a07dcdbd Fix scan-build to fail for reported warnings. 2022-01-20 11:16:55 +01:00
Vojtech Trefny
6e47fb6d85 Use custom utf8/16 conversion instead of iconv
We can avoid the additional dependency by using few functions from
systemd.
2022-01-19 17:09:32 +00:00
Ondrej Kozina
e12ce642a1 Fix typo in repair prompt. 2022-01-19 14:31:11 +01:00
Milan Broz
9a1b3a8aff Remove old base64 implementation and switch to crypto_backend.
This completely removes old base64 implementation.
Code was originally taken from coreutils but recent changes
added many new funtions we do not need.
2022-01-18 12:15:20 +01:00
Milan Broz
f1c7a9896d Add base64 wrappers to crypto_backend.
We need LGPL 2.1+ implementation in crypto backend and also this code
is much easier to read and maintain.
2022-01-18 12:15:20 +01:00
Vojtech Trefny
c210c3a665 man: Fix default locking directory in cryptsetup man page
The default location has been changed from /run/lock/cryptsetup to
/run/cryptsetup in 6f4c15b2b2.
2022-01-17 07:31:54 +01:00
Milan Broz
8e27541a3b Relax a little bit warnings in CI and run it in merge requests.
It is almost impossible for contributors to replicate our warnings
if filtered. Let's make it simpler.

Also run clang with extended warnings (some fixes needed).
2022-01-15 16:11:49 +01:00
Guilhem Moulin
1592511fdb Local tests: Add option to avoid treating skipped tests as success.
`make -f Makefile.localtest tests CRYPTSETUP_PATH=/sbin TESTSUITE_NOSKIP=y`
exits with status 77 upon the first skipped test.  This can be useful
when a full test coverage is desired.

As before the test suite exits (with status 1) as soon as a failed (or
skipped when the TESTSUITE_NOSKIP environment variable is defined to
non-empty string) test is encountered.
2022-01-15 11:55:18 +00:00
Guilhem Moulin
cbc143bf95 tests: Replace which calls with command -v.
AFAIK older versions of the POSIX Standard didn't specify a way to
locate commands.  Many operating systems and distributions added a
which(1) utility for that purpose, unfortunately without consistent
behavior across the board.

OTOH POSIX.1-2008 (or was it older?  POSIX.1-2001 mentions it too, but
with a restriction: “On systems supporting the User Portability Utilities
option”) specifies that `command -v` can be used for that purpose:

    https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/utilities/command.html

Moreover the standard adds that if the argument is neither a valid
utility, builtin, shell function nor alias then “no output shall be
written and the exit status shall reflect that the name was not found”.
It's therefore no longer needed to void the error output (spewing error
messages was one of the inconsistent behavior of the different which(1)
utilities).

The upcoming Debian 12 (codename Bookworm) appears to have deprecated
its which(1) utility (as a first step for its removal from the base
system):

    $ which foo
    /usr/bin/which: this version of `which' is deprecated; use `command -v' in scripts instead.

In most places the deprecation notice isn't visible when running the
test suite because most `which` calls run with the error output
redirected to /dev/null, however this is not the case everywhere:

    https://gitlab.com/cryptsetup/cryptsetup/-/blob/v2.4.3/tests/integrity-compat-test#L333
    https://gitlab.com/cryptsetup/cryptsetup/-/blob/v2.4.3/tests/reencryption-compat-test2#L232

This commit replaces all `which` calls from tests/* with `command -v`,
and removes the error output redirection.
2022-01-15 08:50:15 +00:00
Guilhem Moulin
3e160447eb Fix minor spelling error.
(Found by Lintian.)
2022-01-14 15:48:25 +01:00
Milan Broz
5ab106465c Update README. 2022-01-13 10:23:27 +01:00
Milan Broz
79720dabb9 Fix reencrypt mangle test for older jq. 2022-01-13 10:07:38 +01:00
Milan Broz
0bff50a31a Remove reference to missing test. 2022-01-12 18:38:37 +01:00
Milan Broz
c2291a1b9b Add Release Notes. 2022-01-12 18:38:30 +01:00
Milan Broz
f1d7d30dbb Update LUKS2 on-disk description. 2022-01-12 18:38:26 +01:00
Ondrej Kozina
00feca3ce0 Allow reencryption metadata repair from cryptsetup. 2022-01-12 18:38:22 +01:00
Ondrej Kozina
ea47937187 Add CRYPT_REENCRYPT_REPAIR_NEEDED flag.
crypt_reencrypt_status() returns this flag if old
online-reencrypt requirement is detected and reencryption
keyslot digest is missing.

crypt_reencrypt_init_by_passphrase() with same flag applied
repairs (upgrade) reencryption metadata so that
automatic reencryption recovery during activation
is again possible and reencryption operation can be resumed
post CVE-2021-4122 fix.
2022-01-12 18:38:17 +01:00
Milan Broz
f77b26b42b Add reencryption mangle test 2022-01-12 18:38:14 +01:00
Ondrej Kozina
6c8314b297 Make reencryption flag and keyslot inseparable.
LUKS2 validation code now requires reencrypt keyslot together with
online-reencryption flag or none of those.
2022-01-12 18:38:10 +01:00
Ondrej Kozina
59e39e484a Rename LUKS2_keyslot_reencrypt_create function.
The function never writes on-disk. Also removed validation
function call-in since it will be called later before
writing on-disk and metadata does not have to be complete
at the moment of LUKS2_keyslot_reencrypt_allocate call.
2022-01-12 18:38:06 +01:00
Ondrej Kozina
b61ec23e48 Add segments validation for reencryption.
Effective segments during LUKS2 reencryption must
match key characteristics of backup segment
(cipher, sector_size, segment type).
2022-01-12 18:37:52 +01:00
Ondrej Kozina
7420f879e0 Split requirements validation from config section validation. 2022-01-12 14:01:44 +01:00
Ondrej Kozina
7de8ff5ccf Expose json_segment_contains_flag to internal library. 2022-01-12 14:01:04 +01:00
Ondrej Kozina
b4ba1d8758 Move requirement helpers for later changes. 2022-01-12 14:00:57 +01:00
Milan Broz
139d663541 Add disable-luks2 reencryption configure option.
The option --disable-luks2-reencryption completely disable
LUKS2 reencryption code.

When used, the libcryptsetup library can read metadata with
reencryption code, but all reencryption API calls and cryptsetup
reencrypt commands are disabled.

Devices with online reencryption in progress cannot be activated.

This option can cause some incompatibilities. Please use with care.
2022-01-12 13:58:35 +01:00
Milan Broz
665816ae4d Print better error if resilience hash is not available. 2022-01-12 13:56:46 +01:00
Milan Broz
c522996edc Do not run reencryption recovery when not needed. 2022-01-12 13:56:22 +01:00
Milan Broz
750afe309f Reenc keyslot must have key_size == 1. 2022-01-12 13:55:49 +01:00
Milan Broz
eb220d834d Fix debug message. 2022-01-12 13:55:39 +01:00
Ondrej Kozina
0113ac2d88 Fix CVE-2021-4122 - LUKS2 reencryption crash recovery attack
Fix possible attacks against data confidentiality through LUKS2 online
reencryption extension crash recovery.

An attacker can modify on-disk metadata to simulate decryption in
progress with crashed (unfinished) reencryption step and persistently
decrypt part of the LUKS device.

This attack requires repeated physical access to the LUKS device but
no knowledge of user passphrases.

The decryption step is performed after a valid user activates
the device with a correct passphrase and modified metadata.
There are no visible warnings for the user that such recovery happened
(except using the luksDump command). The attack can also be reversed
afterward (simulating crashed encryption from a plaintext) with
possible modification of revealed plaintext.

The problem was caused by reusing a mechanism designed for actual
reencryption operation without reassessing the security impact for new
encryption and decryption operations. While the reencryption requires
calculating and verifying both key digests, no digest was needed to
initiate decryption recovery if the destination is plaintext (no
encryption key). Also, some metadata (like encryption cipher) is not
protected, and an attacker could change it. Note that LUKS2 protects
visible metadata only when a random change occurs. It does not protect
against intentional modification but such modification must not cause
a violation of data confidentiality.

The fix introduces additional digest protection of reencryption
metadata. The digest is calculated from known keys and critical
reencryption metadata. Now an attacker cannot create correct metadata
digest without knowledge of a passphrase for used keyslots.
For more details, see LUKS2 On-Disk Format Specification version 1.1.0.
2022-01-12 13:50:37 +01:00
Josef Andersson
5a17d677c4 po: update sv.po (from translationproject.org) 2021-12-25 16:19:16 +01:00
Мирослав Николић
629fb68aa8 po: update sr.po (from translationproject.org) 2021-12-25 16:19:16 +01:00
Antonio Ceballos
31b36a410b po: update es.po (from translationproject.org) 2021-12-25 16:19:16 +01:00
Tianjia Zhang
80b2cb213c Fix manual typo. 2021-12-24 16:43:57 +08:00
Sean
f996b9b9e8 Update README.md 2021-12-08 16:44:01 +00:00
Milan Broz
c4b66283fe Run CI on stable branches.
The stable branch is named "v2.<minor>.x".
2021-12-01 22:43:33 +01:00
Milan Broz
feb4d24327 Do not mix tabs and spaces in GitHub CI script. 2021-11-28 21:04:12 +01:00
Milan Broz
8a3716d18c Do not mix tabs and spaces in Gitlab CI script. 2021-11-28 21:02:09 +01:00
Milan Broz
e5534c47e9 Fix tabs in GitLab CI scripts and remove gcc comment.
The -Wall changes according to gcc versions.
2021-11-28 21:00:25 +01:00
Milan Broz
03e4cc6f6d Fix missing backslash in CI. 2021-11-28 20:52:31 +01:00
Milan Broz
7940563131 Add limitation to cryptsetup group again in CI. 2021-11-28 20:50:20 +01:00
Vojtech Trefny
6eae9f6e91 bitlk: Fix support for startup key with new metadata entry
Windows 11 now includes the BitLocker volume GUID in the BEK file
metadata entries. This was previously not included so cryptsetup
refused to open the file because there was an unknown metadata
entry in the startup key.

Fixes: #690
2021-11-28 17:10:25 +01:00
Ondrej Kozina
1c36ddfe73 Unify few reencryption error messages. 2021-11-24 19:58:57 +01:00
Ondrej Kozina
db9991d471 Clarify some variable names in reencryption utils. 2021-11-24 19:58:57 +01:00
Ondrej Kozina
6bc1378ddb Remove LUKS2 encryption data size restriction.
LUKS2 encryption with data shift required remaining
data size (size remaining after substracting --reduce-data-size value)
to be at least --reduce-data-size. This was wrong. Remaining
data size restriction should be correctly at least single sector
(whatever sector size is selected or auto-detected).
2021-11-24 19:58:57 +01:00
Ondrej Kozina
d4e49f9988 Enable legacy reencryption compat test. 2021-11-24 19:58:57 +01:00
Ondrej Kozina
2e23913e3b Fix compat-test-args to reflect on luks1 reencryption params.
--decrypt parameter works with LUKS1 format even without --header
parameter.
2021-11-24 19:58:57 +01:00
Ondrej Kozina
8d7bce164c Fix compat-test-args test.
Option --device-size was never used in open action.
2021-11-24 19:58:57 +01:00
Ondrej Kozina
2cf11a2fa4 All options allowed with luksFormat also pass with reencrypt action.
During encryption (both formats) we need full luksFormat action
parameters set
2021-11-24 19:58:57 +01:00
Ondrej Kozina
bd4405ada6 Add --keyslot-cipher and --keyslot-key-size action restrictions. 2021-11-24 19:58:57 +01:00
Ondrej Kozina
c46fd35e56 Add per action parameters verification routines.
It cleans up bloated main function and improves code clarity on
when some parameters need to be verified and when not.
2021-11-24 19:58:57 +01:00
Ondrej Kozina
957c58db41 Remove cryptsetup-reencrypt from the project. 2021-11-24 19:58:57 +01:00
Ondrej Kozina
06fd461bd8 Add --new alias for --encrypt parameter.
To be compatible with cryptsetup-reencrypt utility.
2021-11-24 19:58:57 +01:00
Ondrej Kozina
686acf82a2 Add option to turn off O_EXCL flag in device_check() 2021-11-24 19:58:57 +01:00
Ondrej Kozina
cade8201d2 Enable legacy LUKS1 reencryption in cryptsetup utility. 2021-11-24 19:58:57 +01:00
Ondrej Kozina
390f3f5b73 Remove (legacy) LUKS2 code from former cryptsetup-reencrypt utility.
The old LUKS2 reencryption from cryptsetup-reencrypt will not be
supported anymore.
2021-11-24 19:58:57 +01:00
Ondrej Kozina
d5fdf47b19 Copy effective cryptsetup-reencrypt code in new file.
With only minor editing and drop of code path entry and
command line parameters parsing.
2021-11-24 19:58:57 +01:00
Ondrej Kozina
7d77e0dcbd Refactor new LUKS2 reencryption code.
It will ease the merge with legacy LUKS1 reencryption
code later.
2021-11-24 19:58:54 +01:00
Ondrej Kozina
eb0f9b4f29 Move LUKS2 reencrytption code in separate file. 2021-11-24 19:57:37 +01:00
Ondrej Kozina
7b10f71373 Preparation to merge cryptsetup-reencrypt in cryptsetup. 2021-11-24 19:57:37 +01:00
Ondrej Kozina
c82c3509cf Do not build cryptsetup-reencrypt.
Source code will be removed later completely.
2021-11-24 19:57:37 +01:00
Ondrej Kozina
74ad0d71b9 Add --keep-key parameter for LUKS2 reencryption.
One of missing features when comparing to legacy
reencryption code.
2021-11-24 19:57:30 +01:00
Chris Coulson
98cd52c8d7 allow tokens to be replaced
Currently, token import and token add actions will fail if you use the
--token-id option to specify a token ID that is already in use, but there
are scenarios where you might genuinely want to replace an existing token
in a single atomic operation.

A use case for this might be for a keyslot that is protected by a
TPM, where you store the TPM sealed key and associated metadata as a
token and you want to update the PCR policy associated with the sealed
object or make other changes to it. Currently this requires importing a
new token and then removing the old token.

Instead, add a --token-replace option to allow token import and token
add to replace an existing token if you try to add or import one with an
ID that is already in use.
2021-11-23 15:45:33 +00:00
daniel.zatovic
a9bf78adc3 Remove LLVM repo script 2021-11-23 14:57:51 +01:00
Daniel Zaťovič
83efc03426 Add compilation tests and static analysis on the Gitlab shared runner. 2021-11-23 14:53:10 +01:00
Milan Broz
bfc39f68d8 Set devel version. 2021-11-19 14:36:47 +01:00
Milan Broz
ff51d5a8fa Version 2.4.2. 2021-11-18 11:35:45 +01:00
Jakub Bogusz
949ed8c9e2 po: update pl.po (from translationproject.org) 2021-11-18 10:57:02 +01:00
Milan Broz
31698f8388 LUKS convert: also check sysfs for device activity.
On some "broken" systems, udev directory (where we try to check
if device is active) is present, but the symlink is missing.

Let's fallback in this case on sysfs scanning also, otherwise
possible conversion of an active device can cause data corruption.
2021-11-18 08:15:09 +00:00
Milan Broz
c400a84987 Add 2.4.2 release notes. 2021-11-17 13:11:26 +01:00
Yuri Chornoivan
ce52bb2f5a po: update uk.po (from translationproject.org) 2021-11-16 16:53:12 +01:00
Yuri Kozlov
bf374ca9e6 po: update ru.po (from translationproject.org) 2021-11-16 16:53:12 +01:00
Hiroshi Takekawa
17ca463767 po: update ja.po (from translationproject.org) 2021-11-16 16:53:12 +01:00
Frédéric Marchal
aa8d8ec0ae po: update fr.po (from translationproject.org) 2021-11-16 16:53:12 +01:00
Roland Illig
1b08d47045 po: update de.po (from translationproject.org) 2021-11-16 16:53:12 +01:00
Petr Pisar
0f656105e2 po: update cs.po (from translationproject.org) 2021-11-16 16:53:12 +01:00
Milan Broz
0b3a7ecd01 Update cryptsetup.pot. 2021-11-16 16:52:22 +01:00
Milan Broz
a364355c16 Fix missing translation macros. 2021-11-10 15:29:29 +00:00
Milan Broz
7086c414bc Avoid casting of uint64_t to unsigned int in debug messages. 2021-11-10 13:39:54 +00:00
Milan Broz
0bb193d487 Fix code style.
We do not use curly brackets in this context.
2021-11-10 13:39:54 +00:00
Milan Broz
80b57c6e24 Free json buffer on error path.
Code should not return allocated buffer if validation fails.

(But this does not fix a leak, memory is freed later, it is just more readable.)
2021-11-10 13:39:54 +00:00
Milan Broz
9576549fee Fix bogus memory allocation if LUKS2 header size is invalid.
LUKS2 code read the whole header to buffer to verify checksum,
so malloc is called on unvalidated input size parameter.

This can cause out of memory or unintentional device reads.
(Header validation will fail later anyway - the size is unsupported.)

Just do not allow too small and too big allocations here and fail quickly.

Fixes: #683.
2021-11-10 13:39:54 +00:00
Milan Broz
0cc5f2fdf9 Fix debug message printing LUKS2 checksum.
The trailing NUL is written already by snprintf, moreover,
it is written on wrong place here.

Just rely on snprintf here.

Fixes: #685.
2021-11-10 12:56:20 +01:00
Abhijit Menon-Sen
26a3f3b058 Fix typo ("Veryfing") 2021-11-02 08:08:28 +01:00
Milan Broz
e03f3bb36e Set devel version. 2021-11-01 17:11:33 +01:00
Daniel Zaťovič
be5ab79c9d Switch GitLab CI tags for the libvirt custom runner. 2021-10-26 19:28:42 +02:00
Milan Broz
083cdb9310 Add a debug message before running keyslot PBKDF.
This is useful for debugging if the process is killed by OOM.
2021-10-15 19:17:45 +02:00
leongross
ca30d3cda9 fix minor README.md issues 2021-10-12 14:55:16 +00:00
Мирослав Николић
5c17722854 po: update sr.po (from translationproject.org) 2021-10-12 16:54:00 +02:00
Milan Broz
49177aac46 Add test vector for empty password for Argon2.
While it is insecure, we need crypto backend to support this :)
2021-10-06 21:54:49 +02:00
Milan Broz
d20beacba0 Remove redundant link to uuid lib for static build.
Veritysetup does not need to link this library at all, for others
we have link already in flags.
2021-10-06 13:02:51 +02:00
Milan Broz
26cc1644b4 Do not link integritysetup and veritysetup with pwquality.
These tools do not read passphrases, no need to link to these libraries.

Just move the helper code that introduced this dependence as a side-effect.

Fixes: #677
2021-10-06 13:02:19 +02:00
Milan Broz
9ed0036286 CI: comment out fixed project rule for merge request jobs.
We need pipeline to be created here, seems GitLab does not
allow it otherwise.
2021-09-29 15:20:54 +02:00
Milan Broz
00f7d92514 OpenSSL backend: no need to use strlen for KDF param length. 2021-09-29 10:24:45 +00:00
Milan Broz
43674b2903 OpenSSL3 backend: avoid remaining deprecated calls in API.
Implement HMAC through new API.

In reality, these calls are never used (the only user is internal PBKDF2
that is never called with OpenSSL backend).
2021-09-29 10:24:45 +00:00
Milan Broz
5cfd5fc4cd Crypt vectors test: add test for hash/hmac context reset.
The crypto API expects that after final() call the context is reset,
let's test if backend properly supports it.
2021-09-29 10:24:45 +00:00
Milan Broz
9f252d4bf8 Install openssl binary for CI test. 2021-09-27 22:31:34 +02:00
Ondrej Kozina
321057eed5 Add Fedora rawhide runner to CI. 2021-09-27 17:25:13 +02:00
Ondrej Kozina
1a3d049454 Add tags for currently available runners. 2021-09-27 17:09:21 +02:00
Milan Broz
9d1f29a9fd OpenSSL backend: separate KDF wrappers.
Prepare code for later to add Argon2 OpenSSL wrapper more easily.
2021-09-22 08:25:19 +00:00
Milan Broz
da31341d5d OpenSSL3 backend: use predefined macros to construct KDF params. 2021-09-22 08:25:19 +00:00
Milan Broz
10b1d6493e Check if DM create device failed in an early phase.
This happens when concurrent creation of DM devices meets
in the very early state (no device node exists but creation fails).

Return -ENODEV here instead of -EINVAL.

(Should "fix" random verity concurrent test failure.)
2021-09-21 17:58:34 +02:00
Milan Broz
a76310b53f Do not try to set compiler optimization flag if wipe is implemented in libc.
If zeroing memory is implemented through libc call (like memset_bzero),
compiler should never remove such call. It is not needed to set O0
optimization flag explicitly.

Various checkers like annocheck causes problems with these flags,
just remove it where it makes no sense.

(Moreover, we use the same pattern without compiler magic
in crypt_backend_memzero() already.)
2021-09-20 17:42:20 +02:00
Yuri Kozlov
26d26d7134 po: update ru.po (from translationproject.org) 2021-09-17 18:52:18 +02:00
Hector Martin
a1b577c085 Do not attempt to unload external tokens if USE_EXTERNAL_TOKENS is disabled.
This allows building a static binary as long as --disable-external-tokens is used
2021-09-17 05:44:18 +00:00
Milan Broz
8a0682650e Version 2.4.1. 2021-09-15 11:29:09 +02:00
Milan Broz
85e5ccec17 Update cryptsetup.pot. 2021-09-15 11:26:57 +02:00
Milan Broz
3da5352b89 Fix compatible OpenSSL backend constructor definition. 2021-09-15 08:13:49 +02:00
Ondrej Kozina
1569558503 Fix offset bug in LUKS2 encryption code.
The code did not account for data offset when
set via --offset when creating new header in-before
LUKS2 encryption took place.
2021-09-14 16:10:24 +02:00
Ondrej Kozina
ce704859b8 Fix offset error in decryption hotzone.
The hotzone segment offset has to be altered
accordingly no matter the segment type.

Note for testing: This feature is currently
blocked in cli but it should be tested via
API tests anyway.
2021-09-14 15:21:07 +02:00
Milan Broz
fd18e0b1c9 Fix integrity test & non-fips algorithms.
Apparently algorithms can be in /proc/crypto despite they are not available.
Just limit failure of the test to sha and crc algorithms.
2021-09-14 14:51:50 +02:00
Milan Broz
ba4d5680d6 Fix typo and EOL in vector test. 2021-09-14 10:33:38 +02:00
Milan Broz
75e45462f0 Cache FIPS mode check.
We do not support switch while the crypto backend is already initialized,
so it does not make sense to check repeatedly for the FIPS mode status.
2021-09-14 09:56:05 +02:00
Milan Broz
f8eb7b225a Do not load own OpenSSL backend context in FIPS mode.
In the FIPS mode keep configuration up to the system wide config.
2021-09-13 21:56:59 +02:00
Milan Broz
29ea07ef66 OpenSSL backend: make legacy for OpenSSL3 optional and report loaded providers 2021-09-13 21:56:54 +02:00
Ondrej Kozina
6c9d386303 Adapt crypto backend to openssl3 lib context.
Fully leverage openssl custom library context for various
providers (default, legacy). It can be used to properly
free all openssl resources used by libcryptsetup when
libcryptsetup is unloaded (and destructor is triggered).
2021-09-13 16:54:40 +02:00
Arno Wagner
bf84ead85c sync to Wiki 2021-09-13 11:03:15 +02:00
Yuri Chornoivan
ca2ba1a6f5 po: update uk.po (from translationproject.org) 2021-09-07 12:41:48 +02:00
Jakub Bogusz
284d1615c8 po: update pl.po (from translationproject.org) 2021-09-07 12:41:48 +02:00
Hiroshi Takekawa
b4181ffa3b po: update ja.po (from translationproject.org) 2021-09-07 12:41:48 +02:00
Frédéric Marchal
8c0caf9a1f po: update fr.po (from translationproject.org) 2021-09-07 12:41:48 +02:00
Roland Illig
d2682c4841 po: update de.po (from translationproject.org) 2021-09-07 12:41:48 +02:00
Petr Pisar
39ddcfaaa0 po: update cs.po (from translationproject.org) 2021-09-07 12:41:48 +02:00
Milan Broz
669ad1933a Fix possible use of unallocated parameter.
(Introduced in previous patches.)
2021-08-30 12:39:17 +02:00
Milan Broz
84fa6ffbde Remove some Doxygen docs warnings. 2021-08-30 12:32:42 +02:00
Milan Broz
2206f7f108 Prepare version for translation. 2021-08-30 11:57:11 +02:00
JT Moree
ec946b17eb add headers
add headers for Help: documentation and mailing list
2021-08-27 14:39:03 +00:00
JT Moree
a619cc1757 rename reference to specifications 2021-08-27 14:39:03 +00:00
JT Moree
6c3e2e2bee rework Help section 2021-08-27 14:39:03 +00:00
Ondrej Kozina
621dcea8ee Do not init LUKS2 decryption for devices with data offset.
Currently LUKS2 decryption cannot perform data decryption
with data shift. Even though we can decrypt devices with
data offset > 0 in LUKS2 metadata it does not make much
sense. Such devices cannot be easily mounted after decryption
is finished due to said data offset (fs superblock is moved
typicaly by 16MiBs).
2021-08-27 16:26:37 +02:00
Milan Broz
f6fb530121 Repair also lowercase hash in LUKS1 header.
This patch removes magic for backup load that quietly
run lowecase conversion and add this possibility to repair command.

Most of crypto backends allow uppercase though.
2021-08-25 16:45:00 +00:00
Milan Broz
0066f9dd83 Fix LUKS1 repair to repair wrong ECB mode.
1) Crypsetup repair should try to call crypt_repair() even
if crypt_load is ok - it has no validate system unlike LUKS2
and some errors cannot be hard load errors.

2) Move ECB fix to repair code, do not try magic on load that
no longer works.

And do not use ECB :)

Fixes: #664
2021-08-25 16:45:00 +00:00
Ondrej Kozina
46b70d7317 Add error message when assigning token to inactive keyslot.
While adding or importing new token and assigning immediately to
keyslot it would be useful to provide specific error message
directly from cryptsetup utility when keyslot does not exist.
2021-08-25 16:11:00 +00:00
Milan Broz
8c28774917 Fix vector test print message additional parameter. 2021-08-25 18:09:56 +02:00
Milan Broz
e5d84156e4 Fix linker to use -ldl if external tokens are used.
Also run check for symbols only if external modules are really used.
2021-08-25 13:50:33 +02:00
Milan Broz
5f2c751dd8 Use dlsym() for token load if dlvsym() is not available.
To be discussed. Anyway, we need to support distros with musl...
2021-08-25 13:39:07 +02:00
Ondrej Kozina
53b22cc32e Fix deferred remove test failure on non-udev systems.
Deferred remove non-udev enabled libdevmapper removes
device mapper symlinks immediately. We have to check
device size from sysfs attributes.
2021-08-25 13:39:03 +02:00
Milan Broz
26679e223c Trigger read event for verity test to mark device as corrupted.
If distro does not use udev/blkid, there is no IO event after activation.
Kernel does not mark the device corrupted then (it happens on the
first IO). Just add a simple read to trigger it.
2021-08-25 13:38:58 +02:00
Milan Broz
9b7d3be5c6 Skip UUID= cryptsetup activation test if /dev has no uuid links.
There are still distros that tries to reinvent the wheel, let just
ignore if /dev is not propagated by symlinks that we depend on.
2021-08-25 13:38:54 +02:00
Milan Broz
358dec19b2 Use compatible flags for BusyBox diff command. 2021-08-25 13:38:50 +02:00
Milan Broz
863fd08305 Skip test if incompatible tar from BusyBox is installed.
We depend on sparse images that BusyBox tar cannot handle.
Just install the full tar package for tests.
2021-08-25 13:38:46 +02:00
Milan Broz
93481d1566 Use compatible flags for BusyBox free command. 2021-08-25 13:38:41 +02:00
Milan Broz
3a79b2b09b Fix gettext (-lintl) linker flags.
The external gettext library should be used on main libcryptsetup,
not later for programs (these do not call any translations).

(Also it was in the wrong order there failing compilation.)
2021-08-25 13:38:23 +02:00
Milan Broz
246d306eeb Check for argp library that can be standalone.
Some systems without glibc provides standalone package for argp.
2021-08-25 13:37:33 +02:00
Milan Broz
03943acbb1 Remove obsolete AC_HEADER_STDC macro.
This should be no longer used.
We do not support systems without standard headers anyway.
2021-08-25 13:37:29 +02:00
Milan Broz
20b678c9f3 Fix symbol version test if dlvsym() is not available.
If we have no dlvsym(), just run dlsym() test.
2021-08-25 13:37:25 +02:00
Milan Broz
e008a88b98 Test Coverity action. 2021-08-19 14:29:53 +02:00
Milan Broz
5efa782567 Ignore default algorithm test in FIPS mode.
This can cause unexpected failures (despite it is kind of misconfiguration).
2021-08-19 13:36:13 +02:00
Milan Broz
ab37ad0dc9 Update doxyfile. 2021-08-19 10:31:21 +02:00
Milan Broz
03208167b2 Fix release notes. 2021-08-18 17:19:50 +02:00
477 changed files with 90461 additions and 35470 deletions

31
.codeql-config.yml Normal file
View File

@@ -0,0 +1,31 @@
name: "Cryptsetup CodeQL config"
query-filters:
- exclude:
id: cpp/fixme-comment
- exclude:
id: cpp/empty-block
- exclude:
id: cpp/poorly-documented-function
- exclude:
id: cpp/loop-variable-changed
- exclude:
id: cpp/empty-if
- exclude:
id: cpp/long-switch
- exclude:
id: cpp/complex-condition
- exclude:
id: cpp/commented-out-code
# These produce many false positives
- exclude:
id: cpp/uninitialized-local
- exclude:
id: cpp/path-injection
- exclude:
id: cpp/missing-check-scanf
# CodeQL should understand coverity [toctou] comments
- exclude:
id: cpp/toctou-race-condition

View File

@@ -4,9 +4,10 @@ set -ex
PACKAGES=(
git make autoconf automake autopoint pkg-config libtool libtool-bin
gettext libssl-dev libdevmapper-dev libpopt-dev uuid-dev libsepol1-dev
libjson-c-dev libssh-dev libblkid-dev tar libargon2-0-dev libpwquality-dev
sharutils dmsetup jq xxd expect keyutils netcat passwd openssh-client sshpass
gettext libssl-dev libdevmapper-dev libpopt-dev uuid-dev libsepol-dev
libjson-c-dev libssh-dev libblkid-dev tar libargon2-dev libpwquality-dev
sharutils dmsetup jq xxd expect keyutils netcat-openbsd passwd openssh-client
sshpass asciidoctor meson ninja-build
)
COMPILER="${COMPILER:?}"

View File

@@ -12,27 +12,27 @@ CXX="g++${COMPILER_VERSION:+-$COMPILER_VERSION}"
set -ex
for phase in "${PHASES[@]}"; do
case $phase in
CONFIGURE)
opts=(
--enable-libargon2
)
case $phase in
CONFIGURE)
opts=(
--enable-libargon2
)
sudo -E git clean -xdf
sudo -E git clean -xdf
./autogen.sh
CC="$CC" CXX="$CXX" CFLAGS="${CFLAGS[@]}" CXXFLAGS="${CXXFLAGS[@]}" ./configure "${opts[@]}"
;;
MAKE)
make -j
make -j -C tests check-programs
;;
CHECK)
make check
;;
./autogen.sh
CC="$CC" CXX="$CXX" CFLAGS="${CFLAGS[@]}" CXXFLAGS="${CXXFLAGS[@]}" ./configure "${opts[@]}"
;;
MAKE)
make -j
make -j -C tests check-programs
;;
CHECK)
make check
;;
*)
echo >&2 "Unknown phase '$phase'"
exit 1
esac
*)
echo >&2 "Unknown phase '$phase'"
exit 1
esac
done

View File

@@ -2,9 +2,9 @@ name: Build test
on:
push:
branches:
- 'master'
- 'main'
- 'wip-luks2'
- 'v2.3.x'
- 'v2.*.x'
paths-ignore:
- 'docs/**'
@@ -16,11 +16,11 @@ jobs:
fail-fast: false
matrix:
env:
- { COMPILER: "gcc", COMPILER_VERSION: "11", RUN_SSH_PLUGIN_TEST: "1" }
- { COMPILER: "gcc", COMPILER_VERSION: "14", RUN_SSH_PLUGIN_TEST: "1" }
env: ${{ matrix.env }}
steps:
- name: Repository checkout
uses: actions/checkout@v1
uses: actions/checkout@v4
- name: Ubuntu setup
run: sudo -E .github/workflows/cibuild-setup-ubuntu.sh
- name: Configure & Make

53
.github/workflows/codeql.yml vendored Normal file
View File

@@ -0,0 +1,53 @@
name: "CodeQL"
on:
push:
branches:
- 'main'
- 'wip-luks2'
- 'v2.*.x'
permissions:
contents: read
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
if: github.repository == 'mbroz/cryptsetup'
concurrency:
group: ${{ github.workflow }}-${{ matrix.language }}-${{ github.ref }}
cancel-in-progress: true
permissions:
actions: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'cpp' ]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
queries: +security-extended,security-and-quality
config-file: .codeql-config.yml
- name: Install dependencies
run: |
sudo -E .github/workflows/cibuild-setup-ubuntu.sh
# Force autoconf for now, meson is broken in analysis step
rm meson.build
env: { COMPILER: "gcc", COMPILER_VERSION: "14", RUN_SSH_PLUGIN_TEST: "1" }
- name: Autobuild
uses: github/codeql-action/autobuild@v3
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3

48
.github/workflows/coverity.yml vendored Normal file
View File

@@ -0,0 +1,48 @@
name: Coverity test
on:
push:
branches:
- 'coverity_scan'
paths-ignore:
- 'docs/**'
jobs:
latest:
runs-on: ubuntu-latest
if: github.repository == 'mbroz/cryptsetup'
steps:
- name: Repository checkout
uses: actions/checkout@v4
- name: Ubuntu setup
run: sudo -E .github/workflows/cibuild-setup-ubuntu.sh
env:
COMPILER: "gcc"
COMPILER_VERSION: "14"
- name: Install Coverity
run: |
wget -q https://scan.coverity.com/download/cxx/linux64 --post-data "token=$TOKEN&project=mbroz/cryptsetup" -O cov-analysis-linux64.tar.gz
mkdir cov-analysis-linux64
tar xzf cov-analysis-linux64.tar.gz --strip 1 -C cov-analysis-linux64
env:
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
- name: Run autoconf & configure
run: |
./autogen.sh
./configure
- name: Run cov-build
run: |
export PATH=`pwd`/cov-analysis-linux64/bin:$PATH
cov-build --dir cov-int make
- name: Submit to Coverity Scan
run: |
tar czvf cryptsetup.tgz cov-int
curl \
--form project=mbroz/cryptsetup \
--form token=$TOKEN \
--form email=gmazyland@gmail.com \
--form file=@cryptsetup.tgz \
--form version=trunk \
--form description="`./cryptsetup --version`" \
https://scan.coverity.com/builds?project=mbroz/cryptsetup
env:
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}

6
.gitignore vendored
View File

@@ -6,6 +6,8 @@ Makefile.in.in
*.lo
*.la
*.o
*.so
*.8
**/*.dirstamp
.deps/
.libs/
@@ -15,6 +17,7 @@ ABOUT-NLS
aclocal.m4
autom4te.cache/
compile
compile_commands.json
config.guess
config.h
config.h.in
@@ -54,3 +57,6 @@ tests/luks1-images
tests/tcrypt-images
tests/unit-utils-io
tests/vectors-test
tests/test-symbols-list.h
tests/all-symbols-test
tests/fuzz/LUKS2.pb*

View File

@@ -1,46 +1,25 @@
default:
before_script:
- sudo apt-get -y update --fix-missing
- >
sudo apt-get -y install -y -qq git gcc make
autoconf automake autopoint pkg-config libtool libtool-bin gettext
libssl-dev libdevmapper-dev libpopt-dev uuid-dev libsepol1-dev
libjson-c-dev libssh-dev libblkid-dev tar libargon2-0-dev
libpwquality-dev sharutils dmsetup jq xxd expect keyutils
netcat passwd openssh-client sshpass
- sudo apt-get -y build-dep cryptsetup
- sudo -E git clean -xdf
- ./autogen.sh
- ./configure --enable-libargon2
stages:
- test
- test-opal
# Merge request: Build and run only non-root tests
test-mergerq-job:
stage: test
interruptible: true
rules:
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- make -j
- make -j -C tests check-programs
- make check
.fail_if_coredump_generated:
after_script:
- '[ "$(ls -A /var/coredumps)" ] && exit 1 || true'
# For main branch commit, run all tests as root
test-main-commit-job:
stage: test
interruptible: true
variables:
RUN_SSH_PLUGIN_TEST: "1"
rules:
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
script:
- make -j
- make -j -C tests check-programs
- sudo -E make check
- sudo -E make clean
include:
- local: .gitlab/ci/debian.yml
- local: .gitlab/ci/fedora.yml
- local: .gitlab/ci/fedora-opal.yml
- local: .gitlab/ci/rhel.yml
- local: .gitlab/ci/centos.yml
# - local: .gitlab/ci/annocheck.yml
- local: .gitlab/ci/csmock.yml
- local: .gitlab/ci/gitlab-shared-docker.yml
- local: .gitlab/ci/compilation-various-disables.yml
- local: .gitlab/ci/compilation-gcc.gitlab-ci.yml
- local: .gitlab/ci/compilation-clang.gitlab-ci.yml
- local: .gitlab/ci/compilation-spellcheck.yml
- local: .gitlab/ci/alpinelinux.yml
- local: .gitlab/ci/debian-i686.yml
- local: .gitlab/ci/cifuzz.yml
- local: .gitlab/ci/ubuntu.yml

View File

@@ -0,0 +1,55 @@
.alpinelinux-dependencies:
variables:
DISTRO: cryptsetup-alpine-edge
extends:
- .fail_if_coredump_generated
before_script:
- >
sudo apk add
lvm2-dev openssl-dev popt-dev util-linux-dev json-c-dev
argon2-dev device-mapper which sharutils gettext gettext-dev automake
autoconf libtool build-base keyutils tar jq expect git asciidoctor
- ./autogen.sh
- ./configure --prefix=/usr --libdir=/lib --sbindir=/sbin --disable-static --enable-libargon2 --with-crypto_backend=openssl --disable-external-tokens --disable-ssh-token --enable-asciidoc
test-main-commit-job-alpinelinux:
extends:
- .alpinelinux-dependencies
tags:
- libvirt
- cryptsetup-alpine-edge
stage: test
interruptible: true
variables:
RUN_SSH_PLUGIN_TEST: "0"
rules:
- if: $RUN_SYSTEMD_PLUGIN_TEST != null
when: never
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
script:
- make -j
- make -j -C tests check-programs
- sudo -E make check
test-mergerq-job-alpinelinux:
extends:
- .alpinelinux-dependencies
tags:
- libvirt
- cryptsetup-alpine-edge
stage: test
interruptible: true
variables:
RUN_SSH_PLUGIN_TEST: "0"
rules:
- if: $RUN_SYSTEMD_PLUGIN_TEST != null
when: never
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- make -j
- make -j -C tests check-programs
- sudo -E make check

18
.gitlab/ci/annocheck.yml Normal file
View File

@@ -0,0 +1,18 @@
test-main-commit-job-annocheck:
extends:
- .fail_if_coredump_generated
tags:
- libvirt
- cryptsetup-rhel-9
stage: test
interruptible: true
allow_failure: true
variables:
DISTRO: cryptsetup-rhel-9
RUN_SSH_PLUGIN_TEST: "1"
rules:
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
script:
- sudo /opt/run-annocheck.sh

32
.gitlab/ci/build_srpm Executable file
View File

@@ -0,0 +1,32 @@
#!/bin/bash
set -e
SAVED_PWD=$(pwd)
GIT_DIR="$SAVED_PWD/upstream_git"
SPEC="$GIT_DIR/misc/fedora/cryptsetup.spec"
rm -fr $GIT_DIR
git clone -q --depth 1 https://gitlab.com/cryptsetup/cryptsetup.git $GIT_DIR
cd $GIT_DIR
GIT_COMMIT=$(git rev-parse --short=8 HEAD)
[ -z "$GIT_COMMIT" ] && exit 1
sed -i "s/^AC_INIT.*/AC_INIT([cryptsetup],[$GIT_COMMIT])/" $GIT_DIR/configure.ac
sed -i "s/^Version:.*/Version: $GIT_COMMIT/" $SPEC
sed -i "s/%{version_no_tilde}/$GIT_COMMIT/" $SPEC
sed -i "2i %global source_date_epoch_from_changelog 0" $SPEC
sed -i "3i %define _unpackaged_files_terminate_build 0" $SPEC
./autogen.sh
./configure
make -j dist
rpmbuild --define "_sourcedir $GIT_DIR" --define "_srcrpmdir $SAVED_PWD" -bs $SPEC
cd $SAVED_PWD
rm -fr $GIT_DIR
exit 0

65
.gitlab/ci/centos.yml Normal file
View File

@@ -0,0 +1,65 @@
.centos-openssl-backend:
variables:
DISTRO: cryptsetup-centos-stream-9
extends:
- .fail_if_coredump_generated
before_script:
- sudo dnf clean all
- >
sudo dnf -y -q install
autoconf automake device-mapper-devel gcc gettext-devel json-c-devel
libblkid-devel libpwquality-devel libselinux-devel libssh-devel libtool
libuuid-devel make popt-devel libsepol-devel nc openssh-clients passwd
pkgconfig sharutils sshpass tar uuid-devel vim-common device-mapper
expect gettext git jq keyutils openssl-devel openssl gem swtpm swtpm-tools
tpm2-tools
- sudo gem install asciidoctor
- sudo -E git clean -xdf
- ./autogen.sh
- ./configure --enable-fips --enable-pwquality --with-crypto_backend=openssl --enable-asciidoc
# non-FIPS jobs
test-main-commit-centos-stream9:
extends:
- .centos-openssl-backend
tags:
- libvirt
- cryptsetup-centos-stream-9
stage: test
interruptible: true
variables:
RUN_SSH_PLUGIN_TEST: "1"
RUN_KEYRING_TRUSTED_TEST: "1"
rules:
- if: $RUN_SYSTEMD_PLUGIN_TEST != null
when: never
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
script:
- make -j
- make -j -C tests check-programs
- sudo -E make check
test-mergerq-centos-stream9:
extends:
- .centos-openssl-backend
tags:
- libvirt
- cryptsetup-centos-stream-9
stage: test
interruptible: true
variables:
RUN_SSH_PLUGIN_TEST: "1"
RUN_KEYRING_TRUSTED_TEST: "1"
rules:
- if: $RUN_SYSTEMD_PLUGIN_TEST != null
when: never
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- make -j
- make -j -C tests check-programs
- sudo -E make check

View File

@@ -0,0 +1,55 @@
#!/bin/bash
set -ex
PACKAGES=(
git make autoconf automake autopoint pkg-config libtool libtool-bin
gettext libssl-dev libdevmapper-dev libpopt-dev uuid-dev libsepol-dev
libjson-c-dev libssh-dev libblkid-dev tar libargon2-dev libpwquality-dev
sharutils dmsetup jq xxd expect keyutils netcat-openbsd passwd openssh-client
sshpass asciidoctor
)
COMPILER="${COMPILER:?}"
COMPILER_VERSION="${COMPILER_VERSION:?}"
sed -i 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources
# use this on older Ubuntu
# grep -E '^deb' /etc/apt/sources.list > /etc/apt/sources.list~
# sed -Ei 's/^deb /deb-src /' /etc/apt/sources.list~
# cat /etc/apt/sources.list~ >> /etc/apt/sources.list
apt-get -y update --fix-missing
DEBIAN_FRONTEND=noninteractive apt-get -yq install software-properties-common wget lsb-release
RELEASE="$(lsb_release -cs)"
if [[ $COMPILER == "gcc" ]]; then
# Latest gcc stack deb packages provided by
# https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test
add-apt-repository -y ppa:ubuntu-toolchain-r/test
PACKAGES+=(gcc-$COMPILER_VERSION)
elif [[ $COMPILER == "clang" ]]; then
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
add-apt-repository -n "deb http://apt.llvm.org/${RELEASE}/ llvm-toolchain-${RELEASE}-${COMPILER_VERSION} main"
# scan-build
PACKAGES+=(clang-tools-$COMPILER_VERSION clang-$COMPILER_VERSION lldb-$COMPILER_VERSION lld-$COMPILER_VERSION clangd-$COMPILER_VERSION)
PACKAGES+=(perl)
else
exit 1
fi
#apt-get -y update --fix-missing
(r=3;while ! apt-get -y update --fix-missing ; do ((--r))||exit;sleep 5;echo "Retrying";done)
DEBIAN_FRONTEND=noninteractive apt-get -yq install "${PACKAGES[@]}"
apt-get -y build-dep cryptsetup
echo "====================== VERSIONS ==================="
if [[ $COMPILER == "clang" ]]; then
echo "Using scan-build${COMPILER_VERSION:+-$COMPILER_VERSION}"
fi
${COMPILER}-$COMPILER_VERSION -v
echo "====================== END VERSIONS ==================="

46
.gitlab/ci/cifuzz.yml Normal file
View File

@@ -0,0 +1,46 @@
cifuzz:
variables:
OSS_FUZZ_PROJECT_NAME: cryptsetup
CFL_PLATFORM: gitlab
CIFUZZ_DEBUG: "True"
FUZZ_SECONDS: 300 # 5 minutes per fuzzer
ARCHITECTURE: "x86_64"
DRY_RUN: "False"
LOW_DISK_SPACE: "True"
BAD_BUILD_CHECK: "True"
LANGUAGE: "c"
DOCKER_HOST: "tcp://docker:2375"
DOCKER_IN_DOCKER: "true"
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
image:
name: gcr.io/oss-fuzz-base/cifuzz-base
entrypoint: [""]
services:
- docker:dind
stage: test
parallel:
matrix:
- SANITIZER: [address, undefined, memory]
rules:
# Default code change.
# - if: $CI_PIPELINE_SOURCE == "merge_request_event"
# variables:
# MODE: "code-change"
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $BUILD_AND_RUN_FUZZERS != null
before_script:
# Get gitlab's container id.
- export CFL_CONTAINER_ID=`cut -c9- < /proc/1/cpuset`
script:
# Will build and run the fuzzers.
# We use a hack to override CI_JOB_ID, because otherwise a bad path is used
# in GitLab CI environment
- CI_JOB_ID="$CI_PROJECT_NAMESPACE/$CI_PROJECT_TITLE" python3 "/opt/oss-fuzz/infra/cifuzz/cifuzz_combined_entrypoint.py"
artifacts:
# Upload artifacts when a crash makes the job fail.
when: always
paths:
- artifacts/

48
.gitlab/ci/clang-Wall Executable file
View File

@@ -0,0 +1,48 @@
#!/bin/bash
# clang -Wall plus other important warnings not included in -Wall
for arg in "$@"
do
case $arg in
-O*) Wuninitialized=-Wuninitialized;; # only makes sense with `-O'
esac
done
CLANG="clang${COMPILER_VERSION:+-$COMPILER_VERSION}"
#PEDANTIC="-std=gnu99"
#PEDANTIC="-pedantic -std=gnu99"
#PEDANTIC="-pedantic -std=gnu99 -Wno-variadic-macros"
#CONVERSION="-Wconversion"
EXTRA="\
-Wextra \
-Wsign-compare \
-Wcast-align
-Werror-implicit-function-declaration \
-Wpointer-arith \
-Wwrite-strings \
-Wswitch \
-Wmissing-format-attribute \
-Winit-self \
-Wold-style-definition \
-Wno-missing-field-initializers \
-Wunused-parameter \
-Wno-long-long"
exec $CLANG $PEDANTIC $CONVERSION \
-Wall $Wuninitialized \
-Wno-switch \
-Wdisabled-optimization \
-Wwrite-strings \
-Wpointer-arith \
-Wbad-function-cast \
-Wmissing-prototypes \
-Wmissing-declarations \
-Wstrict-prototypes \
-Wnested-externs \
-Wcomment \
-Winline \
-Wcast-qual \
-Wredundant-decls $EXTRA \
"$@"

View File

@@ -0,0 +1,59 @@
test-clang-compilation:
extends:
- .gitlab-shared-clang
script:
- export CFLAGS="-Wall -Werror"
- ./autogen.sh
- ./configure
- make -j
- make -j check-programs
test-clang-Wall-script:
extends:
- .gitlab-shared-clang
script:
- export CFLAGS="-g -O0"
- export CC="$CI_PROJECT_DIR/.gitlab/ci/clang-Wall"
- ./autogen.sh
- ./configure
- make -j CFLAGS="-g -O0 -Werror"
- make -j CFLAGS="-g -O0 -Werror" check-programs
test-scan-build:
extends:
- .gitlab-shared-clang
script:
- ./autogen.sh
- scan-build${COMPILER_VERSION:+-$COMPILER_VERSION} -V ./configure CFLAGS="-g -O0"
- make clean
- scan-build${COMPILER_VERSION:+-$COMPILER_VERSION} --status-bugs -maxloop 10 make -j
- scan-build${COMPILER_VERSION:+-$COMPILER_VERSION} --status-bugs -maxloop 10 make -j check-programs
test-scan-build-backends:
extends:
- .gitlab-shared-clang
parallel:
matrix:
- BACKENDS: [
"openssl",
"gcrypt",
"nss",
"kernel",
"nettle",
"mbedtls"
]
rules:
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
changes:
- lib/crypto_backend/*
script:
- DEBIAN_FRONTEND=noninteractive apt-get -yq install libgcrypt20-dev libnss3-dev nettle-dev libmbedtls-dev
- ./autogen.sh
- echo "Configuring with crypto backend $BACKENDS"
- scan-build${COMPILER_VERSION:+-$COMPILER_VERSION} -V ./configure CFLAGS="-g -O0" --with-crypto_backend=$BACKENDS
- make clean
- scan-build${COMPILER_VERSION:+-$COMPILER_VERSION} --status-bugs -maxloop 10 make -j
- scan-build${COMPILER_VERSION:+-$COMPILER_VERSION} --status-bugs -maxloop 10 make -j check-programs
- ./tests/vectors-test

View File

@@ -0,0 +1,57 @@
test-gcc-compilation:
extends:
- .gitlab-shared-gcc
script:
- export CFLAGS="-Wall -Werror"
- ./autogen.sh
- ./configure
- make -j
- make -j check-programs
test-gcc-Wall-script:
extends:
- .gitlab-shared-gcc
script:
- export CFLAGS="-g -O0"
- export CC="$CI_PROJECT_DIR/.gitlab/ci/gcc-Wall"
- ./autogen.sh
- ./configure
- make -j CFLAGS="-g -O0 -Werror"
- make -j CFLAGS="-g -O0 -Werror" check-programs
test-gcc-fanalyzer:
extends:
- .gitlab-shared-gcc
script:
- ./autogen.sh
- ./configure CFLAGS="-Wall -Werror -g -O0 -fanalyzer -fdiagnostics-path-format=separate-events" --host=x86_64
- make -j
- make -j check-programs
test-gcc-fanalyzer-backends:
extends:
- .gitlab-shared-gcc
parallel:
matrix:
- BACKENDS: [
"openssl",
"gcrypt",
"nss",
"kernel",
"nettle",
"mbedtls"
]
rules:
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
changes:
- lib/crypto_backend/*
script:
- DEBIAN_FRONTEND=noninteractive apt-get -yq install libgcrypt20-dev libnss3-dev nettle-dev libmbedtls-dev
- ./autogen.sh
- echo "Configuring with crypto backend $BACKENDS"
- ./configure CFLAGS="-Wall -Werror -g -O0 -fanalyzer -fdiagnostics-path-format=separate-events" --host=x86_64 --with-crypto_backend=$BACKENDS
- make -j
- make -j check-programs
- ./tests/vectors-test

View File

@@ -0,0 +1,20 @@
test-run-spellcheck:
image: ubuntu:noble
tags:
- gitlab-org-docker
stage: test
interruptible: true
rules:
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
artifacts:
name: "spellcheck-$CI_COMMIT_REF_NAME"
paths:
- _spellcheck
before_script:
- apt-get -y update --fix-missing
- apt-get -y install git lintian codespell
script:
- echo "Running spellcheck"
- .gitlab/ci/spellcheck

View File

@@ -0,0 +1,33 @@
test-gcc-disable-compiles:
extends:
- .gitlab-shared-gcc
parallel:
matrix:
- DISABLE_FLAGS: [
"keyring",
"external-tokens ssh-token",
"luks2-reencryption",
"cryptsetup veritysetup integritysetup",
"kernel_crypto",
"udev",
"internal-argon2",
"blkid",
"hw-opal"
]
artifacts:
name: "meson-build-logs-$CI_COMMIT_REF_NAME"
paths:
- meson_builddir/meson-logs
script:
- DEBIAN_FRONTEND=noninteractive apt-get -yq install meson ninja-build
- export CFLAGS="-Wall -Werror"
- ./autogen.sh
- echo "Configuring with --disable-$DISABLE_FLAGS"
- ./configure $(for i in $DISABLE_FLAGS; do echo "--disable-$i"; done)
- make -j
- make -j check-programs
- git checkout -f && git clean -xdf
- meson -v
- echo "Configuring with -D$DISABLE_FLAGS=false"
- meson setup meson_builddir $(for i in $DISABLE_FLAGS; do [ "$i" == "internal-argon2" ] && echo "-Dargon-implementation=internal" || echo "-D$i=false"; done)
- ninja -C meson_builddir

36
.gitlab/ci/csmock.yml Normal file
View File

@@ -0,0 +1,36 @@
.dnf-csmock:
variables:
DISTRO: cryptsetup-fedora-rawhide
DISK_SIZE: 20
extends:
- .fail_if_coredump_generated
before_script:
- >
sudo dnf -y -q install
autoconf automake device-mapper-devel gcc gettext-devel json-c-devel
libblkid-devel libpwquality-devel libselinux-devel
libssh-devel libtool libuuid-devel make popt-devel
libsepol-devel.x86_64 pkgconfig tar uuid-devel git
openssl-devel asciidoctor meson ninja-build
rpm-build csmock
test-commit-job-csmock:
extends:
- .dnf-csmock
tags:
- libvirt
- cryptsetup-fedora-rawhide
stage: test
interruptible: true
allow_failure: true
rules:
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/ || $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- .gitlab/ci/build_srpm
- .gitlab/ci/run_csmock
artifacts:
when: always
paths:
- cryptsetup-csmock-results.tar.xz

View File

@@ -0,0 +1,43 @@
test-mergerq-job-debian-i686:
extends:
- .debian-prep
tags:
- libvirt
- cryptsetup-debian-12i686
stage: test
interruptible: true
variables:
DISTRO: cryptsetup-debian-12i686
RUN_SSH_PLUGIN_TEST: "1"
rules:
- if: $RUN_SYSTEMD_PLUGIN_TEST != null
when: never
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- make -j
- make -j -C tests check-programs
- sudo -E make check
test-main-commit-job-debian-i686:
extends:
- .debian-prep
tags:
- libvirt
- cryptsetup-debian-12i686
stage: test
interruptible: true
variables:
DISTRO: cryptsetup-debian-12i686
RUN_SSH_PLUGIN_TEST: "1"
rules:
- if: $RUN_SYSTEMD_PLUGIN_TEST != null
when: never
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
script:
- make -j
- make -j -C tests check-programs
- sudo -E make check

104
.gitlab/ci/debian.yml Normal file
View File

@@ -0,0 +1,104 @@
.debian-prep:
extends:
- .fail_if_coredump_generated
before_script:
- sudo apt-get -y update
- >
sudo apt-get -y install -y -qq git gcc make autoconf automake autopoint
pkgconf libtool libtool-bin gettext libssl-dev libdevmapper-dev
libpopt-dev uuid-dev libsepol-dev libjson-c-dev libssh-dev libblkid-dev
tar libargon2-dev libpwquality-dev sharutils dmsetup jq xxd expect
keyutils netcat-openbsd passwd openssh-client sshpass asciidoctor
swtpm meson ninja-build python3-jinja2 gperf libcap-dev libtss2-dev
libmount-dev swtpm-tools tpm2-tools
- sudo apt-get -y build-dep cryptsetup
- sudo -E git clean -xdf
- ./autogen.sh
- ./configure --enable-libargon2 --enable-asciidoc
test-mergerq-job-debian:
extends:
- .debian-prep
tags:
- libvirt
- cryptsetup-debian-12
stage: test
interruptible: true
variables:
DISTRO: cryptsetup-debian-12
RUN_SSH_PLUGIN_TEST: "1"
RUN_KEYRING_TRUSTED_TEST: "1"
rules:
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- make -j
- make -j -C tests check-programs
- sudo -E make check
test-main-commit-job-debian:
extends:
- .debian-prep
tags:
- libvirt
- cryptsetup-debian-12
stage: test
interruptible: true
variables:
DISTRO: cryptsetup-debian-12
RUN_SSH_PLUGIN_TEST: "1"
RUN_KEYRING_TRUSTED_TEST: "1"
rules:
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
script:
- make -j
- make -j -C tests check-programs
- sudo -E make check
# meson tests
test-mergerq-job-debian-meson:
extends:
- .debian-prep
tags:
- libvirt
- cryptsetup-debian-12
stage: test
interruptible: true
variables:
DISTRO: cryptsetup-debian-12
RUN_SSH_PLUGIN_TEST: "1"
RUN_KEYRING_TRUSTED_TEST: "1"
rules:
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- sudo apt-get -y install -y -qq meson ninja-build
- meson setup build
- ninja -C build
- cd build && sudo -E meson test --verbose --print-errorlogs
test-main-commit-job-debian-meson:
extends:
- .debian-prep
tags:
- libvirt
- cryptsetup-debian-12
stage: test
interruptible: true
variables:
DISTRO: cryptsetup-debian-12
RUN_SSH_PLUGIN_TEST: "1"
RUN_KEYRING_TRUSTED_TEST: "1"
rules:
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
script:
- sudo apt-get -y install -y -qq meson ninja-build
- meson setup build
- ninja -C build
- cd build && sudo -E meson test --verbose --print-errorlogs

145
.gitlab/ci/fedora-opal.yml Normal file
View File

@@ -0,0 +1,145 @@
.opal-template-fedora:
extends:
- .dnf-openssl-backend
tags:
- libvirt
- cryptsetup-fedora-rawhide
stage: test-opal
interruptible: false
variables:
OPAL2_DEV: "/dev/nvme0n1"
OPAL2_PSID_FILE: "/home/gitlab-runner/psid.txt"
VOLATILE: 1
script:
- sudo dnf install -y -q nvme-cli
- sudo nvme list
- make -j
- make -j -C tests check-programs
- sudo -E make check TESTS="00modules-test compat-test-opal"
# Samsung SSD 980 500GB (on tiber machine)
test-commit-rawhide-samsung980:
rules:
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
extends:
- .opal-template-fedora
tags:
- tiber
resource_group: samsung980-on-tiber
interruptible: false
variables:
PCI_PASSTHROUGH_VENDOR_ID: "144d"
PCI_PASSTHROUGH_DEVICE_ID: "a809"
test-mergerq-rawhide-samsung980:
rules:
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
extends:
- .opal-template-fedora
tags:
- tiber
resource_group: samsung980-on-tiber
interruptible: false
variables:
PCI_PASSTHROUGH_VENDOR_ID: "144d"
PCI_PASSTHROUGH_DEVICE_ID: "a809"
# WD PC SN740 SDDQNQD-512G-1014 (on tiber machine)
# Disabled on 2025-03-20, seems broken
#test-commit-rawhide-sn740:
# rules:
# - if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
# when: never
# - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
# extends:
# - .opal-template-fedora
# tags:
# - tiber
# resource_group: sn740-on-tiber
# interruptible: false
# variables:
# PCI_PASSTHROUGH_VENDOR_ID: "15b7"
# PCI_PASSTHROUGH_DEVICE_ID: "5017"
#
#test-mergerq-rawhide-sn740:
# rules:
# - if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
# when: never
# - if: $CI_PIPELINE_SOURCE == "merge_request_event"
# extends:
# - .opal-template-fedora
# tags:
# - tiber
# resource_group: sn740-on-tiber
# interruptible: false
# variables:
# PCI_PASSTHROUGH_VENDOR_ID: "15b7"
# PCI_PASSTHROUGH_DEVICE_ID: "5017"
# Samsung SSD 980 PRO 1TB (on trantor machine)
test-commit-rawhide-samsung980pro:
rules:
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
extends:
- .opal-template-fedora
tags:
- trantor
resource_group: samsung980pro-on-trantor
interruptible: false
variables:
PCI_PASSTHROUGH_VENDOR_ID: "144d"
PCI_PASSTHROUGH_DEVICE_ID: "a80a"
test-mergerq-rawhide-samsung980pro:
rules:
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
extends:
- .opal-template-fedora
tags:
- trantor
resource_group: samsung980pro-on-trantor
interruptible: false
variables:
PCI_PASSTHROUGH_VENDOR_ID: "144d"
PCI_PASSTHROUGH_DEVICE_ID: "a80a"
# # UMIS RPETJ256MGE2MDQ (on tiber machine)
# test-commit-rawhide-umis:
# rules:
# - if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
# when: never
# - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
# extends:
# - .opal-template-fedora
# tags:
# - tiber
# resource_group: umis-on-tiber
# stage: test
# interruptible: false
# variables:
# PCI_PASSTHROUGH_VENDOR_ID: "1cc4"
# PCI_PASSTHROUGH_DEVICE_ID: "6302"
#
# test-mergerq-rawhide-umis:
# rules:
# - if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
# when: never
# - if: $CI_PIPELINE_SOURCE == "merge_request_event"
# extends:
# - .opal-template-fedora
# tags:
# - tiber
# resource_group: umis-on-tiber
# stage: test
# interruptible: false
# variables:
# PCI_PASSTHROUGH_VENDOR_ID: "1cc4"
# PCI_PASSTHROUGH_DEVICE_ID: "6302"

61
.gitlab/ci/fedora.yml Normal file
View File

@@ -0,0 +1,61 @@
.dnf-openssl-backend:
variables:
DISTRO: cryptsetup-fedora-rawhide
PKGS: >-
autoconf automake device-mapper-devel gcc gettext-devel json-c-devel
libargon2-devel libblkid-devel libpwquality-devel libselinux-devel
libssh-devel libtool libuuid-devel make popt-devel
libsepol-devel.x86_64 netcat openssh-clients passwd pkgconfig sharutils
sshpass tar uuid-devel vim-common device-mapper expect gettext git jq
keyutils openssl-devel openssl asciidoctor swtpm meson ninja-build
python3-jinja2 gperf libcap-devel tpm2-tss-devel libmount-devel swtpm-tools
extends:
- .fail_if_coredump_generated
before_script:
- sudo dnf clean all
- (r=3;while ! sudo dnf -y -q install $PKGS ; do ((--r))||exit;sleep 5;echo "Retrying";done)
- sudo -E git clean -xdf
- ./autogen.sh
- ./configure --enable-fips --enable-pwquality --enable-libargon2 --with-crypto_backend=openssl --enable-asciidoc
test-main-commit-job-rawhide:
extends:
- .dnf-openssl-backend
tags:
- libvirt
- cryptsetup-fedora-rawhide
stage: test
interruptible: true
allow_failure: true
variables:
RUN_SSH_PLUGIN_TEST: "1"
RUN_KEYRING_TRUSTED_TEST: "1"
rules:
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
script:
- make -j
- make -j -C tests check-programs
- sudo -E make check
test-mergerq-job-rawhide:
extends:
- .dnf-openssl-backend
tags:
- libvirt
- cryptsetup-fedora-rawhide
stage: test
interruptible: true
allow_failure: true
variables:
RUN_SSH_PLUGIN_TEST: "1"
RUN_KEYRING_TRUSTED_TEST: "1"
rules:
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- make -j
- make -j -C tests check-programs
- sudo -E make check

57
.gitlab/ci/gcc-Wall Executable file
View File

@@ -0,0 +1,57 @@
#!/bin/bash
# gcc -Wall plus other important warnings not included in -Wall
for arg in "$@"
do
case $arg in
-O*) Wuninitialized=-Wuninitialized;; # only makes sense with `-O'
esac
done
GCC="gcc${COMPILER_VERSION:+-$COMPILER_VERSION}"
#PEDANTIC="-std=gnu99"
#PEDANTIC="-pedantic -std=gnu99"
#PEDANTIC="-pedantic -std=gnu99 -Wno-variadic-macros"
#CONVERSION="-Wconversion"
# -Wpacked \
# This does more than expected for gcc (mixed code with declarations)
# -Wdeclaration-after-statement \
EXTRA="-Wextra \
-Wsign-compare \
-Werror-implicit-function-declaration \
-Wpointer-arith \
-Wwrite-strings \
-Wswitch \
-Wmissing-format-attribute \
-Wstrict-aliasing=3 \
-Winit-self \
-Wunsafe-loop-optimizations \
-Wold-style-definition \
-Wno-missing-field-initializers \
-Wunused-parameter \
-Wno-long-long \
-Wmaybe-uninitialized \
-Wvla \
-Wformat-overflow \
-Wformat-truncation"
exec $GCC $PEDANTIC $CONVERSION \
-Wall $Wuninitialized \
-Wno-switch \
-Wdisabled-optimization \
-Wwrite-strings \
-Wpointer-arith \
-Wbad-function-cast \
-Wmissing-prototypes \
-Wmissing-declarations \
-Wstrict-prototypes \
-Wnested-externs \
-Wcomment \
-Winline \
-Wcast-align=strict \
-Wcast-qual \
-Wredundant-decls $EXTRA \
"$@"

View File

@@ -0,0 +1,32 @@
.gitlab-shared-docker:
image: ubuntu:noble
tags:
- gitlab-org-docker
stage: test
interruptible: true
rules:
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
before_script:
- .gitlab/ci/cibuild-setup-ubuntu.sh
- export CC="${COMPILER}${COMPILER_VERSION:+-$COMPILER_VERSION}"
- export CXX="${COMPILER}++${COMPILER_VERSION:+-$COMPILER_VERSION}"
.gitlab-shared-gcc:
extends:
- .gitlab-shared-docker
variables:
COMPILER: "gcc"
COMPILER_VERSION: "14"
CC: "gcc-14"
RUN_SSH_PLUGIN_TEST: "1"
.gitlab-shared-clang:
extends:
- .gitlab-shared-docker
variables:
COMPILER: "clang"
COMPILER_VERSION: "19"
CC: "clang-19"
RUN_SSH_PLUGIN_TEST: "1"

157
.gitlab/ci/rhel.yml Normal file
View File

@@ -0,0 +1,157 @@
.rhel-openssl-backend:
extends:
- .fail_if_coredump_generated
before_script:
- >
sudo yum -y -q install
autoconf automake device-mapper-devel gcc gettext-devel json-c-devel
libblkid-devel libpwquality-devel libselinux-devel libssh-devel libtool
libuuid-devel make popt-devel libsepol-devel nc openssh-clients passwd
pkgconfig sharutils sshpass tar uuid-devel vim-common device-mapper
expect gettext git jq keyutils openssl-devel openssl gem
- sudo gem install asciidoctor
- sudo -E git clean -xdf
- ./autogen.sh
- ./configure --enable-fips --enable-pwquality --with-crypto_backend=openssl --enable-asciidoc
# non-FIPS jobs
test-main-commit-rhel8:
extends:
- .rhel-openssl-backend
tags:
- libvirt
- cryptsetup-rhel-8
stage: test
interruptible: true
variables:
DISTRO: cryptsetup-rhel-8
RUN_SSH_PLUGIN_TEST: "1"
rules:
- if: $RUN_SYSTEMD_PLUGIN_TEST != null
when: never
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
script:
- make -j
- make -j -C tests check-programs
- sudo -E make check
test-main-commit-rhel9:
extends:
- .rhel-openssl-backend
tags:
- libvirt
- cryptsetup-rhel-9
stage: test
interruptible: true
variables:
DISTRO: cryptsetup-rhel-9
RUN_SSH_PLUGIN_TEST: "1"
rules:
- if: $RUN_SYSTEMD_PLUGIN_TEST != null
when: never
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
script:
- make -j
- make -j -C tests check-programs
- sudo -E make check
test-main-commit-rhel10:
extends:
- .rhel-openssl-backend
tags:
- libvirt
- cryptsetup-rhel-10
stage: test
interruptible: true
allow_failure: true
variables:
DISTRO: cryptsetup-rhel-10
RUN_SSH_PLUGIN_TEST: "1"
rules:
- if: $RUN_SYSTEMD_PLUGIN_TEST != null
when: never
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
script:
- make -j
- make -j -C tests check-programs
- sudo -E make check
# FIPS jobs
test-main-commit-rhel8-fips:
extends:
- .rhel-openssl-backend
tags:
- libvirt
- cryptsetup-rhel-8-fips
stage: test
interruptible: true
variables:
DISTRO: cryptsetup-rhel-8-fips
RUN_SSH_PLUGIN_TEST: "1"
rules:
- if: $RUN_SYSTEMD_PLUGIN_TEST != null
when: never
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
script:
- grep -q fips=1 /proc/cmdline || exit 1
- make -j
- make -j -C tests check-programs
- sudo -E make check
test-main-commit-rhel9-fips:
extends:
- .rhel-openssl-backend
tags:
- libvirt
- cryptsetup-rhel-9-fips
stage: test
interruptible: true
allow_failure: true
variables:
DISTRO: cryptsetup-rhel-9-fips
RUN_SSH_PLUGIN_TEST: "1"
rules:
- if: $RUN_SYSTEMD_PLUGIN_TEST != null
when: never
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
script:
- grep -q fips=1 /proc/cmdline || exit 1
- make -j
- make -j -C tests check-programs
- sudo -E make check
test-main-commit-rhel10-fips:
extends:
- .rhel-openssl-backend
tags:
- libvirt
- cryptsetup-rhel-10-fips
stage: test
interruptible: true
allow_failure: true
variables:
DISTRO: cryptsetup-rhel-10-fips
RUN_SSH_PLUGIN_TEST: "1"
rules:
- if: $RUN_SYSTEMD_PLUGIN_TEST != null
when: never
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
script:
- grep -q fips=1 /proc/cmdline || exit 1
- make -j
- make -j -C tests check-programs
- sudo -E make check

22
.gitlab/ci/run_csmock Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
CSMOCK="sudo /usr/bin/csmock"
CSMOCK_TOOLS="gcc,clang,cppcheck,shellcheck"
CSMOCK_TXZ="cryptsetup-csmock-results.tar.xz"
CSMOCK_ERR="cryptsetup-csmock-results/scan-results.err"
$CSMOCK cryptsetup-*.src.rpm \
--keep-going --force \
--cswrap-timeout 300 \
--skip-patches \
--tools $CSMOCK_TOOLS \
--output $CSMOCK_TXZ \
--gcc-analyze \
--cppcheck-add-flag=--check-level=exhaustive \
|| { echo "csmock command failed"; exit 2; }
tar xJf $CSMOCK_TXZ $CSMOCK_ERR --strip-components 1 \
&& test -s $CSMOCK_ERR \
&& { echo "csmock discovered important errors"; echo 3; }
exit 0

31
.gitlab/ci/spellcheck Executable file
View File

@@ -0,0 +1,31 @@
#!/bin/bash
set -e
DIR="_spellcheck"
[ ! -d $DIR ] && mkdir $DIR
echo "[SPELLINTIAN]"
git ls-tree -rz --name-only HEAD | grep -Evz -e '\.(pdf|xz)$' -e ^po/ | \
xargs -r0 spellintian | \
grep -v "(duplicate word)" | \
grep -v "docs/" | tee $DIR/spell1.txt
echo "[CODESPELL]"
git ls-tree -rz --name-only HEAD | grep -Evz -e '\.(pdf|xz)$' -e ^po/ | \
xargs -r0 codespell | \
grep -v "EXPCT" | \
grep -v "params, prams" | \
grep -v "pad, padded" | \
grep -v "CIPHER, CHIP" | \
grep -v "gost" | \
grep -v "userA" | \
grep -v "re-use" | \
grep -v "fo ==" | \
grep -v "docs/" | tee $DIR/spell2.txt
[ -s $DIR/spell1.txt ] && exit 1
[ -s $DIR/spell2.txt ] && exit 2
exit 0

106
.gitlab/ci/ubuntu.yml Normal file
View File

@@ -0,0 +1,106 @@
.ubuntu-prep:
extends:
- .fail_if_coredump_generated
before_script:
- sudo apt-get -y update
- >
sudo apt-get -y install -y -qq git gcc make autoconf automake autopoint
pkgconf libtool libtool-bin gettext libssl-dev libdevmapper-dev
libpopt-dev uuid-dev libsepol-dev libjson-c-dev libssh-dev libblkid-dev
tar libargon2-dev libpwquality-dev sharutils dmsetup jq xxd expect
keyutils netcat-openbsd passwd openssh-client sshpass asciidoctor
swtpm meson ninja-build python3-jinja2 gperf libcap-dev libtss2-dev
libmount-dev swtpm-tools tpm2-tools
# scsi_debug, gost crypto
- sudo apt-get -y install dkms linux-headers-$(uname -r) linux-modules-extra-$(uname -r) gost-crypto-dkms
- sudo apt-get -y build-dep cryptsetup
- sudo -E git clean -xdf
- ./autogen.sh
- ./configure --enable-libargon2 --enable-asciidoc
test-mergerq-job-ubuntu:
extends:
- .ubuntu-prep
tags:
- libvirt
- cryptsetup-ubuntu-2404
stage: test
interruptible: true
variables:
DISTRO: cryptsetup-ubuntu-2404
RUN_SSH_PLUGIN_TEST: "1"
RUN_KEYRING_TRUSTED_TEST: "1"
rules:
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- make -j
- make -j -C tests check-programs
- sudo -E make check
test-main-commit-job-ubuntu:
extends:
- .ubuntu-prep
tags:
- libvirt
- cryptsetup-ubuntu-2404
stage: test
interruptible: true
variables:
DISTRO: cryptsetup-ubuntu-2404
RUN_SSH_PLUGIN_TEST: "1"
RUN_KEYRING_TRUSTED_TEST: "1"
rules:
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
script:
- make -j
- make -j -C tests check-programs
- sudo -E make check
# meson tests
test-mergerq-job-ubuntu-meson:
extends:
- .ubuntu-prep
tags:
- libvirt
- cryptsetup-ubuntu-2404
stage: test
interruptible: true
variables:
DISTRO: cryptsetup-ubuntu-2404
RUN_SSH_PLUGIN_TEST: "1"
RUN_KEYRING_TRUSTED_TEST: "1"
rules:
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- sudo apt-get -y install -y -qq meson ninja-build
- meson setup build
- ninja -C build
- cd build && sudo -E meson test --verbose --print-errorlogs
test-main-commit-job-ubuntu-meson:
extends:
- .ubuntu-prep
tags:
- libvirt
- cryptsetup-ubuntu-2404
stage: test
interruptible: true
variables:
DISTRO: cryptsetup-ubuntu-2404
RUN_SSH_PLUGIN_TEST: "1"
RUN_KEYRING_TRUSTED_TEST: "1"
rules:
- if: $CI_PROJECT_PATH != "cryptsetup/cryptsetup"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /v2\..\.x$/
script:
- sudo apt-get -y install -y -qq meson ninja-build
- meson setup build
- ninja -C build
- cd build && sudo -E meson test --verbose --print-errorlogs

View File

@@ -9,7 +9,10 @@
### Debug log
<!-- Paste a debug log of the failing command (add --debug option) between the markers below (to keep raw debug format).-->
<!-- We need a lot of information from the debug log; without it, we cannot process your report. -->
<!-- Debug log does not contain any private information. Do not paste private data; we'll ask you for more information if needed. -->
```
Output with --debug option:
```
<!-- NOTE: WITHOUT DEBUG LOG, THE BUG REPORT WILL BE CLOSED. ALSO, PLEASE DO NOT TRY TO REMOVE PARTS OF THE DEBUG LOG! -->

158
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,158 @@
Contributing to cryptsetup
==========================
For basic information about the cryptsetup project, please read [README](README.md).
The Cryptsetup project uses free, open-source licenses; details are described in [licensing](README.licensing).
For contribution code or documentation to the cryptsetup project, you must have the necessary rights to the content, and your contribution must be provided under the required license.
We welcome contributions from everyone.
Cryptsetup is an independent project with much volunteer effort, and our resources are limited.
Following the guidelines specified in this file makes it easier for us to process your issue.
Project maintainers can remove or reject abusive or otherwise unacceptable comments or code.
Git repository
--------------
The primary repository is located at [gitlab.com/cryptsetup/cryptsetup](https://gitlab.com/cryptsetup/cryptsetup).
The development branch is ``main``; minor stable releases can use their branches with cherry-picked or backported patches.
There are backup mirrors located at [github.com/mbroz/cryptsetup](https://github.com/mbroz/cryptsetup) and [git.kernel.org/pub/scm/utils/cryptsetup/cryptsetup.git](https://git.kernel.org/pub/scm/utils/cryptsetup/cryptsetup.git).
How to make a bug report
------------------------
To report an issue or feature request, please use GitLab [cryptsetup issue tracker](https://gitlab.com/cryptsetup/cryptsetup/-/issues).
Before reporting an issue, please try to search documentation and existing issues. Always try to reproduce the problem on the latest supported release.
Please *always* collect and attach ``--debug`` log and other information as instructed in the issue template.
Even if you think the problem is obvious, we need logged information about the environment (like versions of kernel modules, etc.).
Please do not report distribution-specific issues if they are not present in the latest upstream release.
For such reports, please use downstream distribution-specific trackers.
If the issue is related to upstream, downstream maintainers will redirect you here, or upstream maintainers will join the discussion.
If you think that you found some security bug, please follow the instructions in the [SECURITY](SECURITY.md) file.
How to contribute changes to cryptsetup
---------------------------------------
The following notes are a very short introduction to cryptsetup internal processes and an overview of generic rules that should be followed for all changes.
Changes from developers and external contributors should go through the GitLab repository [merge reguests](https://gitlab.com/cryptsetup/cryptsetup/-/merge_requests).
Alternatively (for trivial changes), you can send a patch to [cryptsetup mailing list](mailto:cryptsetup@lists.linux.dev).
Please do not write personal emails with questions or patches to maintainers and developers.
### Project structure
Cryptsetup projects include a libcryptsetup library, tools, token plugins, documentation, and a test suite.
Cryptsetup library (libcryptsetup) exports [versioned symbols](lib/libcryptsetup.sym).
Tools (cryptsetup, veritysetup, integritysetup) use libcryptsetup shared library.
Some isolated parts in the lib directory can be reused for tools (the source is recompiled).
The basic directory structure in the repository is
```
├── docs - Documentation and release notes.
├── lib - libcryptsetup implementation
│   ├── bitlk - Bitlocker format
│   ├── crypto_backend - Cryptography backend
│   ├── fvault2 - FileVault2 format
│   ├── integrity - Linux dm-integrity interface
│   ├── loopaes - Linux LoopAES format
│   ├── luks1 - LUKS1 format
│   ├── luks2 - LUKS2 format including OPAL2 SED
│   ├── tcrypt - TrueCrypt / VeraCrypt format
│   └── verity - Linux dm-verity interface
├── man - Manual pages (in AsciiDoc format)
├── misc - Miscellaneous additions
├── po - Translation files
├── scripts - Scripts for system configuration
├── src - Tools implementation
├── tests - Testsuite (test units, regression tests, fuzzing)
└── tokens - Token plugins
```
### Coordination with other projects
The cryptsetup tools and library use low-level functions that depend on many other subsystems.
Currently, the project is supported only for Linux (it will not work on Android or other systems).
Cryptsetup project requires some parts of the Linux kernel, notably the *Device Mapper* (dm-crypt, dm-integrity, dm-verity, dm-zero modules) and kernel *userspace cryptographic interface*.
Missing kernel interface can significantly limit (or even disallow) cryptsetup functionality.
Integration in operating systems also depends on several other projects, most notably *systemd* (that implements its own tooling using libcryptsetup) and *util-Linux* (*blkid* parsing of supported format metadata). Some changes must be synchronized in all needed places (kernel, blkid, libcryptsetup).
Several other projects implement their own token metadata (either through binary token plugins or through generic libcryptsetup JSON token access functions).
### Used cryptography algorithms
Cryptsetup avoids implementing cryptographic primitives but uses cryptographic libraries.
Exceptions were PBKDF internal implementations - PBKDF2 and Argon2 until these were integrated into major cryptographic libraries.
Cryptsetup can be compiled with several cryptographic libraries backend (OpenSSL, libgcrypt, Nettle, NSS, and Linux kernel userspace API).
OpenSSL is the default and strongly recommended configuration.
If the cryptographic library does not implement some cryptographic primitive (for example, if running in a FIPS-140 environment or just
because it does not include it at all), functionality could be limited.
### Configuration and versioning
Cryptsetup can be configured using *Autoconf* or *Meson*. Autoconf support is being deprecated in the long term.
Currently, all new configuration options must be implemented in both systems.
Cryptsetup intentionally does not use a system configuration file (located in /etc).
All functionality must be determined dynamically.
All related /etc configuration files (crypttab, fstab and others) are maintained by systemd (in some legacy distributions by cryptsetup downstream).
Cryptsetup uses [semantic versioning](https://semver.org/).
Major and minor releases are always based on the main git branch; the minor stable (patch) versions can have some specific branch with backported or cherry-picked patches (from the main branch).
Usually, minor releases happen twice per year and stable patch updates according to reported bugs (in 1-3 month intervals).
### Compilation and debugging
The library and tools are written in C language; we require C99 and support gcc and Clang compilers.
Manual pages are generated from AsciiDoc sources and libcryptsetup API documentation by Doxygen (from libcryptsetup.h comments).
Testsuite is a combination of local C utilities, fuzzing implementation in C++, bash scripts, and uses many other system utilities.
All tools contain compiled-in debug messages that are available through --debug options.
With Autoconf and libtool, you can run the cryptsetup tool in the debugger without installation using this one-line script:
```
libtool --mode=execute gdb --args ./cryptsetup --debug $@
```
This will ensure that a properly compiled libcryptsetup file is used.
### Coding style
Cryptsetup uses [Linux kernel coding style](https://cdn.kernel.org/doc/html/latest/process/coding-style.html) for libcryptsetup and tools (where applicable) with some additional notes:
- Use tabulators for indentation; the line should not exceed 100 characters with an 8-character tabulator. Otherwise, use a tab of any length. :-).
- The minimal C standard required is C99.
- The ``goto`` use is allowed only for error path (``goto out`` for common code path, ``goto err`` for specific error code path).
- Split patches per change; do not submit huge patches combining several changes.
- Use an elaborative description in the patch header.
- No need to use sign-off-by lines.
- Use name prefixes (``crypt_``, ``LUKS2_`` and similar).
- Avoid extensive preprocessor use (specifically conditional ``#if`` or ``#ifdef`` sections).
- To check detected configuration options stored in config.h, always use ``#if SOMETHING`` (do NOT use ``#ifdef``).
- Use output only through ``log_err, log_std, log_verbose, log_dbg`` macros.
The ``log_dbg`` is always in English; the others should be wrapped in the ``_()`` macro for translation.
- Use ``assert()`` but only for simple invariants and variables (avoid calling functions).
Do not use assert for user-defined input (this should be a normal error path).
- The code style is quite relaxed in testing scripts (code there is not intended for production use).
### General rules and testing
- Cryptsetup should work on all architectures supported by the Linux kernel.
Only very few functionalities require specific hardware (notably Opal SED support).
If you want to introduce some specific hardware support, please discuss it with the maintainers first.
- All code changes should go through merge requests and reviews.
Code can be merged after review approval (done by someone with the commit right to the development repository), but reviews from external people are very welcome, too.
- All new functionality must come with at least rudimentary coverage in the test suite.
Always run the test suite before opening the merge request (``make check`` with root privilege).
- We have continuous integration (CI) that runs many tests automatically, but the output is not directly visible for external merge request authors (for security reasons).
All CI scripts are available in .gitlab and .github folders in the project repository.
Maintainers will provide you log files if anything fails. Your code must produce no warnings before it is merged.
- We run compilation with many extended [gcc](.gitlab/ci/gcc-Wall) and [Clang](.gitlab/ci/clang-Wall) warnings and include some analyzers, notably
- [Coverity](https://scan.coverity.com), GitHub CodeQL, Clang scan-build, and gcc static analyzer, and
- fuzzing integrated in [OSS-fuzz project](https://github.com/google/oss-fuzz/tree/master/projects/cryptsetup).
- Testsuite can also partially run under Valgrind dynamic analyzer with ``make valgrind-check``.

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,18 @@
EXTRA_DIST = README.md COPYING.LGPL FAQ docs misc autogen.sh
SUBDIRS = po tests
EXTRA_DIST = README.md SECURITY.md README.licensing CONTRIBUTING.md FAQ.md docs misc autogen.sh
EXTRA_DIST += meson_options.txt \
meson.build \
lib/crypto_backend/argon2/meson.build \
lib/crypto_backend/meson.build \
lib/meson.build \
man/meson.build \
po/meson.build \
scripts/meson.build \
src/meson.build \
tests/meson.build \
tokens/meson.build \
tokens/ssh/meson.build
SUBDIRS = po tests tests/fuzz
CLEANFILES =
DISTCLEAN_TARGETS =
@@ -14,9 +27,15 @@ AM_CPPFLAGS = \
-DVERSION=\""$(VERSION)"\" \
-DEXTERNAL_LUKS2_TOKENS_PATH=\"${EXTERNAL_LUKS2_TOKENS_PATH}\"
AM_CFLAGS = -Wall
AM_CXXFLAGS = -Wall
AM_LDFLAGS =
LDADD = $(LTLIBINTL) -lm
if ENABLE_FUZZ_TARGETS
AM_CFLAGS += -fsanitize=fuzzer-no-link
AM_CXXFLAGS += -fsanitize=fuzzer-no-link
endif
LDADD = $(LTLIBINTL)
tmpfilesddir = @DEFAULT_TMPFILESDIR@
@@ -27,6 +46,7 @@ sbin_PROGRAMS =
man8_MANS =
tmpfilesd_DATA =
pkgconfig_DATA =
dist_noinst_DATA =
include man/Makemodule.am
@@ -46,7 +66,7 @@ ACLOCAL_AMFLAGS = -I m4
DISTCHECK_CONFIGURE_FLAGS = \
--with-tmpfilesdir=$$dc_install_base/usr/lib/tmpfiles.d \
--enable-internal-argon2 --enable-internal-sse-argon2 \
--enable-external-tokens --enable-ssh-token
--enable-external-tokens --enable-ssh-token --enable-asciidoc
distclean-local:
-find . -name \*~ -o -name \*.orig -o -name \*.rej | xargs rm -f
@@ -60,3 +80,11 @@ install-data-local:
uninstall-local:
rmdir $(DESTDIR)/${EXTERNAL_LUKS2_TOKENS_PATH} 2>/dev/null || :
check-programs: libcryptsetup.la
$(MAKE) -C tests $@
if ENABLE_FUZZ_TARGETS
fuzz-targets: libcryptsetup.la libcrypto_backend.la
$(MAKE) -C tests/fuzz $@
endif

20
README.licensing Normal file
View File

@@ -0,0 +1,20 @@
The cryptsetup project does not use the same license for all of the code and documentation.
There is code and documentation under:
* GPL-2.0-or-later - GNU General Public License version 2, or any later version
* LGPL-2.1-or-later WITH cryptsetup-OpenSSL-exception
* LGPL-2.1-or-later - GNU Lesser General Public License 2.1 or any later version,
(with cryptsetup-OpenSSL-exception where applicable)
* Apache-2.0 - Apache License 2.0
* CC-BY-SA-4.0 - Creative Commons Attribution Share Alike 4.0 International
* Public Domain
Please, check the source code for more details.
The ./COPYING file (GPL-2.0-or-later) is the default license for code without
an explicitly defined license.

170
README.md
View File

@@ -2,92 +2,142 @@
What the ...?
=============
**Cryptsetup** is a utility used to conveniently set up disk encryption based
on the [DMCrypt](https://gitlab.com/cryptsetup/cryptsetup/wikis/DMCrypt) kernel module.
**Cryptsetup** is an open-source utility used to conveniently set up disk encryption based
on the [dm-crypt](https://gitlab.com/cryptsetup/cryptsetup/wikis/DMCrypt) kernel module.
These include **plain** **dm-crypt** volumes, **LUKS** volumes, **loop-AES**,
**TrueCrypt** (including **VeraCrypt** extension) and **BitLocker** formats.
These formats are supported:
* **plain** volumes,
* **LUKS** volumes,
* **loop-AES**,
* **TrueCrypt** (including **VeraCrypt** extension),
* **BitLocker**, and
* **FileVault2**.
The project also includes a **veritysetup** utility used to conveniently setup
[DMVerity](https://gitlab.com/cryptsetup/cryptsetup/wikis/DMVerity) block integrity checking kernel module
and **integritysetup** to setup
[DMIntegrity](https://gitlab.com/cryptsetup/cryptsetup/wikis/DMIntegrity) block integrity kernel module.
[dm-verity](https://gitlab.com/cryptsetup/cryptsetup/wikis/DMVerity)
block integrity checking kernel module and **integritysetup** to setup
[dm-integrity](https://gitlab.com/cryptsetup/cryptsetup/wikis/DMIntegrity)
block integrity kernel module.
LUKS Design
-----------
**LUKS** is the standard for Linux hard disk encryption. By providing a standard on-disk-format, it does not
only facilitate compatibility among distributions, but also provides secure management of multiple user passwords.
LUKS stores all necessary setup information in the partition header, enabling to transport or migrate data seamlessly.
**LUKS** is the standard for Linux disk encryption. By providing a standardized on-disk format,
it not only facilitate compatibility among distributions, but also enables secure management
of multiple user passwords. LUKS stores all necessary setup information in the partition header,
which enables users to transport or migrate data seamlessly.
Last version of the LUKS2 format specification is
[available here](https://gitlab.com/cryptsetup/LUKS2-docs).
Last version of the LUKS1 format specification is
[available here](https://www.kernel.org/pub/linux/utils/cryptsetup/LUKS_docs/on-disk-format.pdf).
Why LUKS?
---------
* compatibility via standardization,
* secure against low entropy attacks,
* support for multiple keys,
* effective passphrase revocation,
* free.
[Project home page](https://gitlab.com/cryptsetup/cryptsetup/).
-----------------
[Frequently asked questions (FAQ)](https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions)
--------------------------------
### Specification and documentation
* The latest version of the
[LUKS2 format specification](https://gitlab.com/cryptsetup/LUKS2-docs).
* The latest version of the
[LUKS1 format specification](https://cdn.kernel.org/pub/linux/utils/cryptsetup/LUKS_docs/on-disk-format.pdf).
* [Project home page](https://gitlab.com/cryptsetup/cryptsetup/).
* [Frequently asked questions (FAQ)](https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions)
Download
--------
All release tarballs and release notes are hosted on [kernel.org](https://www.kernel.org/pub/linux/utils/cryptsetup/).
Release notes and tarballs are available at
[kernel.org](https://cdn.kernel.org/pub/linux/utils/cryptsetup/).
**The latest stable cryptsetup version is 2.4.0**
* [cryptsetup-2.4.0.tar.xz](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.4/cryptsetup-2.4.0.tar.xz)
* Signature [cryptsetup-2.4.0.tar.sign](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.4/cryptsetup-2.4.0.tar.sign)
**The latest stable cryptsetup release candidate version is 2.8.0-rc1**
* [cryptsetup-2.8.0-rc1.tar.xz](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.8/cryptsetup-2.8.0-rc1.tar.xz)
* Signature [cryptsetup-2.8.0-rc1.tar.sign](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.8/cryptsetup-2.8.0-rc1.tar.sign)
_(You need to decompress file first to check signature.)_
* [Cryptsetup 2.4.0 Release Notes](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.4/v2.4.0-ReleaseNotes).
* [Cryptsetup 2.8.0-rc1 Release Notes](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.8/v2.8.0-rc1-ReleaseNotes).
Previous versions
* [Version 2.3.6](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.3/cryptsetup-2.3.6.tar.xz) -
[Signature](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.3/cryptsetup-2.3.6.tar.sign) -
[Release Notes](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.3/v2.3.6-ReleaseNotes).
* [Version 1.7.5](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/cryptsetup-1.7.5.tar.xz) -
[Signature](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/cryptsetup-1.7.5.tar.sign) -
[Release Notes](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/v1.7.5-ReleaseNotes).
**The latest stable cryptsetup release version is 2.7.5**
* [cryptsetup-2.7.5.tar.xz](https://cdn.kernel.org/pub/linux/utils/cryptsetup/v2.7/cryptsetup-2.7.5.tar.xz)
* Signature [cryptsetup-2.7.5.tar.sign](https://cdn.kernel.org/pub/linux/utils/cryptsetup/v2.7/cryptsetup-2.7.5.tar.sign)
_(You need to decompress file first to check signature.)_
* [Cryptsetup 2.7.5 Release Notes](https://cdn.kernel.org/pub/linux/utils/cryptsetup/v2.7/v2.7.5-ReleaseNotes).
Source and API docs
-------------------
For development version code, please refer to [source](https://gitlab.com/cryptsetup/cryptsetup/tree/master) page,
mirror on [kernel.org](https://git.kernel.org/cgit/utils/cryptsetup/cryptsetup.git/) or [GitHub](https://github.com/mbroz/cryptsetup).
[Previous versions](https://cdn.kernel.org/pub/linux/utils/cryptsetup)
For libcryptsetup documentation see [libcryptsetup API](https://mbroz.fedorapeople.org/libcryptsetup_API/) page.
Source and API documentation
----------------------------
For development version code, please refer to the
[source](https://gitlab.com/cryptsetup/cryptsetup/tree/master) page, with mirrors
at [kernel.org](https://git.kernel.org/cgit/utils/cryptsetup/cryptsetup.git/) and
[GitHub](https://github.com/mbroz/cryptsetup).
The libcryptsetup API/ABI changes are tracked in [compatibility report](https://abi-laboratory.pro/tracker/timeline/cryptsetup/).
For libcryptsetup documentation see
[libcryptsetup API](https://mbroz.fedorapeople.org/libcryptsetup_API/) page.
NLS PO files are maintained by [TranslationProject](https://translationproject.org/domain/cryptsetup.html).
NLS PO files are maintained by
[TranslationProject](https://translationproject.org/domain/cryptsetup.html).
Required packages
-----------------
All distributions provide cryptsetup as distro package. If you need to compile cryptsetup youfself, some packages are required for compilation. Please always prefer distro specific build tools to manually configuring cryptsetup.
Fo available compile options, check ``configure --help`` for more info. If you are using a git snapshot, you need to generate configure script with ``autogen.sh`` script.
All major Linux distributions provide cryptsetup as a bundled package. If you need
to compile cryptsetup yourself, various additional packages are required.
Any distribution-specific build tools are preferred when manually configuring cryptsetup.
Here is the list of packages needed for the compilation of project for particular distributions:
* For Fedora: `git gcc make autoconf automake gettext-devel pkgconfig openssl-devel popt-devel device-mapper-devel libuuid-devel json-c-devel libblkid-devel findutils libtool libssh-devel tar`. Optionally `libargon2-devel libpwquality-devel`. To run internal testsuite you also need `sharutils device-mapper jq vim-common expect keyutils netcat shadow-utils openssh-clients openssh sshpass`.
Below are the packages needed to build for certain Linux distributions:
* For Debian and Ubuntu: `git gcc make autoconf automake autopoint pkg-config libtool gettext libssl-dev libdevmapper-dev libpopt-dev uuid-dev libsepol1-dev libjson-c-dev libssh-dev libblkid-dev tar`. Optionally `libargon2-0-dev libpwquality-dev`. To run internal testsuite you also need `sharutils dmsetup jq xxd expect keyutils netcat passwd openssh-client sshpass`
**For Fedora**:
```
git gcc make autoconf automake gettext-devel pkgconfig openssl-devel popt-devel device-mapper-devel libuuid-devel json-c-devel libblkid-devel findutils libtool libssh-devel tar
Note that the list could change as distributions evolve.
Optionally: libargon2-devel libpwquality-devel
```
To run the internal testsuite (make check) you also need to install
```
sharutils device-mapper jq vim-common expect keyutils netcat shadow-utils openssh-clients openssh sshpass
```
**For Debian and Ubuntu**:
```
git gcc make autoconf automake autopoint pkg-config libtool gettext libssl-dev libdevmapper-dev libpopt-dev uuid-dev libsepol-dev libjson-c-dev libssh-dev libblkid-dev tar
Optionally: libargon2-0-dev libpwquality-dev
```
To run the internal testsuite (make check) you also need to install
```
sharutils dmsetup jq xxd expect keyutils netcat-openbsd passwd openssh-client sshpass
```
Note that the list may change as Linux distributions evolve.
Compilation
-----------
The cryptsetup project uses **automake** and **autoconf** system to generate all files needed to build.
When building from a git snapshot,, use **./autogen.sh && ./configure && make**
to compile the project. When building from a release **tar.xz** tarball, the configure script
is pre-generated (no need to run **autoconf.sh**).
See **./configure --help** and use the **--disable-[feature]** and **--enable-[feature]** options.
To run the test suite that come with the project, type **make check**.
Note that most tests will need root user privileges and will run dangerous storage failure simulations.
Do **not** run tests with root privilege on production systems! Some tests will need the **scsi_debug**
kernel module to be installed.
For more details, please refer to the
[automake](https://www.gnu.org/software/automake/manual/automake.html) and
[autoconf](https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf.html) documentation.
Help!
-----
Please read the [FAQ](https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions) and search the manuals (man page, man-page) before posting questions in the mailing list. You will be able to ask better questions and better understand the answers. The FAQ is online and in the source code. The man pages are in source and should be available after installation using standard man commands. e.g. man cryptsetup
### Documentation
Please read the following before posting questions to the mailing list so that
you can ask better questions and better understand answers.
For cryptsetup and LUKS related questions, please use the dm-crypt mailing list, [dm-crypt@saout.de](mailto:dm-crypt@saout.de).
* [Frequently asked questions (FAQ)](https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions),
* [LUKS Specifications](#specification-and-documentation), and
* manuals (aka man page, man pages, man-page)
If you want to subscribe just send an empty mail to [dm-crypt-subscribe@saout.de](mailto:dm-crypt-subscribe@saout.de).
The FAQ is available online and in the source code for the project. The specifications are
referenced above in this document. The man pages live within the source tree and should be
available after installation using standard man commands, e.g. **man cryptsetup**.
You can also browse [list archive](https://www.saout.de/pipermail/dm-crypt/) or read and search it through
[web interface on lore.kernel.org](https://lore.kernel.org/dm-crypt/) or alternatively on [marc.info](https://marc.info/?l=dm-crypt).
### Mailing List
For cryptsetup and LUKS related questions, please use the cryptsetup mailing list
[cryptsetup@lists.linux.dev](mailto:cryptsetup@lists.linux.dev),
hosted at [kernel.org subspace](https://subspace.kernel.org/lists.linux.dev.html).
To subscribe send an empty email message to
[cryptsetup+subscribe@lists.linux.dev](mailto:cryptsetup+subscribe@lists.linux.dev).
You can also browse and/or search the mailing [list archive](https://lore.kernel.org/cryptsetup/).
USEnet News (NNTP), Atom feed and git access to the public inbox is available through
[lore.kernel.org](https://lore.kernel.org) service.
The former **dm-crypt** [list archive](https://lore.kernel.org/dm-crypt/) is also available.

10
SECURITY.md Normal file
View File

@@ -0,0 +1,10 @@
# Reporting a Security Bug in cryptsetup project
If you think you have discovered a security issue, please report it through
the project issue tracker [New issue](https://gitlab.com/cryptsetup/cryptsetup/issues)
as a confidential issue (select confidential checkbox).
An alternative is to send PGP encrypted mail to the cryptsetup maintainer.
Current maintainer is [Milan Broz](mailto:gmazyland@gmail.com), use PGP key
with fingerprint 2A29 1824 3FDE 4664 8D06 86F9 D9B0 577B D93E 98FC.

View File

@@ -74,7 +74,7 @@ autopoint --force $AP_OPTS
libtoolize --force --copy
aclocal -I m4 $AL_OPTS
autoheader $AH_OPTS
automake --add-missing --copy --gnu $AM_OPTS
automake --force-missing --add-missing --copy --gnu $AM_OPTS
autoconf $AC_OPTS
echo

View File

@@ -1,9 +1,9 @@
AC_PREREQ([2.67])
AC_INIT([cryptsetup],[2.4.0])
AC_INIT([cryptsetup],[2.8.0-rc1])
dnl library version from <major>.<minor>.<release>[-<suffix>]
LIBCRYPTSETUP_VERSION=$(echo $PACKAGE_VERSION | cut -f1 -d-)
LIBCRYPTSETUP_VERSION_INFO=19:0:7
LIBCRYPTSETUP_VERSION_INFO=23:0:11
AM_SILENT_RULES([yes])
AC_CONFIG_SRCDIR(src/cryptsetup.c)
@@ -28,13 +28,13 @@ AC_USE_SYSTEM_EXTENSIONS
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_CPP
AC_PROG_CXX
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_PROG_MKDIR_P
AC_ENABLE_STATIC(no)
LT_INIT
PKG_PROG_PKG_CONFIG
AM_ICONV
dnl ==========================================================================
dnl define PKG_CHECK_VAR for old pkg-config <= 0.28
@@ -53,13 +53,33 @@ AS_VAR_COPY([$1], [pkg_cv_][$1])
AS_VAR_IF([$1], [""], [$5], [$4])
])
])
dnl ==========================================================================
dnl AsciiDoc manual pages
AC_ARG_ENABLE([asciidoc],
AS_HELP_STRING([--disable-asciidoc], [do not generate man pages from asciidoc]),
[], [enable_asciidoc=yes]
)
AC_PATH_PROG([ASCIIDOCTOR], [asciidoctor])
if test "x$enable_asciidoc" = xyes -a "x$ASCIIDOCTOR" = x; then
AC_MSG_ERROR([Building man pages requires asciidoctor installed.])
fi
AM_CONDITIONAL([ENABLE_ASCIIDOC], [test "x$enable_asciidoc" = xyes])
have_manpages=no
AS_IF([test -f "$srcdir/man/cryptsetup-open.8"], [
AC_MSG_NOTICE([re-use already generated man-pages.])
have_manpages=yes]
)
AM_CONDITIONAL([HAVE_MANPAGES], [test "x$have_manpages" = xyes])
dnl ==========================================================================
AC_C_RESTRICT
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h malloc.h inttypes.h sys/ioctl.h sys/mman.h \
AC_CHECK_HEADERS(fcntl.h malloc.h inttypes.h uchar.h sys/ioctl.h sys/mman.h \
sys/sysmacros.h sys/statvfs.h ctype.h unistd.h locale.h byteswap.h endian.h stdint.h)
AC_CHECK_DECLS([O_CLOEXEC],,[AC_DEFINE([O_CLOEXEC],[0], [Defined to 0 if not provided])],
[[
@@ -108,12 +128,10 @@ if test "x$enable_largefile" = "xno"; then
AC_MSG_ERROR([Building with --disable-largefile is not supported, it can cause data corruption.])
fi
AC_C_CONST
AC_C_BIGENDIAN
AC_TYPE_OFF_T
AC_SYS_LARGEFILE
AC_FUNC_FSEEKO
AC_PROG_GCC_TRADITIONAL
AC_FUNC_STRERROR_R
dnl ==========================================================================
@@ -124,7 +142,14 @@ AC_ARG_ENABLE([external-tokens],
[], [enable_external_tokens=yes])
if test "x$enable_external_tokens" = "xyes"; then
AC_DEFINE(USE_EXTERNAL_TOKENS, 1, [Use external tokens])
dnl we need dynamic library loading here
saved_LIBS=$LIBS
AC_SEARCH_LIBS([dlsym],[dl])
AC_CHECK_FUNCS([dlvsym])
AC_SUBST(DL_LIBS, $LIBS)
LIBS=$saved_LIBS
fi
AM_CONDITIONAL(EXTERNAL_TOKENS, test "x$enable_external_tokens" = "xyes")
AC_ARG_ENABLE([ssh-token],
AS_HELP_STRING([--disable-ssh-token], [disable LUKS2 ssh-token]),
@@ -135,6 +160,14 @@ if test "x$enable_ssh_token" = "xyes" -a "x$enable_external_tokens" = "xno"; the
AC_MSG_ERROR([Requested LUKS2 ssh-token build, but external tokens are disabled.])
fi
dnl LUKS2 online reencryption
AC_ARG_ENABLE([luks2-reencryption],
AS_HELP_STRING([--disable-luks2-reencryption], [disable LUKS2 online reencryption extension]),
[], [enable_luks2_reencryption=yes])
if test "x$enable_luks2_reencryption" = "xyes"; then
AC_DEFINE(USE_LUKS2_REENCRYPTION, 1, [Use LUKS2 online reencryption extension])
fi
dnl ==========================================================================
AM_GNU_GETTEXT([external],[need-ngettext])
@@ -180,6 +213,17 @@ if test "x$enable_pwquality" = "xyes"; then
PWQUALITY_STATIC_LIBS="$PWQUALITY_LIBS -lcrack -lz"
fi
dnl ==========================================================================
dnl fuzzers, it requires own static library compilation later
AC_ARG_ENABLE([fuzz-targets],
AS_HELP_STRING([--enable-fuzz-targets], [enable building fuzz targets]))
AM_CONDITIONAL(ENABLE_FUZZ_TARGETS, test "x$enable_fuzz_targets" = "xyes")
if test "x$enable_fuzz_targets" = "xyes"; then
AX_CHECK_COMPILE_FLAG([-fsanitize=fuzzer-no-link],,
AC_MSG_ERROR([Required compiler options not supported; use clang.]), [-Werror])
fi
dnl ==========================================================================
dnl passwdqc library (cryptsetup CLI only)
AC_ARG_ENABLE([passwdqc],
@@ -221,6 +265,9 @@ AC_DEFUN([CONFIGURE_GCRYPT], [
GCRYPT_REQ_VERSION=1.1.42
fi
use_internal_pbkdf2=0
use_internal_argon2=1
dnl libgcrypt rejects to use pkgconfig, use AM_PATH_LIBGCRYPT from gcrypt-devel here.
dnl Do not require gcrypt-devel if other crypto backend is used.
m4_ifdef([AM_PATH_LIBGCRYPT],[
@@ -244,7 +291,24 @@ AC_DEFUN([CONFIGURE_GCRYPT], [
NO_FIPS([])
fi
m4_ifdef([AM_PATH_LIBGCRYPT],[
AC_ARG_ENABLE([gcrypt-argon2],
dnl Check if we can use gcrypt Argon2 (1.11.0 supports empty password)
AS_HELP_STRING([--disable-gcrypt-argon2], [force disable internal gcrypt Argon2]),
[],
[AM_PATH_LIBGCRYPT([1.11.0], [use_internal_argon2=0], [use_internal_argon2=1])])
AM_PATH_LIBGCRYPT($GCRYPT_REQ_VERSION,,[AC_MSG_ERROR([You need the gcrypt library.])])],
AC_MSG_ERROR([Missing support for gcrypt: install gcrypt and regenerate configure.]))
AC_MSG_CHECKING([if internal cryptsetup Argon2 is compiled-in])
if test $use_internal_argon2 = 0; then
AC_MSG_RESULT([no])
else
AC_MSG_RESULT([yes])
fi
AC_CHECK_DECLS([GCRY_CIPHER_MODE_XTS], [], [], [#include <gcrypt.h>])
AC_CHECK_DECLS([GCRY_KDF_ARGON2], [], [], [#include <gcrypt.h>])
if test "x$enable_static_cryptsetup" = "xyes"; then
saved_LIBS=$LIBS
@@ -264,19 +328,25 @@ AC_DEFUN([CONFIGURE_GCRYPT], [
])
AC_DEFUN([CONFIGURE_OPENSSL], [
PKG_CHECK_MODULES([OPENSSL], [openssl >= 0.9.8],,
PKG_CHECK_MODULES([LIBCRYPTO], [libcrypto >= 0.9.8],,
AC_MSG_ERROR([You need openssl library.]))
CRYPTO_CFLAGS=$OPENSSL_CFLAGS
CRYPTO_LIBS=$OPENSSL_LIBS
CRYPTO_CFLAGS=$LIBCRYPTO_CFLAGS
CRYPTO_LIBS=$LIBCRYPTO_LIBS
use_internal_pbkdf2=0
use_internal_argon2=1
if test "x$enable_static_cryptsetup" = "xyes"; then
saved_PKG_CONFIG=$PKG_CONFIG
PKG_CONFIG="$PKG_CONFIG --static"
PKG_CHECK_MODULES([OPENSSL_STATIC], [openssl])
CRYPTO_STATIC_LIBS=$OPENSSL_STATIC_LIBS
PKG_CHECK_MODULES([LIBCRYPTO_STATIC], [libcrypto])
CRYPTO_STATIC_LIBS=$LIBCRYPTO_STATIC_LIBS
PKG_CONFIG=$saved_PKG_CONFIG
fi
saved_LIBS=$LIBS
AC_CHECK_DECLS([OSSL_get_max_threads], [], [], [#include <openssl/thread.h>])
AC_CHECK_DECLS([OSSL_KDF_PARAM_ARGON2_VERSION], [use_internal_argon2=0], [], [#include <openssl/core_names.h>])
LIBS=$saved_LIBS
])
AC_DEFUN([CONFIGURE_NSS], [
@@ -297,6 +367,7 @@ AC_DEFUN([CONFIGURE_NSS], [
CRYPTO_CFLAGS=$NSS_CFLAGS
CRYPTO_LIBS=$NSS_LIBS
use_internal_pbkdf2=1
use_internal_argon2=1
NO_FIPS([])
])
@@ -307,6 +378,7 @@ AC_DEFUN([CONFIGURE_KERNEL], [
# [AC_MSG_ERROR([You need Linux kernel with userspace crypto interface.])],
# [#include <sys/socket.h>])
use_internal_pbkdf2=1
use_internal_argon2=1
NO_FIPS([])
])
@@ -323,6 +395,24 @@ AC_DEFUN([CONFIGURE_NETTLE], [
CRYPTO_STATIC_LIBS=$CRYPTO_LIBS
use_internal_pbkdf2=0
use_internal_argon2=1
NO_FIPS([])
])
AC_DEFUN([CONFIGURE_MBEDTLS], [
AC_CHECK_HEADERS(mbedtls/version.h,,
[AC_MSG_ERROR([You need mbedTLS cryptographic library.])])
saved_LIBS=$LIBS
AC_CHECK_LIB(mbedcrypto, mbedtls_md_init,,
[AC_MSG_ERROR([You need mbedTLS cryptographic library.])])
AC_CHECK_FUNCS(mbedtls_pkcs5_pbkdf2_hmac_ext)
CRYPTO_LIBS=$LIBS
LIBS=$saved_LIBS
CRYPTO_STATIC_LIBS=$CRYPTO_LIBS
use_internal_pbkdf2=0
use_internal_argon2=1
NO_FIPS([])
])
@@ -349,11 +439,6 @@ AC_ARG_ENABLE([veritysetup],
[], [enable_veritysetup=yes])
AM_CONDITIONAL(VERITYSETUP, test "x$enable_veritysetup" = "xyes")
AC_ARG_ENABLE([cryptsetup-reencrypt],
AS_HELP_STRING([--disable-cryptsetup-reencrypt], [disable cryptsetup-reencrypt tool]),
[], [enable_cryptsetup_reencrypt=yes])
AM_CONDITIONAL(REENCRYPT, test "x$enable_cryptsetup_reencrypt" = "xyes")
AC_ARG_ENABLE([integritysetup],
AS_HELP_STRING([--disable-integritysetup], [disable integritysetup support]),
[], [enable_integritysetup=yes])
@@ -400,15 +485,20 @@ PKG_CHECK_MODULES([JSON_C], [json-c])
AC_CHECK_DECLS([json_object_object_add_ex], [], [], [#include <json-c/json.h>])
AC_CHECK_DECLS([json_object_deep_copy], [], [], [#include <json-c/json.h>])
dnl Check for libssh for SSH plugin
dnl Check for libssh and argp for SSH plugin
if test "x$enable_ssh_token" = "xyes"; then
PKG_CHECK_MODULES([LIBSSH], [libssh])
AC_CHECK_DECLS([ssh_session_is_known_server], [], [], [#include <libssh/libssh.h>])
AC_CHECK_HEADER([argp.h], [], AC_MSG_ERROR([You need argp library.]))
saved_LIBS=$LIBS
AC_SEARCH_LIBS([argp_parse],[argp])
AC_SUBST(ARGP_LIBS, $LIBS)
LIBS=$saved_LIBS
fi
dnl Crypto backend configuration.
AC_ARG_WITH([crypto_backend],
AS_HELP_STRING([--with-crypto_backend=BACKEND], [crypto backend (gcrypt/openssl/nss/kernel/nettle) [openssl]]),
AS_HELP_STRING([--with-crypto_backend=BACKEND], [crypto backend (gcrypt/openssl/nss/kernel/nettle/mbedtls) [openssl]]),
[], [with_crypto_backend=openssl])
dnl Kernel crypto API backend needed for benchmark and tcrypt
@@ -428,6 +518,7 @@ case $with_crypto_backend in
nss) CONFIGURE_NSS([]) ;;
kernel) CONFIGURE_KERNEL([]) ;;
nettle) CONFIGURE_NETTLE([]) ;;
mbedtls) CONFIGURE_MBEDTLS([]) ;;
*) AC_MSG_ERROR([Unknown crypto backend.]) ;;
esac
AM_CONDITIONAL(CRYPTO_BACKEND_GCRYPT, test "$with_crypto_backend" = "gcrypt")
@@ -435,6 +526,7 @@ AM_CONDITIONAL(CRYPTO_BACKEND_OPENSSL, test "$with_crypto_backend" = "openssl")
AM_CONDITIONAL(CRYPTO_BACKEND_NSS, test "$with_crypto_backend" = "nss")
AM_CONDITIONAL(CRYPTO_BACKEND_KERNEL, test "$with_crypto_backend" = "kernel")
AM_CONDITIONAL(CRYPTO_BACKEND_NETTLE, test "$with_crypto_backend" = "nettle")
AM_CONDITIONAL(CRYPTO_BACKEND_MBEDTLS, test "$with_crypto_backend" = "mbedtls")
AM_CONDITIONAL(CRYPTO_INTERNAL_PBKDF2, test $use_internal_pbkdf2 = 1)
AC_DEFINE_UNQUOTED(USE_INTERNAL_PBKDF2, [$use_internal_pbkdf2], [Use internal PBKDF2])
@@ -447,12 +539,21 @@ AC_ARG_ENABLE([internal-argon2],
AC_ARG_ENABLE([libargon2],
AS_HELP_STRING([--enable-libargon2], [enable external libargon2 (PHC) library (disables internal bundled version)]))
if test "x$enable_libargon2" = "xyes" ; then
if test $use_internal_argon2 = 0 || ( test "x$enable_internal_argon2" = "xno" && test "x$enable_libargon2" != "xyes" ); then
if test "x$enable_internal_argon2" = "xyes" || test "x$enable_libargon2" = "xyes"; then
AC_MSG_NOTICE([Argon2 in $with_crypto_backend lib is used; internal Argon2 options are ignored.])
fi
enable_internal_argon2=no
enable_internal_sse_argon2=no
enable_libargon2=no
use_internal_argon2=0
elif test "x$enable_libargon2" = "xyes" ; then
AC_CHECK_HEADERS(argon2.h,,
[AC_MSG_ERROR([You need libargon2 development library installed.])])
AC_CHECK_DECL(Argon2_id,,[AC_MSG_ERROR([You need more recent Argon2 library with support for Argon2id.])], [#include <argon2.h>])
PKG_CHECK_MODULES([LIBARGON2], [libargon2],,[LIBARGON2_LIBS="-largon2"])
enable_internal_argon2=no
use_internal_argon2=0
else
AC_MSG_WARN([Argon2 bundled (slow) reference implementation will be used, please consider to use system library with --enable-libargon2.])
@@ -471,11 +572,10 @@ else
fi
fi
if test "x$enable_internal_argon2" = "xyes"; then
AC_DEFINE(USE_INTERNAL_ARGON2, 1, [Use internal Argon2])
fi
AM_CONDITIONAL(CRYPTO_INTERNAL_ARGON2, test "x$enable_internal_argon2" = "xyes")
AM_CONDITIONAL(CRYPTO_INTERNAL_SSE_ARGON2, test "x$enable_internal_sse_argon2" = "xyes")
dnl If libargon is in use, we have defined HAVE_ARGON2_H
AC_DEFINE_UNQUOTED(USE_INTERNAL_ARGON2, [$use_internal_argon2], [Use internal Argon2])
dnl Link with blkid to check for other device types
AC_ARG_ENABLE([blkid],
@@ -510,6 +610,27 @@ AM_CONDITIONAL(HAVE_BLKID, test "x$enable_blkid" = "xyes")
AM_CONDITIONAL(HAVE_BLKID_WIPE, test "x$enable_blkid_wipe" = "xyes")
AM_CONDITIONAL(HAVE_BLKID_STEP_BACK, test "x$enable_blkid_step_back" = "xyes")
AC_ARG_ENABLE([hw-opal],
AS_HELP_STRING([--disable-hw-opal], [disable use of hardware-backed OPAL for device encryption]),
[],
[enable_hw_opal=yes])
if test "x$enable_hw_opal" = "xyes"; then
have_opal=yes
AC_CHECK_DECLS([ OPAL_FL_SUM_SUPPORTED,
IOC_OPAL_GET_LR_STATUS,
IOC_OPAL_GET_GEOMETRY
],
[],
[have_opal=no],
[#include <linux/sed-opal.h>])
if test "x$have_opal" = "xyes"; then
AC_DEFINE([HAVE_HW_OPAL], 1, [Define to 1 to enable OPAL support.])
else
AC_MSG_WARN([Can not compile with OPAL support, kernel headers are too old, requires v6.4.])
fi
fi
dnl Magic for cryptsetup.static build.
if test "x$enable_static_cryptsetup" = "xyes"; then
saved_PKG_CONFIG=$PKG_CONFIG
@@ -542,6 +663,23 @@ if test "x$enable_static_cryptsetup" = "xyes"; then
PKG_CONFIG=$saved_PKG_CONFIG
fi
dnl Check compiler support for symver function attribute
AC_MSG_CHECKING([for symver attribute support])
saved_CFLAGS=$CFLAGS
CFLAGS="-O0 -Werror"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
void _test_sym(void);
__attribute__((__symver__("sym@VERSION_4.2"))) void _test_sym(void) {}
]],
[[ _test_sym() ]]
)],[
AC_DEFINE([HAVE_ATTRIBUTE_SYMVER], 1, [Define to 1 to use __attribute__((symver))])
AC_MSG_RESULT([yes])
], [
AC_MSG_RESULT([no])
])
CFLAGS=$saved_CFLAGS
AC_MSG_CHECKING([for systemd tmpfiles config directory])
PKG_CHECK_VAR([systemd_tmpfilesdir], [systemd], [tmpfilesdir], [], [systemd_tmpfilesdir=no])
AC_MSG_RESULT([$systemd_tmpfilesdir])
@@ -567,6 +705,22 @@ AC_SUBST([LIBSSH_LIBS])
AC_SUBST([LIBCRYPTSETUP_VERSION])
AC_SUBST([LIBCRYPTSETUP_VERSION_INFO])
dnl Set Requires.private for libcryptsetup.pc
dnl pwquality is used only by tools
PKGMODULES="uuid devmapper json-c"
case $with_crypto_backend in
gcrypt) PKGMODULES="$PKGMODULES libgcrypt" ;;
openssl) PKGMODULES="$PKGMODULES openssl" ;;
nss) PKGMODULES="$PKGMODULES nss" ;;
nettle) PKGMODULES="$PKGMODULES nettle" ;;
esac
if test "x$enable_libargon2" = "xyes"; then
PKGMODULES="$PKGMODULES libargon2"
fi
if test "x$enable_blkid" = "xyes"; then
PKGMODULES="$PKGMODULES blkid"
fi
AC_SUBST([PKGMODULES])
dnl ==========================================================================
AC_ARG_ENABLE([dev-random],
AS_HELP_STRING([--enable-dev-random], [use /dev/random by default for key generation (otherwise use /dev/urandom)]))
@@ -602,9 +756,9 @@ AC_DEFUN([CS_ABSPATH], [
])
dnl ==========================================================================
CS_STR_WITH([plain-hash], [password hashing function for plain mode], [ripemd160])
CS_STR_WITH([plain-hash], [password hashing function for plain mode], [sha256])
CS_STR_WITH([plain-cipher], [cipher for plain mode], [aes])
CS_STR_WITH([plain-mode], [cipher mode for plain mode], [cbc-essiv:sha256])
CS_STR_WITH([plain-mode], [cipher mode for plain mode], [xts-plain64])
CS_NUM_WITH([plain-keybits],[key length in bits for plain mode], [256])
CS_STR_WITH([luks1-hash], [hash function for LUKS1 header], [sha256])
@@ -689,5 +843,6 @@ lib/libcryptsetup.pc
po/Makefile.in
scripts/cryptsetup.conf
tests/Makefile
tests/fuzz/Makefile
])
AC_OUTPUT

View File

@@ -74,7 +74,7 @@
2012-03-16 Milan Broz <gmazyland@gmail.com>
* Add --keyfile-offset and --new-keyfile-offset parameters to API and CLI.
* Add repair command and crypt_repair() for known LUKS metadata problems repair.
* Allow to specify --align-payload only for luksFormat.
* Allow one to specify --align-payload only for luksFormat.
2012-03-16 Milan Broz <mbroz@redhat.com>
* Unify password verification option.
@@ -228,7 +228,7 @@
* Fix password callback call.
* Fix default plain password entry from terminal in activate_by_passphrase.
* Add --dump-master-key option for luksDump to allow volume key dump.
* Allow to activate by internally cached volume key
* Allow one to activate by internally cached volume key
(format/activate without keyslots active - used for temporary devices).
* Initialize volume key from active device in crypt_init_by_name()
* Fix cryptsetup binary exitcodes.

View File

@@ -12,30 +12,53 @@ no longer stored directly in dm-crypt target. Starting with cryptsetup 2.0 we
load VK in kernel keyring by default for LUKSv2 devices (when dm-crypt with the
feature is available).
Currently cryptsetup loads VK in 'logon' type kernel key so that VK is passed in
the kernel and can't be read from userspace afterward. Also cryptsetup loads VK in
thread keyring (before passing the reference to dm-crypt target) so that the key
Currently, cryptsetup loads VK in 'logon' type kernel key so that VK is passed in
the kernel and can't be read from userspace afterwards. Also, cryptsetup loads VK in
the thread keyring (before passing the reference to dm-crypt target) so that the key
lifetime is directly bound to the process that performs the dm-crypt setup. When
cryptsetup process exits (for whatever reason) the key gets unlinked in kernel
cryptsetup process exits (for whatever reason) the key gets unlinked in the kernel
automatically. In summary, the key description visible in dm-crypt table line is
a reference to VK that usually no longer exists in kernel keyring service if you
used cryptsetup to for device activation.
used cryptsetup for device activation.
Using this feature dm-crypt no longer maintains a direct key copy (but there's
always at least one copy in kernel crypto layer).
always at least one copy in the kernel crypto layer).
Additionally, libcryptsetup supports the linking of volume keys to
user-specified kernel keyring with crypt_set_keyring_to_link(). The user may
specify keyring name, key type ('user' or 'logon') and key description where
libcryptsetup should link the verified volume key upon subsequent device
activation (or key verification alone).
The volume key(s) (provided the key type is 'user') linked in the user keyring
can be later used to activate the device via crypt_activate_by_keyslot_context()
with CRYPT_KC_TYPE_VK_KEYRING type keyslot context
(acquired by crypt_keyslot_context_init_by_vk_in_keyring()).
Example of how to use volume key linked in custom user keyring from cryptsetup
utility:
1) Open the device and store the volume key to the session keyring:
# cryptsetup open <device> --link-vk-to-keyring "@s::%user:testkey" tst
2) Add a keyslot using the stored volume key in a keyring:
# cryptsetup luksAddKey <device> --volume-key-keyring "%user:testkey"
3) Activate the device using the volume key cached in a keyring ('user' type key)
# cryptsetup open <device> <active_name> --volume-key-keyring "testkey"
II) Keyslot passphrase
The second use case for kernel keyring is to allow cryptsetup reading the keyslot
passphrase stored in kernel keyring instead. The user may load passphrase in kernel
passphrase stored in kernel keyring instead. The user may load the passphrase in the kernel
keyring and notify cryptsetup to read it from there later. Currently, cryptsetup
cli supports kernel keyring for passphrase only via LUKS2 internal token
(luks2-keyring). Library also provides a general method for device activation by
reading passphrase from keyring: crypt_activate_by_keyring(). The key type
(luks2-keyring). The library also provides a general method for device activation by
reading the passphrase from the keyring: crypt_activate_by_keyring(). The key type
for use case II) must always be 'user' since we need to read the actual key
data from userspace unlike with VK in I). Ability to read keyslot passphrase
from kernel keyring also allows easily auto-activate LUKS2 devices.
data from userspace unlike with VK in I). The ability to read keyslot passphrases
from kernel keyring also allows easy auto-activate LUKS2 devices.
Simple example how to use kernel keyring for keyslot passphrase:
Simple example of how to use kernel keyring for keyslot passphrase:
1) create LUKS2 keyring token for keyslot 0 (in LUKS2 device/image)
cryptsetup token add --key-description my:key -S 0 /dev/device
@@ -43,7 +66,7 @@ cryptsetup token add --key-description my:key -S 0 /dev/device
2) Load keyslot passphrase in user keyring
read -s -p "Keyslot passphrase: "; echo -n $REPLY | keyctl padd user my:key @u
3) Activate device using passphrase stored in kernel keyring
3) Activate the device using the passphrase stored in the kernel keyring
cryptsetup open /dev/device my_unlocked_device
4a) unlink the key when no longer needed by
@@ -52,5 +75,5 @@ keyctl unlink %user:my:key @u
4b) or revoke it immediately by
keyctl revoke %user:my:key
If cryptsetup asks for passphrase in step 3) something went wrong with keyring
If cryptsetup asks for a passphrase in step 3) something went wrong with keyring
activation. See --debug output then.

View File

@@ -5,7 +5,7 @@ Why
~~~
LUKS2 format keeps two identical copies of metadata stored consecutively
at the head of metadata device (file or bdev). The metadata
at the head of the metadata device (file or bdev). The metadata
area (both copies) must be updated in a single atomic operation to avoid
header corruption during concurrent write.
@@ -15,17 +15,17 @@ locking with legacy format was not so obvious as it is with the LUKSv2 format.
With LUKS2 the boundary between read-only and read-write is blurry and what
used to be the exclusively read-only operation (i.e., cryptsetup open command) may
easily become read-update operation silently without user's knowledge.
Major feature of LUKS2 format is resilience against accidental
easily become read-update operation silently without the user's knowledge.
A major feature of the LUKS2 format is resilience against accidental
corruption of metadata (i.e., partial header overwrite by parted or cfdisk
while creating partition on mistaken block device).
Such header corruption is detected early on header read and auto-recovery
while creating a partition on a mistaken block device).
Such header corruption is detected early on the header read and the auto-recovery
procedure takes place (the corrupted header with checksum mismatch is being
replaced by the secondary one if that one is intact).
On current Linux systems header load operation may be triggered without user
direct intervention for example by udev rule or from systemd service.
Such clash of header read and auto-recovery procedure could have severe
consequences with the worst case of having LUKS2 device unaccessible or being
On current Linux systems header load operation may be triggered without the user
direct intervention for example by an udev rule or from a systemd service.
Such a clash of header read and auto-recovery procedure could have severe
consequences with the worst case of having a LUKS2 device inaccessible or being
broken beyond repair.
The whole locking of LUKSv2 device headers split into two categories depending
@@ -36,17 +36,17 @@ I) block device
We perform flock() on file descriptors of files stored in a private
directory (by default /run/lock/cryptsetup). The file name is derived
from major:minor couple of affected block device. Note we recommend
that access to private locking directory is supposed to be limited
to superuser only. For this method to work the distribution needs
from major:minor couple of the affected block device. Note we recommend
that access to the private locking directory is supposed to be limited
to the superuser only. For this method to work the distribution needs
to install the locking directory with appropriate access rights.
II) regular files
~~~~~~~~~~~~~~~~~
First notable difference between headers stored in a file
A first notable difference between headers stored in a file
vs. headers stored in a block device is that headers in a file may be
manipulated by the regular user unlike headers on block devices. Therefore
manipulated by the regular user, unlike headers on block devices. Therefore
we perform flock() protection on file with the luks2 header directly.
Limitations
@@ -58,4 +58,40 @@ while locking is enabled.
We do not suppress any other negative effect that two or more concurrent
writers of the same header may cause.
b) The locking is not cluster aware in any way.
b) The locking is not cluster-aware in any way.
Additional LUKS2 locks
======================
LUKS2 reencryption device lock
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Device in LUKS2 reencryption is protected by an exclusive lock placed in the default
locking directory. The lock's purpose is to exclude multiple processes from
performing reencryption on the same device (identified by LUKS uuid). The lock
is taken no matter the LUKS2 reencryption mode (online or offline).
LUKS2 memory hard global lock
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
An optional global lock that makes libcryptsetup serialize memory hard
pbkdf function when deriving a key encryption key from passphrase on unlocking
LUKS2 keyslot. The lock has to be enabled via the CRYPT_ACTIVATE_SERIALIZE_MEMORY_HARD_PBKDF
flag. The lock is placed in the default locking directory.
LUKS2 OPAL lock
~~~~~~~~~~~~~~~
Exclusive per device lock taken when manipulating LUKS2 device configured for use with
SED OPAL2 locking range.
Lock ordering
=============
To avoid a deadlock following rules must apply:
- LUKS2 reencrytpion lock must be taken before LUKS2 OPAL lock.
- LUKS2 OPAL lock must be taken before LUKS2 metadata lock.
- LUKS2 memory hard global lock can not be used with other locks.

View File

@@ -1,4 +1,4 @@
# Doxyfile 1.8.8
# Doxyfile 1.9.8
#---------------------------------------------------------------------------
# Project related configuration options
@@ -10,6 +10,7 @@ PROJECT_BRIEF = "Public cryptsetup API"
PROJECT_LOGO =
OUTPUT_DIRECTORY = doxygen_api_docs
CREATE_SUBDIRS = NO
CREATE_SUBDIRS_LEVEL = 8
ALLOW_UNICODE_NAMES = NO
OUTPUT_LANGUAGE = English
BRIEF_MEMBER_DESC = YES
@@ -22,40 +23,49 @@ STRIP_FROM_PATH =
STRIP_FROM_INC_PATH =
SHORT_NAMES = NO
JAVADOC_AUTOBRIEF = NO
JAVADOC_BANNER = NO
QT_AUTOBRIEF = NO
MULTILINE_CPP_IS_BRIEF = NO
PYTHON_DOCSTRING = YES
INHERIT_DOCS = YES
SEPARATE_MEMBER_PAGES = NO
TAB_SIZE = 8
ALIASES =
TCL_SUBST =
OPTIMIZE_OUTPUT_FOR_C = YES
OPTIMIZE_OUTPUT_JAVA = NO
OPTIMIZE_FOR_FORTRAN = NO
OPTIMIZE_OUTPUT_VHDL = NO
OPTIMIZE_OUTPUT_SLICE = NO
EXTENSION_MAPPING =
MARKDOWN_SUPPORT = YES
TOC_INCLUDE_HEADINGS = 5
MARKDOWN_ID_STYLE = DOXYGEN
AUTOLINK_SUPPORT = YES
BUILTIN_STL_SUPPORT = NO
CPP_CLI_SUPPORT = NO
SIP_SUPPORT = NO
IDL_PROPERTY_SUPPORT = YES
DISTRIBUTE_GROUP_DOC = NO
GROUP_NESTED_COMPOUNDS = NO
SUBGROUPING = YES
INLINE_GROUPED_CLASSES = NO
INLINE_SIMPLE_STRUCTS = NO
TYPEDEF_HIDES_STRUCT = YES
LOOKUP_CACHE_SIZE = 0
NUM_PROC_THREADS = 1
TIMESTAMP = NO
#---------------------------------------------------------------------------
# Build related configuration options
#---------------------------------------------------------------------------
EXTRACT_ALL = NO
EXTRACT_PRIVATE = NO
EXTRACT_PRIV_VIRTUAL = NO
EXTRACT_PACKAGE = NO
EXTRACT_STATIC = NO
EXTRACT_LOCAL_CLASSES = YES
EXTRACT_LOCAL_METHODS = NO
EXTRACT_ANON_NSPACES = NO
RESOLVE_UNNAMED_PARAMS = YES
HIDE_UNDOC_MEMBERS = NO
HIDE_UNDOC_CLASSES = NO
HIDE_FRIEND_COMPOUNDS = NO
@@ -63,6 +73,8 @@ HIDE_IN_BODY_DOCS = NO
INTERNAL_DOCS = NO
CASE_SENSE_NAMES = YES
HIDE_SCOPE_NAMES = NO
HIDE_COMPOUND_REFERENCE= NO
SHOW_HEADERFILE = YES
SHOW_INCLUDE_FILES = YES
SHOW_GROUPED_MEMB_INC = NO
FORCE_LOCAL_INCLUDES = NO
@@ -92,22 +104,27 @@ QUIET = NO
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_IF_INCOMPLETE_DOC = YES
WARN_NO_PARAMDOC = NO
WARN_IF_UNDOC_ENUM_VAL = NO
WARN_AS_ERROR = NO
WARN_FORMAT = "$file:$line: $text"
WARN_LINE_FORMAT = "at line $line of file $file"
WARN_LOGFILE =
#---------------------------------------------------------------------------
# Configuration options related to the input files
#---------------------------------------------------------------------------
INPUT = "doxygen_index.h" \
"../lib/libcryptsetup.h"
INPUT = doxygen_index.h \
../lib/libcryptsetup.h
INPUT_ENCODING = UTF-8
INPUT_FILE_ENCODING =
FILE_PATTERNS =
RECURSIVE = NO
EXCLUDE =
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS =
EXCLUDE_SYMBOLS =
EXAMPLE_PATH = "examples"
EXAMPLE_PATH = examples
EXAMPLE_PATTERNS =
EXAMPLE_RECURSIVE = NO
IMAGE_PATH =
@@ -116,6 +133,7 @@ FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
FILTER_SOURCE_PATTERNS =
USE_MDFILE_AS_MAINPAGE =
FORTRAN_COMMENT_AFTER = 72
#---------------------------------------------------------------------------
# Configuration options related to source browsing
#---------------------------------------------------------------------------
@@ -129,12 +147,13 @@ SOURCE_TOOLTIPS = YES
USE_HTAGS = NO
VERBATIM_HEADERS = YES
CLANG_ASSISTED_PARSING = NO
CLANG_ADD_INC_PATHS = YES
CLANG_OPTIONS =
CLANG_DATABASE_PATH =
#---------------------------------------------------------------------------
# Configuration options related to the alphabetical class index
#---------------------------------------------------------------------------
ALPHABETICAL_INDEX = YES
COLS_IN_ALPHA_INDEX = 5
IGNORE_PREFIX =
#---------------------------------------------------------------------------
# Configuration options related to the HTML output
@@ -147,14 +166,17 @@ HTML_FOOTER =
HTML_STYLESHEET =
HTML_EXTRA_STYLESHEET =
HTML_EXTRA_FILES =
HTML_COLORSTYLE = AUTO_LIGHT
HTML_COLORSTYLE_HUE = 220
HTML_COLORSTYLE_SAT = 100
HTML_COLORSTYLE_GAMMA = 80
HTML_TIMESTAMP = YES
HTML_DYNAMIC_MENUS = YES
HTML_DYNAMIC_SECTIONS = NO
HTML_CODE_FOLDING = YES
HTML_INDEX_NUM_ENTRIES = 100
GENERATE_DOCSET = NO
DOCSET_FEEDNAME = "Doxygen generated docs"
DOCSET_FEEDURL =
DOCSET_BUNDLE_ID = org.doxygen.Project
DOCSET_PUBLISHER_ID = org.doxygen.Publisher
DOCSET_PUBLISHER_NAME = Publisher
@@ -165,6 +187,7 @@ GENERATE_CHI = NO
CHM_INDEX_ENCODING =
BINARY_TOC = NO
TOC_EXPAND = NO
SITEMAP_URL =
GENERATE_QHP = NO
QCH_FILE =
QHP_NAMESPACE = org.doxygen.Project
@@ -177,12 +200,16 @@ GENERATE_ECLIPSEHELP = NO
ECLIPSE_DOC_ID = org.doxygen.Project
DISABLE_INDEX = NO
GENERATE_TREEVIEW = NO
FULL_SIDEBAR = NO
ENUM_VALUES_PER_LINE = 4
TREEVIEW_WIDTH = 250
EXT_LINKS_IN_WINDOW = NO
OBFUSCATE_EMAILS = YES
HTML_FORMULA_FORMAT = png
FORMULA_FONTSIZE = 10
FORMULA_TRANSPARENT = YES
FORMULA_MACROFILE =
USE_MATHJAX = NO
MATHJAX_VERSION = MathJax_2
MATHJAX_FORMAT = HTML-CSS
MATHJAX_RELPATH = http://www.mathjax.org/mathjax
MATHJAX_EXTENSIONS =
@@ -201,18 +228,20 @@ GENERATE_LATEX = YES
LATEX_OUTPUT = latex
LATEX_CMD_NAME = latex
MAKEINDEX_CMD_NAME = makeindex
LATEX_MAKEINDEX_CMD = makeindex
COMPACT_LATEX = NO
PAPER_TYPE = a4
EXTRA_PACKAGES =
LATEX_HEADER =
LATEX_FOOTER =
LATEX_EXTRA_STYLESHEET =
LATEX_EXTRA_FILES =
PDF_HYPERLINKS = YES
USE_PDFLATEX = YES
LATEX_BATCHMODE = NO
LATEX_HIDE_INDICES = NO
LATEX_SOURCE_CODE = NO
LATEX_BIB_STYLE = plain
LATEX_EMOJI_DIRECTORY =
#---------------------------------------------------------------------------
# Configuration options related to the RTF output
#---------------------------------------------------------------------------
@@ -236,17 +265,23 @@ MAN_LINKS = NO
GENERATE_XML = NO
XML_OUTPUT = xml
XML_PROGRAMLISTING = YES
XML_NS_MEMB_FILE_SCOPE = NO
#---------------------------------------------------------------------------
# Configuration options related to the DOCBOOK output
#---------------------------------------------------------------------------
GENERATE_DOCBOOK = NO
DOCBOOK_OUTPUT = docbook
DOCBOOK_PROGRAMLISTING = NO
#---------------------------------------------------------------------------
# Configuration options for the AutoGen Definitions output
#---------------------------------------------------------------------------
GENERATE_AUTOGEN_DEF = NO
#---------------------------------------------------------------------------
# Configuration options related to Sqlite3 output
#---------------------------------------------------------------------------
GENERATE_SQLITE3 = NO
SQLITE3_OUTPUT = sqlite3
SQLITE3_RECREATE_DB = YES
#---------------------------------------------------------------------------
# Configuration options related to the Perl module output
#---------------------------------------------------------------------------
GENERATE_PERLMOD = NO
@@ -273,24 +308,23 @@ GENERATE_TAGFILE =
ALLEXTERNALS = NO
EXTERNAL_GROUPS = YES
EXTERNAL_PAGES = YES
PERL_PATH =
#---------------------------------------------------------------------------
# Configuration options related to the dot tool
# Configuration options related to diagram generator tools
#---------------------------------------------------------------------------
CLASS_DIAGRAMS = YES
MSCGEN_PATH =
DIA_PATH =
HIDE_UNDOC_RELATIONS = YES
HAVE_DOT = NO
DOT_NUM_THREADS = 0
DOT_FONTNAME = Helvetica
DOT_FONTSIZE = 10
DOT_COMMON_ATTR = "fontname=Helvetica,fontsize=10"
DOT_EDGE_ATTR = "labelfontname=Helvetica,labelfontsize=10"
DOT_NODE_ATTR = "shape=box,height=0.2,width=0.4"
DOT_FONTPATH =
CLASS_GRAPH = YES
COLLABORATION_GRAPH = YES
GROUP_GRAPHS = YES
UML_LOOK = NO
UML_LIMIT_NUM_FIELDS = 10
DOT_UML_DETAILS = NO
DOT_WRAP_THRESHOLD = 17
TEMPLATE_RELATIONS = NO
INCLUDE_GRAPH = YES
INCLUDED_BY_GRAPH = YES
@@ -298,16 +332,20 @@ CALL_GRAPH = NO
CALLER_GRAPH = NO
GRAPHICAL_HIERARCHY = YES
DIRECTORY_GRAPH = YES
DIR_GRAPH_MAX_DEPTH = 1
DOT_IMAGE_FORMAT = png
INTERACTIVE_SVG = NO
DOT_PATH =
DOTFILE_DIRS =
MSCFILE_DIRS =
DIA_PATH =
DIAFILE_DIRS =
PLANTUML_JAR_PATH =
PLANTUML_CFG_FILE =
PLANTUML_INCLUDE_PATH =
DOT_GRAPH_MAX_NODES = 50
MAX_DOT_GRAPH_DEPTH = 0
DOT_TRANSPARENT = NO
DOT_MULTI_TARGETS = NO
GENERATE_LEGEND = YES
DOT_CLEANUP = YES
MSCGEN_TOOL =
MSCFILE_DIRS =

View File

@@ -1,21 +1,8 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libcryptsetup API log example
*
* Copyright (C) 2011-2021 Red Hat, Inc. All rights reserved.
*
* This file is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this file; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* Copyright (C) 2011-2025 Red Hat, Inc. All rights reserved.
*/
#include <stdio.h>

View File

@@ -1,21 +1,8 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libcryptsetup API - using LUKS device example
*
* Copyright (C) 2011-2021 Red Hat, Inc. All rights reserved.
*
* This file is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this file; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* Copyright (C) 2011-2025 Red Hat, Inc. All rights reserved.
*/
#include <stdio.h>

View File

@@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -0,0 +1,428 @@
Attribution-ShareAlike 4.0 International
=======================================================================
Creative Commons Corporation ("Creative Commons") is not a law firm and
does not provide legal services or legal advice. Distribution of
Creative Commons public licenses does not create a lawyer-client or
other relationship. Creative Commons makes its licenses and related
information available on an "as-is" basis. Creative Commons gives no
warranties regarding its licenses, any material licensed under their
terms and conditions, or any related information. Creative Commons
disclaims all liability for damages resulting from their use to the
fullest extent possible.
Using Creative Commons Public Licenses
Creative Commons public licenses provide a standard set of terms and
conditions that creators and other rights holders may use to share
original works of authorship and other material subject to copyright
and certain other rights specified in the public license below. The
following considerations are for informational purposes only, are not
exhaustive, and do not form part of our licenses.
Considerations for licensors: Our public licenses are
intended for use by those authorized to give the public
permission to use material in ways otherwise restricted by
copyright and certain other rights. Our licenses are
irrevocable. Licensors should read and understand the terms
and conditions of the license they choose before applying it.
Licensors should also secure all rights necessary before
applying our licenses so that the public can reuse the
material as expected. Licensors should clearly mark any
material not subject to the license. This includes other CC-
licensed material, or material used under an exception or
limitation to copyright. More considerations for licensors:
wiki.creativecommons.org/Considerations_for_licensors
Considerations for the public: By using one of our public
licenses, a licensor grants the public permission to use the
licensed material under specified terms and conditions. If
the licensor's permission is not necessary for any reason--for
example, because of any applicable exception or limitation to
copyright--then that use is not regulated by the license. Our
licenses grant only permissions under copyright and certain
other rights that a licensor has authority to grant. Use of
the licensed material may still be restricted for other
reasons, including because others have copyright or other
rights in the material. A licensor may make special requests,
such as asking that all changes be marked or described.
Although not required by our licenses, you are encouraged to
respect those requests where reasonable. More considerations
for the public:
wiki.creativecommons.org/Considerations_for_licensees
=======================================================================
Creative Commons Attribution-ShareAlike 4.0 International Public
License
By exercising the Licensed Rights (defined below), You accept and agree
to be bound by the terms and conditions of this Creative Commons
Attribution-ShareAlike 4.0 International Public License ("Public
License"). To the extent this Public License may be interpreted as a
contract, You are granted the Licensed Rights in consideration of Your
acceptance of these terms and conditions, and the Licensor grants You
such rights in consideration of benefits the Licensor receives from
making the Licensed Material available under these terms and
conditions.
Section 1 -- Definitions.
a. Adapted Material means material subject to Copyright and Similar
Rights that is derived from or based upon the Licensed Material
and in which the Licensed Material is translated, altered,
arranged, transformed, or otherwise modified in a manner requiring
permission under the Copyright and Similar Rights held by the
Licensor. For purposes of this Public License, where the Licensed
Material is a musical work, performance, or sound recording,
Adapted Material is always produced where the Licensed Material is
synched in timed relation with a moving image.
b. Adapter's License means the license You apply to Your Copyright
and Similar Rights in Your contributions to Adapted Material in
accordance with the terms and conditions of this Public License.
c. BY-SA Compatible License means a license listed at
creativecommons.org/compatiblelicenses, approved by Creative
Commons as essentially the equivalent of this Public License.
d. Copyright and Similar Rights means copyright and/or similar rights
closely related to copyright including, without limitation,
performance, broadcast, sound recording, and Sui Generis Database
Rights, without regard to how the rights are labeled or
categorized. For purposes of this Public License, the rights
specified in Section 2(b)(1)-(2) are not Copyright and Similar
Rights.
e. Effective Technological Measures means those measures that, in the
absence of proper authority, may not be circumvented under laws
fulfilling obligations under Article 11 of the WIPO Copyright
Treaty adopted on December 20, 1996, and/or similar international
agreements.
f. Exceptions and Limitations means fair use, fair dealing, and/or
any other exception or limitation to Copyright and Similar Rights
that applies to Your use of the Licensed Material.
g. License Elements means the license attributes listed in the name
of a Creative Commons Public License. The License Elements of this
Public License are Attribution and ShareAlike.
h. Licensed Material means the artistic or literary work, database,
or other material to which the Licensor applied this Public
License.
i. Licensed Rights means the rights granted to You subject to the
terms and conditions of this Public License, which are limited to
all Copyright and Similar Rights that apply to Your use of the
Licensed Material and that the Licensor has authority to license.
j. Licensor means the individual(s) or entity(ies) granting rights
under this Public License.
k. Share means to provide material to the public by any means or
process that requires permission under the Licensed Rights, such
as reproduction, public display, public performance, distribution,
dissemination, communication, or importation, and to make material
available to the public including in ways that members of the
public may access the material from a place and at a time
individually chosen by them.
l. Sui Generis Database Rights means rights other than copyright
resulting from Directive 96/9/EC of the European Parliament and of
the Council of 11 March 1996 on the legal protection of databases,
as amended and/or succeeded, as well as other essentially
equivalent rights anywhere in the world.
m. You means the individual or entity exercising the Licensed Rights
under this Public License. Your has a corresponding meaning.
Section 2 -- Scope.
a. License grant.
1. Subject to the terms and conditions of this Public License,
the Licensor hereby grants You a worldwide, royalty-free,
non-sublicensable, non-exclusive, irrevocable license to
exercise the Licensed Rights in the Licensed Material to:
a. reproduce and Share the Licensed Material, in whole or
in part; and
b. produce, reproduce, and Share Adapted Material.
2. Exceptions and Limitations. For the avoidance of doubt, where
Exceptions and Limitations apply to Your use, this Public
License does not apply, and You do not need to comply with
its terms and conditions.
3. Term. The term of this Public License is specified in Section
6(a).
4. Media and formats; technical modifications allowed. The
Licensor authorizes You to exercise the Licensed Rights in
all media and formats whether now known or hereafter created,
and to make technical modifications necessary to do so. The
Licensor waives and/or agrees not to assert any right or
authority to forbid You from making technical modifications
necessary to exercise the Licensed Rights, including
technical modifications necessary to circumvent Effective
Technological Measures. For purposes of this Public License,
simply making modifications authorized by this Section 2(a)
(4) never produces Adapted Material.
5. Downstream recipients.
a. Offer from the Licensor -- Licensed Material. Every
recipient of the Licensed Material automatically
receives an offer from the Licensor to exercise the
Licensed Rights under the terms and conditions of this
Public License.
b. Additional offer from the Licensor -- Adapted Material.
Every recipient of Adapted Material from You
automatically receives an offer from the Licensor to
exercise the Licensed Rights in the Adapted Material
under the conditions of the Adapter's License You apply.
c. No downstream restrictions. You may not offer or impose
any additional or different terms or conditions on, or
apply any Effective Technological Measures to, the
Licensed Material if doing so restricts exercise of the
Licensed Rights by any recipient of the Licensed
Material.
6. No endorsement. Nothing in this Public License constitutes or
may be construed as permission to assert or imply that You
are, or that Your use of the Licensed Material is, connected
with, or sponsored, endorsed, or granted official status by,
the Licensor or others designated to receive attribution as
provided in Section 3(a)(1)(A)(i).
b. Other rights.
1. Moral rights, such as the right of integrity, are not
licensed under this Public License, nor are publicity,
privacy, and/or other similar personality rights; however, to
the extent possible, the Licensor waives and/or agrees not to
assert any such rights held by the Licensor to the limited
extent necessary to allow You to exercise the Licensed
Rights, but not otherwise.
2. Patent and trademark rights are not licensed under this
Public License.
3. To the extent possible, the Licensor waives any right to
collect royalties from You for the exercise of the Licensed
Rights, whether directly or through a collecting society
under any voluntary or waivable statutory or compulsory
licensing scheme. In all other cases the Licensor expressly
reserves any right to collect such royalties.
Section 3 -- License Conditions.
Your exercise of the Licensed Rights is expressly made subject to the
following conditions.
a. Attribution.
1. If You Share the Licensed Material (including in modified
form), You must:
a. retain the following if it is supplied by the Licensor
with the Licensed Material:
i. identification of the creator(s) of the Licensed
Material and any others designated to receive
attribution, in any reasonable manner requested by
the Licensor (including by pseudonym if
designated);
ii. a copyright notice;
iii. a notice that refers to this Public License;
iv. a notice that refers to the disclaimer of
warranties;
v. a URI or hyperlink to the Licensed Material to the
extent reasonably practicable;
b. indicate if You modified the Licensed Material and
retain an indication of any previous modifications; and
c. indicate the Licensed Material is licensed under this
Public License, and include the text of, or the URI or
hyperlink to, this Public License.
2. You may satisfy the conditions in Section 3(a)(1) in any
reasonable manner based on the medium, means, and context in
which You Share the Licensed Material. For example, it may be
reasonable to satisfy the conditions by providing a URI or
hyperlink to a resource that includes the required
information.
3. If requested by the Licensor, You must remove any of the
information required by Section 3(a)(1)(A) to the extent
reasonably practicable.
b. ShareAlike.
In addition to the conditions in Section 3(a), if You Share
Adapted Material You produce, the following conditions also apply.
1. The Adapter's License You apply must be a Creative Commons
license with the same License Elements, this version or
later, or a BY-SA Compatible License.
2. You must include the text of, or the URI or hyperlink to, the
Adapter's License You apply. You may satisfy this condition
in any reasonable manner based on the medium, means, and
context in which You Share Adapted Material.
3. You may not offer or impose any additional or different terms
or conditions on, or apply any Effective Technological
Measures to, Adapted Material that restrict exercise of the
rights granted under the Adapter's License You apply.
Section 4 -- Sui Generis Database Rights.
Where the Licensed Rights include Sui Generis Database Rights that
apply to Your use of the Licensed Material:
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
to extract, reuse, reproduce, and Share all or a substantial
portion of the contents of the database;
b. if You include all or a substantial portion of the database
contents in a database in which You have Sui Generis Database
Rights, then the database in which You have Sui Generis Database
Rights (but not its individual contents) is Adapted Material,
including for purposes of Section 3(b); and
c. You must comply with the conditions in Section 3(a) if You Share
all or a substantial portion of the contents of the database.
For the avoidance of doubt, this Section 4 supplements and does not
replace Your obligations under this Public License where the Licensed
Rights include other Copyright and Similar Rights.
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
c. The disclaimer of warranties and limitation of liability provided
above shall be interpreted in a manner that, to the extent
possible, most closely approximates an absolute disclaimer and
waiver of all liability.
Section 6 -- Term and Termination.
a. This Public License applies for the term of the Copyright and
Similar Rights licensed here. However, if You fail to comply with
this Public License, then Your rights under this Public License
terminate automatically.
b. Where Your right to use the Licensed Material has terminated under
Section 6(a), it reinstates:
1. automatically as of the date the violation is cured, provided
it is cured within 30 days of Your discovery of the
violation; or
2. upon express reinstatement by the Licensor.
For the avoidance of doubt, this Section 6(b) does not affect any
right the Licensor may have to seek remedies for Your violations
of this Public License.
c. For the avoidance of doubt, the Licensor may also offer the
Licensed Material under separate terms or conditions or stop
distributing the Licensed Material at any time; however, doing so
will not terminate this Public License.
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
License.
Section 7 -- Other Terms and Conditions.
a. The Licensor shall not be bound by any additional or different
terms or conditions communicated by You unless expressly agreed.
b. Any arrangements, understandings, or agreements regarding the
Licensed Material not stated herein are separate from and
independent of the terms and conditions of this Public License.
Section 8 -- Interpretation.
a. For the avoidance of doubt, this Public License does not, and
shall not be interpreted to, reduce, limit, restrict, or impose
conditions on any use of the Licensed Material that could lawfully
be made without permission under this Public License.
b. To the extent possible, if any provision of this Public License is
deemed unenforceable, it shall be automatically reformed to the
minimum extent necessary to make it enforceable. If the provision
cannot be reformed, it shall be severed from this Public License
without affecting the enforceability of the remaining terms and
conditions.
c. No term or condition of this Public License will be waived and no
failure to comply consented to unless expressly agreed to by the
Licensor.
d. Nothing in this Public License constitutes or may be interpreted
as a limitation upon, or waiver of, any privileges and immunities
that apply to the Licensor or You, including from the legal
processes of any jurisdiction or authority.
=======================================================================
Creative Commons is not a party to its public
licenses. Notwithstanding, Creative Commons may elect to apply one of
its public licenses to material it publishes and in those instances
will be considered the “Licensor.” The text of the Creative Commons
public licenses is dedicated to the public domain under the CC0 Public
Domain Dedication. Except for the limited purpose of indicating that
material is shared under a Creative Commons public license or as
otherwise permitted by the Creative Commons policies published at
creativecommons.org/policies, Creative Commons does not authorize the
use of the trademark "Creative Commons" or any other trademark or logo
of Creative Commons without its prior written consent including,
without limitation, in connection with any unauthorized modifications
to any of its public licenses or any other arrangements,
understandings, or agreements concerning use of licensed material. For
the avoidance of doubt, this paragraph does not form part of the
public licenses.
Creative Commons may be contacted at creativecommons.org.

View File

@@ -0,0 +1,354 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
-----
In addition, as a special exception, the copyright holders give
permission to link the code of portions of this program with the
OpenSSL library under certain conditions as described in each
individual source file, and distribute linked combinations
including the two.
You must obey the GNU General Public License in all respects
for all of the code used other than OpenSSL. If you modify
file(s) with this exception, you may extend this exception to your
version of the file(s), but you are not obligated to do so. If you
do not wish to do so, delete this exception statement from your
version. If you delete this exception statement from all source
files in the program, then also delete it here.

Binary file not shown.

View File

@@ -85,7 +85,7 @@ Libcryptsetup API additions:
* Fix optional password callback handling.
* Allow to activate by internally cached volume key immediately after
* Allow one to activate by internally cached volume key immediately after
crypt_format() without active slot (for temporary devices with
on-disk metadata)

View File

@@ -24,7 +24,7 @@ Changes since version 1.4.1
* Fix header check to support old (cryptsetup 1.0.0) header alignment.
(Regression in 1.4.0)
* Allow to specify --align-payload only for luksFormat.
* Allow one to specify --align-payload only for luksFormat.
* Add --master-key-file option to luksOpen (open using volume key).

View File

@@ -32,7 +32,7 @@ Changes since version 1.4.2
Device-mapper now retry removal if device is busy.
* Allow "private" activation (skip some udev global rules) flag.
Cryptsetup library API now allows to specify CRYPT_ACTIVATE_PRIVATE,
Cryptsetup library API now allows one to specify CRYPT_ACTIVATE_PRIVATE,
which means that some udev rules are not processed.
(Used for temporary devices, like internal keyslot mappings where
it is not desirable to run any device scans.)

View File

@@ -4,7 +4,7 @@ Cryptsetup 1.6.0 Release Notes
Changes since version 1.6.0-rc1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Change LUKS default cipher to to use XTS encryption mode,
* Change LUKS default cipher to use XTS encryption mode,
aes-xts-plain64 (i.e. using AES128-XTS).
XTS mode becomes standard in hard disk encryption.
@@ -209,7 +209,7 @@ Important changes
WARNING: these tests do not use dmcrypt, only crypto API.
You have to benchmark the whole device stack and you can get completely
different results. But is is usable for basic comparison.
different results. But it is usable for basic comparison.
(Note for example AES-NI decryption optimization effect in example above.)
Features

View File

@@ -8,7 +8,7 @@ Changes since version 1.6.1
* Fix cipher specification string parsing (found by gcc -fsanitize=address option).
* Try to map TCRYPT system encryption through partition
(allows to activate mapping when other partition on the same device is mounted).
(allows one to activate mapping when other partition on the same device is mounted).
* Print a warning if system encryption is used and device is a partition.
(TCRYPT system encryption uses whole device argument.)

View File

@@ -25,7 +25,7 @@ Changes since version 1.6.3
Please refer to cryptsetup FAQ for detail how to fix this situation.
* Allow to use --disable-gcrypt-pbkdf2 during configuration
* Allow one to use --disable-gcrypt-pbkdf2 during configuration
to force use internal PBKDF2 code.
* Require gcrypt 1.6.1 for imported implementation of PBKDF2

View File

@@ -38,7 +38,7 @@ Changes since version 1.6.4
The command "cryptsetup status" will print basic info, even if you
do not provide detached header argument.
* Allow to specify ECB mode in cryptsetup benchmark.
* Allow one to specify ECB mode in cryptsetup benchmark.
* Add some LUKS images for regression testing.
Note that if image with Whirlpool fails, the most probable cause is that

View File

@@ -35,14 +35,14 @@ Changes since version 1.6.6
* Support permanent device decryption for cryptsetup-reencrypt.
To remove LUKS encryption from a device, you can now use --decrypt option.
* Allow to use --header option in all LUKS commands.
* Allow one to use --header option in all LUKS commands.
The --header always takes precedence over positional device argument.
* Allow luksSuspend without need to specify a detached header.
* Detect if O_DIRECT is usable on a device allocation.
There are some strange storage stack configurations which wrongly allows
to open devices with direct-io but fails on all IO operations later.
one to open devices with direct-io but fails on all IO operations later.
Cryptsetup now tries to read the device first sector to ensure it can use
direct-io.

View File

@@ -30,7 +30,7 @@ Changes since version 1.6.7
cryptsetup resize will try to resize underlying loop device as well.
(It can be used to grow up file-backed device in one step.)
* Cryptsetup now allows to use empty password through stdin pipe.
* Cryptsetup now allows one to use empty password through stdin pipe.
(Intended only for testing in scripts.)
Cryptsetup API NOTE:

View File

@@ -3,7 +3,7 @@ Cryptsetup 1.7.4 Release Notes
Changes since version 1.7.3
* Allow to specify LUKS1 hash algorithm in Python luksFormat wrapper.
* Allow one to specify LUKS1 hash algorithm in Python luksFormat wrapper.
* Use LUKS1 compiled-in defaults also in Python wrapper.

View File

@@ -89,7 +89,7 @@ Important features
Integritysetup is intended to be used for settings that require
non-cryptographic data integrity protection with no data encryption.
Fo setting integrity protected encrypted devices, see disk authenticated
For setting integrity protected encrypted devices, see disk authenticated
encryption below.
Note that after formatting the checksums need to be initialized;
@@ -583,7 +583,7 @@ Unfinished things & TODO for next releases
in kernel (more on this later).
NOTE: Currently available authenticated modes (GCM, Chacha20-poly1305)
in kernel have too small 96-bit nonces that are problematic with
randomly generated IVs (the collison probability is not negligible).
randomly generated IVs (the collision probability is not negligible).
For the GCM, nonce collision is a fatal problem.
* Authenticated encryption do not set encryption for dm-integrity journal.

View File

@@ -30,7 +30,7 @@ Changes since version 2.0.1
* Add LUKS2 specific options for cryptsetup-reencrypt.
Tokens and persistent flags are now transferred during reencryption;
change of PBKDF keyslot parameters is now supported and allows
change of PBKDF keyslot parameters is now supported and allows one
to set precalculated values (no benchmarks).
* Do not allow LUKS2 --persistent and --test-passphrase cryptsetup flags

View File

@@ -28,7 +28,7 @@ Changes since version 2.0.2
* New API extensions for unbound keyslots (LUKS2 only)
crypt_keyslot_get_key_size() and crypt_volume_key_get()
These functions allow to get key and key size for unbound keyslots.
These functions allow one to get key and key size for unbound keyslots.
* New enum value CRYPT_SLOT_UNBOUND for keyslot status (LUKS2 only).

View File

@@ -170,21 +170,21 @@ These new calls are now exported, for details see libcryptsetup.h:
* crypt_get_metadata_size
* crypt_set_metadata_size
allows to set/get area sizes in LUKS header
allows one to set/get area sizes in LUKS header
(according to specification).
* crypt_get_default_type
get default compiled-in LUKS type (version).
* crypt_get_pbkdf_type_params
allows to get compiled-in PBKDF parameters.
allows one to get compiled-in PBKDF parameters.
* crypt_keyslot_set_encryption
* crypt_keyslot_get_encryption
allows to set/get per-keyslot encryption algorithm for LUKS2.
allows one to set/get per-keyslot encryption algorithm for LUKS2.
* crypt_keyslot_get_pbkdf
allows to get PBKDF parameters per-keyslot.
allows one to get PBKDF parameters per-keyslot.
and these new defines:
* CRYPT_LOG_DEBUG_JSON (message type for JSON debug)

View File

@@ -9,7 +9,7 @@ native read-write access to BitLocker Full Disk Encryption devices.
The BITLK implementation is based on publicly available information
and it is an independent and opensource implementation that allows
to access this proprietary disk encryption.
one to access this proprietary disk encryption.
Changes since version 2.2.2
~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@@ -18,7 +18,7 @@ Changes since version 2.3.1
The slot number --key-slot (-S) option is mandatory here.
An unbound keyslot store a key is that is not assigned to data
area on disk (LUKS2 allows to store arbitrary keys).
area on disk (LUKS2 allows one to store arbitrary keys).
* Rephrase some error messages and remove redundant end-of-lines.

View File

@@ -75,7 +75,7 @@ Changes since version 2.3.3
If users want to use blake2b/blake2s, the kernel algorithm name includes
a dash (like "blake2s-256").
Theses algorithms can now be used for integritysetup devices.
These algorithms can now be used for integritysetup devices.
* Fix crypto backend to properly handle ECB mode.

View File

@@ -1,6 +1,6 @@
Cryptsetup 2.4.0 Release Notes
==============================
Stable release candidate with new features and bug fixes.
Stable release with new features and bug fixes.
This version introduces support for external libraries
(plugins) for handling LUKS2 token objects.

47
docs/v2.4.1-ReleaseNotes Normal file
View File

@@ -0,0 +1,47 @@
Cryptsetup 2.4.1 Release Notes
==============================
Stable bug-fix release with minor extensions.
All users of cryptsetup 2.4.0 should upgrade to this version.
Changes since version 2.4.0
~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Fix compilation for libc implementations without dlvsym().
Some alternative libc implementations (like musl) do not provide
versioned symbols dlvsym function. Code now fallbacks to dlsym
operation for dynamic LUKS2 token load.
It is up to maintainers to ensure that LUKS2 token plugins are
compiled for the supported version.
* Fix compilation and tests on systems with non-standard libraries
(standalone argp library, external gettext library, BusyBox
implementations of standard tools).
* Try to workaround some issues on systems without udev support.
NOTE: non-udev systems cannot provide all functionality for kernel
device-mapper, and some operations can fail.
* Fixes for OpenSSL3 crypto backend (including FIPS mode).
Because cryptsetup still requires some hash functions implemented
in OpenSSL3 legacy provider, crypto backend now uses its library
context and tries to load both default and legacy OpenSSL3 providers.
If FIPS mode is detected, no library context is used, and it is up
to the OpenSSL system-wide policy to load proper providers.
NOTE: We still use some deprecated API in the OpenSSL3 backend,
and there are some known problems in OpenSSL 3.0.0.
* Print error message when assigning a token to an inactive keyslot.
* Fix offset bug in LUKS2 encryption code if --offset option was used.
* Do not allow LUKS2 decryption for devices with data offset.
Such devices cannot be used after decryption.
* Fix LUKS1 cryptsetup repair command for some specific problems.
Repair code can now fix wrongly used initialization vector
specification in ECB mode (that is insecure anyway!) and repair
the upper-case hash specification in the LUKS1 header.

37
docs/v2.4.2-ReleaseNotes Normal file
View File

@@ -0,0 +1,37 @@
Cryptsetup 2.4.2 Release Notes
==============================
Stable bug-fix release.
All users of cryptsetup 2.4.1 should upgrade to this version.
Changes since version 2.4.1
~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Fix possible large memory allocation if LUKS2 header size is invalid.
LUKS2 code read the full header to buffer to verify the checksum.
The maximal supported header size now limits the memory allocation.
* Fix memory corruption in debug message printing LUKS2 checksum.
* veritysetup: remove link to the UUID library for the static build.
* Remove link to pwquality library for integritysetup and veritysetup.
These tools do not read passphrases.
* OpenSSL3 backend: avoid remaining deprecated calls in API.
Crypto backend no longer use API deprecated in OpenSSL 3.0
* Check if kernel device-mapper create device failed in an early phase.
This happens when a concurrent creation of device-mapper devices
meets in the very early state.
* Do not set compiler optimization flag for Argon2 KDF if the memory
wipe is implemented in libc.
* Do not attempt to unload LUKS2 tokens if external tokens are disabled.
This allows building a static binary with --disable-external-tokens.
* LUKS convert: also check sysfs for device activity.
If udev symlink is missing, code fallbacks to sysfs scan to prevent
data corruption for the active device.

101
docs/v2.4.3-ReleaseNotes Normal file
View File

@@ -0,0 +1,101 @@
Cryptsetup 2.4.3 Release Notes
==============================
Stable security bug-fix release that fixes CVE-2021-4122.
All users of cryptsetup 2.4.x must upgrade to this version.
Changes since version 2.4.2
~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Fix possible attacks against data confidentiality through LUKS2 online
reencryption extension crash recovery (CVE-2021-4122).
An attacker can modify on-disk metadata to simulate decryption in
progress with crashed (unfinished) reencryption step and persistently
decrypt part of the LUKS device.
This attack requires repeated physical access to the LUKS device but
no knowledge of user passphrases.
The decryption step is performed after a valid user activates
the device with a correct passphrase and modified metadata.
There are no visible warnings for the user that such recovery happened
(except using the luksDump command). The attack can also be reversed
afterward (simulating crashed encryption from a plaintext) with
possible modification of revealed plaintext.
The size of possible decrypted data depends on configured LUKS2 header
size (metadata size is configurable for LUKS2).
With the default parameters (16 MiB LUKS2 header) and only one
allocated keyslot (512 bit key for AES-XTS), simulated decryption with
checksum resilience SHA1 (20 bytes checksum for 4096-byte blocks),
the maximal decrypted size can be over 3GiB.
The attack is not applicable to LUKS1 format, but the attacker can
update metadata in place to LUKS2 format as an additional step.
For such a converted LUKS2 header, the keyslot area is limited to
decrypted size (with SHA1 checksums) over 300 MiB.
The issue is present in all cryptsetup releases since 2.2.0.
Versions 1.x, 2.0.x, and 2.1.x are not affected, as these do not
contain LUKS2 reencryption extension.
The problem was caused by reusing a mechanism designed for actual
reencryption operation without reassessing the security impact for new
encryption and decryption operations. While the reencryption requires
calculating and verifying both key digests, no digest was needed to
initiate decryption recovery if the destination is plaintext (no
encryption key). Also, some metadata (like encryption cipher) is not
protected, and an attacker could change it. Note that LUKS2 protects
visible metadata only when a random change occurs. It does not protect
against intentional modification but such modification must not cause
a violation of data confidentiality.
The fix introduces additional digest protection of reencryption
metadata. The digest is calculated from known keys and critical
reencryption metadata. Now an attacker cannot create correct metadata
digest without knowledge of a passphrase for used keyslots.
For more details, see LUKS2 On-Disk Format Specification version 1.1.0.
The former reencryption operation (without the additional digest) is no
longer supported (reencryption with the digest is not backward
compatible). You need to finish in-progress reencryption before
updating to new packages. The alternative approach is to perform
a repair command from the updated package to recalculate reencryption
digest and fix metadata.
The reencryption repair operation always require a user passphrase.
WARNING: Devices with older reencryption in progress can be no longer
activated without performing the action mentioned above.
Encryption in progress can be detected by running the luksDump command
(output includes reencrypt keyslot with reencryption parameters). Also,
during the active reencryption, no keyslot operations are available
(change of passphrases, etc.).
The issue was found by Milan Broz as cryptsetup maintainer.
Other changes
~~~~~~~~~~~~~
* Add configure option --disable-luks2-reencryption to completely disable
LUKS2 reencryption code.
When used, the libcryptsetup library can read metadata with
reencryption code, but all reencryption API calls and cryptsetup
reencrypt commands are disabled.
Devices with online reencryption in progress cannot be activated.
This option can cause some incompatibilities. Please use with care.
* Improve internal metadata validation code for reencryption metadata.
* Add updated documentation for LUKS2 On-Disk Format Specification
version 1.1.0 (with reencryption extension description and updated
metadata description). See docs/on-disk-format-luks2.pdf or online
version in https://gitlab.com/cryptsetup/LUKS2-docs repository.
* Fix support for bitlk (BitLocker compatible) startup key with new
metadata entry introduced in Windows 11.
* Fix space restriction for LUKS2 reencryption with data shift.
The code required more space than was needed.

291
docs/v2.5.0-ReleaseNotes Normal file
View File

@@ -0,0 +1,291 @@
Cryptsetup 2.5.0 Release Notes
==============================
Stable release with new features and bug fixes.
Changes since version 2.4.3
~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Split manual pages into per-action pages and use AsciiDoc format.
Manual pages are now generated from AsciiDoc format, allowing easy
conditional modifications for per-action options.
Generation of man pages requires the asciidoctor tool installed.
Pre-generated man pages are also included in the distribution tarball.
You can use --disable-asciidoc configure option to skip man page
generation completely. In this case, pre-generated man pages will be
used for installation.
For cryptsetup, there is main man page (cryptsetup.8) that references
separate man pages for each command (for example, cryptsetup-open.8).
You can open such a man page by simply running "man cryptsetup open".
Also, man pages for action aliases are available (cryptsetup-luksOpen.8
is an alias for cryptsetup-open.8, etc.)
LUKS volume reencryption changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Remove cryptsetup-reencrypt tool from the project and move reencryption
to already existing "cryptsetup reencrypt" command.
Cryptsetup reencrypt now handles both LUKS1 and LUKS2 reencryption,
encryption, and decryption.
If you need to emulate the old cryptsetup-reencrypt binary, use simple
wrappers script running "exec cryptsetup reencrypt $@".
All command line options should be compatible. An exception is the
reencryption of LUKS2 volumes with old LUKS1 reencryption code that was
replaced by native and more resilient LUKS2 reencryption.
* LUKS2: implement --decryption option that allows LUKS removal. The
operation can run online or offline and supports the data shift option.
During the initialization, the LUKS2 header is exported to a file.
The first data segment is moved to the head of the data device in place
of the original header.
The feature internally introduces several new resilience modes
(combination of existing modes datashift and "checksum" or "journal").
Datashift resilience mode is applied for data moved towards the first
segment, and the first segment is then decrypted in place.
This decryption mode is not backward compatible with prior LUKS2
reencryption. Interrupted operations in progress cannot be resumed
using older cryptsetup releases.
* Reencryption metadata options that are not compatible with recent code
(features implemented in more recent releases) are now only read, but
code will not activate or modify such metadata.
Reencryption metadata contains a version that is validated when
reencryption is resumed.
For more info, see the updated LUKS2 on-disk format specification.
Safe operation of reencryption is to always finish the operation with
only one version of the tools.
* Fix decryption operation with --active-name option and restrict
it to be used only with LUKS2.
* Do not refresh reencryption digest when not needed.
This should speed up the reencryption resume process.
* Store proper resilience data in LUKS2 reencrypt initialization.
Resuming reencryption now does not require specification of resilience
type parameters if these are the same as during initialization.
* Properly wipe the unused area after reencryption with datashift in
the forward direction.
* Check datashift value against larger sector size.
For example, it could cause an issue if misaligned 4K sector appears
during decryption.
* Do not allow sector size increase reencryption in offline mode.
The eventual logical block size increase on the dm-crypt device above
may lead to an unusable filesystem. Do not allow offline reencryption
when sector size increase is requested.
You can use --force-offline-reencrypt option to override this check
(and potentially destroy the data).
* Do not allow dangerous sector size change during reencryption.
By changing the encryption sector size during reencryption, a user
may increase the effective logical block size for the dm-crypt active
device.
Do not allow encryption sector size to be increased over the value
provided by fs superblock in BLOCK_SIZE property.
* Ask the user for confirmation before resuming reencryption.
The prompt is not shown in batch mode or when the user explicitly asks
for a reencryption resume via --resume-only.
* Do not resume reencryption with conflicting parameters.
For example, if the operation was initialized as --encrypt, do not
allow resume with opposing parameter --decrypt and vice versa.
Also, the code now checks for conflicting resilience parameters
(datashift cannot be changed after initialization).
* Add --force-offline-reencrypt option.
It can be used to enforce offline reencryption in batch mode when
the device is a regular file; therefore, cryptsetup cannot detect
properly active devices using it.
Also, it may be useful to override the active device auto-detection
for specific storage configurations (dangerous!).
* Do not allow nested encryption in LUKS reencrypt.
Avoid accidental nested encryption via cryptsetup reencrypt --encrypt.
* Fix --test-passphrase when the device is in reencryption.
* Do not upload keys in keyring during offline reencryption.
Reencryption runs in userspace, so the kernel does not need the key.
* Support all options allowed with luksFormat with encrypt action.
* Add prompt if LUKS2 decryption is run with a detached header.
* Add warning for reencryption of file image and mention
the possible use of --force-offline-reencrypt option.
Other changes
~~~~~~~~~~~~~
* Add resize action to integritysetup.
This allows resizing of standalone integrity devices.
* Support --device-size option (that allows unit specification) for plain
devices (existing --size option requires 512-byte sectors units).
* Fix detection of encryption sector size if a detached header is used.
* Remove obsolete dracut plugin reencryption example.
* Fix possible keyslot area size overflow during conversion to LUKS2.
If keyslots are not sorted according to binary area offset, the area
size calculation was wrong and could overflow.
* Hardening and fixes to LUKS2 validation functions:
* Log a visible error if convert fails due to validation check.
* Check for interval (keyslot and segment area) overflow.
* Check cipher availability before LUKS conversion to LUKS2.
Some historic incompatibilities are ignored for LUKS1 but do not
work for LUKS2.
* Add empty string check to LUKS2 metadata JSON validation.
Most of the LUKS2 fields cannot be empty.
* Fix JSON objects validation to check JSON object type properly.
* TCRYPT: Properly apply retry count and continue if some PBKDF variant
is unavailable.
* BITLK: Add a warning when activating a device with the wrong size
stored in metadata.
* BITLK: Add BitLocker volume size to dump command.
* BITLK: Fix possible UTF16 buffer overflow in volume key dump.
* BITLK: Skip question if the batch mode is set for volume key dump.
* BITLK: Check dm-zero availability in the kernel.
Bitlocker compatible mode uses dm-zero to mask metadata area.
The device cannot be activated if dm-zero is not available.
* Fix error message for LUKS2-only cryptsetup commands to explicitly
state LUKS2 version is required.
* Fix error message for incompatible dm-integrity metadata.
If the integritysetup tool is too old, kernel dm-integrity may use
a more recent version of dm-integrity metadata.
* Properly deactivate the integrity device even if the LUKS2 header
is no longer available.
If LUKS2 is used with integrity protection, there is always
a dm-integrity device underneath that must be deactivated.
* Allow use of --header option for cryptsetup close.
This can be used to check that the activated device has the same UUID.
* Fix activation of LUKS2 device with integrity and detached header.
The kernel-parsed dm-integrity superblock is always located on the
data device, the incorrectly used detached header device here.
* Add ZEROOUT IOCTL support for crypt_wipe API call.
For block devices, we can use optimized in-kernel BLKZEROOUT ioctl.
* VERITY: set loopback sector size according to dm-verity block sizes.
Verity block size has the same limits, so we can optimize the loop
device to increase performance.
* Other Documentation and man page improvements:
* Update LUKS2 on-disk format description.
* Add per-keyslot LUKS2 options to the man page.
Some options were missing for LUKS2 luksAddKey and luksChangeKey.
* Fix cryptsetup manpage to use PBKDF consistently.
* Add compile info to README. This information was lost when we removed
the default automake INSTALL file.
* Use volume key consistently in FAQ and man pages.
* Use markdown version of FAQ directly for installation.
* Clarify graceful reencryption interruption.
Currently, it can be interrupted by both SIGINT and SIGTERM signals.
* Add new mailing list info.
* Mention non-cryptographic xxhash64 hash for integrity protection.
* veritysetup: dump device sizes.
Calculating device sizes for verity devices is a little bit tricky.
Data, hash, and FEC can share devices or be separate devices.
Now dump command prints used device sizes, but it requires that
the user specifies all values that are not stored in superblock
(like FEC device and FEC roots).
* Fix check for argp_usage in configure if argp-standalone lib is used.
* Add constant time memcmp and hexa print implementation and use it for
cryptographic keys handling.
* Display progress when wiping the end of the resized device.
* LUKS2 token: prefer token PIN query before passphrase in some cases.
When a user provides --token-type or specific --token-id, a token PIN
query is preferred to a passphrase query.
* LUKS2 token: allow tokens to be replaced with --token-replace option
for cryptsetup token command.
* LUKS2 token: do not continue operation when interrupted in PIN prompt.
* Add --progress-json parameter to utilities.
Progress data can now be printed out in JSON format suitable for
machine processing.
* Embedded Argon2 PBKDF: optimize and simplify thread exit.
* Avoid using SHA1 in tests and fix new enforcements introduced in FIPS
provider for OpenSSL3 (like minimal parameters for PBKDF2).
* Use custom UTF conversion and avoid linking to iconv as a dependency.
* Reimplement BASE64 with simplified code instead of coreutils version.
* Fix regression when warning messages were not displayed
if some kernel feature is not supported (2.4.2).
* Add support for --key-slot option in luksResume action.
Libcryptsetup API extensions and changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Properly define uint32_t constants in API.
This is not a real change, but it avoids strict compiler warnings.
* crypt_resume_by_token_pin() - Resume crypt device using LUKS2 token.
* crypt_get_label() - Get the label of the LUKS2 device.
* crypt_get_subsystem() - Get the subsystem label of the LUKS2 device.
* Make CRYPT_WIPE_ENCRYPTED_ZERO crypt_wipe() option obsolete.
It was never implemented (the idea was to speed up wipe), but with
the recent RNG performance changes, it makes no longer sense.
* Add struct crypt_params_reencrypt changes related to decryption.
* Improve crypt_reencrypt_status() return values.
Empty or any non-LUKS types now returns CRYPT_REENCRYPT_INVALID status.
For LUKS1 devices, it returns CRYPT_REENCRYPT_NONE.

236
docs/v2.6.0-ReleaseNotes Normal file
View File

@@ -0,0 +1,236 @@
Cryptsetup 2.6.0 Release Notes
==============================
Stable release with new features and bug fixes.
Changes since version 2.5.0
~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Introduce support for handling macOS FileVault2 devices (FVAULT2).
Cryptsetup now supports the mapping of FileVault2 full-disk encryption
by Apple for the macOS operating system using a native Linux kernel.
You can open an existing USB FileVault portable device and (with
the hfsplus filesystem driver) access the native data read/write.
Cryptsetup supports only (legacy) FileVault2 based on Core Storage
and HFS+ filesystem (introduced in MacOS X 10.7 Lion).
It does NOT support the new version of FileVault based on the APFS
filesystem used in recent macOS versions.
Header formatting and changes are not supported; cryptsetup never
changes the metadata on the device.
FVAULT2 extension requires kernel userspace crypto API and kernel
driver for HFS+ (hfsplus) filesystem (available on most systems today).
Example of using FileVault2 formatted USB device:
A typical encrypted device contains three partitions; the FileVault
encrypted partition is here sda2:
$ lsblk -o NAME,FSTYPE,LABEL /dev/sda
NAME FSTYPE LABEL
sda
|-sda1 vfat EFI
|-sda2
`-sda3 hfsplus Boot OS X
Note: blkid does not recognize FileVault2 format yet.
To dump metadata information about the device, you can use
the fvault2Dump command:
$ cryptsetup fvault2Dump /dev/sda2
Header information for FVAULT2 device /dev/sda2.
Physical volume UUID: 6f353c05-daae-4e76-a0ee-6a9569a22d81
Family UUID: f82cceb0-a788-4815-945a-53d57fcd55a8
Logical volume offset: 67108864 [bytes]
Logical volume size: 3288334336 [bytes]
Cipher: aes
Cipher mode: xts-plain64
PBKDF2 iterations: 97962
PBKDF2 salt: 173a4ec7447662ec79ca7a47df6c2a01
To activate the device, use open --type fvault2 option:
$ cryptsetup open --type fvault2 /dev/sda2 test
Enter passphrase for /dev/sda2: ...
And check the status of the active device:
$ cryptsetup status test
/dev/mapper/test is active.
type: FVAULT2
cipher: aes-xts-plain64
keysize: 256 bits
key location: dm-crypt
device: /dev/sda2
sector size: 512
offset: 131072 sectors
size: 6422528 sectors
mode: read/write
Now, if the kernel contains hfsplus filesystem driver, you can mount
decrypted content:
$ mount /dev/mapper/test /mnt/test
For more info about implementation, please refer to the master thesis
by Pavel Tobias, which was the source for this extension.
https://is.muni.cz/th/p0aok/?lang=en
* libcryptsetup: no longer use global memory locking through mlockall()
For many years, libcryptsetup locked all memory (including dependent
library address space) to prevent swapping sensitive content outside
of RAM.
This strategy no longer works as the locking of basic libraries exceeds
the memory locking limit if running as a non-root user.
Libcryptsetup now locks only memory ranges containing sensitive
material (keys) through crypt_safe_alloc() calls.
This change solves many reported mysterious problems of unexpected
failures. If the initial lock was still under the limit and succeeded,
some following memory allocation could fail later as it exceeded
the locking limit. If the initial locking fails, memory locking
was quietly ignored completely.
The whole crypt_memory_lock() API call is deprecated; it no longer
calls memlockall().
* libcryptsetup: process priority is increased only for key derivation
(PBKDF) calls.
Increasing priority was tight to memory locking and works only if
running under superuser.
Only PBKDF calls and benchmarking now increase the process priority.
* Add new LUKS keyslot context handling functions and API.
In practice, the luksAddKey action does two operations.
It unlocks the existing device volume key and stores the unlocked
volume key in a new keyslot.
Previously the options were limited to key files and passphrases.
Newly available methods (keyslot contexts) are passphrase, keyfile,
key (binary representation), and LUKS2 token.
To unlock a keyslot user may:
- provide existing passphrase via interactive prompt (default method)
- use --key-file option to provide a file with a valid passphrase
- provide volume key directly via --volume-key-file
- unlock keyslot via all available LUKS2 tokens by --token-only
- unlock keyslot via specific token with --token-id
- unlock keyslot via specific token type by --token-type
To provide the passphrase for a new keyslot, a user may:
- provide existing passphrase via interactive prompt (default method)
- use --new-keyfile to read the passphrase from the file
- use --new-token-id to select LUKS2 token to get passphrase
for new keyslot. The new keyslot is assigned to the selected token
id if the operation is successful.
* The volume key may now be extracted using a passphrase, keyfile, or
token. For LUKS devices, it also returns the volume key after
a successful crypt_format call.
* Fix --disable-luks2-reencryption configuration option.
* cryptsetup: Print a better error message and warning if the format
produces an image without space available for data.
Activation now fails early with a more descriptive message.
* Print error if anti-forensic LUKS2 hash setting is not available.
If the specified hash was not available, activation quietly failed.
* Fix internal crypt segment compare routine if the user
specified cipher in kernel format (capi: prefix).
* cryptsetup: Add token unassign action.
This action allows removing token binding on specific keyslot.
* veritysetup: add support for --use-tasklets option.
This option sets try_verify_in_tasklet kernel dm-verity option
(available since Linux kernel 6.0) to allow some performance
improvement on specific systems.
* Provide pkgconfig Require.private settings.
While we do not completely provide static build on udev systems,
it helps produce statically linked binaries in certain situations.
* Always update automake library files if autogen.sh is run.
For several releases, we distributed older automake scripts by mistake.
* reencryption: Fix user defined moved segment size in LUKS2 decryption.
The --hotzone-size argument was ignored in cases where the actual data
size was less than the original LUKS2 data offset.
* Delegate FIPS mode detection to configured crypto backend.
System FIPS mode check no longer depends on /etc/system-fips file.
* tests: externally provided systemd plugin is now optionally compiled
from systemd git and tested with cryptsetup
* tests: initial integration to OSS-fuzz project with basic crypt_load()
test for LUKS2 and JSON mutated fuzzing.
For more info, see README in tests/fuzz directory.
* Update documentation, including FAQ and man pages.
Libcryptsetup API extensions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The libcryptsetup API is backward compatible with existing symbols.
New symbols:
crypt_keyslot_context_init_by_passphrase
crypt_keyslot_context_init_by_keyfile
crypt_keyslot_context_init_by_token
crypt_keyslot_context_init_by_volume_key
crypt_keyslot_context_get_error
crypt_keyslot_context_set_pin
crypt_keyslot_context_get_type
crypt_keyslot_context_free
crypt_keyslot_add_by_keyslot_context
crypt_volume_key_get_by_keyslot_context
New defines:
CRYPT_FVAULT2 "FVAULT2" (FileVault2 compatible mode)
Keyslot context types:
CRYPT_KC_TYPE_PASSPHRASE
CRYPT_KC_TYPE_KEYFILE
CRYPT_KC_TYPE_TOKEN
CRYPT_KC_TYPE_KEY
CRYPT_ACTIVATE_TASKLETS (dm-verity: use tasklets activation flag)
WARNING!
~~~~~~~~
The next version of cryptsetup will change the encryption mode and key
derivation option for the PLAIN format.
This change will cause backward incompatibility.
For this reason, the user will have to specify the exact parameters
for cipher, key size, and key derivation parameters for plain format.
The default encryption mode will be AES-XTS with 512bit key (AES-256).
The CBC mode is no longer considered the best default, as it allows easy
bit-flipped ciphertext modification attacks and performance problems.
For the passphrase hashing in plain mode, the encryption key is directly
derived through iterative hashing from a user-provided passphrase
(except a keyfile that is not hashed).
The default hash is RIPEMD160, which is no longer the best default
option. The exact change will be yet discussed but should include
the possibility of using a password-based key derivation function
instead of iterative hashing.

50
docs/v2.6.1-ReleaseNotes Normal file
View File

@@ -0,0 +1,50 @@
Cryptsetup 2.6.1 Release Notes
==============================
Stable bug-fix release with minor extensions.
All users of cryptsetup 2.6.0 should upgrade to this version.
Changes since version 2.6.0
~~~~~~~~~~~~~~~~~~~~~~~~~~~
* bitlk: Fixes for BitLocker-compatible on-disk metadata parser
(found by new cryptsetup OSS-Fuzz fuzzers).
- Fix a possible memory leak if the metadata contains more than
one description field.
- Harden parsing of metadata entries for key and description entries.
- Fix broken metadata parsing that can cause a crash or out of memory.
* Fix possible iteration overflow in OpenSSL2 PBKDF2 crypto backend.
OpenSSL2 uses a signed integer for PBKDF2 iteration count.
As cryptsetup uses an unsigned value, this can lead to overflow and
a decrease in the actual iteration count.
This situation can happen only if the user specifies
--pbkdf-force-iterations option.
OpenSSL3 (and other supported crypto backends) are not affected.
* Fix compilation for new ISO C standards (gcc with -std=c11 and higher).
* fvault2: Fix compilation with very old uuid.h.
* verity: Fix possible hash offset setting overflow.
* bitlk: Fix use of startup BEK key on big-endian platforms.
* Fix compilation with latest musl library.
Recent musl no longer implements lseek64() in some configurations.
Use lseek() as 64-bit offset is mandatory for cryptsetup.
* Do not initiate encryption (reencryption command) when the header and
data devices are the same.
If data device reduction is not requsted, this leads to data corruption
since LUKS metadata was written over the data device.
* Fix possible memory leak if crypt_load() fails.
* Always use passphrases with a minimal 8 chars length for benchmarking.
Some enterprise distributions decided to set an unconditional check
for PBKDF2 password length when running in FIPS mode.
This questionable change led to unexpected failures during LUKS format
and keyslot operations, where short passwords were used for
benchmarking PBKDF2 speed.
PBKDF2 benchmark calculations should not be affected by this change.

437
docs/v2.7.0-ReleaseNotes Normal file
View File

@@ -0,0 +1,437 @@
Cryptsetup 2.7.0 Release Notes
==============================
Stable release with new features and bug fixes.
Changes since version 2.6.1
~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Introduce support for hardware OPAL disk encryption.
Some SATA and NVMe devices support hardware encryption through OPAL2
TCG interface (SEDs - self-encrypting drives). Using hardware disk
encryption is controversial as you must trust proprietary hardware.
On the other side, using both software and hardware encryption
layers increases the security margin by adding an additional layer
of protection. There is usually no performance drop if OPAL encryption
is used (the drive always operates with full throughput), and it does
not add any utilization to the main CPU.
LUKS2 now supports hardware encryption through the Linux kernel
SED OPAL interface (CONFIG_BLK_SED_OPAL Linux kernel option must be
enabled). Cryptsetup OPAL is never enabled by default; you have to use
luksFormat parameters to use it. OPAL support can be disabled during
the build phase with --disable-hw-opal configure option.
LUKS2 OPAL encryption is configured the same way as software encryption
- it stores metadata in the LUKS2 header and activates encryption for
the data area on the disk (configured OPAL locking range).
LUKS2 header metadata must always be visible (thus not encrypted).
The key stored in LUKS2 keyslots contains two parts - volume key
for software (dm-crypt) encryption and unlocking key for OPAL.
OPAL unlocking key is independent of the dm-crypt volume key and is
always 256 bits long. Cryptsetup does not support full drive OPAL
encryption; only a specific locking range is always used.
If the OPAL device is in its initial factory state (after factory
reset), cryptsetup needs to configure the OPAL admin user and password.
If the OPAL admin user is already set, the OPAL password must be
provided during luksFormat.
The provided password is needed only to configure or reset the OPAL
locking range; LUKS device activation requires LUKS passphrase only.
LUKS passphrase should be different from OPAL password (OPAL admin user
is configured inside OPAL hardware while LUKS unlocking passphrase
unlocks LUKS keyslot).
OPAL encryption can be used in combination with software (dm-crypt)
encryption (--hw-opal option) or without the software layer
(--hw-opal-only option).
You can see the configured segment parameters in the luksDump command.
LUKS2 devices with OPAL segments set a new requirement flag in
the LUKS2 header to prevent older cryptsetup metadata manipulation.
Do not use hardware-only encryption if you do not fully trust your
hardware vendor.
Compatibility notes:
- Linux kernel SED interface does NOT work through USB external
adapters due to the missing compatibility layer in Linux USB storage
drivers (even if USB hardware itself can support OPAL commands).
- other TCG security subsystems like Ruby or Pyrite are not
supported. Note that many drives support only Pyrite subsystem that
does NOT encrypt data (it provides only authentication).
- compatibility among OPAL-enabled drives is often very problematic,
specifically for older drives. Many drives have bugs in the firmware
that make the Linux kernel interface unusable.
- if you forget the OPAL admin password, the only way to recover is
the full drive factory reset through the PSID key (usually printed
on the drive itself) that wipes all data on the drive (not only the
LUKS area).
- cryptsetup reencryption is not supported for LUKS2 OPAL-enabled
devices
- most OPAL drives use AES-XTS cipher mode (older drives can use
AES-CBC). This information is not available through kernel SED API.
- locked OPAL locking ranges return IO errors while reading; this
can produce a lot of scary messages in the log if some tools (like
blkid) try to read the locked area.
Examples:
* Formatting the drive
Use --hw-opal with luksFormat (or --hw-opal-only for hardware only
encryption):
# cryptsetup luksFormat --hw-opal <device>
Enter passphrase for <device>: ***
Enter OPAL Admin password: ***
* Check configuration with luksDump.
Note "hw-opal-crypt" segment that uses both dm-crypt and OPAL
encryption - keyslot stores 768 bits key (512 sw + 256 bits OPAL key).
# cryptsetup luksDump <device>
LUKS header information
Version: 2
...
Data segments:
0: hw-opal-crypt
offset: 16777216 [bytes]
length: ... [bytes]
cipher: aes-xts-plain64
sector: 512 [bytes]
HW OPAL encryption:
OPAL segment number: 1
OPAL key: 256 bits
OPAL segment length: ... [bytes]
Keyslots:
0: luks2
Key: 768 bits
...
For devices with OPAL encryption ONLY (only 256 bits OPAL unlocking
key is stored):
LUKS header information
Version: 2
...
Data segments:
0: hw-opal
offset: 16777216 [bytes]
length: ... [bytes]
cipher: (no SW encryption)
HW OPAL encryption:
OPAL segment number: 1
OPAL key: 256 bits
OPAL segment length: ... [bytes]
Keyslots:
0: luks2
Key: 256 bits
...
* Activation and deactivation (open, close, luksSuspend, luksResume)
with OPAL works the same as for the LUKS2 device.
* Erase LUKS metadata (keyslots) and remove OPAL locking range:
# cryptsetup luksErase <device>
Enter OPAL Admin password: ***
The LUKS header is destroyed (unlike in normal LUKS luksErase) as
data are no longer accessible even with previous volume key knowledge.
* Factory reset OPAL drive (if you do not know the Admin password).
You need the PSID (physical presence security ID), which is usually
printed on the device label. Note this will reset the device to
factory state, erasing all data on it (not only LUKS).
# cryptsetup luksErase --hw-opal-factory-reset <device>
Enter OPAL PSID: ***
* plain mode: Set default cipher to aes-xts-plain64 and password hashing
to sha256.
NOTE: this is a backward incompatible change for plain mode (if you
rely on defaults). It is not relevant for LUKS devices.
The default plain encryption mode was CBC for a long time, with many
performance problems. Using XTS mode aligns it with LUKS defaults.
The hash algorithm for plain mode was ripemd160, which is considered
deprecated, so the new default is sha256.
The default key size remains 256 bits (it means using AES-128 as XTS
requires two keys).
Always specify cipher, hash, and key size for plain mode (or even
better, use LUKS as it stores all options in its metadata on disk).
As we need to upgrade algorithms from time to time because of security
reasons, cryptsetup now warns users to specify these options explicitly
in the open cryptsetup command if plain mode is used.
Cryptsetup does not block using any legacy encryption type; just it
must be specified explicitly on the cryptsetup command line.
You can configure these defaults during build time if you need to
enforce backward compatibility.
To get the backward-compatible setting, use:
--with-plain-hash=ripemd160 --with-plain-cipher=aes
--with-plain-mode=cbc-essiv:sha256
Compiled-in defaults are visible in cryptsetup --help output.
* Allow activation (open), luksResume, and luksAddKey to use the volume
key stored in a keyring.
* Allow to store volume key to a user-specified keyring in open and
luksResume commands.
These options are intended to be used for integration with other
systems for automation.
Users can now use the volume key (not passphrase) stored in arbitrary
kernel keyring and directly use it in particular cryptsetup commands
with --volume-key-keyring option. The keyring can use various policies
(set outside of the cryptsetup scope, for example, by keyctl).
The --volume-key-keyring option takes a key description in
keyctl-compatible syntax and can either be a numeric key ID or
a string name in the format [%<key type>:]<key name>.
The default key type is "user".
To store the volume key in a keyring, you can use cryptsetup with
--link-vk-to-keyring option that is available for open and luksResume
cryptsetup command. The option argument has a more complex format:
<keyring_description>::<key_description>.
The <keyring_description> contains the existing kernel keyring
description (numeric id or keyctl format). The <keyring_description>
may be optionally prefixed with "%:" or "%keyring:". The string "::" is
a delimiter that separates keyring and key descriptions.
The <key_description> has the same syntax as used in the
--volume-key-keyring option.
Example:
Open the device and store the volume key to the keyring:
# cryptsetup open <device> --link-vk-to-keyring "@s::%user:testkey" tst
Add keyslot using the stored key in a keyring:
# cryptsetup luksAddKey <device> --volume-key-keyring "%user:testkey"
* Do not flush IO operations if resize grows the device.
This can help performance in specific cases where the encrypted device
is extended automatically while running many IO operations.
* Use only half of detected free memory for Argon2 PBKDF on systems
without swap (for LUKS2 new keyslot or format operations).
This should avoid out-of-memory crashes on low-memory systems without
swap. The benchmark for memory-hard KDF during format is tricky, and
it seems that relying on the maximum half of physical memory is not
enough; relying on free memory should bring the needed security margin
while still using Argon2.
There is no change for systems with active swap.
Note, for very-low memory-constrained systems, a user should avoid
memory-hard PBKDF completely (manually select legacy PBKDF2 instead
of Argon2); cryptsetup does not change PBKDF automatically.
* Add the possibility to specify a directory for external LUKS2 token
handlers (plugins).
Use --external-tokens-path parameter in cryptsetup or
crypt_token_set_external_path API call. The parameter is required to be
an absolute path, and it is set per process context. This parameter is
intended mainly for testing and developing new tokens.
* Do not allow reencryption/decryption on LUKS2 devices with
authenticated encryption or hardware (OPAL) encryption.
The operation fails later anyway; cryptsetup now detects incompatible
parameters early.
* Do not fail LUKS format if the operation was interrupted on subsequent
device wipe.
Device wipe (used with authenticated encryption) is an optional
operation and can be interrupted; not yet wiped part of the device will
only report integrity errors (until overwritten with new data).
* Fix the LUKS2 keyslot option to be used while activating the device
by a token.
It can also be used to check if a specific token (--token-id) can
unlock a specific keyslot (--key-slot option) when --test-passphrase
option is specified.
* Properly report if the dm-verity device cannot be activated due to
the inability to verify the signed root hash (ENOKEY).
* Fix to check passphrase for selected keyslot only when adding
new keyslot.
If the user specifies the exact keyslot to unlock, cryptsetup no longer
checks other keyslots.
* Fix to not wipe the keyslot area before in-place overwrite.
If the LUKS2 keyslot area has to be overwritten (due to lack of free
space for keyslot swap), cryptsetup does not wipe the affected area as
the first step (it will be overwritten later anyway).
Previously, there was an unnecessary risk of losing the keyslot data
if the code crashed before adding the new keyslot.
If there is enough space in the keyslot area, cryptsetup never
overwrites the older keyslot before the new one is written correctly
(even if the keyslot number remains the same).
* bitlk: Fix segfaults when attempting to verify the volume key.
Also, clarify that verifying the volume key is impossible without
providing a passphrase or recovery key.
* Add --disable-blkid command line option to avoid blkid device check.
* Add support for the meson build system.
All basic operations are supported (compile, test, and dist) with some
minor exceptions; please see the meson manual for more info.
The Meson build system will completely replace autotools in some future
major release. Both autotools and meson build systems are supported,
and the release archive is built with autotools.
* Fix wipe operation that overwrites the whole device if used for LUKS2
header with no keyslot area.
Formatting a LUKS2 device with no defined keyslots area is a very
specific operation, and the code now properly recognizes such
configuration.
* Fix luksErase to work with detached LUKS header.
* Disallow the use of internal kernel 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 the 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 directly in the LUKS
header; unfortunately, the code allowed it until now.
Devices with CAPI specification in metadata can no longer be activated;
header repair is required.
CAPI specification could allow attackers to change the cipher
specification to enforce loading some specific kernel crypto driver
(for example, load driver with known side-channel issues).
This can be problematic, specifically in a cloud environment
(modifying LUKS2 metadata in container image).
Thanks to Jan Wichelmann, Luca Wilke, and Thomas Eisenbarth from
University of Luebeck for noticing the problems with this code.
* Fix reencryption to fail early for unknown cipher.
* tcrypt: Support new Blake2 hash for VeraCrypt.
VeraCrypt introduces support for Blake2 PRF for PBKDF2; also support it
in cryptsetup compatible tcrypt format.
* tcrypt: use hash values as substring for limiting KDF check.
This allows the user to specify --hash sha or --hash blake2 to limit
the KDF scan without the need to specify the full algorithm name
(similar to cipher where we already use substring match).
* 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.
It can be now used also for LUKS keyslot encryption.
* Do not decrease PBKDF parameters if the user forces them.
If a user explicitly specifies PBKDF parameters (like iterations,
used memory, or threads), do not limit them, even if it can cause
resource exhaustion.
The force options were mostly used for decreasing parameters, but it
should work even opposite - despite the fact it can mean an
out-of-memory crash.
The only limits are hard limits per the PBKDF algorithm.
* Support OpenSSL 3.2 Argon2 implementation.
Argon2 is now available directly in OpenSSL, so the code no longer
needs to use libargon implementation.
Configure script should detect this automatically.
* Add support for Argon2 from libgcrypt
(requires yet unreleased gcrypt 1.11).
Argon2 has been available since version 1.10, but we need version 1.11,
which will allow empty passwords.
* Used Argon2 PBKDF implementation is now reported in debug mode
in the cryptographic backend version. For native support in
OpenSSL 3.2 or libgcrypt 1.11, "argon2" is displayed.
If libargon2 is used, "cryptsetup libargon2" (for embedded
library) or "external libargon2" is displayed.
* Link only libcrypto from OpenSSL.
This reduces dependencies as other OpenSSL libraries are not needed.
* Disable reencryption for Direct-Access (DAX) devices.
Linux kernel device-mapper cannot stack DAX/non-DAX devices in
the mapping table, so online reencryption cannot work. Detect DAX
devices and warn users during LUKS format. Also, DAX or persistent
memory devices do not provide atomic sector updates; any single
modification can corrupt the whole encryption block.
* Print a warning message if the device is not aligned to sector size.
If a partition is resized after format, activation could fail when
the device is not multiple of a sector size. Print at least a warning
here, as the activation error message is visible only in kernel syslog.
* Fix sector size and integrity fields display for non-LUKS2 crypt
devices for the status command.
* Fix suspend for LUKS2 with authenticated encryption (also suspend
dm-integrity device underneath).
This should stop the dm-integrity device from issuing journal updates
and possibly corrupt data if the user also tries to modify the
underlying device.
* Update keyring and locking documentation and LUKS2 specification
for OPAL2 support.
Libcryptsetup API extensions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The libcryptsetup API is backward compatible for all existing symbols.
New symbols:
crypt_activate_by_keyslot_context
crypt_format_luks2_opal
crypt_get_hw_encryption_type
crypt_get_hw_encryption_key_size
crypt_keyslot_context_init_by_keyring
crypt_keyslot_context_init_by_vk_in_keyring
crypt_keyslot_context_init_by_signed_key
crypt_resume_by_keyslot_context
crypt_token_set_external_path
crypt_set_keyring_to_link
crypt_wipe_hw_opal
New defines (hw encryption status):
CRYPT_SW_ONLY
CRYPT_OPAL_HW_ONLY
CRYPT_SW_AND_OPAL_HW
New keyslot context types:
CRYPT_KC_TYPE_KEYRING
CRYPT_KC_TYPE_VK_KEYRING
CRYPT_KC_TYPE_SIGNED_KEY
New requirement flag:
CRYPT_REQUIREMENT_OPAL

30
docs/v2.7.1-ReleaseNotes Normal file
View File

@@ -0,0 +1,30 @@
Cryptsetup 2.7.1 Release Notes
==============================
Stable bug-fix release with minor extensions.
All users of cryptsetup 2.7.0 should upgrade to this version.
Changes since version 2.7.0
~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Fix interrupted LUKS1 decryption resume.
With the replacement of the cryptsetup-reencrypt tool by the cryptsetup
reencrypt command, resuming the interrupted LUKS1 decryption operation
could fail. LUKS2 was not affected.
* Allow --link-vk-to-keyring with --test-passphrase option.
This option allows uploading the volume key in a user-specified kernel
keyring without activating the device.
* Fix crash when --active-name was used in decryption initialization.
* Updates and changes to man pages, including indentation, sorting options
alphabetically, fixing mistakes in crypt_set_keyring_to_link, and fixing
some typos.
* Fix compilation with libargon2 when --disable-internal-argon2 was used.
* Do not require installed argon2.h header and never compile internal
libargon2 code if the crypto library directly supports Argon2.
* Fixes to regression tests to support older Linux distributions.

31
docs/v2.7.2-ReleaseNotes Normal file
View File

@@ -0,0 +1,31 @@
Cryptsetup 2.7.2 Release Notes
==============================
Stable bug-fix release.
All users of cryptsetup 2.7 should upgrade to this version.
Changes since version 2.7.1
~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Fix activation of OPAL-only encrypted LUKS device with tokens.
The issue was caused by an invalid volume key check (assert)
that is impossible without software encryption.
* Fix formatting of OPAL devices with 4096-byte sector size.
* Fix incorrect OPAL locking range alignment calculation if used
over an unaligned device partition.
* Add --hw-opal-factory-reset option description to the manual page.
* Do not check the passphrase quality for OPAL Admin PIN,
as this passphrase already exists.
* Update license for FAQ document to CC BY-SA 4.0.
NOTE: Please note that with OPAL-only (--hw-opal-only) encryption,
the configured OPAL administrator PIN (passphrase) allows unlocking
all configured locking ranges without LUKS keyslot decryption
(without knowledge of LUKS passphrase).
Because of many observed problems with compatibility, cryptsetup
currently DOES NOT use OPAL single-user mode, which would allow such
decoupling of OPAL admin PIN access.

114
docs/v2.7.3-ReleaseNotes Normal file
View File

@@ -0,0 +1,114 @@
Cryptsetup 2.7.3 Release Notes
==============================
Stable bug-fix release with security fixes.
All users of cryptsetup 2.7 must upgrade to this version.
Changes since version 2.7.2
~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Do not allow formatting LUKS2 with Opal SED (hardware encryption)
if the reported logical sector size for the block device and Opal
encryption logical block differs.
Such a configuration can lead to a partially encrypted Opal locking
range or data destruction following the expected locking range.
Some NVMe drives support multiple LBAF profiles (typically supporting
512-byte and 4096-byte sector size). Some broken Opal NVMe firmware can
report bogus encryption size that disagrees with real used sector size.
This usually happens after low-level NVMe reformatting (LBAF profile
change with nvme utility) to different sector size.
Moreover, some firmware versions do not properly reset this even after
explicit PSID revert.
Cryptsetup calculates the Opal locking range using the reported block
size in Opal geometry ioctl. Unfortunately, the broken firmware drive
internally uses the logical block size of the block device, which can
differ. This can lead to two possible situations:
- Opal reports a smaller block size (512-byte) while the drive uses
a 4096-byte sector. The configured locking range is then much larger,
destroying data following the expected locking range setting.
- Opal reports a larger block size (4096-byte) while the drive uses
a 512-byte sector. The configured locking range is then much smaller,
leaving the remaining space in the locking range unencrypted (violating
the confidentiality of data).
Cryptsetup now detects this discrepancy and disallows LUKS2 format with
Opal hardware encryption in such a case.
For already formatted devices, you will see this warning:
"Bogus OPAL logical block size differs from device block size."
If you also used software encryption (dm-crypt over Opal), data will
still be fully encrypted with software dm-crypt.
With hw-only encryption, your configuration is probably already broken
(insecure or accessing data beyond the assigned area).
Note that this is caused by bad firmware (seen with multiple vendors),
and the problem was reported, at least for drives we have access to.
* Fixes to wiping LUKS2 headers after Opal locking area erase.
As the hardware locking range is destroyed (cryptsetup erase command),
the LUKS2 header is no longer usable and was partially wiped.
Now the code fully wipes also the secondary header, as the previous
code wiped only the primary LUKS area.
Note that this is an exception, as the normal erase command wipes only
the keyslots, keeping the LUKS2 header in place. With Opal encryption,
the data segment is no longer valid, so the whole LUKS2 header is no
longer usable.
* Mention the need for possible PSID revert before Opal format for some
drives (man page).
* Fix Bitlocker-compatible code to ignore newly seen metadata entries.
Recent Windows OS versions started to include new (undocumented)
metadata entries in Bitlocker. These entries are now quietly ignored,
allowing Bitlocker images to open with cryptsetup again.
* Fix interactive query retry if LUKS2 unbound keyslot is present.
If an unbound keyslot is present, the password query retry count is
now properly applied.
* Detect unsupported zoned devices for LUKS header devices.
Zoned devices cannot be written with direct-io and used for LUKS header
logic in general. Code now rejects placing the LUKS header on a zoned
device, while you can still create a detached header and use a zoned
device for encrypted data.
* Allow "capi" cipher format for benchmark command and fix parsing
of plain IV in "capi" format.
Some ciphers can be specified only in Linux kernel crypto notation
(in short, "capi"). Code now allows this format also for benchmark,
for example, "benchmark -c capi:xts\(aes\)-plain64"
(that is equivalent to -c aes-xts-plain64).
* Add support for HCTR2 encryption mode.
The HCTR2 encryption mode was added to the Linux kernel for fscrypt,
but as it is a length-preserving mode (with sector tweak), it can be
easily used for disk encryption, too.
The mode has the same property as wide modes (any change is propagated
to the whole sector instead of only one block as in XTS mode).
As it needs a larger initialization vector (32 bytes), we need to add
an exception in the userspace format code.
You can now use --cipher aes-hctr2-plain64 for the format operation.
* Source code now uses SPDX license identifiers instead of full
license preambles.
* Fix missing includes for cryptographic backend that could cause
compilation errors for some systems.
* Fix tests to work correctly in FIPS mode with recent OpenSSL 3.2.
* Fix various (mostly false positive) issues detected by Coverity.

62
docs/v2.7.4-ReleaseNotes Normal file
View File

@@ -0,0 +1,62 @@
Cryptsetup 2.7.4 Release Notes
==============================
Stable bug-fix release.
All users of cryptsetup 2.7 should upgrade to this version.
Changes since version 2.7.3
~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Detect device busy failure for device-mapper table-referenced devices.
Some device-mapper ioctl failures can disappear in libdevmapper,
causing the libcryptsetup wrapper to return an invalid error (EINVAL)
instead of EEXIST or EBUSY. One such case is when there is a device
creation race, and the device-mapper device name is created, but
the following mapping table load fails. This can happen because some
block devices used in table mapping have already been claimed by
another process (the kernel needs exclusive access).
The kernel ioctl properly returns EBUSY; this errno is lost in
libdevmapper (dm_task_get_errno returns 0). It should be fixed by
libdevmapper in the future.
Such behavior was seen in the systemd way of handling dm-verity
devices. With these changes, the code should react for EEXIST and
EBUSY, as another process has already activated the device.
Code calling libcryptsetup also must not check the underlying device
with an exclusive open flag (O_EXCL). Otherwise, it could cause a race
in the kernel device-mapper, resulting in no process succeeding device
activation (see also CRYPT_ACTIVATE_SHARED flag below).
* Fix shared activation for dm-verity devices.
The CRYPT_ACTIVATE_SHARED flag was silently ignored when activating
dm-verity devices. Dm-verity shared activation is generally safe
since all verity devices are read-only.
The shared flag is a way to skip the exclusive access check for the
device, allowing it to create multiple mappings with the same device or
properly handle a racy concurrent activation of devices with the same
name from different processes.
* Add --shared option for veritysetup open action.
The option allows the data device to be used in multiple device-mapper
table mappings (skip exclusive access check) or to allow concurrent
dm-verity device activation of the same device (only one process
succeeds in this case; the other will return EEXIST or EBUSY).
* Do not use exclusive flag for the allocated backing loop files.
Using this flag is an undefined operation for opening an existing file.
The flag should be used only for allocated loop (block) devices.
* Fixes for problems found by static analyzers and Valgrind.
These include fixes for non-default libgcrypt, NSS, and Nettle
cryptographic backends, buffer operations to avoid partial read/write,
and several other workarounds for mostly false positive warnings.
* Fixes to tests and CI scripts.

23
docs/v2.7.5-ReleaseNotes Normal file
View File

@@ -0,0 +1,23 @@
Cryptsetup 2.7.5 Release Notes
==============================
Stable bug-fix release.
All users of cryptsetup 2.7 must upgrade to this version.
Changes since version 2.7.4
~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Fix possible online reencryption data corruption (only in 2.7.x).
In some situations (initializing a suspended device-mapper device),
cryptsetup disabled direct-io device access. This caused unsafe
online reencryption operations that could lead to data corruption.
The code now adds strict checks (and aborts the operation) and
changes direct-io detection code to prevent data corruption.
* Fix a clang compilation error in SSH token plugin.
As clang linker treats missing symbols as errors, the linker phase
for the SSH token failed as the optional cryptsetup_token_buffer_free
was not defined.
* Fix crypto backend initialization in crypt_format_luks2_opal API call.

View File

@@ -0,0 +1,328 @@
Cryptsetup 2.8.0-rc1 Release Notes
==================================
Stable release with new features and bug fixes
All users of cryptsetup 2.7 must upgrade to this version.
Changes since version 2.7.5
~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Introduce support for inline mode (use HW sectors with additional hardware metadata space).
Some enterprise NVMe drives allow formatting sector size with additional metadata space,
for example, sector size 4096 bytes + 64 bytes for metadata.
We hope common firmware will soon support such features in more recent models.
If this metadata space is available (not internally used by a data integrity profile),
it removes the need to use the dm-integrity layer for sector metadata allocation.
This means that the performance bottleneck caused by the dm-integrity journal is eliminated.
Note: such drive must be reformatted with an external nvme tool.
You can check for support (reported as LBA format) by running the command
"nvme id-ns -H <nvme device>" and then you can reformat to the selected profile
(with complete data loss) with "nvme format -l <lbaf>.
This way, you can also reformat NVMe drive to 4096-byte sectors,which is strongly recommended
for encryption performance.
The required device mapper for inline mode was introduced in Linux kernel version 6.11.
The inline mode can be used with the new --integrity-inline option.
For integritysetup, the kernel dm-integrity layer is still used, but it directly maps metadata
to the hardware (eliminating the journal).
For cryptsetup, the dm-integrity layer is eliminated, and only the dm-crypt kernel driver is used.
The libcryptsetup exports a new crypt_format_inline API call.
Examples (underlying device must provide inline HW metadata space):
Use integritysetup format with inline mode with default CRC32 checksums:
# integritysetup format --sector-size 4096 --integrity-inline <device> [--no-wipe]
# integritysetup open <device> test
# integritysetup status test
/dev/mapper/test is active.
type: INTEGRITY
tag size: 4 [bytes]
integrity: crc32c
device: <device>
sector size: 4096 [bytes]
...
inline mode
journal: not active
Use LUKS2 with authenticated encryption (here with AEGIS AEAD cipher):
# cryptsetup luksFormat --integrity-inline --integrity aead --sector-size 4096 \
-c aegis128-random --key-size 128 <device> [--integrity-no-wipe]
# cryptsetup open <device> test
# cryptsetup luksDump <device>
...
Requirements: inline-hw-tags
After format, the inline mode is used automatically, and no special options are needed.
Please check the manual pages for more details about used options.
Note that the LUKS2 authenticated encryption is still an experimental feature.
The inline mode only improves performance by removing the dm-integrity layer.
* Finalize use of keyslot context API.
Keyslot context is a generic abstraction over keyslot manipulation.
It extends many exiting commands by additional functions like tokens in activation, resume,
reencryption and similar commands without introducing new specific API functions.
* Make all keyslot context types fully self-contained.
In the previous version, the caller is responsible for releasing of some allocated memory.
In this version, all memory is allocated internally. The existing keyslot context API function
provides backward compatibility through versioned symbols.
* Add --key-description and --new-key-description cryptsetup options.
These can be used for the specification of the keyring with passphrase retrieval in the open,
resize, luksResume, luksFormat, luksAddKey and luksDump.
* Support more precise keyslot selection in reencryption initialization.
Reencryption must update stored keys in keyslots, so it needs to unlock all keyslots first.
When no specific keyslot is selected by the --key-slot option, all active keyslots are updated.
Users may narrow down the selection of keyslots by specifying either --token-id, --token-type
or --token-only option. Only keyslots associated with the specific token (--token-id) or
a specific type (--token-type) or any token (--token-only) will be updated.
All other keyslots will be erased after reencryption is finished.
During reencryption, there are two volume keys (old and new).
For very specific use cases, reencryption can also be initialized by providing
volume keys directly by --volume-key-file, --new-volume-key-file, --volume-key-keyring
or --new-volume-key-keyring options. These options allow reencryption of the device with
no active keyslots (these can be added later).
If the --force-no-keyslots option is specified, all active keyslots will be erased after
the reencryption operation is finished.
* Allow reencryption to resume using token and volume keys.
The reencryption can be resumed using tokens (similar to initialization described above).
For very specific use cases, reencryption can be resumed by providing volume keys.
* Cryptsetup repair command now tries to check LUKS keyslot areas for corruption.
A keyslot binary area contains an encrypted volume key diffused to a larger area by
the anti-forensic splitter. If this area is corrupted, the keyslot can no longer be unlocked,
even with the correct password.
Active keyslot area should look like random data, so some specific corruption can be detected
by randomness analysis.
Cryptsetup repair command now tries to analyze the area expecting a uniform distribution
of bytes in 4096-byte blocks. If a problem is detected, it tries to localize corruption
in a smaller block (using the expected bit count).
Both tests are based on the Chi-squared statistical test.
This analysis can replace the external keyslot check program and usually is more sensitive.
However, it cannot detect all corruptions and can produce false positives.
Please use it as a hint when your password is no longer accepted, and you suspect
header corruption. This is the example output of the analysis:
# cryptsetup repair <device>
Keyslot 2 binary data could be corrupted.
Suspected offset: 0x88000
You can use hexdump -v -C -n 128 -s <offset_0xXXXX> <device> to inspect the data.
The test does not modify the header. A keyslot corruption cannot be repaired.
You have to use a backup header.
* Opal2 SED: PSID keyfile is now expected to be 32 alphanumeric characters.
If the keyfile size is not explicitly set, it uses only first 32 bytes.
All Opal2 manufacturers seem to use PSID of this length.
* Opal2: Avoid the Erase method and use Secure Erase for locking range.
The Erase method is defined for Single-user mode (SUM) and works on SUM-enabled locking ranges.
As we do not use SUM yet, this always fails and falls back to Secure erase anyway.
* Opal2: Fix some error description (in debug only).
Some Opal error messages were incorrect.
Cryptsetup now use all codes according to TCG specifications.
* Opal2: Do not allow deferred deactivation.
The self-encrypting drive must be locked immediately; deferred deactivation is not supported.
* Allow --reduce-device-size and --device-size combination for reencryption (encrypt) action.
For some very specific cases, this can be used to encrypt only part of the device together
with allocation a new space for the LUKS header.
* Fix the userspace storage backend to support kernel "capi:" cipher specification format.
This avoids unnecessary fallback to the device-mapper instead of the userspace crypto library
in luksFormat. The "capi:" is Linux kernel cryptographic format.
For example, capi:xts(aes)-plain64 is equivalent of aes-xts-plain64.
* Disallow conversion from LUKS2 to LUKS1 if kernel "capi:" cipher specification is used.
LUKS1 never officially supported this cipher specification format.
Such devices cannot be converted to LUKS1 (while existing devices can still be activated).
* Explicitly disallow kernel "capi:" cipher specification format for LUKS2 keyslot encryption.
This specification is intended to be used for data encryption, not for keyslots.
* Do not allow conversion of LUKS2 to LUKS1 if an unbound keyslot is present.
LUKS1 does not support unbound keyslots. Such devices cannot be converted.
* cryptsetup: Adjust the XTS key size for kernel "capi:" cipher specification.
Double key size as there are two keys the same way as for dm-crypt format.
* Remove keyslot warning about possible failure due to low memory.
This check was intended to warn users about possible out-of-memory situations
but produced many false positives.
* Do not limit Argon2 KDF memory cost on systems with more than 4GB of available memory.
The memory cost is intended to be limited only in low-memory situations (like virtual machines
without swap), not on systems with plenty of RAM.
* Properly report out of memory error for cryptographic backends implementing Argon2.
* Avoid KDF2 memory cost overflow on 32-bit platforms.
* Do not use page size as a fallback for device block size.
This check produced wrong values if used on platforms with larger page sizes (64kB)
and specific underlying storage (like ZFS).
* veritysetup: Check hash device size in advance.
If hashes are stored in a file image, allocate the size in advance.
For a block device, check if hashes (Merkle tree) fits the device.
* Print a better error message for unsupported LUKS2 AEAD device resize.
* Optimize LUKS2 metadata writes.
LUKS2 supports several JSON area length configurations. Do not write full metadata
(including padding), as it may generate noticeable overhead with LUKS2.
* veritysetup: support --error-as-corruption option.
The panic/restart_on_error options were introduced in Linux kernel 6.12 and process errors
(like media read error) the same way as data corruption.
Use this flag in combination with --panic-on-corruption or --restart-on-corruption.
* Report all sizes in status and dump command output in the correct units.
Since the support of --sector-size option, the meaning of "sectors" became ambiguous as it
usually means 512-byte sectors (device-mapper unit). Confusion occurs when the sector size
is 4096 bytes while units used for display are 512-byte sectors.
All status commands in tools now display units explicitly to avoid confusion.
For example:
# cryptsetup status test
...
sector size: 4096 [bytes]
offset: 32768 [512-byte units] (134217728 [bytes])
size: 7501443760 [512-byte units] (30725913640960 [bytes])
If you parse the output of status commands, please check your scripts to ensure they work
with the new output properly.
* Add --integrity-key-size option to cryptsetup.
This option can be used to set up non-standard integrity key size (e.g. for HMAC).
It adds a new (optional) JSON "key_size" attribute in the segment.integrity JSON object
(see updated LUKS2 specification). If not set, the code uses selected hash length size.
* Support trusted & encrypted keyrings for plain devices.
* Support plain format resize with a keyring key.
If a plain dm-crypt device references the keyring, cryptsetup now allows resizing.
The user must ensure that the key in the keyring is unchanged since activation.
Otherwise, reloading the key can cause data corruption after an unexpected key change.
* TCRYPT: Clear mapping of system-encrypted partitions.
TrueCrypt/VeraCrypt supports full system encryption (only a partition table is not encrypted)
or system partition encryption (only a system partition is encrypted).
The metadata header then contains the offset and size of the encrypted area.
Cryptsetup needs to know the specific partition offset to calculate encryption parameters.
To properly map a partition, the user must specify a real partition device so cryptsetup
can calculate this offset. As the partition can be an image in a file, cryptsetup now tries
to determine proper parameters and use device size stored in VeraCrypt metadata.
Please see the manual page description (TCRYPT section) for a detailed description.
* TCRYPT: Print all information from the decrypted metadata header in the tcryptDump command.
Print also volume sizes (if present) and flags.
* Always lock the volume key structure in memory.
Some memory for safe allocation was not allocated from locked (unswappable) memory.
Older cryptsetup locked all memory. Selective locking was introduced in version 2.6.0.
* Do not run direct-io read check on block devices.
Block devices always support direct-io.
This check produced unnecessary error with locked Opal2 devices.
* Fix a possible segfault in deferred deactivation.
Thanks Clément Guérin for the report.
* Exclude cipher allocation time from the cryptsetup benchmark.
* Add Mbed-TLS optional crypto backend.
Mbed-TLS is a tiny TLS implementation designed for embedded environments.
The backend can be enabled with the --with-crypto_backend=mbedtls configure option.
* Fix the wrong preprocessor use of #ifdef for config.h processed by Meson.
Cryptsetup supports Autoconf and, optionally, Meson configuration.
Part of the code wrongly used #ifdef instead of #if conditional sections.
This caused problems with Meson-generated config.h.
* Reorganize license files.
The license text files are now in docs/licenses.
The COPYING file in the root directory is the default license.
Libcryptsetup API extensions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The libcryptsetup API is backward compatible with all existing symbols.
Due to the self-contained memory allocation, these symbols have the new version
crypt_keyslot_context_init_by_passphrase;
crypt_keyslot_context_init_by_keyfile;
crypt_keyslot_context_init_by_token;
crypt_keyslot_context_init_by_volume_key;
crypt_keyslot_context_init_by_signed_key;
crypt_keyslot_context_init_by_keyring;
crypt_keyslot_context_init_by_vk_in_keyring;
New symbols:
crypt_format_inline
crypt_get_old_volume_key_size
crypt_reencrypt_init_by_keyslot_context
crypt_safe_memcpy
New defines:
CRYPT_ACTIVATE_HIGH_PRIORITY
CRYPT_ACTIVATE_ERROR_AS_CORRUPTION
CRYPT_ACTIVATE_INLINE_MODE
CRYPT_REENCRYPT_CREATE_NEW_DIGEST
New requirement flag:
CRYPT_REQUIREMENT_INLINE_HW_TAGS

View File

@@ -32,7 +32,8 @@ libcryptsetup_la_LIBADD = \
@LIBARGON2_LIBS@ \
@JSON_C_LIBS@ \
@BLKID_LIBS@ \
$(LTLIBICONV) \
@DL_LIBS@ \
$(LTLIBINTL) \
libcrypto_backend.la \
libutils_io.la
@@ -52,8 +53,6 @@ libcryptsetup_la_SOURCES = \
lib/utils_loop.h \
lib/utils_devpath.c \
lib/utils_wipe.c \
lib/utils_fips.c \
lib/utils_fips.h \
lib/utils_device.c \
lib/utils_keyring.c \
lib/utils_keyring.h \
@@ -68,14 +67,14 @@ libcryptsetup_la_SOURCES = \
lib/volumekey.c \
lib/random.c \
lib/crypt_plain.c \
lib/base64.h \
lib/base64.c \
lib/integrity/integrity.h \
lib/integrity/integrity.c \
lib/loopaes/loopaes.h \
lib/loopaes/loopaes.c \
lib/tcrypt/tcrypt.h \
lib/tcrypt/tcrypt.c \
lib/keyslot_context.h \
lib/keyslot_context.c \
lib/luks1/af.h \
lib/luks1/af.c \
lib/luks1/keyencryption.c \
@@ -98,12 +97,17 @@ libcryptsetup_la_SOURCES = \
lib/luks2/luks2_keyslot_luks2.c \
lib/luks2/luks2_keyslot_reenc.c \
lib/luks2/luks2_reencrypt.c \
lib/luks2/luks2_reencrypt_digest.c \
lib/luks2/luks2_segment.c \
lib/luks2/luks2_token_keyring.c \
lib/luks2/luks2_token.c \
lib/luks2/luks2_internal.h \
lib/luks2/luks2.h \
lib/luks2/hw_opal/hw_opal.c \
lib/luks2/hw_opal/hw_opal.h \
lib/utils_blkid.c \
lib/utils_blkid.h \
lib/bitlk/bitlk.h \
lib/bitlk/bitlk.c
lib/bitlk/bitlk.c \
lib/fvault2/fvault2.h \
lib/fvault2/fvault2.c

View File

@@ -1,605 +0,0 @@
/* base64.c -- Encode binary data using printable characters.
Copyright (C) 1999-2001, 2004-2006, 2009-2019 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <https://www.gnu.org/licenses/>. */
/* Written by Simon Josefsson. Partially adapted from GNU MailUtils
* (mailbox/filter_trans.c, as of 2004-11-28). Improved by review
* from Paul Eggert, Bruno Haible, and Stepan Kasal.
*
* See also RFC 4648 <https://www.ietf.org/rfc/rfc4648.txt>.
*
* Be careful with error checking. Here is how you would typically
* use these functions:
*
* bool ok = base64_decode_alloc (in, inlen, &out, &outlen);
* if (!ok)
* FAIL: input was not valid base64
* if (out == NULL)
* FAIL: memory allocation error
* OK: data in OUT/OUTLEN
*
* size_t outlen = base64_encode_alloc (in, inlen, &out);
* if (out == NULL && outlen == 0 && inlen != 0)
* FAIL: input too long
* if (out == NULL)
* FAIL: memory allocation error
* OK: data in OUT/OUTLEN.
*
*/
#include <config.h>
/* Get prototype. */
#include "base64.h"
/* Get malloc. */
#include <stdlib.h>
/* Get UCHAR_MAX. */
#include <limits.h>
#include <string.h>
/* C89 compliant way to cast 'char' to 'unsigned char'. */
static unsigned char
to_uchar (char ch)
{
return ch;
}
static const char b64c[64] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/* Base64 encode IN array of size INLEN into OUT array. OUT needs
to be of length >= BASE64_LENGTH(INLEN), and INLEN needs to be
a multiple of 3. */
static void
base64_encode_fast (const char *restrict in, size_t inlen, char *restrict out)
{
while (inlen)
{
*out++ = b64c[(to_uchar (in[0]) >> 2) & 0x3f];
*out++ = b64c[((to_uchar (in[0]) << 4) + (to_uchar (in[1]) >> 4)) & 0x3f];
*out++ = b64c[((to_uchar (in[1]) << 2) + (to_uchar (in[2]) >> 6)) & 0x3f];
*out++ = b64c[to_uchar (in[2]) & 0x3f];
inlen -= 3;
in += 3;
}
}
/* Base64 encode IN array of size INLEN into OUT array of size OUTLEN.
If OUTLEN is less than BASE64_LENGTH(INLEN), write as many bytes as
possible. If OUTLEN is larger than BASE64_LENGTH(INLEN), also zero
terminate the output buffer. */
void
base64_encode (const char *restrict in, size_t inlen,
char *restrict out, size_t outlen)
{
/* Note this outlen constraint can be enforced at compile time.
I.E. that the output buffer is exactly large enough to hold
the encoded inlen bytes. The inlen constraints (of corresponding
to outlen, and being a multiple of 3) can change at runtime
at the end of input. However the common case when reading
large inputs is to have both constraints satisfied, so we depend
on both in base_encode_fast(). */
if (outlen % 4 == 0 && inlen == outlen / 4 * 3)
{
base64_encode_fast (in, inlen, out);
return;
}
while (inlen && outlen)
{
*out++ = b64c[(to_uchar (in[0]) >> 2) & 0x3f];
if (!--outlen)
break;
*out++ = b64c[((to_uchar (in[0]) << 4)
+ (--inlen ? to_uchar (in[1]) >> 4 : 0))
& 0x3f];
if (!--outlen)
break;
*out++ =
(inlen
? b64c[((to_uchar (in[1]) << 2)
+ (--inlen ? to_uchar (in[2]) >> 6 : 0))
& 0x3f]
: '=');
if (!--outlen)
break;
*out++ = inlen ? b64c[to_uchar (in[2]) & 0x3f] : '=';
if (!--outlen)
break;
if (inlen)
inlen--;
if (inlen)
in += 3;
}
if (outlen)
*out = '\0';
}
/* Allocate a buffer and store zero terminated base64 encoded data
from array IN of size INLEN, returning BASE64_LENGTH(INLEN), i.e.,
the length of the encoded data, excluding the terminating zero. On
return, the OUT variable will hold a pointer to newly allocated
memory that must be deallocated by the caller. If output string
length would overflow, 0 is returned and OUT is set to NULL. If
memory allocation failed, OUT is set to NULL, and the return value
indicates length of the requested memory block, i.e.,
BASE64_LENGTH(inlen) + 1. */
size_t
base64_encode_alloc (const char *in, size_t inlen, char **out)
{
size_t outlen = 1 + BASE64_LENGTH (inlen);
/* Check for overflow in outlen computation.
*
* If there is no overflow, outlen >= inlen.
*
* If the operation (inlen + 2) overflows then it yields at most +1, so
* outlen is 0.
*
* If the multiplication overflows, we lose at least half of the
* correct value, so the result is < ((inlen + 2) / 3) * 2, which is
* less than (inlen + 2) * 0.66667, which is less than inlen as soon as
* (inlen > 4).
*/
if (inlen > outlen)
{
*out = NULL;
return 0;
}
*out = malloc (outlen);
if (!*out)
return outlen;
base64_encode (in, inlen, *out, outlen);
return outlen - 1;
}
/* With this approach this file works independent of the charset used
(think EBCDIC). However, it does assume that the characters in the
Base64 alphabet (A-Za-z0-9+/) are encoded in 0..255. POSIX
1003.1-2001 require that char and unsigned char are 8-bit
quantities, though, taking care of that problem. But this may be a
potential problem on non-POSIX C99 platforms.
IBM C V6 for AIX mishandles "#define B64(x) ...'x'...", so use "_"
as the formal parameter rather than "x". */
#define B64(_) \
((_) == 'A' ? 0 \
: (_) == 'B' ? 1 \
: (_) == 'C' ? 2 \
: (_) == 'D' ? 3 \
: (_) == 'E' ? 4 \
: (_) == 'F' ? 5 \
: (_) == 'G' ? 6 \
: (_) == 'H' ? 7 \
: (_) == 'I' ? 8 \
: (_) == 'J' ? 9 \
: (_) == 'K' ? 10 \
: (_) == 'L' ? 11 \
: (_) == 'M' ? 12 \
: (_) == 'N' ? 13 \
: (_) == 'O' ? 14 \
: (_) == 'P' ? 15 \
: (_) == 'Q' ? 16 \
: (_) == 'R' ? 17 \
: (_) == 'S' ? 18 \
: (_) == 'T' ? 19 \
: (_) == 'U' ? 20 \
: (_) == 'V' ? 21 \
: (_) == 'W' ? 22 \
: (_) == 'X' ? 23 \
: (_) == 'Y' ? 24 \
: (_) == 'Z' ? 25 \
: (_) == 'a' ? 26 \
: (_) == 'b' ? 27 \
: (_) == 'c' ? 28 \
: (_) == 'd' ? 29 \
: (_) == 'e' ? 30 \
: (_) == 'f' ? 31 \
: (_) == 'g' ? 32 \
: (_) == 'h' ? 33 \
: (_) == 'i' ? 34 \
: (_) == 'j' ? 35 \
: (_) == 'k' ? 36 \
: (_) == 'l' ? 37 \
: (_) == 'm' ? 38 \
: (_) == 'n' ? 39 \
: (_) == 'o' ? 40 \
: (_) == 'p' ? 41 \
: (_) == 'q' ? 42 \
: (_) == 'r' ? 43 \
: (_) == 's' ? 44 \
: (_) == 't' ? 45 \
: (_) == 'u' ? 46 \
: (_) == 'v' ? 47 \
: (_) == 'w' ? 48 \
: (_) == 'x' ? 49 \
: (_) == 'y' ? 50 \
: (_) == 'z' ? 51 \
: (_) == '0' ? 52 \
: (_) == '1' ? 53 \
: (_) == '2' ? 54 \
: (_) == '3' ? 55 \
: (_) == '4' ? 56 \
: (_) == '5' ? 57 \
: (_) == '6' ? 58 \
: (_) == '7' ? 59 \
: (_) == '8' ? 60 \
: (_) == '9' ? 61 \
: (_) == '+' ? 62 \
: (_) == '/' ? 63 \
: -1)
static const signed char b64[0x100] = {
B64 (0), B64 (1), B64 (2), B64 (3),
B64 (4), B64 (5), B64 (6), B64 (7),
B64 (8), B64 (9), B64 (10), B64 (11),
B64 (12), B64 (13), B64 (14), B64 (15),
B64 (16), B64 (17), B64 (18), B64 (19),
B64 (20), B64 (21), B64 (22), B64 (23),
B64 (24), B64 (25), B64 (26), B64 (27),
B64 (28), B64 (29), B64 (30), B64 (31),
B64 (32), B64 (33), B64 (34), B64 (35),
B64 (36), B64 (37), B64 (38), B64 (39),
B64 (40), B64 (41), B64 (42), B64 (43),
B64 (44), B64 (45), B64 (46), B64 (47),
B64 (48), B64 (49), B64 (50), B64 (51),
B64 (52), B64 (53), B64 (54), B64 (55),
B64 (56), B64 (57), B64 (58), B64 (59),
B64 (60), B64 (61), B64 (62), B64 (63),
B64 (64), B64 (65), B64 (66), B64 (67),
B64 (68), B64 (69), B64 (70), B64 (71),
B64 (72), B64 (73), B64 (74), B64 (75),
B64 (76), B64 (77), B64 (78), B64 (79),
B64 (80), B64 (81), B64 (82), B64 (83),
B64 (84), B64 (85), B64 (86), B64 (87),
B64 (88), B64 (89), B64 (90), B64 (91),
B64 (92), B64 (93), B64 (94), B64 (95),
B64 (96), B64 (97), B64 (98), B64 (99),
B64 (100), B64 (101), B64 (102), B64 (103),
B64 (104), B64 (105), B64 (106), B64 (107),
B64 (108), B64 (109), B64 (110), B64 (111),
B64 (112), B64 (113), B64 (114), B64 (115),
B64 (116), B64 (117), B64 (118), B64 (119),
B64 (120), B64 (121), B64 (122), B64 (123),
B64 (124), B64 (125), B64 (126), B64 (127),
B64 (128), B64 (129), B64 (130), B64 (131),
B64 (132), B64 (133), B64 (134), B64 (135),
B64 (136), B64 (137), B64 (138), B64 (139),
B64 (140), B64 (141), B64 (142), B64 (143),
B64 (144), B64 (145), B64 (146), B64 (147),
B64 (148), B64 (149), B64 (150), B64 (151),
B64 (152), B64 (153), B64 (154), B64 (155),
B64 (156), B64 (157), B64 (158), B64 (159),
B64 (160), B64 (161), B64 (162), B64 (163),
B64 (164), B64 (165), B64 (166), B64 (167),
B64 (168), B64 (169), B64 (170), B64 (171),
B64 (172), B64 (173), B64 (174), B64 (175),
B64 (176), B64 (177), B64 (178), B64 (179),
B64 (180), B64 (181), B64 (182), B64 (183),
B64 (184), B64 (185), B64 (186), B64 (187),
B64 (188), B64 (189), B64 (190), B64 (191),
B64 (192), B64 (193), B64 (194), B64 (195),
B64 (196), B64 (197), B64 (198), B64 (199),
B64 (200), B64 (201), B64 (202), B64 (203),
B64 (204), B64 (205), B64 (206), B64 (207),
B64 (208), B64 (209), B64 (210), B64 (211),
B64 (212), B64 (213), B64 (214), B64 (215),
B64 (216), B64 (217), B64 (218), B64 (219),
B64 (220), B64 (221), B64 (222), B64 (223),
B64 (224), B64 (225), B64 (226), B64 (227),
B64 (228), B64 (229), B64 (230), B64 (231),
B64 (232), B64 (233), B64 (234), B64 (235),
B64 (236), B64 (237), B64 (238), B64 (239),
B64 (240), B64 (241), B64 (242), B64 (243),
B64 (244), B64 (245), B64 (246), B64 (247),
B64 (248), B64 (249), B64 (250), B64 (251),
B64 (252), B64 (253), B64 (254), B64 (255)
};
#if UCHAR_MAX == 255
# define uchar_in_range(c) true
#else
# define uchar_in_range(c) ((c) <= 255)
#endif
/* Return true if CH is a character from the Base64 alphabet, and
false otherwise. Note that '=' is padding and not considered to be
part of the alphabet. */
bool
isbase64 (char ch)
{
return uchar_in_range (to_uchar (ch)) && 0 <= b64[to_uchar (ch)];
}
/* Initialize decode-context buffer, CTX. */
void
base64_decode_ctx_init (struct base64_decode_context *ctx)
{
ctx->i = 0;
}
/* If CTX->i is 0 or 4, there are four or more bytes in [*IN..IN_END), and
none of those four is a newline, then return *IN. Otherwise, copy up to
4 - CTX->i non-newline bytes from that range into CTX->buf, starting at
index CTX->i and setting CTX->i to reflect the number of bytes copied,
and return CTX->buf. In either case, advance *IN to point to the byte
after the last one processed, and set *N_NON_NEWLINE to the number of
verified non-newline bytes accessible through the returned pointer. */
static const char *
get_4 (struct base64_decode_context *ctx,
char const *restrict *in, char const *restrict in_end,
size_t *n_non_newline)
{
if (ctx->i == 4)
ctx->i = 0;
if (ctx->i == 0)
{
char const *t = *in;
if (4 <= in_end - *in && memchr (t, '\n', 4) == NULL)
{
/* This is the common case: no newline. */
*in += 4;
*n_non_newline = 4;
return (const char *) t;
}
}
{
/* Copy non-newline bytes into BUF. */
char const *p = *in;
while (p < in_end)
{
char c = *p++;
if (c != '\n')
{
ctx->buf[ctx->i++] = c;
if (ctx->i == 4)
break;
}
}
*in = p;
*n_non_newline = ctx->i;
return ctx->buf;
}
}
#define return_false \
do \
{ \
*outp = out; \
return false; \
} \
while (false)
/* Decode up to four bytes of base64-encoded data, IN, of length INLEN
into the output buffer, *OUT, of size *OUTLEN bytes. Return true if
decoding is successful, false otherwise. If *OUTLEN is too small,
as many bytes as possible are written to *OUT. On return, advance
*OUT to point to the byte after the last one written, and decrement
*OUTLEN to reflect the number of bytes remaining in *OUT. */
static bool
decode_4 (char const *restrict in, size_t inlen,
char *restrict *outp, size_t *outleft)
{
char *out = *outp;
if (inlen < 2)
return false;
if (!isbase64 (in[0]) || !isbase64 (in[1]))
return false;
if (*outleft)
{
*out++ = ((b64[to_uchar (in[0])] << 2)
| (b64[to_uchar (in[1])] >> 4));
--*outleft;
}
if (inlen == 2)
return_false;
if (in[2] == '=')
{
if (inlen != 4)
return_false;
if (in[3] != '=')
return_false;
}
else
{
if (!isbase64 (in[2]))
return_false;
if (*outleft)
{
*out++ = (((b64[to_uchar (in[1])] << 4) & 0xf0)
| (b64[to_uchar (in[2])] >> 2));
--*outleft;
}
if (inlen == 3)
return_false;
if (in[3] == '=')
{
if (inlen != 4)
return_false;
}
else
{
if (!isbase64 (in[3]))
return_false;
if (*outleft)
{
*out++ = (((b64[to_uchar (in[2])] << 6) & 0xc0)
| b64[to_uchar (in[3])]);
--*outleft;
}
}
}
*outp = out;
return true;
}
/* Decode base64-encoded input array IN of length INLEN to output array
OUT that can hold *OUTLEN bytes. The input data may be interspersed
with newlines. Return true if decoding was successful, i.e. if the
input was valid base64 data, false otherwise. If *OUTLEN is too
small, as many bytes as possible will be written to OUT. On return,
*OUTLEN holds the length of decoded bytes in OUT. Note that as soon
as any non-alphabet, non-newline character is encountered, decoding
is stopped and false is returned. If INLEN is zero, then process
only whatever data is stored in CTX.
Initially, CTX must have been initialized via base64_decode_ctx_init.
Subsequent calls to this function must reuse whatever state is recorded
in that buffer. It is necessary for when a quadruple of base64 input
bytes spans two input buffers.
If CTX is NULL then newlines are treated as garbage and the input
buffer is processed as a unit. */
bool
base64_decode_ctx (struct base64_decode_context *ctx,
const char *restrict in, size_t inlen,
char *restrict out, size_t *outlen)
{
size_t outleft = *outlen;
bool ignore_newlines = ctx != NULL;
bool flush_ctx = false;
unsigned int ctx_i = 0;
if (ignore_newlines)
{
ctx_i = ctx->i;
flush_ctx = inlen == 0;
}
while (true)
{
size_t outleft_save = outleft;
if (ctx_i == 0 && !flush_ctx)
{
while (true)
{
/* Save a copy of outleft, in case we need to re-parse this
block of four bytes. */
outleft_save = outleft;
if (!decode_4 (in, inlen, &out, &outleft))
break;
in += 4;
inlen -= 4;
}
}
if (inlen == 0 && !flush_ctx)
break;
/* Handle the common case of 72-byte wrapped lines.
This also handles any other multiple-of-4-byte wrapping. */
if (inlen && *in == '\n' && ignore_newlines)
{
++in;
--inlen;
continue;
}
/* Restore OUT and OUTLEFT. */
out -= outleft_save - outleft;
outleft = outleft_save;
{
char const *in_end = in + inlen;
char const *non_nl;
if (ignore_newlines)
non_nl = get_4 (ctx, &in, in_end, &inlen);
else
non_nl = in; /* Might have nl in this case. */
/* If the input is empty or consists solely of newlines (0 non-newlines),
then we're done. Likewise if there are fewer than 4 bytes when not
flushing context and not treating newlines as garbage. */
if (inlen == 0 || (inlen < 4 && !flush_ctx && ignore_newlines))
{
inlen = 0;
break;
}
if (!decode_4 (non_nl, inlen, &out, &outleft))
break;
inlen = in_end - in;
}
}
*outlen -= outleft;
return inlen == 0;
}
/* Allocate an output buffer in *OUT, and decode the base64 encoded
data stored in IN of size INLEN to the *OUT buffer. On return, the
size of the decoded data is stored in *OUTLEN. OUTLEN may be NULL,
if the caller is not interested in the decoded length. *OUT may be
NULL to indicate an out of memory error, in which case *OUTLEN
contains the size of the memory block needed. The function returns
true on successful decoding and memory allocation errors. (Use the
*OUT and *OUTLEN parameters to differentiate between successful
decoding and memory error.) The function returns false if the
input was invalid, in which case *OUT is NULL and *OUTLEN is
undefined. */
bool
base64_decode_alloc_ctx (struct base64_decode_context *ctx,
const char *in, size_t inlen, char **out,
size_t *outlen)
{
/* This may allocate a few bytes too many, depending on input,
but it's not worth the extra CPU time to compute the exact size.
The exact size is 3 * (inlen + (ctx ? ctx->i : 0)) / 4, minus 1 if the
input ends with "=" and minus another 1 if the input ends with "==".
Dividing before multiplying avoids the possibility of overflow. */
size_t needlen = 3 * (inlen / 4) + 3;
*out = malloc (needlen);
if (!*out)
return true;
if (!base64_decode_ctx (ctx, in, inlen, *out, &needlen))
{
free (*out);
*out = NULL;
return false;
}
if (outlen)
*outlen = needlen;
return true;
}

View File

@@ -1,68 +0,0 @@
/* base64.h -- Encode binary data using printable characters.
Copyright (C) 2004-2006, 2009-2019 Free Software Foundation, Inc.
Written by Simon Josefsson.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <https://www.gnu.org/licenses/>. */
#ifndef BASE64_H
# define BASE64_H
/* Get size_t. */
# include <stddef.h>
/* Get bool. */
# include <stdbool.h>
# ifdef __cplusplus
extern "C" {
# endif
/* This uses that the expression (n+(k-1))/k means the smallest
integer >= n/k, i.e., the ceiling of n/k. */
# define BASE64_LENGTH(inlen) ((((inlen) + 2) / 3) * 4)
struct base64_decode_context
{
unsigned int i;
char buf[4];
};
extern bool isbase64 (char ch) __attribute__ ((__const__));
extern void base64_encode (const char *restrict in, size_t inlen,
char *restrict out, size_t outlen);
extern size_t base64_encode_alloc (const char *in, size_t inlen, char **out);
extern void base64_decode_ctx_init (struct base64_decode_context *ctx);
extern bool base64_decode_ctx (struct base64_decode_context *ctx,
const char *restrict in, size_t inlen,
char *restrict out, size_t *outlen);
extern bool base64_decode_alloc_ctx (struct base64_decode_context *ctx,
const char *in, size_t inlen,
char **out, size_t *outlen);
#define base64_decode(in, inlen, out, outlen) \
base64_decode_ctx (NULL, in, inlen, out, outlen)
#define base64_decode_alloc(in, inlen, out, outlen) \
base64_decode_alloc_ctx (NULL, in, inlen, out, outlen)
# ifdef __cplusplus
}
# endif
#endif /* BASE64_H */

View File

@@ -1,30 +1,16 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* BITLK (BitLocker-compatible) volume handling
*
* Copyright (C) 2019-2021 Red Hat, Inc. All rights reserved.
* Copyright (C) 2019-2021 Milan Broz
* Copyright (C) 2019-2021 Vojtech Trefny
*
* This file is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this file; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* Copyright (C) 2019-2025 Red Hat, Inc. All rights reserved.
* Copyright (C) 2019-2025 Milan Broz
* Copyright (C) 2019-2025 Vojtech Trefny
*/
#include <errno.h>
#include <string.h>
#include <uuid/uuid.h>
#include <time.h>
#include <iconv.h>
#include <limits.h>
#include "bitlk.h"
@@ -234,86 +220,11 @@ static const char* get_bitlk_type_string(BITLKEncryptionType type)
}
}
/* TODO -- move to some utils file */
static void hexprint(struct crypt_device *cd, const char *d, int n, const char *sep)
{
int i;
for(i = 0; i < n; i++)
log_std(cd, "%02hhx%s", (const char)d[i], sep);
}
static uint64_t filetime_to_unixtime(uint64_t time)
{
return (time - EPOCH_AS_FILETIME) / HUNDREDS_OF_NANOSECONDS;
}
static int convert_to_utf8(struct crypt_device *cd, uint8_t *input, size_t inlen, char **out)
{
char *outbuf = NULL;
iconv_t ic;
size_t ic_inlen = inlen;
size_t ic_outlen = inlen;
char *ic_outbuf = NULL;
size_t r = 0;
outbuf = malloc(inlen);
if (outbuf == NULL)
return -ENOMEM;
memset(outbuf, 0, inlen);
ic_outbuf = outbuf;
ic = iconv_open("UTF-8", "UTF-16LE");
r = iconv(ic, (char **) &input, &ic_inlen, &ic_outbuf, &ic_outlen);
iconv_close(ic);
if (r == 0)
*out = strdup(outbuf);
else {
*out = NULL;
log_dbg(cd, "Failed to convert volume description: %s", strerror(errno));
r = 0;
}
free(outbuf);
return r;
}
static int passphrase_to_utf16(struct crypt_device *cd, char *input, size_t inlen, char **out)
{
char *outbuf = NULL;
iconv_t ic;
size_t ic_inlen = inlen;
size_t ic_outlen = inlen * 2;
char *ic_outbuf = NULL;
size_t r = 0;
if (inlen == 0)
return r;
outbuf = crypt_safe_alloc(inlen * 2);
if (outbuf == NULL)
return -ENOMEM;
memset(outbuf, 0, inlen * 2);
ic_outbuf = outbuf;
ic = iconv_open("UTF-16LE", "UTF-8");
r = iconv(ic, &input, &ic_inlen, &ic_outbuf, &ic_outlen);
iconv_close(ic);
if (r == 0) {
*out = outbuf;
} else {
*out = NULL;
crypt_safe_free(outbuf);
log_dbg(cd, "Failed to convert passphrase: %s", strerror(errno));
r = -errno;
}
return r;
}
static int parse_vmk_entry(struct crypt_device *cd, uint8_t *data, int start, int end, struct bitlk_vmk **vmk)
{
uint16_t key_entry_size = 0;
@@ -324,19 +235,23 @@ static int parse_vmk_entry(struct crypt_device *cd, uint8_t *data, int start, in
const char *key = NULL;
struct volume_key *vk = NULL;
bool supported = false;
int r = 0;
/* only passphrase or recovery passphrase vmks are supported (can be used to activate) */
supported = (*vmk)->protection == BITLK_PROTECTION_PASSPHRASE ||
(*vmk)->protection == BITLK_PROTECTION_RECOVERY_PASSPHRASE ||
(*vmk)->protection == BITLK_PROTECTION_STARTUP_KEY;
while (end - start > 2) {
while ((end - start) >= (ssize_t)(sizeof(key_entry_size) + sizeof(key_entry_type) + sizeof(key_entry_value))) {
/* size of this entry */
memcpy(&key_entry_size, data + start, sizeof(key_entry_size));
key_entry_size = le16_to_cpu(key_entry_size);
if (key_entry_size == 0)
break;
if (key_entry_size > (end - start))
return -EINVAL;
/* type and value of this entry */
memcpy(&key_entry_type, data + start + sizeof(key_entry_size), sizeof(key_entry_type));
memcpy(&key_entry_value,
@@ -355,20 +270,24 @@ static int parse_vmk_entry(struct crypt_device *cd, uint8_t *data, int start, in
}
/* stretch key with salt, skip 4 B (encryption method of the stretch key) */
if (key_entry_value == BITLK_ENTRY_VALUE_STRETCH_KEY)
if (key_entry_value == BITLK_ENTRY_VALUE_STRETCH_KEY) {
if ((end - start) < (BITLK_ENTRY_HEADER_LEN + BITLK_SALT_SIZE + 4))
return -EINVAL;
memcpy((*vmk)->salt,
data + start + BITLK_ENTRY_HEADER_LEN + 4,
sizeof((*vmk)->salt));
BITLK_SALT_SIZE);
/* AES-CCM encrypted key */
else if (key_entry_value == BITLK_ENTRY_VALUE_ENCRYPTED_KEY) {
} else if (key_entry_value == BITLK_ENTRY_VALUE_ENCRYPTED_KEY) {
if (key_entry_size < (BITLK_ENTRY_HEADER_LEN + BITLK_NONCE_SIZE + BITLK_VMK_MAC_TAG_SIZE))
return -EINVAL;
/* nonce */
memcpy((*vmk)->nonce,
data + start + BITLK_ENTRY_HEADER_LEN,
sizeof((*vmk)->nonce));
BITLK_NONCE_SIZE);
/* MAC tag */
memcpy((*vmk)->mac_tag,
data + start + BITLK_ENTRY_HEADER_LEN + BITLK_NONCE_SIZE,
sizeof((*vmk)->mac_tag));
BITLK_VMK_MAC_TAG_SIZE);
/* AES-CCM encrypted key */
key_size = key_entry_size - (BITLK_ENTRY_HEADER_LEN + BITLK_NONCE_SIZE + BITLK_VMK_MAC_TAG_SIZE);
key = (const char *) data + start + BITLK_ENTRY_HEADER_LEN + BITLK_NONCE_SIZE + BITLK_VMK_MAC_TAG_SIZE;
@@ -392,10 +311,20 @@ static int parse_vmk_entry(struct crypt_device *cd, uint8_t *data, int start, in
/* unknown timestamps in recovery protected VMK */
} else if (key_entry_value == BITLK_ENTRY_VALUE_RECOVERY_TIME) {
;
/* optional hint (?) string (masked email?), we can safely ignore it */
} else if (key_entry_value == BITLK_ENTRY_VALUE_HINT) {
;
} else if (key_entry_value == BITLK_ENTRY_VALUE_STRING) {
if (convert_to_utf8(cd, data + start + BITLK_ENTRY_HEADER_LEN, key_entry_size - BITLK_ENTRY_HEADER_LEN, &string) < 0) {
log_err(cd, _("Invalid string found when parsing Volume Master Key."));
if (key_entry_size < BITLK_ENTRY_HEADER_LEN)
return -EINVAL;
string = malloc((key_entry_size - BITLK_ENTRY_HEADER_LEN) * 2 + 1);
if (!string)
return -ENOMEM;
r = crypt_utf16_to_utf8(&string, CONST_CAST(char16_t *)(data + start + BITLK_ENTRY_HEADER_LEN),
key_entry_size - BITLK_ENTRY_HEADER_LEN);
if (r < 0 || !string) {
free(string);
log_err(cd, _("Invalid string found when parsing Volume Master Key."));
return -EINVAL;
} else if ((*vmk)->name != NULL) {
if (supported) {
@@ -414,6 +343,9 @@ static int parse_vmk_entry(struct crypt_device *cd, uint8_t *data, int start, in
/* no idea what this is, lets hope it's not important */
} else if (key_entry_value == BITLK_ENTRY_VALUE_USE_KEY && (*vmk)->protection == BITLK_PROTECTION_STARTUP_KEY) {
;
/* quietly ignore unsupported TPM key */
} else if (key_entry_value == BITLK_ENTRY_VALUE_TPM_KEY && (*vmk)->protection == BITLK_PROTECTION_TPM) {
;
} else {
if (supported) {
log_err(cd, _("Unexpected metadata entry value '%u' found when parsing supported Volume Master Key."), key_entry_value);
@@ -443,10 +375,8 @@ void BITLK_bitlk_vmk_free(struct bitlk_vmk *vmk)
struct bitlk_vmk *vmk_next = NULL;
while (vmk) {
if (vmk->guid)
free(vmk->guid);
if (vmk->name)
free(vmk->name);
free(vmk->guid);
free(vmk->name);
crypt_free_volume_key(vmk->vk);
vmk_next = vmk->next;
free(vmk);
@@ -460,8 +390,7 @@ void BITLK_bitlk_metadata_free(struct bitlk_metadata *metadata)
return;
free(metadata->guid);
if (metadata->description)
free(metadata->description);
free(metadata->description);
BITLK_bitlk_vmk_free(metadata->vmks);
BITLK_bitlk_fvek_free(metadata->fvek);
}
@@ -475,6 +404,7 @@ int BITLK_read_sb(struct crypt_device *cd, struct bitlk_metadata *params)
struct bitlk_fve_metadata fve = {};
struct bitlk_entry_vmk entry_vmk = {};
uint8_t *fve_entries = NULL;
size_t fve_entries_size = 0;
uint32_t fve_metadata_size = 0;
int fve_offset = 0;
char guid_buf[UUID_STR_LEN] = {0};
@@ -483,9 +413,9 @@ int BITLK_read_sb(struct crypt_device *cd, struct bitlk_metadata *params)
int i = 0;
int r = 0;
int start = 0;
int end = 0;
size_t key_size = 0;
const char *key = NULL;
char *description = NULL;
struct bitlk_vmk *vmk = NULL;
struct bitlk_vmk *vmk_p = params->vmks;
@@ -499,8 +429,8 @@ int BITLK_read_sb(struct crypt_device *cd, struct bitlk_metadata *params)
/* read and check the signature */
if (read_lseek_blockwise(devfd, device_block_size(cd, device),
device_alignment(device), &sig, sizeof(sig), 0) != sizeof(sig)) {
log_err(cd, _("Failed to read BITLK signature from %s."), device_path(device));
r = -EINVAL;
log_dbg(cd, "Failed to read BITLK signature from %s.", device_path(device));
r = -EIO;
goto out;
}
@@ -511,7 +441,7 @@ int BITLK_read_sb(struct crypt_device *cd, struct bitlk_metadata *params)
params->togo = true;
fve_offset = BITLK_HEADER_METADATA_OFFSET_TOGO;
} else {
log_err(cd, _("Invalid or unknown signature for BITLK device."));
log_dbg(cd, "Invalid or unknown signature for BITLK device.");
r = -EINVAL;
goto out;
}
@@ -581,8 +511,8 @@ int BITLK_read_sb(struct crypt_device *cd, struct bitlk_metadata *params)
le16_to_cpu(fve.curr_state), le16_to_cpu(fve.next_state));
}
params->volume_size = le64_to_cpu(fve.volume_size);
params->metadata_version = le16_to_cpu(fve.fve_version);
fve_metadata_size = le32_to_cpu(fve.metadata_size);
switch (le16_to_cpu(fve.encryption)) {
/* AES-CBC with Elephant difuser */
@@ -637,40 +567,56 @@ int BITLK_read_sb(struct crypt_device *cd, struct bitlk_metadata *params)
params->creation_time = filetime_to_unixtime(le64_to_cpu(fve.creation_time));
fve_metadata_size = le32_to_cpu(fve.metadata_size);
if (fve_metadata_size < (BITLK_FVE_METADATA_HEADER_LEN + sizeof(entry_size) + sizeof(entry_type)) ||
fve_metadata_size > BITLK_FVE_METADATA_SIZE) {
r = -EINVAL;
goto out;
}
fve_entries_size = fve_metadata_size - BITLK_FVE_METADATA_HEADER_LEN;
/* read and parse all FVE metadata entries */
fve_entries = malloc(fve_metadata_size - BITLK_FVE_METADATA_HEADER_LEN);
fve_entries = malloc(fve_entries_size);
if (!fve_entries) {
r = -ENOMEM;
goto out;
}
memset(fve_entries, 0, (fve_metadata_size - BITLK_FVE_METADATA_HEADER_LEN));
memset(fve_entries, 0, fve_entries_size);
log_dbg(cd, "Reading BITLK FVE metadata entries of size %" PRIu32 " on device %s, offset %" PRIu64 ".",
fve_metadata_size - BITLK_FVE_METADATA_HEADER_LEN, device_path(device),
params->metadata_offset[0] + BITLK_FVE_METADATA_HEADERS_LEN);
log_dbg(cd, "Reading BITLK FVE metadata entries of size %zu on device %s, offset %" PRIu64 ".",
fve_entries_size, device_path(device), params->metadata_offset[0] + BITLK_FVE_METADATA_HEADERS_LEN);
if (read_lseek_blockwise(devfd, device_block_size(cd, device),
device_alignment(device), fve_entries, fve_metadata_size - BITLK_FVE_METADATA_HEADER_LEN,
params->metadata_offset[0] + BITLK_FVE_METADATA_HEADERS_LEN) != (ssize_t)(fve_metadata_size - BITLK_FVE_METADATA_HEADER_LEN)) {
device_alignment(device), fve_entries, fve_entries_size,
params->metadata_offset[0] + BITLK_FVE_METADATA_HEADERS_LEN) != (ssize_t)fve_entries_size) {
log_err(cd, _("Failed to read BITLK metadata entries from %s."), device_path(device));
r = -EINVAL;
goto out;
}
end = fve_metadata_size - BITLK_FVE_METADATA_HEADER_LEN;
while (end - start > 2) {
while ((fve_entries_size - start) >= (sizeof(entry_size) + sizeof(entry_type))) {
/* size of this entry */
memcpy(&entry_size, fve_entries + start, sizeof(entry_size));
entry_size = le16_to_cpu(entry_size);
if (entry_size == 0)
break;
if (entry_size > (fve_entries_size - start)) {
r = -EINVAL;
goto out;
}
/* type of this entry */
memcpy(&entry_type, fve_entries + start + sizeof(entry_size), sizeof(entry_type));
entry_type = le16_to_cpu(entry_type);
/* VMK */
if (entry_type == BITLK_ENTRY_TYPE_VMK) {
if (entry_size < (BITLK_ENTRY_HEADER_LEN + sizeof(entry_vmk))) {
r = -EINVAL;
goto out;
}
/* skip first four variables in the entry (entry size, type, value and version) */
memcpy(&entry_vmk,
fve_entries + start + BITLK_ENTRY_HEADER_LEN,
@@ -707,7 +653,11 @@ int BITLK_read_sb(struct crypt_device *cd, struct bitlk_metadata *params)
vmk_p = vmk;
vmk = vmk->next;
/* FVEK */
} else if (entry_type == BITLK_ENTRY_TYPE_FVEK) {
} else if (entry_type == BITLK_ENTRY_TYPE_FVEK && !params->fvek) {
if (entry_size < (BITLK_ENTRY_HEADER_LEN + BITLK_NONCE_SIZE + BITLK_VMK_MAC_TAG_SIZE)) {
r = -EINVAL;
goto out;
}
params->fvek = malloc(sizeof(struct bitlk_fvek));
if (!params->fvek) {
r = -ENOMEM;
@@ -715,11 +665,11 @@ int BITLK_read_sb(struct crypt_device *cd, struct bitlk_metadata *params)
}
memcpy(params->fvek->nonce,
fve_entries + start + BITLK_ENTRY_HEADER_LEN,
sizeof(params->fvek->nonce));
BITLK_NONCE_SIZE);
/* MAC tag */
memcpy(params->fvek->mac_tag,
fve_entries + start + BITLK_ENTRY_HEADER_LEN + BITLK_NONCE_SIZE,
sizeof(params->fvek->mac_tag));
BITLK_VMK_MAC_TAG_SIZE);
/* AES-CCM encrypted key */
key_size = entry_size - (BITLK_ENTRY_HEADER_LEN + BITLK_NONCE_SIZE + BITLK_VMK_MAC_TAG_SIZE);
key = (const char *) fve_entries + start + BITLK_ENTRY_HEADER_LEN + BITLK_NONCE_SIZE + BITLK_VMK_MAC_TAG_SIZE;
@@ -731,28 +681,41 @@ int BITLK_read_sb(struct crypt_device *cd, struct bitlk_metadata *params)
/* volume header info (location and size) */
} else if (entry_type == BITLK_ENTRY_TYPE_VOLUME_HEADER) {
struct bitlk_entry_header_block entry_header;
if ((fve_entries_size - start) < (BITLK_ENTRY_HEADER_LEN + sizeof(entry_header))) {
r = -EINVAL;
goto out;
}
memcpy(&entry_header,
fve_entries + start + BITLK_ENTRY_HEADER_LEN,
sizeof(entry_header));
params->volume_header_offset = le64_to_cpu(entry_header.offset);
params->volume_header_size = le64_to_cpu(entry_header.size);
/* volume description (utf-16 string) */
} else if (entry_type == BITLK_ENTRY_TYPE_DESCRIPTION) {
r = convert_to_utf8(cd, fve_entries + start + BITLK_ENTRY_HEADER_LEN,
entry_size - BITLK_ENTRY_HEADER_LEN,
&(params->description));
if (r < 0) {
BITLK_bitlk_vmk_free(vmk);
} else if (entry_type == BITLK_ENTRY_TYPE_DESCRIPTION && !params->description) {
if (entry_size < BITLK_ENTRY_HEADER_LEN) {
r = -EINVAL;
goto out;
}
description = malloc((entry_size - BITLK_ENTRY_HEADER_LEN) * 2 + 1);
if (!description) {
r = -ENOMEM;
goto out;
}
r = crypt_utf16_to_utf8(&description, CONST_CAST(char16_t *)(fve_entries + start + BITLK_ENTRY_HEADER_LEN),
entry_size - BITLK_ENTRY_HEADER_LEN);
if (r < 0) {
free(description);
BITLK_bitlk_vmk_free(vmk);
log_err(cd, _("Failed to convert BITLK volume description"));
goto out;
}
params->description = description;
}
start += entry_size;
}
out:
if (fve_entries)
free(fve_entries);
free(fve_entries);
return r;
}
@@ -760,6 +723,7 @@ int BITLK_dump(struct crypt_device *cd, struct device *device, struct bitlk_meta
{
struct volume_key *vk_p;
struct bitlk_vmk *vmk_p;
char time[32];
int next_id = 0;
int i = 0;
@@ -767,11 +731,13 @@ int BITLK_dump(struct crypt_device *cd, struct device *device, struct bitlk_meta
log_std(cd, "Version: \t%u\n", params->metadata_version);
log_std(cd, "GUID: \t%s\n", params->guid);
log_std(cd, "Sector size: \t%u [bytes]\n", params->sector_size);
log_std(cd, "Created: \t%s", ctime((time_t *)&(params->creation_time)));
log_std(cd, "Volume size: \t%" PRIu64 " [bytes]\n", params->volume_size);
if (ctime_r((time_t *)&params->creation_time, time))
log_std(cd, "Created: \t%s", time);
log_std(cd, "Description: \t%s\n", params->description);
log_std(cd, "Cipher name: \t%s\n", params->cipher);
log_std(cd, "Cipher mode: \t%s\n", params->cipher_mode);
log_std(cd, "Cipher key: \t%u bits\n", params->key_size);
log_std(cd, "Cipher key: \t%u [bits]\n", params->key_size);
log_std(cd, "\n");
@@ -785,20 +751,20 @@ int BITLK_dump(struct crypt_device *cd, struct device *device, struct bitlk_meta
log_std(cd, "\tGUID: \t%s\n", vmk_p->guid);
log_std(cd, "\tProtection: \t%s\n", get_vmk_protection_string (vmk_p->protection));
log_std(cd, "\tSalt: \t");
hexprint(cd, (const char *) vmk_p->salt, 16, "");
crypt_log_hex(cd, (const char *) vmk_p->salt, 16, "", 0, NULL);
log_std(cd, "\n");
vk_p = vmk_p->vk;
while (vk_p) {
log_std(cd, "\tKey data size:\t%zu [bytes]\n", vk_p->keylength);
vk_p = vk_p->next;
log_std(cd, "\tKey data size:\t%zu [bytes]\n", crypt_volume_key_length(vk_p));
vk_p = crypt_volume_key_next(vk_p);
}
vmk_p = vmk_p->next;
next_id++;
}
log_std(cd, " %d: FVEK\n", next_id);
log_std(cd, "\tKey data size:\t%zu [bytes]\n", params->fvek->vk->keylength);
log_std(cd, "\tKey data size:\t%zu [bytes]\n", crypt_volume_key_length(params->fvek->vk));
log_std(cd, "\n");
@@ -835,13 +801,13 @@ static int get_recovery_key(struct crypt_device *cd,
- each part is a number dividable by 11
*/
if (passwordLen != BITLK_RECOVERY_KEY_LEN) {
if (passwordLen == BITLK_RECOVERY_KEY_LEN + 1 && password[passwordLen - 1] == '\n') {
/* looks like a recovery key with an extra newline, possibly from a key file */
passwordLen--;
log_dbg(cd, "Possible extra EOL stripped from the recovery key.");
} else
return 0;
}
if (passwordLen == BITLK_RECOVERY_KEY_LEN + 1 && password[passwordLen - 1] == '\n') {
/* looks like a recovery key with an extra newline, possibly from a key file */
passwordLen--;
log_dbg(cd, "Possible extra EOL stripped from the recovery key.");
} else
return 0;
}
for (i = BITLK_RECOVERY_PART_LEN; i < passwordLen; i += BITLK_RECOVERY_PART_LEN + 1) {
if (password[i] != '-')
@@ -869,21 +835,31 @@ static int get_recovery_key(struct crypt_device *cd,
return 0;
}
static int parse_external_key_entry(struct crypt_device *cd, const char *data, int start, int end, struct volume_key **vk)
static int parse_external_key_entry(struct crypt_device *cd,
const char *data,
int start,
int end,
struct volume_key **vk,
const struct bitlk_metadata *params)
{
uint16_t key_entry_size = 0;
uint16_t key_entry_type = 0;
uint16_t key_entry_value = 0;
size_t key_size = 0;
const char *key = NULL;
struct bitlk_guid guid;
char guid_buf[UUID_STR_LEN] = {0};
while (end - start > 2) {
while ((end - start) >= (ssize_t)(sizeof(key_entry_size) + sizeof(key_entry_type) + sizeof(key_entry_value))) {
/* size of this entry */
memcpy(&key_entry_size, data + start, sizeof(key_entry_size));
key_entry_size = le16_to_cpu(key_entry_size);
if (key_entry_size == 0)
break;
if (key_entry_size > (end - start))
return -EINVAL;
/* type and value of this entry */
memcpy(&key_entry_type, data + start + sizeof(key_entry_size), sizeof(key_entry_type));
memcpy(&key_entry_value,
@@ -892,13 +868,14 @@ static int parse_external_key_entry(struct crypt_device *cd, const char *data, i
key_entry_type = le16_to_cpu(key_entry_type);
key_entry_value = le16_to_cpu(key_entry_value);
/* only properties should be in this entry */
if (key_entry_type != BITLK_ENTRY_TYPE_PROPERTY) {
if (key_entry_type != BITLK_ENTRY_TYPE_PROPERTY && key_entry_type != BITLK_ENTRY_TYPE_VOLUME_GUID) {
log_err(cd, _("Unexpected metadata entry type '%u' found when parsing external key."), key_entry_type);
return -EINVAL;
}
if (key_entry_value == BITLK_ENTRY_VALUE_KEY) {
if (key_entry_size < (BITLK_ENTRY_HEADER_LEN + 4))
return -EINVAL;
key_size = key_entry_size - (BITLK_ENTRY_HEADER_LEN + 4);
key = (const char *) data + start + BITLK_ENTRY_HEADER_LEN + 4;
*vk = crypt_alloc_volume_key(key_size, key);
@@ -908,7 +885,17 @@ static int parse_external_key_entry(struct crypt_device *cd, const char *data, i
/* optional "ExternalKey" string, we can safely ignore it */
} else if (key_entry_value == BITLK_ENTRY_VALUE_STRING)
;
else {
/* GUID of the BitLocker device we are trying to open with this key */
else if (key_entry_value == BITLK_ENTRY_VALUE_GUID) {
if ((end - start) < (ssize_t)(BITLK_ENTRY_HEADER_LEN + sizeof(struct bitlk_guid)))
return -EINVAL;
memcpy(&guid, data + start + BITLK_ENTRY_HEADER_LEN, sizeof(struct bitlk_guid));
guid_to_string(&guid, guid_buf);
if (strcmp(guid_buf, params->guid) != 0) {
log_err(cd, _("BEK file GUID '%s' does not match GUID of the volume."), guid_buf);
return -EINVAL;
}
} else {
log_err(cd, _("Unexpected metadata entry value '%u' found when parsing external key."), key_entry_value);
return -EINVAL;
}
@@ -925,7 +912,8 @@ static int get_startup_key(struct crypt_device *cd,
const char *password,
size_t passwordLen,
const struct bitlk_vmk *vmk,
struct volume_key **su_key)
struct volume_key **su_key,
const struct bitlk_metadata *params)
{
struct bitlk_bek_header bek_header = {0};
char guid_buf[UUID_STR_LEN] = {0};
@@ -934,7 +922,7 @@ static int get_startup_key(struct crypt_device *cd,
uint16_t key_entry_type = 0;
uint16_t key_entry_value = 0;
if (passwordLen < BITLK_BEK_FILE_HEADER_LEN)
if (passwordLen < (BITLK_BEK_FILE_HEADER_LEN + sizeof(key_entry_size) + sizeof(key_entry_type) + sizeof(key_entry_value)))
return -EPERM;
memcpy(&bek_header, password, BITLK_BEK_FILE_HEADER_LEN);
@@ -946,13 +934,14 @@ static int get_startup_key(struct crypt_device *cd,
else
return -EPERM;
if (bek_header.metadata_version != 1) {
log_err(cd, "Unsupported BEK metadata version %" PRIu32 "", bek_header.metadata_version);
if (le32_to_cpu(bek_header.metadata_version) != 1) {
log_err(cd, _("Unsupported BEK metadata version %" PRIu32), le32_to_cpu(bek_header.metadata_version));
return -ENOTSUP;
}
if (bek_header.metadata_size != passwordLen) {
log_err(cd, "Unexpected BEK metadata size %" PRIu32 " does not match BEK file length", bek_header.metadata_size);
if (le32_to_cpu(bek_header.metadata_size) != passwordLen) {
log_err(cd, _("Unexpected BEK metadata size %" PRIu32 " does not match BEK file length"),
le32_to_cpu(bek_header.metadata_size));
return -EINVAL;
}
@@ -975,7 +964,7 @@ static int get_startup_key(struct crypt_device *cd,
if (key_entry_type == BITLK_ENTRY_TYPE_STARTUP_KEY && key_entry_value == BITLK_ENTRY_VALUE_EXTERNAL_KEY) {
return parse_external_key_entry(cd, password,
BITLK_BEK_FILE_HEADER_LEN + BITLK_ENTRY_HEADER_LEN + BITLK_STARTUP_KEY_HEADER_LEN,
passwordLen, su_key);
passwordLen, su_key, params);
} else {
log_err(cd, _("Unexpected metadata entry found when parsing startup key."));
log_dbg(cd, "Entry type: %u, entry value: %u", key_entry_type, key_entry_value);
@@ -983,8 +972,7 @@ static int get_startup_key(struct crypt_device *cd,
}
}
static int bitlk_kdf(struct crypt_device *cd,
const char *password,
static int bitlk_kdf(const char *password,
size_t passwordLen,
bool recovery,
const uint8_t *salt,
@@ -993,7 +981,7 @@ static int bitlk_kdf(struct crypt_device *cd,
struct bitlk_kdf_data kdf = {};
struct crypt_hash *hd = NULL;
int len = 0;
char *utf16Password = NULL;
char16_t *utf16Password = NULL;
int i = 0;
int r = 0;
@@ -1010,11 +998,16 @@ static int bitlk_kdf(struct crypt_device *cd,
if (!recovery) {
/* passphrase: convert to UTF-16 first, then sha256(sha256(pw)) */
r = passphrase_to_utf16(cd, CONST_CAST(char*)password, passwordLen, &utf16Password);
utf16Password = crypt_safe_alloc(sizeof(char16_t) * (passwordLen + 1));
if (!utf16Password) {
r = -ENOMEM;
goto out;
}
r = crypt_utf8_to_utf16(&utf16Password, CONST_CAST(char*)password, passwordLen);
if (r < 0)
goto out;
crypt_hash_write(hd, utf16Password, passwordLen * 2);
crypt_hash_write(hd, (char*)utf16Password, passwordLen * 2);
r = crypt_hash_final(hd, kdf.initial_sha256, len);
if (r < 0)
goto out;
@@ -1060,11 +1053,14 @@ static int decrypt_key(struct crypt_device *cd,
int r;
uint16_t key_size = 0;
outbuf = crypt_safe_alloc(enc_key->keylength);
outbuf = crypt_safe_alloc(crypt_volume_key_length(enc_key));
if (!outbuf)
return -ENOMEM;
r = crypt_bitlk_decrypt_key(key->key, key->keylength, enc_key->key, outbuf, enc_key->keylength,
r = crypt_bitlk_decrypt_key(crypt_volume_key_get_key(key),
crypt_volume_key_length(key),
crypt_volume_key_get_key(enc_key), outbuf,
crypt_volume_key_length(enc_key),
(const char*)iv, iv_size, (const char*)tag, tag_size);
if (r < 0) {
if (r == -ENOTSUP)
@@ -1075,9 +1071,10 @@ static int decrypt_key(struct crypt_device *cd,
/* key_data has it's size as part of the metadata */
memcpy(&key_size, outbuf, 2);
key_size = le16_to_cpu(key_size);
if (enc_key->keylength != key_size) {
if (crypt_volume_key_length(enc_key) != key_size) {
log_err(cd, _("Unexpected key data size."));
log_dbg(cd, "Expected key data size: %zu, got %" PRIu16 "", enc_key->keylength, key_size);
log_dbg(cd, "Expected key data size: %zu, got %" PRIu16 "",
crypt_volume_key_length(enc_key), key_size);
r = -EINVAL;
goto out;
@@ -1087,7 +1084,7 @@ static int decrypt_key(struct crypt_device *cd,
crypt_get_volume_key_size(cd) == 32) {
/* 128bit AES-CBC with Elephant -- key size is 256 bit (2 keys) but key data is 512 bits,
data: 16B CBC key, 16B empty, 16B elephant key, 16B empty */
memcpy(outbuf + 16 + BITLK_OPEN_KEY_METADATA_LEN,
crypt_safe_memcpy(outbuf + 16 + BITLK_OPEN_KEY_METADATA_LEN,
outbuf + 2 * 16 + BITLK_OPEN_KEY_METADATA_LEN, 16);
key_size = 32 + BITLK_OPEN_KEY_METADATA_LEN;
}
@@ -1116,7 +1113,7 @@ int BITLK_get_volume_key(struct crypt_device *cd,
next_vmk = params->vmks;
while (next_vmk) {
if (next_vmk->protection == BITLK_PROTECTION_PASSPHRASE) {
r = bitlk_kdf(cd, password, passwordLen, false, next_vmk->salt, &vmk_dec_key);
r = bitlk_kdf(password, passwordLen, false, next_vmk->salt, &vmk_dec_key);
if (r) {
/* something wrong happened, but we still want to check other key slots */
next_vmk = next_vmk->next;
@@ -1136,13 +1133,14 @@ int BITLK_get_volume_key(struct crypt_device *cd,
continue;
}
log_dbg(cd, "Trying to use given password as a recovery key.");
r = bitlk_kdf(cd, recovery_key->key, recovery_key->keylength,
r = bitlk_kdf(crypt_volume_key_get_key(recovery_key),
crypt_volume_key_length(recovery_key),
true, next_vmk->salt, &vmk_dec_key);
crypt_free_volume_key(recovery_key);
if (r)
return r;
} else if (next_vmk->protection == BITLK_PROTECTION_STARTUP_KEY) {
r = get_startup_key(cd, password, passwordLen, next_vmk, &vmk_dec_key);
r = get_startup_key(cd, password, passwordLen, next_vmk, &vmk_dec_key, params);
if (r) {
next_vmk = next_vmk->next;
continue;
@@ -1214,7 +1212,7 @@ static int _activate_check(struct crypt_device *cd,
next_vmk = params->vmks;
while (next_vmk) {
if (next_vmk->protection == BITLK_PROTECTION_CLEAR_KEY) {
log_err(cd, _("Activation of partially decrypted BITLK device is not supported."));
log_err(cd, _("Activation of BITLK device with clear key protection is not supported."));
return -ENOTSUP;
}
next_vmk = next_vmk->next;
@@ -1243,7 +1241,7 @@ static int _activate(struct crypt_device *cd,
uint64_t next_start = 0;
uint64_t next_end = 0;
uint64_t last_segment = 0;
uint32_t dmt_flags;
uint64_t dmt_flags = 0;
r = _activate_check(cd, params);
if (r)
@@ -1254,6 +1252,11 @@ static int _activate(struct crypt_device *cd,
if (r)
return r;
if (dmd.size * SECTOR_SIZE != params->volume_size)
log_std(cd, _("WARNING: BitLocker volume size %" PRIu64 " does not match the underlying device size %" PRIu64 ""),
params->volume_size,
dmd.size * SECTOR_SIZE);
/* there will be always 4 dm-zero segments: 3x metadata, 1x FS header */
for (i = 0; i < 3; i++) {
segments[num_segments].offset = params->metadata_offset[i] / SECTOR_SIZE;
@@ -1362,7 +1365,7 @@ static int _activate(struct crypt_device *cd,
crypt_get_cipher_spec(cd),
segments[i].iv_offset,
segments[i].iv_offset,
NULL, 0,
NULL, 0, 0,
params->sector_size);
if (r)
goto out;
@@ -1384,60 +1387,31 @@ static int _activate(struct crypt_device *cd,
log_err(cd, _("Cannot activate device, kernel dm-crypt is missing support for BITLK Elephant diffuser."));
r = -ENOTSUP;
}
if ((dmd.flags & CRYPT_ACTIVATE_IV_LARGE_SECTORS) && !(dmt_flags & DM_SECTOR_SIZE_SUPPORTED)) {
log_err(cd, _("Cannot activate device, kernel dm-crypt is missing support for large sector size."));
r = -ENOTSUP;
}
if (dm_flags(cd, DM_ZERO, &dmt_flags) < 0) {
log_err(cd, _("Cannot activate device, kernel dm-zero module is missing."));
r = -ENOTSUP;
}
}
out:
dm_targets_free(cd, &dmd);
return r;
}
int BITLK_activate_by_passphrase(struct crypt_device *cd,
const char *name,
const char *password,
size_t passwordLen,
const struct bitlk_metadata *params,
uint32_t flags)
{
int r = 0;
struct volume_key *open_fvek_key = NULL;
r = _activate_check(cd, params);
if (r)
return r;
r = BITLK_get_volume_key(cd, password, passwordLen, params, &open_fvek_key);
if (r < 0)
goto out;
/* Password verify only */
if (!name)
goto out;
r = _activate(cd, name, open_fvek_key, params, flags);
out:
crypt_free_volume_key(open_fvek_key);
return r;
}
int BITLK_activate_by_volume_key(struct crypt_device *cd,
const char *name,
const char *volume_key,
size_t volume_key_size,
struct volume_key *vk,
const struct bitlk_metadata *params,
uint32_t flags)
{
int r = 0;
struct volume_key *open_fvek_key = NULL;
int r;
r = _activate_check(cd, params);
if (r)
return r;
open_fvek_key = crypt_alloc_volume_key(volume_key_size, volume_key);
if (!open_fvek_key)
return -ENOMEM;
r = _activate(cd, name, open_fvek_key, params, flags);
crypt_free_volume_key(open_fvek_key);
return r;
return _activate(cd, name, vk, params, flags);
}

View File

@@ -1,23 +1,10 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* BITLK (BitLocker-compatible) header definition
*
* Copyright (C) 2019-2021 Red Hat, Inc. All rights reserved.
* Copyright (C) 2019-2021 Milan Broz
* Copyright (C) 2019-2021 Vojtech Trefny
*
* This file is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this file; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* Copyright (C) 2019-2025 Red Hat, Inc. All rights reserved.
* Copyright (C) 2019-2025 Milan Broz
* Copyright (C) 2019-2025 Vojtech Trefny
*/
#ifndef _CRYPTSETUP_BITLK_H
@@ -61,6 +48,7 @@ typedef enum {
BITLK_ENTRY_TYPE_STARTUP_KEY = 0x0006,
BITLK_ENTRY_TYPE_DESCRIPTION = 0x0007,
BITLK_ENTRY_TYPE_VOLUME_HEADER = 0x000f,
BITLK_ENTRY_TYPE_VOLUME_GUID = 0x0019,
} BITLKFVEEntryType;
typedef enum {
@@ -76,6 +64,8 @@ typedef enum {
BITLK_ENTRY_VALUE_EXTERNAL_KEY = 0x0009,
BITLK_ENTRY_VALUE_OFFSET_SIZE = 0x000f,
BITLK_ENTRY_VALUE_RECOVERY_TIME = 0x015,
BITLK_ENTRY_VALUE_GUID = 0x0017,
BITLK_ENTRY_VALUE_HINT = 0x0018,
} BITLKFVEEntryValue;
struct bitlk_vmk {
@@ -97,6 +87,7 @@ struct bitlk_fvek {
struct bitlk_metadata {
uint16_t sector_size;
uint64_t volume_size;
bool togo;
bool state;
BITLKEncryptionType type;
@@ -124,17 +115,9 @@ int BITLK_get_volume_key(struct crypt_device *cd,
const struct bitlk_metadata *params,
struct volume_key **open_fvek_key);
int BITLK_activate_by_passphrase(struct crypt_device *cd,
const char *name,
const char *password,
size_t passwordLen,
const struct bitlk_metadata *params,
uint32_t flags);
int BITLK_activate_by_volume_key(struct crypt_device *cd,
const char *name,
const char *volume_key,
size_t volume_key_size,
struct volume_key *vk,
const struct bitlk_metadata *params,
uint32_t flags);

View File

@@ -10,13 +10,13 @@
#include <stdint.h>
#include <sys/param.h>
#if defined(HAVE_BYTESWAP_H)
#if HAVE_BYTESWAP_H
# include <byteswap.h>
#endif
#if defined(HAVE_ENDIAN_H)
#if HAVE_ENDIAN_H
# include <endian.h>
#elif defined(HAVE_SYS_ENDIAN_H) /* BSDs have them here */
#elif HAVE_SYS_ENDIAN_H /* BSDs have them here */
# include <sys/endian.h>
#endif

View File

@@ -1,23 +1,10 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* cryptsetup plain device helper functions
*
* Copyright (C) 2004 Jana Saout <jana@saout.de>
* Copyright (C) 2010-2021 Red Hat, Inc. All rights reserved.
* Copyright (C) 2010-2021 Milan Broz
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* Copyright (C) 2010-2025 Red Hat, Inc. All rights reserved.
* Copyright (C) 2010-2025 Milan Broz
*/
#include <string.h>
@@ -105,7 +92,7 @@ int crypt_plain_hash(struct crypt_device *cd,
log_dbg(cd, "Too short plain passphrase.");
return -EINVAL;
}
memcpy(key, passphrase, hash_size);
crypt_safe_memcpy(key, passphrase, hash_size);
r = 0;
} else
r = hash(hash_name_buf, hash_size, key, passphrase_size, passphrase);

View File

@@ -9,9 +9,12 @@ libcrypto_backend_la_SOURCES = \
lib/crypto_backend/crypto_storage.c \
lib/crypto_backend/pbkdf_check.c \
lib/crypto_backend/crc32.c \
lib/crypto_backend/base64.c \
lib/crypto_backend/utf8.c \
lib/crypto_backend/argon2_generic.c \
lib/crypto_backend/cipher_generic.c \
lib/crypto_backend/cipher_check.c
lib/crypto_backend/cipher_check.c \
lib/crypto_backend/memutils.c
if CRYPTO_BACKEND_GCRYPT
libcrypto_backend_la_SOURCES += lib/crypto_backend/crypto_gcrypt.c
@@ -28,6 +31,9 @@ endif
if CRYPTO_BACKEND_NETTLE
libcrypto_backend_la_SOURCES += lib/crypto_backend/crypto_nettle.c
endif
if CRYPTO_BACKEND_MBEDTLS
libcrypto_backend_la_SOURCES += lib/crypto_backend/crypto_mbedtls.c
endif
if CRYPTO_INTERNAL_PBKDF2
libcrypto_backend_la_SOURCES += lib/crypto_backend/pbkdf2_generic.c

View File

@@ -360,7 +360,7 @@ int blake2b_long(void *pout, size_t outlen, const void *in, size_t inlen) {
TRY(blake2b_final(&blake_state, out, outlen));
} else {
uint32_t toproduce;
uint8_t out_buffer[BLAKE2B_OUTBYTES];
uint8_t out_buffer[BLAKE2B_OUTBYTES] = {0};
uint8_t in_buffer[BLAKE2B_OUTBYTES];
TRY(blake2b_init(&blake_state, BLAKE2B_OUTBYTES));
TRY(blake2b_update(&blake_state, outlen_bytes, sizeof(outlen_bytes)));

View File

@@ -120,18 +120,24 @@ void free_memory(const argon2_context *context, uint8_t *memory,
}
}
void NOT_OPTIMIZED secure_wipe_memory(void *v, size_t n) {
#if defined(_MSC_VER) && VC_GE_2005(_MSC_VER)
void secure_wipe_memory(void *v, size_t n) {
SecureZeroMemory(v, n);
}
#elif defined memset_s
void secure_wipe_memory(void *v, size_t n) {
memset_s(v, n, 0, n);
#elif defined(HAVE_EXPLICIT_BZERO)
}
#elif HAVE_EXPLICIT_BZERO
void secure_wipe_memory(void *v, size_t n) {
explicit_bzero(v, n);
}
#else
void NOT_OPTIMIZED secure_wipe_memory(void *v, size_t n) {
static void *(*const volatile memset_sec)(void *, int, size_t) = &memset;
memset_sec(v, 0, n);
#endif
}
#endif
/* Memory clear flag defaults to true. */
int FLAG_clear_internal_memory = 1;
@@ -273,7 +279,6 @@ static void *fill_segment_thr(void *thread_data)
{
argon2_thread_data *my_data = thread_data;
fill_segment(my_data->instance_ptr, my_data->pos);
argon2_thread_exit();
return 0;
}
@@ -351,12 +356,9 @@ static int fill_memory_blocks_mt(argon2_instance_t *instance) {
}
fail:
if (thread != NULL) {
free(thread);
}
if (thr_data != NULL) {
free(thr_data);
}
free(thread);
free(thr_data);
return rc;
}

View File

@@ -83,7 +83,7 @@
static int b64_byte_to_char(unsigned x) {
return (LT(x, 26) & (x + 'A')) |
(GE(x, 26) & LT(x, 52) & (x + ('a' - 26))) |
(GE(x, 52) & LT(x, 62) & (x + ('0' - 52))) | (EQ(x, 62) & '+') |
(GE(x, 52) & LT(x, 62) & (x - (52 - '0'))) | (EQ(x, 62) & '+') |
(EQ(x, 63) & '/');
}

View File

@@ -0,0 +1,28 @@
libargon2_sources = files(
'blake2/blake2b.c',
'argon2.c',
'core.c',
'encoding.c',
'thread.c',
)
if use_internal_sse_argon2
libargon2_sources += files(
'opt.c',
)
else
libargon2_sources += files(
'ref.c',
)
endif
libargon2 = static_library('argon2',
libargon2_sources,
override_options : ['c_std=c89', 'optimization=3'],
build_by_default : false,
include_directories: include_directories(
'blake2',
),
dependencies : [
threads,
])

View File

@@ -46,12 +46,4 @@ int argon2_thread_join(argon2_thread_handle_t handle) {
#endif
}
void argon2_thread_exit(void) {
#if defined(_WIN32)
_endthreadex(0);
#else
pthread_exit(NULL);
#endif
}
#endif /* ARGON2_NO_THREADS */

View File

@@ -58,10 +58,5 @@ int argon2_thread_create(argon2_thread_handle_t *handle,
*/
int argon2_thread_join(argon2_thread_handle_t handle);
/* Terminate the current thread. Must be run inside a thread created by
* argon2_thread_create.
*/
void argon2_thread_exit(void);
#endif /* ARGON2_NO_THREADS */
#endif

View File

@@ -1,42 +1,30 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* Argon2 PBKDF2 library wrapper
*
* Copyright (C) 2016-2021 Red Hat, Inc. All rights reserved.
* Copyright (C) 2016-2021 Milan Broz
*
* This file is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this file; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* Copyright (C) 2016-2025 Red Hat, Inc. All rights reserved.
* Copyright (C) 2016-2025 Milan Broz
*/
#include <errno.h>
#include "crypto_backend_internal.h"
/* Check for HAVE_ARGON2_H is run only if libargon2 code is used */
#if USE_INTERNAL_ARGON2 || HAVE_ARGON2_H
#define CONST_CAST(x) (x)(uintptr_t)
#if HAVE_ARGON2_H
#include <argon2.h>
#else
#include "argon2/argon2.h"
#endif
#define CONST_CAST(x) (x)(uintptr_t)
int argon2(const char *type, const char *password, size_t password_length,
const char *salt, size_t salt_length,
char *key, size_t key_length,
uint32_t iterations, uint32_t memory, uint32_t parallel)
{
#if !USE_INTERNAL_ARGON2 && !HAVE_ARGON2_H
return -EINVAL;
#else
argon2_type atype;
argon2_context context = {
.flags = ARGON2_DEFAULT_FLAGS,
@@ -54,6 +42,9 @@ int argon2(const char *type, const char *password, size_t password_length,
};
int r;
/* This code must not be run if crypt backend library natively supports Argon2 */
assert(!(crypt_backend_flags() & CRYPT_BACKEND_ARGON2));
if (!strcmp(type, "argon2i"))
atype = Argon2_i;
else if(!strcmp(type, "argon2id"))
@@ -75,5 +66,33 @@ int argon2(const char *type, const char *password, size_t password_length,
}
return r;
#endif
}
#else /* USE_INTERNAL_ARGON2 || HAVE_ARGON2_H */
#pragma GCC diagnostic ignored "-Wunused-parameter"
int argon2(const char *type, const char *password, size_t password_length,
const char *salt, size_t salt_length,
char *key, size_t key_length,
uint32_t iterations, uint32_t memory, uint32_t parallel)
{
return -EINVAL;
}
#endif
/* Additional string for crypt backend version */
const char *crypt_argon2_version(void)
{
const char *version = "";
if (crypt_backend_flags() & CRYPT_BACKEND_ARGON2)
return version;
#if HAVE_ARGON2_H /* this has priority over internal argon2 */
version = " [external libargon2]";
#elif USE_INTERNAL_ARGON2
version = " [cryptsetup libargon2]";
#endif
return version;
}

263
lib/crypto_backend/base64.c Normal file
View File

@@ -0,0 +1,263 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* Base64 "Not encryption" helpers, copied and adapted from systemd project.
*
* Copyright (C) 2010 Lennart Poettering
*
* cryptsetup related changes
* Copyright (C) 2021-2025 Milan Broz
*/
#include <errno.h>
#include <stdlib.h>
#include <limits.h>
#include "crypto_backend.h"
#define WHITESPACE " \t\n\r"
/* https://tools.ietf.org/html/rfc4648#section-4 */
static char base64char(int x)
{
static const char table[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
return table[x & 63];
}
static int unbase64char(char c)
{
unsigned offset;
if (c >= 'A' && c <= 'Z')
return c - 'A';
offset = 'Z' - 'A' + 1;
if (c >= 'a' && c <= 'z')
return c - 'a' + offset;
offset += 'z' - 'a' + 1;
if (c >= '0' && c <= '9')
return c - '0' + offset;
offset += '9' - '0' + 1;
if (c == '+')
return offset;
offset++;
if (c == '/')
return offset;
return -EINVAL;
}
int crypt_base64_encode(char **out, size_t *out_length, const char *in, size_t in_length)
{
char *r, *z;
const uint8_t *x;
assert(in || in_length == 0);
assert(out);
/* three input bytes makes four output bytes, padding is added so we must round up */
z = r = malloc(4 * (in_length + 2) / 3 + 1);
if (!r)
return -ENOMEM;
for (x = (const uint8_t *)in; x < (const uint8_t*)in + (in_length / 3) * 3; x += 3) {
/* x[0] == XXXXXXXX; x[1] == YYYYYYYY; x[2] == ZZZZZZZZ */
*(z++) = base64char(x[0] >> 2); /* 00XXXXXX */
*(z++) = base64char((x[0] & 3) << 4 | x[1] >> 4); /* 00XXYYYY */
*(z++) = base64char((x[1] & 15) << 2 | x[2] >> 6); /* 00YYYYZZ */
*(z++) = base64char(x[2] & 63); /* 00ZZZZZZ */
}
switch (in_length % 3) {
case 2:
*(z++) = base64char(x[0] >> 2); /* 00XXXXXX */
*(z++) = base64char((x[0] & 3) << 4 | x[1] >> 4); /* 00XXYYYY */
*(z++) = base64char((x[1] & 15) << 2); /* 00YYYY00 */
*(z++) = '=';
break;
case 1:
*(z++) = base64char(x[0] >> 2); /* 00XXXXXX */
*(z++) = base64char((x[0] & 3) << 4); /* 00XX0000 */
*(z++) = '=';
*(z++) = '=';
break;
}
*z = 0;
*out = r;
if (out_length)
*out_length = z - r;
return 0;
}
static int unbase64_next(const char **p, size_t *l)
{
int ret;
assert(p);
assert(l);
/* Find the next non-whitespace character, and decode it. If we find padding, we return it as INT_MAX. We
* greedily skip all preceding and all following whitespace. */
for (;;) {
if (*l == 0)
return -EPIPE;
if (!strchr(WHITESPACE, **p))
break;
/* Skip leading whitespace */
(*p)++, (*l)--;
}
if (**p == '=')
ret = INT_MAX; /* return padding as INT_MAX */
else {
ret = unbase64char(**p);
if (ret < 0)
return ret;
}
for (;;) {
(*p)++, (*l)--;
if (*l == 0)
break;
if (!strchr(WHITESPACE, **p))
break;
/* Skip following whitespace */
}
return ret;
}
int crypt_base64_decode(char **out, size_t *out_length, const char *in, size_t in_length)
{
uint8_t *buf = NULL;
const char *x;
uint8_t *z;
size_t len;
int r;
assert(in || in_length == 0);
assert(out);
assert(out_length);
if (in_length == (size_t) -1)
in_length = strlen(in);
/* A group of four input bytes needs three output bytes, in case of padding we need to add two or three extra
* bytes. Note that this calculation is an upper boundary, as we ignore whitespace while decoding */
len = (in_length / 4) * 3 + (in_length % 4 != 0 ? (in_length % 4) - 1 : 0);
buf = malloc(len + 1);
if (!buf)
return -ENOMEM;
for (x = in, z = buf;;) {
int a, b, c, d; /* a == 00XXXXXX; b == 00YYYYYY; c == 00ZZZZZZ; d == 00WWWWWW */
a = unbase64_next(&x, &in_length);
if (a == -EPIPE) /* End of string */
break;
if (a < 0) {
r = a;
goto err;
}
if (a == INT_MAX) { /* Padding is not allowed at the beginning of a 4ch block */
r = -EINVAL;
goto err;
}
b = unbase64_next(&x, &in_length);
if (b < 0) {
r = b;
goto err;
}
if (b == INT_MAX) { /* Padding is not allowed at the second character of a 4ch block either */
r = -EINVAL;
goto err;
}
c = unbase64_next(&x, &in_length);
if (c < 0) {
r = c;
goto err;
}
d = unbase64_next(&x, &in_length);
if (d < 0) {
r = d;
goto err;
}
if (c == INT_MAX) { /* Padding at the third character */
if (d != INT_MAX) { /* If the third character is padding, the fourth must be too */
r = -EINVAL;
goto err;
}
/* b == 00YY0000 */
if (b & 15) {
r = -EINVAL;
goto err;
}
if (in_length > 0) { /* Trailing rubbish? */
r = -ENAMETOOLONG;
goto err;
}
*(z++) = (uint8_t) a << 2 | (uint8_t) (b >> 4); /* XXXXXXYY */
break;
}
if (d == INT_MAX) {
/* c == 00ZZZZ00 */
if (c & 3) {
r = -EINVAL;
goto err;
}
if (in_length > 0) { /* Trailing rubbish? */
r = -ENAMETOOLONG;
goto err;
}
*(z++) = (uint8_t) a << 2 | (uint8_t) b >> 4; /* XXXXXXYY */
*(z++) = (uint8_t) b << 4 | (uint8_t) c >> 2; /* YYYYZZZZ */
break;
}
*(z++) = (uint8_t) a << 2 | (uint8_t) b >> 4; /* XXXXXXYY */
*(z++) = (uint8_t) b << 4 | (uint8_t) c >> 2; /* YYYYZZZZ */
*(z++) = (uint8_t) c << 6 | (uint8_t) d; /* ZZWWWWWW */
}
*z = 0;
*out_length = (size_t) (z - buf);
*out = (char *)buf;
return 0;
err:
free(buf);
/* Ignore other errors in crypt_backend */
if (r != -ENOMEM)
r = -EINVAL;
return r;
}

View File

@@ -1,22 +1,9 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* Cipher performance check
*
* Copyright (C) 2018-2021 Red Hat, Inc. All rights reserved.
* Copyright (C) 2018-2021 Milan Broz
*
* This file is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this file; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* Copyright (C) 2018-2025 Red Hat, Inc. All rights reserved.
* Copyright (C) 2018-2025 Milan Broz
*/
#include <errno.h>
@@ -55,43 +42,36 @@ static int time_ms(struct timespec *start, struct timespec *end, double *ms)
return 0;
}
static int cipher_perf_one(const char *name, const char *mode, char *buffer, size_t buffer_size,
const char *key, size_t key_size, const char *iv, size_t iv_size, int enc)
static int cipher_perf_one(struct crypt_cipher_kernel *cipher, char *buffer, size_t buffer_size,
const char *iv, size_t iv_size, int enc)
{
struct crypt_cipher_kernel cipher;
size_t done = 0, block = CIPHER_BLOCK_BYTES;
int r;
if (buffer_size < block)
block = buffer_size;
r = crypt_cipher_init_kernel(&cipher, name, mode, key, key_size);
if (r < 0)
return r;
while (done < buffer_size) {
if ((done + block) > buffer_size)
block = buffer_size - done;
if (enc)
r = crypt_cipher_encrypt_kernel(&cipher, &buffer[done], &buffer[done],
r = crypt_cipher_encrypt_kernel(cipher, &buffer[done], &buffer[done],
block, iv, iv_size);
else
r = crypt_cipher_decrypt_kernel(&cipher, &buffer[done], &buffer[done],
r = crypt_cipher_decrypt_kernel(cipher, &buffer[done], &buffer[done],
block, iv, iv_size);
if (r < 0)
break;
return r;
done += block;
}
crypt_cipher_destroy_kernel(&cipher);
return r;
return 0;
}
static int cipher_measure(const char *name, const char *mode, char *buffer, size_t buffer_size,
const char *key, size_t key_size, const char *iv, size_t iv_size,
int encrypt, double *ms)
static int cipher_measure(struct crypt_cipher_kernel *cipher, char *buffer, size_t buffer_size,
const char *iv, size_t iv_size, int encrypt, double *ms)
{
struct timespec start, end;
int r;
@@ -103,7 +83,7 @@ static int cipher_measure(const char *name, const char *mode, char *buffer, size
if (clock_gettime(CLOCK_MONOTONIC_RAW, &start) < 0)
return -EINVAL;
r = cipher_perf_one(name, mode, buffer, buffer_size, key, key_size, iv, iv_size, encrypt);
r = cipher_perf_one(cipher, buffer, buffer_size, iv, iv_size, encrypt);
if (r < 0)
return r;
@@ -131,15 +111,20 @@ int crypt_cipher_perf_kernel(const char *name, const char *mode, char *buffer, s
const char *key, size_t key_size, const char *iv, size_t iv_size,
double *encryption_mbs, double *decryption_mbs)
{
struct crypt_cipher_kernel cipher;
double ms_enc, ms_dec, ms;
int r, repeat_enc, repeat_dec;
r = crypt_cipher_init_kernel(&cipher, name, mode, key, key_size);
if (r < 0)
return r;
ms_enc = 0.0;
repeat_enc = 1;
while (ms_enc < 1000.0) {
r = cipher_measure(name, mode, buffer, buffer_size, key, key_size, iv, iv_size, 1, &ms);
r = cipher_measure(&cipher, buffer, buffer_size, iv, iv_size, 1, &ms);
if (r < 0)
return r;
goto out;
ms_enc += ms;
repeat_enc++;
}
@@ -147,9 +132,9 @@ int crypt_cipher_perf_kernel(const char *name, const char *mode, char *buffer, s
ms_dec = 0.0;
repeat_dec = 1;
while (ms_dec < 1000.0) {
r = cipher_measure(name, mode, buffer, buffer_size, key, key_size, iv, iv_size, 0, &ms);
r = cipher_measure(&cipher, buffer, buffer_size, iv, iv_size, 0, &ms);
if (r < 0)
return r;
goto out;
ms_dec += ms;
repeat_dec++;
}
@@ -157,5 +142,8 @@ int crypt_cipher_perf_kernel(const char *name, const char *mode, char *buffer, s
*encryption_mbs = speed_mbs(buffer_size * repeat_enc, ms_enc);
*decryption_mbs = speed_mbs(buffer_size * repeat_dec, ms_dec);
return 0;
r = 0;
out:
crypt_cipher_destroy_kernel(&cipher);
return r;
}

View File

@@ -1,27 +1,13 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* Linux kernel cipher generic utilities
*
* Copyright (C) 2018-2021 Red Hat, Inc. All rights reserved.
* Copyright (C) 2018-2021 Milan Broz
*
* This file is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this file; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* Copyright (C) 2018-2025 Red Hat, Inc. All rights reserved.
* Copyright (C) 2018-2025 Milan Broz
*/
#include <string.h>
#include <stdbool.h>
#include <errno.h>
#include <strings.h>
#include "crypto_backend.h"
struct cipher_alg {
@@ -51,6 +37,7 @@ static const struct cipher_alg cipher_algs[] = {
{ "xchacha12,aes", "adiantum", 32, false },
{ "xchacha20,aes", "adiantum", 32, false },
{ "sm4", NULL, 16, false },
{ "aria", NULL, 16, false },
{ NULL, NULL, 0, false }
};
@@ -75,6 +62,9 @@ int crypt_cipher_ivsize(const char *name, const char *mode)
if (!ca)
return -EINVAL;
if (mode && !strcasecmp(mode, "hctr2"))
return 32;
if (mode && !strcasecmp(mode, "ecb"))
return 0;

View File

@@ -38,8 +38,6 @@
*
*/
#include <stdio.h>
#include "crypto_backend.h"
static const uint32_t crc32_tab[] = {
@@ -97,18 +95,87 @@ static const uint32_t crc32_tab[] = {
0x2d02ef8dL
};
static const uint32_t crc32c_tab[] = {
0x00000000L, 0xF26B8303L, 0xE13B70F7L, 0x1350F3F4L, 0xC79A971FL,
0x35F1141CL, 0x26A1E7E8L, 0xD4CA64EBL, 0x8AD958CFL, 0x78B2DBCCL,
0x6BE22838L, 0x9989AB3BL, 0x4D43CFD0L, 0xBF284CD3L, 0xAC78BF27L,
0x5E133C24L, 0x105EC76FL, 0xE235446CL, 0xF165B798L, 0x030E349BL,
0xD7C45070L, 0x25AFD373L, 0x36FF2087L, 0xC494A384L, 0x9A879FA0L,
0x68EC1CA3L, 0x7BBCEF57L, 0x89D76C54L, 0x5D1D08BFL, 0xAF768BBCL,
0xBC267848L, 0x4E4DFB4BL, 0x20BD8EDEL, 0xD2D60DDDL, 0xC186FE29L,
0x33ED7D2AL, 0xE72719C1L, 0x154C9AC2L, 0x061C6936L, 0xF477EA35L,
0xAA64D611L, 0x580F5512L, 0x4B5FA6E6L, 0xB93425E5L, 0x6DFE410EL,
0x9F95C20DL, 0x8CC531F9L, 0x7EAEB2FAL, 0x30E349B1L, 0xC288CAB2L,
0xD1D83946L, 0x23B3BA45L, 0xF779DEAEL, 0x05125DADL, 0x1642AE59L,
0xE4292D5AL, 0xBA3A117EL, 0x4851927DL, 0x5B016189L, 0xA96AE28AL,
0x7DA08661L, 0x8FCB0562L, 0x9C9BF696L, 0x6EF07595L, 0x417B1DBCL,
0xB3109EBFL, 0xA0406D4BL, 0x522BEE48L, 0x86E18AA3L, 0x748A09A0L,
0x67DAFA54L, 0x95B17957L, 0xCBA24573L, 0x39C9C670L, 0x2A993584L,
0xD8F2B687L, 0x0C38D26CL, 0xFE53516FL, 0xED03A29BL, 0x1F682198L,
0x5125DAD3L, 0xA34E59D0L, 0xB01EAA24L, 0x42752927L, 0x96BF4DCCL,
0x64D4CECFL, 0x77843D3BL, 0x85EFBE38L, 0xDBFC821CL, 0x2997011FL,
0x3AC7F2EBL, 0xC8AC71E8L, 0x1C661503L, 0xEE0D9600L, 0xFD5D65F4L,
0x0F36E6F7L, 0x61C69362L, 0x93AD1061L, 0x80FDE395L, 0x72966096L,
0xA65C047DL, 0x5437877EL, 0x4767748AL, 0xB50CF789L, 0xEB1FCBADL,
0x197448AEL, 0x0A24BB5AL, 0xF84F3859L, 0x2C855CB2L, 0xDEEEDFB1L,
0xCDBE2C45L, 0x3FD5AF46L, 0x7198540DL, 0x83F3D70EL, 0x90A324FAL,
0x62C8A7F9L, 0xB602C312L, 0x44694011L, 0x5739B3E5L, 0xA55230E6L,
0xFB410CC2L, 0x092A8FC1L, 0x1A7A7C35L, 0xE811FF36L, 0x3CDB9BDDL,
0xCEB018DEL, 0xDDE0EB2AL, 0x2F8B6829L, 0x82F63B78L, 0x709DB87BL,
0x63CD4B8FL, 0x91A6C88CL, 0x456CAC67L, 0xB7072F64L, 0xA457DC90L,
0x563C5F93L, 0x082F63B7L, 0xFA44E0B4L, 0xE9141340L, 0x1B7F9043L,
0xCFB5F4A8L, 0x3DDE77ABL, 0x2E8E845FL, 0xDCE5075CL, 0x92A8FC17L,
0x60C37F14L, 0x73938CE0L, 0x81F80FE3L, 0x55326B08L, 0xA759E80BL,
0xB4091BFFL, 0x466298FCL, 0x1871A4D8L, 0xEA1A27DBL, 0xF94AD42FL,
0x0B21572CL, 0xDFEB33C7L, 0x2D80B0C4L, 0x3ED04330L, 0xCCBBC033L,
0xA24BB5A6L, 0x502036A5L, 0x4370C551L, 0xB11B4652L, 0x65D122B9L,
0x97BAA1BAL, 0x84EA524EL, 0x7681D14DL, 0x2892ED69L, 0xDAF96E6AL,
0xC9A99D9EL, 0x3BC21E9DL, 0xEF087A76L, 0x1D63F975L, 0x0E330A81L,
0xFC588982L, 0xB21572C9L, 0x407EF1CAL, 0x532E023EL, 0xA145813DL,
0x758FE5D6L, 0x87E466D5L, 0x94B49521L, 0x66DF1622L, 0x38CC2A06L,
0xCAA7A905L, 0xD9F75AF1L, 0x2B9CD9F2L, 0xFF56BD19L, 0x0D3D3E1AL,
0x1E6DCDEEL, 0xEC064EEDL, 0xC38D26C4L, 0x31E6A5C7L, 0x22B65633L,
0xD0DDD530L, 0x0417B1DBL, 0xF67C32D8L, 0xE52CC12CL, 0x1747422FL,
0x49547E0BL, 0xBB3FFD08L, 0xA86F0EFCL, 0x5A048DFFL, 0x8ECEE914L,
0x7CA56A17L, 0x6FF599E3L, 0x9D9E1AE0L, 0xD3D3E1ABL, 0x21B862A8L,
0x32E8915CL, 0xC083125FL, 0x144976B4L, 0xE622F5B7L, 0xF5720643L,
0x07198540L, 0x590AB964L, 0xAB613A67L, 0xB831C993L, 0x4A5A4A90L,
0x9E902E7BL, 0x6CFBAD78L, 0x7FAB5E8CL, 0x8DC0DD8FL, 0xE330A81AL,
0x115B2B19L, 0x020BD8EDL, 0xF0605BEEL, 0x24AA3F05L, 0xD6C1BC06L,
0xC5914FF2L, 0x37FACCF1L, 0x69E9F0D5L, 0x9B8273D6L, 0x88D28022L,
0x7AB90321L, 0xAE7367CAL, 0x5C18E4C9L, 0x4F48173DL, 0xBD23943EL,
0xF36E6F75L, 0x0105EC76L, 0x12551F82L, 0xE03E9C81L, 0x34F4F86AL,
0xC69F7B69L, 0xD5CF889DL, 0x27A40B9EL, 0x79B737BAL, 0x8BDCB4B9L,
0x988C474DL, 0x6AE7C44EL, 0xBE2DA0A5L, 0x4C4623A6L, 0x5F16D052L,
0xAD7D5351L
};
/*
* This a generic crc32() function, it takes seed as an argument,
* and does __not__ xor at the end. Then individual users can do
* whatever they need.
*/
uint32_t crypt_crc32(uint32_t seed, const unsigned char *buf, size_t len)
static uint32_t compute_crc32(
const uint32_t *crc32_table,
uint32_t seed,
const unsigned char *buf,
size_t len)
{
uint32_t crc = seed;
const unsigned char *p = buf;
while(len-- > 0)
crc = crc32_tab[(crc ^ *p++) & 0xff] ^ (crc >> 8);
crc = crc32_table[(crc ^ *p++) & 0xff] ^ (crc >> 8);
return crc;
}
uint32_t crypt_crc32(uint32_t seed, const unsigned char *buf, size_t len)
{
return compute_crc32(crc32_tab, seed, buf, len);
}
uint32_t crypt_crc32c(uint32_t seed, const unsigned char *buf, size_t len)
{
return compute_crc32(crc32c_tab, seed, buf, len);
}

Some files were not shown because too many files have changed in this diff Show More