我的环境是 ubuntu 12.04 + Play 2.2.2 + java 7 + java-apns 0.2.3
在我从苹果下载 aps_development 并安装到我的 keyChain 后,然后将证书和私钥导出到 Dev_Certificates.p12。我把它放在 conf/certs/Dev_Certificates.p12 下。这是我得到的错误:
pool-7-thread-1, WRITE: TLSv1 Handshake, length = 48
pool-7-thread-1, READ: TLSv1 Alert, length = 2
pool-7-thread-1, RECV TLSv1 ALERT: fatal, handshake_failure
%% Invalidated: [Session-3, TLS_RSA_WITH_AES_128_CBC_SHA]
pool-7-thread-1, called closeSocket()
pool-7-thread-1, handling exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
pool-7-thread-1, called close()
pool-7-thread-1, called closeInternal(true)
Thread-13, handling exception: java.net.SocketException: Socket is closed
[error] application - ConnectionClosed MessageID: -1 Error: UNKNOWN
[error] c.n.a.i.ApnsConnectionImpl - Couldn't send message after 3 retries.Message(Id=1; Token=62303732366363653231353337356337313133303637373437643839333738323631626662356139663037633234386366613034346635643737353031376635; Payload={"aps":{"alert":{"loc-args":["angelokh"],"action-loc-key":"REPLY","loc-key":"NEW_MESSAGE_PUSH_FORMAT"},"badge":0},"extra":{"traversableAgain":true,"empty":false}})
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) ~[na:1.7.0_55]
at sun.security.ssl.Alerts.getSSLException(Alerts.java:154) ~[na:1.7.0_55]
at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1959) ~[na:1.7.0_55]
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1077) ~[na:1.7.0_55]
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312) ~[na:1.7.0_55]
at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:702) ~[na:1.7.0_55]
[error] application - MessageSendFailed Msg: Message(Id=1; Token=62303732366363653231353337356337313133303637373437643839333738323631626662356139663037633234386366613034346635643737353031376635; Payload={"aps":{"alert":{"loc-args":["angelokh"],"action-loc-key":"REPLY","loc-key":"NEW_MESSAGE_PUSH_FORMAT"},"badge":0},"extra":{"traversableAgain":true,"empty":false}}) Exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
编辑1:
p12 文件位于 conf/certs/ 下。该服务被创建为 def 函数并由 akka 演员调用。
def apnsService = {
val certPath = "certs/DEV-APNS-CERT.p12"
val baseBuilder =
APNS.newService()
.asBatched()
.withCert(getClass.getResourceAsStream(certPath), "password")
baseBuilder.withSandboxDestination()
}.build