Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/plugins/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -2598,12 +2598,14 @@ BDCryptoLUKSInfo* bd_crypto_luks_info (const gchar *device, GError **error) {
if (ret != 0) {
/* not a block device, try init_by_name */
crypt_free (cd);
cd = NULL;
ret = crypt_init_by_name (&cd, device);
} else {
ret = crypt_load (cd, CRYPT_LUKS, NULL);
if (ret != 0) {
/* not a LUKS device, try init_by_name */
crypt_free (cd);
cd = NULL;
ret = crypt_init_by_name (&cd, device);
}
}
Expand Down Expand Up @@ -2751,6 +2753,7 @@ BDCryptoIntegrityInfo* bd_crypto_integrity_info (const gchar *device, GError **e
if (ret != 0) {
/* not a block device, try init_by_name */
crypt_free (cd);
cd = NULL;
ret = crypt_init_by_name (&cd, device);
} else {
ret = crypt_load (cd, CRYPT_LUKS, NULL);
Expand All @@ -2759,6 +2762,7 @@ BDCryptoIntegrityInfo* bd_crypto_integrity_info (const gchar *device, GError **e
ret = crypt_load (cd, CRYPT_INTEGRITY, NULL);
if (ret != 0) {
crypt_free (cd);
cd = NULL;
ret = crypt_init_by_name (&cd, device);
}
}
Expand Down Expand Up @@ -2824,12 +2828,14 @@ BDCryptoLUKSTokenInfo** bd_crypto_luks_token_info (const gchar *device, GError *
if (ret != 0) {
/* not a block device, try init_by_name */
crypt_free (cd);
cd = NULL;
ret = crypt_init_by_name (&cd, device);
} else {
ret = crypt_load (cd, CRYPT_LUKS, NULL);
if (ret != 0) {
/* not a LUKS device, try init_by_name */
crypt_free (cd);
cd = NULL;
ret = crypt_init_by_name (&cd, device);
}
}
Expand Down
10 changes: 10 additions & 0 deletions tests/crypto_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,10 @@ def _verify_luks_info(self, info, version):
def test_luks_info(self):
"""Verify that we can get information about a LUKS device"""

with self.assertRaisesRegex(GLib.GError, "Failed to initialize device"):
# not a LUKS device
BlockDev.crypto_luks_info(self.loop_devs[0])

ctx = BlockDev.CryptoKeyslotContext(passphrase=PASSWD)
succ = BlockDev.crypto_luks_format(self.loop_devs[0], "aes-cbc-essiv:sha256", 256, ctx, 0)
self.assertTrue(succ)
Expand Down Expand Up @@ -1430,6 +1434,9 @@ def test_luks2_integrity(self):
if not BlockDev.utils_have_kernel_module("dm-integrity"):
self.skipTest('dm-integrity kernel module not available, skipping.')

with self.assertRaisesRegex(GLib.GError, "Failed to initialize device"):
BlockDev.crypto_integrity_info(self.loop_devs[0])

extra = BlockDev.CryptoLUKSExtra()
extra.integrity = "hmac(sha256)"

Expand Down Expand Up @@ -1476,6 +1483,9 @@ def _verify_token_info (self, info):
def test_luks2_token_info(self):
"""Verify that we can get information about LUKS2 tokens"""

with self.assertRaisesRegex(GLib.GError, "Failed to initialize device"):
BlockDev.crypto_luks_token_info(self.loop_devs[0])

# the simple case with password
self._luks2_format(self.loop_devs[0], PASSWD, None, fast_pbkdf=True)

Expand Down
Loading