Skip to content

Commit 39d94f6

Browse files
committed
Removed use of deprecated APIs/constants
1 parent 8cfd2bc commit 39d94f6

File tree

5 files changed

+11
-16
lines changed

5 files changed

+11
-16
lines changed

azure-iot-device/azure/iot/device/common/http_transport.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ def _create_ssl_context(self):
6969
This method creates the SSLContext object used to authenticate the connection. The generated context is used by the http_client and is necessary when authenticating using a self-signed X509 cert or trusted X509 cert
7070
"""
7171
logger.debug("creating a SSL context")
72-
ssl_context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLSv1_2)
72+
# Note that PROTOCOL_TLS_CLIENT implies ssl.CERT_REQUIRED and check_hostname == true
73+
ssl_context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLS_CLIENT)
7374

7475
if self._server_verification_cert:
7576
ssl_context.load_verify_locations(cadata=self._server_verification_cert)
@@ -91,9 +92,6 @@ def _create_ssl_context(self):
9192
self._x509_cert.pass_phrase,
9293
)
9394

94-
ssl_context.verify_mode = ssl.CERT_REQUIRED
95-
ssl_context.check_hostname = True
96-
9795
return ssl_context
9896

9997
@pipeline_thread.invoke_on_http_thread_nowait

azure-iot-device/azure/iot/device/common/mqtt_transport.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ def _create_ssl_context(self):
321321
This method creates the SSLContext object used by Paho to authenticate the connection.
322322
"""
323323
logger.debug("creating a SSL context")
324-
ssl_context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLSv1_2)
324+
# Note that PROTOCOL_TLS_CLIENT implies ssl.CERT_REQUIRED and check_hostname == true
325+
ssl_context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLS_CLIENT)
325326

326327
if self._server_verification_cert:
327328
logger.debug("configuring SSL context with custom server verification cert")
@@ -346,9 +347,6 @@ def _create_ssl_context(self):
346347
self._x509_cert.pass_phrase,
347348
)
348349

349-
ssl_context.verify_mode = ssl.CERT_REQUIRED
350-
ssl_context.check_hostname = True
351-
352350
return ssl_context
353351

354352
def shutdown(self):

tests/e2e/iothub_e2e/sync/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def brand_new_client(device_identity, client_kwargs, service_helper, device_id,
2020
# Keep this here. It is useful to see this info inside the inside devops pipeline test failures.
2121
logger.info(
2222
"Connecting device_id={}, module_id={}, to hub={} at {} (UTC)".format(
23-
device_id, module_id, test_env.IOTHUB_HOSTNAME, datetime.datetime.utcnow()
23+
device_id, module_id, test_env.IOTHUB_HOSTNAME, datetime.datetime.now(datetime.UTC)
2424
)
2525
)
2626

tests/unit/common/test_http_transport.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,13 @@ def test_proxy_format(self, proxy_options):
100100
)
101101
def test_configures_tls_context(self, mocker):
102102
mock_ssl_context_constructor = mocker.patch.object(ssl, "SSLContext")
103-
mock_ssl_context = mock_ssl_context_constructor.return_value
104103

105104
HTTPTransport(hostname=fake_hostname)
106105
# Verify correctness of TLS/SSL Context
107106
assert mock_ssl_context_constructor.call_count == 1
108-
assert mock_ssl_context_constructor.call_args == mocker.call(protocol=ssl.PROTOCOL_TLSv1_2)
109-
assert mock_ssl_context.check_hostname is True
110-
assert mock_ssl_context.verify_mode == ssl.CERT_REQUIRED
107+
assert mock_ssl_context_constructor.call_args == mocker.call(
108+
protocol=ssl.PROTOCOL_TLS_CLIENT
109+
)
111110

112111
@pytest.mark.it(
113112
"Configures TLS/SSL context using default certificates if protocol wrapper not instantiated with a server verification certificate"

tests/unit/common/test_mqtt_transport.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@ def test_configures_tls_context(self, mocker):
267267

268268
# Verify correctness of TLS/SSL Context
269269
assert mock_ssl_context_constructor.call_count == 1
270-
assert mock_ssl_context_constructor.call_args == mocker.call(protocol=ssl.PROTOCOL_TLSv1_2)
271-
assert mock_ssl_context.check_hostname is True
272-
assert mock_ssl_context.verify_mode == ssl.CERT_REQUIRED
270+
assert mock_ssl_context_constructor.call_args == mocker.call(
271+
protocol=ssl.PROTOCOL_TLS_CLIENT
272+
)
273273

274274
# Verify context has been set
275275
assert mock_mqtt_client.tls_set_context.call_count == 1

0 commit comments

Comments
 (0)