2014-10-12 4 views
4

서버에 연결하는 동안 문제가 발생했습니다. 나는 많은 예를 들었지만 연결을 얻지 못했습니다. 사이트는 https://sikuani.udea.edu.co:4443이며 인증서가 있습니다 (Chrome에 따르면 버전 3 임). SSLv3 연결이 작동하지 않습니다.

나는이 작업을 수행하는 기본 프로그램을 가지고 있지만 항상이이 오류와 함께 실패 :

import java.net.URL; 
import java.io.*; 
import javax.net.ssl.HttpsURLConnection; 

public class Test 
{ 
    public static void main(String[] args) { 
     System.setProperty("https.protocols", "SSLv3"); 
     System.setProperty("javax.net.debug", "all"); 

     String httpsURL = "https://sikuani.udea.edu.co:4443"; 
     URL myurl = new URL(httpsURL); 
     HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection(); 
     InputStream ins = con.getInputStream(); 
     InputStreamReader isr = new InputStreamReader(ins); 
     BufferedReader in = new BufferedReader(isr); 

     String inputLine; 

     while ((inputLine = in.readLine()) != null) { 
      System.out.println(inputLine); 
     } 

     in.close(); 
    } 
} 

I :

Exception in thread "main" javax.net.ssl.SSLException: Received fatal alert: unexpected_message 

또는

Exception in thread "main" javax.net.ssl.SSLException: Received fatal alert: close_notify 

내 코드입니다 구글, 여기에, 자바의 foros 검색 한 적이 있지만 해결책을 찾지 못했습니다 (일부 foros는 자바 오류, 다른 것들은 SSL을 사용하여 v3 params이면 충분하며 trusStore를 만드는 다른 매개 변수는 작동합니다.)

가까운 솔루션이 trustStore와 인증서를 사용하고 있다고 생각하지만이 작업을 수행하는 올바른 params를 설정하는 방법을 알지 못합니다.

도움 주셔서 감사합니다.

편집 :

이는 System.setProperty를 사용하여 내 출력 ("javax.net.debug의를", "SSL, 악수") ;:

// A lot of certificates are loaded... 
trigger seeding of SecureRandom 
done seeding SecureRandom 
Ignoring unavailable cipher suite: TLS_DHE_DSS_WITH_AES_256_GCM_SHA384 
Ignoring unavailable cipher suite: TLS_RSA_WITH_AES_256_CBC_SHA 
Ignoring unavailable cipher suite: TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 
Ignoring unavailable cipher suite: TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA 
Ignoring unavailable cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 
Ignoring unavailable cipher suite: TLS_RSA_WITH_AES_256_CBC_SHA256 
Ignoring unavailable cipher suite: TLS_DHE_DSS_WITH_AES_256_CBC_SHA 
Ignoring unavailable cipher suite: TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 
Ignoring unavailable cipher suite: TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 
Ignoring unavailable cipher suite: TLS_RSA_WITH_AES_256_GCM_SHA384 
Ignoring unavailable cipher suite: TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 
Ignoring unavailable cipher suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 
Ignoring unavailable cipher suite: TLS_ECDH_RSA_WITH_AES_256_CBC_SHA 
Ignoring unavailable cipher suite: TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 
Ignoring unavailable cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 
Ignoring unavailable cipher suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 
Ignoring unavailable cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA 
Ignoring unavailable cipher suite: TLS_DHE_DSS_WITH_AES_256_CBC_SHA256 
Ignoring unavailable cipher suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA 
Ignoring unavailable cipher suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA 
Ignoring unavailable cipher suite: TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 
Allow unsafe renegotiation: false 
Allow legacy hello messages: true 
Is initial handshake: true 
Is secure renegotiation: false 
main, setSoTimeout(0) called 
Ignoring unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 for SSLv3 
Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 for SSLv3 
Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_128_CBC_SHA256 for SSLv3 
Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 for SSLv3 
Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 for SSLv3 
Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 for SSLv3 
Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 for SSLv3 
Ignoring unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 
Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 
Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_128_CBC_SHA256 
Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 
Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 
Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 
Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 
Ignoring unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 
Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 
Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_128_GCM_SHA256 
Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 
Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 
Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 
Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_128_GCM_SHA256 
%% No cached client session 
*** ClientHello, SSLv3 
RandomCookie: GMT: 1413064824 bytes = { 174, 241, 202, 226, 44, 117, 251, 126, 253, 137, 159, 14, 36, 19, 204, 203, 101, 47, 192, 51, 106, 143, 205, 111, 4, 139, 102, 89 } 
Session ID: {} 
Cipher Suites: [TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, TLS_ECDHE_RSA_WITH_RC4_128_SHA, SSL_RSA_WITH_RC4_128_SHA, TLS_ECDH_ECDSA_WITH_RC4_128_SHA, TLS_ECDH_RSA_WITH_RC4_128_SHA, TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_RC4_128_MD5, TLS_EMPTY_RENEGOTIATION_INFO_SCSV] 
Compression Methods: { 0 } 
Extension elliptic_curves, curve names: {secp256r1, sect163k1, sect163r2, secp192r1, secp224r1, sect233k1, sect233r1, sect283k1, sect283r1, secp384r1, sect409k1, sect409r1, secp521r1, sect571k1, sect571r1, secp160k1, secp160r1, secp160r2, sect163r1, secp192k1, sect193r1, sect193r2, secp224k1, sect239k1, secp256k1} 
Extension ec_point_formats, formats: [uncompressed] 
Extension server_name, server_name: [type=host_name (0), value=sikuani.udea.edu.co] 
*** 
main, WRITE: SSLv3 Handshake, length = 177 
main, READ: SSLv3 Alert, length = 2 
main, RECV TLSv1.2 ALERT: fatal, close_notify 
main, called closeSocket() 
main, handling exception: javax.net.ssl.SSLException: Received fatal alert: close_notify 
Exception in thread "main" javax.net.ssl.SSLException: Received fatal alert: close_notify 
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:208) 
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:154) 
    at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1991) 
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1104) 
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1343) 
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1371) 
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1355) 
    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.getInputStream0(HttpURLConnection.java:1511) 
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1439) 
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254) 
    at Test.main(Test.java:44) 

I이 제거 된 경우

: 여기
main, WRITE: TLSv1.2 Handshake, length = 235 
main, READ: TLSv1 Alert, length = 2 
main, RECV TLSv1.2 ALERT: fatal, unexpected_message main, called closeSocket() 
main, handling exception: javax.net.ssl.SSLException: Received fatal alert: unexpected_message 
Exception in thread "main" javax.net.ssl.SSLException: Received fatal alert: unexpected_message – 
+0

문제는 서버 쪽 일 수 있습니까? 'https : // www.google.com /'에 연결하려고하면 모든 것이 정상적으로 작동합니다. – dds

+0

하지만 서버가 작동 중입니다. 브라우저에서 동일한 URL을 사용해도 정상적으로 작동합니다. –

+0

'jqvax.net.debug = ssl, handshake ''에 의해 인쇄 된 것을 게시하십시오. 질문에 편집하십시오 : – EJP

답변

2

당신이 다음 사용해야하는 코드입니다 : SSLv3에의 프로토콜을 설정 라인,이이
import java.io.BufferedReader; 
import java.io.InputStream; 
import java.io.InputStreamReader; 
import java.net.HttpURLConnection; 
import java.net.URL; 

public class Test { 
    public static void main(String[] args) { 
     System.setProperty("https.protocols", "TLSv1,SSLv3,SSLv2Hello"); 
     System.setProperty("javax.net.debug", "all"); 

     try{ 
      String httpsURL = "https://sikuani.udea.edu.co:4443"; 
      URL myurl = new URL(httpsURL); 
      HttpURLConnection con = (HttpURLConnection)myurl.openConnection(); 
      InputStream ins = con.getInputStream(); 
      InputStreamReader isr = new InputStreamReader(ins); 
      BufferedReader in = new BufferedReader(isr); 

      String inputLine; 

      while ((inputLine = in.readLine()) != null) { 
       System.out.println(inputLine); 
      } 

      in.close(); 
     } 
     catch(Exception ex){ 

     } 
    } 
} 

무슨 일이 일어나고 있는지 볼 수 있도록 디버그 상태로 둡니다. 내가받은 의견에 따라 코드를 변경했습니다. 내가 추가 한 선을 더할 여지는 없었습니다. 또한 확장 이후 대신 HttpURLConnection을 사용할 수 있습니다. 'SSLv2Hello'를 추가하면 문제가 해결됩니다.

나는 이것이 작동해야한다고 생각한다. - 지금 시도해 보라.

+0

안녕하세요, Alvin, Eclipse가 없어요. 콘솔을 통해 작업하고 있는데,이 두 줄을 추가했습니다. 이 오류가 지금 있습니다 : '스레드 "main"의 예외 "java.lang.ClassCastException : com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl을 javax.net.ssl.HttpsURLConnection로 캐스팅 할 수 없습니다." ' –

+0

위의 수정 된 코드를 사용하십시오! –

+0

Alvin, 코드를 복사했지만 여전히 작동하지 않습니다 (동일한 오류가 발생합니다). jdk-1.8.0_20.jdk를 사용하고 있습니다. –

1

SSLv3 프로토콜을 설정하는 줄을 제거하십시오. 너는 필요 없어. X509 버전 3은 SSLv3과 동일하지 않습니다.

+0

안녕 EJP, 나는이 있습니다 '주, WRITE : TLSv1.2 핸드 셰이크, 길이 = 235 주, READ : TLSv1의 경고를, 길이 = 2 주, RECV TLSv1.2 경고를 : fatal, unexpected_message main, closeSocket() 호출 주 처리 예외 : javax.net.ssl.SSLException : 치명적인 경고 수신 : unexpected_message 스레드 "main"의 예외 javax.net.ssl.SSLException : 치명적인 경고 수신 : unexpected_message ' –

+0

호기심. 만약 내가 그것을 제거하면'illegal_parameter '입니다.'TLSv1'로 설정하면'unexpected_message'가됩니다.'SSLv3'으로 설정하면'close_notify.'입니다. – EJP

+1

@EJP, 내 코드 샘플에 추가 한'System.setProperty ("https.protocols", "SSLv3, SSLv2Hello"); 비슷한 오류 메시지가 나타났습니다. –

관련 문제