The ssl module now rejects TLS certificate chains that contain any of a set of
compromised eMudhra intermediate CA keys. This is an extraordinary measure and
a last line of defense: removing trust is primarily the job of the platform root
store, and the built-in denylist only blocks connections while that update has
not yet reached the OS, a container image, or a bundled trust store in various
Python packages. Entries are added to the denylist only under a very high
threshold.
The denylist matches on the public key (the SHA-256 digest of the RFC-5280
SubjectPublicKeyInfo), so it also covers the cross-signed certificates that
reuse one of the distrusted keys.
---------
Signed-off-by: Christian Heimes <christian@python.org>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Include the client's certificate when the session was resumed from a
ticket, and return [] instead of raising AttributeError when the client
sent no certificate.
ANT-2026-2RMA0IPV
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Free decoded subject alternative names when certificate conversion
fails, and close the key log file if the BIO allocation fails.
Backport to 3.15 and 3.14.
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
ssl.OPENSSL_VERSION_INFO is now a named tuple.
Add ssl.OPENSSL_API_VERSION_INFO which provides information about the
version of the OpenSSL library that was used for building the module.
The private name _OPENSSL_API_VERSION is kept as an alias.
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
The value of a @setter is now a parameter, which can use a converter,
and a @getter can define a return converter. Declaring the value is
optional.
The accessors of an attribute are now collected in a Property, so the
entry of PyGetSetDef is identified by the Python name instead of the C
basename, and is composed without the help of the preprocessor unless
some accessor is compiled conditionally.
Replace soft deprecated PyBytes_FromStringAndSize() with
PyBytesWriter.
Remove 'pseudo' parameter of PySSL_RAND(): it's no longer needed since
ssl.RAND_pseudo_bytes() has been removed (in 2022,
commit d435a18c53).
Add a test on ssl.RAND_bytes(0).
On GCC and clang, implement Py_MIN(), Py_MAX() and Py_ABS()
using typeof() and statement expression to only evaluate each
argument once and detect signed/unsigned comparison.
Test also these macros in test_cext and test_cppext to test different
compiler flags and test the limited C API.
The pid_t, Py_off_t, HANDLE, DWORD and BOOL converters were defined in
9 files. The Py_off_t type and its converter function are now shared too.
DWORD in _winapi is used with bitwise=True to keep accepting negative
values.
The pid_t converter is now used for the pid parameters in the
_remote_debugging module, which were declared as int.
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
LibreSSL does not provide SSL_CTX_set1_sigalgs_list() or
SSL_CTX_set1_client_sigalgs_list(), added in gh-138252, so _ssl failed to
compile against LibreSSL on 3.15+. Guard the set_server_sigalgs() and
set_client_sigalgs() methods so they raise NotImplementedError on LibreSSL,
and skip the corresponding tests.
The _SSLSocket object now remembers if it gets an EOF error. In this
case, read(), sendfile(), write() and do_handshake method calls fail
with SSLEOFError without calling the underlying OpenSSL function.
Co-authored-by: Gregory P. Smith <greg@krypto.org>
The Modules/_ssl_data_40.h file was created with the commands:
python Tools/ssl/multissltests.py --steps=library --base-directory "$PWD/multissl" --openssl '4.0.0' --system Linux
python Tools/ssl/make_ssl_data.py multissl/src/openssl-4.0.0 Modules/_ssl_data_40.h
Update Modules/_ssl.c to include it on OpenSSL 4.0.0 and newer.
Update test_ssl for the new error message.
Rename from _Py_INTERNAL_ABI_SLOT to _Py_ABI_SLOT
and define the macro using _PyABIInfo_DEFAULT.
Use the ABI slot in stdlib extension modules to enable running
a check of ABI version compatibility.
_tkinter, _tracemalloc and readline don't use the slots, hence they need
explicit handling.
Co-authored-by: Victor Stinner <vstinner@python.org>
In newPySSLSocket(), when SSL_new() returns NULL, Py_DECREF(self)
was called before _setSSLError(get_state_ctx(self), ...), causing
a use-after-free. Additionally, get_state_ctx() was called with
self (PySSLSocket*) instead of sslctx (PySSLContext*), which is
a type confusion bug.
Fix by calling _setSSLError() before Py_DECREF() and using
sslctx instead of self for get_state_ctx().
When user tries to load a certificate chain, attach the related
filename to the exception being raised. Improving user experience.
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
The 'exc' field was used by our debug SSL callbacks. Keep the exception
in the normal per-thread state to avoid shared mutable state between
threads.
This also avoids a reference count leak if the Python callback raised an
exception because it can be called multiple times per SSL operation.
The signature algorithms allowed for certificate-based client authentication or
for the server to complete the TLS handshake can be defined on a SSL context via
`ctx.set_client_sigalgs()` and `ctx.set_server_sigalgs()`.
With OpenSSL 3.4 or later, the list of available TLS algorithms can be retrieved
by `ssl.get_sigalgs()`.
With OpenSSL 3.5 or later, the selected signature algorithms can be retrieved from
SSL sockets via `socket.client_sigalg()` and `socket.server_sigalg()`.
This commit also partially amends 377b787618
by using `PyUnicode_DecodeFSDefault` instead of `PyUnicode_DecodeASCII` in
`_ssl._SSLContext.get_groups`, so that functions consistently decode strings
obtained from OpenSSL.
---------
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
* Add OpenSSL 3.5.2 definitions to Modules/_ssl_data_35.h (moved from Modules/_ssl_data_34.h)
* Demote OpenSSL 3.1 to "old", remove it from CI
* Update all OpenSSL versions to latest patchlevel in CI config and multissltests defaults
* Add OpenSSL 3.5.2 to CI configuration and multissltests default list
* Fix a typo in the argument parser description of multissltests.py
Add support for getting and setting groups used for key agreement.
* `ssl.SSLSocket.group()` returns the name of the group used
for the key agreement of the current session establishment.
This feature requires Python to be built with OpenSSL 3.2 or later.
* `ssl.SSLContext.get_groups()` returns the list of names of groups
that are compatible with the TLS version of the current context.
This feature requires Python to be built with OpenSSL 3.5 or later.
* `ssl.SSLContext.set_groups()` sets the groups allowed for key agreement
for sockets created with this context. This feature is always supported.
Replace most PyUnicodeWriter_WriteUTF8() calls with
PyUnicodeWriter_WriteASCII().
Unrelated change to please the linter: remove an unused
import in test_ctypes.
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>