pyauth / pyauth/python-pkcs11

Unpacking search (SearchIter) fails with PK data from Nexus Personal

Open
#192 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
170
Forks
79
PR merge metrics
No merged PRs in 30d

Description

Using this code on version 0.7.0:

pk_query_params = {
            pkcs11.Attribute.CLASS: pkcs11.ObjectClass.PRIVATE_KEY
        }
        q = session.get_objects(pk_query_params)        
        results = list(q)
on Nexus Personal PKCS11 driver fails with:
    results = list(q)
  File "pkcs11/_pkcs11.pyx", line 322, in pkcs11._pkcs11.SearchIter.__next__
  File "pkcs11/_pkcs11.pyx", line 692, in pkcs11._pkcs11.Object._make
  File "pkcs11/_pkcs11.pyx", line 723, in pkcs11._pkcs11.Object.__getitem__
  File "pkcs11/_utils.pyx", line 35, in pkcs11._pkcs11._unpack_attributes
  File "/home/miha/.local/lib/python3.10/site-packages/pkcs11/defaults.py", line 116, in <lambda>
    _bool = (Struct('?').pack, lambda v: Struct('?').unpack(v)[0])
struct.error: unpack requires a buffer of 1 bytes
Exception ignored in: <cyfunction SearchIter.__del__ at 0x7f58cf9cea80>
Traceback (most recent call last):
  File "pkcs11/_pkcs11.pyx", line 326, in pkcs11._pkcs11.SearchIter.__del__
  File "pkcs11/_pkcs11.pyx", line 336, in pkcs11._pkcs11.SearchIter._finalize
  File "pkcs11/_errors.pyx", line 88, in pkcs11._pkcs11.assertRV
pkcs11.exceptions.SessionHandleInvalid: 

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the shown SearchIter usage and inspect pkcs11/_utils.pyx:_unpack_attributes, pkcs11/_pkcs11.pyx:Object.getitem, and SearchIter.next. Determine how the Nexus Personal PKCS11 data reaches the boolean unpacking path, then verify that list(q) completes without the reported struct.error or cleanup exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.