【问题标题】:iOS Push Notifications AuthenticationException for Certificate证书的 iOS 推送通知 AuthenticationException
【发布时间】:2014-03-23 17:13:16
【问题描述】:

我正在尝试使用 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;
    }
}

【问题讨论】:

  • 您是否尝试使用 openssl 和企业证书连接到 apns 服务?首先验证你的证书没有问题。
  • 没有?我还不清楚如何做到这一点。你能详细说明一下吗?
  • 你应该运行这个命令:openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert YourSSLCertAndPrivateKey.pem -debug -showcerts -CAfile "Entrust.net 证书颁发机构 (2048)。 pem" 根据您使用的证书更新 url。如果无法连接,则说明您的证书或网络配置有问题。
  • 我得到“无法加载客户端证书私钥文件 5793:error:0906D06C:PEM 例程:PEM_read_bio:no start line:/SourceCache/OpenSSL098/OpenSSL098-47.1/src/crypto/pem/pem_lib .c:648:期待:任何私钥”
  • 我可以使用此证书构建应用程序并通过 MDM 部署它。

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


【解决方案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 签名。

【讨论】:

  • 好的@Nilesh。我认为我没有使用 APNS 证书。我生成了一个并下载了 Entrust 证书(下载为 .cer.txt),但我无法让它工作。我不确定我是否使用了正确的私钥(我不确定从哪里获取我的 APNS 证书的私钥)。
  • 感谢您的帮助 Nilesh。您的回答表明我的证书无效。出于某种原因,我不得不为 APNS 证书生成一个新的 CSR。否则,APNS 证书在钥匙串中没有任何与之关联的密钥。这样做并为 PushSharp 导出 p12 是可行的。
猜你喜欢
  • 2015-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多