@@ -135,6 +135,28 @@ def setUp(self):
135135 def test_plugin_version (self ):
136136 self .assertEqual (BlockDev .get_plugin_soname (BlockDev .Plugin .CRYPTO ), "libbd_crypto.so.3" )
137137
138+ @tag_test (TestTags .NOSTORAGE )
139+ def test_tech_available (self ):
140+ """Verify that checking crypto functionality availability by technology works as expected"""
141+ succ = BlockDev .crypto_is_tech_avail (BlockDev .CryptoTech .LUKS , BlockDev .CryptoTechMode .CREATE )
142+ self .assertTrue (succ )
143+
144+ if HAVE_BITLK :
145+ succ = BlockDev .crypto_is_tech_avail (BlockDev .CryptoTech .BITLK , BlockDev .CryptoTechMode .OPEN_CLOSE )
146+ self .assertTrue (succ )
147+
148+ # create is not supported with bitlk
149+ with self .assertRaises (GLib .GError ):
150+ BlockDev .crypto_is_tech_avail (BlockDev .CryptoTech .BITLK , BlockDev .CryptoTechMode .CREATE )
151+
152+ if HAVE_FVAULT2 :
153+ succ = BlockDev .crypto_is_tech_avail (BlockDev .CryptoTech .FVAULT2 , BlockDev .CryptoTechMode .OPEN_CLOSE )
154+ self .assertTrue (succ )
155+
156+ # create is not supported with fvault
157+ with self .assertRaises (GLib .GError ):
158+ BlockDev .crypto_is_tech_avail (BlockDev .CryptoTech .FVAULT2 , BlockDev .CryptoTechMode .CREATE )
159+
138160 @tag_test (TestTags .NOSTORAGE )
139161 def test_generate_backup_passhprase (self ):
140162 """Verify that backup passphrase generation works as expected"""
@@ -410,6 +432,9 @@ def test_luks_resize(self):
410432 def test_luks2_resize (self ):
411433 """Verify that resizing LUKS 2 device works"""
412434
435+ with self .assertRaisesRegex (GLib .GError , "Failed to initialize device" ):
436+ BlockDev .crypto_luks_resize ("non-existing-device" , 0 )
437+
413438 # the simple case with password
414439 self ._luks2_format (self .loop_devs [0 ], PASSWD , self .keyfile , fast_pbkdf = True )
415440
@@ -448,6 +473,9 @@ def _luks_open_close(self, create_fn):
448473 ctx = BlockDev .CryptoKeyslotContext (passphrase = PASSWD )
449474 BlockDev .crypto_luks_open (self .loop_devs [0 ], "libblockdev/TestLUKS" , ctx , False )
450475
476+ with self .assertRaisesRegex (GLib .GError , r"Device name can be at most 127 characters long" ):
477+ ctx = BlockDev .CryptoKeyslotContext (passphrase = PASSWD )
478+ BlockDev .crypto_luks_open (self .loop_devs [0 ], "a" * 128 , ctx , False )
451479
452480 with self .assertRaisesRegex (GLib .GError , r"Incorrect passphrase" ):
453481 ctx = BlockDev .CryptoKeyslotContext (passphrase = "wrong-passphrase" )
@@ -558,12 +586,14 @@ def _remove_key(self, create_fn):
558586 succ = BlockDev .crypto_luks_add_key (self .loop_devs [0 ], ctx , nctx )
559587 self .assertTrue (succ )
560588
561- nctx2 = BlockDev .CryptoKeyslotContext (passphrase = PASSWD3 )
589+ nctx2 = BlockDev .CryptoKeyslotContext (keyfile = self . keyfile )
562590 succ = BlockDev .crypto_luks_add_key (self .loop_devs [0 ], ctx , nctx2 )
563591 self .assertTrue (succ )
564592
565- nctx3 = BlockDev .CryptoKeyslotContext (keyfile = self .keyfile )
566- succ = BlockDev .crypto_luks_add_key (self .loop_devs [0 ], ctx , nctx3 )
593+ # add key using the previously added keyfile
594+ nctx3 = BlockDev .CryptoKeyslotContext (passphrase = PASSWD3 )
595+ succ = BlockDev .crypto_luks_add_key (self .loop_devs [0 ], nctx2 , nctx3 )
596+ self .assertTrue (succ )
567597
568598 # remove key, wrong passphrase
569599 with self .assertRaises (GLib .GError ):
@@ -658,6 +688,22 @@ def _change_key(self, create_fn):
658688 succ = BlockDev .crypto_luks_close ("libblockdevTestLUKS" )
659689 self .assertTrue (succ )
660690
691+ # try with keyfile as the "old passphrase"
692+ kctx = BlockDev .CryptoKeyslotContext (keyfile = self .keyfile )
693+ succ = BlockDev .crypto_luks_change_key (self .loop_devs [0 ], kctx , ctx )
694+ self .assertTrue (succ )
695+
696+ # keyfile should no longer work
697+ with self .assertRaises (GLib .GError ):
698+ BlockDev .crypto_luks_remove_key (self .loop_devs [0 ], kctx )
699+
700+ # passphrase should work
701+ succ = BlockDev .crypto_luks_open (self .loop_devs [0 ], "libblockdevTestLUKS" , ctx )
702+ self .assertTrue (succ )
703+
704+ succ = BlockDev .crypto_luks_close ("libblockdevTestLUKS" )
705+ self .assertTrue (succ )
706+
661707 @tag_test (TestTags .SLOW )
662708 def test_luks_change_key (self ):
663709 self ._change_key (self ._luks_format )
0 commit comments