Skip to content

Commit dcb2292

Browse files
committed
ussl: Fix exception on missing SSL Context attributes.
Signed-off-by: iabdalkader <[email protected]>
1 parent cfb5de9 commit dcb2292

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/arduino_iot_cloud/ussl.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
# SSL module with m2crypto backend for HSM support.
88

99
import ssl
10+
import sys
11+
import logging
1012

1113
pkcs11 = None
1214

@@ -29,7 +31,7 @@ def wrap_socket(sock, ssl_params={}):
2931
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
3032
if hasattr(ctx, "set_default_verify_paths"):
3133
ctx.set_default_verify_paths()
32-
if verify != ssl.CERT_REQUIRED:
34+
if hasattr(ctx, "check_hostname") and verify != ssl.CERT_REQUIRED:
3335
ctx.check_hostname = False
3436
ctx.verify_mode = verify
3537
if keyfile is not None and certfile is not None:
@@ -41,7 +43,11 @@ def wrap_socket(sock, ssl_params={}):
4143
return ctx.wrap_socket(sock, server_hostname=hostname)
4244
else:
4345
# 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)
4551

4652
global pkcs11
4753
if pkcs11 is None:

0 commit comments

Comments
 (0)