获取javax.net.ssl​​.SSLHandshakeException:收到致命警报:handshake_failure错误 [英] Getting javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure Error

查看:3493
本文介绍了获取javax.net.ssl​​.SSLHandshakeException:收到致命警报:handshake_failure错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Java的PNS推送通知发送到iPhone,但我收到以下错误 -
javax.net.ssl​​.SSLHandshakeException:收到致命警报:handshake_failure

I am trying to send push notification to iPhone using Java-pns but I am getting the following error - javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

我的code是 -

My code is -

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 我收到这是有效文件和密钥库。

For NotificationTest.verifyKeystore I am getting that this valid is File and Keystore.

我不理解为什么我收到此错误。

I am not understanding why I am getting this error.

请有人能帮助我吗?

先谢谢了...

在我的日志我已经看到,

In my log I have seen that

** CertificateRequest

** CertificateRequest

证书类型:RSA,DSS,ECDSA

Cert Types: RSA, DSS, ECDSA

证书颁发机构:

[阅读] MD5和SHA1散列:LEN = 10

[read] MD5 and SHA1 hashes: len = 10

0000:0D 00 00 06 03 01 02 40 0​​0 00 ....... @ ..

0000: 0D 00 00 06 03 01 02 40 00 00 .......@..

** ServerHelloDone

** ServerHelloDone

[阅读] MD5和SHA1散列:LEN = 4

[read] MD5 and SHA1 hashes: len = 4

0000:0E 00 00 00 ....

0000: 0E 00 00 00 ....

**证书链

**

** ClientKeyExchange,RSA preMasterSecret,使用TLSv1

** ClientKeyExchange, RSA PreMasterSecret, TLSv1

[写入] MD5和SHA1散列:LEN = 269

[write] MD5 and SHA1 hashes: len = 269

主要阅读:使用TLSv1警报,长度= 2

main, READ: TLSv1 Alert, length = 2

为主,RECV的TLSv1警告:致命的,handshake_failure

main, RECV TLSv1 ALERT: fatal, handshake_failure

主,被叫则closesocket()

main, called closeSocket()

主,处理异常:javax.net.ssl​​.SSLHandshakeException:收到致命警报:
handshake_failure

main, handling exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

我不理解为什么证书颁发机构:为空

推荐答案

不可能回答没有看到堆栈跟踪,并可能与运行客户端或服务器时所产生的输出 -Djavax.net.debug = SSL ,握手然而

Impossible to answer without seeing a stack trace and possibly the output produced when running client or server with -Djavax.net.debug=ssl,handshake. However:

的String [] =密码套件sslSocket.getSupportedCipherSuites();
  sslSocket.setEnabledCipherSuites(密码套件);

String[] cipherSuites = sslSocket.getSupportedCipherSuites(); sslSocket.setEnabledCipherSuites(cipherSuites);

不要那样做。这是从根本上不安全,它只是掩盖了真正的问题,这是几乎总是一个证书信任链问题:要么客户不信任服务器证书,反之亦然。

Don't do that. It is radically insecure, and it just conceals the real problem, which is almost always a certificate trust chain problem: either the client doesn't trust the server's certificate or vice versa.

这篇关于获取javax.net.ssl​​.SSLHandshakeException:收到致命警报:handshake_failure错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆