Skip to content

Commit 29a7b34

Browse files
committed
Fixed NPE with SslMode.TUNNEL Usage
Motivation: A NPE was identified when utilizing `SslMode.TUNNEL`, introduced by PR #204. The issue arises when `ConnectionContext#isMariaDb` is invoked from `SslBridgeHandler#isTls13Enabled`, leading to an NPE due to the ConnectionContext not being initialized at that time. Modification: We have updated ConnectionContext#isMariaDb to return false if the context has not been initialized, preventing the NPE. (Mainly to restore previous behavior) Result: This change addresses the NPE issue, ensuring stability when `SslMode.TUNNEL` is selected. It resolves the problem reported in GoogleCloudPlatform/cloud-sql-jdbc-socket-factory#1828
1 parent 2054a76 commit 29a7b34

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

src/main/java/io/asyncer/r2dbc/mysql/client/SslBridgeHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ static MySqlSslContextSpec forClient(MySqlSslConfiguration ssl, ConnectionContex
222222

223223
if (tlsProtocols.length > 0) {
224224
builder.protocols(tlsProtocols);
225-
} else if (isTls13Enabled(context)) {
225+
} else if (ssl.getSslMode() == SslMode.TUNNEL|| isTls13Enabled(context)) {
226226
builder.protocols(TLS_PROTOCOLS);
227227
} else {
228228
// Not sure if we need to check the JDK version, suggest not.

src/test/java/io/asyncer/r2dbc/mysql/SslTunnelIntegrationTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class SslTunnelIntegrationTest {
5858
public void setUp() throws CertificateException, SSLException {
5959
server = new SelfSignedCertificate();
6060
client = new SelfSignedCertificate();
61-
final SslContext sslContext = SslContextBuilder.forServer(server.key(), server.cert()).build();
61+
final SslContext sslContext = SslContextBuilder.forServer(server.key(), server.cert()).protocols(TlsVersions.TLS1_1, TlsVersions.TLS1, TlsVersions.TLS1_2, TlsVersions.TLS1_3).build();
6262
sslTunnelServer = new SslTunnelServer("localhost", 3306, sslContext);
6363
sslTunnelServer.setUp();
6464
}
@@ -87,7 +87,6 @@ public void sslTunnelConnectionTest() {
8787
.database("r2dbc")
8888
.createDatabaseIfNotExist(true)
8989
.sslMode(SslMode.TUNNEL)
90-
.tlsVersion(TlsVersions.TLS1_3, TlsVersions.TLS1_2)
9190
.sslKey(client.privateKey().getAbsolutePath())
9291
.sslCert(client.certificate().getAbsolutePath())
9392
.sslCa(server.certificate().getAbsolutePath())

0 commit comments

Comments
 (0)