APNS SSlStream 身份验证失败,因为远程方已关闭传输流

发布于 2024-10-11 11:02:49 字数 238 浏览 9 评论 0原文

我正在尝试使用 asp.net、C# 将通知推送到 iphone。我在这行代码中收到以下错误“身份验证失败,因为远程方已关闭传输流”。

sslStream.AuthenticateAsClient("gateway.sandbox.push.apple.com", clientCertificateCollection, SslProtocols.Ssl3, false);

任何人都可以帮助我吗?

提前致谢。

Im trying to push notification to iphone using asp.net, C#. I get the following error "Authentication failed because the remote party has closed the transport stream" in this line of code.

sslStream.AuthenticateAsClient("gateway.sandbox.push.apple.com", clientCertificateCollection, SslProtocols.Ssl3, false);

can anyone plz help me in this.

Thanks in advance.

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

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

发布评论

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

评论(6

我一直都在从未离去 2024-10-18 11:02:49

您可以尝试将 X509Certificate 更改为 X509Certificate2,将 X509CertificateCollection 更改为 X509Certificate2Collection。

you can try by changing X509Certificate to X509Certificate2 and X509CertificateCollection to X509Certificate2Collection.

‘画卷フ 2024-10-18 11:02:49

最近我也收到错误:
“对 SSPI 的调用失败。收到的消息意外或格式错误。”
内部异常:
“身份验证失败,因为远程方已关闭传输流”

对我有帮助的是更改一点 OpenSslStream 方法
- SSL 协议中的 TSL

旧代码:

apnsStream.AuthenticateAsClient(
    this.Host, this.certificates, 
    System.Security.Authentication.SslProtocols.Ssl3, 
    false
);

新代码:

apnsStream.AuthenticateAsClient(
    this.Host, this.certificates, 
    System.Security.Authentication.SslProtocols.Ssl3 | System.Security.Authentication.SslProtocols.Tls,
    false
);

希望它能帮助某人......

Recently I also received error:
"A call to SSPI failed. The message received was unexpected or badly formatted."
with internal exception:
"Authentication failed because the remote party has closed the transport stream"

What helped me is to change a little OpenSslStream method
- TSL in SSL protocol

old code:

apnsStream.AuthenticateAsClient(
    this.Host, this.certificates, 
    System.Security.Authentication.SslProtocols.Ssl3, 
    false
);

new code:

apnsStream.AuthenticateAsClient(
    this.Host, this.certificates, 
    System.Security.Authentication.SslProtocols.Ssl3 | System.Security.Authentication.SslProtocols.Tls,
    false
);

Hopefully it will help someone...

清风无影 2024-10-18 11:02:49

我个人使用这个:

sslStream.AuthenticateAsClient("gateway.sandbox.push.apple.com", clientCertificateCollection, SslProtocols.Default, false);

            using (TcpClient client = new TcpClient())
            {


                client.Connect("gateway.sandbox.push.apple.com", 2195);


                using (NetworkStream networkStream = client.GetStream())
                {
                    try
                    {

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


                        try
                        {
                            sslStream.AuthenticateAsClient("gateway.sandbox.push.apple.com", "gateway.sandbox.push.apple.com", SslProtocols.Default, false);
                          //building messages
                          sslStream.Write(msg);
                          sslStream.close();

Personally I use this :

sslStream.AuthenticateAsClient("gateway.sandbox.push.apple.com", clientCertificateCollection, SslProtocols.Default, false);

            using (TcpClient client = new TcpClient())
            {


                client.Connect("gateway.sandbox.push.apple.com", 2195);


                using (NetworkStream networkStream = client.GetStream())
                {
                    try
                    {

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


                        try
                        {
                            sslStream.AuthenticateAsClient("gateway.sandbox.push.apple.com", "gateway.sandbox.push.apple.com", SslProtocols.Default, false);
                          //building messages
                          sslStream.Write(msg);
                          sslStream.close();
紫瑟鸿黎 2024-10-18 11:02:49

我认为这里的问题是您已将苹果的证书转换为服务器开发上的证书,您可以在 openssl 中使用以下命令来执行此操作:

  • command1:
    openssl x509 -in“apn_developer_identity.cer”-inform DER -out“apn_developer_identity.pem”-outform PEM
  • 命令2:
    openssl pkcs12 -nocerts -in "pushkey1.p12" -out "pushkey1.pem" -passin pass:yourpass -passout pass:yourpass
  • command3:
    openssl pkcs12 -export -inkey "pushkey1.pem" -in "apn_developer_identity.pem" -out "apn_developer_identity.p12" -passin pass:yourpass -passout pass:yourpass

I think problem here is you have convert certificate from apple to certificate on server developement, you could use following command in openssl to do that:

  • command1:
    openssl x509 -in "apn_developer_identity.cer" -inform DER -out "apn_developer_identity.pem" -outform PEM
  • command2:
    openssl pkcs12 -nocerts -in "pushkey1.p12" -out "pushkey1.pem" -passin pass:yourpass -passout pass:yourpass
  • command3:
    openssl pkcs12 -export -inkey "pushkey1.pem" -in "apn_developer_identity.pem" -out "apn_developer_identity.p12" -passin pass:yourpass -passout pass:yourpass
北城半夏 2024-10-18 11:02:49

尝试下面的代码
sslStream.AuthenticateAsClient(“gateway.sandbox.push.apple.com”, clientCertificateCollection, SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls, false);

Try the below code
sslStream.AuthenticateAsClient("gateway.sandbox.push.apple.com", clientCertificateCollection, SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls, false);

痴者 2024-10-18 11:02:49

尝试仅使用私钥创建证书。

Try to create the certificate with Private key only.

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