0

jdk バージョン 1.6.0_29 を使用して Java https クライアント (HttpsURLConnection を使用) を作成しようとしています。次に、証明書 /wlserver_10.3/server/lib/CertGenCA.der をクライアントのキーストアにインポートしました。次のコマンドで:

keytool -import -alias test -keystore "D:\Program Files\Java\jdk1.6.0_29\jre\lib\security\cacerts" -file CertGenCA.der

問題は、「スレッド "main" javax.net.ssl.SSLHandshakeException で例外が発生し続けることです: ハンドシェイク中にリモート ホストが接続を閉じました」SSL デバッグ出力は次のとおりです。

           keyStore is : 
           keyStore type is : 
           jks keyStore provider is : 
           init keystore

           init keymanager of type SunX509
           trustStore is: D:\Program Files\Java\jdk1.6.0_29\jre\lib\security\cacerts
           trustStore type is : jks
           trustStore provider is : 
           init truststore
enter code here
adding as trusted cert:
Subject: CN=SwissSign Platinum CA - G2, O=SwissSign AG, C=CH
Issuer:  CN=SwissSign Platinum CA - G2, O=SwissSign AG, C=CH 
Algorithm: RSA; Serial number: 0x4eb200670c035d4f 
Valid from Wed Oct 25 04:36:00 VET 2006 until Sat Oct 25 04:06:00 VET 2036



adding as trusted cert:
Subject: EMAILADDRESS=info@valicert.com, CN=http://www.valicert.com/, OU=ValiCert Class    1 Policy Validation Authority, O="ValiCert, Inc.", L=ValiCert Validation Network

発行者: EMAILADDRESS=info@valicert.com, CN= http://www.valicert.com/ , OU=ValiCert Class 1 Policy Validation Authority, O="ValiCert, Inc.", L=ValiCert Validation Network Algorithm: RSA; シリアル番号: 0x1 1999 年 6 月 25 日金曜日 18:23:48 VET から 2019 年 6 月 25 日火曜日 17:53:48 VET まで有効

.. .. ..

            trigger seeding of SecureRandom
            done seeding SecureRandom

            Allow unsafe renegotiation: false 
            Allow legacy hello messages: true 
            Is initial handshake: true 
            Is secure renegotiation: false 

            %% No cached client session 
            *** ClientHello, SSLv3 
            RandomCookie:  GMT: 1362670800 bytes = { 77, 1, 89, 245, 75, 245, 125, 199, 168, 78, 33, 255, 83, 57, 65, 228, 118, 11, 240, 48, 210, 7, 245, 45, 70, 153, 149, 149 }


            Session ID:  {} 
            Cipher Suites: [SSL_RSA_WITH_RC4_128_MD5, SSL_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, SSL_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_DES_CBC_SHA, SSL_DHE_RSA_WITH_DES_CBC_SHA, SSL_DHE_DSS_WITH_DES_CBC_SHA, SSL_RSA_EXPORT_WITH_RC4_40_MD5, SSL_RSA_EXPORT_WITH_DES40_CBC_SHA, SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA, SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]

              Compression Methods:  { 0 } 
              *** 
              main, WRITE: SSLv3 Handshake, length = 75 
              main, received EOFException: error 
              Exception in thread "main" javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake 

メイン、例外処理: javax.net.ssl.SSLHandshakeException: ハンドシェイク中にリモート ホストが接続を閉じました

              main, SEND TLSv1 ALERT:  fatal, description = handshake_failure
              main, WRITE: TLSv1 Alert, length = 2 
              main, called closeSocket()

メイン、close() と呼ばれる メイン、com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:849) で closeInternal(true) と呼ばれる

.. ..

               Caused by: java.io.EOFException: SSL peer shut down incorrectly
               at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:333)
               at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:830)
... 7 more

この情報をすべて解釈する方法がわからない

私のコードはEclipseから実行され、ヒットしているURL(JAX-WS)はLABとsolarisボックスにあります

私のテストクライアントコードは次のとおりです。


URL wsdlLocation = new URL("https://server.lab.ciso.com:8833/Impl/Service?wsdl");

    System.setProperty("weblogic.security.SSL.ignoreHostnameVerification", "true");
    System.setProperty("javax.net.ssl.trustStore", "D:\\Program Files\\Java\\jdk1.6.0_29\\jre\\lib\\security\\cacerts");
    System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
    System.setProperty("https.protocols", "SSLv3");

    SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();

    HttpsURLConnection conn = null;
    try {
        conn = (HttpsURLConnection) wsdlLocation.openConnection();
        conn.setSSLSocketFactory(sslsocketfactory);
        conn.setDoOutput(true);
        conn.setUseCaches(false);
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Content-Type","application/Json");
        conn.setDoInput(true);
        conn.connect();
        BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        StringBuilder sb = new StringBuilder();
        String line;
        while ( ((line = br.readLine()) != null)) {
            if((line.indexOf("wsp:PolicyReference") == -1))
                sb.append(line+"\n");
        }
        br.close();
        System.out.println("Random code::"+sb.toString());

    } finally {
        if (conn != null) {
            conn.disconnect();
        }
    }

4

1 に答える 1

0

まず第一に、JDK インストールの cacerts トラストストアを変更することは非常に悪い習慣です。現在脆弱性のために週に 1 回リリースされている JDK 更新で変更が失われるからです。

変更した Java トラストストアを使用する場合は、それをプロジェクトにコピーし、そこから変更/使用します。

コードの主な問題 (私が推測) は、次の呼び出しを使用してプロトコルを SSLv3 に制限していることですSystem.setProperty("https.protocols", "SSLv3");

SSL3 は非常に古く、特定の状況では安全ではないため、TLS v1.0 以降を使用する必要があります。サーバーが TLS に制限されている場合 (ここではそのようです)、接続は失敗します。

したがって、またはに変更"SSLv3"します(AFAIRはJava 7でのみサポートされています)。"TLSv1""TLSv1.1""TLSv1.2"

于 2013-03-08T12:52:34.893 に答える