iOS推送通知证书的AuthenticationException

时间:2014-02-21 23:18:10

标签: c# ssl push-notification apple-push-notifications pushsharp

我正在尝试使用PushSharp向我的应用发送推送通知。我有两个Apple帐户...一个是普通帐户,另一个是企业帐户。我在常规帐户上有开发人员证书,但我的开发和分发证书都无法在Enterprise帐户中运行。我收到了身份验证异常..

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

1 个答案:

答案 0 :(得分:1)

使用以下命令将您的ssl证书转换为pem格式

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

    openssl pkcs12 -in yourP12File.pfx -clcerts -nokeys -out publicCert.pem

然后运行以下命令以确保您的证书或网络连接没有问题。

  

openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert   YourSSLCertAndPrivateKey.pem -debug -showcerts -CAfile“Entrust.net   证书颁发机构(2048).pem“

您应下载Entrust证书并将其转换为pem,因为APNS证书已由Entrust签署。