Bug 457120 - System.Net.Security.SslStream's AuthenticateAsServer hangs
Summary: System.Net.Security.SslStream's AuthenticateAsServer hangs
Status: VERIFIED FIXED
Alias: None
Product: Mono: Class Libraries
Classification: Mono
Component: CORLIB (show other bugs)
Version: 2.0.x
Hardware: x86 Windows Vista
: P5 - None : Major
Target Milestone: 2.6.x
Assignee: Mono Bugs
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords: DSLA_REQUIRED, DSLA_SOLUTION_PROVIDED
Depends on:
Blocks:
 
Reported: 2008-12-07 20:30 UTC by Maciej Paszta
Modified: 2012-06-25 05:10 UTC (History)
5 users (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
Server's code (3.51 KB, text/plain)
2008-12-07 20:32 UTC, Maciej Paszta
Details
Client code (2.41 KB, text/plain)
2008-12-07 20:32 UTC, Maciej Paszta
Details
Example client certificate (1.42 KB, application/octet-stream)
2008-12-07 20:33 UTC, Maciej Paszta
Details
Example server certificate (1.42 KB, application/octet-stream)
2008-12-07 20:33 UTC, Maciej Paszta
Details
Suggested fix for SslStream (467 bytes, patch)
2009-11-04 12:02 UTC, Maciej Paszta
Details | Diff
Test case (15.82 KB, text/plain)
2012-06-18 08:21 UTC, Maciej Paszta
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Maciej Paszta 2008-12-07 20:30:46 UTC
Client -> Server connection. In the tested environment the initial connection is made using plaintext communication (NetworkStream), when specific message is received SslStream is created on the top of the existing stream and further communication is done via secured channel. The authentication process requires both server and client to authenticate with their certificates. Call to the AuthenticateAsServer on the server side hangs and doesn't exit. Tested framework combinations:

Client(.Net) -> Server(.Net) - works
Client(Mono) -> Server(.Net) - works
Client(Mono) -> Server(Mono) - doesn't work
Client(.NET) -> Server(Mono) - doesn't work

The issue is present on Windows Vista as well as out production environment, which is Debian.
Comment 1 Maciej Paszta 2008-12-07 20:32:12 UTC
Created attachment 258496 [details]
Server's code

Code that works on the server side (only part of the original code is attached - but it exposes the issue)
Comment 2 Maciej Paszta 2008-12-07 20:32:42 UTC
Created attachment 258497 [details]
Client code

Client code
Comment 3 Maciej Paszta 2008-12-07 20:33:16 UTC
Created attachment 258498 [details]
Example client certificate
Comment 4 Maciej Paszta 2008-12-07 20:33:48 UTC
Created attachment 258499 [details]
Example server certificate

Example server certificate
Comment 5 Sebastien Pouliot 2008-12-08 13:55:27 UTC
Quick guess: the stream is not flushed prior to switching into SSL
Comment 6 Maciej Paszta 2008-12-08 16:31:23 UTC
Doing input.Flush() in server code prior to creating SslStream doesn't help
Comment 7 Maciej Paszta 2009-10-19 15:21:46 UTC
Yesterday my friend pointed about behavior that is exposed by SslServerStream - authentication process is triggered as soon as something is sent through the connection. I've altered my test case and put the following code in Client's Program.cs around line no. 50 :

m_sslClient.Write(new byte[] { 0 });

After this modification, server code finally exits from call to AuthenticateAsServer. This behavior is different than the one exposed by .NET framework.
Comment 8 Maciej Paszta 2009-11-04 12:02:55 UTC
Created attachment 325492 [details]
Suggested fix for SslStream

My friend Maciej Kowalewski prepared a simple patch that resolves the issue. This patch is somehow a workaround for how a SslServerStream works (there is no direct method to authenticate server/client contrary to SslStream).
Comment 9 Maciej Paszta 2010-04-13 07:35:27 UTC
Any news on the issue? I suppose that this bug also mentioned here: https://bugzilla.novell.com/show_bug.cgi?id=528508
Comment 10 Stuart Ross 2010-05-27 00:16:29 UTC
The suggested patch on this bug targets the same line of code on the suggested patch on this page.
https://bugzilla.novell.com/show_bug.cgi?id=430504
Comment 11 Chris Pugmire 2012-06-13 06:27:30 UTC
So this bug is now almost 4 years old, and still hasn't been patched in the latest source, I'm mystified, this bug prevents mono being used for some applications, the patch is a simple one line change that works (for me). 

But  I can't distribute a product which requires users to download mono, patch the source and rebuild it.  I don't mean to complain, I'm just curious how to get this fix applied, I'm happy to help if I can...
Comment 12 Maciej Paszta 2012-06-13 06:39:41 UTC
I was in the same situation regarding my software. I finally decided to embed the source code of SslStream from Mono into my application, patch it and use it to provide compatibility with .NETs implementation. Since the code is under MIT X11 license, there is no problem as long as you comply with its requirement and include a copy of the license in your software.
Comment 13 Forgotten User oDRaEXi7Ku 2012-06-14 10:24:03 UTC
(In reply to comment #11)
> ... the patch is a simple one line change that works (for me). 

The patch is more likely to get accepted if it adds a unit test that passes on .NET and fails in current Mono (but which doesn't fail after applying the fix).
Comment 14 Maciej Paszta 2012-06-18 08:21:05 UTC
Created attachment 495106 [details]
Test case

Provided test case (NUnit) that fails on Mono but succeeds on .NET and patched version of Mono.
Comment 15 Maciej Paszta 2012-06-25 05:10:16 UTC
Fixed with pull request 343: https://github.com/mono/mono/pull/343