Skip to content

Commit a658a99

Browse files
committed
reverted some changes
1 parent 39d94f6 commit a658a99

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ 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-
# Note that PROTOCOL_TLS_CLIENT implies ssl.CERT_REQUIRED and check_hostname == true
73-
ssl_context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLS_CLIENT)
72+
ssl_context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLSv1_2)
7473

7574
if self._server_verification_cert:
7675
ssl_context.load_verify_locations(cadata=self._server_verification_cert)
@@ -92,6 +91,9 @@ def _create_ssl_context(self):
9291
self._x509_cert.pass_phrase,
9392
)
9493

94+
ssl_context.verify_mode = ssl.CERT_REQUIRED
95+
ssl_context.check_hostname = True
96+
9597
return ssl_context
9698

9799
@pipeline_thread.invoke_on_http_thread_nowait

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,7 @@ 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-
# Note that PROTOCOL_TLS_CLIENT implies ssl.CERT_REQUIRED and check_hostname == true
325-
ssl_context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLS_CLIENT)
324+
ssl_context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLSv1_2)
326325

327326
if self._server_verification_cert:
328327
logger.debug("configuring SSL context with custom server verification cert")
@@ -347,6 +346,9 @@ def _create_ssl_context(self):
347346
self._x509_cert.pass_phrase,
348347
)
349348

349+
ssl_context.verify_mode = ssl.CERT_REQUIRED
350+
ssl_context.check_hostname = True
351+
350352
return ssl_context
351353

352354
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.now(datetime.UTC)
23+
device_id, module_id, test_env.IOTHUB_HOSTNAME, datetime.datetime.utcnow()
2424
)
2525
)
2626

tests/unit/common/test_http_transport.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,14 @@ 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
103104

104105
HTTPTransport(hostname=fake_hostname)
105106
# Verify correctness of TLS/SSL Context
106107
assert mock_ssl_context_constructor.call_count == 1
107-
assert mock_ssl_context_constructor.call_args == mocker.call(
108-
protocol=ssl.PROTOCOL_TLS_CLIENT
109-
)
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
110111

111112
@pytest.mark.it(
112113
"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(
271-
protocol=ssl.PROTOCOL_TLS_CLIENT
272-
)
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
273273

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

0 commit comments

Comments
 (0)