[Cryptech-Commits] [sw/pkcs11] 01/02: Enable locking in py11.
git at cryptech.is
git at cryptech.is
Fri Sep 18 05:43:45 UTC 2015
This is an automated email from the git hooks/post-receive script.
sra at hactrn.net pushed a commit to branch ecdsa
in repository sw/pkcs11.
commit 261e1e35db97e99df38c12f6a48bb28f6b827ac8
Author: Rob Austein <sra at hactrn.net>
Date: Thu Sep 17 18:06:28 2015 -0400
Enable locking in py11.
---
py11/__init__.py | 17 +++++++++++++++--
scripts/py11-test.py | 3 +--
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/py11/__init__.py b/py11/__init__.py
index ab187f7..bb4813f 100644
--- a/py11/__init__.py
+++ b/py11/__init__.py
@@ -35,8 +35,21 @@ class PKCS11 (object):
self.so.C_GetInfo(byref(info))
return info.cryptokiVersion
- def C_Initialize(self):
- self.so.C_Initialize(None)
+ # http://stackoverflow.com/questions/15786635/using-ctypes-to-write-callbacks-that-pass-in-pointer-to-pointer-parameters-to-be
+ # suggests that it should be straightforward to write callback
+ # functions to implement the mutex semantics, and we get the
+ # CK_CREATEMUTEX call, but we dump core on the CK_LOCKMUTEX call.
+ # Specifying CKF_OS_LOCKING_OK does work, and is sufficient for most
+ # purposes, so leaving the callbacks out of the API for now.
+
+ def C_Initialize(self, flags = 0):
+ if flags == 0:
+ self.so.C_Initialize(None)
+ else:
+ init_arg = CK_C_INITIALIZE_ARGS(cast(None, CK_CREATEMUTEX), cast(None, CK_DESTROYMUTEX),
+ cast(None, CK_LOCKMUTEX), cast(None, CK_UNLOCKMUTEX),
+ flags, None)
+ self.so.C_Initialize(cast(byref(init_arg), CK_VOID_PTR))
def C_Finalize(self):
self.so.C_Finalize(None)
diff --git a/scripts/py11-test.py b/scripts/py11-test.py
index 45d6713..8e189e3 100644
--- a/scripts/py11-test.py
+++ b/scripts/py11-test.py
@@ -64,10 +64,9 @@ ec_curve_oid_p256 = "".join(chr(i) for i in (0x06, 0x08, 0x2a, 0x86, 0x48, 0xce,
ec_curve_oid_p384 = "".join(chr(i) for i in (0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x22))
ec_curve_oid_p521 = "".join(chr(i) for i in (0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x23))
-
p11 = PKCS11("./libpkcs11.so")
-p11.C_Initialize()
+p11.C_Initialize(CKF_OS_LOCKING_OK)
slots = p11.C_GetSlotList()
More information about the Commits
mailing list