Skip to content

Commit 34119d6

Browse files
charlesconnellApache9
authored andcommitted
HBASE-28122: Support TLSv1.3 cipher suites (#5444)
Co-authored-by: Charles Connell <[email protected]> Signed-off-by: Duo Zhang <[email protected]> (cherry picked from commit d8b5198)
1 parent 0c40def commit 34119d6

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

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

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ public final class X509Util {
115115
"hbase.client.netty.tls.handshaketimeout";
116116
public static final int DEFAULT_HANDSHAKE_DETECTION_TIMEOUT_MILLIS = 5000;
117117

118+
private static String[] getTls13Ciphers() {
119+
return new String[] { "TLS_AES_128_GCM_SHA256", "TLS_AES_256_GCM_SHA384" };
120+
}
121+
118122
private static String[] getGCMCiphers() {
119123
return new String[] { "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
120124
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
@@ -136,14 +140,17 @@ private static String[] getCBCCiphers() {
136140
// Note that this performance assumption might not hold true for architectures other than x86_64.
137141
private static final String[] DEFAULT_CIPHERS_JAVA9 =
138142
ObjectArrays.concat(getGCMCiphers(), getCBCCiphers(), String.class);
143+
private static final String[] DEFAULT_CIPHERS_JAVA11 =
144+
ObjectArrays.concat(ObjectArrays.concat(getTls13Ciphers(), getGCMCiphers(), String.class),
145+
getCBCCiphers(), String.class);
139146

140147
private static final String[] DEFAULT_CIPHERS_OPENSSL = getOpenSslFilteredDefaultCiphers();
141148

142149
/**
143150
* Not all of our default ciphers are available in OpenSSL. Takes our default cipher lists and
144-
* filters them to only those available in OpenSsl. Does GCM first, then CBC because GCM tends to
145-
* be better and faster, and we don't need to worry about the java8 vs 9 performance issue if
146-
* OpenSSL is handling it.
151+
* filters them to only those available in OpenSsl. Prefers TLS 1.3, then GCM, then CBC because
152+
* GCM tends to be better and faster, and we don't need to worry about the java8 vs 9 performance
153+
* issue if OpenSSL is handling it.
147154
*/
148155
private static String[] getOpenSslFilteredDefaultCiphers() {
149156
if (!OpenSsl.isAvailable()) {
@@ -152,16 +159,9 @@ private static String[] getOpenSslFilteredDefaultCiphers() {
152159

153160
Set<String> openSslSuites = OpenSsl.availableJavaCipherSuites();
154161
List<String> defaultSuites = new ArrayList<>();
155-
for (String cipher : getGCMCiphers()) {
156-
if (openSslSuites.contains(cipher)) {
157-
defaultSuites.add(cipher);
158-
}
159-
}
160-
for (String cipher : getCBCCiphers()) {
161-
if (openSslSuites.contains(cipher)) {
162-
defaultSuites.add(cipher);
163-
}
164-
}
162+
Arrays.stream(getTls13Ciphers()).filter(openSslSuites::contains).forEach(defaultSuites::add);
163+
Arrays.stream(getGCMCiphers()).filter(openSslSuites::contains).forEach(defaultSuites::add);
164+
Arrays.stream(getCBCCiphers()).filter(openSslSuites::contains).forEach(defaultSuites::add);
165165
return defaultSuites.toArray(new String[0]);
166166
}
167167

@@ -219,10 +219,19 @@ static String[] getDefaultCipherSuites(boolean useOpenSsl) {
219219

220220
static String[] getDefaultCipherSuitesForJavaVersion(String javaVersion) {
221221
Objects.requireNonNull(javaVersion);
222+
222223
if (javaVersion.matches("\\d+")) {
223224
// Must be Java 9 or later
224-
LOG.debug("Using Java9+ optimized cipher suites for Java version {}", javaVersion);
225-
return DEFAULT_CIPHERS_JAVA9;
225+
int javaVersionInt = Integer.parseInt(javaVersion);
226+
if (javaVersionInt >= 11) {
227+
LOG.debug(
228+
"Using Java11+ optimized cipher suites for Java version {}, including TLSv1.3 support",
229+
javaVersion);
230+
return DEFAULT_CIPHERS_JAVA11;
231+
} else {
232+
LOG.debug("Using Java9+ optimized cipher suites for Java version {}", javaVersion);
233+
return DEFAULT_CIPHERS_JAVA9;
234+
}
226235
} else if (javaVersion.startsWith("1.")) {
227236
// Must be Java 1.8 or earlier
228237
LOG.debug("Using Java8 optimized cipher suites for Java version {}", javaVersion);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,21 +379,21 @@ public void testGetDefaultCipherSuitesJava8() {
379379
public void testGetDefaultCipherSuitesJava9() {
380380
String[] cipherSuites = X509Util.getDefaultCipherSuitesForJavaVersion("9");
381381
// Java 9+ default should have the GCM suites first
382-
assertThat(cipherSuites[0], containsString("GCM"));
382+
assertEquals(cipherSuites[0], "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256");
383383
}
384384

385385
@Test
386386
public void testGetDefaultCipherSuitesJava10() {
387387
String[] cipherSuites = X509Util.getDefaultCipherSuitesForJavaVersion("10");
388388
// Java 9+ default should have the GCM suites first
389-
assertThat(cipherSuites[0], containsString("GCM"));
389+
assertEquals(cipherSuites[0], "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256");
390390
}
391391

392392
@Test
393393
public void testGetDefaultCipherSuitesJava11() {
394394
String[] cipherSuites = X509Util.getDefaultCipherSuitesForJavaVersion("11");
395-
// Java 9+ default should have the GCM suites first
396-
assertThat(cipherSuites[0], containsString("GCM"));
395+
// Java 11+ default should have the TLSv1.3 suites first
396+
assertThat(cipherSuites[0], containsString("TLS_AES_128_GCM"));
397397
}
398398

399399
@Test

0 commit comments

Comments
 (0)