@@ -81,30 +81,23 @@ class VerifiedHTTPSConnection(HTTPSConnection):
81
81
82
82
def connect (self ):
83
83
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 )
91
86
92
87
sock = socket .create_connection (
93
88
(self .host , self .port ), ** self .connection_kwargs )
94
89
95
- # for >= py2.7
96
- if getattr (self , '_tunnel_host' , None ):
97
- self .sock = sock
90
+ if self ._tunnel_host :
98
91
self ._tunnel ()
99
92
100
93
cert_path = os .path .join (os .path .dirname (__file__ ), 'cacert.pem' )
101
94
102
- context = ssl .SSLContext ()
95
+ context = ssl .SSLContext (protocol = ssl . PROTOCOL_TLS_CLIENT )
103
96
context .verify_mode = ssl .CERT_REQUIRED
104
97
context .load_verify_locations (cert_path )
105
98
if hasattr (self , 'cert_file' ) and hasattr (self , 'key_file' ) and self .cert_file and self .key_file :
106
99
context .load_cert_chain (certfile = self .cert_file , keyfile = self .key_file )
107
- self .sock = context .wrap_socket (sock )
100
+ self .sock = context .wrap_socket (sock , server_hostname = self . host )
108
101
109
102
try :
110
103
match_hostname (self .sock .getpeercert (), self .host )
0 commit comments