【问题标题】:iPhone certificate error in apns sharp A call to SSPI failedapns sharp 中的 iPhone 证书错误调用 SSPI 失败
【发布时间】:2011-07-15 13:02:45
【问题描述】:

我有一个托管在 azure 中的数据服务,我从中向 iphone 发送通知,但是在与 apns 建立连接时出现以下错误 “对 SSPI 的调用失败。收到的消息出乎意料或格式错误。”我还参考了以下链接以获取相同的错误,但仍然收到错误

apple push notification with APNS sharpC# iPhone push server?

        try
        {
            using (TcpClient client = new TcpClient())
            {

                try
                {
                    client.Connect("gateway.sandbox.push.apple.com", 2195);
                    Logging("TSSLProDi :Connected to Apple");
                }
                catch (Exception ex)
                {
                    Logging("TSSLProDi :" + ex.Message + "-IE-" + ex.InnerException);

                }
                using (NetworkStream networkStream = client.GetStream())
                {
                    Logging("TSSLProDi :Client connected.");

                    X509Certificate clientCertificate = new X509Certificate(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory + @"startup\certname.pfx"), "mycertpassword");
                    X509CertificateCollection clientCertificateCollection = new X509CertificateCollection(new X509Certificate[1] { clientCertificate });

                    // Create an SSL stream that will close the client's stream.
                    SslStream sslStream = new SslStream(
                        client.GetStream(),
                        false,
                        new RemoteCertificateValidationCallback(validateServerCertificate),
                        null
                        );

                    try
                    {
                        sslStream.AuthenticateAsClient("gateway.sandbox.push.apple.com", clientCertificateCollection, System.Security.Authentication.SslProtocols.Default, false);
                        Logging("TSSLProDi :slStreamAuthenticated");
                    }
                    catch (AuthenticationException ex)
                    {
                        Logging("TSSLProDi :" + "Exception: " + ex.Message.ToString());
                        if (ex.InnerException != null)
                        {
                            Logging("Inner exception: " + ex.InnerException.Message.ToString());
                        }
                        Logging("TSSLProDi :" + "Authentication failed - closing the connection.");
                        client.Close();
                        return;
                    }
                }

            }
        }
        catch (Exception ex)
        {

            Logging("TSSLProCert :" + ex.Message + "-IE-" + ex.InnerException);
        }

我还在 VM 上安装了所需的证书。 我收到从苹果获得的 iphone developer_identity 证书的一个警告是“Windows 没有足够的信息来验证此证书”我的 iphone 证书有问题。请帮帮我,我卡住了

【问题讨论】:

    标签: iphone azure apple-push-notifications apns-sharp


    【解决方案1】:

    得到了解决方案,我刚刚将 X509Certificate 更改为 X509Certificate2 并将 X509CertificateCollection 更改为 X509Certificate2Collection

    【讨论】:

      【解决方案2】:

      我建议您按照本教程中的步骤从您的开发者证书创建一个 p12 文件。

      http://help.adobe.com/en_US/as3/iphone/WS144092a96ffef7cc-371badff126abc17b1f-7fff.html

      在 Windows 中注册此文件也很重要。这就像在生成文件后双击文件一样简单。之后不要忘记更新对 X509Certificate 构造函数的调用。

      本教程在 Windows 上同样适用,但您可能需要下载 OpenSSL 客户端,该客户端可在此处找到:

      http://gnuwin32.sourceforge.net/packages/openssl.htm.

      【讨论】:

      • 嘿,我按照你提到的做了,但我仍然收到“对 sspi 的调用失败......”的错误。
      • 您的 p12 文件路径可能仍然存在问题。首先尝试硬编码路径,看看这是否可能是问题所在。并且不要忘记在 Windows 中注册文件。
      • 我已经在受信任的根 ca 部分和个人部分注册了证书。我尝试使用硬编码值,但仍然出现相同的错误。
      • 对 p12 文件运行此命令时的输出是什么? openssl pkcs12 -info -in filename.p12
      【解决方案3】:

      我不知道这在 3 年后是否会有所帮助,但我将答案留给 iOS8。

      Apple 已经更改了服务器安全性,就在您提到的那一行,您必须从 SSL 更改为 TLS:

      原码:

      _apnsStream.AuthenticateAsClient(host,certificates,System.Security.Authentication.SslProtocols.Ssl3, false); 
      

      新代码:

      _apnsStream.AuthenticateAsClient(host,certificates,System.Security.Authentication.SslProtocols.Tls, false);
      

      我希望这些信息对某人有所帮助。

      有人在 GIT 论坛中对此发表了评论

      【讨论】:

      • 解决了我的问题,感谢您的回答。我希望他们有一些信息,他们做了这个改变
      • 非常感谢马可安东尼奥!
      【解决方案4】:

      有点晚了,但谁知道它是否对某人有帮助...我在证书上犯了一个大错误,并安装了我从 Apple Developer Site 下载的 .CER...我知道...我的错,但它可能如果你像我一样愚蠢,就会发生:-P

      当您下载 .CER 时,您必须将其导入您的钥匙串,然后导出包含私钥的证书...这将生成一个 .P12 证书,这是您必须在 Windows 中安装的证书机器。在 LocalMachine/Personal 商店中安装 .P12 后,身份验证对我来说效果很好。

      【讨论】:

        【解决方案5】:

        我也遇到了同样的问题,我用.p12证书文件代替.pfx并使用moon-apns发送通知,问题解决了。

        在此处下载 Moon-APNS 代码:https://github.com/arashnorouzi/Moon-APNS

        【讨论】:

          【解决方案6】:

          试试这个:

          SslStream sslStream = new SslStream(client.GetStream(), false);
          

          【讨论】:

          • 也试过但同样的错误。我有正确的证书和密码代码有什么问题
          猜你喜欢
          • 2015-07-16
          • 2013-09-04
          • 1970-01-01
          • 2019-06-29
          • 2019-09-08
          • 2015-10-19
          • 2015-06-05
          • 2015-11-19
          相关资源
          最近更新 更多