aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--py11/__init__.py17
-rw-r--r--scripts/py11-test.py3
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()