python-pkcs11 0.8.0__cp313-cp313-win_amd64.whl

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.
@@ -0,0 +1,392 @@
1
+ Metadata-Version: 2.4
2
+ Name: python-pkcs11
3
+ Version: 0.8.0
4
+ Summary: PKCS#11 support for Python
5
+ Author-email: Andrey Kislyuk <kislyuk@gmail.com>, Danielle Madeley <danielle@madeley.id.au>
6
+ Maintainer-email: Andrey Kislyuk <kislyuk@gmail.com>
7
+ License-Expression: MIT
8
+ Project-URL: Homepage, https://python-pkcs11.readthedocs.io/en/latest/
9
+ Project-URL: Documentation, https://python-pkcs11.readthedocs.io/en/latest/
10
+ Project-URL: Issues, https://github.com/pyauth/python-pkcs11/issues
11
+ Project-URL: Repository, https://github.com/pyauth/python-pkcs11
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Security :: Cryptography
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/x-rst
22
+ License-File: LICENSE
23
+ Requires-Dist: asn1crypto>=1.5.1
24
+ Dynamic: license-file
25
+
26
+ .. image:: https://travis-ci.org/danni/python-pkcs11.svg?branch=master
27
+ :target: https://travis-ci.org/danni/python-pkcs11
28
+
29
+ Python PKCS#11 - High Level Wrapper API
30
+ =======================================
31
+
32
+ A high level, "more Pythonic" interface to the PKCS#11 (Cryptoki) standard
33
+ to support HSM and Smartcard devices in Python.
34
+
35
+ The interface is designed to follow the logical structure of a HSM, with
36
+ useful defaults for obscurely documented parameters. Many APIs will optionally
37
+ accept iterables and act as generators, allowing you to stream large data
38
+ blocks for symmetric encryption.
39
+
40
+ python-pkcs11 also includes numerous utility functions to convert between PKCS
41
+ #11 data structures and common interchange formats including PKCS #1 and X.509.
42
+
43
+ python-pkcs11 is fully documented and has a full integration test suite for all
44
+ features.
45
+
46
+ Historically, this project used to run continuous integration tests against several
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
49
+ to contribute some CI setup with additional PKCS#11 implementations or actual HSMs,
50
+ let's chat!
51
+
52
+ Source: https://github.com/pyauth/python-pkcs11
53
+
54
+ Documentation: http://python-pkcs11.readthedocs.io/en/latest/
55
+
56
+ Getting Started
57
+ ---------------
58
+
59
+ Install from Pip:
60
+
61
+ ::
62
+
63
+ pip install python-pkcs11
64
+
65
+
66
+ Or build from source:
67
+
68
+ ::
69
+
70
+ python -m build .
71
+
72
+ Or using ``uv``:
73
+
74
+ ::
75
+
76
+ uv build
77
+
78
+ Assuming your PKCS#11 library is set as `PKCS11_MODULE` and contains a
79
+ token named `DEMO`:
80
+
81
+ AES
82
+ ~~~
83
+
84
+ ::
85
+
86
+ import pkcs11
87
+
88
+ # Initialise our PKCS#11 library
89
+ lib = pkcs11.lib(os.environ['PKCS11_MODULE'])
90
+ token = lib.get_token(token_label='DEMO')
91
+
92
+ data = b'INPUT DATA'
93
+
94
+ # Open a session on our token
95
+ with token.open(user_pin='1234') as session:
96
+ # Generate an AES key in this session
97
+ key = session.generate_key(pkcs11.KeyType.AES, 256)
98
+
99
+ # Get an initialisation vector
100
+ iv = session.generate_random(128) # AES blocks are fixed at 128 bits
101
+ # Encrypt our data
102
+ crypttext = key.encrypt(data, mechanism_param=iv)
103
+
104
+ 3DES
105
+ ~~~~
106
+
107
+ ::
108
+
109
+ import pkcs11
110
+
111
+ # Initialise our PKCS#11 library
112
+ lib = pkcs11.lib(os.environ['PKCS11_MODULE'])
113
+ token = lib.get_token(token_label='DEMO')
114
+
115
+ data = b'INPUT DATA'
116
+
117
+ # Open a session on our token
118
+ with token.open(user_pin='1234') as session:
119
+ # Generate a DES key in this session
120
+ key = session.generate_key(pkcs11.KeyType.DES3)
121
+
122
+ # Get an initialisation vector
123
+ iv = session.generate_random(64) # DES blocks are fixed at 64 bits
124
+ # Encrypt our data
125
+ crypttext = key.encrypt(data, mechanism_param=iv)
126
+
127
+ RSA
128
+ ~~~
129
+
130
+ ::
131
+
132
+ import pkcs11
133
+
134
+ lib = pkcs11.lib(os.environ['PKCS11_MODULE'])
135
+ token = lib.get_token(token_label='DEMO')
136
+
137
+ data = b'INPUT DATA'
138
+
139
+ # Open a session on our token
140
+ with token.open(user_pin='1234') as session:
141
+ # Generate an RSA keypair in this session
142
+ pub, priv = session.generate_keypair(pkcs11.KeyType.RSA, 2048)
143
+
144
+ # Encrypt as one block
145
+ crypttext = pub.encrypt(data)
146
+
147
+ DSA
148
+ ~~~
149
+
150
+ ::
151
+
152
+ import pkcs11
153
+
154
+ lib = pkcs11.lib(os.environ['PKCS11_MODULE'])
155
+ token = lib.get_token(token_label='DEMO')
156
+
157
+ data = b'INPUT DATA'
158
+
159
+ # Open a session on our token
160
+ with token.open(user_pin='1234') as session:
161
+ # Generate an DSA keypair in this session
162
+ pub, priv = session.generate_keypair(pkcs11.KeyType.DSA, 1024)
163
+
164
+ # Sign
165
+ signature = priv.sign(data)
166
+
167
+ ECDSA
168
+ ~~~~~
169
+
170
+ ::
171
+
172
+ import pkcs11
173
+
174
+ lib = pkcs11.lib(os.environ['PKCS11_MODULE'])
175
+ token = lib.get_token(token_label='DEMO')
176
+
177
+ data = b'INPUT DATA'
178
+
179
+ # Open a session on our token
180
+ with token.open(user_pin='1234') as session:
181
+ # Generate an EC keypair in this session from a named curve
182
+ ecparams = session.create_domain_parameters(
183
+ pkcs11.KeyType.EC, {
184
+ pkcs11.Attribute.EC_PARAMS: pkcs11.util.ec.encode_named_curve_parameters('secp256r1'),
185
+ }, local=True)
186
+ pub, priv = ecparams.generate_keypair()
187
+
188
+ # Sign
189
+ signature = priv.sign(data)
190
+
191
+ Diffie-Hellman
192
+ ~~~~~~~~~~~~~~
193
+
194
+ ::
195
+
196
+ import pkcs11
197
+
198
+ lib = pkcs11.lib(os.environ['PKCS11_MODULE'])
199
+ token = lib.get_token(token_label='DEMO')
200
+
201
+ with token.open() as session:
202
+ # Given shared Diffie-Hellman parameters
203
+ parameters = session.create_domain_parameters(pkcs11.KeyType.DH, {
204
+ pkcs11.Attribute.PRIME: prime, # Diffie-Hellman parameters
205
+ pkcs11.Attribute.BASE: base,
206
+ })
207
+
208
+ # Generate a DH key pair from the public parameters
209
+ public, private = parameters.generate_keypair()
210
+
211
+ # Share the public half of it with our other party.
212
+ _network_.write(public[Attribute.VALUE])
213
+ # And get their shared value
214
+ other_value = _network_.read()
215
+
216
+ # Derive a shared session key with perfect forward secrecy
217
+ session_key = private.derive_key(
218
+ pkcs11.KeyType.AES, 128,
219
+ mechanism_param=other_value)
220
+
221
+
222
+ Elliptic-Curve Diffie-Hellman
223
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
224
+
225
+ ::
226
+
227
+ import pkcs11
228
+
229
+ lib = pkcs11.lib(os.environ['PKCS11_MODULE'])
230
+ token = lib.get_token(token_label='DEMO')
231
+
232
+ with token.open() as session:
233
+ # Given DER encocded EC parameters, e.g. from
234
+ # openssl ecparam -outform der -name <named curve>
235
+ parameters = session.create_domain_parameters(pkcs11.KeyType.EC, {
236
+ pkcs11.Attribute.EC_PARAMS: ecparams,
237
+ })
238
+
239
+ # Generate a DH key pair from the public parameters
240
+ public, private = parameters.generate_keypair()
241
+
242
+ # Share the public half of it with our other party.
243
+ _network_.write(public[pkcs11.Attribute.EC_POINT])
244
+ # And get their shared value
245
+ other_value = _network_.read()
246
+
247
+ # Derive a shared session key
248
+ session_key = private.derive_key(
249
+ pkcs11.KeyType.AES, 128,
250
+ mechanism_param=(pkcs11.KDF.NULL, None, other_value))
251
+
252
+ Tested Compatibility
253
+ --------------------
254
+
255
+ +------------------------------+--------------+-----------------+--------------+-------------------+
256
+ | Functionality | SoftHSMv2 | Thales nCipher | Opencryptoki | OpenSC (Nitrokey) |
257
+ +==============================+==============+=================+==============+===================+
258
+ | Get Slots/Tokens | Works | Works | Works | Works |
259
+ +------------------------------+--------------+-----------------+--------------+-------------------+
260
+ | Get Mechanisms | Works | Works | Works | Works |
261
+ +------------------------------+--------------+-----------------+--------------+-------------------+
262
+ | Initialize token | Not implemented |
263
+ +------------------------------+-------------------------------------------------------------------+
264
+ | Slot events | Not implemented |
265
+ +------------------------------+-------------------------------------------------------------------+
266
+ | Alternative authentication | Not implemented |
267
+ | path | |
268
+ +------------------------------+-------------------------------------------------------------------+
269
+ | `Always authenticate` keys | Not implemented |
270
+ +-------------+----------------+--------------+-----------------+--------------+-------------------+
271
+ | Create/Copy | Keys | Works | Works | Errors | Create |
272
+ | +----------------+--------------+-----------------+--------------+-------------------+
273
+ | | Certificates | Caveats [1]_ | Caveats [1]_ | Caveats [1]_ | ? |
274
+ | +----------------+--------------+-----------------+--------------+-------------------+
275
+ | | Domain Params | Caveats [1]_ | Caveats [1]_ | ? | N/A |
276
+ +-------------+----------------+--------------+-----------------+--------------+-------------------+
277
+ | Destroy Object | Works | N/A | Works | Works |
278
+ +------------------------------+--------------+-----------------+--------------+-------------------+
279
+ | Generate Random | Works | Works | Works | Works |
280
+ +------------------------------+--------------+-----------------+--------------+-------------------+
281
+ | Seed Random | Works | N/A | N/A | N/A |
282
+ +------------------------------+--------------+-----------------+--------------+-------------------+
283
+ | Digest (Data & Keys) | Works | Caveats [2]_ | Works | Works |
284
+ +--------+---------------------+--------------+-----------------+--------------+-------------------+
285
+ | AES | Generate key | Works | Works | Works | N/A |
286
+ | +---------------------+--------------+-----------------+--------------+ |
287
+ | | Encrypt/Decrypt | Works | Works | Works | |
288
+ | +---------------------+--------------+-----------------+--------------+ |
289
+ | | Wrap/Unwrap | ? [3]_ | Works | Errors | |
290
+ | +---------------------+--------------+-----------------+--------------+ |
291
+ | | Sign/Verify | Works | Works [4]_ | N/A | |
292
+ +--------+---------------------+--------------+-----------------+--------------+-------------------+
293
+ | DES2/ | Generate key | Works | Works | Works | N/A |
294
+ | DES3 +---------------------+--------------+-----------------+--------------+ |
295
+ | | Encrypt/Decrypt | Works | Works | Works | |
296
+ | +---------------------+--------------+-----------------+--------------+ |
297
+ | | Wrap/Unwrap | ? | ? | ? | |
298
+ | +---------------------+--------------+-----------------+--------------+ |
299
+ | | Sign/Verify | ? | ? | ? | |
300
+ +--------+---------------------+--------------+-----------------+--------------+-------------------+
301
+ | RSA | Generate key pair | Works | Works | Works | Works [4]_ [8]_ |
302
+ | +---------------------+--------------+-----------------+--------------+-------------------+
303
+ | | Encrypt/Decrypt | Works | Works | Works | Decrypt only [9]_ |
304
+ | +---------------------+--------------+-----------------+--------------+-------------------+
305
+ | | Wrap/Unwrap | Works | Works | Works | N/A |
306
+ | +---------------------+--------------+-----------------+--------------+-------------------+
307
+ | | Sign/Verify | Works | Works | Works | Works |
308
+ +--------+---------------------+--------------+-----------------+--------------+-------------------+
309
+ | DSA | Generate parameters | Works | Error | N/A | N/A |
310
+ | +---------------------+--------------+-----------------+ | |
311
+ | | Generate key pair | Works | Caveats [5]_ | | |
312
+ | +---------------------+--------------+-----------------+ | |
313
+ | | Sign/Verify | Works | Works [4]_ | | |
314
+ +--------+---------------------+--------------+-----------------+--------------+-------------------+
315
+ | DH | Generate parameters | Works | N/A | N/A | N/A |
316
+ | +---------------------+--------------+-----------------+ | |
317
+ | | Generate key pair | Works | Caveats [6]_ | | |
318
+ | +---------------------+--------------+-----------------+ | |
319
+ | | Derive Key | Works | Caveats [7]_ | | |
320
+ +--------+---------------------+--------------+-----------------+--------------+-------------------+
321
+ | EC | Generate key pair | Caveats [6]_ | ? [3]_ | N/A | Works |
322
+ | +---------------------+--------------+-----------------+ +-------------------+
323
+ | | Sign/Verify (ECDSA) | Works [4]_ | ? [3]_ | | Sign only [9]_ |
324
+ | +---------------------+--------------+-----------------+ +-------------------+
325
+ | | Derive key (ECDH) | Works | ? [3]_ | | ? |
326
+ +--------+---------------------+--------------+-----------------+--------------+-------------------+
327
+ | Proprietary extensions | N/A | Not implemented | N/A | N/A |
328
+ +------------------------------+--------------+-----------------+--------------+-------------------+
329
+
330
+ .. [1] Device supports limited set of attributes.
331
+ .. [2] Digesting keys is not supported.
332
+ .. [3] Untested: requires support in device.
333
+ .. [4] Default mechanism not supported, must specify a mechanism.
334
+ .. [5] From existing domain parameters.
335
+ .. [6] Local domain parameters only.
336
+ .. [7] Generates security warnings about the derived key.
337
+ .. [8] `store` parameter is ignored, all keys are stored.
338
+ .. [9] Encryption/verify not supported, extract the public key
339
+
340
+ Python version:
341
+
342
+ * >= 3.9
343
+
344
+ PKCS#11 versions:
345
+
346
+ * 2.11
347
+ * 2.20
348
+ * 2.40
349
+ * 3.1
350
+
351
+ Feel free to send pull requests for any functionality that's not exposed. The
352
+ code is designed to be readable and expose the PKCS #11 spec in a
353
+ straight-forward way.
354
+
355
+ If you want your device supported, get in touch!
356
+
357
+ More info on PKCS #11
358
+ ---------------------
359
+
360
+ The latest version of the PKCS #11 spec is available from OASIS:
361
+
362
+ http://docs.oasis-open.org/pkcs11/pkcs11-base/v2.40/pkcs11-base-v2.40.html
363
+
364
+ You should also consult the documentation for your PKCS #11 implementation.
365
+ Many implementations expose additional vendor options configurable in your
366
+ environment, including alternative features, modes and debugging
367
+ information.
368
+
369
+ License
370
+ -------
371
+
372
+ MIT License
373
+
374
+ Copyright (c) 2017 Danielle Madeley and contributors
375
+
376
+ Permission is hereby granted, free of charge, to any person obtaining a copy
377
+ of this software and associated documentation files (the "Software"), to deal
378
+ in the Software without restriction, including without limitation the rights
379
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
380
+ copies of the Software, and to permit persons to whom the Software is
381
+ furnished to do so, subject to the following conditions:
382
+
383
+ The above copyright notice and this permission notice shall be included in all
384
+ copies or substantial portions of the Software.
385
+
386
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
387
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
388
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
389
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
390
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
391
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
392
+ SOFTWARE.
@@ -0,0 +1,20 @@
1
+ pkcs11/__init__.py,sha256=8Axeo_uTUY2iWXSsvoNP1ZuoGjAIv0Hu5VirTPp5CG4,775
2
+ pkcs11/_pkcs11.cp313-win_amd64.pyd,sha256=gTRU7LvpXAJ-gEIHIpS_5jxmBP_RUk6h1VztNxUAUAg,486912
3
+ pkcs11/_pkcs11.pxd,sha256=zu4t07Rrxa-2F0LS8J90vuB7KMeq7Wg93DoHqp4D_Uw,21583
4
+ pkcs11/_pkcs11.pyx,sha256=EniISP9Z2SlBeeOALPerZ6Uun_SpCl_KtHox6MrceBQ,67937
5
+ pkcs11/constants.py,sha256=ExQPy4UaI1gn2ahre_duxz6HeW0VFM07Adir8NFE-dI,15317
6
+ pkcs11/defaults.py,sha256=MQs8stKqirTn60oag5gNvIo5ML8wjQe-S_WAgGX_Dwk,6046
7
+ pkcs11/exceptions.py,sha256=fRqVX0dUMZLsmG2n19K5K0QIs7yUUpNK6z2BUhIMxP4,8999
8
+ pkcs11/mechanisms.py,sha256=lG4RFMMEgEE0uUALujJif1yQLEXzPlw7sreKaVjOYO4,23305
9
+ pkcs11/types.py,sha256=Essq-8iPbBR-O93Aklqw_6r4COBfwzhjKxBzSBzG1vg,38817
10
+ pkcs11/util/__init__.py,sha256=iy78MXJ4PM3wmk7itMnJJjTfGNMJhIsj3n3SahuHY7E,363
11
+ pkcs11/util/dh.py,sha256=Rd5-PM5YBFYS-gujkXMmYWrTta5tNwYf8skFQ0g6qMI,1607
12
+ pkcs11/util/dsa.py,sha256=_sfPy4INERHp6irfcgnfAPLLacLaLZ3TqxkzYxjADjA,2349
13
+ pkcs11/util/ec.py,sha256=w_QhmTrQ0Cp2LYY_pJXbHriK8YHKExqfvwQ3_-ve3b8,3696
14
+ pkcs11/util/rsa.py,sha256=v1NlS01g2_QVdDnT5Rj9ZOMI4-IIY7QqqHAFCXZzgBY,2944
15
+ pkcs11/util/x509.py,sha256=VgFMp_ZxuwBTWduPD1VhTGcp4OiECwbS3l41tPPl30Q,3602
16
+ python_pkcs11-0.8.0.dist-info/licenses/LICENSE,sha256=_MQXAG7rWQ5-aJCEtiFxPMrUNaRrR68AsJZYOb3ZMr0,1094
17
+ python_pkcs11-0.8.0.dist-info/METADATA,sha256=U6K3eGu4W20F7W7l5O8eWYS-k6xRPdcmF0gw4Ww3PbY,17348
18
+ python_pkcs11-0.8.0.dist-info/WHEEL,sha256=qV0EIPljj1XC_vuSatRWjn02nZIz3N1t8jsZz7HBr2U,101
19
+ python_pkcs11-0.8.0.dist-info/top_level.txt,sha256=QXuJ7iSMaVyTfyYhAivm5m835NHoayh_MrtE-mxVwwc,7
20
+ python_pkcs11-0.8.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: false
4
+ Tag: cp313-cp313-win_amd64
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Danielle Madeley
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ pkcs11