证书的 iOS 推送通知 AuthenticationException [英] iOS Push Notifications AuthenticationException for Certificate

查看:29
本文介绍了证书的 iOS 推送通知 AuthenticationException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to use PushSharp to send a push notification to my app. I have two Apple accounts... one is a regular account, and the other is an Enterprise account. I have a developer certificate on the regular account that works, but both my development and distribution certificates fail to work from the Enterprise account. I get an Authentication Exception..

A call to SSPI failed, see inner exception.

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

出现在PushSharp的这段代码中(我没有注释掉这一行):

This occurs in this code of PushSharp (I didn't comment the line out):

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

这是我的测试项目中的代码:

Here is the code from my test project:

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

推荐答案

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

Convert your ssl certificates to pem format using following commands

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

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

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

Then run following command to ensure that there is no issue with your certificate or network connection.

openssl s_client -connect gateway.sandbox.push.apple.com:2195 -certYourSSLCertAndPrivateKey.pem -debug -showcerts -CAfile "Entrust.net证书颁发机构 (2048).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 签署的.

You should download Entrust certificate and convert it to pem as APNS certificates are signed by Entrust.

这篇关于证书的 iOS 推送通知 AuthenticationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆