@@ -63,19 +63,21 @@ def create_sock():
63
63
64
64
# Reference(s): https://docs.python.org/2/library/ssl.html#ssl.SSLContext
65
65
# https://www.mnot.net/blog/2014/12/27/python_2_and_tls_sni
66
- if re . search ( r"\A[\d.]+\Z" , self . host or "" ) is None and kb . tlsSNI . get ( self . host ) is not False and hasattr (ssl , "SSLContext" ):
66
+ if hasattr (ssl , "SSLContext" ):
67
67
for protocol in (_ for _ in _protocols if _ >= ssl .PROTOCOL_TLSv1 ):
68
68
try :
69
69
sock = create_sock ()
70
70
if protocol not in _contexts :
71
71
_contexts [protocol ] = ssl .SSLContext (protocol )
72
+ if self .cert_file and self .key_file :
73
+ _contexts [protocol ].load_cert_chain (certfile = self .cert_file , keyfile = self .key_file )
72
74
try :
73
75
# Reference(s): https://askubuntu.com/a/1263098
74
76
# https://askubuntu.com/a/1250807
75
77
_contexts [protocol ].set_ciphers ("DEFAULT@SECLEVEL=1" )
76
78
except ssl .SSLError :
77
79
pass
78
- result = _contexts [protocol ].wrap_socket (sock , do_handshake_on_connect = True , server_hostname = self .host )
80
+ result = _contexts [protocol ].wrap_socket (sock , do_handshake_on_connect = True , server_hostname = self .host if re . search ( r"\A[\d.]+\Z" , self . host or "" ) is None else None )
79
81
if result :
80
82
success = True
81
83
self .sock = result
@@ -88,14 +90,11 @@ def create_sock():
88
90
self ._tunnel_host = None
89
91
logger .debug ("SSL connection error occurred for '%s' ('%s')" % (_lut [protocol ], getSafeExString (ex )))
90
92
91
- if kb .tlsSNI .get (self .host ) is None :
92
- kb .tlsSNI [self .host ] = success
93
-
94
- if not success :
93
+ elif hasattr (ssl , "wrap_socket" ):
95
94
for protocol in _protocols :
96
95
try :
97
96
sock = create_sock ()
98
- _ = ssl .wrap_socket (sock , self .key_file , self .cert_file , ssl_version = protocol )
97
+ _ = ssl .wrap_socket (sock , keyfile = self .key_file , certfile = self .cert_file , ssl_version = protocol )
99
98
if _ :
100
99
success = True
101
100
self .sock = _
0 commit comments