2014-06-07 240 views
4

我試圖將推送通知發送到iOS設備。
我爲APNS創建了一個開發人員證書,並將其與應用程序標識符綁定在一起。Apple APNS和「Entrust安全CA根證書」?

我接着就用愛出風頭(https://github.com/relayrides/pushy)建立到APNS服務器的連接:

final PushManagerFactory<SimpleApnsPushNotification> pushManagerFactory = 
     new PushManagerFactory<SimpleApnsPushNotification>(
       ApnsEnvironment.getSandboxEnvironment(), 
       PushManagerFactory.createDefaultSSLContext(DEV_CERT_P12__PATH, DEV_CERT_P12__PASSWORD) 
       ); 

final PushManager<SimpleApnsPushNotification> pushManager = pushManagerFactory.buildPushManager(); 

pushManager.registerFailedConnectionListener(new MyFailedConnectionListener()); 

pushManager.start(); 

....

public static class MyFailedConnectionListener implements FailedConnectionListener<SimpleApnsPushNotification> { 

    public void handleFailedConnection(
      final PushManager<? extends SimpleApnsPushNotification> pushManager, 
      final Throwable cause) { 

     System.out.println("ERROR - "+ cause.toString()); 

     if (cause instanceof SSLHandshakeException) { 

      // This is probably a permanent failure, and we should shut down 
      // the PushManager. 
     } 
    } 
} 

我得到這個錯誤:javax.net.ssl.SSLException: Received fatal alert: certificate_unknown


我用我已經從我與應用結合的證書的私鑰創建的P12文件在developer.apple.com enter image description here



多搜索我已經後設法獲得一些信息,爲什麼我不能得到這個東西的工作,在Apple Doc

Note: To establish a TLS session with APNs, an Entrust Secure CA root certificate must be installed on the provider’s server. If the server is running OS X, this root certificate is already in the keychain. On other systems, the certificate might not be available. You can download this certificate from the Entrust SSL Certificates website.

不過,我仍然不知道我該做的。
我真的很感激這裏的一些更具體的指導。

謝謝。

+0

你是如何創建的P12文件?你是否從keytool應用程序導出證書+私鑰? – Eran

+0

我在OS X上,所以我只是使用Keychain Access導出私鑰。 – thedp

+0

我的意思是KeyChain Access應用程序(我忘了名字)。您應該選擇推送證書和私鑰並將其導出到p12文件。 – Eran

回答

8

我找到了解決方案。作爲向我暗示的人,我不知道爲什麼它解決了這個問題。

使用OpenSSL的,我已經轉換的P12文件(我從鑰匙串訪問了),質子交換膜,並從PEM回P12 ...

  1. 轉換下載的文件CER從應用程序的APN(在developer.apple.com),以PEM
    openssl x509 -in aps_development.cer -inform DER -out aps_development.pem -outform PEM

  2. 轉換鑰匙扣Access創建的P12文件爲PEM
    openssl pkcs12 -nocerts -in Certificates.p12 -out Certificates.pem

  3. 創建一個新的,好的,P12文件
    openssl pkcs12 -export -inkey Certificates.pem -in aps_development.pem -out GOOD_Certificates.p12

欲瞭解更多信息:http://help.adobe.com/en_US/as3/iphone/WS144092a96ffef7cc-371badff126abc17b1f-7fff.html

+2

這拯救了生命 –