Skip to content

Session crashes when using vendor defined user type in open #230

@ipo-test

Description

@ipo-test

When using the Thales Luna HSM 7 vendor defined user type 0x80000001 for login, the session crashes with "ValueError: 2147483649 is not a valid UserType".

    with token.open(user_pin=user_pin, user_type=0x80000001) as session:
  File "/opt/python/venv/lib/python3.12/site-packages/pkcs11/types.py", line 306, in __exit__
    self.close()
  File "pkcs11/_pkcs11.pyx", line 902, in pkcs11._pkcs11.Session.close
  File "pkcs11/_pkcs11.pyx", line 896, in pkcs11._pkcs11.Session.user_type.__get__
  File "/usr/lib/python3.12/enum.py", line 757, in __call__
    return cls.__new__(cls, value)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/enum.py", line 1171, in __new__
    raise ve_exc
ValueError: 2147483649 is not a valid UserType

According to the PR #109, this feature should be supported. I'm using the python-pkcs11 version 0.9.4.

Here's a simple script to reproduce the issue:

#!/usr/bin/env python3

import os
import pkcs11
from pkcs11.constants import UserType


user_pin = os.environ['PKCS11_PIN']
pkcs11_module_path = os.environ['PKCS11_MODULE']
lib = pkcs11.lib(pkcs11_module_path)
token = lib.get_token(token_label='Test')

with token.open(user_pin=user_pin, user_type=0x80000001) as session:
    print(session)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions