apns Sharp 中的 iPhone 证书错误 对 SSPI 的调用失败

发布于 2024-11-24 07:00:51 字数 2883 浏览 2 评论 0原文

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

apple Push通知 APNS SharpC# iPhone 推送服务器?

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

我也在虚拟机上安装了所需的证书。 我从苹果获得的 iPhone Developer_identity 证书上收到的一个警告是“Windows 没有足够的信息来验证此证书”是我的 iPhone 证书有问题。请帮助我,我被困住了

i have a data service hosted in azure from which i am sending notification to iphone but while establishing connection with apns i am getting following error
"A call to SSPI failed. The message received was unexpected or badly formatted." i also refered following links for the same error but still getting the error

apple push notification with APNS sharp and
C# 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);
        }

i have installed the needed certificates on VM also.
one warning i am getting on iphone developer_identity certificate which i got from apple is that "Windows does not have enough information to verify this certificate" is there is some thing wrong with my iphone certificate. please help me i am stuck

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

半世晨晓 2024-12-01 07:00:51

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

got the solution i have just changed X509Certificate to X509Certificate2 and X509CertificateCollection to X509Certificate2Collection

讽刺将军 2024-12-01 07:00:51

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

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

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

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

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

I suggest you follow the steps in this tutorial to create a p12 file from you developer certificate.

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

It's also important that you register this file in windows. This is as simple as double-clicking the file after you've generated it. Don't forget to update the call to the X509Certificate constructor afterwards.

The tutorial works equally well on Windows, but you might have to download an OpenSSL client which can be found here:

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

于我来说 2024-12-01 07:00:51

我不知道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论坛评论了这个

I do not know if this will be helpful after 3 years, but I leave the answer for iOS8.

Apple has changed the server security and right on the line you mention, you have to change from SSL to TLS:

Original code:

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

New code:

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

I hope this information is helpful to someone.

Someone commented this in the GIT forum

意中人 2024-12-01 07:00:51

有点晚了,但谁知道它是否对某人有帮助...我在证书方面犯了一个大错误,并安装了我从苹果开发者网站下载的.CER...我知道...我的错,但如果你和我一样愚蠢:-P

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

Little late, but who knows if it helps somebody... I made a big mistake with the certificate, and installed the .CER I downloaded from Apple Developer Site... I know... my fault, but it could happen if you're as dumb as I am :-P

When you download the .CER, you have to import it into your keychain and then EXPORT the certificate INCLUDING the private key... that will generate a .P12 certificate, and THAT is the one you have to install in the Windows machine. Once I installed the .P12 in the LocalMachine/Personal store, the authentication worked just fine for me.

抠脚大汉 2024-12-01 07:00:51

我遇到了同样的问题,我使用 .p12 证书文件而不是 .pfx 并使用 Moon-apns 发送通知,问题已解决。

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

I got same problem, I use .p12 certificate file instead of .pfx and use moon-apns to send notification, the problem been solved.

Donwnload Moon-APNS code here: https://github.com/arashnorouzi/Moon-APNS

箹锭⒈辈孓 2024-12-01 07:00:51

试试这个:

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

Try this :

SslStream sslStream = new SslStream(client.GetStream(), false);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文