Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit f74c914

Browse files
committed
Relax TLS requirements for HTTP/1.1
1 parent 4be85ea commit f74c914

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

hyper/http20/connection.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
Objects that build hyper's connection-level HTTP/2 abstraction.
77
"""
8-
from ..tls import wrap_socket
8+
from ..tls import wrap_socket, H2_NPN_PROTOCOLS
99
from .hpack_compat import Encoder, Decoder
1010
from .stream import Stream
1111
from .frame import (
@@ -201,7 +201,10 @@ def connect(self):
201201
"""
202202
if self._sock is None:
203203
sock = socket.create_connection((self.host, self.port), 5)
204-
sock = wrap_socket(sock, self.host)
204+
205+
sock, proto = wrap_socket(sock, self.host)
206+
assert proto in H2_NPN_PROTOCOLS
207+
205208
self._sock = BufferedSocket(sock, self.network_buffer_size)
206209

207210
# We need to send the connection header immediately on this

hyper/tls.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,18 @@ def wrap_socket(sock, server_hostname):
4040
if _context.check_hostname: # pragma: no cover
4141
ssl.match_hostname(ssl_sock.getpeercert(), server_hostname)
4242

43+
proto = ''
4344
with ignore_missing():
44-
assert ssl_sock.selected_npn_protocol() in H2_NPN_PROTOCOLS
45+
proto = ssl_sock.selected_npn_protocol()
4546

46-
return ssl_sock
47+
return (ssl_sock, proto)
4748

4849

4950
def _init_context():
5051
"""
5152
Creates the singleton SSLContext we use.
5253
"""
53-
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
54+
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
5455
context.set_default_verify_paths()
5556
context.load_verify_locations(cafile=cert_loc)
5657
context.verify_mode = ssl.CERT_REQUIRED

test/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def _start_server(self):
5151
sock = socket.socket(socket.AF_INET6)
5252
if sys.platform != 'win32':
5353
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
54-
sock = self.cxt.wrap_socket(sock, server_side=True)
54+
sock, proto = self.cxt.wrap_socket(sock, server_side=True)
5555
sock.bind((self.host, 0))
5656
self.port = sock.getsockname()[1]
5757

0 commit comments

Comments
 (0)