什么是Java APNS证书的正确格式?

时间:2013-11-19 17:06:32

标签: java ios macos apple-push-notifications javaapns

我正在使用Java APNS(com.notnoop.apns,v0.2.3)将推送通知发送到我的iOS应用程序。我正在使用以下行创建APNS服务:

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

并收到以下例外:

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...>>

我猜我的P12证书不正确。 (我也已经尝试过PEM证书。)目前我已经以这种方式创建了P12证书,然后应用了密码:

Screenshot of Keychain.app


创建与Java APNS兼容的证书的正确方法是什么?

2 个答案:

答案 0 :(得分:17)

我使用PKCS#12(.p12文件)。要创建它我做:

  1. 从钥匙串导出私钥并将其命名为aps_private-key.p12

  2. 使用以下命令转换密钥 openssl pkcs12 -nocerts -out aps_private-key.pem -in aps_private-key.p12,请务必输入至少4个字符的PEM密码短语。

  3. https://developer.apple.com/account/ios/identifiers/bundle/bundleList.action下载该应用的证书。下载的文件应该被称为aps_development.cer

  4. 使用以下命令openssl x509 -in aps_development.cer -inform der -out aps_development.pem

  5. 转换证书
  6. 使用openssl pkcs12 -export -in aps_development.pem -out aps_dev_credentials.p12 -inkey aps_private-key.pem生成凭据。

  7. 我已准备好使用步骤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();
    

答案 1 :(得分:3)

我今年早些时候根据本教程创建了它,它运行得很好。

首先遵循:http://raywenderlich.com/32960

然后按照此处的说明http://code.google.com/p/apns-sharp/wiki/HowToCreatePKCS12Certificate

获取创建的.pem然后进行转换