tsaarni commented on code in PR #1919:
URL: https://github.com/apache/zookeeper/pull/1919#discussion_r1338936374


##########
zookeeper-server/src/main/java/org/apache/zookeeper/common/X509Util.java:
##########
@@ -81,7 +87,32 @@ public abstract class X509Util implements Closeable, 
AutoCloseable {
         }
     }
 
-    public static final String DEFAULT_PROTOCOL = "TLSv1.2";
+    public static final String DEFAULT_PROTOCOL = defaultTlsProtocol();
+
+    /**
+     * Return TLSv1.3 or TLSv1.2 depending on Java runtime version being used.
+     * TLSv1.3 was first introduced in JDK11 and back-ported to OpenJDK 8u272.
+     */
+    private static String defaultTlsProtocol() {
+        String defaultProtocol = "TLSv1.2";
+        List<String> supported = new ArrayList<>();
+        try {
+            supported = 
Arrays.asList(SSLContext.getDefault().getSupportedSSLParameters().getProtocols());
+            if (supported.contains("TLSv1.3")) {
+                defaultProtocol = "TLSv1.3";
+            }
+        } catch (NoSuchAlgorithmException e) {
+            // Ignore.
+        }
+        LOG.info("Default TLS protocol is {}, supported TLS protocols are {}", 
defaultProtocol, supported);
+        return defaultProtocol;
+    }
+
+    // ChaCha20 was introduced in OpenJDK 11.0.15 and it is not supported by 
JDK8.
+    private static String[] getTLSv13Ciphers() {
+        return new String[]{"TLS_AES_256_GCM_SHA384", 
"TLS_AES_128_GCM_SHA256", "TLS_CHACHA20_POLY1305_SHA256"};
+    }

Review Comment:
   Since the cipher list is hardcoded, I needed to extend it with TLSv1.3 
ciphers. My approach was to list all TLSv1.3 ciphers that JDK would normally 
enable by default. So, I created the list by checking what 
`SSLServerSocketFactory.getDefault().getDefaultCipherSuites()` returns on 
recent JDK, and out from that list I picked the ones that are for TLSv1.3. This 
also happens to match with list recommended here 
https://wiki.mozilla.org/Security/Server_Side_TLS#Modern_compatibility.
   
   There are more TLSv1.3 ciphers in JDK, but Java does not enable them by 
default  
https://docs.oracle.com/en/java/javase/17/docs/specs/security/standard-names.html#jsse-cipher-suite-names
 (see rows where column "Introduced in" says TLSv1.3).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to