summaryrefslogtreecommitdiff
path: root/src/shared/cryptsetup-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-08-19 22:15:12 +0200
committerLennart Poettering <lennart@poettering.net>2022-09-08 16:34:27 +0200
commitfdf6c27cbaea5af63b474b6160c1effa5f3a3b46 (patch)
treeca1f8194933579d19c3b9b409b78b419ff150c1e /src/shared/cryptsetup-util.c
parentdc63b2c90940c683a58195f43e59e1c08178629d (diff)
downloadsystemd-fdf6c27cbaea5af63b474b6160c1effa5f3a3b46.tar.gz
tpm2-util: add common parser for the LUKS2 TPM2 JSON structure
This splits out the JSON parser used by the systemd-cryptsetup code. This is preparation for later work to reuse it in the tpm2 cryptsetup token module, which currently uses a separate but very similar parser for the same data. No change in behaviour.
Diffstat (limited to 'src/shared/cryptsetup-util.c')
-rw-r--r--src/shared/cryptsetup-util.c46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/shared/cryptsetup-util.c b/src/shared/cryptsetup-util.c
index b93f702aff..da6dcb2f09 100644
--- a/src/shared/cryptsetup-util.c
+++ b/src/shared/cryptsetup-util.c
@@ -1,12 +1,12 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
-#if HAVE_LIBCRYPTSETUP
#include "alloc-util.h"
#include "cryptsetup-util.h"
#include "dlfcn-util.h"
#include "log.h"
#include "parse-util.h"
+#if HAVE_LIBCRYPTSETUP
static void *cryptsetup_dl = NULL;
int (*sym_crypt_activate_by_passphrase)(struct crypt_device *cd, const char *name, int keyslot, const char *passphrase, size_t passphrase_size, uint32_t flags);
@@ -224,6 +224,28 @@ int cryptsetup_get_token_as_json(
return 0;
}
+int cryptsetup_add_token_json(struct crypt_device *cd, JsonVariant *v) {
+ _cleanup_free_ char *text = NULL;
+ int r;
+
+ r = dlopen_cryptsetup();
+ if (r < 0)
+ return r;
+
+ r = json_variant_format(v, 0, &text);
+ if (r < 0)
+ return log_debug_errno(r, "Failed to format token data for LUKS: %m");
+
+ log_debug("Adding token text <%s>", text);
+
+ r = sym_crypt_token_json_set(cd, CRYPT_ANY_TOKEN, text);
+ if (r < 0)
+ return log_debug_errno(r, "Failed to write token data to LUKS: %m");
+
+ return 0;
+}
+#endif
+
int cryptsetup_get_keyslot_from_token(JsonVariant *v) {
int keyslot, r;
JsonVariant *w;
@@ -252,25 +274,3 @@ int cryptsetup_get_keyslot_from_token(JsonVariant *v) {
return keyslot;
}
-
-int cryptsetup_add_token_json(struct crypt_device *cd, JsonVariant *v) {
- _cleanup_free_ char *text = NULL;
- int r;
-
- r = dlopen_cryptsetup();
- if (r < 0)
- return r;
-
- r = json_variant_format(v, 0, &text);
- if (r < 0)
- return log_debug_errno(r, "Failed to format token data for LUKS: %m");
-
- log_debug("Adding token text <%s>", text);
-
- r = sym_crypt_token_json_set(cd, CRYPT_ANY_TOKEN, text);
- if (r < 0)
- return log_debug_errno(r, "Failed to write token data to LUKS: %m");
-
- return 0;
-}
-#endif