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

Commit bca22f4

Browse files
committed
Fix SSL verify_mode monkey-patching on Python 2.7
1 parent 0d3a4f5 commit bca22f4

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

hyper/http20/tls.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
# to.
2121
_context = None
2222

23+
# Exposed here so it can be monkey-patched in integration tests.
24+
_verify_mode = ssl.CERT_REQUIRED
25+
2326

2427
# Work out where our certificates are.
2528
cert_loc = path.join(path.dirname(__file__), '..', 'certs.pem')
@@ -45,7 +48,7 @@ def wrap_socket(socket, server_hostname):
4548
else:
4649
def wrap_socket(socket, server_hostname):
4750
return ssl.wrap_socket(socket, ssl_version=ssl.PROTOCOL_SSLv23,
48-
ca_certs=cert_loc, cert_reqs=ssl.CERT_NONE) # FIXME CERT_REQUIRED
51+
ca_certs=cert_loc, cert_reqs=_verify_mode)
4952

5053

5154
def _init_context():
@@ -55,7 +58,7 @@ def _init_context():
5558
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
5659
context.set_default_verify_paths()
5760
context.load_verify_locations(cafile=cert_loc)
58-
context.verify_mode = ssl.CERT_REQUIRED
61+
context.verify_mode = _verify_mode
5962

6063
try:
6164
context.set_npn_protocols(SUPPORTED_PROTOCOLS)

test/test_integration.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
"""
99
import requests
1010
import ssl
11-
import sys
1211
import threading
1312
import hyper
1413
import pytest
1514
from hyper import HTTP20Connection
15+
from hyper.compat import is_py3
1616
from hyper.contrib import HTTP20Adapter
1717
from hyper.http20.frame import (
1818
Frame, SettingsFrame, WindowUpdateFrame, DataFrame, HeadersFrame,
@@ -27,9 +27,9 @@
2727
from server import SocketLevelTest
2828

2929
# Turn off certificate verification for the tests.
30-
if sys.version_info[0] == 3:
30+
hyper.http20.tls._verify_mode = ssl.CERT_NONE
31+
if is_py3:
3132
hyper.http20.tls._context = hyper.http20.tls._init_context()
32-
hyper.http20.tls._context.verify_mode = ssl.CERT_NONE
3333

3434
def decode_frame(frame_data):
3535
f, length = Frame.parse_frame_header(frame_data[:8])

0 commit comments

Comments
 (0)