From 82118bdd5ff5e09ee61be4c179e6184e4ca8d047 Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Wed, 14 Feb 2024 13:32:48 +0100 Subject: [PATCH] Add --key-description for resize command. --- man/common_options.adoc | 2 +- src/cryptsetup.c | 13 +++++++------ src/cryptsetup_args.h | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/man/common_options.adoc b/man/common_options.adoc index bfd02f6e..0b23335a 100644 --- a/man/common_options.adoc +++ b/man/common_options.adoc @@ -441,7 +441,7 @@ it is requested. Reencrypt only the LUKS1 header and keyslots. Skips data in-place reencryption. endif::[] -ifdef::ACTION_LUKSFORMAT,ACTION_LUKSDUMP,ACTION_TOKEN[] +ifdef::ACTION_LUKSFORMAT,ACTION_LUKSDUMP,ACTION_RESIZE,ACTION_TOKEN[] *--key-description *:: Set key description in keyring that will be used for passphrase retrieval. endif::[] diff --git a/src/cryptsetup.c b/src/cryptsetup.c index 97728c6c..04509b3c 100644 --- a/src/cryptsetup.c +++ b/src/cryptsetup.c @@ -896,6 +896,7 @@ static int action_resize(void) uint64_t dev_size = 0; char *password = NULL; struct crypt_device *cd = NULL; + struct crypt_keyslot_context *kc = NULL; r = crypt_init_by_name_and_header(&cd, action_argv[0], ARG_STR(OPT_HEADER_ID)); if (r) @@ -936,15 +937,14 @@ static int action_resize(void) if (r >= 0 || quit || ARG_SET(OPT_TOKEN_ONLY_ID)) goto out; - r = tools_get_key(NULL, &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_passphrase(0), 0, cd); + r = init_keyslot_context(cd, &password, &passwordLen, verify_passphrase(0), + false, false, &kc); if (r < 0) goto out; - r = crypt_activate_by_passphrase(cd, NULL, ARG_INT32(OPT_KEY_SLOT_ID), - password, passwordLen, - CRYPT_ACTIVATE_KEYRING_KEY); + r = crypt_activate_by_keyslot_context(cd, NULL,ARG_INT32(OPT_KEY_SLOT_ID), + kc, CRYPT_ANY_SLOT, NULL, + CRYPT_ACTIVATE_KEYRING_KEY); tools_passphrase_msg(r); tools_keyslot_msg(r, UNLOCKED); } @@ -954,6 +954,7 @@ out: r = crypt_resize(cd, action_argv[0], dev_size); crypt_safe_free(password); + crypt_keyslot_context_free(kc); crypt_free(cd); return r; } diff --git a/src/cryptsetup_args.h b/src/cryptsetup_args.h index c1c66559..9d97e7f5 100644 --- a/src/cryptsetup_args.h +++ b/src/cryptsetup_args.h @@ -71,7 +71,7 @@ #define OPT_ITER_TIME_ACTIONS { BENCHMARK_ACTION, FORMAT_ACTION, ADDKEY_ACTION, CHANGEKEY_ACTION, CONVERTKEY_ACTION, REENCRYPT_ACTION } #define OPT_IV_LARGE_SECTORS_ACTIONS { OPEN_ACTION } #define OPT_KEEP_KEY_ACTIONS { REENCRYPT_ACTION } -#define OPT_KEY_DESCRIPTION_ACTIONS { TOKEN_ACTION, LUKSDUMP_ACTION, FORMAT_ACTION } +#define OPT_KEY_DESCRIPTION_ACTIONS { TOKEN_ACTION, LUKSDUMP_ACTION, FORMAT_ACTION, RESIZE_ACTION } #define OPT_KEY_SIZE_ACTIONS { OPEN_ACTION, BENCHMARK_ACTION, FORMAT_ACTION, REENCRYPT_ACTION, ADDKEY_ACTION } #define OPT_KEY_SLOT_ACTIONS { OPEN_ACTION, REENCRYPT_ACTION, CONFIG_ACTION, FORMAT_ACTION, ADDKEY_ACTION, CHANGEKEY_ACTION, CONVERTKEY_ACTION, LUKSDUMP_ACTION, TOKEN_ACTION, RESUME_ACTION } #define OPT_KEYSLOT_CIPHER_ACTIONS { FORMAT_ACTION, REENCRYPT_ACTION, ADDKEY_ACTION, CHANGEKEY_ACTION, CONVERTKEY_ACTION }