I need to check, which TLS version is used by certain URLs. I used

try {
    myUrl = new URL(url);

    HttpsURLConnection conn = (HttpsURLConnection) myUrl.openConnection();
    logger.debug("connection made...");
    SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
    conn.setSSLSocketFactory(sslsocketfactory);
    SSLSocket socket = (SSLSocket) sslsocketfactory.createSocket(myUrl.getHost(), 443);

    String[] protocols = socket.getEnabledProtocols();
    String enabledProtocols="";
    for (String protocol : protocols )
        enabledProtocols=enabledProtocols+protocol+" ";
    logger.info("enabled protocols: "+enabledProtocols);
    SSLSession session = socket.getSession();
    logger.info("used protocol: "+session.getProtocol());
    result=result+session.getProtocol()+";"+enabledProtocols+";";
    conn.disconnect();
} catch (Exception e) {
    result=result+"error while connecting to bank";
    logger.debug(url, e);
}

But sslsocketfactory.createSocket seems to be blocked by proxy servers, so I can't use class SSLSocket I get java.net.ConnectException or UnknownHostException. Without proxy, the code works fine

0 Answers