python-nss-ng 1.3.0__tar.gz → 1.3.2__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.
- python_nss_ng-1.3.2/.git_archival.txt +4 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/PKG-INFO +1 -1
- python_nss_ng-1.3.2/_version.txt +1 -0
- {python_nss_ng-1.3.0/typings/nss → python_nss_ng-1.3.2/src}/nss.pyi +2 -2
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/src/py_nspr_error.c +89 -21
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/src/py_nss.c +91 -13
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_cert_components.py +40 -0
- python_nss_ng-1.3.2/test/test_error_refleaks.py +168 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_performance.py +12 -8
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_zzz_nss_context.py +17 -6
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_zzz_ocsp.py +25 -12
- {python_nss_ng-1.3.0/src → python_nss_ng-1.3.2/typings/nss}/nss.pyi +2 -2
- python_nss_ng-1.3.0/.git_archival.txt +0 -4
- python_nss_ng-1.3.0/_version.txt +0 -1
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/.aislop/config.yml +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/.clangd +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/CONTRIBUTING.md +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/LICENSE +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/LICENSE.gpl +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/LICENSE.lgpl +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/LICENSE.mpl +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/LICENSES/Apache-2.0.txt +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/LICENSES/MPL-2.0.txt +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/MANIFEST.in +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/Makefile +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/QUICKSTART.md +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/README.md +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/REUSE.toml +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/SECURITY.md +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/doc/ChangeLog +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/doc/MAKEFILE_MIGRATION.md +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/doc/MANYLINUX_CONFIG.md +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/doc/MIGRATION.md +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/doc/MUTATION_TESTING.md +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/doc/TESTING.md +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/doc/examples/cert_dump.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/doc/examples/cert_trust.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/doc/examples/httplib_example.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/doc/examples/pbkdf2_example.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/doc/examples/ssl_cipher_info.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/doc/examples/ssl_example.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/doc/examples/ssl_version_range.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/doc/examples/verify_cert.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/doc/examples/verify_server.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/doc/get_api +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/meson.build +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/pyproject.toml +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/pyrightconfig.json +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/scripts/README.md +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/scripts/meson-version.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/scripts/run-all-tests.sh +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/src/NSPRerrs.h +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/src/SECerrs.h +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/src/SSLerrs.h +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/src/__init__.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/src/deprecations.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/src/io.pyi +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/src/nss_context.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/src/py_nspr_common.h +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/src/py_nspr_error.h +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/src/py_nspr_io.c +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/src/py_nspr_io.h +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/src/py_nss.h +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/src/py_shared_doc.h +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/src/py_ssl.c +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/src/py_ssl.h +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/src/py_traceback.h +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/src/secure_logging.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/src/ssl.pyi +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/conftest.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/exceptions.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/run_tests +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/setup_certs.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_cert_request.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_certificate_advanced.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_cipher.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_client_server.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_deprecations.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_digest.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_documentation_accuracy.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_examples.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_misc.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_pkcs12.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_platform_specific.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_property_based.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_secure_logging.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_security.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_thread_safety.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_type_hints.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_util.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_zzz_error_messages.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_zzz_integration.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/test_zzz_nonexistent_certs.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/test/util.py +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/typings/nss/__init__.pyi +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/typings/nss/error.pyi +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/typings/nss/io.pyi +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/typings/nss/ssl.pyi +0 -0
- {python_nss_ng-1.3.0 → python_nss_ng-1.3.2}/uv.lock +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-nss-ng
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.2
|
|
4
4
|
Summary: Python bindings for Network Security Services (NSS) and Netscape Portable Runtime (NSPR)
|
|
5
5
|
Keywords: nss,nspr,cryptography,ssl,tls,pki,x509,security
|
|
6
6
|
Author-Email: John Dennis <jdennis@redhat.com>, Matthew Watkins <mwatkins@linuxfoundation.org>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.3.2
|
|
@@ -1061,7 +1061,7 @@ class DN:
|
|
|
1061
1061
|
def __iter__(self) -> Any: ...
|
|
1062
1062
|
def __getitem__(self, key: Union[int, slice, str]) -> Any: ...
|
|
1063
1063
|
def __contains__(self, key: object) -> bool: ...
|
|
1064
|
-
def has_key(self, key: str) -> bool:
|
|
1064
|
+
def has_key(self, key: Union[str, int, SecItem]) -> bool:
|
|
1065
1065
|
"""Check if the DN has a specific key."""
|
|
1066
1066
|
...
|
|
1067
1067
|
|
|
@@ -1109,7 +1109,7 @@ class RDN:
|
|
|
1109
1109
|
def __le__(self, other: RDN) -> bool: ...
|
|
1110
1110
|
def __gt__(self, other: RDN) -> bool: ...
|
|
1111
1111
|
def __ge__(self, other: RDN) -> bool: ...
|
|
1112
|
-
def has_key(self, key: str) -> bool:
|
|
1112
|
+
def has_key(self, key: Union[str, int, SecItem]) -> bool:
|
|
1113
1113
|
"""Check if the RDN has a specific key."""
|
|
1114
1114
|
...
|
|
1115
1115
|
|
|
@@ -177,6 +177,31 @@ get_error_desc(long *p_error_code)
|
|
|
177
177
|
return result;
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
+
/*
|
|
181
|
+
* Raise the exception held in exception_obj, releasing our reference.
|
|
182
|
+
*
|
|
183
|
+
* PyErr_SetObject() takes its own reference to the value rather than
|
|
184
|
+
* stealing ours, so the reference returned by PyObject_Call() must be
|
|
185
|
+
* dropped here. Without that, every exception raised from C lived for
|
|
186
|
+
* the rest of the process, and with it its traceback and every frame
|
|
187
|
+
* and local variable the traceback refers to. A long-lived program that
|
|
188
|
+
* catches NSPR errors as part of normal control flow - such as
|
|
189
|
+
* PR_WOULD_BLOCK_ERROR on a non-blocking socket - grew without bound.
|
|
190
|
+
*
|
|
191
|
+
* A NULL exception_obj means constructing the exception failed and the
|
|
192
|
+
* error indicator already describes why, so it is left as it is.
|
|
193
|
+
*/
|
|
194
|
+
static PyObject *
|
|
195
|
+
raise_exception_obj(PyObject *type, PyObject *exception_obj)
|
|
196
|
+
{
|
|
197
|
+
if (exception_obj == NULL) {
|
|
198
|
+
return NULL;
|
|
199
|
+
}
|
|
200
|
+
PyErr_SetObject(type, exception_obj);
|
|
201
|
+
Py_DECREF(exception_obj);
|
|
202
|
+
return NULL;
|
|
203
|
+
}
|
|
204
|
+
|
|
180
205
|
static PyObject *
|
|
181
206
|
set_nspr_error(const char *format, ...)
|
|
182
207
|
{
|
|
@@ -192,11 +217,16 @@ set_nspr_error(const char *format, ...)
|
|
|
192
217
|
}
|
|
193
218
|
|
|
194
219
|
if ((kwds = PyDict_New()) == NULL) {
|
|
220
|
+
Py_XDECREF(error_message);
|
|
195
221
|
return NULL;
|
|
196
222
|
}
|
|
197
223
|
|
|
224
|
+
/* PyDict_SetItemString() does not steal the value's reference. */
|
|
198
225
|
if (error_message) {
|
|
199
|
-
|
|
226
|
+
int rc = PyDict_SetItemString(kwds, "error_message", error_message);
|
|
227
|
+
Py_DECREF(error_message);
|
|
228
|
+
if (rc != 0) {
|
|
229
|
+
Py_DECREF(kwds);
|
|
200
230
|
return NULL;
|
|
201
231
|
}
|
|
202
232
|
}
|
|
@@ -204,9 +234,7 @@ set_nspr_error(const char *format, ...)
|
|
|
204
234
|
exception_obj = PyObject_Call((PyObject *)&NSPRErrorType, empty_tuple, kwds);
|
|
205
235
|
Py_DECREF(kwds);
|
|
206
236
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
return NULL;
|
|
237
|
+
return raise_exception_obj((PyObject *)&NSPRErrorType, exception_obj);
|
|
210
238
|
}
|
|
211
239
|
|
|
212
240
|
static PyObject *
|
|
@@ -214,8 +242,10 @@ set_cert_verify_error(unsigned long usages, PyObject *log, const char *format, .
|
|
|
214
242
|
{
|
|
215
243
|
va_list vargs;
|
|
216
244
|
PyObject *error_message = NULL;
|
|
245
|
+
PyObject *py_usages = NULL;
|
|
217
246
|
PyObject *kwds = NULL;
|
|
218
247
|
PyObject *exception_obj = NULL;
|
|
248
|
+
int rc;
|
|
219
249
|
|
|
220
250
|
if (format) {
|
|
221
251
|
va_start(vargs, format);
|
|
@@ -224,30 +254,41 @@ set_cert_verify_error(unsigned long usages, PyObject *log, const char *format, .
|
|
|
224
254
|
}
|
|
225
255
|
|
|
226
256
|
if ((kwds = PyDict_New()) == NULL) {
|
|
257
|
+
Py_XDECREF(error_message);
|
|
227
258
|
return NULL;
|
|
228
259
|
}
|
|
229
260
|
|
|
261
|
+
/* PyDict_SetItemString() does not steal the value's reference. */
|
|
230
262
|
if (error_message) {
|
|
231
|
-
|
|
232
|
-
|
|
263
|
+
rc = PyDict_SetItemString(kwds, "error_message", error_message);
|
|
264
|
+
Py_DECREF(error_message);
|
|
265
|
+
if (rc != 0) {
|
|
266
|
+
goto fail;
|
|
233
267
|
}
|
|
234
268
|
}
|
|
235
269
|
|
|
236
|
-
if (
|
|
237
|
-
|
|
270
|
+
if ((py_usages = PyLong_FromUnsignedLong(usages)) == NULL) {
|
|
271
|
+
goto fail;
|
|
272
|
+
}
|
|
273
|
+
rc = PyDict_SetItemString(kwds, "usages", py_usages);
|
|
274
|
+
Py_DECREF(py_usages);
|
|
275
|
+
if (rc != 0) {
|
|
276
|
+
goto fail;
|
|
238
277
|
}
|
|
239
278
|
|
|
240
279
|
if (log) {
|
|
241
280
|
if (PyDict_SetItemString(kwds, "log", log) != 0) {
|
|
242
|
-
|
|
281
|
+
goto fail;
|
|
243
282
|
}
|
|
244
283
|
}
|
|
245
284
|
|
|
246
285
|
exception_obj = PyObject_Call((PyObject *)&CertVerifyErrorType, empty_tuple, kwds);
|
|
247
286
|
Py_DECREF(kwds);
|
|
248
287
|
|
|
249
|
-
|
|
288
|
+
return raise_exception_obj((PyObject *)&CertVerifyErrorType, exception_obj);
|
|
250
289
|
|
|
290
|
+
fail:
|
|
291
|
+
Py_DECREF(kwds);
|
|
251
292
|
return NULL;
|
|
252
293
|
}
|
|
253
294
|
|
|
@@ -515,30 +556,45 @@ NSPRError_init(NSPRError *self, PyObject *args, PyObject *kwds)
|
|
|
515
556
|
|
|
516
557
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&:NSPRError", kwlist,
|
|
517
558
|
UnicodeOrNoneConvert, &error_message,
|
|
518
|
-
LongOrNoneConvert, &error_code))
|
|
559
|
+
LongOrNoneConvert, &error_code)) {
|
|
560
|
+
/*
|
|
561
|
+
* UnicodeOrNoneConvert hands back a new reference; a later
|
|
562
|
+
* argument failing to parse must not strand it.
|
|
563
|
+
*/
|
|
564
|
+
Py_XDECREF(error_message);
|
|
519
565
|
return -1;
|
|
566
|
+
}
|
|
520
567
|
|
|
521
|
-
|
|
568
|
+
/*
|
|
569
|
+
* Both get_error_desc() and PyUnicode_FromFormat() return a new
|
|
570
|
+
* reference, which the attributes below take over. Adding another
|
|
571
|
+
* one on top leaked both strings with every exception raised.
|
|
572
|
+
*/
|
|
573
|
+
if ((error_desc = get_error_desc(&error_code)) == NULL) {
|
|
574
|
+
Py_XDECREF(error_message);
|
|
575
|
+
return -1;
|
|
576
|
+
}
|
|
522
577
|
|
|
523
578
|
if (error_message) {
|
|
524
579
|
str_value = PyUnicode_FromFormat("%U: %U", error_message, error_desc);
|
|
580
|
+
Py_DECREF(error_message);
|
|
581
|
+
if (str_value == NULL) {
|
|
582
|
+
Py_DECREF(error_desc);
|
|
583
|
+
return -1;
|
|
584
|
+
}
|
|
525
585
|
} else {
|
|
526
586
|
str_value = error_desc;
|
|
587
|
+
Py_INCREF(str_value);
|
|
527
588
|
}
|
|
528
589
|
|
|
529
|
-
|
|
530
590
|
Py_CLEAR(self->str_value);
|
|
531
591
|
self->str_value = str_value;
|
|
532
|
-
Py_XINCREF(self->str_value);
|
|
533
592
|
|
|
534
593
|
Py_CLEAR(self->error_desc);
|
|
535
594
|
self->error_desc = error_desc;
|
|
536
|
-
Py_XINCREF(self->error_desc);
|
|
537
595
|
|
|
538
596
|
self->error_code = error_code;
|
|
539
597
|
|
|
540
|
-
Py_XDECREF(error_message);
|
|
541
|
-
|
|
542
598
|
return 0;
|
|
543
599
|
}
|
|
544
600
|
|
|
@@ -690,8 +746,14 @@ CertVerifyError_init(CertVerifyError *self, PyObject *args, PyObject *kwds)
|
|
|
690
746
|
UnicodeOrNoneConvert, &error_message,
|
|
691
747
|
LongOrNoneConvert, &error_code,
|
|
692
748
|
&usages,
|
|
693
|
-
&log))
|
|
749
|
+
&log)) {
|
|
750
|
+
/*
|
|
751
|
+
* UnicodeOrNoneConvert hands back a new reference; a later
|
|
752
|
+
* argument failing to parse must not strand it.
|
|
753
|
+
*/
|
|
754
|
+
Py_XDECREF(error_message);
|
|
694
755
|
return -1;
|
|
756
|
+
}
|
|
695
757
|
|
|
696
758
|
if ((super_kwds = PyDict_New()) == NULL) {
|
|
697
759
|
Py_XDECREF(error_message);
|
|
@@ -705,15 +767,21 @@ CertVerifyError_init(CertVerifyError *self, PyObject *args, PyObject *kwds)
|
|
|
705
767
|
}
|
|
706
768
|
}
|
|
707
769
|
if (error_code != -1) {
|
|
708
|
-
|
|
770
|
+
/* PyDict_SetItemString() does not steal the value's reference. */
|
|
771
|
+
PyObject *py_error_code = PyLong_FromLong(error_code);
|
|
772
|
+
int rc = py_error_code == NULL ? -1 :
|
|
773
|
+
PyDict_SetItemString(super_kwds, "error_code", py_error_code);
|
|
774
|
+
Py_XDECREF(py_error_code);
|
|
775
|
+
if (rc != 0) {
|
|
709
776
|
Py_XDECREF(error_message);
|
|
710
777
|
Py_DECREF(super_kwds);
|
|
711
778
|
return -1;
|
|
712
779
|
}
|
|
713
780
|
}
|
|
714
|
-
|
|
781
|
+
result = CertVerifyErrorType.tp_base->tp_init((PyObject *)self, empty_tuple, super_kwds);
|
|
782
|
+
Py_DECREF(super_kwds);
|
|
783
|
+
if (result != 0) {
|
|
715
784
|
Py_XDECREF(error_message);
|
|
716
|
-
Py_DECREF(super_kwds);
|
|
717
785
|
return result;
|
|
718
786
|
}
|
|
719
787
|
|
|
@@ -2994,7 +2994,10 @@ get_oid_tag_from_object(PyObject *obj)
|
|
|
2994
2994
|
PyObject *py_obj_string_utf8 = NULL;
|
|
2995
2995
|
char *type_string;
|
|
2996
2996
|
|
|
2997
|
-
|
|
2997
|
+
/* A string UTF-8 cannot encode, such as a lone surrogate. */
|
|
2998
|
+
if ((py_obj_string_utf8 = PyBaseString_UTF8(obj, "OID Tag")) == NULL) {
|
|
2999
|
+
return -1;
|
|
3000
|
+
}
|
|
2998
3001
|
|
|
2999
3002
|
if ((type_string = PyBytes_AsString(py_obj_string_utf8)) == NULL) {
|
|
3000
3003
|
Py_DECREF(py_obj_string_utf8);
|
|
@@ -3029,7 +3032,22 @@ get_oid_tag_from_object(PyObject *obj)
|
|
|
3029
3032
|
}
|
|
3030
3033
|
Py_DECREF(py_obj_string_utf8);
|
|
3031
3034
|
} else if (PyInteger_Check(obj)) {
|
|
3032
|
-
|
|
3035
|
+
long value = PyLong_AsLong(obj);
|
|
3036
|
+
|
|
3037
|
+
if (value == -1 && PyErr_Occurred()) {
|
|
3038
|
+
return -1;
|
|
3039
|
+
}
|
|
3040
|
+
/*
|
|
3041
|
+
* Checked before narrowing: a value that fits a long but not an
|
|
3042
|
+
* int would otherwise wrap onto a real tag - (1 << 32) + 41 is
|
|
3043
|
+
* the common name on LP64.
|
|
3044
|
+
*/
|
|
3045
|
+
if (value < INT_MIN || value > INT_MAX) {
|
|
3046
|
+
PyErr_Format(PyExc_OverflowError,
|
|
3047
|
+
"oid tag %ld is out of range", value);
|
|
3048
|
+
return -1;
|
|
3049
|
+
}
|
|
3050
|
+
oid_tag = (int)value;
|
|
3033
3051
|
} else if (PySecItem_Check(obj)) {
|
|
3034
3052
|
oid_tag = SECOID_FindOIDTag(&((SecItem *)obj)->item);
|
|
3035
3053
|
} else {
|
|
@@ -3041,6 +3059,42 @@ get_oid_tag_from_object(PyObject *obj)
|
|
|
3041
3059
|
return oid_tag;
|
|
3042
3060
|
}
|
|
3043
3061
|
|
|
3062
|
+
/*
|
|
3063
|
+
* Resolve the key of a membership test - `key in rdn`, `rdn.has_key(key)`
|
|
3064
|
+
* and the DN equivalents - to an OID tag.
|
|
3065
|
+
*
|
|
3066
|
+
* Returns the tag; SEC_OID_UNKNOWN when the key identifies no OID, so
|
|
3067
|
+
* nothing can contain it; or -1 with an exception set for an error the
|
|
3068
|
+
* caller must propagate.
|
|
3069
|
+
*
|
|
3070
|
+
* get_oid_tag_from_object() fails with KeyError for a name that is not
|
|
3071
|
+
* an OID, ValueError for a malformed dotted-decimal OID or a string
|
|
3072
|
+
* UTF-8 cannot encode, and OverflowError for an integer no tag could
|
|
3073
|
+
* be. For a membership test each simply means "not present". A key of
|
|
3074
|
+
* a type that cannot name an OID at all is still a TypeError, and a
|
|
3075
|
+
* failure such as MemoryError still propagates. The integer -1 comes
|
|
3076
|
+
* back as -1 without an exception, and names no OID either.
|
|
3077
|
+
*/
|
|
3078
|
+
static int
|
|
3079
|
+
get_oid_tag_for_membership(PyObject *key)
|
|
3080
|
+
{
|
|
3081
|
+
int oid_tag = get_oid_tag_from_object(key);
|
|
3082
|
+
|
|
3083
|
+
if (oid_tag != -1) {
|
|
3084
|
+
return oid_tag;
|
|
3085
|
+
}
|
|
3086
|
+
if (!PyErr_Occurred()) {
|
|
3087
|
+
return SEC_OID_UNKNOWN;
|
|
3088
|
+
}
|
|
3089
|
+
if (PyErr_ExceptionMatches(PyExc_KeyError) ||
|
|
3090
|
+
PyErr_ExceptionMatches(PyExc_ValueError) ||
|
|
3091
|
+
PyErr_ExceptionMatches(PyExc_OverflowError)) {
|
|
3092
|
+
PyErr_Clear();
|
|
3093
|
+
return SEC_OID_UNKNOWN;
|
|
3094
|
+
}
|
|
3095
|
+
return -1;
|
|
3096
|
+
}
|
|
3097
|
+
|
|
3044
3098
|
static bool
|
|
3045
3099
|
is_oid_string(const char *oid_string)
|
|
3046
3100
|
{
|
|
@@ -9989,7 +10043,13 @@ Certificate_verify_with_log(Certificate *self, PyObject *args)
|
|
|
9989
10043
|
required_usages, pr_time, pin_args,
|
|
9990
10044
|
&py_log->log, &returned_usages) != SECSuccess) {
|
|
9991
10045
|
Py_DECREF(pin_args);
|
|
9992
|
-
|
|
10046
|
+
/*
|
|
10047
|
+
* The exception takes its own reference to the log; ours is
|
|
10048
|
+
* released either way, or every failed verification leaks it.
|
|
10049
|
+
*/
|
|
10050
|
+
set_cert_verify_error(returned_usages, (PyObject *)py_log, NULL);
|
|
10051
|
+
Py_DECREF(py_log);
|
|
10052
|
+
return NULL;
|
|
9993
10053
|
}
|
|
9994
10054
|
Py_DECREF(pin_args);
|
|
9995
10055
|
|
|
@@ -11453,8 +11513,14 @@ RDN_contains(RDN *self, PyObject *arg)
|
|
|
11453
11513
|
|
|
11454
11514
|
TraceMethodEnter(self);
|
|
11455
11515
|
|
|
11456
|
-
|
|
11457
|
-
|
|
11516
|
+
/*
|
|
11517
|
+
* The contains slot must return -1 whenever it leaves an exception
|
|
11518
|
+
* set: returning 0 with one pending made `in` raise SystemError.
|
|
11519
|
+
*/
|
|
11520
|
+
if ((oid_tag = get_oid_tag_for_membership(arg)) == -1) {
|
|
11521
|
+
return -1;
|
|
11522
|
+
}
|
|
11523
|
+
if (oid_tag == SEC_OID_UNKNOWN) {
|
|
11458
11524
|
return 0;
|
|
11459
11525
|
}
|
|
11460
11526
|
|
|
@@ -11487,10 +11553,13 @@ RDN_has_key(RDN *self, PyObject *args)
|
|
|
11487
11553
|
&arg))
|
|
11488
11554
|
return NULL;
|
|
11489
11555
|
|
|
11490
|
-
|
|
11491
|
-
|
|
11492
|
-
|
|
11556
|
+
switch (RDN_contains(self, arg)) {
|
|
11557
|
+
case -1:
|
|
11558
|
+
return NULL;
|
|
11559
|
+
case 0:
|
|
11493
11560
|
Py_RETURN_FALSE;
|
|
11561
|
+
default:
|
|
11562
|
+
Py_RETURN_TRUE;
|
|
11494
11563
|
}
|
|
11495
11564
|
}
|
|
11496
11565
|
|
|
@@ -12118,8 +12187,14 @@ DN_contains(DN *self, PyObject *arg)
|
|
|
12118
12187
|
|
|
12119
12188
|
TraceMethodEnter(self);
|
|
12120
12189
|
|
|
12121
|
-
|
|
12122
|
-
|
|
12190
|
+
/*
|
|
12191
|
+
* The contains slot must return -1 whenever it leaves an exception
|
|
12192
|
+
* set: returning 0 with one pending made `in` raise SystemError.
|
|
12193
|
+
*/
|
|
12194
|
+
if ((oid_tag = get_oid_tag_for_membership(arg)) == -1) {
|
|
12195
|
+
return -1;
|
|
12196
|
+
}
|
|
12197
|
+
if (oid_tag == SEC_OID_UNKNOWN) {
|
|
12123
12198
|
return 0;
|
|
12124
12199
|
}
|
|
12125
12200
|
|
|
@@ -12152,10 +12227,13 @@ DN_has_key(DN *self, PyObject *args)
|
|
|
12152
12227
|
&arg))
|
|
12153
12228
|
return NULL;
|
|
12154
12229
|
|
|
12155
|
-
|
|
12156
|
-
|
|
12157
|
-
|
|
12230
|
+
switch (DN_contains(self, arg)) {
|
|
12231
|
+
case -1:
|
|
12232
|
+
return NULL;
|
|
12233
|
+
case 0:
|
|
12158
12234
|
Py_RETURN_FALSE;
|
|
12235
|
+
default:
|
|
12236
|
+
Py_RETURN_TRUE;
|
|
12159
12237
|
}
|
|
12160
12238
|
}
|
|
12161
12239
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
# SPDX-FileCopyrightText: Copyright (c) 2010-2025 python-nss-ng contributors
|
|
3
3
|
|
|
4
4
|
import unittest
|
|
5
|
+
from typing import Any
|
|
5
6
|
|
|
6
7
|
import nss.nss as nss
|
|
7
8
|
|
|
@@ -338,6 +339,45 @@ class TestCertName(unittest.TestCase):
|
|
|
338
339
|
self.assertEqual(list(rdn), [ou1_ava1, ou1_ava2])
|
|
339
340
|
self.assertEqual(rdn[:], [ou1_ava1, ou1_ava2])
|
|
340
341
|
|
|
342
|
+
def test_contains_key_naming_no_oid(self):
|
|
343
|
+
# A key that identifies no OID cannot be present. It used to leave
|
|
344
|
+
# the lookup's KeyError or ValueError set while answering False,
|
|
345
|
+
# which the interpreter reported as SystemError.
|
|
346
|
+
name = nss.DN(self.subject_name)
|
|
347
|
+
rdn = name[0]
|
|
348
|
+
for container in (name, rdn):
|
|
349
|
+
# (1 << 32) + tag fits a C long but not an int, and used to
|
|
350
|
+
# narrow onto that tag.
|
|
351
|
+
aliases = (
|
|
352
|
+
(1 << 32) + nss.SEC_OID_AVA_COMMON_NAME,
|
|
353
|
+
-(1 << 32) + nss.SEC_OID_AVA_COMMON_NAME,
|
|
354
|
+
)
|
|
355
|
+
for key in ("Test CA", "not-an-oid", "1.2.x", "\ud800", -1, 2**70, *aliases):
|
|
356
|
+
self.assertFalse(key in container, key)
|
|
357
|
+
self.assertTrue(key not in container, key)
|
|
358
|
+
self.assertFalse(container.has_key(key), key)
|
|
359
|
+
|
|
360
|
+
def test_oid_lookup_of_unencodable_string_raises(self):
|
|
361
|
+
# A string UTF-8 cannot encode used to crash the interpreter.
|
|
362
|
+
with self.assertRaises(UnicodeEncodeError):
|
|
363
|
+
nss.oid_tag("\ud800")
|
|
364
|
+
with self.assertRaises(UnicodeEncodeError):
|
|
365
|
+
nss.DN(self.subject_name)["\ud800"]
|
|
366
|
+
|
|
367
|
+
def test_oid_tag_rejects_integer_outside_int(self):
|
|
368
|
+
with self.assertRaises(OverflowError):
|
|
369
|
+
nss.oid_tag((1 << 32) + nss.SEC_OID_AVA_COMMON_NAME)
|
|
370
|
+
|
|
371
|
+
def test_contains_rejects_unusable_type(self):
|
|
372
|
+
# Typed Any: the point is a key of a type has_key does not accept.
|
|
373
|
+
unusable: Any = 1.5
|
|
374
|
+
name = nss.DN(self.subject_name)
|
|
375
|
+
for container in (name, name[0]):
|
|
376
|
+
with self.assertRaises(TypeError):
|
|
377
|
+
_ = [] in container
|
|
378
|
+
with self.assertRaises(TypeError):
|
|
379
|
+
container.has_key(unusable)
|
|
380
|
+
|
|
341
381
|
|
|
342
382
|
if __name__ == "__main__":
|
|
343
383
|
unittest.main()
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
# SPDX-FileCopyrightText: 2026 The Linux Foundation
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Regression tests for reference leaks in NSPR error handling.
|
|
6
|
+
|
|
7
|
+
Every NSPRError raised from C used to survive for the life of the
|
|
8
|
+
process, together with its traceback and every frame and local variable
|
|
9
|
+
that traceback refers to; every NSPRError and CertVerifyError also
|
|
10
|
+
leaked the strings and integers it was built from. Long-lived programs
|
|
11
|
+
that treat PR_WOULD_BLOCK_ERROR on a non-blocking socket as ordinary
|
|
12
|
+
control flow grew without bound.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import gc
|
|
16
|
+
import tracemalloc
|
|
17
|
+
|
|
18
|
+
import pytest
|
|
19
|
+
|
|
20
|
+
import nss.error
|
|
21
|
+
import nss.io
|
|
22
|
+
import nss.nss
|
|
23
|
+
|
|
24
|
+
ITERATIONS = 2000
|
|
25
|
+
|
|
26
|
+
# Generous against allocator noise; each leak measured several hundred
|
|
27
|
+
# bytes per iteration.
|
|
28
|
+
MAX_BYTES_PER_ITERATION = 16
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _live(type_name):
|
|
32
|
+
return sum(1 for o in gc.get_objects() if type(o).__name__ == type_name)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _growth(fn, type_name):
|
|
36
|
+
"""Return (surviving objects, traced bytes per call) for ITERATIONS calls."""
|
|
37
|
+
fn() # warm any caches before measuring
|
|
38
|
+
tracemalloc.start()
|
|
39
|
+
try:
|
|
40
|
+
gc.collect()
|
|
41
|
+
live_before = _live(type_name)
|
|
42
|
+
bytes_before = tracemalloc.get_traced_memory()[0]
|
|
43
|
+
for _ in range(ITERATIONS):
|
|
44
|
+
fn()
|
|
45
|
+
gc.collect()
|
|
46
|
+
live_after = _live(type_name)
|
|
47
|
+
bytes_after = tracemalloc.get_traced_memory()[0]
|
|
48
|
+
finally:
|
|
49
|
+
tracemalloc.stop()
|
|
50
|
+
return live_after - live_before, (bytes_after - bytes_before) / ITERATIONS
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@pytest.fixture
|
|
54
|
+
def nonblocking_listener():
|
|
55
|
+
sock = nss.io.Socket(nss.io.PR_AF_INET)
|
|
56
|
+
sock.set_socket_option(nss.io.PR_SockOpt_Reuseaddr, True)
|
|
57
|
+
sock.bind(nss.io.NetworkAddress(nss.io.PR_IpAddrLoopback, 0))
|
|
58
|
+
sock.listen(1)
|
|
59
|
+
sock.set_socket_option(nss.io.PR_SockOpt_Nonblocking, True)
|
|
60
|
+
yield sock
|
|
61
|
+
sock.close()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class TestErrorReferenceLeaks:
|
|
65
|
+
"""NSPR errors must be released once nothing refers to them."""
|
|
66
|
+
|
|
67
|
+
def test_error_raised_from_c_is_released(self, nonblocking_listener):
|
|
68
|
+
def accept_nothing():
|
|
69
|
+
with pytest.raises(nss.error.NSPRError) as exc_info:
|
|
70
|
+
nonblocking_listener.accept()
|
|
71
|
+
assert exc_info.value.errno == nss.error.PR_WOULD_BLOCK_ERROR
|
|
72
|
+
|
|
73
|
+
survivors, per_call = _growth(accept_nothing, "NSPRError")
|
|
74
|
+
assert survivors == 0
|
|
75
|
+
assert per_call < MAX_BYTES_PER_ITERATION
|
|
76
|
+
|
|
77
|
+
def test_error_with_message_raised_from_c_is_released(self):
|
|
78
|
+
# A C path raising with a formatted message: that message string
|
|
79
|
+
# was leaked on top of the exception itself.
|
|
80
|
+
def parse_bad_name():
|
|
81
|
+
with pytest.raises(nss.error.NSPRError) as exc_info:
|
|
82
|
+
nss.nss.DN("this is not=a,,=valid=name")
|
|
83
|
+
assert "cannot parse X500 name" in str(exc_info.value)
|
|
84
|
+
|
|
85
|
+
survivors, per_call = _growth(parse_bad_name, "NSPRError")
|
|
86
|
+
assert survivors == 0
|
|
87
|
+
assert per_call < MAX_BYTES_PER_ITERATION
|
|
88
|
+
|
|
89
|
+
def test_nspr_error_construction_does_not_leak(self):
|
|
90
|
+
def construct():
|
|
91
|
+
nss.error.NSPRError("message", nss.error.PR_WOULD_BLOCK_ERROR)
|
|
92
|
+
|
|
93
|
+
survivors, per_call = _growth(construct, "NSPRError")
|
|
94
|
+
assert survivors == 0
|
|
95
|
+
assert per_call < MAX_BYTES_PER_ITERATION
|
|
96
|
+
|
|
97
|
+
def test_cert_verify_error_construction_does_not_leak(self):
|
|
98
|
+
def construct():
|
|
99
|
+
# (error_message, error_code, usages)
|
|
100
|
+
nss.error.CertVerifyError("message", nss.error.SEC_ERROR_EXPIRED_CERTIFICATE, 1)
|
|
101
|
+
|
|
102
|
+
survivors, per_call = _growth(construct, "CertVerifyError")
|
|
103
|
+
assert survivors == 0
|
|
104
|
+
assert per_call < MAX_BYTES_PER_ITERATION
|
|
105
|
+
|
|
106
|
+
def test_rejected_arguments_do_not_leak(self):
|
|
107
|
+
# The message is converted before the error code is parsed; a bad
|
|
108
|
+
# code used to strand the message's reference.
|
|
109
|
+
message = "a message long enough to be its own allocation" * 2
|
|
110
|
+
|
|
111
|
+
def construct_nspr_error():
|
|
112
|
+
with pytest.raises(TypeError):
|
|
113
|
+
nss.error.NSPRError(message + "x", "not-an-int")
|
|
114
|
+
|
|
115
|
+
def construct_cert_verify_error():
|
|
116
|
+
with pytest.raises(TypeError):
|
|
117
|
+
nss.error.CertVerifyError(message + "y", "not-an-int", 1)
|
|
118
|
+
|
|
119
|
+
for fn, type_name in (
|
|
120
|
+
(construct_nspr_error, "NSPRError"),
|
|
121
|
+
(construct_cert_verify_error, "CertVerifyError"),
|
|
122
|
+
):
|
|
123
|
+
survivors, per_call = _growth(fn, type_name)
|
|
124
|
+
assert survivors == 0
|
|
125
|
+
assert per_call < MAX_BYTES_PER_ITERATION
|
|
126
|
+
|
|
127
|
+
def test_failed_verify_with_log_does_not_leak(self, nss_clean_state):
|
|
128
|
+
# The CertVerifyLog handed to the exception was a new reference
|
|
129
|
+
# the caller never released. It is not tracked by the garbage
|
|
130
|
+
# collector, so only its bytes show the leak.
|
|
131
|
+
certdb = nss_clean_state
|
|
132
|
+
|
|
133
|
+
def fail_verification(cert):
|
|
134
|
+
exc_info = None
|
|
135
|
+
try:
|
|
136
|
+
with pytest.raises(nss.error.CertVerifyError) as exc_info:
|
|
137
|
+
cert.verify_with_log(certdb, True, nss.nss.certificateUsageEmailSigner, None)
|
|
138
|
+
# The log still belongs to the exception, and is usable.
|
|
139
|
+
assert exc_info.value.log is not None
|
|
140
|
+
assert len(exc_info.value.log) >= 0
|
|
141
|
+
finally:
|
|
142
|
+
# A failure here would keep this frame, and with it the
|
|
143
|
+
# certificate and the log, alive in its traceback.
|
|
144
|
+
del cert
|
|
145
|
+
exc_info = None
|
|
146
|
+
|
|
147
|
+
# Held through a list that is emptied on every path: the fixture
|
|
148
|
+
# shuts NSS down afterwards, which NSS refuses while a certificate
|
|
149
|
+
# is still referenced - by a failed assertion's traceback, say.
|
|
150
|
+
held = [nss.nss.find_cert_from_nickname("test_server")]
|
|
151
|
+
try:
|
|
152
|
+
_, per_call = _growth(lambda: fail_verification(held[0]), "CertVerifyError")
|
|
153
|
+
assert per_call < MAX_BYTES_PER_ITERATION
|
|
154
|
+
finally:
|
|
155
|
+
held.clear()
|
|
156
|
+
|
|
157
|
+
def test_error_attributes_survive_the_fix(self):
|
|
158
|
+
err = nss.error.NSPRError("message", nss.error.PR_WOULD_BLOCK_ERROR)
|
|
159
|
+
assert err.errno == nss.error.PR_WOULD_BLOCK_ERROR
|
|
160
|
+
assert str(err).startswith("message: ")
|
|
161
|
+
assert err.error_desc in str(err)
|
|
162
|
+
|
|
163
|
+
bare = nss.error.NSPRError(None, nss.error.PR_WOULD_BLOCK_ERROR)
|
|
164
|
+
assert str(bare) == bare.error_desc
|
|
165
|
+
|
|
166
|
+
cve = nss.error.CertVerifyError("message", nss.error.SEC_ERROR_EXPIRED_CERTIFICATE, 5)
|
|
167
|
+
assert cve.errno == nss.error.SEC_ERROR_EXPIRED_CERTIFICATE
|
|
168
|
+
assert cve.usages == 5
|
|
@@ -205,19 +205,23 @@ class TestMemoryUsage:
|
|
|
205
205
|
gc.collect()
|
|
206
206
|
baseline_blocks = sys.getallocatedblocks()
|
|
207
207
|
|
|
208
|
+
found = 0
|
|
208
209
|
for _ in range(iterations):
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
except NSPRError:
|
|
216
|
-
pass
|
|
210
|
+
cert = nss.find_cert_from_nickname("test_ca")
|
|
211
|
+
if cert is not None:
|
|
212
|
+
# Access properties
|
|
213
|
+
subject = cert.subject
|
|
214
|
+
found += 1
|
|
215
|
+
# Let cert go out of scope
|
|
217
216
|
|
|
218
217
|
# Force garbage collection
|
|
219
218
|
gc.collect()
|
|
220
219
|
|
|
220
|
+
# The nss_db_context fixture creates test_ca, so every lookup has to
|
|
221
|
+
# return a certificate; without this the loop could allocate nothing
|
|
222
|
+
# and leave the growth check below unable to fail.
|
|
223
|
+
assert found == iterations, f"Only {found} of {iterations} lookups found test_ca"
|
|
224
|
+
|
|
221
225
|
# CertificateType carries no Py_TPFLAGS_HAVE_GC, so a retained wrapper
|
|
222
226
|
# never reaches gc.get_objects(); it does cost an allocator block.
|
|
223
227
|
growth = sys.getallocatedblocks() - baseline_blocks
|
|
@@ -219,7 +219,14 @@ class TestNSSContextWithDatabase:
|
|
|
219
219
|
# Try to find a certificate
|
|
220
220
|
try:
|
|
221
221
|
cert = nss.find_cert_from_nickname("test_ca")
|
|
222
|
-
|
|
222
|
+
try:
|
|
223
|
+
assert cert is not None
|
|
224
|
+
finally:
|
|
225
|
+
# Released before the context shuts NSS down, on
|
|
226
|
+
# every path: NSS refuses to shut down while a
|
|
227
|
+
# certificate is still referenced, and destroying one
|
|
228
|
+
# afterwards crashes the next initialisation.
|
|
229
|
+
del cert
|
|
223
230
|
except NSPRError:
|
|
224
231
|
# Certificate might not exist, but database access works
|
|
225
232
|
pass
|
|
@@ -487,13 +494,17 @@ class TestNSSContextRealWorld:
|
|
|
487
494
|
|
|
488
495
|
with NSSContext(db_name=db_path):
|
|
489
496
|
certdb = nss.get_default_certdb()
|
|
497
|
+
assert certdb is not None
|
|
490
498
|
|
|
491
|
-
|
|
499
|
+
cert = nss.find_cert_from_nickname("test_ca")
|
|
492
500
|
try:
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
#
|
|
496
|
-
|
|
501
|
+
assert "CN=Test CA" in str(cert.subject)
|
|
502
|
+
finally:
|
|
503
|
+
# Released before the context shuts NSS down, which NSS
|
|
504
|
+
# refuses while a certificate is still referenced - on
|
|
505
|
+
# every path, since a failed assertion's traceback would
|
|
506
|
+
# otherwise keep it alive through the shutdown.
|
|
507
|
+
del cert
|
|
497
508
|
|
|
498
509
|
def test_digest_operation_in_context(self):
|
|
499
510
|
"""Test performing digest operations within context."""
|
|
@@ -254,12 +254,22 @@ class TestOCSPChecking:
|
|
|
254
254
|
# Clean up
|
|
255
255
|
nss.disable_ocsp_checking()
|
|
256
256
|
|
|
257
|
-
def
|
|
258
|
-
"""
|
|
259
|
-
nss.
|
|
257
|
+
def test_ocsp_repeated_disable(self, nss_clean_state):
|
|
258
|
+
"""Disabling OCSP again reports that it is not enabled, harmlessly."""
|
|
259
|
+
from nss.error import SEC_ERROR_OCSP_NOT_ENABLED
|
|
260
260
|
|
|
261
|
+
nss.enable_ocsp_checking()
|
|
261
262
|
nss.disable_ocsp_checking()
|
|
262
|
-
|
|
263
|
+
|
|
264
|
+
# Documented behaviour: a disable while OCSP is off raises
|
|
265
|
+
# SEC_ERROR_OCSP_NOT_ENABLED, which callers may ignore.
|
|
266
|
+
for _ in range(2):
|
|
267
|
+
with pytest.raises(NSPRError) as exc_info:
|
|
268
|
+
nss.disable_ocsp_checking()
|
|
269
|
+
assert exc_info.value.errno == SEC_ERROR_OCSP_NOT_ENABLED
|
|
270
|
+
|
|
271
|
+
# And OCSP can still be enabled and disabled afterwards.
|
|
272
|
+
nss.enable_ocsp_checking()
|
|
263
273
|
nss.disable_ocsp_checking()
|
|
264
274
|
|
|
265
275
|
|
|
@@ -290,17 +300,20 @@ class TestPKIXValidation:
|
|
|
290
300
|
assert prev2 == (not value)
|
|
291
301
|
assert nss.get_use_pkix_for_validation() == value
|
|
292
302
|
|
|
293
|
-
def
|
|
294
|
-
"""
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
303
|
+
def test_pkix_validation_rejects_non_integer(self, nss_clean_state):
|
|
304
|
+
"""Values that are not integers are rejected; integers are truthy flags."""
|
|
305
|
+
original = nss.get_use_pkix_for_validation()
|
|
306
|
+
try:
|
|
307
|
+
with pytest.raises(TypeError):
|
|
308
|
+
nss.set_use_pkix_for_validation("true")
|
|
298
309
|
|
|
299
|
-
|
|
310
|
+
# The flag is parsed as an int, so 1 and 0 act as True and False.
|
|
300
311
|
nss.set_use_pkix_for_validation(1)
|
|
301
|
-
|
|
302
|
-
with pytest.raises(TypeError):
|
|
312
|
+
assert nss.get_use_pkix_for_validation() is True
|
|
303
313
|
nss.set_use_pkix_for_validation(0)
|
|
314
|
+
assert nss.get_use_pkix_for_validation() is False
|
|
315
|
+
finally:
|
|
316
|
+
nss.set_use_pkix_for_validation(original)
|
|
304
317
|
|
|
305
318
|
def test_pkix_validation_set_true(self, nss_clean_state):
|
|
306
319
|
"""Test explicitly setting PKIX validation to True."""
|
|
@@ -1061,7 +1061,7 @@ class DN:
|
|
|
1061
1061
|
def __iter__(self) -> Any: ...
|
|
1062
1062
|
def __getitem__(self, key: Union[int, slice, str]) -> Any: ...
|
|
1063
1063
|
def __contains__(self, key: object) -> bool: ...
|
|
1064
|
-
def has_key(self, key: str) -> bool:
|
|
1064
|
+
def has_key(self, key: Union[str, int, SecItem]) -> bool:
|
|
1065
1065
|
"""Check if the DN has a specific key."""
|
|
1066
1066
|
...
|
|
1067
1067
|
|
|
@@ -1109,7 +1109,7 @@ class RDN:
|
|
|
1109
1109
|
def __le__(self, other: RDN) -> bool: ...
|
|
1110
1110
|
def __gt__(self, other: RDN) -> bool: ...
|
|
1111
1111
|
def __ge__(self, other: RDN) -> bool: ...
|
|
1112
|
-
def has_key(self, key: str) -> bool:
|
|
1112
|
+
def has_key(self, key: Union[str, int, SecItem]) -> bool:
|
|
1113
1113
|
"""Check if the RDN has a specific key."""
|
|
1114
1114
|
...
|
|
1115
1115
|
|
python_nss_ng-1.3.0/_version.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
1.3.0
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|