cryptenroll: Clean up includes

Split out of #37344.
This commit is contained in:
Daan De Meyer
2025-05-21 16:34:29 +02:00
committed by Yu Watanabe
parent 96fafb925c
commit fee4eaa1b7
17 changed files with 60 additions and 92 deletions

View File

@@ -1,17 +1,18 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "alloc-util.h"
#include "ask-password-api.h"
#include "cryptenroll-fido2.h"
#include "cryptsetup-fido2.h"
#include "cryptsetup-util.h"
#include "fido2-util.h"
#include "glyph-util.h"
#include "hexdecoct.h"
#include "iovec-util.h"
#include "json-util.h"
#include "libfido2-util.h"
#include "memory-util.h"
#include "pretty-print.h"
#include "random-util.h"
#include "string-util.h"
int load_volume_key_fido2(
struct crypt_device *cd,
@@ -20,6 +21,7 @@ int load_volume_key_fido2(
void *ret_vk,
size_t *ret_vks) {
#if HAVE_LIBFIDO2
_cleanup_(erase_and_freep) void *decrypted_key = NULL;
_cleanup_(erase_and_freep) char *passphrase = NULL;
size_t decrypted_key_size;
@@ -63,6 +65,9 @@ int load_volume_key_fido2(
return log_error_errno(r, "Unlocking via FIDO2 device failed: %m");
return r;
#else
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "FIDO2 unlocking not supported.");
#endif
}
int enroll_fido2(
@@ -74,6 +79,7 @@ int enroll_fido2(
const char *salt_file,
bool parameters_in_header) {
#if HAVE_LIBFIDO2
_cleanup_(iovec_done_erase) struct iovec salt = {};
_cleanup_(erase_and_freep) void *secret = NULL;
_cleanup_(erase_and_freep) char *base64_encoded = NULL;
@@ -202,4 +208,7 @@ int enroll_fido2(
log_info("New FIDO2 token enrolled as key slot %i.", keyslot);
return keyslot;
#else
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "FIDO2 key enrollment not supported.");
#endif
}

View File

@@ -1,24 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <sys/types.h>
#include "forward.h"
#include "cryptsetup-util.h"
#include "libfido2-util.h"
#include "log.h"
#if HAVE_LIBFIDO2
int load_volume_key_fido2(struct crypt_device *cd, const char *cd_node, const char *device, void *ret_vk, size_t *ret_vks);
int enroll_fido2(struct crypt_device *cd, const struct iovec *volume_key, const char *device, Fido2EnrollFlags lock_with, int cred_alg, const char *salt_file, bool parameters_in_header);
#else
static inline int load_volume_key_fido2(struct crypt_device *cd, const char *cd_node, const char *device, void *ret_vk, size_t *ret_vks) {
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"FIDO2 unlocking not supported.");
}
static inline int enroll_fido2(struct crypt_device *cd, const struct iovec *volume_key, const char *device, Fido2EnrollFlags lock_with, int cred_alg, const char *salt_file, bool parameters_in_header) {
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"FIDO2 key enrollment not supported.");
}
#endif

View File

@@ -2,8 +2,10 @@
#include "sd-json.h"
#include "alloc-util.h"
#include "cryptenroll.h"
#include "cryptenroll-list.h"
#include "cryptsetup-util.h"
#include "format-table.h"
#include "json-util.h"
#include "log.h"

View File

@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include "cryptsetup-util.h"
#include "forward.h"
int list_enrolled(struct crypt_device *cd);

View File

@@ -1,14 +1,16 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "alloc-util.h"
#include "ask-password-api.h"
#include "cryptenroll-password.h"
#include "cryptsetup-util.h"
#include "env-util.h"
#include "errno-util.h"
#include "escape.h"
#include "iovec-util.h"
#include "log.h"
#include "memory-util.h"
#include "password-quality-util.h"
#include "string-util.h"
#include "strv.h"
int load_volume_key_password(

View File

@@ -1,9 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <sys/types.h>
#include "cryptsetup-util.h"
#include "forward.h"
int load_volume_key_password(struct crypt_device *cd, const char* cd_node, void *ret_vk, size_t *ret_vks);
int enroll_password(struct crypt_device *cd, const struct iovec *volume_key);

View File

@@ -1,12 +1,14 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "alloc-util.h"
#include "cryptenroll-pkcs11.h"
#include "cryptsetup-util.h"
#include "hexdecoct.h"
#include "json-util.h"
#include "memory-util.h"
#include "openssl-util.h"
#include "pkcs11-util.h"
#if HAVE_P11KIT && HAVE_OPENSSL
static int uri_set_private_class(const char *uri, char **ret_uri) {
_cleanup_(sym_p11_kit_uri_freep) P11KitUri *p11kit_uri = NULL;
_cleanup_free_ char *private_uri = NULL;
@@ -30,12 +32,10 @@ static int uri_set_private_class(const char *uri, char **ret_uri) {
*ret_uri = TAKE_PTR(private_uri);
return 0;
}
#endif
int enroll_pkcs11(
struct crypt_device *cd,
const struct iovec *volume_key,
const char *uri) {
int enroll_pkcs11(struct crypt_device *cd, const struct iovec *volume_key,const char *uri) {
#if HAVE_P11KIT && HAVE_OPENSSL
_cleanup_(erase_and_freep) void *decrypted_key = NULL;
_cleanup_(erase_and_freep) char *base64_encoded = NULL;
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
@@ -112,4 +112,7 @@ int enroll_pkcs11(
log_info("New PKCS#11 token enrolled as key slot %i.", keyslot);
return keyslot;
#else
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "PKCS#11 key enrollment not supported.");
#endif
}

View File

@@ -1,16 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <sys/types.h>
#include "forward.h"
#include "cryptsetup-util.h"
#include "log.h"
#if HAVE_P11KIT && HAVE_OPENSSL
int enroll_pkcs11(struct crypt_device *cd, const struct iovec *volume_key, const char *uri);
#else
static inline int enroll_pkcs11(struct crypt_device *cd, const struct iovec *volume_key, const char *uri) {
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"PKCS#11 key enrollment not supported.");
}
#endif

View File

@@ -1,15 +1,15 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "alloc-util.h"
#include "ansi-color.h"
#include "cryptenroll-recovery.h"
#include "cryptsetup-util.h"
#include "glyph-util.h"
#include "iovec-util.h"
#include "json-util.h"
#include "log.h"
#include "memory-util.h"
#include "qrcode-util.h"
#include "recovery-key.h"
#include "terminal-util.h"
int enroll_recovery(
struct crypt_device *cd,

View File

@@ -1,8 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <sys/types.h>
#include "cryptsetup-util.h"
#include "forward.h"
int enroll_recovery(struct crypt_device *cd, const struct iovec *volume_key);

View File

@@ -6,17 +6,19 @@
#include "ask-password-api.h"
#include "cryptenroll-tpm2.h"
#include "cryptsetup-tpm2.h"
#include "cryptsetup-util.h"
#include "env-util.h"
#include "errno-util.h"
#include "fileio.h"
#include "hexdecoct.h"
#include "json-util.h"
#include "log.h"
#include "memory-util.h"
#include "random-util.h"
#include "sha256.h"
#include "strv.h"
#include "tpm2-util.h"
#if HAVE_TPM2
static int search_policy_hash(
struct crypt_device *cd,
const struct iovec policy_hash[],
@@ -164,6 +166,7 @@ static int get_pin(char **ret_pin_str, TPM2Flags *ret_flags) {
return 0;
}
#endif
int load_volume_key_tpm2(
struct crypt_device *cd,
@@ -172,6 +175,7 @@ int load_volume_key_tpm2(
void *ret_vk,
size_t *ret_vks) {
#if HAVE_TPM2
_cleanup_(iovec_done_erase) struct iovec decrypted_key = {};
_cleanup_(erase_and_freep) char *passphrase = NULL;
ssize_t passphrase_size;
@@ -279,6 +283,9 @@ int load_volume_key_tpm2(
return log_error_errno(r, "Unlocking via TPM2 device failed: %m");
return r;
#else
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "TPM2 unlocking not supported.");
#endif
}
int enroll_tpm2(struct crypt_device *cd,
@@ -296,6 +303,7 @@ int enroll_tpm2(struct crypt_device *cd,
const char *pcrlock_path,
int *ret_slot_to_wipe) {
#if HAVE_TPM2
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL, *signature_json = NULL;
_cleanup_(erase_and_freep) char *base64_encoded = NULL;
_cleanup_(iovec_done) struct iovec srk = {}, pubkey = {};
@@ -605,4 +613,7 @@ int enroll_tpm2(struct crypt_device *cd,
*ret_slot_to_wipe = slot_to_wipe;
return keyslot;
#else
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "TPM2 key enrollment not supported.");
#endif
}

View File

@@ -1,23 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <sys/types.h>
#include "forward.h"
#include "cryptsetup-util.h"
#include "log.h"
#include "tpm2-util.h"
#if HAVE_TPM2
int load_volume_key_tpm2(struct crypt_device *cd, const char *cd_node, const char *device, void *ret_vk, size_t *ret_vks);
int enroll_tpm2(struct crypt_device *cd, const struct iovec *volume_key, const char *device, uint32_t seal_key_handle, const char *device_key, Tpm2PCRValue *hash_pcr_values, size_t n_hash_pcr_values, const char *pubkey_path, bool load_pcr_pubkey, uint32_t pubkey_pcr_mask, const char *signature_path, bool use_pin, const char *pcrlock_path, int *ret_slot_to_wipe);
#else
static inline int load_volume_key_tpm2(struct crypt_device *cd, const char *cd_node, const char *device, void *ret_vk, size_t *ret_vks) {
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"TPM2 unlocking not supported.");
}
static inline int enroll_tpm2(struct crypt_device *cd, const struct iovec *volume_key, const char *device, uint32_t seal_key_handle, const char *device_key, Tpm2PCRValue *hash_pcr_values, size_t n_hash_pcr_values, const char *pubkey_path, bool load_pcr_pubkey, uint32_t pubkey_pcr_mask, const char *signature_path, bool use_pin, const char *pcrlock_path, int *ret_slot_to_wipe) {
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"TPM2 key enrollment not supported.");
}
#endif

View File

@@ -1,12 +1,11 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "sd-json.h"
#include "alloc-util.h"
#include "cryptenroll.h"
#include "cryptenroll-wipe.h"
#include "cryptsetup-util.h"
#include "json-util.h"
#include "log.h"
#include "memory-util.h"
#include "parse-util.h"
#include "set.h"
#include "sort-util.h"

View File

@@ -1,8 +1,9 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include "cryptenroll.h"
#include "cryptsetup-util.h"
#include "forward.h"
typedef enum WipeScope WipeScope;
int wipe_slots(struct crypt_device *cd,
const int explicit_slots[],

View File

@@ -3,7 +3,8 @@
#include <getopt.h>
#include <sys/mman.h>
#include "ask-password-api.h"
#include "sd-device.h"
#include "blockdev-list.h"
#include "blockdev-util.h"
#include "build.h"
@@ -16,24 +17,20 @@
#include "cryptenroll-tpm2.h"
#include "cryptenroll-wipe.h"
#include "cryptsetup-util.h"
#include "devnum-util.h"
#include "env-util.h"
#include "escape.h"
#include "extract-word.h"
#include "fileio.h"
#include "libfido2-util.h"
#include "log.h"
#include "main-func.h"
#include "memory-util.h"
#include "pager.h"
#include "parse-argument.h"
#include "parse-util.h"
#include "path-util.h"
#include "pkcs11-util.h"
#include "pretty-print.h"
#include "string-table.h"
#include "strv.h"
#include "terminal-util.h"
#include "string-util.h"
#include "tpm2-pcr.h"
#include "tpm2-util.h"
static EnrollType arg_enroll_type = _ENROLL_TYPE_INVALID;
static char *arg_unlock_keyfile = NULL;

View File

@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <errno.h>
#include "forward.h"
typedef enum EnrollType {
ENROLL_PASSWORD,

View File

@@ -5,25 +5,16 @@ if conf.get('HAVE_LIBCRYPTSETUP') != 1
endif
systemd_cryptenroll_sources = files(
'cryptenroll.c',
'cryptenroll-fido2.c',
'cryptenroll-list.c',
'cryptenroll-password.c',
'cryptenroll-pkcs11.c',
'cryptenroll-recovery.c',
'cryptenroll-tpm2.c',
'cryptenroll-wipe.c',
'cryptenroll.c',
)
if conf.get('HAVE_P11KIT') == 1 and conf.get('HAVE_OPENSSL') == 1
systemd_cryptenroll_sources += files('cryptenroll-pkcs11.c')
endif
if conf.get('HAVE_LIBFIDO2') == 1
systemd_cryptenroll_sources += files('cryptenroll-fido2.c')
endif
if conf.get('HAVE_TPM2') == 1
systemd_cryptenroll_sources += files('cryptenroll-tpm2.c')
endif
executables += [
executable_template + {
'name' : 'systemd-cryptenroll',