Skip to content

Commit

Permalink
Ensure Reactor-Netty Forward Compatibility
Browse files Browse the repository at this point in the history
Motivation:
A change in `r.n.t.SslProvider.ProtocolSslContextSpec` breaks forward
compatibility.

Modifications:
Remove Usage of `ProtocolSslContextSpec`.

Result:
The SSL context is now correctly initialized under the old reactor-netty
version, ensuring forward compatibility.
  • Loading branch information
jchrys committed Feb 20, 2025
1 parent e211cd8 commit 5425fbb
Showing 1 changed file with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import reactor.core.Exceptions;
import reactor.netty.tcp.SslProvider;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLException;
import java.io.File;
import java.net.InetSocketAddress;
import java.util.function.Consumer;

import static io.asyncer.r2dbc.mysql.internal.util.AssertUtils.requireNonNull;
import static io.netty.handler.ssl.SslProvider.JDK;
Expand Down Expand Up @@ -151,10 +151,16 @@ private void handleSslState(ChannelHandlerContext ctx, SslState state) {
switch (state) {
case BRIDGING:
logger.debug("SSL event triggered, enable SSL handler to pipeline");

SslProvider sslProvider = SslProvider.builder()
.sslContext(MySqlSslContextSpec.forClient(ssl, context))
.build();
final SslProvider sslProvider;
try {
// Workaround for a forward incompatible change in reactor-netty version 1.2.0
// See: https://github.com/reactor/reactor-netty/commit/6d0c24d83a7c5b15e403475272293f847415191c
sslProvider = SslProvider.builder()
.sslContext(MySqlSslContextSpec.forClient(ssl, context).sslContext())
.build();
} catch (SSLException e) {
throw Exceptions.propagate(e);
}
SslHandler sslHandler = sslProvider.getSslContext().newHandler(ctx.alloc());

this.sslEngine = sslHandler.engine();
Expand Down Expand Up @@ -195,24 +201,14 @@ private static boolean isTls13Enabled(ConnectionContext context) {
|| (version.isGreaterThanOrEqualTo(MYSQL_5_6_0) && version.isEnterprise());
}

private static final class MySqlSslContextSpec implements SslProvider.ProtocolSslContextSpec {
private static final class MySqlSslContextSpec {

private final SslContextBuilder builder;

private MySqlSslContextSpec(SslContextBuilder builder) {
this.builder = builder;
}

@Override
public MySqlSslContextSpec configure(Consumer<SslContextBuilder> customizer) {
requireNonNull(customizer, "customizer must not be null");

customizer.accept(builder);

return this;
}

@Override
public SslContext sslContext() throws SSLException {
return builder.build();
}
Expand Down

0 comments on commit 5425fbb

Please sign in to comment.