public override bool VerifyHandshake(WebSocket websocket, WebSocketCommandInfo handshakeInfo, out string description) { var handshake = handshakeInfo.Text; if (string.IsNullOrEmpty(handshake)) { description = m_Error_InvalidHandshake; return(false); } var verbLine = string.Empty; if (!handshakeInfo.Text.ParseMimeHeader(websocket.Items, out verbLine)) { description = m_Error_InvalidHandshake; return(false); } if (!ExptectedResponseVerbLines.Contains(verbLine)) { description = verbLine; return(false); } if (!string.IsNullOrEmpty(websocket.SubProtocol)) { var protocol = websocket.Items.GetValue("Sec-WebSocket-Protocol", string.Empty); if (!websocket.SubProtocol.Equals(protocol, StringComparison.OrdinalIgnoreCase)) { description = m_Error_SubProtocolNotMatch; return(false); } } var acceptKey = websocket.Items.GetValue("Sec-WebSocket-Accept", string.Empty); var expectedAcceptKey = websocket.Items.GetValue(m_ExpectedAcceptKey, string.Empty); if (!expectedAcceptKey.Equals(acceptKey, StringComparison.OrdinalIgnoreCase)) { description = m_Error_AcceptKeyNotMatch; return(false); } //more validations description = string.Empty; return(true); }
public override bool VerifyHandshake(WebSocket websocket, WebSocketCommandInfo handshakeInfo, out string description) { var challenge = handshakeInfo.Data; if (challenge.Length != challenge.Length) { description = m_Error_ChallengeLengthNotMatch; return(false); } for (var i = 0; i < m_ExpectedChallenge.Length; i++) { if (challenge[i] != m_ExpectedChallenge[i]) { description = m_Error_ChallengeNotMatch; return(false); } } var verbLine = string.Empty; if (!handshakeInfo.Text.ParseMimeHeader(websocket.Items, out verbLine)) { description = m_Error_InvalidHandshake; return(false); } if (!ExptectedResponseVerbLines.Contains(verbLine)) { description = verbLine; return(false); } description = string.Empty; return(true); }