Skip to content

Integration failure with python-pkcs11 #501

Description

@oli-ben

Hello,

Thank you for this great tooling, the codebase is super easy to navigate, and the docs are good!

However, I have been experiencing a small issue when trying to use NXP's Secure Provisioning SDK (SPSDK):

.venv/lib64/python3.12/site-packages/pkcs11/__init__.py", line 31, in lib
    _lib = _pkcs11.lib(so)
           ^^^^^^^^^^^^^^^
  File "pkcs11/_pkcs11.pyx", line 2034, in pkcs11._pkcs11.lib.__init__
  File "pkcs11/_pkcs11.pyx", line 2011, in pkcs11._pkcs11.lib.initialize
  File "pkcs11/_pkcs11.pyx", line 47, in pkcs11._pkcs11.assertRV
pkcs11.exceptions.ArgumentsBad

I believe I have found the issue, namely that python's pkcs-11 module calls C_Initialize with a NULL pointer.

This is explicitly considered an error case in the yubihsm_pkcs11 module, and has been since the start.

However, when looking at the specification that you yourself link to, I found the following in section 5.4 General-purpose functions:

A call to C_Initialize with pInitArgs set to NULL_PTR is treated like a call to C_Initialize with pInitArgs pointing to a CK_C_INITIALIZE_ARGS which has the CreateMutex, DestroyMutex, LockMutex, UnlockMutex, and pReserved fields set to NULL_PTR, and has the flags field set to 0.

As far as I can tell, this would mean falling back to this:

If the flag isn’t set, and the function pointer fields aren’t supplied (i.e., they all have the value NULL_PTR), that means that the application won’t be accessing the Cryptoki library from multiple threads simultaneously.

which is handled here in yubihsm_pkcs11.

My impression from this is, that in this specific case, yubihsm_pkcs11 is breaking the PKCS#11 interface, and will not work for any python-pkcs11 users.
I am, however, a bit surprised to be the first one to stumble upon this bug, so I'd like to confirm my understanding with you before potentially sending a PR your way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions