Skip to content

Commit eb52ab7

Browse files
Fallback to 1-by-1 fetch when determining capas
If fetching all flags on an object is not possible in one go, try fetching one at a time. This is meant to alleviate some issues with misbehaving tokens. Fixes #221
1 parent 8f8963c commit eb52ab7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pkcs11/_pkcs11.pyx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1366,8 +1366,15 @@ cdef object make_object(Session session, CK_OBJECT_HANDLE handle) with gil:
13661366
# Determine a list of base classes to manufacture our class with
13671367
try:
13681368
attributes = wrapper.get_attribute_list(&attr_keys[0], 8)
1369-
except (AttributeTypeInvalid, FunctionFailed) as e:
1369+
except PKCS11Error:
1370+
# retry fetching the flags one by one, some tokens do not implement error handling
1371+
# on bulk fetches correctly.
13701372
attributes = {}
1373+
for key in attr_keys:
1374+
try:
1375+
attributes[key] = wrapper[key]
1376+
except (AttributeTypeInvalid, AttributeSensitive, FunctionFailed):
1377+
continue
13711378

13721379
object_class = attributes.get(Attribute.CLASS, session.attribute_mapper)
13731380
bases = (_CLASS_MAP[object_class],)

0 commit comments

Comments
 (0)