Skip to content

Ensure Reactor-Netty Forward Compatibility #307

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

Merged
merged 1 commit into from
Feb 20, 2025
Merged
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 @@ -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