pyauth / python-pkcs11

PKCS#11/Cryptoki support for Python
MIT License
149 stars 71 forks source link

test opensession softhsmv2 #152

Closed jkr1987 closed 1 year ago

jkr1987 commented 1 year ago

Hello I'm trying to write a test for softhsmV2 but i'm not able to load libsofhsm2.so

$ echo $PKCS11_MODULE
/usr/lib/softhsm/libsofthsm2.so
import os
import pkcs11

lib   = pkcs11.lib(os.environ['PKCS11_MODULE'])
token = lib.get_token(token_label='My SoftHSMv2 token')

with token.open(rw=True,user_pin='2023') as session:
    print(session)
Traceback (most recent call last):
  File "pkcs11/_errors.pyx", line 88, in pkcs11._pkcs11.assertRV
RuntimeError: Initialisation error (not initialized). Should never see this.
Exception ignored in: 'pkcs11._pkcs11.lib.__dealloc__'
Traceback (most recent call last):
  File "pkcs11/_errors.pyx", line 88, in pkcs11._pkcs11.assertRV
RuntimeError: Initialisation error (not initialized). Should never see this.
Traceback (most recent call last):
  File "/home/jk/pqapp-build/test_pkcs11.py", line 4, in <module>
    lib   = pkcs11.lib(os.environ['PKCS11_MODULE'])
  File "/home/jk/.local/lib/python3.10/site-packages/pkcs11/__init__.py", line 32, in lib
    _lib = _pkcs11.lib(so)
  File "pkcs11/_pkcs11.pyx", line 1432, in pkcs11._pkcs11.lib.__cinit__
  File "pkcs11/_errors.pyx", line 88, in pkcs11._pkcs11.assertRV
pkcs11.exceptions.GeneralError

What i did wrong ?

jkr1987 commented 1 year ago

it was a permission problem with softhsm's config file