我最近添加了SSL到我的網站,它可以通過https訪問。現在,當我的Java應用程序試圖向我的網站發出請求並使用緩衝讀取器讀取它時,它會生成此堆棧跟蹤SSLHandShakeException沒有適當的協議
我沒有使用自簽名證書,證書來自Namecheap,他使用COMODO SSL作爲CA簽名我的證書。即時通訊使用的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 – ChrisianBartram
(1)證書與此錯誤無關。 (2)您是否正在使用Java 8的Sun/Oracle版本,如果是,哪些更新或其他Java?在JRE中進行了任何配置更改,特別是在文件'$ JRE/lib/security/java.security'中? (3)您是否有任何系統屬性設置爲「https」,特別是「https.protocols」? (4)嘗試使用sysprop'javax.net.debug = ssl'運行併發布結果,除非如果您的信任庫有很多證書(默認情況下),那麼可以將該部分降至最低。 –