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)
                 {
                     return false;
                 }
             }
             // Generate response handshake for the client
             var serverShake = GenerateResponseHandshake(handshake, context.Server);
             // Send the response handshake
             SendServerHandshake(serverShake, context);
             return true;
         }
     }
     return false;
 }
 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)
                 {
                     return(false);
                 }
             }
             // Generate response handshake for the client
             var serverShake = GenerateResponseHandshake(handshake, context.Server);
             // Send the response handshake
             SendServerHandshake(serverShake, context);
             return(true);
         }
     }
     return(false);
 }
        private static ServerHandshake GenerateResponseHandshake(ClientHandshake handshake, WebSocketServer server)
        {
            var responseHandshake = new ServerHandshake {
                Accept = GenerateAccept(handshake.Key), Server = server, RequestProtocols = handshake.SubProtocols
            };

            return(responseHandshake);
        }
        public bool Authenticate(Context ctx)
        {
            var context = (ServerContext)ctx;

            if (context.ReceivedByteCount > 8)
            {
                var handshake = new ClientHandshake(context.Header);
                // See if our header had the required information
                if (handshake.IsValid())
                {
                    var origin = context.Server.Origin;
                    // Optionally check Origin and Location if they're set.
                    if (!String.IsNullOrEmpty(origin))
                    {
                        var expectedOrigin = origin;
                        if (!origin.Contains("://"))
                        {
                            expectedOrigin = "http://" + origin;
                        }

                        if (!handshake.Origin.Equals(expectedOrigin, StringComparison.InvariantCultureIgnoreCase))
                            return (false);
                    }

                    var destination = context.Server.Destination;

                    if (!String.IsNullOrEmpty(destination))
                    {
                        if (handshake.Host != destination + ":" + context.Server.Port)
                            return (false);
                    }
                    // Generate response handshake for the client
                    var serverShake = GenerateResponseHandshake(handshake, context.Server);
                    // Send the response handshake
                    SendServerHandshake(serverShake, context);
                    return (true);
                }
            }
            return (false);
        }
Beispiel #5
0
        private void Authenticate()
        {
            _handshake = new ClientHandshake { Version = "8", Origin = Origin, Host = _host, Key = GenerateKey(), ResourcePath = _path, SubProtocols = SubProtocols};

            _client.Client.Send(Encoding.UTF8.GetBytes(_handshake.ToString()));
        }
 private static ServerHandshake GenerateResponseHandshake(ClientHandshake handshake, WebSocketServer server)
 {
     var responseHandshake = new ServerHandshake {Accept = GenerateAccept(handshake.Key), Server = server, RequestProtocols = handshake.SubProtocols};
     return responseHandshake;
 }
 private void SendHeader()
 {
     handshake = new ClientHandshake { Version = "8", Origin = Origin, Host = host, Key = GenerateKey(), ResourcePath = path, SubProtocols = SubProtocols };
     client.Client.Send(Encoding.UTF8.GetBytes(handshake.ToString()));
 }
        private void Authenticate()
        {
            _handshake = new ClientHandshake { Version = "8", Origin = Origin, Host = _host, Key = GenerateKey(), ResourcePath = _path, SubProtocols = SubProtocols};

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

            if (_context.SslStream != null)
            {
                SslStream ns = _context.SslStream;
                byte[] buffer = Encoding.UTF8.GetBytes(_handshake.ToString());
                ns.Write(buffer, 0, buffer.Length);
            }
            else
            {
                _client.Client.Send(Encoding.UTF8.GetBytes(_handshake.ToString()));
            }
        }