summaryrefslogtreecommitdiffstats
path: root/src/utils_reencrypt.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/utils_reencrypt.c43
1 files changed, 33 insertions, 10 deletions
diff --git a/src/utils_reencrypt.c b/src/utils_reencrypt.c
index a78557c..7546811 100644
--- a/src/utils_reencrypt.c
+++ b/src/utils_reencrypt.c
@@ -1,9 +1,9 @@
/*
* cryptsetup - action re-encryption utilities
*
- * Copyright (C) 2009-2023 Red Hat, Inc. All rights reserved.
- * Copyright (C) 2009-2023 Milan Broz
- * Copyright (C) 2021-2023 Ondrej Kozina
+ * Copyright (C) 2009-2024 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2009-2024 Milan Broz
+ * Copyright (C) 2021-2024 Ondrej Kozina
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -306,7 +306,7 @@ static int reencrypt_luks2_load(struct crypt_device *cd, const char *data_device
if (!ARG_SET(OPT_BATCH_MODE_ID) && !ARG_SET(OPT_RESUME_ONLY_ID)) {
r = asprintf(&msg, _("Device %s is already in LUKS2 reencryption. "
"Do you wish to resume previously initialised operation?"),
- crypt_get_metadata_device_name(cd) ?: data_device);
+ crypt_get_metadata_device_name(cd) ?: crypt_get_device_name(cd));
if (r < 0) {
r = -ENOMEM;
goto out;
@@ -349,11 +349,6 @@ static int luks2_reencrypt_in_progress(struct crypt_device *cd)
if (crypt_persistent_flags_get(cd, CRYPT_FLAGS_REQUIREMENTS, &flags))
return -EINVAL;
- if (flags & CRYPT_REQUIREMENT_OFFLINE_REENCRYPT) {
- log_err(_("Legacy LUKS2 reencryption is no longer supported."));
- return -EINVAL;
- }
-
return flags & CRYPT_REQUIREMENT_ONLINE_REENCRYPT;
}
@@ -411,14 +406,34 @@ static enum device_status_info load_luks(struct crypt_device **r_cd,
static bool luks2_reencrypt_eligible(struct crypt_device *cd)
{
+ uint32_t flags;
struct crypt_params_integrity ip = { 0 };
+ if (crypt_persistent_flags_get(cd, CRYPT_FLAGS_REQUIREMENTS, &flags))
+ return false;
+
+ if (flags & CRYPT_REQUIREMENT_OFFLINE_REENCRYPT) {
+ log_err(_("Legacy LUKS2 reencryption is no longer supported."));
+ return false;
+ }
+
+ if (flags & CRYPT_REQUIREMENT_OPAL) {
+ log_err(_("Can not reencrypt LUKS2 device configured to use OPAL."));
+ return false;
+ }
+
/* raw integrity info is available since 2.0 */
if (crypt_get_integrity_info(cd, &ip) || ip.tag_size) {
log_err(_("Reencryption of device with integrity profile is not supported."));
return false;
}
+ /* Check that cipher is in compatible format */
+ if (!crypt_get_cipher(cd)) {
+ log_err(_("No known cipher specification pattern detected in LUKS2 header."));
+ return false;
+ }
+
return true;
}
@@ -1322,9 +1337,15 @@ static int check_broken_luks_signature(const char *device)
int r;
size_t count;
+ if (ARG_SET(OPT_DISABLE_BLKID_ID))
+ return 0;
+
r = tools_detect_signatures(device, PRB_ONLY_LUKS, &count, ARG_SET(OPT_BATCH_MODE_ID));
- if (r < 0)
+ if (r < 0) {
+ if (r == -EIO)
+ log_err(_("Blkid scan failed for %s."), device);
return -EINVAL;
+ }
if (count) {
log_err(_("Device %s contains broken LUKS metadata. Aborting operation."), device);
return -EINVAL;
@@ -1449,6 +1470,8 @@ static int _decrypt(struct crypt_device **cd, enum device_status_info dev_st, co
if ((r = reencrypt_luks2_load(*cd, data_device)) < 0)
return r;
} else if (dev_st == DEVICE_LUKS2) {
+ if (!luks2_reencrypt_eligible(*cd))
+ return -EINVAL;
if (!ARG_SET(OPT_HEADER_ID)) {
log_err(_("LUKS2 decryption requires --header option."));
return -EINVAL;