websocket-sharp icon indicating copy to clipboard operation
websocket-sharp copied to clipboard

Server with SSL enabled throws exceptions while receiving handshake

Open brkastner opened this issue 12 years ago • 7 comments

I'm trying to get a websocket server set up that runs on port 7031 and uses SSL. However, whenever I try to open a connection with the server it doesn't work, and the log file has this information:

4/7/2014 8:25:39 PM|Fatal|<>c__DisplayClass3.<acceptRequestAsync>b__2:479|WebSocketSharp.WebSocketException: An exception has occurred while receiving a handshake. ---> System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
                          Parameter name: value:-1 char: 
                             at WebSocketSharp.Ext.EqualsWith(Int32 value, Char c, Action`1 action) in c:\Sources\websocket-sharp\websocket-sharp\Ext.cs:line 444
                             at WebSocketSharp.WsStream.readHandshakeHeaders(Stream stream) in c:\Sources\websocket-sharp\websocket-sharp\WsStream.cs:line 121
                             at WebSocketSharp.WsStream.ReadHandshake[T](Func`2 parser, Int32 millisecondsTimeout) in c:\Sources\websocket-sharp\websocket-sharp\WsStream.cs:line 202
                             --- End of inner exception stack trace ---
                             at WebSocketSharp.WsStream.ReadHandshake[T](Func`2 parser, Int32 millisecondsTimeout) in c:\Sources\websocket-sharp\websocket-sharp\WsStream.cs:line 225
                             at WebSocketSharp.Net.WebSockets.TcpListenerWebSocketContext..ctor(TcpClient client, X509Certificate cert, Boolean secure, Logger logger) in c:\Sources\websocket-sharp\websocket-sharp\Net\WebSockets\TcpListenerWebSocketContext.cs:line 67
                             at WebSocketSharp.Ext.GetWebSocketContext(TcpClient client, X509Certificate cert, Boolean secure, Logger logger) in c:\Sources\websocket-sharp\websocket-sharp\Ext.cs:line 515
                             at WebSocketSharp.Server.WebSocketServer.<>c__DisplayClass3.<acceptRequestAsync>b__2(Object state) in c:\Sources\websocket-sharp\websocket-sharp\Server\WebSocketServer.cs:line 479

I amended the function EqualsWith to show the int and char passed in so that is where the -1 comes from on the second line. I'm starting the server the following way:

_secureListener = new WebSocketServer(7031, true);
                var certLocation = Path.Combine(Path.GetDirectoryName(
                    new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath), "server.pfx");
                _secureListener.Certificate = new X509Certificate2(certLocation, "password");
                _secureListener.AddWebSocketService<Listener>("/");
                _secureListener.Log.File = Path.Combine(Path.GetDirectoryName(
                    new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath), "websocketlog.txt");
                _secureListener.Start();

The certificate being used was created the following way:

makecert.exe -r -pe -n "CN=localhost" -sky exchange -sv server.pvk server.cer
pvk2pfx -pvk server.pvk -spc server.cer -pfx server.pfx

When I connect from my application's corresponding browser extensions (Chrome & Firefox) the connection is immediately closed with the status code 1006.

Any ideas what could be going wrong?

brkastner avatar Apr 08 '14 01:04 brkastner

Is it available without SSL?

sta avatar Apr 08 '14 08:04 sta

When I start it without SSL it works fine, yep. On Apr 8, 2014 3:23 AM, "sta" [email protected] wrote:

Is it available without SSL?

Reply to this email directly or view it on GitHubhttps://github.com/sta/websocket-sharp/issues/37#issuecomment-39822943 .

brkastner avatar Apr 08 '14 13:04 brkastner

Was your WebSocket client created with wss scheme URL (e.g. wss://localhost:7031) to connect to the server with SSL?

sta avatar Apr 08 '14 14:04 sta

Yep! On Apr 8, 2014 9:18 AM, "sta" [email protected] wrote:

Was your WebSocket client created with wss scheme URL (e.g. wss://localhost:7031) to connect to the server with SSL?

Reply to this email directly or view it on GitHubhttps://github.com/sta/websocket-sharp/issues/37#issuecomment-39853010 .

brkastner avatar Apr 08 '14 14:04 brkastner

Hmm,,,

Certainly, it doesn't work from the client in web browser with the server.pfx created by makecert.exe (that you mentioned) on Windows 8.1 PC. (Intriguingly, it works from the client of websocket-sharp.)

So, i've tested with that server.pfx on my Linux Mint PC, it works from Firefox.

And also, i've tested on ancient Windows XP PC,,, it works from Firefox and Chrome.

I will investigate a little more.

sta avatar Apr 10 '14 13:04 sta

It seems that Windows 8.1 + major web browsers have something problem with SSL3.0/TLS1.0.

Plz see issue #38.

sta avatar Apr 17 '14 05:04 sta

Completely breaking my app, any way to fix?

paralin avatar Jun 04 '14 08:06 paralin