2016-08-27 7 views
1

JavaのHttpsURLConnection(Javaバージョン "1.8.0_91")を使用してAWS APIゲートウェイエンドポイントにアクセスしようとしています。致命的なアラートを受信しました:SSLを無効にした後でもハンドシェイクの失敗

https://at0yve8x72.execute-api.us-west-2.amazonaws.com/test/v1/shorten

しかし、私は「受信致命的な警告:握手_」を取得しています私は無効になっSSL証明書の検証を持っているにもかかわらず。

以下のコードで私がコメントした場合HttpsURLConnection.setDefaultHostnameVerifier(hv)すべて正常です。しかし私は他のモジュールに影響を与えるので、これを私のプロジェクトでコメントすることはできません。 DefaultHostnameVerifierを設定するとハンドシェイクが失敗する原因がわかりません。ここで

は、AWSのAPIゲートウェイは完全に私のClientHelloを拒否されたことが表示されますログインする以上のことから

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 TLSv1 
Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 for TLSv1 
Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_128_CBC_SHA256 for TLSv1 
Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 for TLSv1 
Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 for TLSv1 
Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 for TLSv1 
Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 for TLSv1 
Ignoring unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 for TLSv1.1 
Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 for TLSv1.1 
Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_128_CBC_SHA256 for TLSv1.1 
Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 for TLSv1.1 
Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 for TLSv1.1 
Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 for TLSv1.1 
Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 for TLSv1.1 
%% No cached client session 
*** ClientHello, TLSv1.2 
RandomCookie: GMT: 1455464809 bytes = { 69, 105, 27, 228, 90, 70, 203, 33, 93, 150, 199, 96, 215, 23, 7, 29, 152, 74, 251, 210, 120, 250, 42, 86, 39, 219, 146, 71 } 
Session ID: {} 
Cipher Suites: [TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, 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_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, 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, 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 signature_algorithms, signature_algorithms: SHA512withECDSA, SHA512withRSA, SHA384withECDSA, SHA384withRSA, SHA256withECDSA, SHA256withRSA, SHA224withECDSA, SHA224withRSA, SHA1withECDSA, SHA1withRSA, SHA1withDSA 
*** 
main, WRITE: TLSv1.2 Handshake, length = 193 
main, READ: TLSv1.2 Alert, length = 2 
main, RECV TLSv1.2 ALERT: fatal, handshake_failure 
main, called closeSocket() 
main, handling exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure 
Exception in thread "main" javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure 
    at sun.security.ssl.Alerts.getSSLException(Unknown Source) 
    at sun.security.ssl.Alerts.getSSLException(Unknown Source) 
    at sun.security.ssl.SSLSocketImpl.recvAlert(Unknown Source) 
    at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source) 
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source) 
    at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) 
    at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) 
    at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source) 
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source) 
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source) 
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) 
    at java.net.HttpURLConnection.getResponseCode(Unknown Source) 
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unknown Source) 
    at ShortTestCls.main(ShortTestCls.java:49) 

、ここで

public class ShortTestCls { 

     public static void disableCertificateValidation() { 
      // Create a trust manager that does not validate certificate chains 
      TrustManager[] trustAllCerts = new TrustManager[] { 
       new X509TrustManager() { 
       public X509Certificate[] getAcceptedIssuers() { 
        return new X509Certificate[0]; 
       } 
       public void checkClientTrusted(X509Certificate[] certs, String authType) {} 
       public void checkServerTrusted(X509Certificate[] certs, String authType) {} 
      }}; 

      // Ignore differences between given hostname and certificate hostname 
      HostnameVerifier hv = new HostnameVerifier() { 
       public boolean verify(String hostname, SSLSession session) { return true; } 
      }; 

      // Install the all-trusting trust manager 
      try { 
       SSLContext sc = SSLContext.getInstance("SSL"); 

       sc.init(null, trustAllCerts, new SecureRandom()); 
       HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); 
       HttpsURLConnection.setDefaultHostnameVerifier(hv); 
      } catch (Exception e) {} 
      } 


     public static void main(String... args) throws Exception{ 

      disableCertificateValidation(); 

      URL url = new URL("https://at0yve8x72.execute-api.us-west-2.amazonaws.com/test/v1/shorten?longurl=http://test.com"); 
      HttpURLConnection conn = (HttpURLConnection)url.openConnection(); 
      System.out.println("ResponseCoede ="+conn.getResponseCode()); 
     } 
} 

は、SSLのデバッグログで、私のコードです。私は自分のコードに何が間違っているのか分かりません。

私はこの問題を解決するのに役立つ助言に感謝します。 javax.net.ssl.SSLHandshakeExceptionに関連するいくつかの質問がありますが、解決策が見つかりませんでした。

+0

ハンドシェイクエラーはサーバー証明書の検証とは関係がないため、検証を無効にしないようにします(とにかく悪い考えです)。 –

答えて

3

SSLLabs reportによれば、サイトにはServer Name Indication (SNI)の拡張子が必要です。デバッグ出力に基づいて、クライアントはこの拡張機能を送信しません。

これは、setDefaultHostnameVerifierが使用された場合にJDK 1.8がSNIを使用できないというバグに関連している可能性があります。したがって、私はこのベリファイアを削除し、デフォルトのベリファイアを保つことを推奨します。この問題の詳細については、Extended server_name (SNI Extension) not sent with jdk1.8.0 but send with jdk1.7.0を参照してください。

しかし、私はSSL証明書の確認を無効にしていますが、「致命的な警告を受け取った:handshake_failure」と表示されています。

ハンドシェイクの失敗は、サーバー証明書の検証とは無関係です。したがって、検証を無効にすることは役に立ちません。その無効化の検証とは別に、悪意のあるアイデアはSSLによる保護を弱め、中間の攻撃の人が些細なことになるからです。そして、このサイトでは必要でもありません。ホスト名の検証を無効にすることは、このサイトではよく似ていません。

+0

ありがとうございます。プロダクションでは認証の検証を有効にしますが、開発では無効にしたいと考えています。あなたが言及したように、私は先にデフォルトベリファイアを進めます。 – user3820681

+0

@ user3820681 http://stackoverflow.com/a/34296145/185565を参照してください。カスタムSSLFactoryファサードを使用した回答は、魔法のようにカスタムのホスト名検証機能を許可します。私はJDK7とJDK8の両方で同じコードをテストしましたが、JDK8はファサード工場なしでは失敗します。 – Whome

関連する問題