Ortal Blumenfeld Lagziel
Ortal Blumenfeld Lagziel

Reputation: 2555

Apns c# exception unable to read data from the transport connection an existing connection was forcibly closed by the remote host

Im trying to send apple push notification with valid p12 and token as following:

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.Tls, 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();
        }

    }

when i changed the line code: System.Security.Authentication.SslProtocols.Tls to System.Security.Authentication.SslProtocols.Ssl3 i get "Authentication failed because the remote party has closed the transport stream"

How can i send APNS? How can i send apns???

Upvotes: 2

Views: 1322

Answers (1)

Mad Myche
Mad Myche

Reputation: 1075

SSL3 has been dumped by Apple (amongst others) within the last month (Oct 2014) due to a major security flaw; known as POODLE(Padding Oracle On Downgraded Legacy Encryption).

Upvotes: 1

Related Questions