使用HttpsURLConnection获取handshake_failure。需要使用jdk1,7

问题描述 投票:0回答:2

我有一个非常简单的示例代码。

        String https_url = "https://www.somesite.ca";
        URL url;
        try {
            url = new URL(https_url);
            HttpsURLConnection con = (HttpsURLConnection) url.openConnection();

            System.out.println("****** Content of the URL ********");
            BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));

            String input;

            while ((input = br.readLine()) != null) {
                System.out.println(input);
            }
            br.close();


        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

它可以在我访问的所有站点上正常工作,除了一个。那个网站刚刚开始失败,但是例外

javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
    at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1979)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1086)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1301)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
    at com.unitnet.utils.intouch.TestSSL.testIt(TestSSL.java:42)
    at com.unitnet.utils.intouch.TestSSL.main(TestSSL.java:16)

我可以通过运行jdk1.8使其工作,但这不是一个选项。我真的需要让它与1.7一起工作

有没有人有任何可以帮助我的工作

谢谢

java java-7 apache-commons-httpclient
2个回答
0
投票

安装Java Cryptography Extension(JCE)Unlimited Strength为我解决了这个问题。

资料来源:here


-1
投票

该问题的解决方案启用了JDK 1.7中的TLS

jdk.tls.disabledAlgorithms= SSLv2Hello, SSLv3, TLSv1, TLSv1.1

在服务器上的文件jre / lib / security / java.security中设置此项后,服务器仅接受TLS1.2连接并拒绝较低安全协议版本。这仅适用于Java 7更新75及更高版本。 for more

© www.soinside.com 2019 - 2024. All rights reserved.