Repository navigation
Conversation
This was referenced Oct 19, 2026
Contributor
|
this looks like a valid fix, but should be fixed upstream in the owner's project at https://github.com/bertmelis/espMqttClient . Please do a PR there. |
Contributor
Author
|
Same situation as #3300: this code is in EMS-ESP's own |
ESP_SSLClient::connect() only starts a TLS session when the port is on its built-in list of well-known secure ports (8883 is, 8884 or 18883 are not). On any other port the connection silently stays plain TCP, so with "Enable TLS" ticked the MQTT CONNECT, including the username and password, went out in clear text and the broker rejected the handshake. Upgrade the connection with connectSSL() whenever connect() returns without a secure session.
csutcliff
force-pushed
the
pr/mqtt-tls-any-port
branch
from
October 20, 2026 11:53
4d1e5b7 to
9651c04
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ESP_SSLClient::connect()only starts TLS when the port is on its built-in list of well-known secure ports (_secure_portsinESP_SSLClient.h: 443, 8883 and 24 others). On any other port it quietly connects with plain TCP. With "Enable TLS" ticked and a broker on, say, 8884 or 18883, EMS-ESP therefore sends the MQTT CONNECT, including the username and password, in clear text, and the broker rejects it (mosquitto logswrong version number).Captured on the wire, with port 18883 and TLS enabled, the first bytes from EMS-ESP were
10 56 00 04 4d 51 54 54 ...: a plaintext MQTT CONNECT.Fix
ClientSecureSync::connect()checksisSecure()afterconnect(). If the library left the connection in plain TCP, it upgrades it withconnectSSL(), which runs the handshake on the open socket. On the listed ports nothing changes.The IP-address overload takes the same route.
connectSSL()then checks the certificate against the host name of the last by-name connect, or none if there wasn't one. EMS-ESP always connects by host name, so this only matters ifsetServer()is ever switched from a host name to an IP; a comment says so.Testing
wrong version numberon the broker. After,TLSv1.2 ECDHE-ECDSA-AES256-GCM-SHA384, certificate verified, connected.s_16M_P, clang-format clean.Related MQTT TLS fixes, independent of each other: #3300, #3301, #3303.
Checklist
devbranch.clang-formatCHANGELOG_LATEST.mdupdated