sta / websocket-sharp

A C# implementation of the WebSocket protocol client and server
http://sta.github.io/websocket-sharp
MIT License
5.7k stars 1.66k forks source link

KB 3147458 - Windows 10 broken SSL #253

Open Terricide opened 8 years ago

Terricide commented 8 years ago

Hi I'm not sure if anyone else has seen this but it looks like a change in how Windows 10 works with an SSL stream has broken WebSocket Sharp. Has anyone else seen this?

https://connect.microsoft.com/VisualStudio/feedback/details/2590316/windows-10-update-kb3147458-changes-behavior-of-sslstream-read-beginread-endread

Terricide commented 8 years ago

Also someone posted this as a workaround.

This can be worked around if all Read operations are performed in a loop to fill the buffer to the expected size. technically the SslStream operation reports the bytes read, and you can use this to determine if you expect more data and can continue to fill your buffer. (This is good practice anyways) But this is still a breaking change to some people's code base. taken from this StackOverflow answer: http://stackoverflow.com/questions/36676593/sslstream-reads-invalid-data-kb3147458-sslstream-bug-solved

            byte[] buffer = new byte[MESSAGE_SIZE];
            while (offset < MESSAGE_SIZE)
            {
                bytes = sslStream.Read(buffer, offset, MESSAGE_SIZE - offset);
                offset += bytes;
            }
Terricide commented 8 years ago

I believe I fixed the issue by adding this code to HttpConnection.cs

if (nread == 1) { conn._stream.BeginRead(conn._buffer, 0, _bufferSize, onRead, conn); return; }

Terricide commented 8 years ago

FYI this change to .NET has trickled down to windows 7 now.