Merge pull request #19768 from poettering/homectl-fido2-lock-with
homed: catch up with FIDO2 features in cryptsetup + other fixes
This commit is contained in:
@@ -17,23 +17,38 @@ int (*sym_crypt_activate_by_volume_key)(struct crypt_device *cd, const char *nam
|
||||
int (*sym_crypt_deactivate_by_name)(struct crypt_device *cd, const char *name, uint32_t flags);
|
||||
int (*sym_crypt_format)(struct crypt_device *cd, const char *type, const char *cipher, const char *cipher_mode, const char *uuid, const char *volume_key, size_t volume_key_size, void *params);
|
||||
void (*sym_crypt_free)(struct crypt_device *cd);
|
||||
const char *(*sym_crypt_get_cipher)(struct crypt_device *cd);
|
||||
const char *(*sym_crypt_get_cipher_mode)(struct crypt_device *cd);
|
||||
uint64_t (*sym_crypt_get_data_offset)(struct crypt_device *cd);
|
||||
const char *(*sym_crypt_get_device_name)(struct crypt_device *cd);
|
||||
const char *(*sym_crypt_get_dir)(void);
|
||||
const char *(*sym_crypt_get_type)(struct crypt_device *cd);
|
||||
const char *(*sym_crypt_get_uuid)(struct crypt_device *cd);
|
||||
int (*sym_crypt_get_verity_info)(struct crypt_device *cd, struct crypt_params_verity *vp);
|
||||
int (*sym_crypt_get_volume_key_size)(struct crypt_device *cd);
|
||||
int (*sym_crypt_init)(struct crypt_device **cd, const char *device);
|
||||
int (*sym_crypt_init_by_name)(struct crypt_device **cd, const char *name);
|
||||
int (*sym_crypt_keyslot_add_by_volume_key)(struct crypt_device *cd, int keyslot, const char *volume_key, size_t volume_key_size, const char *passphrase, size_t passphrase_size);
|
||||
int (*sym_crypt_keyslot_destroy)(struct crypt_device *cd, int keyslot);
|
||||
int (*sym_crypt_keyslot_max)(const char *type);
|
||||
int (*sym_crypt_load)(struct crypt_device *cd, const char *requested_type, void *params);
|
||||
int (*sym_crypt_resize)(struct crypt_device *cd, const char *name, uint64_t new_size);
|
||||
int (*sym_crypt_resume_by_passphrase)(struct crypt_device *cd, const char *name, int keyslot, const char *passphrase, size_t passphrase_size);
|
||||
int (*sym_crypt_set_data_device)(struct crypt_device *cd, const char *device);
|
||||
void (*sym_crypt_set_debug_level)(int level);
|
||||
void (*sym_crypt_set_log_callback)(struct crypt_device *cd, void (*log)(int level, const char *msg, void *usrptr), void *usrptr);
|
||||
int (*sym_crypt_set_pbkdf_type)(struct crypt_device *cd, const struct crypt_pbkdf_type *pbkdf) = NULL;
|
||||
int (*sym_crypt_token_json_get)(struct crypt_device *cd, int token, const char **json) = NULL;
|
||||
int (*sym_crypt_token_json_set)(struct crypt_device *cd, int token, const char *json) = NULL;
|
||||
int (*sym_crypt_volume_key_get)(struct crypt_device *cd, int keyslot, char *volume_key, size_t *volume_key_size, const char *passphrase, size_t passphrase_size);
|
||||
#if HAVE_CRYPT_SET_METADATA_SIZE
|
||||
int (*sym_crypt_set_metadata_size)(struct crypt_device *cd, uint64_t metadata_size, uint64_t keyslots_size);
|
||||
#endif
|
||||
int (*sym_crypt_set_pbkdf_type)(struct crypt_device *cd, const struct crypt_pbkdf_type *pbkdf);
|
||||
int (*sym_crypt_suspend)(struct crypt_device *cd, const char *name);
|
||||
int (*sym_crypt_token_json_get)(struct crypt_device *cd, int token, const char **json);
|
||||
int (*sym_crypt_token_json_set)(struct crypt_device *cd, int token, const char *json);
|
||||
#if HAVE_CRYPT_TOKEN_MAX
|
||||
int (*sym_crypt_token_max)(const char *type);
|
||||
#endif
|
||||
crypt_token_info (*sym_crypt_token_status)(struct crypt_device *cd, int token, const char **type);
|
||||
int (*sym_crypt_volume_key_get)(struct crypt_device *cd, int keyslot, char *volume_key, size_t *volume_key_size, const char *passphrase, size_t passphrase_size);
|
||||
|
||||
int dlopen_cryptsetup(void) {
|
||||
_cleanup_(dlclosep) void *dl = NULL;
|
||||
@@ -58,23 +73,38 @@ int dlopen_cryptsetup(void) {
|
||||
DLSYM_ARG(crypt_deactivate_by_name),
|
||||
DLSYM_ARG(crypt_format),
|
||||
DLSYM_ARG(crypt_free),
|
||||
DLSYM_ARG(crypt_get_cipher),
|
||||
DLSYM_ARG(crypt_get_cipher_mode),
|
||||
DLSYM_ARG(crypt_get_data_offset),
|
||||
DLSYM_ARG(crypt_get_device_name),
|
||||
DLSYM_ARG(crypt_get_dir),
|
||||
DLSYM_ARG(crypt_get_type),
|
||||
DLSYM_ARG(crypt_get_uuid),
|
||||
DLSYM_ARG(crypt_get_verity_info),
|
||||
DLSYM_ARG(crypt_get_volume_key_size),
|
||||
DLSYM_ARG(crypt_init),
|
||||
DLSYM_ARG(crypt_init_by_name),
|
||||
DLSYM_ARG(crypt_keyslot_add_by_volume_key),
|
||||
DLSYM_ARG(crypt_keyslot_destroy),
|
||||
DLSYM_ARG(crypt_keyslot_max),
|
||||
DLSYM_ARG(crypt_load),
|
||||
DLSYM_ARG(crypt_resize),
|
||||
DLSYM_ARG(crypt_resume_by_passphrase),
|
||||
DLSYM_ARG(crypt_set_data_device),
|
||||
DLSYM_ARG(crypt_set_debug_level),
|
||||
DLSYM_ARG(crypt_set_log_callback),
|
||||
#if HAVE_CRYPT_SET_METADATA_SIZE
|
||||
DLSYM_ARG(crypt_set_metadata_size),
|
||||
#endif
|
||||
DLSYM_ARG(crypt_set_pbkdf_type),
|
||||
DLSYM_ARG(crypt_suspend),
|
||||
DLSYM_ARG(crypt_token_json_get),
|
||||
DLSYM_ARG(crypt_token_json_set),
|
||||
DLSYM_ARG(crypt_volume_key_get),
|
||||
#if HAVE_CRYPT_TOKEN_MAX
|
||||
DLSYM_ARG(crypt_token_max),
|
||||
#endif
|
||||
DLSYM_ARG(crypt_token_status),
|
||||
DLSYM_ARG(crypt_volume_key_get),
|
||||
NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -82,6 +112,13 @@ int dlopen_cryptsetup(void) {
|
||||
/* Note that we never release the reference here, because there's no real reason to, after all this
|
||||
* was traditionally a regular shared library dependency which lives forever too. */
|
||||
cryptsetup_dl = TAKE_PTR(dl);
|
||||
|
||||
/* Redirect the default logging calls of libcryptsetup to our own logging infra. (Note that
|
||||
* libcryptsetup also maintains per-"struct crypt_device" log functions, which we'll also set
|
||||
* whenever allocating a "struct crypt_device" context. Why set both? To be defensive: maybe some
|
||||
* other code loaded into this process also changes the global log functions of libcryptsetup, who
|
||||
* knows? And if so, we still want our own objects to log via our own infra, at the very least.) */
|
||||
cryptsetup_enable_logging(NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -109,13 +146,17 @@ static void cryptsetup_log_glue(int level, const char *msg, void *usrptr) {
|
||||
}
|
||||
|
||||
void cryptsetup_enable_logging(struct crypt_device *cd) {
|
||||
if (!cd)
|
||||
return;
|
||||
/* It's OK to call this with a NULL parameter, in which case libcryptsetup will set the defaut log
|
||||
* function.
|
||||
*
|
||||
* Note that this is also called from dlopen_cryptsetup(), which we call here too. Sounds like an
|
||||
* endless loop, but isn't because we break it via the check for 'cryptsetup_dl' early in
|
||||
* dlopen_cryptsetup(). */
|
||||
|
||||
if (dlopen_cryptsetup() < 0) /* If this fails, let's gracefully ignore the issue, this is just debug
|
||||
* logging after all, and if this failed we already generated a debug
|
||||
* log message that should help to track things down. */
|
||||
return;
|
||||
if (dlopen_cryptsetup() < 0)
|
||||
return; /* If this fails, let's gracefully ignore the issue, this is just debug logging after
|
||||
* all, and if this failed we already generated a debug log message that should help
|
||||
* to track things down. */
|
||||
|
||||
sym_crypt_set_log_callback(cd, cryptsetup_log_glue, NULL);
|
||||
sym_crypt_set_debug_level(DEBUG_LOGGING ? CRYPT_DEBUG_ALL : CRYPT_DEBUG_NONE);
|
||||
|
||||
@@ -23,20 +23,33 @@ extern int (*sym_crypt_activate_by_volume_key)(struct crypt_device *cd, const ch
|
||||
extern int (*sym_crypt_deactivate_by_name)(struct crypt_device *cd, const char *name, uint32_t flags);
|
||||
extern int (*sym_crypt_format)(struct crypt_device *cd, const char *type, const char *cipher, const char *cipher_mode, const char *uuid, const char *volume_key, size_t volume_key_size, void *params);
|
||||
extern void (*sym_crypt_free)(struct crypt_device *cd);
|
||||
extern const char *(*sym_crypt_get_cipher)(struct crypt_device *cd);
|
||||
extern const char *(*sym_crypt_get_cipher_mode)(struct crypt_device *cd);
|
||||
extern uint64_t (*sym_crypt_get_data_offset)(struct crypt_device *cd);
|
||||
extern const char *(*sym_crypt_get_device_name)(struct crypt_device *cd);
|
||||
extern const char *(*sym_crypt_get_dir)(void);
|
||||
extern const char *(*sym_crypt_get_type)(struct crypt_device *cd);
|
||||
extern const char *(*sym_crypt_get_uuid)(struct crypt_device *cd);
|
||||
extern int (*sym_crypt_get_verity_info)(struct crypt_device *cd, struct crypt_params_verity *vp);
|
||||
extern int (*sym_crypt_get_volume_key_size)(struct crypt_device *cd);
|
||||
extern int (*sym_crypt_init)(struct crypt_device **cd, const char *device);
|
||||
extern int (*sym_crypt_init_by_name)(struct crypt_device **cd, const char *name);
|
||||
extern int (*sym_crypt_keyslot_add_by_volume_key)(struct crypt_device *cd, int keyslot, const char *volume_key, size_t volume_key_size, const char *passphrase, size_t passphrase_size);
|
||||
extern int (*sym_crypt_keyslot_destroy)(struct crypt_device *cd, int keyslot);
|
||||
extern int (*sym_crypt_keyslot_max)(const char *type);
|
||||
extern int (*sym_crypt_load)(struct crypt_device *cd, const char *requested_type, void *params);
|
||||
extern int (*sym_crypt_resize)(struct crypt_device *cd, const char *name, uint64_t new_size);
|
||||
extern int (*sym_crypt_resume_by_passphrase)(struct crypt_device *cd, const char *name, int keyslot, const char *passphrase, size_t passphrase_size);
|
||||
extern int (*sym_crypt_set_data_device)(struct crypt_device *cd, const char *device);
|
||||
extern void (*sym_crypt_set_debug_level)(int level);
|
||||
extern void (*sym_crypt_set_log_callback)(struct crypt_device *cd, void (*log)(int level, const char *msg, void *usrptr), void *usrptr);
|
||||
#if HAVE_CRYPT_SET_METADATA_SIZE
|
||||
extern int (*sym_crypt_set_metadata_size)(struct crypt_device *cd, uint64_t metadata_size, uint64_t keyslots_size);
|
||||
#endif
|
||||
extern int (*sym_crypt_set_pbkdf_type)(struct crypt_device *cd, const struct crypt_pbkdf_type *pbkdf);
|
||||
extern int (*sym_crypt_suspend)(struct crypt_device *cd, const char *name);
|
||||
extern int (*sym_crypt_token_json_get)(struct crypt_device *cd, int token, const char **json);
|
||||
extern int (*sym_crypt_token_json_set)(struct crypt_device *cd, int token, const char *json);
|
||||
extern int (*sym_crypt_volume_key_get)(struct crypt_device *cd, int keyslot, char *volume_key, size_t *volume_key_size, const char *passphrase, size_t passphrase_size);
|
||||
#if HAVE_CRYPT_TOKEN_MAX
|
||||
extern int (*sym_crypt_token_max)(const char *type);
|
||||
#else
|
||||
@@ -47,6 +60,8 @@ static inline int sym_crypt_token_max(_unused_ const char *type) {
|
||||
return 32;
|
||||
}
|
||||
#endif
|
||||
extern crypt_token_info (*sym_crypt_token_status)(struct crypt_device *cd, int token, const char **type);
|
||||
extern int (*sym_crypt_volume_key_get)(struct crypt_device *cd, int keyslot, char *volume_key, size_t *volume_key_size, const char *passphrase, size_t passphrase_size);
|
||||
|
||||
int dlopen_cryptsetup(void);
|
||||
|
||||
|
||||
@@ -1926,6 +1926,8 @@ static int verity_can_reuse(
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Error opening verity device, crypt_init_by_name failed: %m");
|
||||
|
||||
cryptsetup_enable_logging(cd);
|
||||
|
||||
r = sym_crypt_get_verity_info(cd, &crypt_params);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Error opening verity device, crypt_get_verity_info failed: %m");
|
||||
|
||||
@@ -200,6 +200,7 @@ UserRecord* user_record_new(void) {
|
||||
.password_change_now = -1,
|
||||
.pkcs11_protected_authentication_path_permitted = -1,
|
||||
.fido2_user_presence_permitted = -1,
|
||||
.fido2_user_verification_permitted = -1,
|
||||
};
|
||||
|
||||
return h;
|
||||
@@ -774,6 +775,7 @@ static int dispatch_secret(const char *name, JsonVariant *variant, JsonDispatchF
|
||||
{ "pkcs11Pin", /* legacy alias */ _JSON_VARIANT_TYPE_INVALID, json_dispatch_strv, offsetof(UserRecord, token_pin), 0 },
|
||||
{ "pkcs11ProtectedAuthenticationPathPermitted", JSON_VARIANT_BOOLEAN, json_dispatch_tristate, offsetof(UserRecord, pkcs11_protected_authentication_path_permitted), 0 },
|
||||
{ "fido2UserPresencePermitted", JSON_VARIANT_BOOLEAN, json_dispatch_tristate, offsetof(UserRecord, fido2_user_presence_permitted), 0 },
|
||||
{ "fido2UserVerificationPermitted", JSON_VARIANT_BOOLEAN, json_dispatch_tristate, offsetof(UserRecord, fido2_user_verification_permitted), 0 },
|
||||
{},
|
||||
};
|
||||
|
||||
@@ -1016,9 +1018,12 @@ static int dispatch_fido2_hmac_salt(const char *name, JsonVariant *variant, Json
|
||||
Fido2HmacSalt *array, *k;
|
||||
|
||||
static const JsonDispatch fido2_hmac_salt_dispatch_table[] = {
|
||||
{ "credential", JSON_VARIANT_STRING, dispatch_fido2_hmac_credential, offsetof(Fido2HmacSalt, credential), JSON_MANDATORY },
|
||||
{ "salt", JSON_VARIANT_STRING, dispatch_fido2_hmac_salt_value, 0, JSON_MANDATORY },
|
||||
{ "hashedPassword", JSON_VARIANT_STRING, json_dispatch_string, offsetof(Fido2HmacSalt, hashed_password), JSON_MANDATORY },
|
||||
{ "credential", JSON_VARIANT_STRING, dispatch_fido2_hmac_credential, offsetof(Fido2HmacSalt, credential), JSON_MANDATORY },
|
||||
{ "salt", JSON_VARIANT_STRING, dispatch_fido2_hmac_salt_value, 0, JSON_MANDATORY },
|
||||
{ "hashedPassword", JSON_VARIANT_STRING, json_dispatch_string, offsetof(Fido2HmacSalt, hashed_password), JSON_MANDATORY },
|
||||
{ "up", JSON_VARIANT_BOOLEAN, json_dispatch_tristate, offsetof(Fido2HmacSalt, up), 0 },
|
||||
{ "uv", JSON_VARIANT_BOOLEAN, json_dispatch_tristate, offsetof(Fido2HmacSalt, uv), 0 },
|
||||
{ "clientPin", JSON_VARIANT_BOOLEAN, json_dispatch_tristate, offsetof(Fido2HmacSalt, client_pin), 0 },
|
||||
{},
|
||||
};
|
||||
|
||||
@@ -1031,7 +1036,11 @@ static int dispatch_fido2_hmac_salt(const char *name, JsonVariant *variant, Json
|
||||
|
||||
h->fido2_hmac_salt = array;
|
||||
k = h->fido2_hmac_salt + h->n_fido2_hmac_salt;
|
||||
*k = (Fido2HmacSalt) {};
|
||||
*k = (Fido2HmacSalt) {
|
||||
.uv = -1,
|
||||
.up = -1,
|
||||
.client_pin = -1,
|
||||
};
|
||||
|
||||
r = json_dispatch(e, fido2_hmac_salt_dispatch_table, NULL, flags, k);
|
||||
if (r < 0) {
|
||||
@@ -2105,7 +2114,7 @@ int user_record_masked_equal(UserRecord *a, UserRecord *b, UserRecordMask mask)
|
||||
/* Compares the two records, but ignores anything not listed in the specified mask */
|
||||
|
||||
if ((a->mask & ~mask) != 0) {
|
||||
r = user_record_clone(a, USER_RECORD_ALLOW(mask) | USER_RECORD_STRIP(~mask & _USER_RECORD_MASK_MAX), &x);
|
||||
r = user_record_clone(a, USER_RECORD_ALLOW(mask) | USER_RECORD_STRIP(~mask & _USER_RECORD_MASK_MAX) | USER_RECORD_PERMISSIVE, &x);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -2113,7 +2122,7 @@ int user_record_masked_equal(UserRecord *a, UserRecord *b, UserRecordMask mask)
|
||||
}
|
||||
|
||||
if ((b->mask & ~mask) != 0) {
|
||||
r = user_record_clone(b, USER_RECORD_ALLOW(mask) | USER_RECORD_STRIP(~mask & _USER_RECORD_MASK_MAX), &y);
|
||||
r = user_record_clone(b, USER_RECORD_ALLOW(mask) | USER_RECORD_STRIP(~mask & _USER_RECORD_MASK_MAX) | USER_RECORD_PERMISSIVE, &y);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -236,6 +236,9 @@ typedef struct Fido2HmacSalt {
|
||||
|
||||
/* What to test the hashed salt value against, usually UNIX password hash here. */
|
||||
char *hashed_password;
|
||||
|
||||
/* Whether the 'up', 'uv', 'clientPin' features are enabled. */
|
||||
int uv, up, client_pin;
|
||||
} Fido2HmacSalt;
|
||||
|
||||
typedef struct RecoveryKey {
|
||||
@@ -371,6 +374,7 @@ typedef struct UserRecord {
|
||||
Fido2HmacSalt *fido2_hmac_salt;
|
||||
size_t n_fido2_hmac_salt;
|
||||
int fido2_user_presence_permitted;
|
||||
int fido2_user_verification_permitted;
|
||||
|
||||
char **recovery_key_type;
|
||||
RecoveryKey *recovery_key;
|
||||
|
||||
@@ -82,7 +82,8 @@ static int load_user(
|
||||
USER_RECORD_ALLOW_PER_MACHINE|
|
||||
USER_RECORD_ALLOW_BINDING|
|
||||
USER_RECORD_ALLOW_SIGNATURE|
|
||||
(have_privileged ? USER_RECORD_ALLOW_PRIVILEGED : 0));
|
||||
(have_privileged ? USER_RECORD_ALLOW_PRIVILEGED : 0)|
|
||||
USER_RECORD_PERMISSIVE);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -225,7 +226,8 @@ static int load_group(
|
||||
USER_RECORD_ALLOW_PER_MACHINE|
|
||||
USER_RECORD_ALLOW_BINDING|
|
||||
USER_RECORD_ALLOW_SIGNATURE|
|
||||
(have_privileged ? USER_RECORD_ALLOW_PRIVILEGED : 0));
|
||||
(have_privileged ? USER_RECORD_ALLOW_PRIVILEGED : 0)|
|
||||
USER_RECORD_PERMISSIVE);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user