【问题标题】:Push notification - Caused by: java.io.IOException: toDerInputStream rejects tag type 45推送通知 - 原因:java.io.IOException:toDerInputStream 拒绝标签类型 45
【发布时间】:2015-02-18 04:01:22
【问题描述】:

当我的服务器尝试根据设备令牌和 ck.pem(.pem 文件、证书和密钥的组合)向特定设备推送通知时,我收到此错误。

Caused by: java.io.IOException: toDerInputStream rejects tag type 45

这是完整的错误消息出现在我的 Eclipse 控制台中。

initial
starting push notification sending
2014/03/20 14:28:00:252 INFO  net.penril.notification.Initializer: ====Start Push Notification Sending==== 
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
2014/03/20 14:28:04:737 INFO  net.penril.notification.Initializer: Total of record data(1)
SMS OID: 465
IOS test
reg id =x769571d187c15cec398c5a02f196249456e8b73f763754fa17060658f87f6f6
com.notnoop.exceptions.InvalidSSLConfig: java.io.IOException: toDerInputStream rejects tag type 45
2014/03/20 14:28:05:374 INFO  net.penril.notification.Initializer: Failed send notification to APN 
2014/03/20 14:28:05:374 INFO  net.penril.notification.Initializer: ====Complete Push Notification Sending==== 
2014/03/20 14:28:05:374 INFO  net.penril.notification.Initializer: =====End===== 

starting..
    at com.notnoop.apns.internal.Utilities.newSSLContext(Utilities.java:101)
    at com.notnoop.apns.ApnsServiceBuilder.withCert(ApnsServiceBuilder.java:170)
    at com.notnoop.apns.ApnsServiceBuilder.withCert(ApnsServiceBuilder.java:133)
    at net.penril.notification.Initializer.notificationWorker(Initializer.java:156)
    at net.penril.notification.Initializer.Initial(Initializer.java:46)
    at net.penril.notification.PushNotificationCron$Job.run(PushNotificationCron.java:12)
    at EDU.oswego.cs.dl.util.concurrent.ClockDaemon$RunLoop.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:724)
Caused by: java.io.IOException: toDerInputStream rejects tag type 45
    at sun.security.util.DerValue.toDerInputStream(DerValue.java:847)
    at sun.security.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:1221)
    at java.security.KeyStore.load(KeyStore.java:1214)
    at com.notnoop.apns.internal.Utilities.newSSLContext(Utilities.java:85)
    ... 7 more

我怀疑这个错误是由这段代码引起的

System.out.println("reg id =" + record.getRegId());
ApnsService service = APNS.newService().withCert("/Applications/MAMP/htdocs/xxxxx-mobile/ck.pem", "xxxxxx").withSandboxDestination().build();
String payload = APNS.newPayload().alertBody("This for testing").build();
String token = record.getRegId();
service.push(token, payload);

你对这个toDerInputStream rejects tag type 45有什么想法吗?

我已经在这里对这个问题进行了研究:

  1. https://community.oracle.com/thread/1534340?start=0&tstart=0
  2. Java APNS (Apple Push Notification Service) error

为什么?

【问题讨论】:

    标签: java ios apple-push-notifications


    【解决方案1】:

    here java-apns 所述,需要 .p12 私钥,而不是 .pem 文件。

    第一个链接中有在 mac 上创建 .p12 文件的说明,但如果您在 linux 上使用 openssl 工具,则可以使用以下方法创建它:

    openssl pkcs12 -export -inkey mykey.key -in mykey.pem -out mykey.p12
    

    【讨论】:

      【解决方案2】:

      我刚刚找到了答案。当我尝试生成 P12 密钥时,我需要在钥匙串访问中同时选择私钥和证书。

      【讨论】:

      • 如何在 windows 或 linux 中做到这一点?
      猜你喜欢
      • 1970-01-01
      • 2016-09-26
      • 2011-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-26
      相关资源
      最近更新 更多