|
@@ -36,16 +36,13 @@ import java.security.cert.X509CertSelector;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.function.Supplier;
|
|
|
-import java.util.stream.Collectors;
|
|
|
import javax.net.ssl.CertPathTrustManagerParameters;
|
|
|
import javax.net.ssl.KeyManager;
|
|
|
import javax.net.ssl.KeyManagerFactory;
|
|
|
import javax.net.ssl.SSLContext;
|
|
|
import javax.net.ssl.SSLServerSocket;
|
|
|
-import javax.net.ssl.SSLServerSocketFactory;
|
|
|
import javax.net.ssl.SSLSocket;
|
|
|
import javax.net.ssl.TrustManager;
|
|
|
import javax.net.ssl.TrustManagerFactory;
|
|
@@ -62,11 +59,6 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
|
/**
|
|
|
* Utility code for X509 handling
|
|
|
- *
|
|
|
- * Default cipher suites:
|
|
|
- *
|
|
|
- * Performance testing done by Facebook engineers shows that on Intel x86_64 machines, Java9 performs better with
|
|
|
- * GCM and Java8 performs better with CBC, so these seem like reasonable defaults.
|
|
|
*/
|
|
|
public abstract class X509Util implements Closeable, AutoCloseable {
|
|
|
|
|
@@ -102,6 +94,8 @@ public abstract class X509Util implements Closeable, AutoCloseable {
|
|
|
List<String> supported = new ArrayList<>();
|
|
|
try {
|
|
|
supported = Arrays.asList(SSLContext.getDefault().getSupportedSSLParameters().getProtocols());
|
|
|
+ // We cannot use the default protocols directly, because the SSLContext factory methods
|
|
|
+ // only accept a single protocol
|
|
|
if (supported.contains(TLS_1_3)) {
|
|
|
defaultProtocol = TLS_1_3;
|
|
|
}
|
|
@@ -112,36 +106,6 @@ public abstract class X509Util implements Closeable, AutoCloseable {
|
|
|
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"};
|
|
|
- }
|
|
|
-
|
|
|
- private static String[] getGCMCiphers() {
|
|
|
- return new String[]{"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"};
|
|
|
- }
|
|
|
-
|
|
|
- private static String[] getCBCCiphers() {
|
|
|
- return new String[]{"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384", "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384", "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA"};
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Returns a filtered set of ciphers, where ciphers not supported by the JDK are removed.
|
|
|
- */
|
|
|
- private static String[] getSupportedCiphers(String[]... cipherLists) {
|
|
|
- List<String> supported = Arrays.asList(
|
|
|
- ((SSLServerSocketFactory) SSLServerSocketFactory.getDefault()).getSupportedCipherSuites());
|
|
|
-
|
|
|
- return Arrays.stream(cipherLists).flatMap(Arrays::stream).filter(supported::contains).collect(Collectors.toList()).toArray(new String[0]);
|
|
|
- }
|
|
|
-
|
|
|
- // On Java 8, prefer CBC ciphers since AES-NI support is lacking and GCM is slower than CBC.
|
|
|
- private static final String[] DEFAULT_CIPHERS_JAVA8 = getSupportedCiphers(getCBCCiphers(), getGCMCiphers(), getTLSv13Ciphers());
|
|
|
- // On Java 9 and later, prefer GCM ciphers due to improved AES-NI support.
|
|
|
- // Note that this performance assumption might not hold true for architectures other than x86_64.
|
|
|
- // TLSv1.3 ciphers can be added at the end of the list without impacting the priority of TLSv1.3 vs TLSv1.2.
|
|
|
- private static final String[] DEFAULT_CIPHERS_JAVA9 = getSupportedCiphers(getGCMCiphers(), getCBCCiphers(), getTLSv13Ciphers());
|
|
|
-
|
|
|
public static final int DEFAULT_HANDSHAKE_DETECTION_TIMEOUT_MILLIS = 5000;
|
|
|
|
|
|
/**
|
|
@@ -636,26 +600,6 @@ public abstract class X509Util implements Closeable, AutoCloseable {
|
|
|
return getDefaultSSLContextAndOptions().createSSLServerSocket(port);
|
|
|
}
|
|
|
|
|
|
- static String[] getDefaultCipherSuites() {
|
|
|
- return getDefaultCipherSuitesForJavaVersion(System.getProperty("java.specification.version"));
|
|
|
- }
|
|
|
-
|
|
|
- static String[] getDefaultCipherSuitesForJavaVersion(String javaVersion) {
|
|
|
- Objects.requireNonNull(javaVersion);
|
|
|
- if (javaVersion.matches("\\d+")) {
|
|
|
- // Must be Java 9 or later
|
|
|
- LOG.debug("Using Java9+ optimized cipher suites for Java version {}", javaVersion);
|
|
|
- return DEFAULT_CIPHERS_JAVA9;
|
|
|
- } else if (javaVersion.startsWith("1.")) {
|
|
|
- // Must be Java 1.8 or earlier
|
|
|
- LOG.debug("Using Java8 optimized cipher suites for Java version {}", javaVersion);
|
|
|
- return DEFAULT_CIPHERS_JAVA8;
|
|
|
- } else {
|
|
|
- LOG.debug("Could not parse java version {}, using Java8 optimized cipher suites", javaVersion);
|
|
|
- return DEFAULT_CIPHERS_JAVA8;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private FileChangeWatcher newFileChangeWatcher(String fileLocation) throws IOException {
|
|
|
if (fileLocation == null || fileLocation.isEmpty()) {
|
|
|
return null;
|