diff --git a/websocket-sharp.userprefs b/websocket-sharp.userprefs index 1810154c..0c3f8470 100644 --- a/websocket-sharp.userprefs +++ b/websocket-sharp.userprefs @@ -1,8 +1,8 @@  - + - + diff --git a/websocket-sharp/Ext.cs b/websocket-sharp/Ext.cs index c5cb5172..0dc29f61 100644 --- a/websocket-sharp/Ext.cs +++ b/websocket-sharp/Ext.cs @@ -51,6 +51,12 @@ namespace WebSocketSharp return ((uint)rand.Next(upper16 + 1) << 16) + (uint)rand.Next(lower16 + 1); } + public static char GeneratePrintableASCIIwithoutSPandNum(this Random rand) + { + int ascii = rand.Next(2) == 0 ? rand.Next(33, 48) : rand.Next(58, 127); + return Convert.ToChar(ascii); + } + public static string GenerateSecKey(this Random rand, out uint key) { int space = rand.Next(1, 13); @@ -59,35 +65,22 @@ namespace WebSocketSharp key = rand.GenerateKey(space); long mKey = key * space; - char[] mKeyChars = mKey.ToString().ToCharArray(); - int mKeyCharsLen = mKeyChars.Length; + List secKey = new List(mKey.ToString().ToCharArray()); - int secKeyCharsLen = mKeyCharsLen + space + ascii; - char[] secKeyChars = new char[secKeyCharsLen].InitializeWith(' '); - - secKeyChars[0] = mKeyChars[0]; - secKeyChars[secKeyCharsLen - 1] = mKeyChars[mKeyCharsLen - 1]; - - int i = 0; - for (int j = 1; j < mKeyCharsLen - 1; j++) + int i; + for (int n = 0; n < ascii; n++) { - i = rand.Next(i + 1, secKeyCharsLen - mKeyCharsLen + j + 1); - secKeyChars[i] = mKeyChars[j]; + i = rand.Next(secKey.Count + 1); + secKey.Insert(i, rand.GeneratePrintableASCIIwithoutSPandNum()); } - var convToAscii = secKeyChars - .IndexOf(' ') - .OrderBy( x => Guid.NewGuid() ) - .Where( (x, idx) => idx < ascii ); - - int k; - foreach (int index in convToAscii) + for (int n = 0; n < space; n++) { - k = rand.Next(2) == 0 ? rand.Next(33, 48) : rand.Next(58, 127); - secKeyChars[index] = Convert.ToChar(k); + i = rand.Next(1, secKey.Count); + secKey.Insert(i, ' '); } - return new String(secKeyChars); + return new String(secKey.ToArray()); } public static IEnumerable IndexOf(this T[] array, T val) @@ -111,7 +104,7 @@ namespace WebSocketSharp return array; } - public static Byte[] InitializeWithASCII(this Byte[] bytes, Random rand) + public static Byte[] InitializeWithPrintableASCII(this Byte[] bytes, Random rand) { for (int i = 0; i < bytes.Length; i++) { diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index d17b863e..f24e2b24 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -263,7 +263,7 @@ namespace WebSocketSharp : protocol; #if !CHALLENGE string secKeys = String.Empty; - string key3AsASCII = String.Empty; + string key3ToAscii = String.Empty; #else Random rand = new Random(); @@ -271,13 +271,13 @@ namespace WebSocketSharp string secKey1 = rand.GenerateSecKey(out key1); string secKey2 = rand.GenerateSecKey(out key2); - byte[] key3 = new byte[8].InitializeWithASCII(rand); + byte[] key3 = new byte[8].InitializeWithPrintableASCII(rand); string secKeys = "Sec-WebSocket-Key1: {0}\r\n" + "Sec-WebSocket-Key2: {1}\r\n"; secKeys = String.Format(secKeys, secKey1, secKey2); - string key3AsASCII = Encoding.ASCII.GetString(key3); + string key3ToAscii = Encoding.ASCII.GetString(key3); byte[] expectedRes = createExpectedRes(key1, key2, key3); byte[] actualRes = new byte[16]; @@ -290,7 +290,7 @@ namespace WebSocketSharp "Origin: " + origin + "\r\n" + secKeys + "\r\n" + - key3AsASCII; + key3ToAscii; #if DEBUG Console.WriteLine("WS: Info @doHandshake: Handshake from client: \n{0}", request); #endif @@ -354,10 +354,10 @@ namespace WebSocketSharp Console.WriteLine("WS: Info @doHandshake: Sub protocol: {0}", protocol); #endif #if CHALLENGE - string expectedResHexStr = BitConverter.ToString(expectedRes); - string actualResHexStr = BitConverter.ToString(actualRes); + string expectedResToHexStr = BitConverter.ToString(expectedRes); + string actualResToHexStr = BitConverter.ToString(actualRes); - actualResHexStr.NotEqualsDo(expectedResHexStr, (a, b) => + actualResToHexStr.NotEqualsDo(expectedResToHexStr, (a, b) => { Console.WriteLine("WS: Error @doHandshake: Invalid challenge response."); Console.WriteLine("\texpected: {0}", b); @@ -366,7 +366,7 @@ namespace WebSocketSharp } ); #if DEBUG - Console.WriteLine("WS: Info @doHandshake: challenge response: {0}", actualResHexStr); + Console.WriteLine("WS: Info @doHandshake: challenge response: {0}", actualResToHexStr); #endif #endif ReadyState = WsState.OPEN; diff --git a/websocket-sharp/bin/Debug/websocket-sharp.dll b/websocket-sharp/bin/Debug/websocket-sharp.dll index 709ca57d..8f02ccda 100755 Binary files a/websocket-sharp/bin/Debug/websocket-sharp.dll and b/websocket-sharp/bin/Debug/websocket-sharp.dll differ diff --git a/websocket-sharp/bin/Debug/websocket-sharp.dll.mdb b/websocket-sharp/bin/Debug/websocket-sharp.dll.mdb index cc7980ce..5f58012e 100644 Binary files a/websocket-sharp/bin/Debug/websocket-sharp.dll.mdb and b/websocket-sharp/bin/Debug/websocket-sharp.dll.mdb differ diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll index 8af4fa1f..d9f820c1 100755 Binary files a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll and b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 5f51c80e..247caaa1 100644 Binary files a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/websocket-sharp/bin/Release/websocket-sharp.dll b/websocket-sharp/bin/Release/websocket-sharp.dll index 022c9957..1352799c 100755 Binary files a/websocket-sharp/bin/Release/websocket-sharp.dll and b/websocket-sharp/bin/Release/websocket-sharp.dll differ diff --git a/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll b/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll index fa19e1b4..eacf178b 100755 Binary files a/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll and b/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/websocket-sharp/websocket-sharp.pidb b/websocket-sharp/websocket-sharp.pidb index af744ce5..20be6372 100644 Binary files a/websocket-sharp/websocket-sharp.pidb and b/websocket-sharp/websocket-sharp.pidb differ diff --git a/wsclient/bin/Debug/websocket-sharp.dll b/wsclient/bin/Debug/websocket-sharp.dll index 709ca57d..8f02ccda 100755 Binary files a/wsclient/bin/Debug/websocket-sharp.dll and b/wsclient/bin/Debug/websocket-sharp.dll differ diff --git a/wsclient/bin/Debug/websocket-sharp.dll.mdb b/wsclient/bin/Debug/websocket-sharp.dll.mdb index cc7980ce..5f58012e 100644 Binary files a/wsclient/bin/Debug/websocket-sharp.dll.mdb and b/wsclient/bin/Debug/websocket-sharp.dll.mdb differ diff --git a/wsclient/bin/Debug/wsclient.exe b/wsclient/bin/Debug/wsclient.exe index e5d37a65..58c3262d 100755 Binary files a/wsclient/bin/Debug/wsclient.exe and b/wsclient/bin/Debug/wsclient.exe differ diff --git a/wsclient/bin/Debug/wsclient.exe.mdb b/wsclient/bin/Debug/wsclient.exe.mdb index 15ee5a33..a9f0538d 100644 Binary files a/wsclient/bin/Debug/wsclient.exe.mdb and b/wsclient/bin/Debug/wsclient.exe.mdb differ diff --git a/wsclient/bin/Debug_Ubuntu/websocket-sharp.dll b/wsclient/bin/Debug_Ubuntu/websocket-sharp.dll index 8af4fa1f..d9f820c1 100755 Binary files a/wsclient/bin/Debug_Ubuntu/websocket-sharp.dll and b/wsclient/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/wsclient/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/wsclient/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 5f51c80e..247caaa1 100644 Binary files a/wsclient/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/wsclient/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/wsclient/bin/Debug_Ubuntu/wsclient.exe b/wsclient/bin/Debug_Ubuntu/wsclient.exe index cca0a0cc..40c55795 100755 Binary files a/wsclient/bin/Debug_Ubuntu/wsclient.exe and b/wsclient/bin/Debug_Ubuntu/wsclient.exe differ diff --git a/wsclient/bin/Debug_Ubuntu/wsclient.exe.mdb b/wsclient/bin/Debug_Ubuntu/wsclient.exe.mdb index 047b062e..bb02a6e0 100644 Binary files a/wsclient/bin/Debug_Ubuntu/wsclient.exe.mdb and b/wsclient/bin/Debug_Ubuntu/wsclient.exe.mdb differ diff --git a/wsclient/bin/Release/websocket-sharp.dll b/wsclient/bin/Release/websocket-sharp.dll index 022c9957..1352799c 100755 Binary files a/wsclient/bin/Release/websocket-sharp.dll and b/wsclient/bin/Release/websocket-sharp.dll differ diff --git a/wsclient/bin/Release/wsclient.exe b/wsclient/bin/Release/wsclient.exe index 881580e6..3a1d804e 100755 Binary files a/wsclient/bin/Release/wsclient.exe and b/wsclient/bin/Release/wsclient.exe differ diff --git a/wsclient/bin/Release_Ubuntu/websocket-sharp.dll b/wsclient/bin/Release_Ubuntu/websocket-sharp.dll index fa19e1b4..eacf178b 100755 Binary files a/wsclient/bin/Release_Ubuntu/websocket-sharp.dll and b/wsclient/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/wsclient/bin/Release_Ubuntu/wsclient.exe b/wsclient/bin/Release_Ubuntu/wsclient.exe index 57263711..33a3f3d2 100755 Binary files a/wsclient/bin/Release_Ubuntu/wsclient.exe and b/wsclient/bin/Release_Ubuntu/wsclient.exe differ