Skip to content

Fix crash when closing sessions with vendor-specific user types#231

Merged
MatthiasValvekens merged 2 commits into
pyauth:masterfrom
akaloti:fix/custom-user-support
Jun 17, 2026
Merged

Fix crash when closing sessions with vendor-specific user types#231
MatthiasValvekens merged 2 commits into
pyauth:masterfrom
akaloti:fix/custom-user-support

Conversation

@akaloti

@akaloti akaloti commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Fix #230

In the current version of this package, when using a custom user such as the Crypto User -- represented by value 0x80000001 -- on Thales Luna HSM 7, we run into problems when closing a session because:

  • The Session.close() method calls Session.user_type(). (Both methods are defined in pkcs11/_pkcs11.pyx.)
  • Session.user_type() then calls UserType().
  • UserType(), defined in pkcs11/constants.py, crashes because the custom user value 0x80000001 does not match NOBODY (999), SO (0), or USER (1).

This PR fixes the problem by avoiding the indirect call to UserType() in Session.close(). It also updates Session.user_type() to not crash if the user type is a custom user.

@MatthiasValvekens

Copy link
Copy Markdown
Collaborator

Those failing tests seem to be related to an upstream change (#233). I pushed a change to master to disable the offending test when running against opencryptoki for now.

@akaloti

akaloti commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. I merged the change from master into this branch.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 20.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.40%. Comparing base (1ff2114) to head (5367918).
⚠️ Report is 15 commits behind head on master.

Files with missing lines Patch % Lines
pkcs11/_pkcs11.pyx 20.00% 4 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #231      +/-   ##
==========================================
+ Coverage   90.17%   91.40%   +1.23%     
==========================================
  Files          15       15              
  Lines        2625     2677      +52     
  Branches       29       27       -2     
==========================================
+ Hits         2367     2447      +80     
+ Misses        255      228      -27     
+ Partials        3        2       -1     
Flag Coverage Δ
unittests 91.40% <20.00%> (+1.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MatthiasValvekens MatthiasValvekens merged commit bd285f5 into pyauth:master Jun 17, 2026
62 of 65 checks passed
@MatthiasValvekens

Copy link
Copy Markdown
Collaborator

Nice work. Thanks!

@akaloti akaloti deleted the fix/custom-user-support branch June 18, 2026 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Session crashes when using vendor defined user type in open

3 participants