File tree 1 file changed +7
-3
lines changed 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ def wrap_socket(sock, ssl_params={}):
29
29
ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
30
30
if hasattr (ctx , "set_default_verify_paths" ):
31
31
ctx .set_default_verify_paths ()
32
- if verify != ssl .CERT_REQUIRED :
32
+ if hasattr ( ctx , "check_hostname" ) and verify != ssl .CERT_REQUIRED :
33
33
ctx .check_hostname = False
34
34
ctx .verify_mode = verify
35
35
if keyfile is not None and certfile is not None :
@@ -40,8 +40,12 @@ def wrap_socket(sock, ssl_params={}):
40
40
ctx .load_verify_locations (cafile , cadata )
41
41
return ctx .wrap_socket (sock , server_hostname = hostname )
42
42
else :
43
- # Use M2Crypto to load key and cert from HSM.
44
- from M2Crypto import m2 , SSL , Engine
43
+ try :
44
+ # Use M2Crypto to load key and cert from HSM.
45
+ from M2Crypto import m2 , SSL , Engine
46
+ except (ImportError , AttributeError ):
47
+ logging .error ("The m2crypto module is required to use HSM." )
48
+ sys .exit (1 )
45
49
46
50
global pkcs11
47
51
if pkcs11 is None :
You can’t perform that action at this time.
0 commit comments