mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-15 12:50:06 +01:00
Fix create command to properly handle keyfile size.
- for keyfile reset hash, it make no sense (see man page) - use activate_by_keyfile to make code more readable (it still does the stem thing) - if keyfile specified, read only key and do not do exhausted read (regression from 1.1.3) git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@399 36d66b0a-2a48-0410-832c-cd162a569da5
This commit is contained in:
@@ -198,11 +198,15 @@ static int action_create(int arg)
|
||||
};
|
||||
char *password = NULL;
|
||||
unsigned int passwordLen;
|
||||
unsigned int key_size = (opt_key_size ?: DEFAULT_PLAIN_KEYBITS) / 8;
|
||||
int r;
|
||||
|
||||
if (params.hash && !strcmp(params.hash, "plain"))
|
||||
params.hash = NULL;
|
||||
|
||||
if (opt_key_file)
|
||||
params.hash = NULL;
|
||||
|
||||
r = crypt_parse_name_and_mode(opt_cipher ?: DEFAULT_CIPHER(PLAIN),
|
||||
cipher, cipher_mode);
|
||||
if (r < 0) {
|
||||
@@ -219,20 +223,28 @@ static int action_create(int arg)
|
||||
r = crypt_format(cd, CRYPT_PLAIN,
|
||||
cipher, cipher_mode,
|
||||
NULL, NULL,
|
||||
(opt_key_size ?: DEFAULT_PLAIN_KEYBITS) / 8,
|
||||
key_size,
|
||||
¶ms);
|
||||
if (r < 0)
|
||||
goto out;
|
||||
|
||||
r = crypt_get_key(_("Enter passphrase: "), &password, &passwordLen,
|
||||
opt_keyfile_size, opt_key_file, opt_timeout,
|
||||
opt_batch_mode ? 0 : opt_verify_passphrase, cd);
|
||||
if (r < 0)
|
||||
goto out;
|
||||
if (opt_key_file)
|
||||
r = crypt_activate_by_keyfile(cd, action_argv[0],
|
||||
CRYPT_ANY_SLOT, opt_key_file, key_size,
|
||||
opt_readonly ? CRYPT_ACTIVATE_READONLY : 0);
|
||||
else {
|
||||
r = crypt_get_key(_("Enter passphrase: "),
|
||||
&password, &passwordLen, 0, NULL,
|
||||
opt_timeout,
|
||||
opt_batch_mode ? 0 : opt_verify_passphrase,
|
||||
cd);
|
||||
if (r < 0)
|
||||
goto out;
|
||||
|
||||
r = crypt_activate_by_passphrase(cd, action_argv[0], CRYPT_ANY_SLOT,
|
||||
password, passwordLen,
|
||||
opt_readonly ? CRYPT_ACTIVATE_READONLY : 0);
|
||||
r = crypt_activate_by_passphrase(cd, action_argv[0],
|
||||
CRYPT_ANY_SLOT, password, passwordLen,
|
||||
opt_readonly ? CRYPT_ACTIVATE_READONLY : 0);
|
||||
}
|
||||
out:
|
||||
crypt_free(cd);
|
||||
crypt_safe_free(password);
|
||||
|
||||
Reference in New Issue
Block a user