我正在使用 notnoop APNS 0.2.3,在证书方面苦苦挣扎,现在我在 SSL 方面苦苦挣扎。
没有关于如何为库准备 p12 文件的文档,所以我找到了这篇文章来指导我。
service = APNS.newService()
.withCert(mycertPath, myP12password)
.withSandboxDestination()
.build();
service.start();
service.testConnection();
service.push(listOfTokens,payload);
启动方法失败并出现以下转储
09:46:16,657 INFO ~ Failed to send message Message(Token=00; Payload=)... trying again after delay
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:136)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1822)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1004)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1188)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:654)
at com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:100)
at java.io.OutputStream.write(OutputStream.java:58)
at com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:240)
at com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:230)
at com.notnoop.apns.internal.ApnsConnectionImpl.testConnection(ApnsConnectionImpl.java:294)
at com.notnoop.apns.internal.ApnsServiceImpl.testConnection(ApnsServiceImpl.java:57)
我搞砸了p12文件吗?我在这里还缺少什么吗?
[更新 1] 我正在尝试以下脚本来创建和测试 p12 文件命令行,并且还出现连接错误,因此我可能在证书中搞砸了。
[更新 2] 我更改了脚本以创建 p12 文件...以防其他人可以从中受益。
#!/bin/sh
bold=`tput bold`
normal=`tput sgr0`
# CONVERT CERT TO PEM
echo "${bold}CONVERTING${normal} APNS..."
openssl x509 -in aps_development.cer -inform der -out aps_development.pem
openssl x509 -in aps_production.cer -inform der -out aps_production.pem
# CONVERT PRIVATE KEY P12 INTO PEM
echo "${bold}CONVERTING ${normal} private key..."
openssl pkcs12 -nocerts -out my_private.pem -in my_private.p12
# COMBINE CERTS INTO SINGLE P12
echo "${bold}COMBINING ${normal} development..."
#cat aps_development.pem my_private.pem > my_development.pem
openssl pkcs12 -export -in aps_development.pem -inkey my_private.pem -out my_development.p12
# COMBINE CERTS INTO SINGLE P12
echo "${bold}COMBINING ${normal} production..."
#cat aps_production.pem my_private.pem > my_production.pem
openssl pkcs12 -export -in aps_production.pem -inkey my_private.pem -out my_production.p12
echo "${bold}TESTING${normal}..."
# TEST IT
openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert aps_development.pem -key my_private.pem