Skip to content

Commit

Permalink
Merge pull request #86 from mikemanger/fix-deprecation-warnings
Browse files Browse the repository at this point in the history
Tidy up SSL connection to fix deprecation warnings
  • Loading branch information
russella-acm authored Dec 7, 2024
2 parents 09b340a + 802a56d commit baef322
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions lib/createsend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,30 +81,23 @@ class VerifiedHTTPSConnection(HTTPSConnection):

def connect(self):
self.connection_kwargs = {}
# for > py2.5
if hasattr(self, 'timeout'):
self.connection_kwargs.update(timeout=self.timeout)

# for >= py2.7
if hasattr(self, 'source_address'):
self.connection_kwargs.update(source_address=self.source_address)
self.connection_kwargs.update(timeout=self.timeout)
self.connection_kwargs.update(source_address=self.source_address)

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

# for >= py2.7
if getattr(self, '_tunnel_host', None):
self.sock = sock
if self._tunnel_host:
self._tunnel()

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

context = ssl.SSLContext()
context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLS_CLIENT)
context.verify_mode = ssl.CERT_REQUIRED
context.load_verify_locations(cert_path)
if hasattr(self, 'cert_file') and hasattr(self, 'key_file') and self.cert_file and self.key_file:
context.load_cert_chain(certfile=self.cert_file, keyfile=self.key_file)
self.sock = context.wrap_socket(sock)
self.sock = context.wrap_socket(sock, server_hostname=self.host)

try:
match_hostname(self.sock.getpeercert(), self.host)
Expand Down

0 comments on commit baef322

Please sign in to comment.