Try to provide Server Name Indication even if Python does not have SSLContext.

This commit is contained in:
Valentin Lorentz 2016-07-20 20:42:30 +02:00
parent 9c29652697
commit dc4afb45a0

View File

@ -180,8 +180,15 @@ else:
ca_file=None, trusted_fingerprints=None):
# TLSv1.0 is the only TLS version Python < 2.7.9 supports
# (besides SSLv2 and v3, which are known to be insecure)
conn = ssl.wrap_socket(conn, certfile=certfile, ca_certs=ca_file,
ssl_version=ssl.PROTOCOL_TLSv1)
try:
conn = ssl.wrap_socket(conn,
server_hostname=hostname,
certfile=certfile, ca_certs=ca_file,
ssl_version=ssl.PROTOCOL_TLSv1)
except TypeError: # server_hostname is not supported
conn = ssl.wrap_socket(conn,
certfile=certfile, ca_certs=ca_file,
ssl_version=ssl.PROTOCOL_TLSv1)
if trusted_fingerprints:
check_certificate_fingerprint(conn, trusted_fingerprints)
elif verify: