Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java APNS (Apple Push Notification Service) error

I am trying to use Java APNS - an open source project - to send push notifications to iPhones. I am getting an error, though.

I have used a .pem file as certificate. Should this have been a .p12 file? I am not sure what the difference is, but I read somewhere online that there is a difference between these file formats.

Here is the code:

   ApnsService service =
        APNS.newService()
            .withCert("gpk.pem", "XXXX")
            .withSandboxDestination()
            .build();


    String payload = APNS.newPayload().alertBody("Can't be simpler than this!").build();
    String token = "theTokenIsRemoveHere";
    service.push(token, payload);

And here is the error:

Exception in thread "main" com.notnoop.exceptions.InvalidSSLConfig: java.io.IOException: toDerInputStream rejects tag type 45
    at com.notnoop.apns.internal.Utilities.newSSLContext(Utilities.java:102)
    at com.notnoop.apns.ApnsServiceBuilder.withCert(ApnsServiceBuilder.java:161)
    at com.notnoop.apns.ApnsServiceBuilder.withCert(ApnsServiceBuilder.java:124)
    at com.geomobsters.cli.ApnsClient.main(ApnsClient.java:12)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.io.IOException: toDerInputStream rejects tag type 45
    at sun.security.util.DerValue.toDerInputStream(DerValue.java:806)
    at com.sun.net.ssl.internal.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:1201)
    at java.security.KeyStore.load(KeyStore.java:1185)
    at com.notnoop.apns.internal.Utilities.newSSLContext(Utilities.java:87)
    ... 8 more
like image 286
Jakob Jenkov Avatar asked Dec 05 '11 14:12

Jakob Jenkov


People also ask

Why push notification is not working for iOS?

You can fix an iPhone that's not getting notifications by restarting it or making sure notifications are turned on. You should also make sure your iPhone is connected to the internet so apps can receive notifications. If all else fails, you should try resetting the iPhone — just make sure to back it up first.

How do I check my APN push notifications?

Sending a test Android push notificationClick on Settings and open Mobile Apps. Click on the Android App and make sure the Firebase API key has been configured. Click on Test Push and enter the device token for your test device. Add a test payload and send the test.


1 Answers

Java APNS is expecting the cert as .p12 file.

You have to check both privatekey and certificate in your keychain. then right click-> "export 2 files" and export them you have to give it a password, this password you have to type here

.withCert("gpk.pem", "XXXX")

as your XXXX

good luck

EDIT:

.P12 – PKCS#12, contains certificates an private keys saved with a password .PEM – is Base64-encoded certificate, lockedby „-----BEGIN CERTIFICATE-----“ and „-----END CERTIFICATE-----“

like image 115
Starbax Avatar answered Nov 14 '22 23:11

Starbax