My client dials a server. We've recently adopted a security policy to allow only TLS 1.2 connections but we are being soft with the transition: If the server and client cannot agree on a TLS 1.2 socket, then some warning is raised for this issue to be fixed but connection should proceed as normal.
So, I am not really looking for a way to enforce my client to only create TLS 1.2 connection but a way to know which one is currently used.
My question is about how to get that information from the live socket.
Here's how my client creates sockets:
public static SSLSocket getSSLsocket (String hostFQDN, int port, String ksFullPath, String ksPassword, String pkPassword) {
try {
SSLContext context = SSLContext.getInstance("TLS");
KeyManagerFactory keyMngFactory = KeyManagerFactory.getInstance("SunX509");
KeyStore keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(new FileInputStream(ksFullPath), ksPassword.toCharArray());
keyMngFactory.init(keyStore, pkPassword.toCharArray());
context.init(keyMngFactory.getKeyManagers(), null, null);
//TODO: We are going to need a truststore definition... Meanwhile: System.setProperty("javax.net.ssl.trustStore", "src/resources/certificates/epp/cacertsuk");
SSLSocketFactory sslScktFactory = context.getSocketFactory();
return (SSLSocket) sslScktFactory.createSocket(hostFQDN, port);
} catch (Exception e) {
throw new RuntimeException("Could not create SSL socket", e);
}
}
I am aware of this question: How to find what SSL/TLS version is used in Java , where the leading answer seems to say I can get the SSLSession from the SSLSocket and then call .getProtocol... But an example on how to do this was not provided and I was unable to find the solution myself