c# - 证书的 iOS 推送通知 AuthenticationException

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

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

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

最佳答案

使用以下命令将您的 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 Certification Authority (2048).pem"

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

关于c# - 证书的 iOS 推送通知 AuthenticationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21947135/

相关文章:

c# - 如何使用编码的 UI 测试查找网页中的所有链接?

c# - C# 中有指数运算符吗?

ssl - SSL_CTX_set_verify 回调从哪里获取证书?

c# - 如何在 .NET C# 中为 HTTP/2 服务器实现 TLS-ALPN

php - 推送通知 Drupal 模块 - 删除设备(Web 服务)

android - 如何在华为上显示应用图标徽章编号

c# - DbContext的第三方实现,如何同时实现IdentityDbContext

c# - EF 核心 : Cannot insert explicit value for identity column in table when IDENTITY_INSERT is set to OFF on one to many

wordpress - 任何完整的修复混合内容 WP 插件?

ios - 推送通知 IOS react native NSDictionary 错误