@@ -332,6 +332,42 @@ val config = MqttConfig(
332332
333333Log levels from most to least verbose: ` TRACE ` → ` DEBUG ` → ` INFO ` → ` WARN ` → ` ERROR ` → ` NONE ` .
334334
335+ ### Custom TLS trust
336+
337+ By default the TCP transport validates the broker certificate against the platform CA store. To
338+ reach a broker behind a private or self-signed CA, pass a TLS customisation lambda to
339+ ` TcpTransportFactory ` . It runs against ktor's ` TLSConfigBuilder ` :
340+
341+ ``` kotlin
342+ import org.meshtastic.mqtt.transport.tcp.TcpTransportFactory
343+
344+ val client = MqttClient (" my-client" ) {
345+ transportFactory = TcpTransportFactory { trustManager = myPrivateCaTrustManager }
346+ }
347+ client.connect(MqttEndpoint .parse(" mqtts://broker.internal:8883" ))
348+ ```
349+
350+ The hook is applied after the SNI server name is resolved and before platform trust is configured.
351+ On Android that ordering matters: your trust manager is * wrapped* by the hostname-aware trust
352+ manager rather than replacing it, so certificate hostname verification still happens.
353+
354+ This scopes the extra trust to the MQTT connection alone. It replaces the app-wide workaround of
355+ adding ` <certificates src="user"/> ` to ` network_security_config.xml ` , which would affect every
356+ HTTPS connection the app makes.
357+
358+ The hook composes with transport selection as usual:
359+
360+ ``` kotlin
361+ transportFactory = TcpTransportFactory { trustManager = myPrivateCaTrustManager } +
362+ WebSocketTransportFactory ()
363+ ```
364+
365+ ` TLSConfigBuilder ` comes from ` io.ktor:ktor-network-tls ` , exposed transitively by
366+ ` mqtt-client-transport-tcp ` — no extra dependency needed. The WebSocket transport has no equivalent
367+ hook yet. ` trustManager ` specifically is available on the JVM and Android actuals of
368+ ` TLSConfigBuilder ` ; on Apple, Linux, and Windows targets the hook still runs, but ` TLSConfigBuilder `
369+ exposes a different set of properties there.
370+
335371## Android / KMP Integration
336372
337373The library is designed as a drop-in MQTT client for KMP projects. Consumer ProGuard/R8 rules are bundled automatically.
0 commit comments