我对推送通知有一个问题。我有一个由团队成员创建的p.12证书,并且我有要推送到的设备的设备令牌。我使用javapns库来执行推送(我也尝试了javaapns库,结果相同),但我一直收到以下错误:
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:136)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1720)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:954)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1138)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:632)
at com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:59)
at java.io.OutputStream.write(OutputStream.java:58)
at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:402)
at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:350)
at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:320)
at javapns.Push.sendPayload(Push.java:177)
at javapns.Push.combined(Push.java:100)
at PushTest.push(PushTest.java:43)
at PushTest.main(PushTest.java:25)这是我用来测试的代码
try {
List<PushedNotification> n = Push.combined(text, 20, null, file, "********", false, token);
for (PushedNotification notification : n) {
if (notification.isSuccessful())
System.out.println("Push notification sent successfully to: " + notification.getDevice().getToken());
else {
String invalidToken = notification.getDevice().getToken();
Exception theProblem = notification.getException();
theProblem.printStackTrace();
ResponsePacket theErrorResponse = notification.getResponse();
if (theErrorResponse != null)
System.out.println(theErrorResponse.getMessage());
}
}
}
catch (CommunicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (KeystoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}我阅读并尝试了其他几篇文章中的建议,包括将证书导入到cacerts keystore,但导入也失败了。我在windows机器上使用eclipse进行开发。
有人熟悉这个问题吗?我刚开始使用ssl,所以可能我做错了什么,或者我不能使用在另一台机器上生成的证书?
发布于 2012-09-30 15:29:40
我是一个新的iOS开发人员,我以前也遇到过同样的问题。
我最终发现问题出在p12 certificate上。我们不应该使用私钥p12文件,而应该从您的私钥和从苹果下载的证书生成p12。
请执行以下OpenSSL命令以获取正确的p12文件:
developer_identity.cer <= download from Apple
mykey.p12 <= Your private key
openssl x509 -in developer_identity.cer -inform DER -out developer_identity.pem -outform PEM
openssl pkcs12 -nocerts -in mykey.p12 -out mykey.pem
openssl pkcs12 -export -inkey mykey.pem -in developer_identity.pem -out iphone_dev.p12在此之后,您应该使用iphone_dev.p12与苹果服务器进行通信。
发布于 2016-09-09 23:42:21
Sunny's answer是一个很好的工具,但不幸的是它不适合我。
我通过从密钥链中导出证书/私钥对使其正常工作。诀窍是选择顺序很重要!必须首先选择证书,然后选择私钥。
下面是它的工作原理:
https://stackoverflow.com/questions/12585858
复制相似问题