Skip to content

Commit 625c894

Browse files
Merge pull request #1158 from vojtechtrefny/master_change-key-fix
crypto: Fix reading keyfile in bd_crypto_luks_change_key
2 parents 1d15c5a + 5b02aaf commit 625c894

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/plugins/crypto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1734,7 +1734,7 @@ gboolean bd_crypto_luks_change_key (const gchar *device, BDCryptoKeyslotContext
17341734
}
17351735

17361736
if (ncontext->type == BD_CRYPTO_KEYSLOT_CONTEXT_TYPE_KEYFILE) {
1737-
ret = crypt_keyfile_device_read (cd, ncontext->u.keyfile.keyfile, &key_buf, &buf_len,
1737+
ret = crypt_keyfile_device_read (cd, ncontext->u.keyfile.keyfile, &nkey_buf, &nbuf_len,
17381738
ncontext->u.keyfile.keyfile_offset, ncontext->u.keyfile.key_size, 0);
17391739
if (ret != 0) {
17401740
g_set_error (&l_error, BD_CRYPTO_ERROR, BD_CRYPTO_ERROR_KEYFILE_FAILED,

tests/crypto_test.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,33 @@ def _change_key(self, create_fn):
631631
succ = BlockDev.crypto_luks_change_key(self.loop_devs[0], ctx, nctx)
632632
self.assertTrue(succ)
633633

634+
# old passphrase should no longer work
635+
with self.assertRaises(GLib.GError):
636+
BlockDev.crypto_luks_remove_key(self.loop_devs[0], ctx)
637+
638+
# new passphrase should work
639+
succ = BlockDev.crypto_luks_open(self.loop_devs[0], "libblockdevTestLUKS", nctx)
640+
self.assertTrue(succ)
641+
642+
succ = BlockDev.crypto_luks_close("libblockdevTestLUKS")
643+
self.assertTrue(succ)
644+
645+
# try with keyfile as well
646+
kctx = BlockDev.CryptoKeyslotContext(keyfile=self.keyfile)
647+
succ = BlockDev.crypto_luks_change_key(self.loop_devs[0], nctx, kctx)
648+
self.assertTrue(succ)
649+
650+
# old passphrase should no longer work
651+
with self.assertRaises(GLib.GError):
652+
BlockDev.crypto_luks_remove_key(self.loop_devs[0], nctx)
653+
654+
# keyfile should work
655+
succ = BlockDev.crypto_luks_open(self.loop_devs[0], "libblockdevTestLUKS", kctx)
656+
self.assertTrue(succ)
657+
658+
succ = BlockDev.crypto_luks_close("libblockdevTestLUKS")
659+
self.assertTrue(succ)
660+
634661
@tag_test(TestTags.SLOW)
635662
def test_luks_change_key(self):
636663
self._change_key(self._luks_format)

0 commit comments

Comments
 (0)