Skip to content

Commit e45ffab

Browse files
lxsaahclaude
andcommitted
fix(mqtt-connector): select TLS transport for mqtts:// URLs
ConnectorUrl parsing already recognised the mqtts scheme (port default 8883, URL-embedded credentials), but rumqttc defaults to plain TCP unless a TLS transport is set explicitly — an mqtts:// broker URL silently spoke cleartext to port 8883 and failed the handshake. Select Transport::Tls with the native-tls default configuration (system trust roots) when the scheme is mqtts. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent b4e0ce0 commit e45ffab

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

aimdb-mqtt-connector/src/tokio_client.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ impl MqttConnectorImpl {
177177
mqtt_opts.set_credentials(username, password);
178178
}
179179

180+
// mqtts:// selects the TLS transport (system trust roots via
181+
// native-tls); rumqttc otherwise speaks plain TCP regardless of port.
182+
if connector_url.scheme == "mqtts" {
183+
mqtt_opts.set_transport(rumqttc::Transport::Tls(rumqttc::TlsConfiguration::Native));
184+
}
185+
180186
// Wrap router early so we can count topics for capacity calculation
181187
let router_arc = Arc::new(router);
182188
let topic_count = router_arc.resource_ids().len();
@@ -364,4 +370,18 @@ mod tests {
364370
let connector = MqttConnectorImpl::build_internal("not-a-valid-url", None, router).await;
365371
assert!(connector.is_err());
366372
}
373+
374+
#[tokio::test]
375+
async fn test_connector_mqtts_url_with_credentials() {
376+
// mqtts:// with URL-embedded credentials must parse and build; the TLS
377+
// handshake itself only happens once the event loop is polled.
378+
let router = RouterBuilder::new().build();
379+
let connector = MqttConnectorImpl::build_internal(
380+
"mqtts://hub-sub:secret@broker.example.com:8883",
381+
None,
382+
router,
383+
)
384+
.await;
385+
assert!(connector.is_ok());
386+
}
367387
}

0 commit comments

Comments
 (0)