2

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

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

任何人都可以帮助我吗?

提前致谢。

4

6 回答 6

2

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

于 2011-07-19T16:00:54.330 回答
2

最近我还收到错误: “对 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
);

希望它会帮助某人...

于 2014-10-18T09:36:11.357 回答
0

我个人使用这个:

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();
于 2011-01-10T15:23:01.060 回答
0

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

于 2016-10-05T11:11:38.063 回答
0

我认为这里的问题是您在服务器开发中将证书从苹果转换为证书,您可以在 openssl 中使用以下命令来做到这一点:

  • 命令1: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
于 2015-07-27T08:13:20.120 回答
0

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

于 2016-04-28T04:32:14.103 回答