Skip to content

Commit 1e94feb

Browse files
authored
Revert "Add TLS settings for HTTP/2 (#3456)" (#3466)
This reverts commit d480615. Unfortunately, we realized after working on them that we can't really use those new settings. curl also does not implement them.
1 parent aa73abc commit 1e94feb

File tree

3 files changed

+20
-105
lines changed

3 files changed

+20
-105
lines changed

changelog/3456.feature.rst

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/urllib3/util/ssl_.py

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717
HAS_NEVER_CHECK_COMMON_NAME = False
1818
IS_PYOPENSSL = False
1919
ALPN_PROTOCOLS = ["http/1.1"]
20-
OP_NO_COMPRESSION = 0
21-
OP_NO_RENEGOTIATION = 0
22-
OP_NO_TICKET = 0
23-
24-
HTTP2_DEFAULT_CIPHERS = "@SECLEVEL=2:ECDHE+AESGCM:ECDHE+CHACHA20:!aDSS"
2520

2621
_TYPE_VERSION_INFO = typing.Tuple[int, int, int, str, int]
2722

@@ -104,23 +99,19 @@ class _TYPE_PEER_CERT_RET_DICT(TypedDict, total=False):
10499
from ssl import ( # type: ignore[assignment]
105100
CERT_REQUIRED,
106101
HAS_NEVER_CHECK_COMMON_NAME,
102+
OP_NO_COMPRESSION,
103+
OP_NO_TICKET,
107104
OPENSSL_VERSION,
108105
OPENSSL_VERSION_NUMBER,
106+
PROTOCOL_TLS,
107+
PROTOCOL_TLS_CLIENT,
108+
OP_NO_SSLv2,
109+
OP_NO_SSLv3,
109110
SSLContext,
110111
TLSVersion,
111112
)
112113

113-
from .ssltransport import SSLTransport # type: ignore[assignment]
114-
115-
# Need to be careful here in case old TLS versions get
116-
# removed in future 'ssl' module implementations.
117-
for attr in ("TLSv1", "TLSv1_1", "TLSv1_2"):
118-
try:
119-
_SSL_VERSION_TO_TLS_VERSION[getattr(ssl, f"PROTOCOL_{attr}")] = getattr(
120-
TLSVersion, attr
121-
)
122-
except AttributeError: # Defensive:
123-
continue
114+
PROTOCOL_SSLv23 = PROTOCOL_TLS
124115

125116
# Setting SSLContext.hostname_checks_common_name = False didn't work before CPython
126117
# 3.8.9, 3.9.3, and 3.10 (but OK on PyPy) or OpenSSL 1.1.1l+
@@ -133,22 +124,20 @@ class _TYPE_PEER_CERT_RET_DICT(TypedDict, total=False):
133124
):
134125
HAS_NEVER_CHECK_COMMON_NAME = False
135126

136-
# NOTE: Flags are imported separately because they may raise ImportError
137-
from ssl import (
138-
OP_NO_COMPRESSION,
139-
OP_NO_RENEGOTIATION,
140-
OP_NO_TICKET,
141-
PROTOCOL_TLS,
142-
PROTOCOL_TLS_CLIENT,
143-
OP_NO_SSLv2,
144-
OP_NO_SSLv3,
145-
)
127+
# Need to be careful here in case old TLS versions get
128+
# removed in future 'ssl' module implementations.
129+
for attr in ("TLSv1", "TLSv1_1", "TLSv1_2"):
130+
try:
131+
_SSL_VERSION_TO_TLS_VERSION[getattr(ssl, f"PROTOCOL_{attr}")] = getattr(
132+
TLSVersion, attr
133+
)
134+
except AttributeError: # Defensive:
135+
continue
146136

147-
PROTOCOL_SSLv23 = PROTOCOL_TLS
137+
from .ssltransport import SSLTransport # type: ignore[assignment]
148138
except ImportError:
149-
OP_NO_COMPRESSION = 0x20000
150-
OP_NO_TICKET = 0x4000
151-
OP_NO_RENEGOTIATION = 0x40000000
139+
OP_NO_COMPRESSION = 0x20000 # type: ignore[assignment]
140+
OP_NO_TICKET = 0x4000 # type: ignore[assignment]
152141
OP_NO_SSLv2 = 0x1000000 # type: ignore[assignment]
153142
OP_NO_SSLv3 = 0x2000000 # type: ignore[assignment]
154143
PROTOCOL_SSLv23 = PROTOCOL_TLS = 2 # type: ignore[assignment]
@@ -238,7 +227,6 @@ def create_urllib3_context(
238227
ciphers: str | None = None,
239228
ssl_minimum_version: int | None = None,
240229
ssl_maximum_version: int | None = None,
241-
http2: bool = False,
242230
) -> ssl.SSLContext:
243231
"""Creates and configures an :class:`ssl.SSLContext` instance for use with urllib3.
244232
@@ -315,8 +303,6 @@ def create_urllib3_context(
315303
# the case of OpenSSL 1.1.1+ or use our own secure default ciphers.
316304
if ciphers:
317305
context.set_ciphers(ciphers)
318-
elif http2:
319-
context.set_ciphers(HTTP2_DEFAULT_CIPHERS)
320306

321307
# Setting the default here, as we may have no ssl module on import
322308
cert_reqs = ssl.CERT_REQUIRED if cert_reqs is None else cert_reqs
@@ -329,26 +315,21 @@ def create_urllib3_context(
329315
options |= OP_NO_SSLv3
330316
# Disable compression to prevent CRIME attacks for OpenSSL 1.0+
331317
# (issue #309)
332-
# Also, HTTP2 (RFC 9113 9.2.1) requires compression to be disabled
333318
options |= OP_NO_COMPRESSION
334319
# TLSv1.2 only. Unless set explicitly, do not request tickets.
335320
# This may save some bandwidth on wire, and although the ticket is encrypted,
336321
# there is a risk associated with it being on wire,
337322
# if the server is not rotating its ticketing keys properly.
338323
options |= OP_NO_TICKET
339-
if http2:
340-
# HTTP2 (RFC 9113 9.2.1) requires renegotiation to be disabled
341-
options |= OP_NO_RENEGOTIATION
342324

343325
context.options |= options
344326

345327
# Enable post-handshake authentication for TLS 1.3, see GH #1634. PHA is
346328
# necessary for conditional client cert authentication with TLS 1.3.
347329
# The attribute is None for OpenSSL <= 1.1.0 or does not exist when using
348330
# an SSLContext created by pyOpenSSL.
349-
# Disable for HTTP/2: RFC 9113 9.2.3 prohibits post_handshake_auth with HTTP2
350331
if getattr(context, "post_handshake_auth", None) is not None:
351-
context.post_handshake_auth = not http2
332+
context.post_handshake_auth = True
352333

353334
# The order of the below lines setting verify_mode and check_hostname
354335
# matter due to safe-guards SSLContext has to prevent an SSLContext with

test/test_ssl.py

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -225,71 +225,6 @@ def test_create_urllib3_context_ssl_version_and_ssl_min_max_version_no_error(
225225
):
226226
ssl_.create_urllib3_context(**kwargs)
227227

228-
@pytest.mark.parametrize(
229-
["pha", "expected_pha", "cert_reqs"],
230-
[
231-
(None, None, None),
232-
(None, None, ssl.CERT_NONE),
233-
(None, None, ssl.CERT_OPTIONAL),
234-
(None, None, ssl.CERT_REQUIRED),
235-
(False, False, None),
236-
(False, False, ssl.CERT_NONE),
237-
(False, False, ssl.CERT_OPTIONAL),
238-
(False, False, ssl.CERT_REQUIRED),
239-
(True, False, None),
240-
(True, False, ssl.CERT_NONE),
241-
(True, False, ssl.CERT_OPTIONAL),
242-
(True, False, ssl.CERT_REQUIRED),
243-
],
244-
)
245-
def test_create_urllib3_context_http2_no_pha(
246-
self,
247-
monkeypatch: pytest.MonkeyPatch,
248-
pha: bool | None,
249-
expected_pha: bool | None,
250-
cert_reqs: int | None,
251-
) -> None:
252-
context = mock.create_autospec(ssl_.SSLContext)
253-
context.set_ciphers = mock.Mock()
254-
context.options = 0
255-
context.post_handshake_auth = pha
256-
monkeypatch.setattr(ssl_, "SSLContext", lambda *_, **__: context)
257-
258-
assert ssl_.create_urllib3_context(cert_reqs=cert_reqs, http2=True) is context
259-
260-
assert context.post_handshake_auth == expected_pha
261-
262-
def test_create_urllib3_context_http2_default_ciphers(
263-
self, monkeypatch: pytest.MonkeyPatch
264-
) -> None:
265-
ciphers = ssl_.HTTP2_DEFAULT_CIPHERS
266-
context = mock.create_autospec(ssl_.SSLContext)
267-
context.set_ciphers = mock.Mock()
268-
context.options = 0
269-
monkeypatch.setattr(ssl_, "SSLContext", lambda *_, **__: context)
270-
271-
assert ssl_.create_urllib3_context(http2=True) is context
272-
273-
assert context.set_ciphers.call_count == 1
274-
assert context.set_ciphers.call_args == mock.call(ciphers)
275-
276-
def test_create_urllib3_context_http2_options(
277-
self, monkeypatch: pytest.MonkeyPatch
278-
) -> None:
279-
context = mock.create_autospec(ssl_.SSLContext)
280-
context.set_ciphers = mock.Mock()
281-
context.options = 0
282-
monkeypatch.setattr(ssl_, "SSLContext", lambda *_, **__: context)
283-
284-
assert ssl_.create_urllib3_context(http2=True) is context
285-
286-
assert context.options & ssl_.OP_NO_COMPRESSION != 0
287-
assert context.options & ssl_.OP_NO_RENEGOTIATION != 0
288-
289-
def test_create_urllib3_context_http2_ssl_min_version(self) -> None:
290-
context = ssl_.create_urllib3_context(http2=True)
291-
assert context.minimum_version == ssl.TLSVersion.TLSv1_2
292-
293228
def test_assert_fingerprint_raises_exception_on_none_cert(self) -> None:
294229
with pytest.raises(SSLError):
295230
ssl_.assert_fingerprint(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy