python-pkcs11 0.8.0__tar.gz → 0.9.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. python_pkcs11-0.9.0/.github/actions/install-opencryptoki/action.yml +58 -0
  2. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/.github/actions/install-softhsm/action.yml +11 -12
  3. python_pkcs11-0.9.0/.github/actions/test-setup/action.yml +87 -0
  4. python_pkcs11-0.9.0/.github/workflows/coverage.yml +99 -0
  5. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/.github/workflows/release.yml +1 -1
  6. python_pkcs11-0.9.0/.github/workflows/tests.yml +85 -0
  7. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/.gitignore +4 -1
  8. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/PKG-INFO +3 -2
  9. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/README.rst +2 -1
  10. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/extern/load_module.c +8 -3
  11. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/extern/pkcs11t.h +2 -0
  12. python_pkcs11-0.9.0/pkcs11/__init__.py +44 -0
  13. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/pkcs11/_pkcs11.pxd +198 -21
  14. python_pkcs11-0.9.0/pkcs11/_pkcs11.pyx +2194 -0
  15. python_pkcs11-0.9.0/pkcs11/attributes.py +238 -0
  16. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/pkcs11/constants.py +27 -0
  17. python_pkcs11-0.9.0/pkcs11/defaults.py +106 -0
  18. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/pkcs11/exceptions.py +0 -6
  19. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/pkcs11/mechanisms.py +21 -0
  20. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/pkcs11/types.py +217 -169
  21. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/pkcs11/util/dh.py +2 -2
  22. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/pkcs11/util/dsa.py +2 -2
  23. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/pkcs11/util/ec.py +2 -2
  24. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/pkcs11/util/rsa.py +4 -4
  25. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/pkcs11/util/x509.py +7 -2
  26. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/pyproject.toml +23 -0
  27. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/python_pkcs11.egg-info/PKG-INFO +3 -2
  28. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/python_pkcs11.egg-info/SOURCES.txt +5 -1
  29. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/tests/test_aes.py +358 -1
  30. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/tests/test_digest.py +27 -0
  31. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/tests/test_ecc.py +9 -29
  32. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/tests/test_iterators.py +0 -5
  33. python_pkcs11-0.9.0/tests/test_multilib.py +26 -0
  34. python_pkcs11-0.9.0/tests/test_rsa.py +250 -0
  35. python_pkcs11-0.9.0/tests/test_sessions.py +343 -0
  36. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/tests/test_slots_and_tokens.py +49 -4
  37. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/tests/test_x509.py +17 -20
  38. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/uv.lock +109 -0
  39. python_pkcs11-0.8.0/.github/workflows/tests.yml +0 -47
  40. python_pkcs11-0.8.0/Dockerfile +0 -27
  41. python_pkcs11-0.8.0/pkcs11/__init__.py +0 -36
  42. python_pkcs11-0.8.0/pkcs11/_pkcs11.pyx +0 -1891
  43. python_pkcs11-0.8.0/pkcs11/defaults.py +0 -197
  44. python_pkcs11-0.8.0/tests/test_rsa.py +0 -120
  45. python_pkcs11-0.8.0/tests/test_sessions.py +0 -159
  46. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/.github/release-template.md +0 -0
  47. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/.github/workflows/quality.yml +0 -0
  48. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/.python-version +0 -0
  49. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/.readthedocs.yaml +0 -0
  50. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/LICENSE +0 -0
  51. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/MANIFEST.in +0 -0
  52. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/docs/Makefile +0 -0
  53. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/docs/api.rst +0 -0
  54. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/docs/applied.rst +0 -0
  55. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/docs/concurrency.rst +0 -0
  56. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/docs/conf.py +0 -0
  57. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/docs/index.rst +0 -0
  58. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/docs/make.bat +0 -0
  59. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/docs/opensc.rst +0 -0
  60. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/extern/.gitignore +0 -0
  61. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/extern/cryptoki.h +0 -0
  62. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/extern/load_module.h +0 -0
  63. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/extern/pkcs11.h +0 -0
  64. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/extern/pkcs11f.h +0 -0
  65. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/pkcs11/util/__init__.py +0 -0
  66. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/python_pkcs11.egg-info/dependency_links.txt +0 -0
  67. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/python_pkcs11.egg-info/requires.txt +0 -0
  68. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/python_pkcs11.egg-info/top_level.txt +0 -0
  69. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/setup.cfg +0 -0
  70. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/tests/__init__.py +0 -0
  71. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/tests/test_des.py +0 -0
  72. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/tests/test_dh.py +0 -0
  73. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/tests/test_dsa.py +0 -0
  74. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/tests/test_public_key_external.py +0 -0
  75. {python_pkcs11-0.8.0 → python_pkcs11-0.9.0}/tests/test_threading.py +0 -0
@@ -0,0 +1,58 @@
1
+ name: install-opencryptoki
2
+ author: Matthias Valvekens
3
+ description: Install opencryptoki and configure an empty token
4
+ inputs:
5
+ os:
6
+ description: OS to target
7
+ required: true
8
+ token-label:
9
+ description: Label assigned to the token
10
+ required: true
11
+ token-user-pin:
12
+ description: User PIN to configure on the token
13
+ required: true
14
+ token-so-pin:
15
+ description: Security officer PIN to configure on the token
16
+ required: true
17
+ outputs:
18
+ module:
19
+ description: Path to PKCS#11 module
20
+ value: ${{ steps.install.outputs.module }}
21
+ runs:
22
+ using: "composite"
23
+ steps:
24
+ - name: Install opencryptoki
25
+ id: install
26
+ shell: bash
27
+ run: |
28
+ if [[ "${OS_NAME:0:6}" == 'ubuntu' ]]; then
29
+ sudo apt install libcap-dev libldap-dev
30
+ git clone https://github.com/opencryptoki/opencryptoki
31
+ cd opencryptoki
32
+ ./bootstrap.sh
33
+ ./configure --prefix=/usr --sysconfdir=/etc \
34
+ --with-pkcs-group=users \
35
+ --disable-tpmtok --disable-ccatok --disable-ep11tok --disable-icsftok \
36
+ --disable-p11sak --disable-pkcstok_migrate --disable-pkcsstats
37
+ make
38
+ sudo make install
39
+ sudo ldconfig
40
+ echo -e "slot 0\n{\nstdll = libpkcs11_sw.so\ntokversion = 3.12\n}" > /tmp/opencryptoki.conf
41
+ sudo cp /tmp/opencryptoki.conf /etc/opencryptoki/
42
+ sudo chown root:root /etc/opencryptoki/opencryptoki.conf
43
+ echo "module=/usr/lib/opencryptoki/libopencryptoki.so" >> "$GITHUB_OUTPUT"
44
+ else
45
+ echo "$OS_NAME is not a supported target system"
46
+ exit 1
47
+ fi
48
+ env:
49
+ OS_NAME: ${{ inputs.os }}
50
+ - name: Run opencryptoki daemon
51
+ shell: bash
52
+ run: sudo -u pkcsslotd pkcsslotd
53
+ - name: Initialize token
54
+ shell: bash
55
+ run: |
56
+ echo "${{ inputs.token-label }}" | pkcsconf -I -c 0 -S 87654321
57
+ pkcsconf -P -c 0 -S 87654321 -n "${{ inputs.token-so-pin }}"
58
+ pkcsconf -u -c 0 -S "${{ inputs.token-so-pin }}" -n "${{ inputs.token-user-pin }}"
@@ -7,20 +7,22 @@ inputs:
7
7
  required: true
8
8
  token-label:
9
9
  description: Label assigned to the token
10
- required: false
11
- default: TEST
10
+ required: true
12
11
  token-user-pin:
13
12
  description: User PIN to configure on the token
14
- required: false
15
- default: "1234"
13
+ required: true
16
14
  token-so-pin:
17
15
  description: Security officer PIN to configure on the token
18
- required: false
19
- default: "5678"
16
+ required: true
17
+ outputs:
18
+ module:
19
+ description: Path to PKCS#11 module
20
+ value: ${{ steps.install.outputs.module }}
20
21
  runs:
21
22
  using: "composite"
22
23
  steps:
23
24
  - name: Install SoftHSM
25
+ id: install
24
26
  shell: bash
25
27
  run: |
26
28
  if [[ "${OS_NAME:0:6}" == 'ubuntu' ]]; then
@@ -28,14 +30,14 @@ runs:
28
30
  mkdir softhsm_tokens
29
31
  echo "directories.tokendir = $(pwd)/softhsm_tokens" > /tmp/softhsm2.conf
30
32
  echo "SOFTHSM2_CONF=/tmp/softhsm2.conf" >> "$GITHUB_ENV"
31
- echo "PKCS11_MODULE=/usr/lib/softhsm/libsofthsm2.so" >> "$GITHUB_ENV"
33
+ echo "module=/usr/lib/softhsm/libsofthsm2.so" >> "$GITHUB_OUTPUT"
32
34
  elif [[ "${OS_NAME:0:5}" == 'macos' ]]; then
33
35
  brew install softhsm
34
- echo "PKCS11_MODULE=/opt/homebrew/lib/softhsm/libsofthsm2.so" >> "$GITHUB_ENV"
36
+ echo "module=/opt/homebrew/lib/softhsm/libsofthsm2.so" >> "$GITHUB_OUTPUT"
35
37
  elif [[ "${OS_NAME:0:7}" == 'windows' ]]; then
36
38
  choco install softhsm.install
37
39
  echo "SOFTHSM2_CONF=D:/SoftHSM2/etc/softhsm2.conf" >> "$GITHUB_ENV"
38
- echo "PKCS11_MODULE=D:/SoftHSM2/lib/softhsm2-x64.dll" >> "$GITHUB_ENV"
40
+ echo "module=D:/SoftHSM2/lib/softhsm2-x64.dll" >> "$GITHUB_OUTPUT"
39
41
  echo "D:/SoftHSM2/bin" >> "$GITHUB_PATH"
40
42
  echo "D:/SoftHSM2/lib" >> "$GITHUB_PATH"
41
43
  else
@@ -49,6 +51,3 @@ runs:
49
51
  run: |
50
52
  softhsm2-util --init-token --free --label "${{ inputs.token-label }}" \
51
53
  --pin "${{ inputs.token-user-pin }}" --so-pin "${{ inputs.token-so-pin }}"
52
- echo "PKCS11_TOKEN_LABEL=${{ inputs.token-label }}" >> "$GITHUB_ENV"
53
- echo "PKCS11_TOKEN_PIN=${{ inputs.token-user-pin }}" >> "$GITHUB_ENV"
54
- echo "PKCS11_TOKEN_SO_PIN=${{ inputs.token-so-pin }}" >> "$GITHUB_ENV"
@@ -0,0 +1,87 @@
1
+ name: test-setup
2
+ author: Matthias Valvekens
3
+ description: Perform set-up for python-pkcs11 CI
4
+ inputs:
5
+ os:
6
+ description: OS to target
7
+ required: true
8
+ python-version:
9
+ description: Python version to target
10
+ required: true
11
+ dependency-group:
12
+ description: UV dependency group to install
13
+ required: true
14
+ pkcs11-platform:
15
+ description: PKCS#11 platform to target
16
+ required: true
17
+ token-label:
18
+ description: Label assigned to the token
19
+ required: true
20
+ token-user-pin:
21
+ description: User PIN to configure on the token
22
+ required: true
23
+ token-so-pin:
24
+ description: Security officer PIN to configure on the token
25
+ required: true
26
+ outputs:
27
+ module:
28
+ description: Path to PKCS#11 module
29
+ value: ${{ steps.install-result.outputs.module }}
30
+ module2:
31
+ description: Path to alternative PKCS#11 module ('multi' only)
32
+ value: ${{ steps.install-result.outputs.module2 }}
33
+ runs:
34
+ using: "composite"
35
+ steps:
36
+ - name: Setup Python
37
+ uses: actions/setup-python@v5
38
+ with:
39
+ python-version: ${{ inputs.python-version }}
40
+ - uses: ./.github/actions/install-softhsm
41
+ if: inputs.pkcs11-platform == 'softhsm' || inputs.pkcs11-platform == 'multi'
42
+ id: softhsm
43
+ with:
44
+ os: ${{ inputs.os }}
45
+ token-label: ${{ inputs.token-label }}
46
+ token-so-pin: ${{ inputs.token-so-pin }}
47
+ token-user-pin: ${{ inputs.token-user-pin }}
48
+ - uses: ./.github/actions/install-opencryptoki
49
+ # only run opencryptoki tests on ubuntu
50
+ # (macos and windows don't seem to be supported)
51
+ if: inputs.pkcs11-platform == 'opencryptoki' || inputs.pkcs11-platform == 'multi'
52
+ id: opencryptoki
53
+ with:
54
+ os: ${{ inputs.os }}
55
+ token-label: ${{ inputs.token-label }}
56
+ token-so-pin: ${{ inputs.token-so-pin }}
57
+ token-user-pin: ${{ inputs.token-user-pin }}
58
+ - name: Set module path
59
+ id: install-result
60
+ shell: bash
61
+ run: |
62
+ if [[ "$PLATFORM" == 'opencryptoki' ]]; then
63
+ echo "module=${{ steps.opencryptoki.outputs.module }}" >> "$GITHUB_OUTPUT"
64
+ elif [[ "$PLATFORM" == 'softhsm' ]]; then
65
+ echo "module=${{ steps.softhsm.outputs.module }}" >> "$GITHUB_OUTPUT"
66
+ elif [[ "$PLATFORM" == 'multi' ]]; then
67
+ # NOTE: the 'multi' platform is only used for testing the code that
68
+ # swaps between multiple PKCS#11 implementations. As such, any two
69
+ # PKCS#11 implementations will do. If we add a 3rd platform
70
+ # to the CI at a later stage that is faster to install than opencryptoki,
71
+ # switching is an option.
72
+ echo "module=${{ steps.softhsm.outputs.module }}" >> "$GITHUB_OUTPUT"
73
+ echo "module2=${{ steps.opencryptoki.outputs.module }}" >> "$GITHUB_OUTPUT"
74
+ else
75
+ echo "$PLATFORM is not a valid PKCS#11 platform choice"
76
+ exit 1
77
+ fi
78
+ env:
79
+ PLATFORM: ${{ inputs.pkcs11-platform }}
80
+ - name: Install uv
81
+ uses: astral-sh/setup-uv@v4
82
+ with:
83
+ enable-cache: true
84
+ python-version: ${{ inputs.python-version }}
85
+ - name: Install testing dependencies
86
+ shell: bash
87
+ run: uv sync --no-dev --exact --group "${{ inputs.dependency-group }}"
@@ -0,0 +1,99 @@
1
+ name: Coverage
2
+ on:
3
+ pull_request: {}
4
+ workflow_dispatch: {}
5
+ env:
6
+ UV_PYTHON_PREFERENCE: only-system
7
+ UV_NO_SYNC: "1"
8
+ PKCS11_TOKEN_LABEL: "TEST"
9
+ PKCS11_TOKEN_PIN: "1234"
10
+ PKCS11_TOKEN_SO_PIN: "5678"
11
+ jobs:
12
+ # For now, we run the coverage as a separate job.
13
+ # At the time of writing, the latest version of Cython's line tracing
14
+ # seems to lead to segfaults in Python 3.13 -> TODO: investigate
15
+ pytest-coverage:
16
+ runs-on: ubuntu-latest
17
+ strategy:
18
+ matrix:
19
+ pkcs11-platform:
20
+ - softhsm
21
+ - opencryptoki
22
+ steps:
23
+ - name: Acquire sources
24
+ uses: actions/checkout@v4
25
+ - name: Arm coverage-only compiler directives
26
+ # Unfortunately, it doesn't seem to be possible to pass directives
27
+ # to Cython through environment variables: https://github.com/cython/cython/issues/3930
28
+ # Doing it here is still better than introducing a non-declarative setup.py into the
29
+ # build again.
30
+ run: sed -i 's/#coverage#cython/#cython/g' pkcs11/*.pyx
31
+ - uses: ./.github/actions/test-setup
32
+ id: setup
33
+ with:
34
+ os: ubuntu-latest
35
+ python-version: "3.12"
36
+ dependency-group: coverage
37
+ token-label: ${{ env.PKCS11_TOKEN_LABEL }}
38
+ token-so-pin: ${{ env.PKCS11_TOKEN_SO_PIN }}
39
+ token-user-pin: ${{ env.PKCS11_TOKEN_PIN }}
40
+ pkcs11-platform: ${{ matrix.pkcs11-platform }}
41
+ env:
42
+ CFLAGS: "-DCYTHON_TRACE_NOGIL=1"
43
+ EXT_BUILD_DEBUG: "1"
44
+ - name: Run tests
45
+ run: uv run pytest -v --cov=pkcs11 --cov-branch --cov-report=xml:${{ matrix.pkcs11-platform }}-coverage.xml
46
+ env:
47
+ PKCS11_MODULE: ${{ steps.setup.outputs.module }}
48
+ - name: Stash coverage report
49
+ uses: actions/upload-artifact@v4
50
+ with:
51
+ name: coverage-${{ strategy.job-index }}
52
+ path: "*-coverage.xml"
53
+ pytest-coverage-multilib:
54
+ runs-on: ubuntu-latest
55
+ steps:
56
+ - name: Acquire sources
57
+ uses: actions/checkout@v4
58
+ - uses: ./.github/actions/test-setup
59
+ id: setup
60
+ with:
61
+ os: ubuntu-latest
62
+ pkcs11-platform: multi
63
+ token-label: ${{ env.PKCS11_TOKEN_LABEL }}
64
+ token-so-pin: ${{ env.PKCS11_TOKEN_SO_PIN }}
65
+ token-user-pin: ${{ env.PKCS11_TOKEN_PIN }}
66
+ python-version: "3.12"
67
+ dependency-group: coverage
68
+ - name: Run tests
69
+ run: uv run pytest -v --cov=pkcs11 --cov-branch --cov-report=xml:multilib-coverage.xml tests/test_multilib.py
70
+ env:
71
+ PKCS11_MODULE: ${{ steps.setup.outputs.module }}
72
+ PKCS11_MODULE2: ${{ steps.setup.outputs.module2 }}
73
+ - name: Stash coverage report
74
+ uses: actions/upload-artifact@v4
75
+ with:
76
+ name: coverage-multilib
77
+ path: "*-coverage.xml"
78
+ codecov-upload:
79
+ permissions:
80
+ actions: write
81
+ contents: read
82
+ runs-on: ubuntu-latest
83
+ needs: [pytest-coverage]
84
+ steps:
85
+ # checkout necessary to ensure the uploaded report contains the correct paths
86
+ - uses: actions/checkout@v4
87
+ - name: Retrieve coverage reports
88
+ uses: actions/download-artifact@v4
89
+ with:
90
+ pattern: coverage-*
91
+ path: ./reports/
92
+ - name: Upload all coverage reports to Codecov
93
+ uses: codecov/codecov-action@v5
94
+ with:
95
+ token: ${{ secrets.CODECOV_TOKEN }}
96
+ directory: ./reports/
97
+ flags: unittests
98
+ env_vars: OS,PYTHON
99
+ name: codecov-umbrella
@@ -141,4 +141,4 @@ jobs:
141
141
  dist/*.tar.gz
142
142
  body_path: release-body/release.md
143
143
  fail_on_unmatched_files: true
144
- name: python-pkcs11 ${{ needs.extract-params.outputs.version }}
144
+ name: v${{ needs.extract-params.outputs.version }}
@@ -0,0 +1,85 @@
1
+ name: Tests
2
+ on:
3
+ push:
4
+ branches: ["**"]
5
+ pull_request: {}
6
+ workflow_dispatch: {}
7
+ env:
8
+ UV_PYTHON_PREFERENCE: only-system
9
+ UV_NO_SYNC: "1"
10
+ PKCS11_TOKEN_LABEL: "TEST"
11
+ PKCS11_TOKEN_PIN: "1234"
12
+ PKCS11_TOKEN_SO_PIN: "5678"
13
+ jobs:
14
+ tests:
15
+ runs-on: ${{ matrix.os }}
16
+ strategy:
17
+ # Our test suite is pretty fast, so fail-fast: false allows for better troubleshooting.
18
+ fail-fast: false
19
+ matrix:
20
+ os:
21
+ - ubuntu-latest
22
+ - windows-latest
23
+ - macos-latest
24
+ python-version:
25
+ - "3.9"
26
+ - "3.10"
27
+ - "3.11"
28
+ - "3.12"
29
+ - "3.13"
30
+ pkcs11-platform:
31
+ - softhsm
32
+ - opencryptoki
33
+ exclude:
34
+ # only run opencryptoki tests on ubuntu
35
+ # (macos and windows don't seem to be supported)
36
+ - pkcs11-platform: opencryptoki
37
+ os: windows-latest
38
+ - pkcs11-platform: opencryptoki
39
+ os: macos-latest
40
+ steps:
41
+ - name: Acquire sources
42
+ uses: actions/checkout@v4
43
+ - uses: ./.github/actions/test-setup
44
+ id: setup
45
+ with:
46
+ os: ${{ matrix.os }}
47
+ token-label: ${{ env.PKCS11_TOKEN_LABEL }}
48
+ token-so-pin: ${{ env.PKCS11_TOKEN_SO_PIN }}
49
+ token-user-pin: ${{ env.PKCS11_TOKEN_PIN }}
50
+ python-version: ${{ matrix.python-version }}
51
+ pkcs11-platform: ${{ matrix.pkcs11-platform }}
52
+ dependency-group: testing
53
+ - name: Run tests
54
+ run: uv run pytest -v
55
+ env:
56
+ PKCS11_MODULE: ${{ steps.setup.outputs.module }}
57
+ multilib-tests:
58
+ runs-on: ubuntu-latest
59
+ strategy:
60
+ fail-fast: false
61
+ matrix:
62
+ python-version:
63
+ - "3.9"
64
+ - "3.10"
65
+ - "3.11"
66
+ - "3.12"
67
+ - "3.13"
68
+ steps:
69
+ - name: Acquire sources
70
+ uses: actions/checkout@v4
71
+ - uses: ./.github/actions/test-setup
72
+ id: setup
73
+ with:
74
+ os: ubuntu-latest
75
+ pkcs11-platform: multi
76
+ token-label: ${{ env.PKCS11_TOKEN_LABEL }}
77
+ token-so-pin: ${{ env.PKCS11_TOKEN_SO_PIN }}
78
+ token-user-pin: ${{ env.PKCS11_TOKEN_PIN }}
79
+ python-version: ${{ matrix.python-version }}
80
+ dependency-group: testing
81
+ - name: Run tests
82
+ run: uv run pytest -v tests/test_multilib.py
83
+ env:
84
+ PKCS11_MODULE: ${{ steps.setup.outputs.module }}
85
+ PKCS11_MODULE2: ${{ steps.setup.outputs.module2 }}
@@ -6,4 +6,7 @@ __pycache__
6
6
  /dist/
7
7
  /docs/_build
8
8
  /python_pkcs11.egg-info/
9
- /.eggs/
9
+ /.eggs/
10
+ .coverage
11
+ *coverage.xml
12
+ *.html
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-pkcs11
3
- Version: 0.8.0
3
+ Version: 0.9.0
4
4
  Summary: PKCS#11 support for Python
5
5
  Author-email: Andrey Kislyuk <kislyuk@gmail.com>, Danielle Madeley <danielle@madeley.id.au>
6
6
  Maintainer-email: Andrey Kislyuk <kislyuk@gmail.com>
@@ -45,7 +45,8 @@ features.
45
45
 
46
46
  Historically, this project used to run continuous integration tests against several
47
47
  HSM platforms, but this test setup has not been maintained over time. Currently,
48
- the integration tests in GitHub Actions use SoftHSMv2 as a baseline. If you would like
48
+ the integration tests in GitHub Actions use SoftHSMv2 as a baseline.
49
+ We also test against ``opencryptoki`` in CI. If you would like
49
50
  to contribute some CI setup with additional PKCS#11 implementations or actual HSMs,
50
51
  let's chat!
51
52
 
@@ -20,7 +20,8 @@ features.
20
20
 
21
21
  Historically, this project used to run continuous integration tests against several
22
22
  HSM platforms, but this test setup has not been maintained over time. Currently,
23
- the integration tests in GitHub Actions use SoftHSMv2 as a baseline. If you would like
23
+ the integration tests in GitHub Actions use SoftHSMv2 as a baseline.
24
+ We also test against ``opencryptoki`` in CI. If you would like
24
25
  to contribute some CI setup with additional PKCS#11 implementations or actual HSMs,
25
26
  let's chat!
26
27
 
@@ -17,9 +17,12 @@ static PyObject* p11_error() {
17
17
  NULL);
18
18
  PyObject* errmsg = PyUnicode_FromWideChar(msgbuffer, l);
19
19
  LocalFree(msgbuffer);
20
+ if (errmsg == NULL) {
21
+ Py_RETURN_NONE;
22
+ }
20
23
  return errmsg;
21
24
  } else {
22
- return NULL;
25
+ Py_RETURN_NONE;
23
26
  }
24
27
  }
25
28
 
@@ -57,11 +60,13 @@ static PyObject* p11_error() {
57
60
  char* error = dlerror();
58
61
 
59
62
  if (error == NULL) {
60
- return NULL;
63
+ Py_RETURN_NONE;
61
64
  }
62
65
  int len = strlen(error);
63
66
  PyObject* result = PyUnicode_DecodeUTF8(error, len, NULL);
64
- PyMem_Free(error);
67
+ if (result == NULL) {
68
+ Py_RETURN_NONE;
69
+ }
65
70
  return result;
66
71
  }
67
72
 
@@ -270,6 +270,8 @@ typedef CK_ULONG CK_USER_TYPE;
270
270
  #define CKU_USER 1UL
271
271
  /* Context specific */
272
272
  #define CKU_CONTEXT_SPECIFIC 2UL
273
+ /* Value used in python-pkcs11 as a sentinel value for non-logged in sessions */
274
+ #define CKU_USER_NOBODY 999UL
273
275
 
274
276
  /* CK_STATE enumerates the session states */
275
277
  typedef CK_ULONG CK_STATE;
@@ -0,0 +1,44 @@
1
+ """
2
+ :mod:`pkcs11` defines a high-level, "Pythonic" interface to PKCS#11.
3
+ """
4
+
5
+ from pkcs11.constants import * # noqa: F403
6
+ from pkcs11.exceptions import * # noqa: F403
7
+ from pkcs11.mechanisms import * # noqa: F403
8
+ from pkcs11.types import * # noqa: F403
9
+ from pkcs11.util import dh, dsa, ec, rsa, x509 # noqa: F401
10
+
11
+ _loaded = {}
12
+
13
+
14
+ def lib(so):
15
+ """
16
+ Wrap the main library call coming from Cython with a preemptive
17
+ dynamic loading.
18
+ """
19
+ global _loaded
20
+
21
+ try:
22
+ _lib = _loaded[so]
23
+ if not _lib.initialized:
24
+ _lib.initialize()
25
+ return _lib
26
+ except KeyError:
27
+ pass
28
+
29
+ from . import _pkcs11
30
+
31
+ _lib = _pkcs11.lib(so)
32
+ _loaded[so] = _lib
33
+
34
+ return _lib
35
+
36
+
37
+ def unload(so):
38
+ global _loaded
39
+ try:
40
+ loaded_lib = _loaded[so]
41
+ except KeyError:
42
+ return
43
+ del _loaded[so]
44
+ loaded_lib.unload()