@@ -81,30 +81,20 @@ class VerifiedHTTPSConnection(HTTPSConnection):
8181
8282 def connect (self ):
8383 self .connection_kwargs = {}
84- # for > py2.5
85- if hasattr (self , 'timeout' ):
86- self .connection_kwargs .update (timeout = self .timeout )
87-
88- # for >= py2.7
89- if hasattr (self , 'source_address' ):
90- self .connection_kwargs .update (source_address = self .source_address )
84+ self .connection_kwargs .update (timeout = self .timeout )
85+ self .connection_kwargs .update (source_address = self .source_address )
9186
9287 sock = socket .create_connection (
9388 (self .host , self .port ), ** self .connection_kwargs )
9489
95- # for >= py2.7
96- if getattr (self , '_tunnel_host' , None ):
97- self .sock = sock
98- self ._tunnel ()
99-
10090 cert_path = os .path .join (os .path .dirname (__file__ ), 'cacert.pem' )
10191
102- context = ssl .SSLContext ()
92+ context = ssl .SSLContext (protocol = ssl . PROTOCOL_TLS_CLIENT )
10393 context .verify_mode = ssl .CERT_REQUIRED
10494 context .load_verify_locations (cert_path )
10595 if hasattr (self , 'cert_file' ) and hasattr (self , 'key_file' ) and self .cert_file and self .key_file :
10696 context .load_cert_chain (certfile = self .cert_file , keyfile = self .key_file )
107- self .sock = context .wrap_socket (sock )
97+ self .sock = context .wrap_socket (sock , server_hostname = self . host )
10898
10999 try :
110100 match_hostname (self .sock .getpeercert (), self .host )
0 commit comments