java apns ssl错误,不能发送使用Javapns / Javaapns SSL握手失败推送通知

I have an issue with push notifications. I have a p.12 certificate that was created by a team member and I have the device token for the device to be pushed to. I am using the javapns library to do the push (also tried the javaapns lib with same results) but I keep getting this error:

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)

and this is the code I am using to test

try {

List 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();

}

I read and tried the suggestions from several of the other posts including importing the certificate into cacerts keystore but the import fails as well. I am developing using eclipse on a windows machine.

Anyone familiar with this issue? I am new to using ssl so perhaps I'm doing something wrong or is it that I cannot use a certificate generated on another machine?

解决方案

I am a new iOS developer and I had the same issue before.

I finally found that the problem was due to the p12 certificate.

We should not use the private key p12 file, instead we should generate a p12 from your private key and the cert download from Apple.

Please execute the following OpenSSL command to get the correct p12 file:

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

After that, you should use iphone_dev.p12 to communicate with apple server.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值