Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apple push notification get an error Authentication failed because the remote party has closed the transport stream

I get the follwoing error "Authentication failed because the remote party has closed the transport stream"

after the ling code: stream.AuthenticateAsClient(this.appleSettings.Host, this.certificates, System.Security.Authentication.SslProtocols.Ssl3, false);

It poined to a valid p.12

void connect()
        {
            client = new TcpClient();

            //Notify we are connecting
            var eoc = this.OnConnecting;
            if (eoc != null)
                eoc(this.appleSettings.Host, this.appleSettings.Port);

            try
            {
                client.Connect(this.appleSettings.Host, this.appleSettings.Port);
            }
            catch (Exception ex)
            {
                throw new ConnectionFailureException("Connection to Host Failed", ex);
            }

            if (appleSettings.SkipSsl)
            {
                networkStream = client.GetStream();
            }
            else
            {
                stream = new SslStream(client.GetStream(), false,
                    new RemoteCertificateValidationCallback((sender, cert, chain, sslPolicyErrors) => { return true; }),
                    new LocalCertificateSelectionCallback((sender, targetHost, localCerts, remoteCert, acceptableIssuers) =>
                    {
                        return certificate;
                    }));

                try
                {
                    stream.AuthenticateAsClient(this.appleSettings.Host, this.certificates, System.Security.Authentication.SslProtocols.Ssl3, false);
                    //stream.AuthenticateAsClient(this.appleSettings.Host);
                }
                catch (System.Security.Authentication.AuthenticationException ex)
                {
                    throw new ConnectionFailureException("SSL Stream Failed to Authenticate as Client", ex);
                }

                if (!stream.IsMutuallyAuthenticated)
                    throw new ConnectionFailureException("SSL Stream Failed to Authenticate", null);

                if (!stream.CanWrite)
                    throw new ConnectionFailureException("SSL Stream is not Writable", null);

                networkStream = stream;
            }

            //Start reading from the stream asynchronously
            Reader();
        }

    }
like image 332
Ortal Blumenfeld Lagziel Avatar asked Nov 03 '14 12:11

Ortal Blumenfeld Lagziel


2 Answers

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

https://developer.apple.com/news/?id=10222014a

Apple push servers no longer supports SSL3. Try change this to .Default or .TLS and it should work.

like image 109
KristofferArl Avatar answered Nov 18 '22 21:11

KristofferArl


I have used Moon API for .NET and change Protocol Ssl3 to Tls as Above and used .p12 file instead of .pem .p12 is generated using fallowing certificates.

$ openssl pkcs12 -export -in chatPushCert.pem -inkey chatPushKey.pem -certfile CertificateSigningRequest.certSigningRequest -name "apn_developer_identity" -out apn_developer_identity.p12

and every thing working very fine.

like image 1
Dilip Ingole Patil Avatar answered Nov 18 '22 21:11

Dilip Ingole Patil