Skip to content

Commit fb0485f

Browse files
committed
branched to draft75
1 parent abab24d commit fb0485f

25 files changed

+9
-131
lines changed

websocket-sharp.userprefs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Properties>
2-
<MonoDevelop.Ide.Workspace ActiveConfiguration="Release" ctype="Workspace" />
2+
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug_Ubuntu" ctype="Workspace" />
33
<MonoDevelop.Ide.Workbench ActiveDocument="websocket-sharp/WebSocket.cs" ctype="Workbench">
44
<Files>
5-
<File FileName="websocket-sharp/WebSocket.cs" Line="261" Column="1" />
5+
<File FileName="websocket-sharp/WebSocket.cs" Line="1" Column="20" />
66
</Files>
77
</MonoDevelop.Ide.Workbench>
88
<MonoDevelop.Ide.DebuggingService.Breakpoints>

websocket-sharp/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
1818
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
1919

20-
[assembly: AssemblyVersion("1.0.0.*")]
20+
[assembly: AssemblyVersion("0.9.9.*")]
2121

2222
// The following attributes are used to specify the signing key for the assembly,
2323
// if desired. See the Mono documentation for more information about signing.

websocket-sharp/Ext.cs

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
using System;
3030
using System.Collections.Generic;
31-
using System.Linq;
3231

3332
namespace WebSocketSharp
3433
{
@@ -41,72 +40,12 @@ public static bool EqualsWithSaveTo(this int asByte, char c, List<byte> dist)
4140
return b == Convert.ToByte(c);
4241
}
4342

44-
public static uint GenerateKey(this Random rand, int space)
45-
{
46-
uint max = (uint)(0xffffffff / space);
47-
48-
int upper16 = (int)((max & 0xffff0000) >> 16);
49-
int lower16 = (int)(max & 0x0000ffff);
50-
51-
return ((uint)rand.Next(upper16 + 1) << 16) + (uint)rand.Next(lower16 + 1);
52-
}
53-
54-
public static char GeneratePrintableASCIIwithoutSPandNum(this Random rand)
55-
{
56-
int ascii = rand.Next(2) == 0 ? rand.Next(33, 48) : rand.Next(58, 127);
57-
return Convert.ToChar(ascii);
58-
}
59-
60-
public static string GenerateSecKey(this Random rand, out uint key)
61-
{
62-
int space = rand.Next(1, 13);
63-
int ascii = rand.Next(1, 13);
64-
65-
key = rand.GenerateKey(space);
66-
67-
long mKey = key * space;
68-
List<char> secKey = new List<char>(mKey.ToString().ToCharArray());
69-
70-
int i;
71-
ascii.Times( () =>
72-
{
73-
i = rand.Next(secKey.Count + 1);
74-
secKey.Insert(i, rand.GeneratePrintableASCIIwithoutSPandNum());
75-
} );
76-
77-
space.Times( () =>
78-
{
79-
i = rand.Next(1, secKey.Count);
80-
secKey.Insert(i, ' ');
81-
} );
82-
83-
return new String(secKey.ToArray());
84-
}
85-
86-
public static Byte[] InitializeWithPrintableASCII(this Byte[] bytes, Random rand)
87-
{
88-
for (int i = 0; i < bytes.Length; i++)
89-
{
90-
bytes[i] = (byte)rand.Next(32, 127);
91-
}
92-
93-
return bytes;
94-
}
95-
9643
public static void NotEqualsDo(this string expected, string actual, Action<string, string> act)
9744
{
9845
if (expected != actual)
9946
{
10047
act(expected, actual);
10148
}
10249
}
103-
104-
public static void Times(this int n, Action act)
105-
{
106-
for (int i = 0; i < n; i++)
107-
{
108-
act();
109-
}
110-
}
11150
}
11251
}

websocket-sharp/WebSocket.cs

Lines changed: 4 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@
3333
using System;
3434
using System.Collections.Generic;
3535
using System.IO;
36-
using System.Linq;
3736
using System.Net;
3837
using System.Net.Security;
3938
using System.Net.Sockets;
4039
using System.Text;
4140
using System.Threading;
42-
using System.Security.Cryptography;
4341

4442
namespace WebSocketSharp
4543
{
@@ -248,12 +246,7 @@ private void createConnection()
248246

249247
private void doHandshake()
250248
{
251-
#if !CHALLENGE
252249
string request = createOpeningHandshake();
253-
#else
254-
byte[] expectedRes, actualRes = new byte[16];
255-
string request = createOpeningHandshake(out expectedRes);
256-
#endif
257250
#if DEBUG
258251
Console.WriteLine("WS: Info @doHandshake: Handshake from client: \n{0}", request);
259252
#endif
@@ -270,10 +263,6 @@ private void doHandshake()
270263
wsStream.ReadByte().EqualsWithSaveTo('\r', rawdata) &&
271264
wsStream.ReadByte().EqualsWithSaveTo('\n', rawdata))
272265
{
273-
#if CHALLENGE
274-
wsStream.Read(actualRes, 0, actualRes.Length);
275-
rawdata.AddRange(actualRes);
276-
#endif
277266
break;
278267
}
279268
}
@@ -292,21 +281,14 @@ private void doHandshake()
292281
{
293282
throw new IOException("Invalid handshake response: " + a);
294283
};
295-
#if !CHALLENGE
284+
296285
"HTTP/1.1 101 Web Socket Protocol Handshake".NotEqualsDo(response[0], act);
297-
#else
298-
"HTTP/1.1 101 WebSocket Protocol Handshake".NotEqualsDo(response[0], act);
299-
#endif
300286
"Upgrade: WebSocket".NotEqualsDo(response[1], act);
301287
"Connection: Upgrade".NotEqualsDo(response[2], act);
302288

303289
for (int i = 3; i < response.Length; i++)
304290
{
305-
#if !CHALLENGE
306291
if (response[i].Contains("WebSocket-Protocol:"))
307-
#else
308-
if (response[i].Contains("Sec-WebSocket-Protocol:"))
309-
#endif
310292
{
311293
int j = response[i].IndexOf(":");
312294
protocol = response[i].Substring(j + 1).Trim();
@@ -315,29 +297,11 @@ private void doHandshake()
315297
}
316298
#if DEBUG
317299
Console.WriteLine("WS: Info @doHandshake: Sub protocol: {0}", protocol);
318-
#endif
319-
#if CHALLENGE
320-
string expectedResToHexStr = BitConverter.ToString(expectedRes);
321-
string actualResToHexStr = BitConverter.ToString(actualRes);
322-
323-
expectedResToHexStr.NotEqualsDo(actualResToHexStr, (e, a) =>
324-
{
325-
#if DEBUG
326-
Console.WriteLine("WS: Error @doHandshake: Invalid challenge response.");
327-
Console.WriteLine("\texpected: {0}", e);
328-
Console.WriteLine("\tactual : {0}", a);
329-
#endif
330-
throw new IOException("Invalid challenge response: " + a);
331-
});
332300
#endif
333301
ReadyState = WsState.OPEN;
334302
}
335303

336-
#if !CHALLENGE
337304
private string createOpeningHandshake()
338-
#else
339-
private string createOpeningHandshake(out byte[] expectedRes)
340-
#endif
341305
{
342306
string path = uri.PathAndQuery;
343307
string host = uri.DnsSafeHost;
@@ -350,43 +314,18 @@ private string createOpeningHandshake(out byte[] expectedRes)
350314
}
351315

352316
string subProtocol = protocol != String.Empty
353-
#if !CHALLENGE
354317
? String.Format("WebSocket-Protocol: {0}\r\n", protocol)
355-
#else
356-
? String.Format("Sec-WebSocket-Protocol: {0}\r\n", protocol)
357-
#endif
358318
: protocol;
359-
#if !CHALLENGE
360-
string secKeys = String.Empty;
361-
string key3ToAscii = String.Empty;
362-
#else
363-
Random rand = new Random();
364-
365-
uint key1, key2;
366-
string secKey1 = rand.GenerateSecKey(out key1);
367-
string secKey2 = rand.GenerateSecKey(out key2);
368-
369-
byte[] key3 = new byte[8].InitializeWithPrintableASCII(rand);
370-
371-
string secKeys = "Sec-WebSocket-Key1: {0}\r\n" +
372-
"Sec-WebSocket-Key2: {1}\r\n";
373-
secKeys = String.Format(secKeys, secKey1, secKey2);
374-
375-
string key3ToAscii = Encoding.ASCII.GetString(key3);
376319

377-
expectedRes = createExpectedRes(key1, key2, key3);
378-
#endif
379320
return "GET " + path + " HTTP/1.1\r\n" +
380321
"Upgrade: WebSocket\r\n" +
381322
"Connection: Upgrade\r\n" +
382323
subProtocol +
383324
"Host: " + host + "\r\n" +
384325
"Origin: " + origin + "\r\n" +
385-
secKeys +
386-
"\r\n" +
387-
key3ToAscii;
326+
"\r\n";
388327
}
389-
328+
/*
390329
private byte[] createExpectedRes(uint key1, uint key2, byte[] key3)
391330
{
392331
byte[] key1Bytes = BitConverter.GetBytes(key1);
@@ -400,7 +339,7 @@ private byte[] createExpectedRes(uint key1, uint key2, byte[] key3)
400339
MD5 md5 = MD5.Create();
401340
return md5.ComputeHash(concatKeys);
402341
}
403-
342+
*/
404343
private void message()
405344
{
406345
#if DEBUG
-2.5 KB
Binary file not shown.
-1.07 KB
Binary file not shown.
-2.5 KB
Binary file not shown.
-1.07 KB
Binary file not shown.
-1.5 KB
Binary file not shown.
-1.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)