mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-14 20:30:04 +01:00
Use stdin and "-" file check wrapper.
This commit is contained in:
@@ -124,7 +124,6 @@ static int action_open_plain(void)
|
||||
size_t passwordLen;
|
||||
size_t key_size = (opt_key_size ?: DEFAULT_PLAIN_KEYBITS) / 8;
|
||||
uint32_t activate_flags = 0;
|
||||
int keyfile_limited = 0;
|
||||
int r;
|
||||
|
||||
r = crypt_parse_name_and_mode(opt_cipher ?: DEFAULT_CIPHER(PLAIN),
|
||||
@@ -134,11 +133,8 @@ static int action_open_plain(void)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (opt_key_file && strcmp(opt_key_file, "-") != 0)
|
||||
keyfile_limited = 1;
|
||||
|
||||
/* FIXME: temporary hack, no hashing for keyfiles in plain mode */
|
||||
if (opt_key_file && keyfile_limited) {
|
||||
if (opt_key_file && !tools_is_stdin(opt_key_file)) {
|
||||
params.hash = NULL;
|
||||
if (!opt_batch_mode && opt_hash)
|
||||
log_std(_("WARNING: The --hash parameter is being ignored "
|
||||
@@ -148,7 +144,7 @@ static int action_open_plain(void)
|
||||
if (params.hash && !strcmp(params.hash, "plain"))
|
||||
params.hash = NULL;
|
||||
|
||||
if (!opt_batch_mode && !params.hash && opt_key_file && keyfile_limited && opt_keyfile_size)
|
||||
if (!opt_batch_mode && !params.hash && opt_key_file && !tools_is_stdin(opt_key_file) && opt_keyfile_size)
|
||||
log_std(_("WARNING: The --keyfile-size option is being ignored, "
|
||||
"the read size is the same as the encryption key size.\n"));
|
||||
|
||||
@@ -172,7 +168,7 @@ static int action_open_plain(void)
|
||||
|
||||
_set_activation_flags(&activate_flags);
|
||||
|
||||
if (opt_key_file) {
|
||||
if (!tools_is_stdin(opt_key_file)) {
|
||||
/* If no hash, key is read directly, read size is always key_size
|
||||
* (possible opt_keyfile_size is ignored.
|
||||
* If hash is specified, opt_keyfile_size is applied.
|
||||
@@ -185,8 +181,8 @@ static int action_open_plain(void)
|
||||
} else {
|
||||
r = tools_get_key(_("Enter passphrase: "),
|
||||
&password, &passwordLen,
|
||||
opt_keyfile_offset, opt_keyfile_size,
|
||||
NULL, opt_timeout,
|
||||
opt_keyfile_offset, (opt_key_file && !params.hash) ? key_size : opt_keyfile_size,
|
||||
opt_key_file, opt_timeout,
|
||||
_verify_passphrase(0), 0,
|
||||
cd);
|
||||
if (r < 0)
|
||||
|
||||
@@ -81,6 +81,7 @@ int tools_get_key(const char *prompt,
|
||||
const char *key_file,
|
||||
int timeout, int verify, int pwquality,
|
||||
struct crypt_device *cd);
|
||||
int tools_is_stdin(const char *key_file);
|
||||
|
||||
/* Log */
|
||||
#define log_dbg(x...) clogger(NULL, CRYPT_LOG_DEBUG, __FILE__, __LINE__, x)
|
||||
|
||||
@@ -65,6 +65,17 @@ static int tools_check_pwquality(const char *password)
|
||||
}
|
||||
#endif /* ENABLE_PWQUALITY */
|
||||
|
||||
/*
|
||||
* Keyfile - is standard input treated as a binary file (no EOL handling).
|
||||
*/
|
||||
int tools_is_stdin(const char *key_file)
|
||||
{
|
||||
if (!key_file)
|
||||
return 1;
|
||||
|
||||
return strcmp(key_file, "-") ? 0 : 1;
|
||||
}
|
||||
|
||||
int tools_get_key(const char *prompt,
|
||||
char **key, size_t *key_size,
|
||||
size_t keyfile_offset, size_t keyfile_size_max,
|
||||
|
||||
Reference in New Issue
Block a user