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