Bug 594301

Summary: HTTPS problems after inactivity
Product: [Novell Products] MonoTouch Reporter: Olaf Bartelt <obartelt>
Component: RuntimeAssignee: Mono Bugs <mono-bugs>
Status: RESOLVED FIXED QA Contact: Mono Bugs <mono-bugs>
Severity: Critical    
Priority: P5 - None    
Version: unspecified   
Target Milestone: ---   
Hardware: Other   
OS: Other   
Whiteboard:
Found By: Customer Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Attachments: Sample solution including crash report and device log

Description Olaf Bartelt 2010-04-07 09:47:12 UTC
Description of Problem:

When using HTTPS in our application, after there has been some time of inactivity (in most cases somewhere between 2-5 minutes, sometimes with the device suspending, sometimes not (this time happend during profiling with Instruments)), the app crashes in Mono.Security.X509.OSX509Certificates.SecTrustCreateWithCertificates.

Steps to reproduce the problem:

We're using a mixture of System.Net.WebClient and UIWebViews, sometimes also System.Net.HttpWebRequest, all with the same HTTPS url with a valid certificate. No handling for invalid certificates is used.

Actual Results:

The app crashes.

Expected Results:

The HTTPS request should work.

How often does this happen? 

Often.

Additional Information:

Here is the stack trace from the xcode organizer console window:

Wed Apr  7 11:26:26 unknown UIKitApplication:com.amtangee.amtangee[0xd3db][158] <Notice>: Stacktrace:
Wed Apr  7 11:26:26 unknown UIKitApplication:com.amtangee.amtangee[0xd3db][158] <Notice>:   at (wrapper managed-to-native) Mono.Security.X509.OSX509Certificates.SecTrustCreateWithCertificates (intptr,intptr,intptr&) <0xffffffff>
Wed Apr  7 11:26:26 unknown UIKitApplication:com.amtangee.amtangee[0xd3db][158] <Notice>:   at Mono.Security.X509.OSX509Certificates._TrustEvaluateSsl (Mono.Security.X509.X509CertificateCollection) <0x00248>
Wed Apr  7 11:26:26 unknown UIKitApplication:com.amtangee.amtangee[0xd3db][158] <Notice>:   at Mono.Security.X509.OSX509Certificates.TrustEvaluateSsl (Mono.Security.X509.X509CertificateCollection) <0x00023>
Wed Apr  7 11:26:26 unknown UIKitApplication:com.amtangee.amtangee[0xd3db][158] <Notice>:   at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.validateCertificates (Mono.Security.X509.X509CertificateCollection) <0x002f3>
Wed Apr  7 11:26:26 unknown UIKitApplication:com.amtangee.amtangee[0xd3db][158] <Notice>:   at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.ProcessAsTls1 () <0x000cb>
Wed Apr  7 11:26:26 unknown UIKitApplication:com.amtangee.amtangee[0xd3db][158] <Notice>:   at Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process () <0x00053>
Wed Apr  7 11:26:26 unknown UIKitApplication:com.amtangee.amtangee[0xd3db][158] <Notice>:   at Mono.Security.Protocol.Tls.ClientRecordProtocol.ProcessHandshakeMessage (Mono.Security.Protocol.Tls.TlsStream) <0x000a3>
Wed Apr  7 11:26:26 unknown UIKitApplication:com.amtangee.amtangee[0xd3db][158] <Notice>:   at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (System.IAsyncResult) <0x002d7>
Wed Apr  7 11:26:26 unknown UIKitApplication:com.amtangee.amtangee[0xd3db][158] <Notice>:   at System.Net.Sockets.Socket/SocketAsyncResult.Complete () <0x0020b>
Wed Apr  7 11:26:26 unknown UIKitApplication:com.amtangee.amtangee[0xd3db][158] <Notice>:   at System.Net.Sockets.Socket/Worker.Receive () <0x00027>
Wed Apr  7 11:26:26 unknown UIKitApplication:com.amtangee.amtangee[0xd3db][158] <Notice>:   at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0x000c3>
Wed Apr  7 11:26:26 unknown UIKitApplication:com.amtangee.amtangee[0xd3db][158] <Notice>: Native stacktrace:
Wed Apr  7 11:26:26 unknown UIKitApplication:com.amtangee.amtangee[0xd3db][158] <Notice>: 	0   AMTANGEE                            0x00030450 0x0 + 197712
Wed Apr  7 11:26:26 unknown UIKitApplication:com.amtangee.amtangee[0xd3db][158] <Notice>: 	1   AMTANGEE                            0x0000bbe0 0x0 + 48096
Wed Apr  7 11:26:26 unknown UIKitApplication:com.amtangee.amtangee[0xd3db][158] <Notice>: 	2   libSystem.B.dylib                   0x327bb823 _sigtramp + 34
Wed Apr  7 11:26:26 unknown UIKitApplication:com.amtangee.amtangee[0xd3db][158] <Notice>: 	3   CoreFoundation                      0x32d890bd CFGetTypeID + 64
Wed Apr  7 11:26:26 unknown UIKitApplication:com.amtangee.amtangee[0xd3db][158] <Notice>: 	4   Security                            0x305a1634 SecTrustCreateWithCertificates + 236
Wed Apr  7 11:26:26 unknown UIKitApplication:com.amtangee.amtangee[0xd3db][158] <Notice>: 	5   AMTANGEE                            0x002f0e90 WriteZStream + 1337580
Wed Apr  7 11:26:26 unknown UIKitApplication:com.amtangee.amtangee[0xd3db][158] <Notice>: 	6   ???                                 0x0493e8ec 0x0 + 76802284
Wed Apr  7 11:26:26 unknown UIKitApplication:com.amtangee.amtangee[0xd3db][158] <Notice>: * Assertion: should not be reached at ../../../../mono/mini/mini-darwin.c:258
Comment 1 Olaf Bartelt 2010-04-07 10:46:07 UTC
I'm using MonoTouch 1.5 Professional, forgot to mention that...
Comment 2 Geoff Norton 2010-04-08 03:24:24 UTC
Hello,

  Could you provide a sample application which exhibits this behaviour?  Thanks.
Comment 3 Miguel de Icaza 2010-04-08 04:05:08 UTC
A cleaned up stack-trace:
 Stacktrace:
   at (wrapper managed-to-native) Mono.Security.X509.OSX509Certificates.SecTrustCreateWithCertificates (intptr,intptr,intptr&) <0xffffffff>
   at Mono.Security.X509.OSX509Certificates._TrustEvaluateSsl (Mono.Security.X509.X509CertificateCollection) <0x00248>
   at Mono.Security.X509.OSX509Certificates.TrustEvaluateSsl (Mono.Security.X509.X509CertificateCollection) <0x00023>
   at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.validateCertificates (Mono.Security.X509.X509CertificateCollection) <0x002f3>
   at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.ProcessAsTls1 () <0x000cb>
   at Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process () <0x00053>
   at Mono.Security.Protocol.Tls.ClientRecordProtocol.ProcessHandshakeMessage (Mono.Security.Protocol.Tls.TlsStream) <0x000a3>
   at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (System.IAsyncResult) <0x002d7>
   at System.Net.Sockets.Socket/SocketAsyncResult.Complete () <0x0020b>
   at System.Net.Sockets.Socket/Worker.Receive () <0x00027>
   at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0x000c3>

 Native stacktrace:
     0   AMTANGEE                            0x00030450 0x0 + 197712
     1   AMTANGEE                            0x0000bbe0 0x0 + 48096
     2   libSystem.B.dylib                   0x327bb823 _sigtramp + 34
     3   CoreFoundation                      0x32d890bd CFGetTypeID +
64
     4   Security                            0x305a1634
SecTrustCreateWithCertificates + 236
     5   AMTANGEE                            0x002f0e90 WriteZStream +
1337580
     6   ???                                 0x0493e8ec 0x0 + 76802284
 * Assertion: should not be reached at
Comment 4 Olaf Bartelt 2010-04-08 08:20:49 UTC
(In reply to comment #2)
> Hello,
> 
>   Could you provide a sample application which exhibits this behaviour? 
> Thanks.

I'll try and build one, but am quite busy at the moment as there are other things needed to be done to our app.

Maybe if it helps in the meantime: Most of the time, I fetch the HTTPS request using System.Net.WebClient.DownloadString(url) first and then parse the result and load that into a UIWebView with LoadHtmlString, but I believe the problem occurs with the WebClient...

Thanks,
Olaf
Comment 5 Olaf Bartelt 2010-04-08 09:22:16 UTC
Created attachment 353095 [details]
Sample solution including crash report and device log

This attachment include a simple sample that exhibits the same behaviour. I was able to reproduce the issue when launching the application, changing the selected tab to "Item 2", then waiting for the device to suspend while connected via USB, then re-activating the device and switching to "Item 1". You probably have to try that a few times, it does not seem to fail everytime.
Comment 6 Olaf Bartelt 2010-04-08 12:19:25 UTC
Bug 594625 seems to be the exact same issue and stacktrace, though on Mac OS X/Mono 2.6.3 and not on the iPhone/MonoTouch - maybe this helps...

Also I have updated today to MonoTouch 2.0.1 and the latest Mono and MonoDevelop final releases, and the problem persists...
Comment 7 Geoff Norton 2010-04-28 19:01:26 UTC
This should be fixed in the next release.