【发布时间】:2019-06-20 14:34:35
【问题描述】:
我最近在我的网站上添加了 SSL,它可以通过 https 访问。现在,当我的 java 应用程序尝试向我的网站发出请求并使用缓冲读取器从中读取时,它会产生此堆栈跟踪
我没有使用自签名证书,该证书来自使用 COMODO SSL 作为 CA 签署我的证书的 Namecheap。我正在使用 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)
我的代码非常基本,只是尝试使用缓冲阅读器阅读我网站上的页面
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 的密钥库中,我什至还尝试使用此代码接受每个证书(这违背了我知道的 SSL 的目的)
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) {
}
}
我很难过,任何帮助将不胜感激!
【问题讨论】:
-
您可能需要提供更多详细信息。我假设使用自签名证书?什么java版本?
-
我没有使用自签名证书,该证书来自 Namecheap,他使用 COMODO SSL 作为 CA 来签署我的证书。我正在使用 java 8
-
(1) 证书与此错误无关。 (2) 您使用的是 Java 8 的 Sun/Oracle 版本,如果是,是哪个更新,还是其他 Java?是否在 JRE 中进行了任何配置更改,尤其是在文件
$JRE/lib/security/java.security中? (3) 您是否设置了任何涉及https尤其是https.protocols的系统属性? (4) 尝试使用 syspropjavax.net.debug=ssl运行并发布结果,除非您的信任库有很多证书(默认情况下),您可以将这部分减少到最低限度。 -
请注明您使用的Java版本。如果您添加
-Djavax.net.debug=ssl:handshake:verbose,它将允许您更详细地检查握手问题。
标签: java ssl bufferedreader