Commit Graph

386 Commits

Author SHA1 Message Date
Frantisek Sumsal
dfe7cfe4fb cryptsetup: fix build with -Db_ndebug=true
```
 ...
 ../src/cryptsetup/cryptsetup-tokens/cryptsetup-token-systemd-fido2.c:33:13: error: variable 'r' set but not used [-Werror,-Wunused-but-set-variable]
         int r;
             ^
 1 error generated.
 ...
 ../src/cryptsetup/cryptsetup-tokens/cryptsetup-token-systemd-pkcs11.c:34:13: error: variable 'r' set but not used [-Werror,-Wunused-but-set-variable]
         int r;
             ^
 1 error generated.
 ninja: build stopped: subcommand failed.
 + fatal ''\''meson compile'\'' failed with -Db_ndebug=true'
```
2022-05-21 23:27:24 +02:00
Lennart Poettering
d6d450074f Merge pull request #22919 from poettering/cryptsetup-tweaks
various minor tweaks to cryptsetup/veritysetup/integritysetup
2022-03-31 16:50:37 +02:00
Antonio Alvarez Feijoo
49be03838d cryptsetup: fall back to traditional unlocking if any TPM2 operation fails
If any TPM2 operation fails, the boot process should continue and
prompt for a text password (if configured to do so).

Fixes #22870
2022-03-31 14:58:21 +01:00
Lennart Poettering
542bb9be7c tree-wide: unify some code that looks for --help in the command line 2022-03-31 11:44:46 +02:00
Lennart Poettering
2e4aae981e cryptsetup: adjust some log levels
Let's upgrade log levels of some noteworthy messages from LOG_DEBUG to
LOG_NOTICE. These messages contain information that previous log
messages in the error path didn't say, namely that we'll now fall back
to traditional unlocking.

Note that this leaves similar log messages for cases where
TPM2/PKCS#11/FIDO2 support is disabled at build at LOG_DEBUG, since in
that case nothing really failed, we just systematically can't do
TPM2/PKCS#11/FIDO2 and hence it is pointless and not actionable for
users to do anything about it...
2022-03-31 11:24:07 +02:00
Lennart Poettering
2fabbad898 cryptsetup: add helper for mangling "none" option strings
let's unify some code here, and let's do so in cryptsetup-util.h so that
we can later reuse this in integritysetup/veritysetup
2022-03-31 11:24:01 +02:00
Lennart Poettering
dcbc38c916 cryptsetup: rename functions that try to do FIDO2/TPM2/PKCS#11 via cryptsetup plugins to say so
The are so many different flavours of functions that attach volumes,
hence say explicitly that these are about libcryptsetup plugins, and
nothing else.

Just some renaming, no code changes beyond that.
2022-03-31 11:23:16 +02:00
Zbigniew Jędrzejewski-Szmek
88a65c936e cryptsetup: shorten message a bit
If it is reported as missing, we don't need to say that we assume
it is missing.
2022-03-29 18:14:51 +02:00
Lennart Poettering
7be4b23649 efi-loader: split efi-api.[ch] from efi-loader.[ch]
Some refactoring: split efi-loader.[ch] in two: isolate the calls that
implement out boot loader interface spec, and those which implement
access to upstream UEFI firmware features.

They are quite different in nature and behaviour, and even semantically
it makes to keep these two separate. At the very least because the
previous name "efi-loader.[ch]" suggests all was about loader-specific
APIs, but much of it is generic uefi stuff...

While we are at it, I renamed a bunch of return parameters to follow our
usual ret_xyz naming. But besides renaming no real code changes.
2022-03-24 15:21:09 +01:00
Antonio Alvarez Feijoo
7500c6cbef cryptsetup: fix typo 2022-03-24 12:08:54 +00:00
Yu Watanabe
de010b0b2e strv: make iterator in STRV_FOREACH() declaread in the loop
This also avoids multiple evaluations in STRV_FOREACH_BACKWARDS()
2022-03-19 08:33:33 +09:00
Michael Biebl
ad337e55a3 tree-wide: fix duplicated words
the the
in in
not not
we we
2022-03-18 08:14:01 +09:00
Grigori Goronzy
4005d41ef0 cryptsetup: add manual TPM2 PIN configuration
Handle the case where TPM2 metadata is not available and explicitly
provided in crypttab. This adds a new "tpm2-pin" option to crypttab
options for this purpose.
2022-03-15 21:17:00 +01:00
Grigori Goronzy
1f895adac2 cryptsetup: add libcryptsetup TPM2 PIN support
This is unfinished: we don't have any way to actually query for PINs
interactively this way. It is similar to FIDO2 and PKCS#11 in this
regard.

Nonetheless, this code is capable of validating and dumping tokens, so
it is already useful as-is.
2022-03-15 21:17:00 +01:00
Grigori Goronzy
bea344a1a4 cryptsetup: add support for TPM2 pin
Extend cryptsetup for TPM2 pin entry, similar to FIDO2.
2022-03-15 21:17:00 +01:00
Grigori Goronzy
2f5a892aa0 tpm2: support policies with PIN
Modify TPM2 authentication policy to optionally include an authValue, i.e.
a password/PIN. We use the "PIN" terminology since it's used by other
systems such as Windows, even though the PIN is not necessarily numeric.

The pin is hashed via SHA256 to allow for arbitrary length PINs.

v2: fix tpm2_seal in sd-repart
v3: applied review feedback
2022-03-15 21:17:00 +01:00
Lennart Poettering
e99ca14741 env-util: replace unsetenv_erase() by new getenv_steal_erase() helper
The new helper combines a bunch of steps every invocation of
unsetenv_erase() did so far: getenv() + strdup() + unsetenv_erase().
Let's unify this into one helper that is harder to use incorrectly. It's
in inspired by TAKE_PTR() in a way: get the env var out and invalidate
where it was before.
2022-02-20 12:38:06 +09:00
Jan Janssen
b7de9651db generator: Rename password arg
This function does not expect a password, but a key file path. The
cryptsetup helper binary even calls it that.

No Code changes.

Follow up on: 6e41f4dd91
Fixes: https://github.com/systemd/systemd/security/code-scanning/81
2022-02-19 10:15:38 +01:00
Zbigniew Jędrzejewski-Szmek
c01543fdd5 meson: drop three more single-use convenience libraries
The way that the cryptsetup plugins were built was unnecessarilly complicated.
We would build three static libraries that would then be linked into dynamic
libraries. No need to do this.

While at it, let's use a convenience library to avoid compiling the shared code
more than once.

We want the output .so files to be located in the main build directory,
like with all consumable build artifacts, so we need to maintain the split
between src/cryptsetup/cryptsetup-token/meson.build and the main meson.build
file.

AFAICT, the build artifacts are the same: exported and undefined symbols are
identical. There is a tiny difference in size, but I think it might be caused
by a different build directory name.
2021-12-16 11:51:40 +01:00
Zbigniew Jędrzejewski-Szmek
718ca77232 shared/json: use int64_t instead of intmax_t
We were already asserting that the intmax_t and uintmax_t types
are the same as int64_t and uint64_t. Pretty much everywhere in
the code base we use the latter types. In principle intmax_t could
be something different on some new architecture, and then the code would
fail to compile or behave differently. We actually do not want the code
to behave differently on those architectures, because that'd break
interoperability. So let's just use int64_t/uint64_t since that's what
we indend to use.
2021-11-18 01:34:31 +01:00
Lennart Poettering
a2236110c3 cryptsetup: minor modernizations 2021-10-11 11:12:29 +02:00
Lennart Poettering
5cbe70af02 cryptsetup: add a configurable token waiting timeout
Let's add  configurable timeout how long to wait for FIDO2/PKCS#11
devices to show up. Once the timeout is hit, let's automatically revert
to querying via passphrase.

Fixes: #19739
2021-10-11 11:12:29 +02:00
Lennart Poettering
40091021c3 cryptsetup: before querying user for a PIN, check if a FIDO2 device is actually plugged in
Before we'd already ask for a PIN just because we know we'll need it
when the token is plugged in. We'd only the try to talk to the device
and notice it actually isn't plugged in. This is quite confusing, as
querying for the PIN suggests we already had a device we are talking to.

Let's hence check if there's actually device before we ask the PIN
question. And if there is none, let's immediately inform the caller, so
that they watch udev and retry once a device has shown up.
2021-10-11 11:12:29 +02:00
Lennart Poettering
64c590fb06 cryptsetup: optionally turn off token module support in libcryptsetup
This is useful for debugging purposes.
2021-10-11 11:12:29 +02:00
Lennart Poettering
92828080fb cryptsetup: don't repeat exact same code twice
let's move turning off of the cache bit into the for loop, so that we
can eliminate a copy of the loop body.
2021-10-11 11:12:29 +02:00