4

I'm using Java APNS (com.notnoop.apns, v0.2.3) to send Push Notifications to my iOS app. I'm creating the APNS service with the following lines:

private ApnsService createApnsService() throws IOException {
        ApnsServiceBuilder serviceBuilder = APNS.newService().withCert(certResource.getInputStream(), certPassword);
        serviceBuilder.withSandboxDestination();
        return serviceBuilder.build();
}

And receive the following exception:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is com.notnoop.exceptions.NetworkIOException: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure\n\tat org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)\n\tat org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:647)\n\tat org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:728)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)...    <<...the stacktrace is much longer, but I've cut it of here, since nobody would read it anyway...>>

I'm guessing that my P12 certificate is incorrect. (I've also tried PEM certificate already.) At the moment I've created the P12 certificate at this way and then applied a password:

Screenshot of Keychain.app


What's the correct way to create the certificate which is compatible with Java APNS?

miho
  • 11,765
  • 7
  • 42
  • 85
  • 1
    I created it as per this tutorial earlier this year and it worked perfectly. http://www.raywenderlich.com/32960 – Woodstock Nov 19 '13 at 17:21
  • With Java APNS or the PHP one mentioned in the tutorial? Since in the tutorial they are using PEM-certificates, due to the documentation of Java APNS you should use P12 certificates instead. – miho Nov 19 '13 at 17:26
  • 1
    created a pem and then converted, as per instructions here http://code.google.com/p/apns-sharp/wiki/HowToCreatePKCS12Certificate – Woodstock Nov 19 '13 at 17:27
  • I have used Java APNS and PHP based solutions – Woodstock Nov 19 '13 at 17:28
  • 2
    @JohnWoods Thanks for the link. Your solution with the PKCS12 certificate works. When you create this as an answer I'll mark it as the correct one. – miho Nov 19 '13 at 17:41
  • Thanks alot Miho, I have created an answer, appreciate it. – Woodstock Nov 20 '13 at 09:42

2 Answers2

17

I use PKCS#12 (a .p12 file). To create it I do:

  1. Export the private key from the Keychain and name it aps_private-key.p12.

  2. Convert the key with the following command openssl pkcs12 -nocerts -out aps_private-key.pem -in aps_private-key.p12, make sure to enter a PEM pass phrase of at least 4 characters.

  3. Download the certificate of the app from https://developer.apple.com/account/ios/identifiers/bundle/bundleList.action. The downloaded file should be called something like aps_development.cer.

  4. Convert the certificate with the following command openssl x509 -in aps_development.cer -inform der -out aps_development.pem

  5. Generate the credentials using openssl pkcs12 -export -in aps_development.pem -out aps_dev_credentials.p12 -inkey aps_private-key.pem.

  6. And I'm ready to use the credentials generated in step 5 (aps_dev_credentials.p12).

    final InputStream certificate = Thread.currentThread().getContextClassLoader()
            .getResourceAsStream("aps_dev_credentials.p12");
    final char[] passwd = {'1','2','3','4'};
    final ApnsService apnsService = com.notnoop.apns.APNS.newService()
            .withCert(certificate, new String(passwd))
            .withSandboxDestination().build();
    apnsService.testConnection();
    
user454322
  • 7,300
  • 5
  • 41
  • 52
3

I created it as per this tutorial earlier this year and it worked perfectly.

First follow this: http://raywenderlich.com/32960

Then take the created .pem and then convert, as per instructions here http://code.google.com/p/apns-sharp/wiki/HowToCreatePKCS12Certificate

miho
  • 11,765
  • 7
  • 42
  • 85
Woodstock
  • 22,184
  • 15
  • 80
  • 118