Thursday, 16 July 2015

Working with Apple Notifications using javapns plugin and Java 7

If you are trying to push notifications to apple devices with jdk 7 and using javapns plugin for pushing messages to Apple Server, You will end up getting the following error by using the p12 file generated using the keychain access in MAC.
javapns.communication.exceptions.InvalidCertificateChainException: Invalid certificate chain (Received fatal alert: certificate_unknown)!  Verify that the keystore you provided was produced according to specs...
    at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:410)
    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.alert(Push.java:47)
 The simple solution is, just convert APNS .p12 certificates to JKS file with jdk 6 keytool and again convert JKS back to .p12 format with jdk 7 keytool.

Convert .p12 to jks:

keytool -importkeystore -destkeystore C:\Push_jks.jks -srckeystore C:\Push_j6.p12 -srcstoretype PKCS12

Convert jks to .p12:

keytool -importkeystore -srckeystore F:\Push_jks.jks -srcstoretype JKS -deststoretype PKCS12 -destkeystore C:\Push_j7.p12


Please provide the complete path of the files in place of C:\Push_j6.p12, C:\Push_j7.p12,F:\Push_jks.jks

Note : for reference i have used windows file paths in the above example.

No comments:

Post a Comment