Add java8-to-25 module: legacy Java 8 app run on JDK 8, 17 and 25, tool coverage, JVM flags, libraries, OpenRewrite and the fixed version
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6vDJ5fWY5uEZaJFNi
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import java.io.FileInputStream;
|
||||
import java.security.KeyStore;
|
||||
import java.security.Security;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
import javax.net.ssl.SSLServerSocket;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
|
||||
/** Prints the TLS and keystore defaults of the running JDK and tries three handshakes.
|
||||
* Usage: java CryptoDefaults keystore.p12 (store password "changeit"). Compiles on JDK 8. */
|
||||
public class CryptoDefaults {
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println("java.version = " + System.getProperty("java.version"));
|
||||
System.out.println("keystore.type = " + KeyStore.getDefaultType());
|
||||
SSLParameters p = SSLContext.getDefault().getDefaultSSLParameters();
|
||||
System.out.println("protocols = " + Arrays.toString(p.getProtocols()));
|
||||
List<String> rsaKx = new ArrayList<String>();
|
||||
for (String s : p.getCipherSuites()) if (s.startsWith("TLS_RSA_")) rsaKx.add(s);
|
||||
System.out.println("cipher suites = " + p.getCipherSuites().length + " enabled, "
|
||||
+ rsaKx.size() + " of them TLS_RSA_*");
|
||||
for (String key : new String[] {"jdk.tls.disabledAlgorithms", "jdk.jar.disabledAlgorithms"}) {
|
||||
System.out.println(key + " =");
|
||||
for (String item : Security.getProperty(key).split(",")) System.out.println(" " + item.trim());
|
||||
}
|
||||
|
||||
KeyStore ks = KeyStore.getInstance("PKCS12");
|
||||
try (FileInputStream in = new FileInputStream(args[0])) { ks.load(in, "changeit".toCharArray()); }
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(ks, "changeit".toCharArray());
|
||||
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||||
tmf.init(ks);
|
||||
SSLContext ctx = SSLContext.getInstance("TLS");
|
||||
ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
|
||||
|
||||
handshake(ctx, "TLSv1.2 default suites", "TLSv1.2", null);
|
||||
handshake(ctx, "TLSv1.1 only", "TLSv1.1", null);
|
||||
handshake(ctx, "TLS_RSA_WITH_AES_128_GCM_SHA256", "TLSv1.2", "TLS_RSA_WITH_AES_128_GCM_SHA256");
|
||||
}
|
||||
|
||||
static void handshake(SSLContext ctx, String label, String protocol, String suite) throws Exception {
|
||||
final SSLServerSocket server = (SSLServerSocket) ctx.getServerSocketFactory().createServerSocket(0);
|
||||
server.setEnabledProtocols(new String[] {"TLSv1.2", "TLSv1.1"});
|
||||
server.setEnabledCipherSuites(server.getSupportedCipherSuites());
|
||||
Thread t = new Thread(() -> {
|
||||
try (SSLSocket s = (SSLSocket) server.accept()) { s.startHandshake(); s.getOutputStream().write(1); }
|
||||
catch (Exception ignored) { }
|
||||
});
|
||||
t.start();
|
||||
try (SSLSocket c = (SSLSocket) ctx.getSocketFactory().createSocket("localhost", server.getLocalPort())) {
|
||||
c.setEnabledProtocols(new String[] {protocol});
|
||||
if (suite != null) c.setEnabledCipherSuites(new String[] {suite});
|
||||
c.startHandshake();
|
||||
c.getInputStream().read();
|
||||
System.out.println("[ok] " + label + " -> " + c.getSession().getProtocol() + " " + c.getSession().getCipherSuite());
|
||||
} catch (Exception e) {
|
||||
System.out.println("[FAIL] " + label + " -> " + e.getClass().getName() + ": " + e.getMessage());
|
||||
} finally {
|
||||
t.join(3000);
|
||||
server.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user