Beispiel #1
0
        private bool ValidateMessage(dynamic message)
        {
            string command = (string)message.command;

            switch (command)
            {
            case "AUTHENTICATE":
            {
                string mac = HMacUtil.Encode(((string)message.transactionUuid + "." + (string)message.command));
                return(Equals(mac, (string)message.signature));
            }

            case "VALIDATE_PASSWORD":
            case "SET_PASSWORD":
            {
                string mac = HMacUtil.Encode(((string)message.transactionUuid + "." + (string)message.command + "." + (string)message.target + "." + (string)message.payload));
                return(Equals(mac, (string)message.signature));
            }

            default:
                Logger.Information("Unknown command: " + (string)message.command);
                break;
            }

            return(false);
        }
Beispiel #2
0
        internal void Reply(string transactionUuid, string command, string target, bool valid)
        {
            dynamic response = new ExpandoObject();

            response.transactionUuid = transactionUuid;
            response.command         = command;
            response.target          = target;
            response.status          = (valid) ? "true" : "false";
            response.clientVersion   = VERSION;
            response.signature       = HMacUtil.Encode(transactionUuid + "." + command + "." + target + "." + (valid ? "true" : "false"));

            socket.Send(JsonConvert.SerializeObject(response));

            LogResponse(response);
        }