|
Vojtech Trefny |
75aaea |
From 5d29bc014a33d9bdc1c5fb4b8add2f38850f46a8 Mon Sep 17 00:00:00 2001
|
|
Vojtech Trefny |
75aaea |
From: Vojtech Trefny <vtrefny@redhat.com>
|
|
Vojtech Trefny |
75aaea |
Date: Wed, 24 Feb 2021 14:44:03 +0100
|
|
Vojtech Trefny |
75aaea |
Subject: [PATCH] crypto: Fix default key size for non XTS ciphers
|
|
Vojtech Trefny |
75aaea |
|
|
Vojtech Trefny |
75aaea |
512 bits should be default only for AES-XTS which needs two keys,
|
|
Vojtech Trefny |
75aaea |
default for other modes must be 256 bits.
|
|
Vojtech Trefny |
75aaea |
|
|
Vojtech Trefny |
75aaea |
resolves: rhbz#1931847
|
|
Vojtech Trefny |
75aaea |
---
|
|
Vojtech Trefny |
75aaea |
src/plugins/crypto.c | 11 +++++++++--
|
|
Vojtech Trefny |
75aaea |
src/plugins/crypto.h | 2 +-
|
|
Vojtech Trefny |
75aaea |
tests/crypto_test.py | 36 ++++++++++++++++++++++++++++++++++++
|
|
Vojtech Trefny |
75aaea |
3 files changed, 46 insertions(+), 3 deletions(-)
|
|
Vojtech Trefny |
75aaea |
|
|
Vojtech Trefny |
75aaea |
diff --git a/src/plugins/crypto.c b/src/plugins/crypto.c
|
|
Vojtech Trefny |
75aaea |
index f4a2e8f0..1e7043fa 100644
|
|
Vojtech Trefny |
75aaea |
--- a/src/plugins/crypto.c
|
|
Vojtech Trefny |
75aaea |
+++ b/src/plugins/crypto.c
|
|
Vojtech Trefny |
75aaea |
@@ -774,8 +774,15 @@ static gboolean luks_format (const gchar *device, const gchar *cipher, guint64 k
|
|
Vojtech Trefny |
75aaea |
return FALSE;
|
|
Vojtech Trefny |
75aaea |
}
|
|
Vojtech Trefny |
75aaea |
|
|
Vojtech Trefny |
75aaea |
- /* resolve requested/default key_size (should be in bytes) */
|
|
Vojtech Trefny |
75aaea |
- key_size = (key_size != 0) ? (key_size / 8) : (DEFAULT_LUKS_KEYSIZE_BITS / 8);
|
|
Vojtech Trefny |
75aaea |
+ if (key_size == 0) {
|
|
Vojtech Trefny |
75aaea |
+ if (g_str_has_prefix (cipher_specs[1], "xts-"))
|
|
Vojtech Trefny |
75aaea |
+ key_size = DEFAULT_LUKS_KEYSIZE_BITS * 2;
|
|
Vojtech Trefny |
75aaea |
+ else
|
|
Vojtech Trefny |
75aaea |
+ key_size = DEFAULT_LUKS_KEYSIZE_BITS;
|
|
Vojtech Trefny |
75aaea |
+ }
|
|
Vojtech Trefny |
75aaea |
+
|
|
Vojtech Trefny |
75aaea |
+ /* key_size should be in bytes */
|
|
Vojtech Trefny |
75aaea |
+ key_size = key_size / 8;
|
|
Vojtech Trefny |
75aaea |
|
|
Vojtech Trefny |
75aaea |
/* wait for enough random data entropy (if requested) */
|
|
Vojtech Trefny |
75aaea |
if (min_entropy > 0) {
|
|
Vojtech Trefny |
75aaea |
diff --git a/src/plugins/crypto.h b/src/plugins/crypto.h
|
|
Vojtech Trefny |
75aaea |
index 71a1438d..a38724d9 100644
|
|
Vojtech Trefny |
75aaea |
--- a/src/plugins/crypto.h
|
|
Vojtech Trefny |
75aaea |
+++ b/src/plugins/crypto.h
|
|
Vojtech Trefny |
75aaea |
@@ -36,7 +36,7 @@ typedef enum {
|
|
Vojtech Trefny |
75aaea |
/* 20 chars * 6 bits per char (64-item charset) = 120 "bits of security" */
|
|
Vojtech Trefny |
75aaea |
#define BD_CRYPTO_BACKUP_PASSPHRASE_LENGTH 20
|
|
Vojtech Trefny |
75aaea |
|
|
Vojtech Trefny |
75aaea |
-#define DEFAULT_LUKS_KEYSIZE_BITS 512
|
|
Vojtech Trefny |
75aaea |
+#define DEFAULT_LUKS_KEYSIZE_BITS 256
|
|
Vojtech Trefny |
75aaea |
#define DEFAULT_LUKS_CIPHER "aes-xts-plain64"
|
|
Vojtech Trefny |
75aaea |
#define DEFAULT_LUKS2_SECTOR_SIZE 512
|
|
Vojtech Trefny |
75aaea |
|
|
Vojtech Trefny |
75aaea |
diff --git a/tests/crypto_test.py b/tests/crypto_test.py
|
|
Vojtech Trefny |
75aaea |
index 0609a070..0aecc032 100644
|
|
Vojtech Trefny |
75aaea |
--- a/tests/crypto_test.py
|
|
Vojtech Trefny |
75aaea |
+++ b/tests/crypto_test.py
|
|
Vojtech Trefny |
75aaea |
@@ -236,6 +236,42 @@ def test_luks2_format(self):
|
|
Vojtech Trefny |
75aaea |
self.fail("Failed to get pbkdf information from:\n%s %s" % (out, err))
|
|
Vojtech Trefny |
75aaea |
self.assertEqual(int(m.group(1)), 5)
|
|
Vojtech Trefny |
75aaea |
|
|
Vojtech Trefny |
75aaea |
+ def _get_luks1_key_size(self, device):
|
|
Vojtech Trefny |
75aaea |
+ _ret, out, err = run_command("cryptsetup luksDump %s" % device)
|
|
Vojtech Trefny |
75aaea |
+ m = re.search(r"MK bits:\s*(\S+)\s*", out)
|
|
Vojtech Trefny |
75aaea |
+ if not m or len(m.groups()) != 1:
|
|
Vojtech Trefny |
75aaea |
+ self.fail("Failed to get key size information from:\n%s %s" % (out, err))
|
|
Vojtech Trefny |
75aaea |
+ key_size = m.group(1)
|
|
Vojtech Trefny |
75aaea |
+ if not key_size.isnumeric():
|
|
Vojtech Trefny |
75aaea |
+ self.fail("Failed to get key size information from: %s" % key_size)
|
|
Vojtech Trefny |
75aaea |
+ return int(key_size)
|
|
Vojtech Trefny |
75aaea |
+
|
|
Vojtech Trefny |
75aaea |
+ @tag_test(TestTags.SLOW, TestTags.CORE)
|
|
Vojtech Trefny |
75aaea |
+ def test_luks_format_key_size(self):
|
|
Vojtech Trefny |
75aaea |
+ """Verify that formating device as LUKS works"""
|
|
Vojtech Trefny |
75aaea |
+
|
|
Vojtech Trefny |
75aaea |
+ # aes-xts: key size should default to 512
|
|
Vojtech Trefny |
75aaea |
+ succ = BlockDev.crypto_luks_format(self.loop_dev, "aes-xts-plain64", 0, PASSWD, None, 0)
|
|
Vojtech Trefny |
75aaea |
+ self.assertTrue(succ)
|
|
Vojtech Trefny |
75aaea |
+
|
|
Vojtech Trefny |
75aaea |
+ key_size = self._get_luks1_key_size(self.loop_dev)
|
|
Vojtech Trefny |
75aaea |
+ self.assertEqual(key_size, 512)
|
|
Vojtech Trefny |
75aaea |
+
|
|
Vojtech Trefny |
75aaea |
+ # aes-cbc: key size should default to 256
|
|
Vojtech Trefny |
75aaea |
+ succ = BlockDev.crypto_luks_format(self.loop_dev, "aes-cbc-essiv:sha256", 0, PASSWD, None, 0)
|
|
Vojtech Trefny |
75aaea |
+ self.assertTrue(succ)
|
|
Vojtech Trefny |
75aaea |
+
|
|
Vojtech Trefny |
75aaea |
+ key_size = self._get_luks1_key_size(self.loop_dev)
|
|
Vojtech Trefny |
75aaea |
+ self.assertEqual(key_size, 256)
|
|
Vojtech Trefny |
75aaea |
+
|
|
Vojtech Trefny |
75aaea |
+ # try specifying key size for aes-xts
|
|
Vojtech Trefny |
75aaea |
+ succ = BlockDev.crypto_luks_format(self.loop_dev, "aes-xts-plain64", 256, PASSWD, None, 0)
|
|
Vojtech Trefny |
75aaea |
+ self.assertTrue(succ)
|
|
Vojtech Trefny |
75aaea |
+
|
|
Vojtech Trefny |
75aaea |
+ key_size = self._get_luks1_key_size(self.loop_dev)
|
|
Vojtech Trefny |
75aaea |
+ self.assertEqual(key_size, 256)
|
|
Vojtech Trefny |
75aaea |
+
|
|
Vojtech Trefny |
75aaea |
+
|
|
Vojtech Trefny |
75aaea |
class CryptoTestResize(CryptoTestCase):
|
|
Vojtech Trefny |
75aaea |
|
|
Vojtech Trefny |
75aaea |
def _get_key_location(self, device):
|