Title: `ssl.HAS_TLSv1_2` is `False` with OpenSSL 4.0 although TLS 1.2 connections work · Issue #159387 · python/cpython · GitHub
Open Graph Title: `ssl.HAS_TLSv1_2` is `False` with OpenSSL 4.0 although TLS 1.2 connections work · Issue #159387 · python/cpython
X Title: `ssl.HAS_TLSv1_2` is `False` with OpenSSL 4.0 although TLS 1.2 connections work · Issue #159387 · python/cpython
Description: Bug report Summary When _ssl is built against OpenSSL 4.0, ssl.HAS_TLSv1_2 is False, yet a context limited to maximum_version = TLSVersion.TLSv1_2 negotiates a TLS 1.2 connection. The same compile-time condition makes _ssl treat TLS 1.3 ...
Open Graph Description: Bug report Summary When _ssl is built against OpenSSL 4.0, ssl.HAS_TLSv1_2 is False, yet a context limited to maximum_version = TLSVersion.TLSv1_2 negotiates a TLS 1.2 connection. The same compile-...
X Description: Bug report Summary When _ssl is built against OpenSSL 4.0, ssl.HAS_TLSv1_2 is False, yet a context limited to maximum_version = TLSVersion.TLSv1_2 negotiates a TLS 1.2 connection. The same compile-...
Opengraph URL: https://github.com/python/cpython/issues/159387
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`ssl.HAS_TLSv1_2` is `False` with OpenSSL 4.0 although TLS 1.2 connections work","articleBody":"### Bug report\n\n### Summary\n\nWhen `_ssl` is built against OpenSSL 4.0, `ssl.HAS_TLSv1_2` is `False`, yet a context limited to `maximum_version = TLSVersion.TLSv1_2` negotiates a TLS 1.2 connection. The same compile-time condition makes `_ssl` treat TLS 1.3 as the minimum available protocol. As a result, `TLSVersion.MINIMUM_SUPPORTED` resolves to TLS 1.3, and `test_ssl` skips its TLS 1.2 tests.\n\n### Reproduction\n\n\n```python\nimport os, socket, ssl, threading\nimport test\n\nprint(ssl.OPENSSL_VERSION)\nprint(\"HAS_TLSv1_2:\", ssl.HAS_TLSv1_2)\n\ncertfile = os.path.join(os.path.dirname(test.__file__), \"certdata\", \"keycert.pem\")\nserver_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)\nserver_ctx.load_cert_chain(certfile)\nserver_ctx.maximum_version = ssl.TLSVersion.TLSv1_2\n\nclient_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)\nclient_ctx.check_hostname = False\nclient_ctx.verify_mode = ssl.CERT_NONE\nclient_ctx.maximum_version = ssl.TLSVersion.TLSv1_2\n\nlistener = socket.create_server((\"127.0.0.1\", 0))\n\ndef serve():\n conn, _ = listener.accept()\n with server_ctx.wrap_socket(conn, server_side=True) as s:\n s.recv(1)\n\nt = threading.Thread(target=serve)\nt.start()\nwith client_ctx.wrap_socket(socket.create_connection(listener.getsockname())) as s:\n print(\"negotiated:\", s.version(), s.cipher())\n s.send(b\"x\")\nt.join()\nlistener.close()\n\nctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)\nctx.maximum_version = ssl.TLSVersion.MINIMUM_SUPPORTED\nprint(\"maximum_version = MINIMUM_SUPPORTED ->\", repr(ctx.maximum_version))\n```\n\n```bash\n./python -m test test_ssl -v -m test_psk -m test_min_max_version_tlsv1_2 \\\n -m test_min_max_version_mismatch -m test_protocol_tlsv1_2\n```\n\n### Actual Behavior\n\n```\nOpenSSL 4.0.2 25 Aug 2026\nHAS_TLSv1_2: False\nnegotiated: TLSv1.2 ('ECDHE-RSA-AES256-GCM-SHA384', 'TLSv1.2', 256)\nmaximum_version = MINIMUM_SUPPORTED -> \u003cTLSVersion.TLSv1_3: 772>\n```\n\n```\ntest_min_max_version_mismatch (test.test_ssl.ThreadedTests.test_min_max_version_mismatch) ... skipped 'TLSv1_2 is not available.'\ntest_min_max_version_tlsv1_2 (test.test_ssl.ThreadedTests.test_min_max_version_tlsv1_2) ... skipped 'TLSv1_2 is not available.'\nConnecting to a TLSv1.2 server with various client options. ... skipped 'TLSv1_2 is not available.'\ntest_psk (test.test_ssl.ThreadedTests.test_psk) ... skipped 'TLSv1_2 is not available.'\n```\n\n### Expected Behavior\n\nThe `ssl` documentation defines `HAS_TLSv1_2` as \"Whether the OpenSSL library has built-in support for the TLS 1.2 protocol.\" OpenSSL 4.0.2 still supports TLS 1.2: the handshake above succeeds, and `openssl ciphers -s -tls1_2` lists TLS 1.2 cipher suites such as `ECDHE-ECDSA-AES256-GCM-SHA384`. So `HAS_TLSv1_2` should be `True`. `TLSVersion.MINIMUM_SUPPORTED` should map to a version no higher than TLS 1.2, and the TLS 1.2 tests in `test_ssl` should run instead of being skipped.\n\n#### Root cause\n\n`Modules/_ssl.c` contains this block, added for OpenSSL 4.0 in gh-146207:\n\n```c\n#if (OPENSSL_VERSION_NUMBER >= 0x40000000L)\n# define OPENSSL_NO_SSL3\n# define OPENSSL_NO_TLS1\n# define OPENSSL_NO_TLS1_1\n# define OPENSSL_NO_TLS1_2\n# define OPENSSL_NO_SSL3_METHOD\n# define OPENSSL_NO_TLS1_METHOD\n# define OPENSSL_NO_TLS1_1_METHOD\n# define OPENSSL_NO_TLS1_2_METHOD\n#endif\n```\n\nThe OpenSSL 4.0 compatibility block mixes up protocol availability with fixed-version method availability.\n\nOPENSSL_NO_TLS1_2_METHOD means TLSv1_2_method() is unavailable, while OPENSSL_NO_TLS1_2 means the TLS 1.2 protocol itself is unavailable. OpenSSL 4.0 removed the deprecated fixed-version methods, but TLS 1.0, 1.1 and 1.2 remain usable through TLS_method().\n\nBecause _ssl.c defines the protocol-level macros as well, CPython treats TLS 1.0–1.2 as unavailable. This makes ssl.HAS_TLSv1_2 false, causes TLSVersion.MINIMUM_SUPPORTED to resolve to TLS 1.3, and makes TLS 1.2 tests guarded by requires_tls_version() get skipped, even though a TLS 1.2 handshake succeeds.\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-159388\n* gh-161320\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/lpyu001","@type":"Person","name":"lpyu001"},"datePublished":"2026-10-14T02:13:08Z","url":"https://github.com/python/cpython/issues/159387"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8d7b6d12-f1d4-7138-2620-2c56e1bc5218 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DB16:22DB35:471B82C:5A84AF6:6B023346 |
| html-safe-nonce | 1542d01580af1bc0c30109ba6603ddb635e0f625720ad12f2cb371e4fb5ea3e9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQjE2OjIyREIzNTo0NzFCODJDOjVBODRBRjY6NkIwMjMzNDYiLCJ2aXNpdG9yX2lkIjoiNDQ5NDg1MzY5NzA2NjY0NDI5NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f412c1dddd83383609bc74a1676d714dcf9a6e30790073df68004621ed170f04 |
| hovercard-subject-tag | issue:5840751164 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/159387/issue_layout |
| twitter:image | https://opengraph.githubassets.com/95b9349dc397f3a9ff5a43876e57e36ef4dae151975fc2c7ff9071a777ce0ce3/python/cpython/issues/159387 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/95b9349dc397f3a9ff5a43876e57e36ef4dae151975fc2c7ff9071a777ce0ce3/python/cpython/issues/159387 |
| og:image:alt | Bug report Summary When _ssl is built against OpenSSL 4.0, ssl.HAS_TLSv1_2 is False, yet a context limited to maximum_version = TLSVersion.TLSv1_2 negotiates a TLS 1.2 connection. The same compile-... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | lpyu001 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width