2016-07-05 24 views
1

我最近添加了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) { 

    } 
} 

我難倒了,任何幫助將不勝感激!

+0

您可能需要提供更多詳細信息。使用自簽名證書我假設?什麼java版本? –

+0

我沒有使用自簽名證書,證書來自Namecheap誰使用COMODO SSL作爲CA簽署我的證書。即時通訊使用java 8 – ChrisianBartram

+1

(1)證書與此錯誤無關。 (2)您是否正在使用Java 8的Sun/Oracle版本,如果是,哪些更新或其他Java?在JRE中進行了任何配置更改,特別是在文件'$ JRE/lib/security/java.security'中? (3)您是否有任何系統屬性設置爲「https」,特別是「https.protocols」? (4)嘗試使用sysprop'javax.net.debug = ssl'運行併發布結果,除非如果您的信任庫有很多證書(默認情況下),那麼可以將該部分降至最低。 –

回答

1

協議被禁用或加密套件都不合適
這個問題的關鍵在於這種說法。它的基本含義是:

  1. 客戶端使用的TLS實現不支持服務器證書使用的密碼套件。
  2. 服務器上的TLS配置已禁用客戶端支持的密碼套件。
  3. 客戶端上的TLS配置會禁用服務器提供的密碼套件。
  4. 客戶端和服務器之間的TLS版本不兼容。

這會導致TLS握手失敗,並且連接失敗。選中上述三種情況中的一種或全部。

+0

即使在發送到服務器之前,也會發生此異常。 –

+0

它似乎在TLS握手期間發生。 – automaton

+0

它在握手_logic_中,但是如果您通過代碼追蹤它在某處(在特別是ClientHello)之前的某個點,則在socket = TCP級別發送。 (TCP SYN/ACK已經完成,如果您計算的話,但與SSL/TLS無關。) –

相關問題