Skip to content

Commit baef322

Browse files
authored
Merge pull request #86 from mikemanger/fix-deprecation-warnings
Tidy up SSL connection to fix deprecation warnings
2 parents 09b340a + 802a56d commit baef322

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

lib/createsend/utils.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,30 +81,23 @@ class VerifiedHTTPSConnection(HTTPSConnection):
8181

8282
def connect(self):
8383
self.connection_kwargs = {}
84-
# for > py2.5
85-
if hasattr(self, 'timeout'):
86-
self.connection_kwargs.update(timeout=self.timeout)
87-
88-
# for >= py2.7
89-
if hasattr(self, 'source_address'):
90-
self.connection_kwargs.update(source_address=self.source_address)
84+
self.connection_kwargs.update(timeout=self.timeout)
85+
self.connection_kwargs.update(source_address=self.source_address)
9186

9287
sock = socket.create_connection(
9388
(self.host, self.port), **self.connection_kwargs)
9489

95-
# for >= py2.7
96-
if getattr(self, '_tunnel_host', None):
97-
self.sock = sock
90+
if self._tunnel_host:
9891
self._tunnel()
9992

10093
cert_path = os.path.join(os.path.dirname(__file__), 'cacert.pem')
10194

102-
context = ssl.SSLContext()
95+
context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLS_CLIENT)
10396
context.verify_mode = ssl.CERT_REQUIRED
10497
context.load_verify_locations(cert_path)
10598
if hasattr(self, 'cert_file') and hasattr(self, 'key_file') and self.cert_file and self.key_file:
10699
context.load_cert_chain(certfile=self.cert_file, keyfile=self.key_file)
107-
self.sock = context.wrap_socket(sock)
100+
self.sock = context.wrap_socket(sock, server_hostname=self.host)
108101

109102
try:
110103
match_hostname(self.sock.getpeercert(), self.host)

0 commit comments

Comments
 (0)