Commit e630dfc9 authored by Gerhard Weis's avatar Gerhard Weis

use ssl.create_default_context and SNI if available

parent 403bfce4
...@@ -186,9 +186,14 @@ class VerifyingHTTPSConn(HTTPSConnection): ...@@ -186,9 +186,14 @@ class VerifyingHTTPSConn(HTTPSConnection):
else: else:
actual_host = self.host actual_host = self.host
self.sock = ssl.wrap_socket( if hasattr(ssl, 'create_default_context'):
sock, cert_reqs=ssl.CERT_REQUIRED, ca_certs=self.ca_bundle ctx = ssl.create_default_context(cafile=self.ca_bundle)
) self.sock = ctx.wrap_socket(sock, server_hostname=actual_host)
else:
# This is for python < 2.7.9 and < 3.4?
self.sock = ssl.wrap_socket(
sock, cert_reqs=ssl.CERT_REQUIRED, ca_certs=self.ca_bundle
)
try: try:
match_hostname(self.sock.getpeercert(), actual_host) match_hostname(self.sock.getpeercert(), actual_host)
except CertificateError: except CertificateError:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment