@@ -63,19 +63,21 @@ def create_sock():
6363
6464 # Reference(s): https://docs.python.org/2/library/ssl.html#ssl.SSLContext
6565 # 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" ):
6767 for protocol in (_ for _ in _protocols if _ >= ssl .PROTOCOL_TLSv1 ):
6868 try :
6969 sock = create_sock ()
7070 if protocol not in _contexts :
7171 _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 )
7274 try :
7375 # Reference(s): https://askubuntu.com/a/1263098
7476 # https://askubuntu.com/a/1250807
7577 _contexts [protocol ].set_ciphers ("DEFAULT@SECLEVEL=1" )
7678 except ssl .SSLError :
7779 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 )
7981 if result :
8082 success = True
8183 self .sock = result
@@ -88,14 +90,11 @@ def create_sock():
8890 self ._tunnel_host = None
8991 logger .debug ("SSL connection error occurred for '%s' ('%s')" % (_lut [protocol ], getSafeExString (ex )))
9092
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" ):
9594 for protocol in _protocols :
9695 try :
9796 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 )
9998 if _ :
10099 success = True
101100 self .sock = _
0 commit comments