2014-02-21 222 views
1

我想用PushSharp發送推送通知給我的應用程序。我有兩個蘋果賬戶......一個是普通賬戶,另一個是企業賬戶。我在常規帳戶上有開發人員證書,但我的開發證書和分發證書都無法通過企業帳戶工作。我得到一個驗證異常..iOS推送通知AuthenticationException證書

A call to SSPI failed, see inner exception. 

Inner Exception: 
[System.ComponentModel.Win32Exception]: {"An unknown error occurred while processing the certificate"} 

這發生在PushSharp的代碼(我沒有發表評論線路輸出):

try 
{ 
    stream.AuthenticateAsClient(this.appleSettings.Host, this.certificates, System.Security.Authentication.SslProtocols.Ssl3, false); 
    //stream.AuthenticateAsClient(this.appleSettings.Host); 
} 
catch (System.Security.Authentication.AuthenticationException ex) 
{ 
    throw new ConnectionFailureException("SSL Stream Failed to Authenticate as Client", ex); 
} 

這裏是我的測試項目中的代碼:

public static void SendPingToApple() 
{ 
    try 
    { 
     var devicetoken = "mytoken"; 
     var appleCert = File.ReadAllBytes(AssemblyPathName + @"\Resources\DistPrivKey1.p12"); 
     var push = new PushBroker(); 
     push.RegisterAppleService(new ApplePushChannelSettings(IsProduction, appleCert, "password")); 

     push.QueueNotification(new AppleNotification() 
      .ForDeviceToken(devicetoken.ToUpper()) 
      .WithAlert("Test Notification")); 

      push.StopAllServices(); 
    } 
    catch (Exception ex) 
    { 
     throw; 
    } 
} 
+0

您是否嘗試使用openssl和使用企業證書連接到apns服務?首先確認您的證書沒有問題。 – Nilesh

+0

不是嗎?我不清楚該怎麼做。你能詳細說明嗎? –

+0

你應該運行這個命令:openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert YourSSLCertAndPrivateKey.pem -debug -showcerts -CAfile「Entrust.net Certification Authority(2048).pem」根據你正在使用哪種證書。如果無法連接,則證書或網絡配置有問題。 – Nilesh

回答

1

使用以下命令

openssl pkcs12 -in yourP12File.pfx -nocerts -out privateKey.pem 

    openssl pkcs12 -in yourP12File.pfx -clcerts -nokeys -out publicCert.pem 
將您的SSL證書以PEM格式

然後運行以下命令以確保證書或網絡連接沒有問題。

openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert YourSSLCertAndPrivateKey.pem -debug -showcerts -CAfile "Entrust.net Certification Authority (2048).pem"

您應該下載Entrust證書並將其轉換爲pem,因爲APNS證書由Entrust簽署。

+0

行@Nilesh。我不認爲我正在使用APNS證書。我生成了一個並下載了Entrust證書(作爲.cer.txt下載),但我無法實現。我不確定我是否使用了正確的私鑰(我不確定在哪裏獲得我的APNS證書的私鑰)。 –

+0

謝謝你的幫助Nilesh。你的回答表明我的證書是無效的。出於某種原因,我必須爲APNS證書生成新的CSR。否則,APNS證書在鑰匙串中沒有與其關聯的任何密鑰。這樣做併爲PushSharp導出p12工作。 –

+0

很高興幫助:) – Nilesh