Ejemplo n.º 1
0
 protected override bool CheckAuthentication(Context context)
 {
     if (context.ReceivedByteCount > 8)
     {
         var handshake = new ClientHandshake(context.Header);
         // See if our header had the required information
         if (handshake.IsValid())
         {
             // Optionally check Origin and Location if they're set.
             if (!String.IsNullOrEmpty(Origin))
             {
                 if (handshake.Origin != "http://" + Origin)
                 {
                     return false;
                 }
             }
             if (!String.IsNullOrEmpty(Destination))
             {
                 if (handshake.Host != Destination + ":" + context.Server.Port.ToString())
                 {
                     return false;
                 }
             }
             // Generate response handshake for the client
             ServerHandshake serverShake = GenerateResponseHandshake(handshake);
             serverShake.SubProtocol = handshake.SubProtocol;
             // Send the response handshake
             SendServerHandshake(serverShake, context);
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 2
0
 private static ServerHandshake GenerateResponseHandshake(ClientHandshake handshake)
 {
     var responseHandshake = new ServerHandshake {Accept = GenerateAccept(handshake.Key)};
     return responseHandshake;
 }
Ejemplo n.º 3
0
        private void Authenticate()
        {
            _handshake = new ClientHandshake { Version = "8", Origin = Origin, Host = _host, Key = GenerateKey(), ResourcePath = _path };

            _client.Client.Send(Encoding.UTF8.GetBytes(_handshake.ToString()));
        }