26
26
27
27
from M2Crypto import Engine , m2 , SSL
28
28
29
+ CERT_NONE = SSL .verify_none
30
+ CERT_REQUIRED = SSL .verify_peer
31
+
29
32
_key = None
30
33
_cert = None
31
34
32
35
# Default engine and provider.
33
- ENGINE_PATH = "/usr/lib/engines-1.1/libpkcs11.so"
34
- MODULE_PATH = "/usr/lib/softhsm/libsofthsm2.so"
36
+ _ENGINE_PATH = "/usr/lib/engines-1.1/libpkcs11.so"
37
+ _MODULE_PATH = "/usr/lib/softhsm/libsofthsm2.so"
35
38
36
39
37
40
def init (pin , certfile , keyfile , engine_path , module_path ):
@@ -51,9 +54,10 @@ def wrap_socket(
51
54
certfile ,
52
55
keyfile ,
53
56
ca_certs = None ,
57
+ cert_reqs = CERT_NONE ,
54
58
ciphers = None ,
55
- engine_path = ENGINE_PATH ,
56
- module_path = MODULE_PATH ,
59
+ engine_path = _ENGINE_PATH ,
60
+ module_path = _MODULE_PATH ,
57
61
):
58
62
if _key is None or _cert is None :
59
63
init (pin , certfile , keyfile , engine_path , module_path )
@@ -66,7 +70,7 @@ def wrap_socket(
66
70
if ciphers is not None :
67
71
ctx .set_cipher_list (ciphers )
68
72
69
- if ca_certs is not None :
73
+ if ca_certs is not None and cert_reqs is not CERT_NONE :
70
74
if ctx .load_verify_locations (ca_certs ) != 1 :
71
75
raise Exception ("Failed to load CA certs" )
72
76
ctx .set_verify (SSL .verify_peer , depth = 9 )
0 commit comments