/* key is coming from tty, fd or binary stdin */
if (hash_name) {
if (hash(NULL, hash_name, key, key_size, pass, passLen) < 0) {
- log_err(cd, _("Key processing error.\n"));
+ log_err(cd, _("Key processing error (using hash algorithm %s).\n"),
+ hash_name);
safe_free(key);
return NULL;
}
const char *uuid,
struct crypt_params_plain *params)
{
- if (!cipher || !cipher_mode || !params || !params->hash) {
+ if (!cipher || !cipher_mode) {
log_err(cd, _("Invalid plain crypt parameters.\n"));
return -EINVAL;
}
if (uuid)
cd->plain_uuid = strdup(uuid);
- if (params->hash)
+ if (params && params->hash)
cd->plain_hdr.hash = strdup(params->hash);
- cd->plain_hdr.offset = params->offset;
- cd->plain_hdr.skip = params->skip;
+ cd->plain_hdr.offset = params ? params->offset : 0;
+ cd->plain_hdr.skip = params ? params->skip : 0;
- if ((params->hash && !cd->plain_hdr.hash) ||
- !cd->plain_cipher || !cd->plain_cipher_mode)
+ if (!cd->plain_cipher || !cd->plain_cipher_mode)
return -ENOMEM;
return 0;
return -ENOMEM;
}
- if (isPLAIN(cd->type)) {
+ if (isPLAIN(cd->type) && cd->plain_hdr.hash) {
processed_key = process_key(cd, cd->plain_hdr.hash, NULL, key_len,
passphrase, passphrase_size);
if (!processed_key) {
static void cmdLineLog(int level, char *msg)
{
- strncat(global_log, msg, sizeof(global_log));
+ strncat(global_log, msg, sizeof(global_log) - strlen(global_log));
global_lines++;
}
static void _cleanup(void)
{
+ int r;
struct stat st;
- //system("udevadm settle");
+ //r = system("udevadm settle");
if (!stat(DMDIR CDEVICE_1, &st))
- system("dmsetup remove " CDEVICE_1);
+ r = system("dmsetup remove " CDEVICE_1);
if (!stat(DMDIR CDEVICE_2, &st))
- system("dmsetup remove " CDEVICE_2);
+ r = system("dmsetup remove " CDEVICE_2);
if (!stat(DEVICE_EMPTY, &st))
- system("dmsetup remove " DEVICE_EMPTY_name);
+ r = system("dmsetup remove " DEVICE_EMPTY_name);
if (!stat(DEVICE_ERROR, &st))
- system("dmsetup remove " DEVICE_ERROR_name);
+ r = system("dmsetup remove " DEVICE_ERROR_name);
if (!strncmp("/dev/loop", DEVICE_1, 9))
- system("losetup -d " DEVICE_1);
+ r = system("losetup -d " DEVICE_1);
if (!strncmp("/dev/loop", DEVICE_2, 9))
- system("losetup -d " DEVICE_2);
+ r = system("losetup -d " DEVICE_2);
- system("rm -f " IMAGE_EMPTY);
+ r = system("rm -f " IMAGE_EMPTY);
_remove_keyfiles();
}
static void _setup(void)
{
- system("dmsetup create " DEVICE_EMPTY_name " --table \"0 10000 zero\"");
- system("dmsetup create " DEVICE_ERROR_name " --table \"0 10000 error\"");
+ int r;
+
+ r = system("dmsetup create " DEVICE_EMPTY_name " --table \"0 10000 zero\"");
+ r = system("dmsetup create " DEVICE_ERROR_name " --table \"0 10000 error\"");
if (!strncmp("/dev/loop", DEVICE_1, 9))
- system("losetup " DEVICE_1 " " IMAGE1);
+ r = system("losetup " DEVICE_1 " " IMAGE1);
if (!strncmp("/dev/loop", DEVICE_2, 9)) {
- system("dd if=/dev/zero of=" IMAGE_EMPTY " bs=1M count=4");
- system("losetup " DEVICE_2 " " IMAGE_EMPTY);
+ r = system("dd if=/dev/zero of=" IMAGE_EMPTY " bs=1M count=4");
+ r = system("losetup " DEVICE_2 " " IMAGE_EMPTY);
}
}
FAIL_(crypt_init(&cd, ""), "empty device string");
+ // default is "plain" hash - no password hash
+ OK_(crypt_init(&cd, DEVICE_1));
+ OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_size, NULL));
+ OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
+ EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
+ // FIXME: this should get key from active device?
+ //OK_(crypt_volume_key_get(cd, CRYPT_ANY_SLOT, key2, &key_size, passphrase, strlen(passphrase)));
+ //OK_(memcmp(key, key2, key_size));
+ OK_(crypt_deactivate(cd, CDEVICE_1));
+ crypt_free(cd);
+
+ // Now use hashed password
OK_(crypt_init(&cd, DEVICE_1));
OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_size, ¶ms));
OK_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphrase, strlen(passphrase), 0));