I'm trying to connect to an Eracom HSM [which is from about 15 years ago!] using Python. My Google searches led me to a library named py-hsm. It seems that it has a really straightforward usage based on the documentation. But when I tried to use it, I faced the following error:
1 C:\> python
2 Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32
3
4 >>> from pyhsm.hsmclient import HsmClient
5 >>> c = HsmClient(pkcs11_lib="C:\Eracom\ProtectToolkit C SDK\bin\sw\cryptoki.dll")
6 Traceback (most recent call last):
7 File "<stdin>", line 1, in <module>
8 File "C:\Python\Python38-32\lib\site-packages\pyhsm\hsmclient.py", line 138, in __init__
9 self.__init_libhsm()
10 File "C:\Python\Python38-32\lib\site-packages\pyhsm\hsmclient.py", line 157, in __init_libhsm
11 self.__libhsm = CDLL(self.__pyLibHsmName)
12 File "C:\Python\Python38-32\lib\ctypes\__init__.py", line 373, in __init__
13 self._handle = _dlopen(self._name, mode)
14 FileNotFoundError: Could not find module 'libhsm.dll' (or one of its dependencies). Try using the full path with constructor syntax.
15 >>>
I did a wholes system search for the mentioned DLL (libhsm.dll), but I found nothing.
Question1:
- Is there any better package/library to aim this goal?
- How can I fix the issue?
As far as I remember you need to install "HSM Access Provider" that provides this dll. It has two variants:
PCI Access Provider (for HSM physically installed in the computer)
Network Access Provider (for HSM accessed remotely over a network link)
The cryptoki dynamic library depends on the dynamic library
libhsm.dll(shouldn't it beethsm.dll?) provided by the access provider.You can check your HSM access provider installation with the
hsmstatecommand (as far as I remember it is part of the access provider installation).You can check your overall HSM installation with the
ctstatcommand.If everything fails you can check your
cryptoki.dlldependencies with Dependency Walker (Windows) orlddcommand (Linux).See the respective PTK-C Installation Guide.
Good luck!