17
17
HAS_NEVER_CHECK_COMMON_NAME = False
18
18
IS_PYOPENSSL = False
19
19
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"
25
20
26
21
_TYPE_VERSION_INFO = typing .Tuple [int , int , int , str , int ]
27
22
@@ -104,23 +99,19 @@ class _TYPE_PEER_CERT_RET_DICT(TypedDict, total=False):
104
99
from ssl import ( # type: ignore[assignment]
105
100
CERT_REQUIRED ,
106
101
HAS_NEVER_CHECK_COMMON_NAME ,
102
+ OP_NO_COMPRESSION ,
103
+ OP_NO_TICKET ,
107
104
OPENSSL_VERSION ,
108
105
OPENSSL_VERSION_NUMBER ,
106
+ PROTOCOL_TLS ,
107
+ PROTOCOL_TLS_CLIENT ,
108
+ OP_NO_SSLv2 ,
109
+ OP_NO_SSLv3 ,
109
110
SSLContext ,
110
111
TLSVersion ,
111
112
)
112
113
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
124
115
125
116
# Setting SSLContext.hostname_checks_common_name = False didn't work before CPython
126
117
# 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):
133
124
):
134
125
HAS_NEVER_CHECK_COMMON_NAME = False
135
126
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
146
136
147
- PROTOCOL_SSLv23 = PROTOCOL_TLS
137
+ from . ssltransport import SSLTransport # type: ignore[assignment]
148
138
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]
152
141
OP_NO_SSLv2 = 0x1000000 # type: ignore[assignment]
153
142
OP_NO_SSLv3 = 0x2000000 # type: ignore[assignment]
154
143
PROTOCOL_SSLv23 = PROTOCOL_TLS = 2 # type: ignore[assignment]
@@ -238,7 +227,6 @@ def create_urllib3_context(
238
227
ciphers : str | None = None ,
239
228
ssl_minimum_version : int | None = None ,
240
229
ssl_maximum_version : int | None = None ,
241
- http2 : bool = False ,
242
230
) -> ssl .SSLContext :
243
231
"""Creates and configures an :class:`ssl.SSLContext` instance for use with urllib3.
244
232
@@ -315,8 +303,6 @@ def create_urllib3_context(
315
303
# the case of OpenSSL 1.1.1+ or use our own secure default ciphers.
316
304
if ciphers :
317
305
context .set_ciphers (ciphers )
318
- elif http2 :
319
- context .set_ciphers (HTTP2_DEFAULT_CIPHERS )
320
306
321
307
# Setting the default here, as we may have no ssl module on import
322
308
cert_reqs = ssl .CERT_REQUIRED if cert_reqs is None else cert_reqs
@@ -329,26 +315,21 @@ def create_urllib3_context(
329
315
options |= OP_NO_SSLv3
330
316
# Disable compression to prevent CRIME attacks for OpenSSL 1.0+
331
317
# (issue #309)
332
- # Also, HTTP2 (RFC 9113 9.2.1) requires compression to be disabled
333
318
options |= OP_NO_COMPRESSION
334
319
# TLSv1.2 only. Unless set explicitly, do not request tickets.
335
320
# This may save some bandwidth on wire, and although the ticket is encrypted,
336
321
# there is a risk associated with it being on wire,
337
322
# if the server is not rotating its ticketing keys properly.
338
323
options |= OP_NO_TICKET
339
- if http2 :
340
- # HTTP2 (RFC 9113 9.2.1) requires renegotiation to be disabled
341
- options |= OP_NO_RENEGOTIATION
342
324
343
325
context .options |= options
344
326
345
327
# Enable post-handshake authentication for TLS 1.3, see GH #1634. PHA is
346
328
# necessary for conditional client cert authentication with TLS 1.3.
347
329
# The attribute is None for OpenSSL <= 1.1.0 or does not exist when using
348
330
# an SSLContext created by pyOpenSSL.
349
- # Disable for HTTP/2: RFC 9113 9.2.3 prohibits post_handshake_auth with HTTP2
350
331
if getattr (context , "post_handshake_auth" , None ) is not None :
351
- context .post_handshake_auth = not http2
332
+ context .post_handshake_auth = True
352
333
353
334
# The order of the below lines setting verify_mode and check_hostname
354
335
# matter due to safe-guards SSLContext has to prevent an SSLContext with
0 commit comments