Skip to content

Commit 0f04382

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

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/arduino_iot_cloud/ussl.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def wrap_socket(sock, ssl_params={}):
2929
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
3030
if hasattr(ctx, "set_default_verify_paths"):
3131
ctx.set_default_verify_paths()
32-
if verify != ssl.CERT_REQUIRED:
32+
if hasattr(ctx, "check_hostname") and verify != ssl.CERT_REQUIRED:
3333
ctx.check_hostname = False
3434
ctx.verify_mode = verify
3535
if keyfile is not None and certfile is not None:
@@ -40,8 +40,12 @@ def wrap_socket(sock, ssl_params={}):
4040
ctx.load_verify_locations(cafile, cadata)
4141
return ctx.wrap_socket(sock, server_hostname=hostname)
4242
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)
4549

4650
global pkcs11
4751
if pkcs11 is None:

0 commit comments

Comments
 (0)