summaryrefslogtreecommitdiffstats
path: root/Modules/_ssl.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-131423: Update to OpenSSL 3.0.16. (GH-131839)Steve Dower2025-03-281-0/+6
| | | | | The bin tag is 3.0.16.1 because we rebuilt without uplink support to fix gh-131804. This PR also prevents making calls that are now unsafe without uplink, and updates the tests to property interpret these failures as unsupported.
* [3.13] gh-127257: ssl: Raise OSError for ERR_LIB_SYS (GH-127361) (GH-127812)Miss Islington (bot)2024-12-121-0/+10
| | | | | | | | | | | | | | | | | | | gh-127257: ssl: Raise OSError for ERR_LIB_SYS (GH-127361) From the ERR_raise manpage: ERR_LIB_SYS This "library code" indicates that a system error is being reported. In this case, the reason code given to `ERR_raise()` and `ERR_raise_data()` *must* be `errno(3)`. This PR only handles ERR_LIB_SYS for the high-lever error types SSL_ERROR_SYSCALL and SSL_ERROR_SSL, i.e., not the ones where OpenSSL indicates it has some more information about the issue. (cherry picked from commit f4b31edf2d9d72878dab1f66a36913b5bcc848ec) Co-authored-by: Petr Viktorin <encukou@gmail.com>
* [3.13] gh-126890: Restore stripped `ssl` docstrings (GH-127281) (#127513)Peter Bierma2024-12-021-13/+50
| | | | | (cherry picked from commit c112de1da2d18e3b5c2ea30b0e409f18e574efd8) Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
* [3.13] gh-124984: Enhance `ssl` thread safety (GH-124993) (#125780)Peter Bierma2024-12-021-225/+460
| | | | | | | | | Make SSL objects thread safe in Free Theaded build by using critical sections. (cherry picked from commit 4c53b2577531c77193430cdcd66ad6385fcda81f) Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
* [3.13] gh-126433: Fix compiler warnings on 32-bit Windows (#126444) (#126827)Victor Stinner2024-11-141-2/+4
| | | | | gh-126433: Fix compiler warnings on 32-bit Windows (#126444) (cherry picked from commit 0b67ce930a56c4ffd597b1a658ddcbacfb40e798)
* [3.13] gh-126455: Disallow _ssl.SSLSocket instantiation (GH-126481) (#126486)Miss Islington (bot)2024-11-061-1/+1
| | | | | | | | | gh-126455: Disallow _ssl.SSLSocket instantiation (GH-126481) Prevent creation of incomplete/invalid _ssl.SSLSocket objects when created directly. (cherry picked from commit b1c4ffc20573befb4db66bbbdd569b9bd13bb127) Co-authored-by: Victor Stinner <vstinner@python.org>
* [3.13] gh-126106: Fix `NULL` possible derefrence in `Modules/_ssl.c` ↵Miss Islington (bot)2024-10-291-3/+3
| | | | | | | | | (GH-126111) (#126116) gh-126106: Fix `NULL` possible derefrence in `Modules/_ssl.c` (GH-126111) (cherry picked from commit a64a1c920660b0c1e4dd5a9573004cd527e15184) Co-authored-by: sobolevn <mail@sobolevn.me> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
* [3.13] gh-116810: fix memory leak in ssl module (GH-123249) (#124800)Miss Islington (bot)2024-10-071-63/+13
| | | | | | | | | | | | | gh-116810: fix memory leak in ssl module (GH-123249) Resolve a memory leak introduced in CPython 3.10's :mod:`ssl` when the :attr:`ssl.SSLSocket.session` property was accessed. Speeds up read and write access to said property by no longer unnecessarily cloning session objects via serialization. (cherry picked from commit 7e7223e18f58ec48fb36a68fb75b5c5b7a45042a) Co-authored-by: Jeffrey R. Van Voorst <jeff.vanvoorst@gmail.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Gregory P. Smith <greg@krypto.org> Co-authored-by: Antoine Pitrou <antoine@python.org>
* gh-116322: Add Py_mod_gil module slot (#116882)Brett Simmers2024-05-031-0/+1
| | | | | | | | | | | | | | This PR adds the ability to enable the GIL if it was disabled at interpreter startup, and modifies the multi-phase module initialization path to enable the GIL when loading a module, unless that module's spec includes a slot indicating it can run safely without the GIL. PEP 703 called the constant for the slot `Py_mod_gil_not_used`; I went with `Py_MOD_GIL_NOT_USED` for consistency with gh-104148. A warning will be issued up to once per interpreter for the first GIL-using module that is loaded. If `-v` is given, a shorter message will be printed to stderr every time a GIL-using module is loaded (including the first one that issues a warning).
* gh-101732: Modules/_ssl.c: use Y2038 compatible openssl function when ↵Alexander Kanavin2024-05-031-0/+4
| | | | available (GH-118425)
* gh-111926: Make weakrefs thread-safe in free-threaded builds (#117168)mpage2024-04-081-7/+6
| | | | | | | | | Most mutable data is protected by a striped lock that is keyed on the referenced object's address. The weakref's hash is protected using the weakref's per-object lock. Note that this only affects free-threaded builds. Apart from some minor refactoring, the added code is all either gated by `ifdef`s or is a no-op (e.g. `Py_BEGIN_CRITICAL_SECTION`).
* gh-117310: Remove extra DECREF on "no ciphers" error path in ↵Gregory P. Smith2024-03-281-1/+0
| | | | | | | | | | `_ssl._SSLContext` constructor (#117309) Remove extra self DECREF on ssl "no ciphers" error path. This doesn't come up in practice because nobody links against a broken OpenSSL library that provides nothing.
* gh-115627: Fix PySSL_SetError handling SSL_ERROR_SYSCALL (GH-115628)yevgeny hong2024-03-261-30/+18
| | | | | | | | | | | | | | | | | Python 3.10 changed from using SSL_write() and SSL_read() to SSL_write_ex() and SSL_read_ex(), but did not update handling of the return value. Change error handling so that the return value is not examined. OSError (not EOF) is now returned when retval is 0. According to *recent* man pages of all functions for which we call PySSL_SetError, (in OpenSSL 3.0 and 1.1.1), their return value should be used to determine whether an error happened (i.e. if PySSL_SetError should be called), but not what kind of error happened (so, PySSL_SetError shouldn't need retval). To get the error, we need to use SSL_get_error. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Petr Viktorin <encukou@gmail.com>
* gh-110850: Cleanup pycore_time.h includes (#115724)Victor Stinner2024-02-201-0/+1
| | | | | <pycore_time.h> include is no longer needed to get the PyTime_t type in internal header files. This type is now provided by <Python.h> include. Add <pycore_time.h> includes to C files instead.
* gh-110850: Replace _PyTime_t with PyTime_t (#115719)Victor Stinner2024-02-201-7/+7
| | | | | Run command: sed -i -e 's!\<_PyTime_t\>!PyTime_t!g' $(find -name "*.c" -o -name "*.h")
* gh-114572: Fix locking in cert_store_stats and get_ca_certs (#114573)David Benjamin2024-02-161-5/+60
| | | | | | | | | | | | | | | | | * gh-114572: Fix locking in cert_store_stats and get_ca_certs cert_store_stats and get_ca_certs query the SSLContext's X509_STORE with X509_STORE_get0_objects, but reading the result requires a lock. See https://github.com/openssl/openssl/pull/23224 for details. Instead, use X509_STORE_get1_objects, newly added in that PR. X509_STORE_get1_objects does not exist in current OpenSSLs, but we can polyfill it with X509_STORE_lock and X509_STORE_unlock. * Work around const-correctness problem * Add missing X509_STORE_get1_objects failure check * Add blurb
* gh-89532: Remove LibreSSL workarounds (#28728)Rami2024-01-061-3/+3
| | | | | | Remove LibreSSL specific workaround ifdefs from `_ssl.c` and delete the non-version-specific `_ssl_data.h` file (relevant for OpenSSL < 1.1.1, which we no longer support per PEP 644). Co-authored-by: Christian Heimes <christian@python.org> Co-authored-by: Gregory P. Smith <greg@krypto.org>
* gh-113332: Simplify calls to SSL_(CTX_)set_verify in _ssl.c (#113333)David Benjamin2023-12-261-7/+2
| | | | _ssl.c currently tries to preserve the verification callback, but at no point does it ever set one. Just pass in NULL.
* gh-112454: Disable TLS-PSK if OpenSSL was built without PSK support (#112491)Grant Ramsay2023-11-291-0/+28
| | | | | | If OpenSSL was built without PSK support, the python TLS-PSK methods will raise "NotImplementedError" if called. Add a constant "ssl.HAS_PSK" to check if TLS-PSK is supported
* gh-63284: Add support for TLS-PSK (pre-shared key) to the ssl module (#103181)Grant Ramsay2023-11-271-0/+224
| | | | | | | | Add support for TLS-PSK (pre-shared key) to the ssl module. --------- Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net> Co-authored-by: Gregory P. Smith <greg@krypto.org>
* gh-111230: Fix errors checking in _ssl module init (#111232)Nikita Sobolev2023-10-251-82/+71
| | | Introduce ADD_INT_CONST macro wrapper for PyModule_AddIntConstant()
* gh-67565: Remove redundant C-contiguity checks (GH-105521)Furkan Onder2023-10-231-1/+2
| | | | Co-authored-by: Stefan Krah <skrah@bytereef.org>
* gh-106320: Remove private _PyErr_ChainExceptions() (#108713)Victor Stinner2023-08-311-0/+1
| | | | | | | | | | | | | Remove _PyErr_ChainExceptions(), _PyErr_ChainExceptions1() and _PyErr_SetFromPyStatus() functions from the public C API. * Move the private _PyErr_ChainExceptions() and _PyErr_ChainExceptions1() function to the internal C API (pycore_pyerrors.h). * Move the private _PyErr_SetFromPyStatus() to the internal C API (pycore_initconfig.h). * No longer export the _PyErr_ChainExceptions() function. * Move run_in_subinterp_with_config() from _testcapi to _testinternalcapi.
* gh-107913: Fix possible losses of OSError error codes (GH-107930)Serhiy Storchaka2023-08-261-4/+4
| | | | | | Functions like PyErr_SetFromErrno() and SetFromWindowsErr() should be called immediately after using the C API which sets errno or the Windows error code.
* gh-107077: Raise SSLCertVerificationError even if the error is set via ↵Pablo Galindo Salgado2023-08-031-0/+4
| | | | | | SSL_ERROR_SYSCALL (#107586) Co-authored-by: T. Wouters <thomas@python.org>
* gh-86493: Modernize modules initialization code (GH-106858)Serhiy Storchaka2023-07-251-1/+1
| | | | | Use PyModule_Add() or PyModule_AddObjectRef() instead of soft deprecated PyModule_AddObject().
* gh-106320: Remove _PyIsSelectable_fd() C API (#107142)Victor Stinner2023-07-231-0/+1
| | | | Move _PyIsSelectable_fd() macro to the internal C API (pycore_fileutils.h).
* gh-86493: Use PyModule_Add() instead of PyModule_AddObjectRef() (GH-106860)Serhiy Storchaka2023-07-181-7/+1
|
* gh-86493: Fix possible leaks in some modules initialization (GH-106768)Serhiy Storchaka2023-07-181-4/+4
| | | | Fix _ssl, _stat, _testinternalcapi, _threadmodule, cmath, math, posix, time.
* gh-106831: Fix NULL check of d2i_SSL_SESSION() result in _ssl.c (#106832)Nikita Sobolev2023-07-171-3/+4
|
* gh-106687: _ssl: use uint64_t for SSL options (#106700)Victor Stinner2023-07-171-26/+54
| | | | | | | | SSL_CTX_get_options() uses uint64_t for options: https://www.openssl.org/docs/man3.1/man3/SSL_CTX_get_options.html Fix this compiler warning on Windows with MSC: conversion from 'uint64_t' to 'long', possible loss of data
* gh-105293: Do not call SSL_CTX_set_session_id_context on client side SSL ↵Grant Ramsay2023-07-141-5/+9
| | | | | | | | | | context (#105295) * gh-105293: Do not call SSL_CTX_set_session_id_context on client side SSL context Openssl states this is a "server side only" operation. Calling this on a client side socket can result in unexpected behavior * Add news entry on SSL "set session id context" changes
* gh-104922: remove PY_SSIZE_T_CLEAN (#106315)Inada Naoki2023-07-021-2/+0
|
* gh-105927: _ssl GET_SOCKET() uses _PyWeakref_GET_REF() (#106002)Victor Stinner2023-06-231-2/+12
|
* gh-105927: _ssl uses _PyWeakref_GET_REF() (#105965)Victor Stinner2023-06-211-13/+24
|
* gh-105375: Harden _ssl initialisation (#105599)Erlend E. Aasland2023-06-111-5/+11
| | | | Add proper error handling to prevent reference leaks and overwritten exceptions.
* gh-103142: Upgrade binary builds and CI to OpenSSL 1.1.1u (#105174)Gregory P. Smith2023-06-011-1/+3
| | | | | | | | | | | | | Upgrade builds to OpenSSL 1.1.1u. This OpenSSL version addresses a pile if less-urgent CVEs since 1.1.1t. The Mac/BuildScript/build-installer.py was already updated. Also updates _ssl_data_111.h from OpenSSL 1.1.1u, _ssl_data_300.h from 3.0.9, and adds a new _ssl_data_31.h file from 3.1.1 along with the ssl.c code to use it. Manual edits to the _ssl_data_300.h file prevent it from removing any existing definitions in case those exist in some peoples builds and were important (avoiding regressions during backporting). backports of this prior to 3.12 will not include the openssl 3.1 header.
* GH-103092: isolate `_ssl` (#104725)Kumar Aditya2023-05-221-3/+16
|
* gh-98836: Extend PyUnicode_FromFormat() (GH-98838)Serhiy Storchaka2023-05-211-4/+1
| | | | | | | | | * Support for conversion specifiers o (octal) and X (uppercase hexadecimal). * Support for length modifiers j (intmax_t) and t (ptrdiff_t). * Length modifiers are now applied to all integer conversions. * Support for wchar_t C strings (%ls and %lV). * Support for variable width and precision (*). * Support for flag - (left alignment).
* gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205)Eric Snow2023-05-051-0/+3
| | | Here we are doing no more than adding the value for Py_mod_multiple_interpreters and using it for stdlib modules. We will start checking for it in gh-104206 (once PyInterpreterState.ceval.own_gil is added in gh-104204).
* gh-103242: Migrate SSLContext.set_ecdh_curve not to use deprecated APIs ↵Dong-hee Na2023-04-081-3/+8
| | | | | (#103378) Migrate `SSLContext.set_ecdh_curve()` not to use deprecated OpenSSL APIs.
* gh-100062: Remove error code tables from _ssl and err_names_to_codes (GH-100063)David Benjamin2023-04-031-14/+0
| | | | | | | | | | Prior to https://github.com/python/cpython/pull/25300, the make_ssl_data.py script used various tables, exposed in _ssl, to update the error list. After that PR, this is no longer used. Moreover, the err_names_to_codes map isn't used at all. Clean those up. This gets them out of the way if, in the future, OpenSSL provides an API to do what the code here is doing directly. (https://github.com/openssl/openssl/issues/19848)
* fix typo in _ssl.c (GH-103192)Ikko Eltociear Ashimine2023-04-021-1/+1
| | | | | seperated -> separated Automerge-Triggered-By: GH:AlexWaygood
* gh-100372: Use BIO_eof to detect EOF for SSL_FILETYPE_ASN1 (GH-100373)David Benjamin2023-03-241-4/+6
| | | | | | | In PEM, we need to parse until error and then suppress `PEM_R_NO_START_LINE`, because PEM allows arbitrary leading and trailing data. DER, however, does not. Parsing until error and suppressing `ASN1_R_HEADER_TOO_LONG` doesn't quite work because that error also covers some cases that should be rejected. Instead, check `BIO_eof` early and stop the loop that way. Automerge-Triggered-By: GH:Yhg1s
* gh-96931: Fix incorrect results in ssl.SSLSocket.shared_ciphers (#96932)Benjamin Fogle2023-03-221-8/+28
|
* GH-95494: Fix transport EOF handling in OpenSSL 3.0 (GH-95495)David Benjamin2023-03-221-4/+10
| | | | | | | | | | | | | | | | | | | | | GH-25309 enabled SSL_OP_IGNORE_UNEXPECTED_EOF by default, with a comment that it restores OpenSSL 1.1.1 behavior, but this wasn't quite right. That option causes OpenSSL to treat transport EOF as the same as close_notify (i.e. SSL_ERROR_ZERO_RETURN), whereas Python actually has distinct SSLEOFError and SSLZeroReturnError exceptions. (The latter is usually mapped to a zero return from read.) In OpenSSL 1.1.1, the ssl module would raise them for transport EOF and close_notify, respectively. In OpenSSL 3.0, both act like close_notify. Fix this by, instead, just detecting SSL_R_UNEXPECTED_EOF_WHILE_READING and mapping that to the other exception type. There doesn't seem to have been any unit test of this error, so fill in the missing one. This had to be done with the BIO path because it's actually slightly tricky to simulate a transport EOF with Python's fd based APIs. (If you instruct the server to close the socket, it gets confused, probably because the server's SSL object is still referencing the now dead fd?)
* gh-102192: remove redundant exception fields from ssl module socket (#102466)Irit Katriel2023-03-161-19/+9
|
* gh-102255: Improve build support for Windows API partitions (GH-102256)Max Bachmann2023-03-091-0/+4
| | | | | Add `MS_WINDOWS_DESKTOP`, `MS_WINDOWS_APPS`, `MS_WINDOWS_SYSTEM` and `MS_WINDOWS_GAMES` preprocessor definitions to allow switching off functionality missing from particular API partitions ("partitions" are used in Windows to identify overlapping subsets of APIs). CPython only officially supports `MS_WINDOWS_DESKTOP` and `MS_WINDOWS_SYSTEM` (APPS is included by normal desktop builds, but APPS without DESKTOP is not covered). Other configurations are a convenience for people building their own runtimes. `MS_WINDOWS_GAMES` is for the Xbox subset of the Windows API, which is also available on client OS, but is restricted compared to `MS_WINDOWS_DESKTOP`. These restrictions may change over time, as they relate to the build headers rather than the OS support, and so we assume that Xbox builds will use the latest available version of the GDK.
* gh-89051: Add ssl.OP_LEGACY_SERVER_CONNECT (#93927)Thomas Grainger2022-12-201-0/+2
| | | | | | Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Christian Heimes <christian@python.org> Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com> Fixes https://github.com/python/cpython/issues/89051
* bpo-15999: Accept arbitrary values for boolean parameters. (#15609)Serhiy Storchaka2022-12-031-4/+4
| | | builtins and extension module functions and methods that expect boolean values for parameters now accept any Python object rather than just a bool or int type. This is more consistent with how native Python code itself behaves.