Skip to content

Enable hostname verification for SSLSocketFactory in setSocketFactory - #2186

Merged
acogoluegnes merged 1 commit into
v5.xfrom
socket-factory-hostname-verification-v5
Nov 16, 2026
Merged

acogoluegnes merged 1 commit into
v5.xfrom
socket-factory-hostname-verification-v5

Conversation

@acogoluegnes

Copy link
Copy Markdown
Contributor

ConnectionFactory#setSocketFactory now enables server hostname verification when it receives an SSLSocketFactory. This applies to blocking IO, the default IO layer. useSslProtocol and setSslContextFactory have enabled verification by default since 5.33.0, but an SSLSocketFactory passed to setSocketFactory did not get it. TLS connections set up this way checked the server certificate chain, but not that the certificate matches the broker host name.

This is a breaking change for applications that pass an SSLSocketFactory to setSocketFactory and connect to a broker whose certificate does not match the host name (for example when connecting by IP address). These applications should use a certificate that matches the host name. If that is not possible, they can replace the socket configurator after setting the socket factory:

factory.setSocketFactory(sslContext.getSocketFactory());
factory.setSocketConfigurator(SocketConfigurators.defaultConfigurator());

Other TLS setups are not affected. useTlsWithNoVerification still disables hostname verification, and NIO behaves as before.

ConnectionFactory#setSocketFactory now enables server hostname
verification when it receives an SSLSocketFactory. This applies to
blocking IO, the default IO layer. useSslProtocol and
setSslContextFactory have enabled verification by default since
5.33.0, but an SSLSocketFactory passed to setSocketFactory did not
get it. TLS connections set up this way checked the server
certificate chain, but not that the certificate matches the broker
host name.

This is a breaking change for applications that pass an
SSLSocketFactory to setSocketFactory and connect to a broker whose
certificate does not match the host name (for example when connecting
by IP address). These applications should use a certificate that
matches the host name. If that is not possible, they can replace the
socket configurator after setting the socket factory:

    factory.setSocketFactory(sslContext.getSocketFactory());
    factory.setSocketConfigurator(SocketConfigurators.defaultConfigurator());

Other TLS setups are not affected. useTlsWithNoVerification still
disables hostname verification, and NIO behaves as before.

(cherry picked from commit 10737ca)# Conflicts:
@acogoluegnes acogoluegnes added this to the 5.38.0 milestone Nov 16, 2026
@acogoluegnes
acogoluegnes marked this pull request as ready for review November 16, 2026 14:53
@acogoluegnes
acogoluegnes merged commit 7f70601 into v5.x Nov 16, 2026
4 checks passed
@acogoluegnes
acogoluegnes deleted the socket-factory-hostname-verification-v5 branch November 16, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant