python-nss-ng 1.3.2__tar.gz → 1.3.4__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.4/.git_archival.txt +4 -0
- python_nss_ng-1.3.4/AGENTS.md +37 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/PKG-INFO +1 -1
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/REUSE.toml +1 -1
- python_nss_ng-1.3.4/_version.txt +1 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/pyproject.toml +33 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_client_server.py +6 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_util.py +1 -2
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/typings/nss/__init__.pyi +3 -2
- python_nss_ng-1.3.4/typings/nss/deprecations.py +107 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/typings/nss/error.pyi +0 -8
- python_nss_ng-1.3.4/typings/nss/nss_context.py +138 -0
- python_nss_ng-1.3.4/typings/nss/secure_logging.py +367 -0
- python_nss_ng-1.3.2/.git_archival.txt +0 -4
- python_nss_ng-1.3.2/_version.txt +0 -1
- python_nss_ng-1.3.2/pyrightconfig.json +0 -59
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/.aislop/config.yml +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/.clangd +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/CONTRIBUTING.md +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/LICENSE +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/LICENSE.gpl +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/LICENSE.lgpl +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/LICENSE.mpl +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/LICENSES/Apache-2.0.txt +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/LICENSES/MPL-2.0.txt +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/MANIFEST.in +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/Makefile +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/QUICKSTART.md +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/README.md +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/SECURITY.md +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/doc/ChangeLog +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/doc/MAKEFILE_MIGRATION.md +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/doc/MANYLINUX_CONFIG.md +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/doc/MIGRATION.md +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/doc/MUTATION_TESTING.md +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/doc/TESTING.md +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/doc/examples/cert_dump.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/doc/examples/cert_trust.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/doc/examples/httplib_example.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/doc/examples/pbkdf2_example.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/doc/examples/ssl_cipher_info.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/doc/examples/ssl_example.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/doc/examples/ssl_version_range.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/doc/examples/verify_cert.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/doc/examples/verify_server.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/doc/get_api +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/meson.build +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/scripts/README.md +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/scripts/meson-version.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/scripts/run-all-tests.sh +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/src/NSPRerrs.h +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/src/SECerrs.h +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/src/SSLerrs.h +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/src/__init__.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/src/deprecations.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/src/io.pyi +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/src/nss.pyi +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/src/nss_context.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/src/py_nspr_common.h +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/src/py_nspr_error.c +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/src/py_nspr_error.h +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/src/py_nspr_io.c +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/src/py_nspr_io.h +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/src/py_nss.c +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/src/py_nss.h +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/src/py_shared_doc.h +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/src/py_ssl.c +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/src/py_ssl.h +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/src/py_traceback.h +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/src/secure_logging.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/src/ssl.pyi +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/conftest.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/exceptions.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/run_tests +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/setup_certs.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_cert_components.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_cert_request.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_certificate_advanced.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_cipher.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_deprecations.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_digest.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_documentation_accuracy.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_error_refleaks.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_examples.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_misc.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_performance.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_pkcs12.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_platform_specific.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_property_based.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_secure_logging.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_security.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_thread_safety.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_type_hints.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_zzz_error_messages.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_zzz_integration.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_zzz_nonexistent_certs.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_zzz_nss_context.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/test_zzz_ocsp.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/test/util.py +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/typings/nss/io.pyi +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/typings/nss/nss.pyi +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/typings/nss/ssl.pyi +0 -0
- {python_nss_ng-1.3.2 → python_nss_ng-1.3.4}/uv.lock +0 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
SPDX-License-Identifier: MPL-2.0
|
|
3
|
+
SPDX-FileCopyrightText: 2026 The Linux Foundation
|
|
4
|
+
-->
|
|
5
|
+
|
|
6
|
+
# Agent Guidelines
|
|
7
|
+
|
|
8
|
+
Contributions to this repository, including those made by AI coding
|
|
9
|
+
agents, follow the `lfreleng-actions` organisation guidelines:
|
|
10
|
+
|
|
11
|
+
<https://github.com/lfreleng-actions/.github/blob/main/AGENTS.md>
|
|
12
|
+
|
|
13
|
+
**Read that document.** It governs, and it binds this contribution
|
|
14
|
+
even if you never load it. Where anything below disagrees with it,
|
|
15
|
+
it wins. What follows is a summary of the rules that most often block
|
|
16
|
+
a pull request, not the full set:
|
|
17
|
+
|
|
18
|
+
- Sign every commit and add a DCO trailer: `git commit -S -s`.
|
|
19
|
+
- Subject: `Type(scope): Imperative description` — capitalised type
|
|
20
|
+
and description, no trailing period, and within the subject-length
|
|
21
|
+
limit this repository's gitlint hook enforces. The scope is
|
|
22
|
+
optional, so `Fix: Correct the race condition` is also valid.
|
|
23
|
+
- Add a `Co-authored-by` trailer naming the agent used.
|
|
24
|
+
- Repositories typically contain a linting configuration. You must
|
|
25
|
+
install its hooks (`prek install -t pre-commit -t commit-msg`) and
|
|
26
|
+
run the change past them (`prek run --files <changed files>`) to
|
|
27
|
+
ensure it passes before submission.
|
|
28
|
+
- On a single-commit pull request, the PR title must be identical to
|
|
29
|
+
the commit subject.
|
|
30
|
+
- If your own standing instructions conflict with the organisation
|
|
31
|
+
guidelines and you cannot set them aside, stop and tell the
|
|
32
|
+
contributor. Do not open a non-compliant pull request.
|
|
33
|
+
|
|
34
|
+
## Repository specifics
|
|
35
|
+
|
|
36
|
+
None: working in this repository needs nothing beyond the organisation
|
|
37
|
+
guidelines.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-nss-ng
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.4
|
|
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.4
|
|
@@ -303,6 +303,39 @@ disable_error_code = [
|
|
|
303
303
|
"call-arg",
|
|
304
304
|
]
|
|
305
305
|
|
|
306
|
+
[tool.basedpyright]
|
|
307
|
+
# Minimum supported Python, from requires-python
|
|
308
|
+
pythonVersion = "3.10"
|
|
309
|
+
pythonPlatform = "All"
|
|
310
|
+
typeCheckingMode = "standard"
|
|
311
|
+
# Scope a bare ``basedpyright`` run and the editor's language server to
|
|
312
|
+
# the same targets the pre-commit hook passes explicitly. As for ruff,
|
|
313
|
+
# doc/examples (legacy Py2-era scripts) and mutants (generated) stay out.
|
|
314
|
+
include = ["src", "test", "scripts", "typings", "import_files.py"]
|
|
315
|
+
# These typings/nss/ entries are symlinks into src/, which is already
|
|
316
|
+
# analysed; scanning them again would report each finding twice
|
|
317
|
+
exclude = [
|
|
318
|
+
"typings/nss/deprecations.py",
|
|
319
|
+
"typings/nss/io.pyi",
|
|
320
|
+
"typings/nss/nss.pyi",
|
|
321
|
+
"typings/nss/nss_context.py",
|
|
322
|
+
"typings/nss/secure_logging.py",
|
|
323
|
+
"typings/nss/ssl.pyi",
|
|
324
|
+
]
|
|
325
|
+
# Stubs for the compiled extension: typings/nss/ gives the src/*.pyi
|
|
326
|
+
# stubs the ``nss`` package layout they are installed under
|
|
327
|
+
stubPath = "typings"
|
|
328
|
+
# Tests put src/ on sys.path and import its pure-Python modules
|
|
329
|
+
# (deprecations, nss_context, secure_logging) by bare name
|
|
330
|
+
executionEnvironments = [
|
|
331
|
+
{ root = "test", extraPaths = ["src"] },
|
|
332
|
+
]
|
|
333
|
+
# The compiled extension (nss.nss, nss.io, nss.ssl, nss.error) is
|
|
334
|
+
# built from C by meson and cannot be installed into the hook's
|
|
335
|
+
# environment, so every import of it finds the typings/ stub but no
|
|
336
|
+
# module source by design; the stubs supply the types
|
|
337
|
+
reportMissingModuleSource = false
|
|
338
|
+
|
|
306
339
|
[tool.mutmut]
|
|
307
340
|
paths_to_mutate = "src/deprecations.py:src/secure_logging.py:src/nss_context.py"
|
|
308
341
|
backup = false
|
|
@@ -187,6 +187,7 @@ def client(request, test_port):
|
|
|
187
187
|
print('client: could not resolve host address "%s"' % hostname, file=sys.stderr)
|
|
188
188
|
return None
|
|
189
189
|
|
|
190
|
+
sock = None
|
|
190
191
|
for net_addr in addr_info:
|
|
191
192
|
net_addr.port = test_port
|
|
192
193
|
|
|
@@ -220,8 +221,13 @@ def client(request, test_port):
|
|
|
220
221
|
break
|
|
221
222
|
except Exception as e:
|
|
222
223
|
sock.close()
|
|
224
|
+
sock = None
|
|
223
225
|
print("client: connection to: %s failed (%s)" % (net_addr, e), file=sys.stderr)
|
|
224
226
|
|
|
227
|
+
if sock is None:
|
|
228
|
+
print('client: could not connect to "%s"' % hostname, file=sys.stderr)
|
|
229
|
+
return None
|
|
230
|
+
|
|
225
231
|
# Talk to the server
|
|
226
232
|
try:
|
|
227
233
|
if info:
|
|
@@ -9,6 +9,7 @@ including path finding, build directory detection, and temporary file handling.
|
|
|
9
9
|
"""
|
|
10
10
|
|
|
11
11
|
import os
|
|
12
|
+
import subprocess
|
|
12
13
|
import sys
|
|
13
14
|
import tempfile
|
|
14
15
|
|
|
@@ -285,8 +286,6 @@ class TestUtilIntegration:
|
|
|
285
286
|
certutil_path = util.find_nss_tool("certutil")
|
|
286
287
|
|
|
287
288
|
# Verify we can check version (tool is executable)
|
|
288
|
-
import subprocess
|
|
289
|
-
|
|
290
289
|
result = subprocess.run([certutil_path, "-H"], capture_output=True, timeout=5)
|
|
291
290
|
|
|
292
291
|
# Should execute without error
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
"""Type stub package for the nss namespace.
|
|
5
5
|
|
|
6
6
|
Provides a package layout (nss/) so static type checkers can resolve
|
|
7
|
-
``nss.nss``, ``nss.ssl`` and ``nss.io`` submodules
|
|
8
|
-
|
|
7
|
+
``nss.nss``, ``nss.ssl`` and ``nss.io`` submodules, plus the
|
|
8
|
+
pure-Python modules installed alongside them. Except for ``error.pyi``,
|
|
9
|
+
the modules are symlinks back into ``src/`` to avoid duplication.
|
|
9
10
|
"""
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
# SPDX-FileCopyrightText: Copyright (c) 2010-2025 python-nss-ng contributors
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Deprecation registry and utilities for python-nss-ng.
|
|
6
|
+
|
|
7
|
+
This module provides a centralized registry of deprecated functionality
|
|
8
|
+
and utilities for emitting deprecation warnings.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import warnings
|
|
12
|
+
from typing import Dict
|
|
13
|
+
|
|
14
|
+
# Central registry of deprecated functionality
|
|
15
|
+
# Key: deprecated symbol name
|
|
16
|
+
# Value: replacement/migration guidance
|
|
17
|
+
DEPRECATED_REGISTRY: Dict[str, str] = {
|
|
18
|
+
"io.NetworkAddress()": (
|
|
19
|
+
"NetworkAddress initialization from a string parameter only works for IPv4. "
|
|
20
|
+
"Use io.AddrInfo instead for proper IPv4/IPv6 support."
|
|
21
|
+
),
|
|
22
|
+
"io.NetworkAddress.set_from_string()": (
|
|
23
|
+
"NetworkAddress.set_from_string() only works for IPv4. "
|
|
24
|
+
"Use io.AddrInfo instead for proper IPv4/IPv6 support."
|
|
25
|
+
),
|
|
26
|
+
"io.NetworkAddress.hostentry": (
|
|
27
|
+
"HostEntry objects only support IPv4. This property will be removed. "
|
|
28
|
+
"Use io.AddrInfo instead for proper IPv4/IPv6 support."
|
|
29
|
+
),
|
|
30
|
+
"io.HostEntry.get_network_addresses()": (
|
|
31
|
+
"Use iteration instead (e.g., 'for net_addr in hostentry'). "
|
|
32
|
+
"The port parameter is not respected; port will be the value when "
|
|
33
|
+
"HostEntry object was created."
|
|
34
|
+
),
|
|
35
|
+
"io.HostEntry.get_network_address()": (
|
|
36
|
+
"Use indexing instead (e.g., 'hostentry[i]'). "
|
|
37
|
+
"The port parameter is not respected; port will be the value when "
|
|
38
|
+
"HostEntry object was created."
|
|
39
|
+
),
|
|
40
|
+
"io.Socket() without family": (
|
|
41
|
+
"Socket initialization without explicit family parameter is deprecated. "
|
|
42
|
+
"The default family parameter of PR_AF_INET is deprecated because when "
|
|
43
|
+
"iterating through NetworkAddress objects returned by AddrInfo, some "
|
|
44
|
+
"addresses may be IPv6. Use the family property of the NetworkAddress "
|
|
45
|
+
"object associated with the socket, e.g., Socket(net_addr.family)."
|
|
46
|
+
),
|
|
47
|
+
"ssl.SSLSocket() without family": (
|
|
48
|
+
"SSLSocket initialization without explicit family parameter is deprecated. "
|
|
49
|
+
"The default family parameter of PR_AF_INET is deprecated because when "
|
|
50
|
+
"iterating through NetworkAddress objects returned by AddrInfo, some "
|
|
51
|
+
"addresses may be IPv6. Use the family property of the NetworkAddress "
|
|
52
|
+
"object associated with the socket, e.g., SSLSocket(net_addr.family)."
|
|
53
|
+
),
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def warn_deprecated(symbol_name: str, alternative: str | None = None, stacklevel: int = 2) -> None:
|
|
58
|
+
"""
|
|
59
|
+
Emit a deprecation warning for a deprecated symbol.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
symbol_name: The name of the deprecated symbol (should be in DEPRECATED_REGISTRY)
|
|
63
|
+
alternative: Optional alternative guidance (overrides registry if provided)
|
|
64
|
+
stacklevel: Stack level for the warning (default: 2, caller of this function)
|
|
65
|
+
"""
|
|
66
|
+
if alternative is None:
|
|
67
|
+
alternative = DEPRECATED_REGISTRY.get(symbol_name, "This functionality is deprecated.")
|
|
68
|
+
|
|
69
|
+
message = f"{symbol_name} is deprecated. {alternative}"
|
|
70
|
+
|
|
71
|
+
warnings.warn(message, category=DeprecationWarning, stacklevel=stacklevel)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def is_deprecated(symbol_name: str) -> bool:
|
|
75
|
+
"""
|
|
76
|
+
Check if a symbol is in the deprecation registry.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
symbol_name: The name of the symbol to check
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
True if the symbol is deprecated, False otherwise
|
|
83
|
+
"""
|
|
84
|
+
return symbol_name in DEPRECATED_REGISTRY
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def get_deprecation_message(symbol_name: str) -> str | None:
|
|
88
|
+
"""
|
|
89
|
+
Get the deprecation message for a symbol.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
symbol_name: The name of the deprecated symbol
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
The deprecation message, or None if the symbol is not deprecated
|
|
96
|
+
"""
|
|
97
|
+
return DEPRECATED_REGISTRY.get(symbol_name)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def list_deprecated() -> Dict[str, str]:
|
|
101
|
+
"""
|
|
102
|
+
Get a copy of the entire deprecation registry.
|
|
103
|
+
|
|
104
|
+
Returns:
|
|
105
|
+
Dictionary mapping deprecated symbols to their deprecation messages
|
|
106
|
+
"""
|
|
107
|
+
return DEPRECATED_REGISTRY.copy()
|
|
@@ -27,7 +27,6 @@ from typing import Any, List, Tuple
|
|
|
27
27
|
# Exception classes
|
|
28
28
|
# ---------------------------------------------------------------------------
|
|
29
29
|
|
|
30
|
-
|
|
31
30
|
class NSPRError(Exception):
|
|
32
31
|
"""Base exception for NSPR / NSS errors.
|
|
33
32
|
|
|
@@ -46,10 +45,8 @@ class NSPRError(Exception):
|
|
|
46
45
|
error_message: str
|
|
47
46
|
|
|
48
47
|
def __init__(self, *args: Any) -> None: ...
|
|
49
|
-
|
|
50
48
|
def __str__(self) -> str: ...
|
|
51
49
|
|
|
52
|
-
|
|
53
50
|
class CertVerifyError(NSPRError):
|
|
54
51
|
"""Exception raised when certificate verification fails.
|
|
55
52
|
|
|
@@ -67,26 +64,22 @@ class CertVerifyError(NSPRError):
|
|
|
67
64
|
|
|
68
65
|
def __init__(self, *args: Any) -> None: ...
|
|
69
66
|
|
|
70
|
-
|
|
71
67
|
# ---------------------------------------------------------------------------
|
|
72
68
|
# Helpers
|
|
73
69
|
# ---------------------------------------------------------------------------
|
|
74
70
|
|
|
75
|
-
|
|
76
71
|
def nspr_error_name(errno: int) -> str:
|
|
77
72
|
"""Return the symbolic name (e.g. ``"PR_END_OF_FILE_ERROR"``)
|
|
78
73
|
associated with ``errno``, or a generic placeholder if the code
|
|
79
74
|
is not recognised by NSPR / NSS."""
|
|
80
75
|
...
|
|
81
76
|
|
|
82
|
-
|
|
83
77
|
def nspr_error_string(errno: int) -> str:
|
|
84
78
|
"""Return the human-readable description string associated with
|
|
85
79
|
``errno``, or a generic placeholder if the code is not recognised
|
|
86
80
|
by NSPR / NSS."""
|
|
87
81
|
...
|
|
88
82
|
|
|
89
|
-
|
|
90
83
|
def lookup_nspr_error(errno: int) -> Tuple[int, str, str] | None:
|
|
91
84
|
"""Look up an NSPR / NSS error code.
|
|
92
85
|
|
|
@@ -95,7 +88,6 @@ def lookup_nspr_error(errno: int) -> Tuple[int, str, str] | None:
|
|
|
95
88
|
"""
|
|
96
89
|
...
|
|
97
90
|
|
|
98
|
-
|
|
99
91
|
# ---------------------------------------------------------------------------
|
|
100
92
|
# Dynamic constants
|
|
101
93
|
# ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
# SPDX-FileCopyrightText: Copyright (c) 2010-2025 python-nss-ng contributors
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
NSS lifecycle context manager for python-nss-ng.
|
|
6
|
+
|
|
7
|
+
This module provides context managers for proper NSS initialization and shutdown,
|
|
8
|
+
helping to avoid common lifecycle management issues.
|
|
9
|
+
|
|
10
|
+
NSS initialization and shutdown rules:
|
|
11
|
+
- nss_init() or nss_init_nodb() should be called exactly once per process
|
|
12
|
+
- nss_shutdown() should be called exactly once per process, not per thread
|
|
13
|
+
- Repeated init/shutdown in high-frequency loops should be avoided
|
|
14
|
+
- All NSS operations must occur after initialization and before shutdown
|
|
15
|
+
|
|
16
|
+
Example usage:
|
|
17
|
+
>>> with NSSContext(db_name='sql:pki'):
|
|
18
|
+
... # NSS is initialized, perform operations
|
|
19
|
+
... cert = nss.find_cert_from_nickname('server_cert')
|
|
20
|
+
... # NSS will be shut down on exit
|
|
21
|
+
|
|
22
|
+
>>> with NSSContext(): # No database
|
|
23
|
+
... # NSS initialized without database
|
|
24
|
+
... digest = nss.sha256_digest(b"data")
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
import contextlib
|
|
28
|
+
import logging
|
|
29
|
+
from collections.abc import Callable, Generator
|
|
30
|
+
from typing import Any
|
|
31
|
+
|
|
32
|
+
# aislop-ignore-file ai-slop/hallucinated-import -- "nss" is this package's own compiled C-extension module (built from py_nss.c)
|
|
33
|
+
|
|
34
|
+
logger = logging.getLogger(__name__)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class NSSContext:
|
|
38
|
+
"""
|
|
39
|
+
Context manager for NSS initialization and shutdown.
|
|
40
|
+
|
|
41
|
+
This ensures proper NSS lifecycle management with automatic cleanup.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
db_name: Path to NSS certificate database (e.g., 'sql:pki').
|
|
45
|
+
If None, NSS is initialized without a database.
|
|
46
|
+
password_callback: Optional password callback function
|
|
47
|
+
flags: Optional NSS initialization flags
|
|
48
|
+
|
|
49
|
+
Example:
|
|
50
|
+
>>> with NSSContext(db_name='sql:pki'):
|
|
51
|
+
... cert = nss.find_cert_from_nickname('my_cert')
|
|
52
|
+
... print(cert.subject)
|
|
53
|
+
|
|
54
|
+
>>> with NSSContext(): # No database
|
|
55
|
+
... data = b"hello world"
|
|
56
|
+
... digest = nss.sha256_digest(data)
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
def __init__(
|
|
60
|
+
self,
|
|
61
|
+
db_name: str | None = None,
|
|
62
|
+
password_callback: Callable[..., Any] | None = None,
|
|
63
|
+
flags: int = 0,
|
|
64
|
+
):
|
|
65
|
+
"""Initialize NSS context manager."""
|
|
66
|
+
self.db_name = db_name
|
|
67
|
+
self.password_callback = password_callback
|
|
68
|
+
self.flags = flags
|
|
69
|
+
self._initialized = False
|
|
70
|
+
|
|
71
|
+
def __enter__(self):
|
|
72
|
+
"""Initialize NSS on context entry."""
|
|
73
|
+
try:
|
|
74
|
+
import nss.nss as nss
|
|
75
|
+
|
|
76
|
+
if self.password_callback:
|
|
77
|
+
nss.set_password_callback(self.password_callback)
|
|
78
|
+
|
|
79
|
+
if self.db_name:
|
|
80
|
+
logger.debug(f"Initializing NSS with database: {self.db_name}")
|
|
81
|
+
nss.nss_init(self.db_name)
|
|
82
|
+
else:
|
|
83
|
+
logger.debug("Initializing NSS without database")
|
|
84
|
+
nss.nss_init_nodb()
|
|
85
|
+
|
|
86
|
+
self._initialized = True
|
|
87
|
+
logger.debug("NSS initialized successfully")
|
|
88
|
+
return self
|
|
89
|
+
|
|
90
|
+
except Exception as e:
|
|
91
|
+
logger.error(f"Failed to initialize NSS: {e}")
|
|
92
|
+
raise
|
|
93
|
+
|
|
94
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
95
|
+
"""Shutdown NSS on context exit."""
|
|
96
|
+
if self._initialized:
|
|
97
|
+
try:
|
|
98
|
+
import nss.nss as nss
|
|
99
|
+
|
|
100
|
+
logger.debug("Shutting down NSS")
|
|
101
|
+
nss.nss_shutdown()
|
|
102
|
+
self._initialized = False
|
|
103
|
+
logger.debug("NSS shutdown complete")
|
|
104
|
+
except Exception as e:
|
|
105
|
+
logger.warning(f"Error during NSS shutdown: {e}")
|
|
106
|
+
# Don't raise - we're already exiting
|
|
107
|
+
|
|
108
|
+
# Return False to propagate any exception that occurred in the with block
|
|
109
|
+
return False
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@contextlib.contextmanager
|
|
113
|
+
def nss_context(
|
|
114
|
+
db_name: str | None = None,
|
|
115
|
+
password_callback: Callable[..., Any] | None = None,
|
|
116
|
+
flags: int = 0,
|
|
117
|
+
) -> Generator[None, None, None]:
|
|
118
|
+
"""
|
|
119
|
+
Functional context manager for NSS lifecycle.
|
|
120
|
+
|
|
121
|
+
This is a functional alternative to the NSSContext class.
|
|
122
|
+
|
|
123
|
+
Args:
|
|
124
|
+
db_name: Path to NSS certificate database or None for no database
|
|
125
|
+
password_callback: Optional password callback function
|
|
126
|
+
flags: Optional NSS initialization flags
|
|
127
|
+
|
|
128
|
+
Yields:
|
|
129
|
+
None - context is active while NSS is initialized
|
|
130
|
+
|
|
131
|
+
Example:
|
|
132
|
+
>>> with nss_context('sql:pki'):
|
|
133
|
+
... # NSS operations here
|
|
134
|
+
... pass
|
|
135
|
+
"""
|
|
136
|
+
context = NSSContext(db_name=db_name, password_callback=password_callback, flags=flags)
|
|
137
|
+
with context:
|
|
138
|
+
yield
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
# SPDX-FileCopyrightText: Copyright (c) 2010-2025 python-nss-ng contributors
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Secure logging utilities for python-nss-ng.
|
|
6
|
+
|
|
7
|
+
This module provides security-conscious logging wrappers that help prevent
|
|
8
|
+
accidental logging of sensitive cryptographic material.
|
|
9
|
+
|
|
10
|
+
The intentional use of both print() and logging in python-nss-ng:
|
|
11
|
+
- print() is used for control flow and status messages in examples to avoid
|
|
12
|
+
accidental capture by log handlers that might leak sensitive information
|
|
13
|
+
- logging is used for diagnostics and errors in library code with careful
|
|
14
|
+
attention to what is logged
|
|
15
|
+
|
|
16
|
+
This module helps enforce these patterns and provides utilities for secure logging.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
import logging
|
|
20
|
+
from collections.abc import Callable
|
|
21
|
+
from enum import Enum
|
|
22
|
+
from typing import Any
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class LogSensitivity(Enum):
|
|
26
|
+
"""Classification of log message sensitivity."""
|
|
27
|
+
|
|
28
|
+
PUBLIC = "public"
|
|
29
|
+
"""Safe for logging - contains no sensitive information."""
|
|
30
|
+
|
|
31
|
+
SENSITIVE = "sensitive"
|
|
32
|
+
"""Contains sensitive information - should not be logged."""
|
|
33
|
+
|
|
34
|
+
REDACTED = "redacted"
|
|
35
|
+
"""Should be logged in redacted form only."""
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# Items that should NEVER be logged
|
|
39
|
+
FORBIDDEN_LOG_PATTERNS = {
|
|
40
|
+
"private key",
|
|
41
|
+
"priv_key",
|
|
42
|
+
"private_key",
|
|
43
|
+
"password",
|
|
44
|
+
"passwd",
|
|
45
|
+
"passphrase",
|
|
46
|
+
"secret",
|
|
47
|
+
"pin",
|
|
48
|
+
"token",
|
|
49
|
+
"key_material",
|
|
50
|
+
"symmetric_key",
|
|
51
|
+
"session_key",
|
|
52
|
+
"master_secret",
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def secure_log(
|
|
57
|
+
logger_fn: Callable[[str], None], message: str, *, sensitive: bool = False, redact: bool = False
|
|
58
|
+
) -> None:
|
|
59
|
+
"""
|
|
60
|
+
Securely log a message with sensitivity awareness.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
logger_fn: The logging function to call (e.g., logger.debug, logger.error)
|
|
64
|
+
message: The message to log
|
|
65
|
+
sensitive: If True, the message will not be logged at all
|
|
66
|
+
redact: If True, attempt to redact sensitive parts of the message
|
|
67
|
+
|
|
68
|
+
Examples:
|
|
69
|
+
>>> logger = logging.getLogger(__name__)
|
|
70
|
+
>>> secure_log(logger.info, "Operation successful", sensitive=False)
|
|
71
|
+
>>> secure_log(logger.debug, "Private key loaded", sensitive=True) # Not logged
|
|
72
|
+
>>> secure_log(logger.info, "Key size: 2048", redact=True)
|
|
73
|
+
"""
|
|
74
|
+
if sensitive:
|
|
75
|
+
# Drop sensitive messages entirely
|
|
76
|
+
return
|
|
77
|
+
|
|
78
|
+
if redact:
|
|
79
|
+
message = redact_message(message)
|
|
80
|
+
|
|
81
|
+
logger_fn(message)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def redact_message(message: str) -> str:
|
|
85
|
+
"""
|
|
86
|
+
Redact potentially sensitive information from a log message.
|
|
87
|
+
|
|
88
|
+
This is a basic implementation that replaces common patterns.
|
|
89
|
+
For production use, consider more sophisticated redaction.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
message: The message to redact
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
The redacted message
|
|
96
|
+
"""
|
|
97
|
+
import re
|
|
98
|
+
|
|
99
|
+
# Redact things that look like base64 encoded data (common for keys)
|
|
100
|
+
# Base64 can end with = or == padding, which hex never has
|
|
101
|
+
# Check for base64 with padding first (= is not a word char, so use lookahead)
|
|
102
|
+
message = re.sub(r"\b[A-Za-z0-9+/]{40,}={1,2}(?!\w)", "[REDACTED_BASE64]", message)
|
|
103
|
+
|
|
104
|
+
# Then check for base64 without padding but with non-hex characters
|
|
105
|
+
# Must contain at least one non-hex character (g-z, G-Z, +, /) to distinguish from hex
|
|
106
|
+
message = re.sub(r"\b(?=.*[g-zG-Z+/])[A-Za-z0-9+/]{40,}\b", "[REDACTED_BASE64]", message)
|
|
107
|
+
|
|
108
|
+
# Redact things that look like hex keys (long hex strings - only 0-9a-fA-F)
|
|
109
|
+
# Must have at least 32 characters and ONLY hex characters
|
|
110
|
+
message = re.sub(r"\b[0-9a-fA-F]{32,}\b", "[REDACTED_HEX]", message)
|
|
111
|
+
|
|
112
|
+
# Redact password-like patterns
|
|
113
|
+
return re.sub(
|
|
114
|
+
r"(password|passwd|pwd|pin)\s*[:=]\s*\S+", r"\1: [REDACTED]", message, flags=re.IGNORECASE
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def check_message_safety(message: str) -> LogSensitivity:
|
|
119
|
+
"""
|
|
120
|
+
Check if a message appears to contain sensitive information.
|
|
121
|
+
|
|
122
|
+
Args:
|
|
123
|
+
message: The message to check
|
|
124
|
+
|
|
125
|
+
Returns:
|
|
126
|
+
LogSensitivity classification
|
|
127
|
+
"""
|
|
128
|
+
message_lower = message.lower()
|
|
129
|
+
|
|
130
|
+
for pattern in FORBIDDEN_LOG_PATTERNS:
|
|
131
|
+
if pattern in message_lower:
|
|
132
|
+
return LogSensitivity.SENSITIVE
|
|
133
|
+
|
|
134
|
+
# Check for long base64 strings (likely encoded keys)
|
|
135
|
+
# Base64 can end with = or == padding, which hex never has
|
|
136
|
+
import re
|
|
137
|
+
|
|
138
|
+
if re.search(r"\b[A-Za-z0-9+/]{40,}={1,2}(?!\w)", message):
|
|
139
|
+
return LogSensitivity.REDACTED
|
|
140
|
+
|
|
141
|
+
# Base64 without padding but with non-hex characters
|
|
142
|
+
if re.search(r"\b(?=.*[g-zG-Z+/])[A-Za-z0-9+/]{40,}\b", message):
|
|
143
|
+
return LogSensitivity.REDACTED
|
|
144
|
+
|
|
145
|
+
# Check for long hex strings (likely keys)
|
|
146
|
+
if re.search(r"\b[0-9a-fA-F]{32,}\b", message):
|
|
147
|
+
return LogSensitivity.REDACTED
|
|
148
|
+
|
|
149
|
+
return LogSensitivity.PUBLIC
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
class SecureLogger:
|
|
153
|
+
"""
|
|
154
|
+
A wrapper around Python's logging.Logger that enforces secure logging practices.
|
|
155
|
+
|
|
156
|
+
This logger automatically checks messages for sensitive content and handles
|
|
157
|
+
them appropriately based on configuration.
|
|
158
|
+
|
|
159
|
+
Example:
|
|
160
|
+
>>> import logging
|
|
161
|
+
>>> base_logger = logging.getLogger(__name__)
|
|
162
|
+
>>> secure = SecureLogger(base_logger)
|
|
163
|
+
>>> secure.info("Certificate loaded successfully")
|
|
164
|
+
>>> secure.debug("Processing key data", sensitive=True) # Not logged
|
|
165
|
+
"""
|
|
166
|
+
|
|
167
|
+
def __init__(self, logger: logging.Logger, auto_redact: bool = True, strict: bool = False):
|
|
168
|
+
"""
|
|
169
|
+
Initialize SecureLogger.
|
|
170
|
+
|
|
171
|
+
Args:
|
|
172
|
+
logger: The underlying Python logger to wrap
|
|
173
|
+
auto_redact: If True, automatically redact suspicious content
|
|
174
|
+
strict: If True, raise exception on attempt to log sensitive data
|
|
175
|
+
"""
|
|
176
|
+
self.logger = logger
|
|
177
|
+
self.auto_redact = auto_redact
|
|
178
|
+
self.strict = strict
|
|
179
|
+
|
|
180
|
+
def _log(
|
|
181
|
+
self, level: int, message: str, sensitive: bool = False, *args: Any, **kwargs: Any
|
|
182
|
+
) -> None:
|
|
183
|
+
"""Internal logging method with sensitivity checks."""
|
|
184
|
+
if sensitive:
|
|
185
|
+
if self.strict:
|
|
186
|
+
raise ValueError(f"Attempt to log sensitive data: {message[:50]}...")
|
|
187
|
+
return
|
|
188
|
+
|
|
189
|
+
# Automatic sensitivity detection
|
|
190
|
+
if self.auto_redact:
|
|
191
|
+
sensitivity = check_message_safety(message)
|
|
192
|
+
if sensitivity == LogSensitivity.SENSITIVE:
|
|
193
|
+
if self.strict:
|
|
194
|
+
raise ValueError(f"Potentially sensitive data detected: {message[:50]}...")
|
|
195
|
+
return
|
|
196
|
+
if sensitivity == LogSensitivity.REDACTED:
|
|
197
|
+
message = redact_message(message)
|
|
198
|
+
|
|
199
|
+
self.logger.log(level, message, *args, **kwargs)
|
|
200
|
+
|
|
201
|
+
def debug(self, message: str, sensitive: bool = False, *args: Any, **kwargs: Any) -> None:
|
|
202
|
+
"""Log a debug message."""
|
|
203
|
+
self._log(logging.DEBUG, message, sensitive, *args, **kwargs)
|
|
204
|
+
|
|
205
|
+
def info(self, message: str, sensitive: bool = False, *args: Any, **kwargs: Any) -> None:
|
|
206
|
+
"""Log an info message."""
|
|
207
|
+
self._log(logging.INFO, message, sensitive, *args, **kwargs)
|
|
208
|
+
|
|
209
|
+
def warning(self, message: str, sensitive: bool = False, *args: Any, **kwargs: Any) -> None:
|
|
210
|
+
"""Log a warning message."""
|
|
211
|
+
self._log(logging.WARNING, message, sensitive, *args, **kwargs)
|
|
212
|
+
|
|
213
|
+
def error(self, message: str, sensitive: bool = False, *args: Any, **kwargs: Any) -> None:
|
|
214
|
+
"""Log an error message."""
|
|
215
|
+
self._log(logging.ERROR, message, sensitive, *args, **kwargs)
|
|
216
|
+
|
|
217
|
+
def critical(self, message: str, sensitive: bool = False, *args: Any, **kwargs: Any) -> None:
|
|
218
|
+
"""Log a critical message."""
|
|
219
|
+
self._log(logging.CRITICAL, message, sensitive, *args, **kwargs)
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def get_secure_logger(name: str, auto_redact: bool = True, strict: bool = False) -> SecureLogger:
|
|
223
|
+
"""
|
|
224
|
+
Get a SecureLogger instance.
|
|
225
|
+
|
|
226
|
+
Args:
|
|
227
|
+
name: Logger name (typically __name__)
|
|
228
|
+
auto_redact: Enable automatic redaction
|
|
229
|
+
strict: Enable strict mode (raises exceptions on sensitive data)
|
|
230
|
+
|
|
231
|
+
Returns:
|
|
232
|
+
A SecureLogger instance
|
|
233
|
+
"""
|
|
234
|
+
base_logger = logging.getLogger(name)
|
|
235
|
+
return SecureLogger(base_logger, auto_redact=auto_redact, strict=strict)
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def log_exception_safely(
|
|
239
|
+
logger_fn: Callable[[str], None],
|
|
240
|
+
exc: Exception,
|
|
241
|
+
context: str = "",
|
|
242
|
+
*,
|
|
243
|
+
include_traceback: bool = False,
|
|
244
|
+
) -> None:
|
|
245
|
+
"""
|
|
246
|
+
Log an exception in a secure manner, avoiding sensitive data leakage.
|
|
247
|
+
|
|
248
|
+
This function logs exception information while being careful not to
|
|
249
|
+
expose sensitive data that might be in exception messages (e.g.,
|
|
250
|
+
file paths containing key material, connection strings with passwords).
|
|
251
|
+
|
|
252
|
+
Args:
|
|
253
|
+
logger_fn: The logging function to call (e.g., logger.error)
|
|
254
|
+
exc: The exception to log
|
|
255
|
+
context: Additional context about where the exception occurred
|
|
256
|
+
include_traceback: If True, include limited traceback info
|
|
257
|
+
|
|
258
|
+
Example:
|
|
259
|
+
>>> try:
|
|
260
|
+
... nss.nss_init("invalid_path")
|
|
261
|
+
... except Exception as e:
|
|
262
|
+
... log_exception_safely(logger.error, e, "NSS initialization")
|
|
263
|
+
"""
|
|
264
|
+
exc_type = type(exc).__name__
|
|
265
|
+
exc_message = str(exc)
|
|
266
|
+
|
|
267
|
+
# Check if exception message appears sensitive
|
|
268
|
+
sensitivity = check_message_safety(exc_message)
|
|
269
|
+
|
|
270
|
+
if sensitivity == LogSensitivity.SENSITIVE:
|
|
271
|
+
# Log only the exception type and context
|
|
272
|
+
msg = f"{context}: {exc_type} occurred (details redacted for security)"
|
|
273
|
+
elif sensitivity == LogSensitivity.REDACTED:
|
|
274
|
+
msg = f"{context}: {exc_type}: {redact_message(exc_message)}"
|
|
275
|
+
else:
|
|
276
|
+
# Safe to log
|
|
277
|
+
msg = f"{context}: {exc_type}: {exc_message}" if context else f"{exc_type}: {exc_message}"
|
|
278
|
+
|
|
279
|
+
logger_fn(msg)
|
|
280
|
+
|
|
281
|
+
if include_traceback:
|
|
282
|
+
# Only include limited traceback info, not full stack
|
|
283
|
+
import traceback
|
|
284
|
+
|
|
285
|
+
tb_lines = traceback.format_tb(exc.__traceback__, limit=3)
|
|
286
|
+
# Redact each line of traceback
|
|
287
|
+
for line in tb_lines:
|
|
288
|
+
logger_fn(f" {redact_message(line.strip())}")
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
class SecureExceptionHandler:
|
|
292
|
+
"""
|
|
293
|
+
Context manager for secure exception handling with logging.
|
|
294
|
+
|
|
295
|
+
Use this to wrap code blocks where you want automatic secure
|
|
296
|
+
exception logging without exposing sensitive information.
|
|
297
|
+
|
|
298
|
+
Example:
|
|
299
|
+
>>> logger = logging.getLogger(__name__)
|
|
300
|
+
>>> with SecureExceptionHandler(logger, "Certificate loading"):
|
|
301
|
+
... cert = nss.Certificate(certdata)
|
|
302
|
+
"""
|
|
303
|
+
|
|
304
|
+
def __init__(
|
|
305
|
+
self,
|
|
306
|
+
logger: logging.Logger,
|
|
307
|
+
context: str,
|
|
308
|
+
reraise: bool = True,
|
|
309
|
+
log_level: int = logging.ERROR,
|
|
310
|
+
):
|
|
311
|
+
"""
|
|
312
|
+
Initialize the exception handler.
|
|
313
|
+
|
|
314
|
+
Args:
|
|
315
|
+
logger: Logger to use for exception logging
|
|
316
|
+
context: Context description for the operation
|
|
317
|
+
reraise: If True, re-raise the exception after logging
|
|
318
|
+
log_level: Logging level to use (default: ERROR)
|
|
319
|
+
"""
|
|
320
|
+
self.logger = logger
|
|
321
|
+
self.context = context
|
|
322
|
+
self.reraise = reraise
|
|
323
|
+
self.log_level = log_level
|
|
324
|
+
|
|
325
|
+
def __enter__(self):
|
|
326
|
+
return self
|
|
327
|
+
|
|
328
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
329
|
+
if exc_type is not None:
|
|
330
|
+
|
|
331
|
+
def logger_fn(msg: str) -> None:
|
|
332
|
+
self.logger.log(self.log_level, msg)
|
|
333
|
+
|
|
334
|
+
log_exception_safely(logger_fn, exc_val, self.context)
|
|
335
|
+
|
|
336
|
+
return not self.reraise
|
|
337
|
+
return None
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
# Example usage patterns
|
|
341
|
+
if __name__ == "__main__":
|
|
342
|
+
logging.basicConfig(level=logging.DEBUG)
|
|
343
|
+
|
|
344
|
+
logger = get_secure_logger(__name__)
|
|
345
|
+
|
|
346
|
+
# Safe logging
|
|
347
|
+
logger.info("Certificate validation successful")
|
|
348
|
+
logger.debug("Key size: 2048 bits")
|
|
349
|
+
|
|
350
|
+
# Sensitive data - not logged
|
|
351
|
+
logger.debug("Private key: ABC123...", sensitive=True)
|
|
352
|
+
|
|
353
|
+
# Auto-redacted
|
|
354
|
+
logger.info("Token value: 1234567890abcdef1234567890abcdef1234567890abcdef")
|
|
355
|
+
|
|
356
|
+
# Exception logging examples
|
|
357
|
+
try:
|
|
358
|
+
raise ValueError("Database path: /secret/path/to/keydb contains sensitive info")
|
|
359
|
+
except ValueError as e:
|
|
360
|
+
log_exception_safely(logger.error, e, "Test exception")
|
|
361
|
+
|
|
362
|
+
# Context manager example
|
|
363
|
+
base_logger = logging.getLogger("test")
|
|
364
|
+
with SecureExceptionHandler(base_logger, "Demo operation", reraise=False):
|
|
365
|
+
raise RuntimeError("password=secret123")
|
|
366
|
+
|
|
367
|
+
print("\nSecure logging examples completed.")
|
python_nss_ng-1.3.2/_version.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
1.3.2
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"include": [
|
|
3
|
-
"src",
|
|
4
|
-
"test",
|
|
5
|
-
"scripts"
|
|
6
|
-
],
|
|
7
|
-
"exclude": [
|
|
8
|
-
"**/node_modules",
|
|
9
|
-
"**/__pycache__",
|
|
10
|
-
"**/.*",
|
|
11
|
-
"build",
|
|
12
|
-
"dist",
|
|
13
|
-
".eggs",
|
|
14
|
-
"*.egg-info",
|
|
15
|
-
"mutants"
|
|
16
|
-
],
|
|
17
|
-
"stubPath": "typings",
|
|
18
|
-
"venvPath": ".",
|
|
19
|
-
"venv": ".venv",
|
|
20
|
-
"pythonVersion": "3.10",
|
|
21
|
-
"pythonPlatform": "All",
|
|
22
|
-
"typeCheckingMode": "basic",
|
|
23
|
-
"useLibraryCodeForTypes": true,
|
|
24
|
-
"reportMissingImports": "warning",
|
|
25
|
-
"reportMissingModuleSource": "none",
|
|
26
|
-
"reportMissingTypeStubs": "none",
|
|
27
|
-
"reportPrivateUsage": "none",
|
|
28
|
-
"reportUnknownMemberType": "none",
|
|
29
|
-
"reportUnknownArgumentType": "none",
|
|
30
|
-
"reportUnknownVariableType": "none",
|
|
31
|
-
"reportUnknownParameterType": "none",
|
|
32
|
-
"reportUntypedFunctionDecorator": "none",
|
|
33
|
-
"reportUntypedClassDecorator": "none",
|
|
34
|
-
"reportUntypedBaseClass": "none",
|
|
35
|
-
"reportGeneralTypeIssues": "warning",
|
|
36
|
-
"reportOptionalMemberAccess": "warning",
|
|
37
|
-
"reportOptionalSubscript": "warning",
|
|
38
|
-
|
|
39
|
-
"executionEnvironments": [
|
|
40
|
-
{
|
|
41
|
-
"root": "src",
|
|
42
|
-
"pythonVersion": "3.10",
|
|
43
|
-
"extraPaths": [
|
|
44
|
-
"src"
|
|
45
|
-
]
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
"root": "test",
|
|
49
|
-
"pythonVersion": "3.10",
|
|
50
|
-
"extraPaths": [
|
|
51
|
-
"src"
|
|
52
|
-
]
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
"root": "scripts",
|
|
56
|
-
"pythonVersion": "3.10"
|
|
57
|
-
}
|
|
58
|
-
]
|
|
59
|
-
}
|
|
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
|
|
File without changes
|
|
File without changes
|