Skip to content

Commit a6919a4

Browse files
committed
Deprecate tls#hostnameVerification
Now set up with Netty's SslContextBuilder#endpointIdentificationAlgorithm(String).
1 parent f7aa4e4 commit a6919a4

File tree

6 files changed

+25
-36
lines changed

6 files changed

+25
-36
lines changed

src/docs/asciidoc/api.adoc

+4-10
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,9 @@ TLS can be enabled by using the `rabbitmq-stream+tls` scheme in the URI.
8888
The default TLS port is 5551.
8989

9090
Use the `EnvironmentBuilder#tls` method to configure TLS.
91-
The most important setting is a `io.netty.handler.ssl.SslContext` instance,
92-
which is created and configured with the
93-
`io.netty.handler.ssl.SslContext#forClient` method. Note hostname verification
94-
is enabled by default.
91+
The most important setting is a `io.netty.handler.ssl.SslContext` instance, which is created and configured with the
92+
`io.netty.handler.ssl.SslContext#forClient` method.
93+
Note hostname verification is enabled by default.
9594

9695
The following snippet shows a common configuration, whereby
9796
the client is instructed to trust servers with certificates
@@ -242,15 +241,10 @@ Used as a prefix for connection names.
242241
|Configuration helper for TLS.
243242
|TLS is enabled if a `rabbitmq-stream+tls` URI is provided.
244243

245-
|`tls#hostnameVerification`
246-
|Enable or disable hostname verification.
247-
|Enabled by default.
248-
249244
|`tls#sslContext`
250245
|Set the `io.netty.handler.ssl.SslContext` used for the TLS connection.
251246
Use `io.netty.handler.ssl.SslContextBuilder#forClient` to configure it.
252-
The server certificate chain and the client private key are the typical
253-
elements that need to be configured.
247+
The server certificate chain, the client private key, and hostname verification are the usual elements that need to be configured.
254248
|The JDK trust manager and no client private key.
255249

256250
|`tls#trustEverything`

src/main/java/com/rabbitmq/stream/EnvironmentBuilder.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -442,25 +442,31 @@ interface TlsConfiguration {
442442
* <p>Hostname verification is enabled by default.
443443
*
444444
* @return the TLS configuration helper
445+
* @deprecated use {@link SslContextBuilder#endpointIdentificationAlgorithm(String)} with {@link
446+
* #sslContext(SslContext)}
445447
*/
448+
@Deprecated(forRemoval = true)
446449
TlsConfiguration hostnameVerification();
447450

448451
/**
449452
* Enable or disable hostname verification.
450453
*
451454
* <p>Hostname verification is enabled by default.
452455
*
453-
* @param hostnameVerification
456+
* @param hostnameVerification whether to enable hostname verification or not
454457
* @return the TLS configuration helper
458+
* @deprecated use {@link SslContextBuilder#endpointIdentificationAlgorithm(String)} with {@link
459+
* #sslContext(SslContext)}
455460
*/
461+
@Deprecated(forRemoval = true)
456462
TlsConfiguration hostnameVerification(boolean hostnameVerification);
457463

458464
/**
459465
* Netty {@link SslContext} for TLS connections.
460466
*
461467
* <p>Use {@link SslContextBuilder#forClient()} to configure and create an instance.
462468
*
463-
* @param sslContext
469+
* @param sslContext the SSL context
464470
* @return the TLS configuration helper
465471
*/
466472
TlsConfiguration sslContext(SslContext sslContext);

src/main/java/com/rabbitmq/stream/impl/Client.java

-15
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@
9696
import java.util.function.Consumer;
9797
import java.util.function.Supplier;
9898
import java.util.function.ToLongFunction;
99-
import javax.net.ssl.SSLEngine;
10099
import javax.net.ssl.SSLHandshakeException;
101-
import javax.net.ssl.SSLParameters;
102100
import org.slf4j.Logger;
103101
import org.slf4j.LoggerFactory;
104102

@@ -280,13 +278,6 @@ public void initChannel(SocketChannel ch) {
280278
SslHandler sslHandler =
281279
parameters.sslContext.newHandler(ch.alloc(), parameters.host, parameters.port);
282280

283-
if (parameters.tlsHostnameVerification) {
284-
SSLEngine sslEngine = sslHandler.engine();
285-
SSLParameters sslParameters = sslEngine.getSSLParameters();
286-
sslParameters.setEndpointIdentificationAlgorithm("HTTPS");
287-
sslEngine.setSSLParameters(sslParameters);
288-
}
289-
290281
ch.pipeline().addFirst("ssl", sslHandler);
291282
}
292283
channelCustomizer.accept(ch);
@@ -2375,7 +2366,6 @@ public static class ClientParameters {
23752366
private ChunkChecksum chunkChecksum = JdkChunkChecksum.CRC32_SINGLETON;
23762367
private MetricsCollector metricsCollector = NoOpMetricsCollector.SINGLETON;
23772368
private SslContext sslContext;
2378-
private boolean tlsHostnameVerification = true;
23792369
private ByteBufAllocator byteBufAllocator;
23802370
private Duration rpcTimeout;
23812371
private Consumer<Channel> channelCustomizer = noOpConsumer();
@@ -2532,11 +2522,6 @@ public ClientParameters sslContext(SslContext sslContext) {
25322522
return this;
25332523
}
25342524

2535-
public ClientParameters tlsHostnameVerification(boolean tlsHostnameVerification) {
2536-
this.tlsHostnameVerification = tlsHostnameVerification;
2537-
return this;
2538-
}
2539-
25402525
public ClientParameters compressionCodecFactory(
25412526
CompressionCodecFactory compressionCodecFactory) {
25422527
this.compressionCodecFactory = compressionCodecFactory;

src/main/java/com/rabbitmq/stream/impl/StreamEnvironment.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,13 @@ class StreamEnvironment implements Environment {
129129
try {
130130
SslContext sslContext =
131131
tlsConfiguration.sslContext() == null
132-
? SslContextBuilder.forClient().build()
132+
? SslContextBuilder.forClient()
133+
.endpointIdentificationAlgorithm(
134+
tlsConfiguration.hostnameVerificationEnabled() ? "HTTPS" : null)
135+
.build()
133136
: tlsConfiguration.sslContext();
134137

135138
clientParametersPrototype.sslContext(sslContext);
136-
clientParametersPrototype.tlsHostnameVerification(
137-
tlsConfiguration.hostnameVerificationEnabled());
138139

139140
} catch (SSLException e) {
140141
throw new StreamException("Error while creating Netty SSL context", e);

src/main/java/com/rabbitmq/stream/impl/StreamEnvironmentBuilder.java

+3
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,14 @@ private DefaultTlsConfiguration(EnvironmentBuilder environmentBuilder) {
373373
}
374374

375375
@Override
376+
@SuppressWarnings("removal")
376377
public TlsConfiguration hostnameVerification() {
377378
this.hostnameVerification = true;
378379
return this;
379380
}
380381

381382
@Override
383+
@SuppressWarnings("removal")
382384
public TlsConfiguration hostnameVerification(boolean hostnameVerification) {
383385
this.hostnameVerification = hostnameVerification;
384386
return this;
@@ -400,6 +402,7 @@ public TlsConfiguration trustEverything() {
400402
this.sslContext(
401403
SslContextBuilder.forClient()
402404
.trustManager(Utils.TRUST_EVERYTHING_TRUST_MANAGER)
405+
.endpointIdentificationAlgorithm("NONE")
403406
.build());
404407
} catch (SSLException e) {
405408
throw new StreamException("Error while creating Netty SSL context", e);

src/test/java/com/rabbitmq/stream/impl/TlsTest.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,12 @@ void hostnameVerificationShouldFailWhenSettingHostToLoopbackInterface() throws E
295295
@Test
296296
void shouldConnectWhenSettingHostToLoopbackInterfaceAndDisablingHostnameVerification()
297297
throws Exception {
298-
SslContext context = SslContextBuilder.forClient().trustManager(caCertificate()).build();
299-
cf.get(
300-
new ClientParameters()
301-
.sslContext(context)
302-
.host("127.0.0.1")
303-
.tlsHostnameVerification(false));
298+
SslContext context =
299+
SslContextBuilder.forClient()
300+
.endpointIdentificationAlgorithm(null)
301+
.trustManager(caCertificate())
302+
.build();
303+
cf.get(new ClientParameters().sslContext(context).host("127.0.0.1"));
304304
}
305305

306306
@Test

0 commit comments

Comments
 (0)