Skip to content

Commit 2ce1ae1

Browse files
authored
Allow use of TLS without custom/self-signed certificate chain
Fixes #347
1 parent e7866ac commit 2ce1ae1

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/configuration/parser.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ def __parse_mqtt_transport(args: Namespace, config: Configuration) -> None:
9797
config.mqtt_transport_protocol = TransportProtocol.TLS
9898
if args.tls_server_cert_path:
9999
config.tls_server_cert_path = args.tls_server_cert_path
100-
else:
101-
msg = f"No server certificate authority file provided for TLS MQTT URI {args.mqtt_uri}"
102-
raise SystemExit(msg)
103100
else:
104101
msg = f"Invalid MQTT URI scheme: {parse_result.scheme}, use tcp or ws"
105102
raise SystemExit(msg)

src/publisher/mqtt_publisher.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,16 @@ async def connect(self) -> None:
5050
)
5151
else:
5252
self.client.set_auth_credentials(username=self.configuration.mqtt_user)
53+
5354
if self.transport_protocol.with_tls:
55+
ssl_context = ssl.create_default_context()
5456
cert_uri = self.configuration.tls_server_cert_path
55-
LOG.debug(
56-
f"Configuring network encryption and authentication options for MQTT using {cert_uri}"
57-
)
58-
ssl_context = ssl.SSLContext()
59-
ssl_context.load_verify_locations(cafile=cert_uri)
60-
ssl_context.check_hostname = False
57+
if cert_uri:
58+
LOG.debug(
59+
f"Using custom CA file {cert_uri}"
60+
)
61+
ssl_context.load_verify_locations(cafile=cert_uri)
62+
ssl_context.check_hostname = False
6163
else:
6264
ssl_context = None
6365
await self.client.connect(

0 commit comments

Comments
 (0)