Switch reencrypt --encrypt initialization to keyslot context.

This allows to simplify init_keyslot_context and we can only
pass single pointer from luksFormat routine.
This commit is contained in:
Ondrej Kozina
2025-04-25 18:06:05 +02:00
committed by Milan Broz
parent 9f0dd9cc4c
commit 4493d9ad3e
4 changed files with 67 additions and 68 deletions

View File

@@ -271,31 +271,32 @@ out:
return r;
}
/*
* FIXME: Refactor password and passwordLen params away after keyslot context support
* is added in --encrypt reencryption mode.
*/
int luks_init_keyslot_context(struct crypt_device *cd,
const char *msg,
char **password, size_t *passwordLen, bool verify, bool pwquality,
bool reencrypt, /* tmp hack to use old get_key */
struct crypt_keyslot_context **kc)
const char *msg,
bool verify, bool pwquality,
struct crypt_keyslot_context **r_kc)
{
char *password;
size_t passwordLen;
int r = -EINVAL;
assert(cd);
assert(r_kc);
if (ARG_SET(OPT_KEY_DESCRIPTION_ID))
r = crypt_keyslot_context_init_by_keyring(cd, ARG_STR(OPT_KEY_DESCRIPTION_ID), kc);
else if (ARG_SET(OPT_KEY_FILE_ID) && !tools_is_stdin(ARG_STR(OPT_KEY_FILE_ID)) && !reencrypt)
r = crypt_keyslot_context_init_by_keyring(cd, ARG_STR(OPT_KEY_DESCRIPTION_ID), r_kc);
else if (ARG_SET(OPT_KEY_FILE_ID) && !tools_is_stdin(ARG_STR(OPT_KEY_FILE_ID)))
r = crypt_keyslot_context_init_by_keyfile(cd, ARG_STR(OPT_KEY_FILE_ID),
ARG_UINT32(OPT_KEYFILE_SIZE_ID),
ARG_UINT64(OPT_KEYFILE_OFFSET_ID), kc);
else if (password) {
r = tools_get_key(msg, password, passwordLen, ARG_UINT64(OPT_KEYFILE_OFFSET_ID),
ARG_UINT64(OPT_KEYFILE_OFFSET_ID), r_kc);
else {
r = tools_get_key(msg, &password, &passwordLen, ARG_UINT64(OPT_KEYFILE_OFFSET_ID),
ARG_UINT32(OPT_KEYFILE_SIZE_ID), ARG_STR(OPT_KEY_FILE_ID),
ARG_UINT32(OPT_TIMEOUT_ID), verify, pwquality, cd);
if (r < 0)
return r;
r = crypt_keyslot_context_init_by_passphrase(cd, *password, *passwordLen, kc);
r = crypt_keyslot_context_init_by_passphrase(cd, password, passwordLen, r_kc);
crypt_safe_free(password);
}
return r;