nooojmy
fsd
This commit is contained in:
parent
bea5eafbf8
commit
a1d57101cb
7 changed files with 21 additions and 38 deletions
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Square;
|
||||||
|
|
||||||
namespace Kneesocks {
|
namespace Kneesocks {
|
||||||
public class Connection {
|
public class Connection {
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Square;
|
||||||
|
|
||||||
namespace Kneesocks {
|
namespace Kneesocks {
|
||||||
public class Frame {
|
public class Frame {
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Square;
|
||||||
|
|
||||||
namespace Kneesocks {
|
namespace Kneesocks {
|
||||||
public class Handshake {
|
public class Handshake {
|
||||||
|
@ -84,9 +85,7 @@ namespace Kneesocks {
|
||||||
public static Handshake AcceptRequest(Handshake request) {
|
public static Handshake AcceptRequest(Handshake request) {
|
||||||
const string nonce = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
const string nonce = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
||||||
var key = request.GetHeader("Sec-WebSocket-Key");
|
var key = request.GetHeader("Sec-WebSocket-Key");
|
||||||
var connectionHash = (key + nonce).SHA1().Base64Encode(false);
|
var connectionHash = (key + nonce).SHA1().Base64Encode();
|
||||||
|
|
||||||
var test = ("dGhlIHNhbXBsZSBub25jZQ==" + nonce).SHA1().Base64Encode(false);
|
|
||||||
|
|
||||||
var shake = new Handshake(kStatusCode.Switching_Protocols);
|
var shake = new Handshake(kStatusCode.Switching_Protocols);
|
||||||
shake.SetHeader("Upgrade", "websocket")
|
shake.SetHeader("Upgrade", "websocket")
|
||||||
|
|
|
@ -48,7 +48,6 @@
|
||||||
<Compile Include="ReadBuffer.cs" />
|
<Compile Include="ReadBuffer.cs" />
|
||||||
<Compile Include="Server.cs" />
|
<Compile Include="Server.cs" />
|
||||||
<Compile Include="Stack.cs" />
|
<Compile Include="Stack.cs" />
|
||||||
<Compile Include="Utilities.cs" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Square\Square.csproj">
|
<ProjectReference Include="..\Square\Square.csproj">
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Kneesocks {
|
|
||||||
public static class StringExtensions {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ByteArrayExtensions {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class CryptoExtensions {
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -9,5 +9,9 @@ namespace Square {
|
||||||
public static string Base64Encode(this byte[] bytes) {
|
public static string Base64Encode(this byte[] bytes) {
|
||||||
return Convert.ToBase64String(bytes);
|
return Convert.ToBase64String(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string ToHexString(this byte[] bytes) {
|
||||||
|
return BitConverter.ToString(bytes).Replace("-", "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,38 +7,36 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Square {
|
namespace Square {
|
||||||
public static class CryptoExtensions {
|
public static class CryptoExtensions {
|
||||||
public enum kHashReturnType {
|
public static byte[] SHA1(this string str) {
|
||||||
RAW, HEX, BASE64
|
return Encoding.UTF8.GetBytes(str).SHA1();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string SHA1(this string str, kHashReturnType type = kHashReturnType.RAW) {
|
public static byte[] SHA1(this byte[] bytes) {
|
||||||
using(var hasher = new SHA1CryptoServiceProvider()) {
|
using(var hasher = new SHA1CryptoServiceProvider()) {
|
||||||
return ParseRawHash(
|
return hasher.ComputeHash(bytes);
|
||||||
hasher.ComputeHash(str.GetBytes(false)),
|
|
||||||
type
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string MD5(this string str, kHashReturnType type = kHashReturnType.RAW) {
|
public static byte[] MD5(this string str) {
|
||||||
|
return Encoding.UTF8.GetBytes(str).MD5();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] MD5(this byte[] bytes) {
|
||||||
using(var hasher = new MD5CryptoServiceProvider()) {
|
using(var hasher = new MD5CryptoServiceProvider()) {
|
||||||
return ParseRawHash(
|
return hasher.ComputeHash(bytes);
|
||||||
hasher.ComputeHash(str.GetBytes(false)),
|
|
||||||
type
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string ParseRawHash(byte[] hash, kHashReturnType type) {
|
/*private static string ParseRawHash(byte[] hash, kHashReturnType type) {
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case kHashReturnType.BASE64:
|
case kHashReturnType.BASE64:
|
||||||
return hash.Base64Encode(false);
|
return hash.Base64Encode();
|
||||||
case kHashReturnType.HEX:
|
case kHashReturnType.HEX:
|
||||||
return BitConverter.ToString(hash).Replace("-", "");
|
return BitConverter.ToString(hash).Replace("-", "");
|
||||||
case kHashReturnType.RAW:
|
case kHashReturnType.RAW:
|
||||||
default:
|
default:
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue