File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -101,12 +101,21 @@ def connect(self):
101101
102102 cert_path = os .path .join (os .path .dirname (__file__ ), 'cacert.pem' )
103103
104- self .sock = ssl .wrap_socket (
105- sock ,
106- self .key_file ,
107- self .cert_file ,
108- cert_reqs = ssl .CERT_REQUIRED ,
109- ca_certs = cert_path )
104+ # for >= py3.7, mandatory since 3.12
105+ if hasattr (ssl .SSLContext , 'wrap_socket' ):
106+ context = ssl .SSLContext ()
107+ context .verify_mode = ssl .CERT_REQUIRED
108+ context .load_verify_locations (cert_path )
109+ if hasattr (self , 'cert_file' ) and hasattr (self , 'key_file' ) and self .cert_file and self .key_file :
110+ context .load_cert_chain (certfile = self .cert_file , keyfile = self .key_file )
111+ self .sock = context .wrap_socket (sock )
112+ else :
113+ self .sock = ssl .wrap_socket (
114+ sock ,
115+ self .key_file ,
116+ self .cert_file ,
117+ cert_reqs = ssl .CERT_REQUIRED ,
118+ ca_certs = cert_path )
110119
111120 try :
112121 match_hostname (self .sock .getpeercert (), self .host )
You can’t perform that action at this time.
0 commit comments