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