Skip to content

Commit

Permalink
Fixed NPE with SslMode.TUNNEL Usage
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jchrys committed Feb 7, 2024
1 parent bee7c2c commit 81e527b
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 81e527b

Please sign in to comment.