Skip to content

Commit ffa153e

Browse files
authored
Merge branch 'campaignmonitor:master' into master
2 parents 0f973a3 + f930519 commit ffa153e

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

lib/createsend/utils.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,21 @@ def connect(self):
101101

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

104-
self.sock = ssl.wrap_socket(
105-
sock,
106-
self.key_file,
107-
self.cert_file,
108-
cert_reqs=ssl.CERT_REQUIRED,
109-
ca_certs=cert_path)
104+
# for >= py3.7, mandatory since 3.12
105+
if hasattr(ssl.SSLContext, 'wrap_socket'):
106+
context = ssl.SSLContext()
107+
context.verify_mode = ssl.CERT_REQUIRED
108+
context.load_verify_locations(cert_path)
109+
if hasattr(self, 'cert_file') and hasattr(self, 'key_file') and self.cert_file and self.key_file:
110+
context.load_cert_chain(certfile=self.cert_file, keyfile=self.key_file)
111+
self.sock = context.wrap_socket(sock)
112+
else:
113+
self.sock = ssl.wrap_socket(
114+
sock,
115+
self.key_file,
116+
self.cert_file,
117+
cert_reqs=ssl.CERT_REQUIRED,
118+
ca_certs=cert_path)
110119

111120
try:
112121
match_hostname(self.sock.getpeercert(), self.host)

0 commit comments

Comments
 (0)