protected override bool CheckAuthentication(Context context) { if (context.ReceivedByteCount > 8) { var handshake = new ClientHandshake(new ArraySegment<byte>(context.Buffer, context.ReceivedByteCount - 8, 8), context.Header); // See if our header had the required information if (handshake.IsValid()) { // Optionally check Origin and Location if they're set. if (Origin != string.Empty) { if (handshake.Origin != "http://" + Origin) { return false; } } if (Destination != string.Empty) { 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(new ArraySegment <byte>(context.Buffer, context.ReceivedByteCount - 8, 8), context.Header); // See if our header had the required information if (handshake.IsValid()) { // Optionally check Origin and Location if they're set. if (Origin != string.Empty) { if (handshake.Origin != "http://" + Origin) { return(false); } } if (Destination != string.Empty) { 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() { Location = "ws://" + handshake.Host + handshake.ResourcePath, Origin = handshake.Origin, AnswerBytes = GenerateAnswerBytes(handshake.Key1, handshake.Key2, handshake.ChallengeBytes), Server = server, RequestProtocols = server.SubProtocols }; return(responseHandshake); }
private static ServerHandshake GenerateResponseHandshake(ClientHandshake handshake, WebSocketServer server) { var responseHandshake = new ServerHandshake() { Location = "ws://" + handshake.Host + handshake.ResourcePath, Origin = handshake.Origin, AnswerBytes = GenerateAnswerBytes(handshake.Key1, handshake.Key2, handshake.ChallengeBytes), Server = server, RequestProtocols = server.SubProtocols }; return responseHandshake; }
protected override bool CheckAuthentication(Context context) { if (context.ReceivedByteCount > 8) { var handshake = new ClientHandshake(new ArraySegment<byte>(context.Buffer, context.ReceivedByteCount - 8, 8), 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)) { var expectedOrigin = Origin; if (!Origin.Contains("://")) { expectedOrigin = "http://" + Origin; } if (!handshake.Origin.Equals(expectedOrigin, StringComparison.InvariantCultureIgnoreCase)) { 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(new ArraySegment <byte>(context.Buffer, context.ReceivedByteCount - 8, 8), 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)) { var expectedOrigin = Origin; if (!Origin.Contains("://")) { expectedOrigin = "http://" + Origin; } if (!handshake.Origin.Equals(expectedOrigin, StringComparison.InvariantCultureIgnoreCase)) { 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) { // mjb string Protocol = "ws://"; if (server.IsSecure == true) { Protocol = "wss://"; } var responseHandshake = new ServerHandshake() { // mjb Location = "ws://" + handshake.Host + handshake.ResourcePath, Location = Protocol + handshake.Host + handshake.ResourcePath, Origin = handshake.Origin, AnswerBytes = GenerateAnswerBytes(handshake.Key1, handshake.Key2, handshake.ChallengeBytes), Server = server, RequestProtocols = server.SubProtocols }; return responseHandshake; }