[Cryptech-Commits] [sw/pkcs11] 02/02: Regression tests for today's C_FindObjects() bugfixes.
git at cryptech.is
git at cryptech.is
Thu May 4 21:13:52 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/pkcs11.
commit 89f03d199f820f3de967ee2a72b7d9a4cf21ea7f
Author: Rob Austein <sra at hactrn.net>
AuthorDate: Thu May 4 17:12:27 2017 -0400
Regression tests for today's C_FindObjects() bugfixes.
---
unit_tests.py | 40 ++++++++++++++++++++++++++++++++++++++--
1 file changed, 38 insertions(+), 2 deletions(-)
diff --git a/unit_tests.py b/unit_tests.py
index 1a7470d..fe96207 100644
--- a/unit_tests.py
+++ b/unit_tests.py
@@ -187,14 +187,25 @@ class TestDevice(TestCase):
self.assertIsInstance(random, str)
self.assertEqual(len(random), n)
- def test_findObjects(self):
- "Test basic C_FindObjects*() behavior"
+ def test_findObjects_operation_state(self):
+ "Test C_FindObjects*() CKR_OPERATION_* behavior"
session = p11.C_OpenSession(args.slot)
+
+ with self.assertRaises(CKR_OPERATION_NOT_INITIALIZED):
+ for handle in p11.C_FindObjects(session):
+ self.assertIsInstance(handle, (int, long))
+
+ with self.assertRaises(CKR_OPERATION_NOT_INITIALIZED):
+ p11.C_FindObjectsFinal(session)
+
p11.C_FindObjectsInit(session, CKA_CLASS = CKO_PUBLIC_KEY)
+
with self.assertRaises(CKR_OPERATION_ACTIVE):
p11.C_FindObjectsInit(session, CKA_CLASS = CKO_PRIVATE_KEY)
+
for handle in p11.C_FindObjects(session):
self.assertIsInstance(handle, (int, long))
+
p11.C_FindObjectsFinal(session)
@@ -573,6 +584,31 @@ class TestKeys(TestCase):
p11.C_VerifyUpdate(self.session, tbs)
p11.C_VerifyFinal(self.session, sig)
+ def _find_objects(self, chunk_size = 10, template = None, **kwargs):
+ p11.C_FindObjectsInit(self.session, template, **kwargs)
+ for handle in p11.C_FindObjects(self.session, chunk_size):
+ self.assertIsInstance(handle, (int, long))
+ p11.C_FindObjectsFinal(self.session)
+
+ @unittest.skipUnless(pycrypto_loaded, "requires PyCrypto")
+ def test_findObjects(self):
+ self._load_rsa_keypair(rsa_1024_pem, "RSA-1024")
+ self._load_rsa_keypair(rsa_2048_pem, "RSA-2048")
+ self._load_rsa_keypair(rsa_3416_pem, "RSA-3416")
+ self._find_objects(chunk_size = 1, CKA_CLASS = CKO_PUBLIC_KEY)
+ self._find_objects(chunk_size = 1, CKA_CLASS = CKO_PRIVATE_KEY)
+ self._find_objects(chunk_size = 10, CKA_CLASS = CKO_PUBLIC_KEY)
+ self._find_objects(chunk_size = 10, CKA_CLASS = CKO_PRIVATE_KEY)
+ self._find_objects(chunk_size = 100, CKA_CLASS = CKO_PUBLIC_KEY)
+ self._find_objects(chunk_size = 100, CKA_CLASS = CKO_PRIVATE_KEY)
+ self._find_objects(chunk_size = 1)
+ self._find_objects(chunk_size = 1)
+ self._find_objects(chunk_size = 10)
+ self._find_objects(chunk_size = 10)
+ self._find_objects(chunk_size = 100)
+ self._find_objects(chunk_size = 100)
+
+
# Keys for preload tests, here rather than inline because they're
# bulky. These are in PKCS #8 format, see PyCrypto or the "pkey" and
# "genpkey" commands to OpenSSL's command line tool.
More information about the Commits
mailing list