mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-14 20:30:04 +01:00
Support online reencryption for PAES cipher.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com> (With few adjustments by Ondrej Kozina)
This commit is contained in:
@@ -2882,7 +2882,7 @@ static int reencrypt_init_by_passphrase(struct crypt_device *cd,
|
|||||||
if (flags & CRYPT_REENCRYPT_RECOVERY)
|
if (flags & CRYPT_REENCRYPT_RECOVERY)
|
||||||
return reencrypt_recovery_by_passphrase(cd, hdr, keyslot_old, keyslot_new, passphrase, passphrase_size);
|
return reencrypt_recovery_by_passphrase(cd, hdr, keyslot_old, keyslot_new, passphrase, passphrase_size);
|
||||||
|
|
||||||
if (cipher) {
|
if (cipher && !crypt_cipher_wrapped_key(cipher, cipher_mode)) {
|
||||||
r = crypt_keyslot_get_key_size(cd, keyslot_new);
|
r = crypt_keyslot_get_key_size(cd, keyslot_new);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ as soon as possible and mounted (used) before full data area encryption is compl
|
|||||||
|
|
||||||
Action supports following additional \fB<options>\fR [\-\-encrypt, \-\-decrypt, \-\-device\-size,
|
Action supports following additional \fB<options>\fR [\-\-encrypt, \-\-decrypt, \-\-device\-size,
|
||||||
\-\-resilience, \-\-resilience-hash, \-\-hotzone-size, \-\-init\-only, \-\-resume\-only,
|
\-\-resilience, \-\-resilience-hash, \-\-hotzone-size, \-\-init\-only, \-\-resume\-only,
|
||||||
\-\-reduce\-device\-size].
|
\-\-reduce\-device\-size, \-\-master\-key\-file, \-\-key\-size].
|
||||||
|
|
||||||
.SH PLAIN MODE
|
.SH PLAIN MODE
|
||||||
Plain dm-crypt encrypts the device sector-by-sector with a
|
Plain dm-crypt encrypts the device sector-by-sector with a
|
||||||
|
|||||||
@@ -3119,7 +3119,7 @@ static int action_reencrypt_luks2(struct crypt_device *cd)
|
|||||||
{
|
{
|
||||||
size_t i, vk_size, kp_size;
|
size_t i, vk_size, kp_size;
|
||||||
int r, keyslot_old = CRYPT_ANY_SLOT, keyslot_new = CRYPT_ANY_SLOT, key_size;
|
int r, keyslot_old = CRYPT_ANY_SLOT, keyslot_new = CRYPT_ANY_SLOT, key_size;
|
||||||
char dm_name[PATH_MAX], cipher [MAX_CIPHER_LEN], mode[MAX_CIPHER_LEN], *vk;
|
char dm_name[PATH_MAX], cipher [MAX_CIPHER_LEN], mode[MAX_CIPHER_LEN], *vk = NULL;
|
||||||
const char *active_name = NULL;
|
const char *active_name = NULL;
|
||||||
struct keyslot_passwords *kp;
|
struct keyslot_passwords *kp;
|
||||||
struct crypt_params_luks2 luks2_params = {};
|
struct crypt_params_luks2 luks2_params = {};
|
||||||
@@ -3161,6 +3161,7 @@ static int action_reencrypt_luks2(struct crypt_device *cd)
|
|||||||
|
|
||||||
if (!key_size)
|
if (!key_size)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
vk_size = key_size;
|
||||||
|
|
||||||
r = crypt_keyslot_max(CRYPT_LUKS2);
|
r = crypt_keyslot_max(CRYPT_LUKS2);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@@ -3175,11 +3176,11 @@ static int action_reencrypt_luks2(struct crypt_device *cd)
|
|||||||
if (r)
|
if (r)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
vk_size = key_size;
|
if (opt_master_key_file) {
|
||||||
vk = crypt_safe_alloc(vk_size);
|
r = tools_read_mk(opt_master_key_file, &vk, key_size);
|
||||||
if (!vk) {
|
|
||||||
r = -ENOMEM;
|
if (r < 0)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = -ENOENT;
|
r = -ENOENT;
|
||||||
@@ -3189,7 +3190,7 @@ static int action_reencrypt_luks2(struct crypt_device *cd)
|
|||||||
r = set_keyslot_params(cd, i);
|
r = set_keyslot_params(cd, i);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
break;
|
break;
|
||||||
r = crypt_keyslot_add_by_key(cd, CRYPT_ANY_SLOT, NULL, key_size,
|
r = crypt_keyslot_add_by_key(cd, CRYPT_ANY_SLOT, vk, key_size,
|
||||||
kp[i].password, kp[i].passwordLen, CRYPT_VOLUME_KEY_NO_SEGMENT);
|
kp[i].password, kp[i].passwordLen, CRYPT_VOLUME_KEY_NO_SEGMENT);
|
||||||
tools_keyslot_msg(r, CREATED);
|
tools_keyslot_msg(r, CREATED);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@@ -3198,9 +3199,17 @@ static int action_reencrypt_luks2(struct crypt_device *cd)
|
|||||||
kp[i].new = r;
|
kp[i].new = r;
|
||||||
keyslot_new = r;
|
keyslot_new = r;
|
||||||
keyslot_old = i;
|
keyslot_old = i;
|
||||||
r = crypt_volume_key_get(cd, keyslot_new, vk, &vk_size, kp[i].password, kp[i].passwordLen);
|
if (!vk) {
|
||||||
if (r < 0)
|
/* key generated in crypt_keyslot_add_by_key() call above */
|
||||||
break;
|
vk = crypt_safe_alloc(key_size);
|
||||||
|
if (!vk) {
|
||||||
|
r = -ENOMEM;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
r = crypt_volume_key_get(cd, keyslot_new, vk, &vk_size, kp[i].password, kp[i].passwordLen);
|
||||||
|
if (r < 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
r = assign_tokens(cd, i, r);
|
r = assign_tokens(cd, i, r);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
break;
|
break;
|
||||||
@@ -3220,8 +3229,6 @@ static int action_reencrypt_luks2(struct crypt_device *cd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
crypt_safe_free(vk);
|
|
||||||
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
@@ -3241,6 +3248,7 @@ static int action_reencrypt_luks2(struct crypt_device *cd)
|
|||||||
kp[keyslot_old].passwordLen, keyslot_old, kp[keyslot_old].new,
|
kp[keyslot_old].passwordLen, keyslot_old, kp[keyslot_old].new,
|
||||||
cipher, mode, ¶ms);
|
cipher, mode, ¶ms);
|
||||||
err:
|
err:
|
||||||
|
crypt_safe_free(vk);
|
||||||
for (i = 0; i < kp_size; i++) {
|
for (i = 0; i < kp_size; i++) {
|
||||||
crypt_safe_free(kp[i].password);
|
crypt_safe_free(kp[i].password);
|
||||||
if (r < 0 && kp[i].new >= 0 &&
|
if (r < 0 && kp[i].new >= 0 &&
|
||||||
|
|||||||
Reference in New Issue
Block a user