Reputation: 33
I'm trying to use pkcs11 from Python and I have a problem. I had view many examples and all of them start with the same code. However, when I execute it, console raises error in the third line of the code.
Code:
import pkcs11
import os
# Initialise our PKCS#11 library
lib = pkcs11.lib(os.environ['PKCS11_MODULE'])
token = lib.get_token(token_label='DEMO')
Error in the line:
lib = pkcs11.lib(os.environ['PKCS11_MODULE'])
Error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/UserDict.py", line 40, in __getitem__
raise KeyError(key)
KeyError: 'PKCS11_MODULE'
Upvotes: 0
Views: 2763
Reputation: 81
to solve this you have to add the route of your driver (in windows a file .dll in linux a file .so), like this:
import pkcs11
lib = pkcs11.lib("C:/Windows/System32/eps2003csp11.dll")
for slot in lib.get_slots():
token = slot.get_token()
print(token)
if token.label == '...':
break
In my case, i work with usb token. With this the result is the username of the token connected.
Upvotes: 0
Reputation: 1034
pkcs11 wraps a native library. It expects to find that library in a path given by the PKCS11_MODULE
environment variable.
You should set that environment variable to where you have installed the native component.
$ export PKCS11_MODULE='/some/path'
$ python myscript.py
Upvotes: 2