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

时间:2011-01-07 11:35:47

标签: apple-push-notifications apns-sharp

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

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

任何人都可以帮助我。

提前致谢。

6 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分: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
);

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

答案 2 :(得分: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();

答案 3 :(得分:0)

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

  • 命令1: 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
  • 指令代码3: openssl pkcs12 -export -inkey" pushkey1.pem" -in" apn_developer_identity.pem" -out" apn_developer_identity.p12" -passin pass:yourpass -passout pass:yourpass

答案 4 :(得分:0)

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

答案 5 :(得分:0)

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

相关问题