我有一個奇怪的問題,我無法修復。JDK 1.5 SSLHandshakeException
我有通過套接字的JDK 1.5版本和基於SSL的通信,只需發送和接收字符串數據。
try {
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(new FileInputStream(
"path_to_.jks"),
"secret_of_jks".toCharArray());
TrustManagerFactory tmf = TrustManagerFactory
.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ks);
KeyManagerFactory kmf = KeyManagerFactory
.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(ks, "secret_of_jks".toCharArray());
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
Socket s = ctx.getSocketFactory().createSocket("address_of_server", PORT);
String jsonEx = "json text to send server";
StringBuilder sb = new StringBuilder();
sb.append(jsonEx.getBytes().length);
sb.append("\r\n");
sb.append(jsonEx);
PrintWriter writer = new PrintWriter(s.getOutputStream(), true);
writer.println(sb.toString());
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
System.out.println(in.readLine());
writer.flush();
} catch (Exception e) {
e.printStackTrace();
}
當我使用JDK 1.7+一切工作正常,但是當我切換到1.6倍,它拋出javax.net.ssl.SSLException: Connection has been shutdown: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
我的證書加密的2048,我還安裝了JCE無限制強度仲裁策略 http://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.html
這裏是一些例外,如果有人感興趣:
javax.net.ssl.SSLException:Connection has has被關閉: javax.net.ssl.SSLHandshakeException:在 com.sun.net.ssl.internal.ssl.SSLSocketImpl.checkEOF(SSLSocketImpl.java:1154) 握手期間關閉遠程主機連接 在 的com.sun。 net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:65) 在 sun.nio.cs.StreamDecoder $ CharsetSD.readBytes(StreamDecoder.java:411) 在 sun.nio.cs.StreamDecoder $ CharsetSD.implRead(StreamDecoder.java:453) at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:183)at java.io.InputStreamReader.read(InputStreamReader.java:167)at java.io. BufferedReader.fill(BufferedReader.java:136)at java .io.BufferedReader.readLine(BufferedReader.java:299) java.io.BufferedReader.readLine(BufferedReader.java:362)at ConnectorTest.main(ConnectorTest.java:45)引起者: javax.net.ssl .SSLHandshakeException:遠程主機在 com.sun.net.ssl.internal.ssl.SSLSocketImpl收於 com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:739)連接 握手期間 .performInitialHandshake(SSLSocketImpl.java:1025) 在 com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:619) 在 com.sun.net.ssl.internal.ssl.AppOutputStream .write(AppOutputStream.java:59) at sun.nio.cs.StreamEncoder $ CharsetSE.writeBytes(StreamEncoder.java:336) 在 sun.nio.cs.StreamEncoder $ CharsetSE.implFlushBuffer(StreamEncoder.java:404) 在 sun.nio.cs.StreamEncoder $ CharsetSE.implFlush(StreamEncoder.java:408) 在sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:152)在 java.io.OutputStreamWriter.flush(OutputStreamWriter.java:213)在 java.io .BufferedWriter.flush(BufferedWriter.java:236)at java.io.PrintWriter.newLine(PrintWriter.java:410)at java.io.PrintWriter.println(PrintWriter.java:559)at java.io.PrintWriter .println(PrintWriter.java:670)at ConnectorTest.main(ConnectorTest.java:43)引起者: java.io.EOFException:SSL對等方關閉不正確 com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:321) at com.sun.net.ssl.internal.ssl .SSLSocketImpl.readRecord(SSLSocketImpl.java:720) ...13多
ConnectorTest Line 43 is
System.out.println(in.readLine());
更新
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, TLSv1
RandomCookie: GMT: 1439443814 bytes = { 228, 36, 73, 128, 109, 225, 11, 36, 62, 40, 147, 150, 27, 145, 150, 163, 244, 28, 97, 56, 188, 81, 117, 31, 235, 60, 101, 224 }
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: TLSv1 Handshake, length = 75
main, WRITE: SSLv2 client hello message, length = 101
main, received EOFException: error
main, handling exception: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
main, SEND TLSv1 ALERT: fatal, description = handshake_failure
main, WRITE: TLSv1 Alert, length = 2
main, called closeSocket()
更新2
我剛剛發現,它們之間的區別是:
從星期二有效02月16日20時07分36秒GET直到2016週四02月16日20時07分36秒GET 2017年 1.7 正確
從星期二02月16日16時07分36秒GMT 2016有效期至星期四二月16 16時07分36秒 GMT 2017年1.6錯誤
您可以檢查此鏈接,而不是一個解決方案,但一些見解: http://stackoverflow.com/questions/21245796/javax-net-ssl-sslhandshakeexception-remote-host-closed-connection-during-handsh –