<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python-pkcs11 (NXP SPSDK) signing with Venafi in Network Security Discussions</title>
    <link>https://live.paloaltonetworks.com/t5/network-security-discussions/python-pkcs11-nxp-spsdk-signing-with-venafi/m-p/1420064#M684</link>
    <description>&lt;P&gt;This issue has been fixed with a PR from Micha Gorrell in the python-pkcs11 repo. https://github.com/pyauth/python-pkcs11/pull/200&lt;/P&gt;</description>
    <pubDate>Tue, 08 Jul 2025 12:58:59 GMT</pubDate>
    <dc:creator>CyberArkAlumni</dc:creator>
    <dc:date>2025-07-08T12:58:59Z</dc:date>
    <item>
      <title>Python-pkcs11 (NXP SPSDK) signing with Venafi</title>
      <link>https://live.paloaltonetworks.com/t5/network-security-discussions/python-pkcs11-nxp-spsdk-signing-with-venafi/m-p/1420063#M683</link>
      <description>&lt;P&gt;I've been trying to do boot container signing using the &lt;A alt="https://spsdk.readthedocs.io/en/latest/index.html" href="https://spsdk.readthedocs.io/en/latest/index.html" target="_blank"&gt;NXP SPSDK&lt;/A&gt; tool which is a python based API. The SPSDK uses the &lt;A alt="https://python-pkcs11.readthedocs.io/en/latest/api.html" href="https://python-pkcs11.readthedocs.io/en/latest/api.html" target="_blank"&gt;python-pkcs11&lt;/A&gt; 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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote a short python script that access the PKCS11 keys in the same way as the SPSDK tool.&lt;/P&gt;&lt;P&gt;Environment: Ubuntu 22.04&lt;/P&gt;&lt;P&gt;Reproduce the issue: &lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Install the Venafi Code Sign protect client.&lt;/LI&gt;&lt;LI&gt;Create a python virtual environment and install the python-pkcs11 package&lt;/LI&gt;&lt;LI&gt;Run the following python script setting the pin and key to the correct values.&lt;/LI&gt;&lt;/OL&gt;&lt;CODE&gt;import pkcs11
from pkcs11 import KeyType, Attribute
&amp;nbsp;
lib = pkcs11.lib('/opt/venafi/codesign/lib/venafipkcs11.so')
token = lib.get_token(token_label='Remote Token')
pin = "user_pin"
key_label = "key_name"
&amp;nbsp;
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])&lt;/CODE&gt;&lt;P&gt;I then get this error:&lt;/P&gt;&lt;CODE&gt;Traceback (most recent call last):
  File "/extra/python-pkcs11-venafi/main.py", line 12, in &amp;lt;module&amp;gt;
    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_t&lt;/CODE&gt;&lt;P&gt;From 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 &lt;B&gt;C_GetAttributeValue &lt;/B&gt;which returns a value of &lt;B&gt;CK_UNAVAILABLE_INFORMATION&lt;/B&gt; which is set to ~0UL which is the max unsigned 64 bit integer.&lt;B&gt; &lt;/B&gt;Does Venafi implement the &lt;B&gt;C_GetAttributeValue &lt;/B&gt;API call?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Has the python-pkcs11 API ever been tested with Venafi?&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;</description>
      <pubDate>Mon, 05 May 2025 21:14:04 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/network-security-discussions/python-pkcs11-nxp-spsdk-signing-with-venafi/m-p/1420063#M683</guid>
      <dc:creator>John_Ripple</dc:creator>
      <dc:date>2025-05-05T21:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: Python-pkcs11 (NXP SPSDK) signing with Venafi</title>
      <link>https://live.paloaltonetworks.com/t5/network-security-discussions/python-pkcs11-nxp-spsdk-signing-with-venafi/m-p/1420064#M684</link>
      <description>&lt;P&gt;This issue has been fixed with a PR from Micha Gorrell in the python-pkcs11 repo. https://github.com/pyauth/python-pkcs11/pull/200&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jul 2025 12:58:59 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/network-security-discussions/python-pkcs11-nxp-spsdk-signing-with-venafi/m-p/1420064#M684</guid>
      <dc:creator>CyberArkAlumni</dc:creator>
      <dc:date>2025-07-08T12:58:59Z</dc:date>
    </item>
  </channel>
</rss>

