[Cryptech-Commits] [sw/libhal] 02/03: Handle error conditions when deleting keys by UUID.

git at cryptech.is git at cryptech.is
Sun Apr 23 22:44:11 UTC 2017


This is an automated email from the git hooks/post-receive script.

sra at hactrn.net pushed a commit to branch ksng
in repository sw/libhal.

commit f502844d18282c928cf5fedb483514c1fcfd0b92
Author: Rob Austein <sra at hactrn.net>
AuthorDate: Sun Apr 23 18:30:05 2017 -0400

    Handle error conditions when deleting keys by UUID.
---
 unit-tests.py | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/unit-tests.py b/unit-tests.py
index 2cdc663..10aa810 100644
--- a/unit-tests.py
+++ b/unit-tests.py
@@ -563,11 +563,19 @@ class TestPKeyMatch(TestCaseLoggedIn):
                      exportable       = HAL_KEY_FLAG_EXPORTABLE)
         return ", ".join(sorted(k for k, v in names.iteritems() if (flags & v) != 0))
 
+    @staticmethod
+    def cleanup_key(uuid):
+        try:
+            with hsm.pkey_open(uuid) as pkey:
+                pkey.delete()
+        except Exception as e:
+            logger.debug("Problem deleting key %s: %s", uuid, e)
+
     def load_keys(self, flags):
         uuids = set()
         for obj in PreloadedKey.db.itervalues():
             with hsm.pkey_load(obj.der, flags) as k:
-                self.addCleanup(lambda uuid: hsm.pkey_open(uuid).delete(), k.uuid)
+                self.addCleanup(self.cleanup_key, k.uuid)
                 uuids.add(k.uuid)
                 #print k.uuid, k.key_type, k.key_curve, self.key_flag_names(k.key_flags)
                 k.set_attributes(dict((i, a) for i, a in enumerate((str(obj.keytype), str(obj.fn2)))))
@@ -637,13 +645,21 @@ class TestPKeyAttribute(TestCaseLoggedIn):
     Attribute creation/lookup/deletion tests.
     """
 
+    @staticmethod
+    def cleanup_key(uuid):
+        try:
+            with hsm.pkey_open(uuid) as pkey:
+                pkey.delete()
+        except:
+            logger.debug("Problem deleting key %s: %s", uuid, e)
+
     def load_and_fill(self, flags, n_keys = 1, n_attrs = 2, n_fill = 0):
         pinwheel = Pinwheel()
         for i in xrange(n_keys):
             for obj in PreloadedKey.db.itervalues():
                 with hsm.pkey_load(obj.der, flags) as k:
                     pinwheel()
-                    self.addCleanup(lambda uuid: hsm.pkey_open(uuid).delete(), k.uuid)
+                    self.addCleanup(self.cleanup_key, k.uuid)
                     k.set_attributes(dict((j, "Attribute {}{}".format(j, "*" * n_fill))
                                           for j in xrange(n_attrs)))
                     pinwheel()



More information about the Commits mailing list