Skip to content

Commit bdefd1e

Browse files
authored
HBASE-29444 Default to JRE default TLS protcol list (#7142)
1 parent d76bbe2 commit bdefd1e

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

hbase-common/src/main/java/org/apache/hadoop/hbase/io/crypto/tls/X509Util.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ public final class X509Util {
8787
public static final String TLS_CIPHER_SUITES = CONFIG_PREFIX + "ciphersuites";
8888
public static final String TLS_CERT_RELOAD = CONFIG_PREFIX + "certReload";
8989
public static final String TLS_USE_OPENSSL = CONFIG_PREFIX + "useOpenSsl";
90-
public static final String DEFAULT_PROTOCOL = "TLSv1.2";
9190

9291
//
9392
// Server-side specific configs
@@ -206,7 +205,10 @@ public static SslContext createSslContextForClient(Configuration config)
206205
}
207206

208207
sslContextBuilder.enableOcsp(sslOcspEnabled);
209-
sslContextBuilder.protocols(getEnabledProtocols(config));
208+
String[] enabledProtocols = getEnabledProtocols(config);
209+
if (enabledProtocols != null) {
210+
sslContextBuilder.protocols(enabledProtocols);
211+
}
210212
String[] cipherSuites = getCipherSuites(config);
211213
if (cipherSuites != null) {
212214
sslContextBuilder.ciphers(Arrays.asList(cipherSuites));
@@ -276,7 +278,10 @@ public static SslContext createSslContextForServer(Configuration config)
276278
}
277279

278280
sslContextBuilder.enableOcsp(sslOcspEnabled);
279-
sslContextBuilder.protocols(getEnabledProtocols(config));
281+
String[] enabledProtocols = getEnabledProtocols(config);
282+
if (enabledProtocols != null) {
283+
sslContextBuilder.protocols(enabledProtocols);
284+
}
280285
String[] cipherSuites = getCipherSuites(config);
281286
if (cipherSuites != null) {
282287
sslContextBuilder.ciphers(Arrays.asList(cipherSuites));
@@ -391,9 +396,13 @@ static X509TrustManager createTrustManager(String trustStoreLocation, char[] tru
391396
private static String[] getEnabledProtocols(Configuration config) {
392397
String enabledProtocolsInput = config.get(TLS_ENABLED_PROTOCOLS);
393398
if (enabledProtocolsInput == null) {
394-
return new String[] { config.get(TLS_CONFIG_PROTOCOL, DEFAULT_PROTOCOL) };
399+
enabledProtocolsInput = config.get(TLS_CONFIG_PROTOCOL);
400+
}
401+
if (enabledProtocolsInput != null) {
402+
return enabledProtocolsInput.split(",");
403+
} else {
404+
return null;
395405
}
396-
return enabledProtocolsInput.split(",");
397406
}
398407

399408
private static String[] getCipherSuites(Configuration config) {

hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/TestX509Util.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,16 @@ public void testCreateSSLContextWithClientAuthNONE() throws Exception {
9696
public void testCreateSSLContextWithoutCustomProtocol() throws Exception {
9797
SslContext sslContext = X509Util.createSslContextForClient(conf);
9898
ByteBufAllocator byteBufAllocatorMock = mock(ByteBufAllocator.class);
99-
assertArrayEquals(new String[] { X509Util.DEFAULT_PROTOCOL },
99+
assertArrayEquals(new String[] { "TLSv1.3", "TLSv1.2" },
100+
sslContext.newEngine(byteBufAllocatorMock).getEnabledProtocols());
101+
}
102+
103+
@Test
104+
public void testCreateTcNativeSSLContextWithoutCustomProtocol() throws Exception {
105+
conf.set(X509Util.TLS_USE_OPENSSL, "true");
106+
SslContext sslContext = X509Util.createSslContextForClient(conf);
107+
ByteBufAllocator byteBufAllocatorMock = mock(ByteBufAllocator.class);
108+
assertArrayEquals(new String[] { "TLSv1.3", "TLSv1.2" },
100109
sslContext.newEngine(byteBufAllocatorMock).getEnabledProtocols());
101110
}
102111

0 commit comments

Comments
 (0)