From 81e527bce40eb98032a23de31b43c6e38054699d Mon Sep 17 00:00:00 2001 From: jchrys Date: Thu, 8 Feb 2024 04:28:24 +0900 Subject: [PATCH] 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 https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory/pull/1828 --- .../asyncer/r2dbc/mysql/client/SslBridgeHandler.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/asyncer/r2dbc/mysql/client/SslBridgeHandler.java b/src/main/java/io/asyncer/r2dbc/mysql/client/SslBridgeHandler.java index 0ac8e0599..952be3917 100644 --- a/src/main/java/io/asyncer/r2dbc/mysql/client/SslBridgeHandler.java +++ b/src/main/java/io/asyncer/r2dbc/mysql/client/SslBridgeHandler.java @@ -220,11 +220,13 @@ static MySqlSslContextSpec forClient(MySqlSslConfiguration ssl, ConnectionContex .applicationProtocolConfig(null); String[] tlsProtocols = ssl.getTlsVersion(); - if (tlsProtocols.length > 0) { - builder.protocols(tlsProtocols); - } else if (ssl.getSslMode() != SslMode.TUNNEL && isTls13Enabled(context)) { + if (tlsProtocols.length > 0 || ssl.getSslMode() == SslMode.TUNNEL) { + if (tlsProtocols.length > 0) { + builder.protocols(tlsProtocols); + } + } else if (isTls13Enabled(context)) { builder.protocols(TLS_PROTOCOLS); - } else if (ssl.getSslMode() != SslMode.TUNNEL){ + } else { // Not sure if we need to check the JDK version, suggest not. if (logger.isWarnEnabled()) { logger.warn("{} {} does not support TLS1.2, TLS1.1 is disabled in latest JDKs",