- Access exclusive content
- Connect with peers
- Share your expertise
- Find support resources
05-05-2025 02:14 PM
I've been trying to do boot container signing using the NXP SPSDK tool which is a python based API. The SPSDK uses the python-pkcs11 API to access PKCS11 keys. I'm am currently coming across an overflow error when trying to use this tool with the python-pkcs11 API.
I wrote a short python script that access the PKCS11 keys in the same way as the SPSDK tool.
Environment: Ubuntu 22.04
Reproduce the issue:
import pkcs11
from pkcs11 import KeyType, Attribute
lib = pkcs11.lib('/opt/venafi/codesign/lib/venafipkcs11.so')
token = lib.get_token(token_label='Remote Token')
pin = "user_pin"
key_label = "key_name"
with token.open(user_pin=pin, rw=True) as session:
# Find all private keys
private_key = session.get_key(object_class=pkcs11.ObjectClass.PRIVATE_KEY,label=key_label)
print(private_key[pkcs11.Attribute.LABEL])I then get this error:
Traceback (most recent call last):
File "/extra/python-pkcs11-venafi/main.py", line 12, in <module>
private_key = session.get_key(object_class=pkcs11.ObjectClass.PRIVATE_KEY,label=key_label)
File "/extra/python-pkcs11-venafi/.venv/lib/python3.10/site-packages/pkcs11/types.py", line 324, in get_key
key = next(iterator)
File "pkcs11/_pkcs11.pyx", line 343, in pkcs11._pkcs11.SearchIter.__next__
File "pkcs11/_pkcs11.pyx", line 713, in pkcs11._pkcs11.Object._make
File "pkcs11/_pkcs11.pyx", line 749, in pkcs11._pkcs11.Object.__getitem__
File "pkcs11/_utils.pyx", line 11, in pkcs11._pkcs11.CK_BYTE_buffer
File "stringsource", line 151, in View.MemoryView.array.__cinit__
OverflowError: Python int too large to convert to C ssize_tFrom what I can tell, the python library is using a 64 bit unsigned integer with size 18446744073709551615 and then cython is trying to convert it to a C ssize_t with a size of [-1, 9223372036854775807] which is a signed 64 bit integer. This looks like it is happening because the python-pkcs11 API is calling pkcs11 function C_GetAttributeValue which returns a value of CK_UNAVAILABLE_INFORMATION which is set to ~0UL which is the max unsigned 64 bit integer. Does Venafi implement the C_GetAttributeValue API call?
Has the python-pkcs11 API ever been tested with Venafi?
Unfortunately, some kind of python implementation is necessary because the NXP SPSDK is completely python based, but custom python implementations can be added as plugins. Is there a better python API to use for accessing keys through Venafi?
07-08-2025 05:58 AM
This issue has been fixed with a PR from Micha Gorrell in the python-pkcs11 repo. https://github.com/pyauth/python-pkcs11/pull/200
Click Accept as Solution to acknowledge that the answer to your question has been provided.
The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!
These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!
The LIVEcommunity thanks you for your participation!

