Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

SNI support #523 #1302

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions raven/utils/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,31 @@ def __init__(self, *args, **kwargs):
httplib.HTTPConnection.__init__(self, *args, **kwargs)

def connect(self):
sock = socket.create_connection(
address=(self.host, self.port),
timeout=self.timeout,
)
if self._tunnel_host:
self.sock = sock
self._tunnel()

self.sock = ssl.wrap_socket(
sock, ca_certs=ca_certs, cert_reqs=ssl.CERT_REQUIRED)
# https://docs.python.org/3/library/ssl.html#socket-creation
if sys.version_info > (2, 7, 9) or sys.version_info > (3, 2):
sock = socket.create_connection(
address=(self.host, self.port),
timeout=self.timeout,
)

if self._tunnel_host:
self.sock = sock
self._tunnel()

context = ssl.create_default_context(cafile=ca_certs)
self.sock = context.wrap_socket(sock, server_hostname=self.host)
else:
sock = socket.create_connection(
address=(self.host, self.port),
timeout=self.timeout,
)

if self._tunnel_host:
self.sock = sock
self._tunnel()

self.sock = ssl.wrap_socket(
sock, ca_certs=ca_certs, cert_reqs=ssl.CERT_REQUIRED)

if assert_hostname is not None:
match_hostname(self.sock.getpeercert(),
Expand Down