如何在没有SSLContext的情况下获取URL的TLS版本

时间:2019-05-04 08:07:38

标签: java ssl tls1.2

我需要检查某些URL使用哪个TLS版本。 我用过

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);
}

但是sslsocketfactory.createSocket似乎被代理服务器阻止,所以我不能使用SSLSocket类

0 个答案:

没有答案