SSLHandShakeException没有适当的协议 [英] SSLHandShakeException No Appropriate Protocol

查看:204
本文介绍了SSLHandShakeException没有适当的协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在我的网站上添加了SSL,可以通过https访问。现在,当我的java应用程序尝试向我的网站发出请求并使用缓冲读取器读取它时,它会生成此堆栈跟踪

I recently added SSL to my website and it can be accessed over https. Now when my java application tries to make requests to my website and read from it with a buffered reader it produces this stack trace

我没有使用自签名证书证书是来自Namecheap,他使用COMODO SSL作为CA来签署我的证书。即时通讯使用java 8

Im not using a self signed certificate the cert is from Namecheap who uses COMODO SSL as the CA to sign my certificate. im using java 8

javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
at sun.security.ssl.Handshaker.activate(Handshaker.java:503)
at sun.security.ssl.SSLSocketImpl.kickstartHandshake(SSLSocketImpl.java:1482)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1351)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)

我的代码非常基本,只是尝试使用缓冲的阅读器阅读我网站上的页面

My code is very basic and simply tries to read the page on my site using a buffered reader

 private void populateDataList() {
    try {
        URL url = new URL("https://myURL.com/Data/Data.txt");
        URLConnection con = url.openConnection();
        con.setRequestProperty("Connection", "close");
        con.setDoInput(true);
        con.setUseCaches(false);

        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String line;
        int i = 0;
        while((line = in.readLine()) != null) {
            this.url.add(i, line);
            i++;
        }
    }   catch (Exception e) {
        e.printStackTrace();
    }

}

我已尝试将我的SSL证书添加到JVM的Keystore和Ive甚至试图用这个代码接受每个证书(这证明了我所知道的SSL的目的)

Ive tried adding my SSL certificate to the JVM's Keystore and Ive also even tried to accept every certificate (which defeats the purpose of SSL I know) with this code

 private void trustCertificate() {
    TrustManager[] trustAllCerts = new TrustManager[] {
            new X509TrustManager() {
                public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                    return new X509Certificate[0];
                }
                public void checkClientTrusted(
                        java.security.cert.X509Certificate[] certs, String authType) {
                }
                public void checkServerTrusted(
                        java.security.cert.X509Certificate[] certs, String authType) {
                }
            }
    };
    try {
        SSLContext sc = SSLContext.getInstance("TLS");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    } catch (GeneralSecurityException e) {
    }
    try {
        URL url = new URL("https://myURL.com/index.php");
        URLConnection con = url.openConnection();
        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String line;
        while((line = br.readLine()) != null) {
            System.out.println(line);
        }

    } catch (Exception e) {

    }
}

我很难过,任何帮助都会非常感激!

Im stumped and any help would be much appreciated!

推荐答案

协议被禁用或密码套件不合适

关键问题出在那个声明中。它基本上意味着:

protocol is disabled or cipher suites are inappropriate
The key to the problem lies in that statement. What it basically means is either:


  1. 客户端使用的TLS实现不支持服务器证书使用的密码套件。

  2. 服务器上的TLS配置已禁用客户端支持的密码套件。

  3. 客户端上的TLS配置禁用服务器提供的密码套件。 / li>
  4. 客户端和服务器之间的TLS版本不兼容。

这会导致TLS中的握手失败,并且连接失败。检查上述三种情况中的一种或全部。

This leads to handshake failure in TLS, and the connection fails. Check one or all of the three scenarios above.

这篇关于SSLHandShakeException没有适当的协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆