Skip to content

Commit

Permalink
Revert "Add check for builtin ssl module"
Browse files Browse the repository at this point in the history
This reverts commit 153090b.
  • Loading branch information
MathCatsAnd committed Jan 21, 2023
1 parent 790ce5f commit 52d52df
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 62 deletions.
44 changes: 10 additions & 34 deletions adafruit_azureiot/device_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@
* Author(s): Jim Bennett, Elena Horton
"""
SSL_MODULE = True

import json
import ssl
import time
try:
import ssl
except:
SSL_MODULE = False

import adafruit_logging as logging
from adafruit_logging import Logger
Expand Down Expand Up @@ -55,9 +51,6 @@ def __init__(
device_id: str,
device_sas_key: str,
logger: Logger = None,
device_certificate = None,
private_certificate_key = None,
use_builtin_ssl_module = True
):
"""Creates an instance of the device registration service
Expand All @@ -84,10 +77,6 @@ def __init__(
self._socket = socket
self._iface = iface

self._device_certificate = device_certificate
self._private_certificate_key = private_certificate_key
self._use_builtin_ssl_module = use_builtin_ssl_module

# pylint: disable=W0613
# pylint: disable=C0103
def _on_connect(self, client, userdata, _, rc) -> None:
Expand Down Expand Up @@ -207,28 +196,15 @@ def register_device(self, expiry: int) -> str:

MQTT.set_socket(self._socket, self._iface)

if self._use_builtin_ssl_module and SSL_MODULE:
self._mqtt = MQTT.MQTT(
broker=constants.DPS_END_POINT,
username=username,
password=auth_string,
port=8883,
keep_alive=120,
client_id=self._device_id,
ssl_context=ssl.create_default_context(),
)
else:
if self._device_certificate is not None:
self.iface.set_certificate(self._device_certificate)
self.iface.set_private_key(self._private_certificate_key)
self._mqtt = MQTT.MQTT(
broker=constants.DPS_END_POINT,
username=username,
password=auth_string,
port=8883,
keep_alive=120,
client_id=self._device_id
)
self._mqtt = MQTT.MQTT(
broker=constants.DPS_END_POINT,
username=username,
password=auth_string,
port=8883,
keep_alive=120,
client_id=self._device_id,
ssl_context=ssl.create_default_context(),
)

self._mqtt.enable_logger(logging, self._logger.getEffectiveLevel())

Expand Down
31 changes: 3 additions & 28 deletions adafruit_azureiot/iot_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@
* Author(s): Jim Bennett, Elena Horton
"""

SSL_MODULE = True

import gc
import json
import ssl
import time
try:
import ssl
except:
SSL_MODULE = False

import adafruit_minimqtt.adafruit_minimqtt as MQTT
import adafruit_logging as logging
Expand Down Expand Up @@ -137,28 +132,15 @@ def _create_mqtt_client(self) -> None:
)
)

if self._use_builtin_ssl_module and SSL_MODULE:
self._mqtt = MQTT.MQTT(
self._mqtts = MQTT.MQTT(
broker=self._hostname,
username=self._username,
password=self._passwd,
port=8883,
keep_alive=120,
client_id=self._device_id,
ssl_context=ssl.create_default_context(),
)
else:
if self._device_certificate is not None:
self.iface.set_certificate(self._device_certificate)
self.iface.set_private_key(self._private_certificate_key)
self._mqtt = MQTT.MQTT(
broker=self._hostname,
username=self._username,
password=self._passwd,
port=8883,
keep_alive=120,
client_id=self._device_id
)
)

self._mqtts.enable_logger(logging, self._logger.getEffectiveLevel())

Expand Down Expand Up @@ -350,9 +332,6 @@ def __init__(
device_sas_key: str,
token_expires: int = 21600,
logger: Logger = None,
device_certificate = None,
private_certificate_key = None,
use_builtin_ssl_module = True
):
"""Create the Azure IoT MQTT client
Expand Down Expand Up @@ -386,10 +365,6 @@ def __init__(
self._logger.addHandler(logging.StreamHandler())
self._is_subscribed_to_twins = False

self._device_certificate = device_certificate
self._private_certificate_key = private_certificate_key
self._use_builtin_ssl_module = use_builtin_ssl_module

def _subscribe_to_core_topics(self):
device_bound_topic = "devices/{}/messages/devicebound/#".format(self._device_id)
self._mqtts.add_topic_callback(
Expand Down

0 comments on commit 52d52df

Please sign in to comment.