HarunBahcel / apns-sharp

Automatically exported from code.google.com/p/apns-sharp
0 stars 0 forks source link

FeedbackService - infinite loop when attempting connect with expired cert #14

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. using an expired P12 certificate
2. run the Feedback test console app
3. There is an exception that results in an infinite loop in
FeedbackService.cs (while loop staring line 261)

What is the expected output? What do you see instead?
exit from the while loop and return.

What version of the product are you using? On what operating system?
Apns-Sharp-1.0.1.0 on Windows 7 / VS2008 SP1

Please provide any additional information below.

Exception Message: A call to SSPI failed, see inner exception.
Inner Exception Message: The received certificate has expired.

Stack Trace:
   at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken
message, AsyncProtocolRequest asyncRequest, Exception exception)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32
count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer,
AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32
count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer,
AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32
count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer,
AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32
count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer,
AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ForceAuthentication(Boolean
receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult
lazyResult)
   at JdSoft.Apple.Apns.Feedback.FeedbackService.ensureConnected() in
D:\code\j2\Apns-Sharp-1.0.1.0-Source\JdSoft.Apple.Apns.Feedback\FeedbackService.
cs:line
271

The problem would seem to be that the exception is suppressed and there is
no call to break from the while loop. Thus the while loop conditions are
never met (!connected && !disposing) and the connection is attempted
indefinitely. 

==== patched method ====

private bool ensureConnected()
        {
            bool connected = false;

            if (apnsStream == null || !apnsStream.CanWrite)
                connected = false;

            if (apnsClient == null || !apnsClient.Connected)
                connected = false;

            while (!connected && !disposing)
            {
                try
                {
                    apnsClient = new TcpClient(Host, Port);

                    apnsStream = new SslStream(apnsClient.GetStream(), true,
                        new RemoteCertificateValidationCallback(validateServerCertificate),
                        new LocalCertificateSelectionCallback(selectLocalCertificate));

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

                    connected = apnsStream.CanWrite;
                }
                catch (Exception ex)
                {
                    if (this.Error != null)
                        this.Error(this, ex);

                    connected = false;
                                    ///////// possible patch? //////////
                                    // break to prevent infinite loop
                    break;
                }

            }

            return connected;
        }

Original issue reported on code.google.com by ratherfl...@gmail.com on 15 Nov 2009 at 10:03

Attachments:

GoogleCodeExporter commented 8 years ago
I've added properties to FeedbackService:  ConnectAttemps and ReconnectDelay

This should prevent infinite looping.

Original comment by jond...@gmail.com on 22 Dec 2009 at 5:56

GoogleCodeExporter commented 8 years ago
Well, it doesn't.

Original comment by stevenjc...@gmail.com on 15 May 2012 at 1:52