Ejemplo n.º 1
0
 public static ConnectionHandshake Generate()
 {
     var r = new Random();
     var ret = new ConnectionHandshake();
     var k1 = handshake_key();
     var k2 = handshake_key();
     ret.Key1 = k1.Item2;
     ret.Key2 = k2.Item2;
     byte[] rand = new byte[8];
     for (int i = 0; i < 8; i++)
     {
         rand[i] = (byte) r.Next(0, 255);
     }
     ret.FinalKey = rand;
     ret.Hash = handshake(k1.Item2, k2.Item2, rand);
     return ret;
 }
Ejemplo n.º 2
0
 private void WriteHeaders(ConnectionHandshake handshake)
 {
     var stream = this.sock.GetSocketStream();
     var host = ConnectionPath.Host + ((ConnectionPath.Port != 80 || ConnectionPath.Port != 443) ? ":" + ConnectionPath.Port.ToString() : "");
     var origin = ConnectionPath.Scheme + "://" + ConnectionPath.Host + ((ConnectionPath.Port != 80 || ConnectionPath.Port != 443) ? ":" + ConnectionPath.Port.ToString() : "");
     var headerstr = string.Format(header, ConnectionPath.AbsolutePath, handshake.Key1, handshake.Key2, host, origin);
     byte[] h = Encoding.UTF8.GetBytes(headerstr);
     byte[] all = new byte[h.Length + handshake.FinalKey.Length];
     Array.Copy(h, all, h.Length);
     Array.Copy(handshake.FinalKey, 0, all, h.Length, handshake.FinalKey.Length);
     stream.Write(all);
 }
Ejemplo n.º 3
0
 private bool EnsureResponse(ByteBuffer data, ConnectionHandshake handie)
 {
     bool good = true;
     int pos = data.Length - 16;
     for (int i = 0; i < 16; i++)
     {
         good = data.Bytes[pos + i] == handie.Hash[i];
     }
     return good;
 }