Skip to content

Commit 75b7d87

Browse files
committed
allow use of tls without custom/self-signed certificate chain
1 parent d4c6aeb commit 75b7d87

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/configuration/parser.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,6 @@ def process_arguments() -> Configuration:
414414
config.mqtt_transport_protocol = TransportProtocol.TLS
415415
if args.tls_server_cert_path:
416416
config.tls_server_cert_path = args.tls_server_cert_path
417-
else:
418-
msg = f"No server certificate authority file provided for TLS MQTT URI {args.mqtt_uri}"
419-
raise SystemExit(msg)
420417
else:
421418
msg = f"Invalid MQTT URI scheme: {parse_result.scheme}, use tcp or ws"
422419
raise SystemExit(msg)

src/publisher/mqtt_publisher.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,19 @@ 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:
5455
cert_uri = self.configuration.tls_server_cert_path
5556
LOG.debug(
5657
f"Configuring network encryption and authentication options for MQTT using {cert_uri}"
5758
)
5859
ssl_context = ssl.SSLContext()
59-
ssl_context.load_verify_locations(cafile=cert_uri)
60-
ssl_context.check_hostname = False
60+
if cert_uri:
61+
ssl_context.load_verify_locations(cafile=cert_uri)
62+
ssl_context.check_hostname = False
63+
else:
64+
LOG.debug(f"Custom certificate chain not provided, using default")
65+
ssl_context = True # Use default SSL context if no cert is provided
6166
else:
6267
ssl_context = None
6368
await self.client.connect(

0 commit comments

Comments
 (0)