![](/img/trans.png)
[英]Getting javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
[英]Getting javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure Error
我正在嘗試使用Java-pns向iPhone發送推送通知但我收到以下錯誤 - javax.net.ssl.SSLHandshakeException:收到致命警報:handshake_failure
我的代碼是 -
String token="95076d2846e8979b46efd1884206a590d99d0f3f6139d947635ac4186cdc5942";
String host = "gateway.sandbox.push.apple.com";
int port = 2195;
String payload = "{\"aps\":{\"alert\":\"Message from Java o_O\"}}";
NotificationTest.verifyKeystore("res/myFile.p12", "password", false);
KeyStore keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(getClass().getResourceAsStream("res/myFile.p12"), "password".toCharArray());
KeyManagerFactory keyMgrFactory = KeyManagerFactory.getInstance("SunX509");
keyMgrFactory.init(keyStore, "password".toCharArray());
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyMgrFactory.getKeyManagers(), null, null);
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(host, port);
String[] cipherSuites = sslSocket.getSupportedCipherSuites();
sslSocket.setEnabledCipherSuites(cipherSuites);
sslSocket.startHandshake();
char[] t = token.toCharArray();
byte[] b = Hex.decodeHex(t);
OutputStream outputstream = sslSocket.getOutputStream();
outputstream.write(0);
outputstream.write(0);
outputstream.write(32);
outputstream.write(b);
outputstream.write(0);
outputstream.write(payload.length());
outputstream.write(payload.getBytes());
outputstream.flush();
outputstream.close();
System.out.println("Message sent .... ");
對於NotificationTest.verifyKeystore,我得知這個有效的是File和Keystore。
我不明白為什么我會收到這個錯誤。
請有人幫幫我嗎?
提前致謝 ...
在我的日志中,我已經看到了
** CertificateRequest
證書類型:RSA,DSS,ECDSA
證書頒發機構:
[read] MD5和SHA1哈希:len = 10
0000:0D 00 00 06 03 01 02 40 00 00 ....... @ ..
** ServerHelloDone
[read] MD5和SHA1哈希:len = 4
0000:0E 00 00 00 ....
**證書鏈
**
** ClientKeyExchange,RSA PreMasterSecret,TLSv1
[寫] MD5和SHA1哈希:len = 269
。
。
。
。
。
main,READ:TLSv1 Alert,length = 2
main,RECV TLSv1 ALERT:致命,handshake_failure
main,名為closeSocket()
main,處理異常:javax.net.ssl.SSLHandshakeException:收到致命警報:handshake_failure
我不明白為什么證書頒發機構是空的?
使用-Djavax.net.debug=ssl,handshake.
時,無法查看堆棧跟蹤以及運行客戶端或服務器時可能產生的輸出-Djavax.net.debug=ssl,handshake.
然而:
String [] cipherSuites = sslSocket.getSupportedCipherSuites(); sslSocket.setEnabledCipherSuites(密碼組);
不要那樣做。 它從根本上說是不安全的,它只是隱藏了真正的問題,這幾乎總是證書信任鏈問題:客戶端不信任服務器的證書,反之亦然。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.