推送通知 - 引起:java.io.IOException:toDerInputStream 拒绝标签类型 45

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22525388/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 16:15:21  来源:igfitidea点击:

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

javaiosapple-push-notifications

提问by Mohammad Nurdin

I got this error when my server try to push a notification to a specific device based on device token and ck.pem (combination between .pem file, cert and key).

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

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

This is full error message appear in my eclipse console.

这是我的 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

I suspect this error cause by this code

我怀疑此代码导致此错误

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);

Do you have any idea about this toDerInputStream rejects tag type 45?

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

I already doing my research about this problem here:

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

  1. https://community.oracle.com/thread/1534340?start=0&tstart=0
  2. Java APNS (Apple Push Notification Service) error
  1. https://community.oracle.com/thread/1534340?start=0&tstart=0
  2. Java APNS(Apple 推送通知服务)错误

Why?

为什么?

采纳答案by Mohammad Nurdin

I just found the answer. When I try to generate a P12 key, I need to select both, a private key and certificate in keychain access.

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

enter image description here

在此处输入图片说明

回答by DeRauk

As stated herejava-apns is expecting the .p12 private key, not the .pem file.

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

The instructions for creating a .p12 file on a mac are in the first link, but if you're using the openssl tool on linux you can create it with:

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

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