Skip to content

doc: document how to Disable hostname verification in ssl config #11526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: 4.8.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ public final Optional<SslContext> build(SslConfiguration ssl, HttpVersion httpVe
@NonNull
@Override
public final SslContext build(SslConfiguration ssl, HttpVersionSelection versionSelection) {
try {
return createSslContextBuilder(ssl, versionSelection).build();
} catch (SSLException ex) {
throw new SslConfigurationException("An error occurred while setting up SSL", ex);
}
}

protected SslContextBuilder createSslContextBuilder(SslConfiguration ssl, HttpVersionSelection versionSelection) {
SslContextBuilder sslBuilder = SslContextBuilder
.forClient()
.keyManager(getKeyManagerFactory(ssl))
Expand Down Expand Up @@ -122,12 +130,7 @@ public final SslContext build(SslConfiguration ssl, HttpVersionSelection version
versionSelection.getAlpnSupportedProtocols()
));
}

try {
return sslBuilder.build();
} catch (SSLException ex) {
throw new SslConfigurationException("An error occurred while setting up SSL", ex);
}
return sslBuilder;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.micronaut.http.client.netty.ssl;

import io.micronaut.context.annotation.BootstrapContextCompatible;
import io.micronaut.context.annotation.Replaces;
import io.micronaut.context.annotation.Requires;
import io.micronaut.context.annotation.Secondary;
import io.micronaut.context.env.Environment;
import io.micronaut.core.io.ResourceResolver;
import io.micronaut.http.client.HttpVersionSelection;
import io.micronaut.http.ssl.SslConfiguration;
import io.netty.handler.ssl.SslContextBuilder;
import jakarta.inject.Singleton;

@Requires(env = Environment.TEST)
@Singleton
@BootstrapContextCompatible
@Secondary
@Replaces(NettyClientSslBuilder.class)
class NettyClientSslBuilderReplacement extends NettyClientSslBuilder {
NettyClientSslBuilderReplacement(ResourceResolver resourceResolver) {
super(resourceResolver);
}

@Override
protected SslContextBuilder createSslContextBuilder(SslConfiguration ssl, HttpVersionSelection versionSelection) {
SslContextBuilder builder = super.createSslContextBuilder(ssl, versionSelection);
builder.endpointIdentificationAlgorithm(null);
return builder;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
To use an implementation based on https://netty.io[Netty], add the following dependency to your build:

dependency:micronaut-http-client[]

== Disable hostname verification in ssl config

It may be necessary in a testing or development environment to disable hostname verification.

To disable hostname verification in your test classpath, you could create a <<replaces, Bean Replacement>> in `src/test/java`:

[source,java]
----
include::http-client/src/test/java/io/micronaut/http/client/netty/ssl/NettyClientSslBuilderReplacement.java[indent=0]
----
WARNING: Disabling host name verification leaves your application potentially vulnerable to Man-in-the-Middle attacks and should only be done with the utmost care typically only in a development / testing environment. Never disable host name verification in production or in a scenario where you are making remote calls over the internet.
Loading