FIDO2: support pin-less LUKS enroll/unlock
Closes: https://github.com/systemd/systemd/issues/19246 Some FIDO2 devices allow the user to choose whether to use a PIN or not and will HMAC with a different secret depending on the choice. Some other devices (or some device-specific configuration) can instead make it mandatory. Allow the cryptenroll user to choose whether to use a PIN or not, but fail immediately if it is a hard requirement. Record the choice in the JSON-encoded LUKS header metadata so that the right set of options can be used on unlock.
This commit is contained in:
committed by
Luca Boccassi
parent
cd5f57bda7
commit
cde2f8605e
@@ -24,6 +24,7 @@ int acquire_fido2_key(
|
||||
size_t key_data_size,
|
||||
usec_t until,
|
||||
bool headless,
|
||||
Fido2EnrollFlags required,
|
||||
void **ret_decrypted_key,
|
||||
size_t *ret_decrypted_key_size) {
|
||||
|
||||
@@ -73,19 +74,22 @@ int acquire_fido2_key(
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
r = fido2_use_hmac_hash(
|
||||
device,
|
||||
rp_id ?: "io.systemd.cryptsetup",
|
||||
salt, salt_size,
|
||||
cid, cid_size,
|
||||
pins,
|
||||
/* up= */ true,
|
||||
ret_decrypted_key,
|
||||
ret_decrypted_key_size);
|
||||
if (!IN_SET(r,
|
||||
-ENOANO, /* needs pin */
|
||||
-ENOLCK)) /* pin incorrect */
|
||||
return r;
|
||||
if (!FLAGS_SET(required, FIDO2ENROLL_PIN) || pins) {
|
||||
r = fido2_use_hmac_hash(
|
||||
device,
|
||||
rp_id ?: "io.systemd.cryptsetup",
|
||||
salt, salt_size,
|
||||
cid, cid_size,
|
||||
pins,
|
||||
/* up= */ true,
|
||||
required,
|
||||
ret_decrypted_key,
|
||||
ret_decrypted_key_size);
|
||||
if (!IN_SET(r,
|
||||
-ENOANO, /* needs pin */
|
||||
-ENOLCK)) /* pin incorrect */
|
||||
return r;
|
||||
}
|
||||
|
||||
pins = strv_free_erase(pins);
|
||||
|
||||
@@ -107,12 +111,14 @@ int find_fido2_auto_data(
|
||||
size_t *ret_salt_size,
|
||||
void **ret_cid,
|
||||
size_t *ret_cid_size,
|
||||
int *ret_keyslot) {
|
||||
int *ret_keyslot,
|
||||
Fido2EnrollFlags *ret_required) {
|
||||
|
||||
_cleanup_free_ void *cid = NULL, *salt = NULL;
|
||||
size_t cid_size = 0, salt_size = 0;
|
||||
_cleanup_free_ char *rp = NULL;
|
||||
int r, keyslot = -1;
|
||||
Fido2EnrollFlags required = FIDO2ENROLL_PIN; /* For backward compatibility, require pin by default */
|
||||
|
||||
assert(cd);
|
||||
assert(ret_salt);
|
||||
@@ -120,6 +126,7 @@ int find_fido2_auto_data(
|
||||
assert(ret_cid);
|
||||
assert(ret_cid_size);
|
||||
assert(ret_keyslot);
|
||||
assert(ret_required);
|
||||
|
||||
/* Loads FIDO2 metadata from LUKS2 JSON token headers. */
|
||||
|
||||
@@ -176,6 +183,17 @@ int find_fido2_auto_data(
|
||||
if (!rp)
|
||||
return log_oom();
|
||||
}
|
||||
|
||||
w = json_variant_by_key(v, "fido2-clientPin-required");
|
||||
if (w) {
|
||||
/* The "fido2-clientPin-required" field is optional. */
|
||||
|
||||
if (!json_variant_is_boolean(w))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"FIDO2 token data's 'fido2-clientPin-required' field is not a boolean.");
|
||||
|
||||
SET_FLAG(required, FIDO2ENROLL_PIN, json_variant_boolean(w));
|
||||
}
|
||||
}
|
||||
|
||||
if (!cid)
|
||||
@@ -190,5 +208,6 @@ int find_fido2_auto_data(
|
||||
*ret_salt = TAKE_PTR(salt);
|
||||
*ret_salt_size = salt_size;
|
||||
*ret_keyslot = keyslot;
|
||||
*ret_required = required;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "cryptsetup-util.h"
|
||||
#include "libfido2-util.h"
|
||||
#include "log.h"
|
||||
#include "time-util.h"
|
||||
|
||||
@@ -23,6 +24,7 @@ int acquire_fido2_key(
|
||||
size_t key_data_size,
|
||||
usec_t until,
|
||||
bool headless,
|
||||
Fido2EnrollFlags required,
|
||||
void **ret_decrypted_key,
|
||||
size_t *ret_decrypted_key_size);
|
||||
|
||||
@@ -33,7 +35,8 @@ int find_fido2_auto_data(
|
||||
size_t *ret_salt_size,
|
||||
void **ret_cid,
|
||||
size_t *ret_cid_size,
|
||||
int *ret_keyslot);
|
||||
int *ret_keyslot,
|
||||
Fido2EnrollFlags *ret_required);
|
||||
|
||||
#else
|
||||
|
||||
@@ -51,6 +54,7 @@ static inline int acquire_fido2_key(
|
||||
size_t key_data_size,
|
||||
usec_t until,
|
||||
bool headless,
|
||||
Fido2EnrollFlags required,
|
||||
void **ret_decrypted_key,
|
||||
size_t *ret_decrypted_key_size) {
|
||||
|
||||
@@ -65,7 +69,8 @@ static inline int find_fido2_auto_data(
|
||||
size_t *ret_salt_size,
|
||||
void **ret_cid,
|
||||
size_t *ret_cid_size,
|
||||
int *ret_keyslot) {
|
||||
int *ret_keyslot,
|
||||
Fido2EnrollFlags *ret_required) {
|
||||
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
|
||||
"FIDO2 token support not available.");
|
||||
|
||||
@@ -739,6 +739,7 @@ static int attach_luks_or_plain_or_bitlk_by_fido2(
|
||||
int keyslot = arg_key_slot, r;
|
||||
const char *rp_id;
|
||||
const void *cid;
|
||||
Fido2EnrollFlags required;
|
||||
|
||||
assert(cd);
|
||||
assert(name);
|
||||
@@ -759,7 +760,8 @@ static int attach_luks_or_plain_or_bitlk_by_fido2(
|
||||
&discovered_salt_size,
|
||||
&discovered_cid,
|
||||
&discovered_cid_size,
|
||||
&keyslot);
|
||||
&keyslot,
|
||||
&required);
|
||||
|
||||
if (IN_SET(r, -ENOTUNIQ, -ENXIO))
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN),
|
||||
@@ -767,6 +769,10 @@ static int attach_luks_or_plain_or_bitlk_by_fido2(
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (FLAGS_SET(required, FIDO2ENROLL_PIN) && arg_headless)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(ENOPKG),
|
||||
"A PIN is required to unlock this volume, but the 'headless' parameter was set.");
|
||||
|
||||
rp_id = discovered_rp_id;
|
||||
key_data = discovered_salt;
|
||||
key_data_size = discovered_salt_size;
|
||||
@@ -791,6 +797,7 @@ static int attach_luks_or_plain_or_bitlk_by_fido2(
|
||||
key_data, key_data_size,
|
||||
until,
|
||||
arg_headless,
|
||||
required,
|
||||
&decrypted_key, &decrypted_key_size);
|
||||
if (r >= 0)
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user