Error when using / initializing APNS

897 views
Skip to first unread message

Jakob Jenkov

unread,
Dec 5, 2011, 10:11:13 AM12/5/11
to Java client for Apple Push Notification service (APNs)
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);


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

- Jakob Jenkov

Olivier Costet

unread,
Dec 5, 2011, 10:43:08 AM12/5/11
to java-apn...@googlegroups.com
Yes, it's got to be a PKCS#12, containing your APNS certificate along
with the private key.

.pem files generally are certificates only (no private key).

If you created the APNS cert on a Mac, you'll have to import the
certificate you got on the Apple portal into the Mac's KeyChain (or
something like that), and then export it and the private key as a P12.

OC.
--
Show me a man who is a good loser and I'll show you a man who is playing
golf with his boss.
Reply all
Reply to author
Forward
0 new messages