Example #1
0
        /// <param name = "type">rsa | ecdsa | bliss | any</param>
        /// <param name = "data">PEM or DER encoded key data</param>
        public static string LoadKey(this Session session, string type, string data)
        {
            var typeMessage = new KeyValueMessage("type", type);
            var dataMessage = new KeyValueMessage("data", data);

            return(TypedCommandRequest(session, Command.LoadKey, new[] { typeMessage, dataMessage }, messages => (messages[1] as KeyValueMessage).Value));
        }
Example #2
0
 void On_Example2(KeyValueMessage message)
 {
     foreach (var item in message.Data)
     {
         Debug.Log(string.Format("{0}={1}", item.Key, item.Value));
     }
 }
Example #3
0
 void On_LOGIN(KeyValueMessage message)
 {
     if (message.Data.ContainsKey("errorcode") == true)
     {
         Debug.Log(ErrorCode_LOGIN.ToString(int.Parse(message.Data["errorcode"].ToString())));
     }
 }
Example #4
0
        public override Task <KeyValueMessage> StoreValue(KeyValueMessage request, grpc.ServerCallContext context)
        {
            var client   = this.GetClient(request.Key);
            var response = client.StoreValue(request);

            return(Task.FromResult(response));
        }
Example #5
0
 void Send_Example2(string udid, byte platform)
 {
     KeyValueMessage message = new KeyValueMessage(IDTable[MessageID.Example2]);
     message.AddField("udid", udid);
     message.AddField("platform", platform);
     session.Send(message);
 }
Example #6
0
 void SendExample1()
 {
     KeyValueMessage message = new KeyValueMessage(IDTable[MessageID.Example1]);
     message.AddField("stringValue", "abcd");
     message.AddField("intValue", 1234);
     message.AddField("floatValue", 1234.5f);
     message.AddField("boolValue", true);
     session.Send(message);
 }
Example #7
0
        // type: X509 | X509_AC | X509_CRL | OCSP_RESPONSE | PUBKEY | ANY
        // flag: NONE | CA | AA | OCSP | ANY
        // subject: set to list only certificates having subject
        public static IEnumerable <IEnumerable <KeyValueMessage> > ListCerts(this Session session, string type, string flag, string subject = "")
        {
            var typeMessage    = new KeyValueMessage("type", type);
            var flagMessage    = new KeyValueMessage("flag", flag);
            var subjectMessage = new KeyValueMessage("subject", subject);

            return(session.StreamedRequest(Command.ListCerts, typeMessage, flagMessage, subjectMessage)
                   .Select(messages => messages.Select(msg => msg as KeyValueMessage)));
        }
Example #8
0
 void Send_Example1(string stringValue, int intValue, float floatValue, bool boolValue)
 {
     KeyValueMessage message = new KeyValueMessage(IDTable[MessageID.Example1]);
     message.AddField("stringValue", stringValue);
     message.AddField("intValue", intValue);
     message.AddField("floatValue", floatValue);
     message.AddField("boolValue", boolValue);
     session.Send(message);
 }
Example #9
0
        void OnReceive(string id, byte[] buffer, int offset, int length)
        {
            Debug.Log(string.Format("[id:{0}] Recv", IDTable[id]));

            KeyValueMessage recvMessage = new KeyValueMessage(id);
            recvMessage.RawData = new ArraySegment<byte>(buffer, offset, length);

            //MessageHandler_Normal(recvMessage);
            MessageHandler_Reflection(recvMessage);
        }
 public KVSetCommand(KeyValueMessage message)
 {
     _messageFrames = new List<IMessageFrame>
         {
             new StringMessageFrame(message.Key),
             new BinaryMessageFrame(BitConverter.GetBytes(message.Sequence)),
             message.UUID.HasValue? (IMessageFrame) new BinaryMessageFrame(message.UUID.Value.ToByteArray()) : new EmptyMessageFrame(),
             new StringMessageFrame(message.EncodeProperties()),
             new BinaryMessageFrame(message.Body)
         };
 }
Example #11
0
 void MessageHandler_Reflection(KeyValueMessage message)
 {
     MessageID id = IDTable[message.ID];
     MethodInfo mi = HandlerFunctionTable[id];
     if (mi == null)
     {
         Debug.LogWarning(string.Format("Receive unknown message:{0}", id));
         return;
     }
     mi.Invoke(this, new object[] { message });
 }
Example #12
0
 public KVSetCommand(KeyValueMessage message)
 {
     _messageFrames = new List <IMessageFrame>
     {
         new StringMessageFrame(message.Key),
         new BinaryMessageFrame(BitConverter.GetBytes(message.Sequence)),
         message.UUID.HasValue? (IMessageFrame) new BinaryMessageFrame(message.UUID.Value.ToByteArray()) : new EmptyMessageFrame(),
         new StringMessageFrame(message.EncodeProperties()),
         new BinaryMessageFrame(message.Body)
     };
 }
Example #13
0
        void On_LOGIN(KeyValueMessage message)
        {
            if (message.Data.ContainsKey("errorcode") == true)
            {
                Debug.Log(ErrorCode_LOGIN.ToString(int.Parse(message.Data["errorcode"].ToString())));
            }

            foreach (var kvp in message.Data)
            {
                Debug.Log(string.Format("{0}={1}", kvp.Key, kvp.Value));
            }
        }
Example #14
0
        void OnReceive(string id, byte[] buffer, int offset, int length)
        {
            KeyValueMessage recvMessage = new KeyValueMessage(id);
            recvMessage.RawData = new ArraySegment<byte>(buffer, offset, length);

            foreach (var item in recvMessage.Data)
            {
                Debug.Log(string.Format("{0}={1}", item.Key, item.Value));
            }

            Debug.Log(string.Format("[id:{0}] Recv", IDTable[id]));
        }
Example #15
0
        void SendExample2()
        {
            Example2Data data = new Example2Data();
            data.stringValue = "abcd";
            data.intValue = 1234;
            data.floatValue = 1234.5f;
            data.boolValue = true;

            KeyValueMessage message = new KeyValueMessage(IDTable[MessageID.Example2]);
            foreach (var field in typeof(Example2Data).GetFields())
            {
                message.AddField(field.Name, field.GetValue(data));
            }
            session.Send(message);
        }
Example #16
0
        void On_GET_KEY(KeyValueMessage message)
        {
            if (message.Data.ContainsKey("errorcode") == true)
            {
                Debug.Log(ErrorCode_GET_KEY.ToString(int.Parse(message.Data["errorcode"].ToString())));
            }

            foreach (var kvp in message.Data)
            {
                Debug.Log(string.Format("{0}={1}", kvp.Key, kvp.Value));
                AES.Init((string)kvp.Value);
            }

            Send_LOGIN(SystemInfo.deviceUniqueIdentifier, (byte)Application.platform);
        }
Example #17
0
        public override KeyValueMessage GetValue(KeyMessage request, CallOptions options)
        {
            if (!this.nodeStore.ContainsKey(request.Key))
            {
                ThrowRpcException(StatusCode.NotFound, "Key not found");
            }

            var value    = this.nodeStore.GetValue(request.Key);
            var response = new KeyValueMessage()
            {
                Key   = request.Key,
                Value = value
            };

            return(response);
        }
Example #18
0
 void MessageHandler_Normal(KeyValueMessage message)
 {
     MessageID id = IDTable[message.ID];
     switch (id)
     {
         case MessageID.Example1:
             On_Example1(message);
             break;
         case MessageID.Example2:
             On_Example2(message);
             break;
         default:
             Debug.LogWarning(string.Format("Receive unknown message:{0}", id));
             break;
     }
 }
Example #19
0
 void MessageHandler_Normal(KeyValueMessage message)
 {
     MessageID id = IDTable[message.ID];
     switch (id)
     {
         case MessageID.GET_KEY:
             On_GET_KEY(message);
             break;
         case MessageID.LOGIN:
             On_LOGIN(message);
             break;
         default:
             Debug.LogWarning(string.Format("Receive unknown message:{0}", id));
             break;
     }
 }
        public void LocalNodeServerClient_StoreValue_ThrowsOnFailure()
        {
            // Arrange
            var key     = "a";
            var value   = "aValue";
            var request = new KeyValueMessage()
            {
                Key   = key,
                Value = value
            };

            this.nodeStoreMock
            .Setup(x => x.AddValue(key, value))
            .Returns(false);

            // Act
            Assert.Catch <RpcException>(() => LocalNodeServerClient_StoreValue_ThrowsOnFailureAct(request));
        }
        public void LocalNodeServerClient_StoreValue_ThrowsOnFailure()
        {
            // Arrange
            var key     = "a";
            var value   = "aValue";
            var request = new KeyValueMessage()
            {
                Key   = key,
                Value = value
            };

            this.nodeStoreMock
            .Setup(x => x.AddValue(key, value))
            .Returns(false);

            // Act
            var response = this.client.StoreValue(request);
        }
        public void LocalNodeServerClient_StoreValue_ThrowsOnDuplicateKey()
        {
            // Arrange
            var key     = "a";
            var value   = "aValue";
            var request = new KeyValueMessage()
            {
                Key   = key,
                Value = value
            };

            this.nodeStoreMock
            .Setup(x => x.AddValue(key, value))
            .Throws(new DuplicateKeyException(key));

            // Act
            var response = this.client.StoreValue(request);
        }
        public void LocalNodeServerClient_StoreValue_ThrowsOnDuplicateKey()
        {
            // Arrange
            var key     = "a";
            var value   = "aValue";
            var request = new KeyValueMessage()
            {
                Key   = key,
                Value = value
            };

            this.nodeStoreMock
            .Setup(x => x.AddValue(key, value))
            .Throws(new DuplicateKeyException(key));

            // Act
            Assert.Catch <RpcException>(() => LocalNodeServerClient_StoreValue_ThrowsOnDuplicateKeyAct(request));
        }
Example #24
0
        public override KeyValueMessage StoreValue(KeyValueMessage request, CallOptions options)
        {
            try
            {
                var added = this.nodeStore.AddValue(request.Key, request.Value);

                if (!added)
                {
                    ThrowRpcException(StatusCode.Internal, "Couldn't store value.");
                }
            }
            catch (DuplicateKeyException)
            {
                ThrowRpcException(StatusCode.AlreadyExists, "Duplicate key found.");
            }

            return(request);
        }
Example #25
0
        private static void StoreValue(string command, IList <string> args)
        {
            var client  = GetRandomClient();
            var request = new KeyValueMessage()
            {
                Key   = args[0],
                Value = args[1]
            };

            try
            {
                var response = client.StoreValue(request);
                Console.WriteLine("Success: Got key value = {0} {1}", response.Key, response.Value);
            }
            catch (RpcException e)
            {
                Console.WriteLine("Error: {0} {1} ", e.Status.StatusCode, e.Status.Detail);
            }
        }
        public void LocalNodeServerClient_StoreValue_StoresValue()
        {
            // Arrange
            var key     = "a";
            var value   = "aValue";
            var request = new KeyValueMessage()
            {
                Key   = key,
                Value = value
            };

            this.nodeStoreMock
            .Setup(x => x.AddValue(key, value))
            .Returns(true);

            // Act
            var response = this.client.StoreValue(request);

            // Assert
            Assert.AreEqual(key, response.Key);
            Assert.AreEqual(value, response.Value);
        }
 private void LocalNodeServerClient_StoreValue_ThrowsOnDuplicateKeyAct(KeyValueMessage request)
 {
     var response = this.client.StoreValue(request);
 }
Example #28
0
        public int Auth(bool listen, bool enrollment)
        {
            IConnection container = this;
            int retval = 99;
            KeyValueMessage keyval;
            List<string> authtypes = new List<string>();
           // authtypes.Add("NONE");
            authtypes.Add("RSA");

            string authstring = "";
            foreach (string entry in authtypes)
            {
                if (authstring == "")
                {
                    authstring = entry;
                }
                else
                {
                    authstring = authstring + " " + entry;
                }
            }

            keyval = new KeyValueMessage("Control.PreAuth");
            keyval.Add("node.uuid", Runner.Network.Node.UUID.ToString());
            keyval.Add("auth.types", authstring);
            keyval.Add("version", SimpleMesh.Service.Utility.Version);
            if (listen == false)
            {
                container.Send(keyval);
            }
            bool end;
            end = false;
            bool error = false;
            IMessage Recieved;
            bool uuid = false;
            bool authreceived = false;
            bool enrolling = false;
            KeyValueMessage messages;
            List<string> typelist;
            typelist = new List<string>();
            string conntype;
            Dictionary<string, string> Parameters = new Dictionary<string, string>();
            while (end == false)
            {
                Recieved = container.Receive(true);
                if (Recieved.Type.Substring(0, 6) != "Error.")
                {
                    switch (Recieved.Type)
                    {
                        case "Control.PreAuth":
                            messages = new KeyValueMessage(Recieved);
                            foreach (KeyValuePair<string, string> keyn in messages.Data)
                            {
                                switch (keyn.Key)
                                {
                                    case "node.uuid":
                                        uuid = true;
                                        break;
                                    case "auth.types":
                                        authreceived = true;
                                        string[] types = keyn.Value.Split(' ');
                                        foreach (string type in types)
                                        {
                                            if (authtypes.Contains(type))
                                            {
                                                typelist.Add(type);
                                            }
                                        }
                                        break;
                                }
                                Parameters.Add(keyn.Key, keyn.Value);
                            }
                            if (listen == true)
                            {
                                container.Send(keyval);
                            }
                            break;
                    }
                }
                else
                {
                    end = true;
                    error = true;
                }
                if (authreceived == true && uuid == true)
                {
                    end = true;
                }
            }
            if (error == true)
            {
                retval = 1;
                return retval;
            }
            string msg;
            msg = "Auth Types available:";
            bool first = true;
            foreach (string type in typelist)
            {
                msg = msg + " " + type;
            }
            Runner.DebugMessage("Debug.Info.Connect", msg);
            string authtotry = "";
            if (typelist.Count != 0)
            {
                if (typelist.Contains("NONE"))
                {
                    authtotry = "NONE";
                }
                else
                {
                    authtotry = typelist[0];
                }
                Runner.DebugMessage("Debug.Info.Connect", "Using " + authtotry);
            }
            else
            {
                retval = 1;
                return retval;
            }
            Node node;
            switch (authtotry)
            {
                case "RSA":
                    if (Runner.Network.NodeList.TryGetValue(Parameters["node.uuid"], out node) == true)
                    {
                        container.Node = node;
                        node.Version = Parameters["version"];

                        if (listen == true)
                        {
                            TextMessage bmsg = new TextMessage("Control.Auth.Challenge");
                            byte[] cookie = new byte[64];
                            Runner.Network.Random.NextBytes(cookie);
                            foreach (KeyValuePair<UUID, Auth> auth in node.AuthKeyList)
                            {
                                string ciphertext;
                                IMessage rmsg = auth.Value.Key.Encrypt(true, cookie, out ciphertext);
                                if (rmsg.Type == "Error.OK")
                                {
                                    string firstmessage = auth.Key + "!" + ciphertext;
                                    rmsg = Runner.Network.Node.Key.Encrypt(false, UTF8Encoding.UTF8.GetBytes(firstmessage), out ciphertext);
                                    bmsg.Data = Runner.Network.Node.Key.UUID.ToString() + "!" + ciphertext;
                                    this.Send(bmsg);
                                    Boolean ending = false;
                                    while (ending == false)
                                    {
                                        TextMessage tmsg;
                                        tmsg = new TextMessage(this.Receive(true));
                                        Boolean denied = false;
                                        switch (tmsg.Type)
                                        {
                                            case "Control.Auth.Response":
                                                string[] chunks = tmsg.Data.Split('!');
                                                ciphertext = chunks[1];
                                                byte[] bytes;
                                                Runner.Network.Node.Key.Decrypt(true, ciphertext, out bytes);
                                                chunks = UTF8Encoding.UTF8.GetString(bytes).Split('!');
                                                foreach (KeyValuePair<UUID, Auth> authtoken in node.AuthKeyList)
                                                {
                                                    if (authtoken.Key.ToString() == chunks[0])
                                                    {
                                                        authtoken.Value.Key.Decrypt(false, chunks[1], out bytes);
                                                        for (int i = 0; i < 64; i++)
                                                        {
                                                            if (cookie[i] != bytes[i]) {
                                                                denied = true;
                                                                break;
                                                            }
                                                        }
                                                        break;
                                                    }
                                                }
                                                if (denied == false)
                                                {
                                                    if (Runner.Network.NodeList.TryGetValue(Parameters["node.uuid"], out node) == true)
                                                    {
                                                        container.Node = node;
                                                        node.Version = Parameters["version"];
                                                        TextMessage omsg = new TextMessage("Control.Auth.OK");
                                                        omsg.Data = "test";
                                                        omsg.Sequence = tmsg.Sequence;
                                                        this.Send(omsg);
                                                        retval = 0;
                                                        ending = true;
                                                    }
                                                    else
                                                    {
                                                        retval = 1;
                                                    }
                                                }

                                                break;
                                        }
                                        }
                                }
                                else
                                {
                                    Runner.DebugMessage("Debug.Info.Auth", rmsg.Type);
                                }
                            }
                        }
                        else
                        {
                            bool ending = false;
                            while (ending == false)
                            {
                                IMessage rmsg;
                                rmsg = this.Receive(true);
                                switch (rmsg.Type)
                                {
                                    case "Control.Auth.Challenge":
                                        TextMessage Challenge = new TextMessage(rmsg);
                                        string[] chunks = Challenge.Data.Split('!');
                                        UUID uuidauth = new UUID(chunks[0]);
                                        IMessage response;
                                        foreach (KeyValuePair<UUID, Auth> auth in node.AuthKeyList)
                                        {
                                            if (auth.Key.ToString() == uuidauth.ToString())
                                            {
                                                byte[] firststage;
                                                response = auth.Value.Key.Decrypt(false, chunks[1], out firststage);
                                                if (response.Type == "Error.OK")
                                                {
                                                    byte[] output;
                                                    chunks = UTF8Encoding.UTF8.GetString(firststage).Split('!');
                                                    response = Runner.Network.Node.Key.Decrypt(true, chunks[1], out output);
                                                    byte[] plaintext = new byte[64];
                                                    for (int i = 0; i < 64; i++)
                                                    {
                                                        plaintext[i] = output[i];
                                                    }                                                    Challenge.Type = "Control.Auth.Response";
                                                    string ciphertext;
                                                    response = Runner.Network.Node.Key.Encrypt(false, plaintext, out ciphertext);
                                                    if (response.Type == "Error.OK")
                                                    {
                                                        ciphertext = Runner.Network.Node.Key.UUID + "!" + ciphertext;
                                                        response = auth.Value.Key.Encrypt(true, UTF8Encoding.UTF8.GetBytes(ciphertext), out ciphertext);
                                                        if (response.Type == "Error.OK")
                                                        {
                                                            ciphertext = auth.Key.ToString() + "!" + ciphertext;
                                                            Challenge.Data = ciphertext;
                                                            this.Send(Challenge);
                                                            ending = true;
                                                            break;
                                                        }
                                                        else
                                                        {
                                                            retval = 1;
                                                            ending = true;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        retval = 1;
                                                        ending = true;
                                                    }
                                                }
                                            }
                                        }
                                        break;
                                }
                            }
                            ending = false;
                            while (ending == false)
                            {
                                IMessage rmsg = this.Receive(true);
                                switch (rmsg.Type)
                                {
                                    case "Control.Auth.OK":
                                        container.Node = node;
                                        node.Version = Parameters["version"];
                                        retval = 0;
                                        ending = true;
                                        break;
                                    default:
                                        retval = 1;
                                        ending = true;
                                        break;

                                }
                            }
                        }
                        Runner.DebugMessage("Debug.Info.Auth", "Remote Node is: " + node.ToString());
                        retval = 0;
                    }
                    else
                    {
                        retval = 1;
                    }
                    break;
                case "NONE":
                    if (Runner.Network.NodeList.TryGetValue(Parameters["node.uuid"], out node) == true)
                    {
                        container.Node = node;
                        node.Version = Parameters["version"];
                        Runner.DebugMessage("Debug.Info.Auth", "Remote Node is: " + node.ToString());
                        retval = 0;
                    }
                    else
                    {
                        retval = 1;
                    }
                    break;
            }
            return retval;
        }
Example #29
0
 void Send_GET_KEY(string version)
 {
     KeyValueMessage message = new KeyValueMessage(IDTable[MessageID.GET_KEY]);
     message.AddField("version", version);
     session.Send(message);
 }
Example #30
0
        public int Auth(bool listen, bool enrollment)
        {
            IConnection     container = this;
            int             retval    = 99;
            KeyValueMessage keyval;
            List <string>   authtypes = new List <string>();

            // authtypes.Add("NONE");
            authtypes.Add("RSA");

            string authstring = "";

            foreach (string entry in authtypes)
            {
                if (authstring == "")
                {
                    authstring = entry;
                }
                else
                {
                    authstring = authstring + " " + entry;
                }
            }

            keyval = new KeyValueMessage("Control.PreAuth");
            keyval.Add("node.uuid", Runner.Network.Node.UUID.ToString());
            keyval.Add("auth.types", authstring);
            keyval.Add("version", SimpleMesh.Service.Utility.Version);
            if (listen == false)
            {
                container.Send(keyval);
            }
            bool end;

            end = false;
            bool            error = false;
            IMessage        Recieved;
            bool            uuid         = false;
            bool            authreceived = false;
            bool            enrolling    = false;
            KeyValueMessage messages;
            List <string>   typelist;

            typelist = new List <string>();
            string conntype;
            Dictionary <string, string> Parameters = new Dictionary <string, string>();

            while (end == false)
            {
                Recieved = container.Receive(true);
                if (Recieved.Type.Substring(0, 6) != "Error.")
                {
                    switch (Recieved.Type)
                    {
                    case "Control.PreAuth":
                        messages = new KeyValueMessage(Recieved);
                        foreach (KeyValuePair <string, string> keyn in messages.Data)
                        {
                            switch (keyn.Key)
                            {
                            case "node.uuid":
                                uuid = true;
                                break;

                            case "auth.types":
                                authreceived = true;
                                string[] types = keyn.Value.Split(' ');
                                foreach (string type in types)
                                {
                                    if (authtypes.Contains(type))
                                    {
                                        typelist.Add(type);
                                    }
                                }
                                break;
                            }
                            Parameters.Add(keyn.Key, keyn.Value);
                        }
                        if (listen == true)
                        {
                            container.Send(keyval);
                        }
                        break;
                    }
                }
                else
                {
                    end   = true;
                    error = true;
                }
                if (authreceived == true && uuid == true)
                {
                    end = true;
                }
            }
            if (error == true)
            {
                retval = 1;
                return(retval);
            }
            string msg;

            msg = "Auth Types available:";
            bool first = true;

            foreach (string type in typelist)
            {
                msg = msg + " " + type;
            }
            Runner.DebugMessage("Debug.Info.Connect", msg);
            string authtotry = "";

            if (typelist.Count != 0)
            {
                if (typelist.Contains("NONE"))
                {
                    authtotry = "NONE";
                }
                else
                {
                    authtotry = typelist[0];
                }
                Runner.DebugMessage("Debug.Info.Connect", "Using " + authtotry);
            }
            else
            {
                retval = 1;
                return(retval);
            }
            Node node;

            switch (authtotry)
            {
            case "RSA":
                if (Runner.Network.NodeList.TryGetValue(Parameters["node.uuid"], out node) == true)
                {
                    container.Node = node;
                    node.Version   = Parameters["version"];

                    if (listen == true)
                    {
                        TextMessage bmsg   = new TextMessage("Control.Auth.Challenge");
                        byte[]      cookie = new byte[64];
                        Runner.Network.Random.NextBytes(cookie);
                        foreach (KeyValuePair <UUID, Auth> auth in node.AuthKeyList)
                        {
                            string   ciphertext;
                            IMessage rmsg = auth.Value.Key.Encrypt(true, cookie, out ciphertext);
                            if (rmsg.Type == "Error.OK")
                            {
                                string firstmessage = auth.Key + "!" + ciphertext;
                                rmsg      = Runner.Network.Node.Key.Encrypt(false, UTF8Encoding.UTF8.GetBytes(firstmessage), out ciphertext);
                                bmsg.Data = Runner.Network.Node.Key.UUID.ToString() + "!" + ciphertext;
                                this.Send(bmsg);
                                Boolean ending = false;
                                while (ending == false)
                                {
                                    TextMessage tmsg;
                                    tmsg = new TextMessage(this.Receive(true));
                                    Boolean denied = false;
                                    switch (tmsg.Type)
                                    {
                                    case "Control.Auth.Response":
                                        string[] chunks = tmsg.Data.Split('!');
                                        ciphertext = chunks[1];
                                        byte[] bytes;
                                        Runner.Network.Node.Key.Decrypt(true, ciphertext, out bytes);
                                        chunks = UTF8Encoding.UTF8.GetString(bytes).Split('!');
                                        foreach (KeyValuePair <UUID, Auth> authtoken in node.AuthKeyList)
                                        {
                                            if (authtoken.Key.ToString() == chunks[0])
                                            {
                                                authtoken.Value.Key.Decrypt(false, chunks[1], out bytes);
                                                for (int i = 0; i < 64; i++)
                                                {
                                                    if (cookie[i] != bytes[i])
                                                    {
                                                        denied = true;
                                                        break;
                                                    }
                                                }
                                                break;
                                            }
                                        }
                                        if (denied == false)
                                        {
                                            if (Runner.Network.NodeList.TryGetValue(Parameters["node.uuid"], out node) == true)
                                            {
                                                container.Node = node;
                                                node.Version   = Parameters["version"];
                                                TextMessage omsg = new TextMessage("Control.Auth.OK");
                                                omsg.Data     = "test";
                                                omsg.Sequence = tmsg.Sequence;
                                                this.Send(omsg);
                                                retval = 0;
                                                ending = true;
                                            }
                                            else
                                            {
                                                retval = 1;
                                            }
                                        }

                                        break;
                                    }
                                }
                            }
                            else
                            {
                                Runner.DebugMessage("Debug.Info.Auth", rmsg.Type);
                            }
                        }
                    }
                    else
                    {
                        bool ending = false;
                        while (ending == false)
                        {
                            IMessage rmsg;
                            rmsg = this.Receive(true);
                            switch (rmsg.Type)
                            {
                            case "Control.Auth.Challenge":
                                TextMessage Challenge = new TextMessage(rmsg);
                                string[]    chunks    = Challenge.Data.Split('!');
                                UUID        uuidauth  = new UUID(chunks[0]);
                                IMessage    response;
                                foreach (KeyValuePair <UUID, Auth> auth in node.AuthKeyList)
                                {
                                    if (auth.Key.ToString() == uuidauth.ToString())
                                    {
                                        byte[] firststage;
                                        response = auth.Value.Key.Decrypt(false, chunks[1], out firststage);
                                        if (response.Type == "Error.OK")
                                        {
                                            byte[] output;
                                            chunks   = UTF8Encoding.UTF8.GetString(firststage).Split('!');
                                            response = Runner.Network.Node.Key.Decrypt(true, chunks[1], out output);
                                            byte[] plaintext = new byte[64];
                                            for (int i = 0; i < 64; i++)
                                            {
                                                plaintext[i] = output[i];
                                            }
                                            Challenge.Type = "Control.Auth.Response";
                                            string ciphertext;
                                            response = Runner.Network.Node.Key.Encrypt(false, plaintext, out ciphertext);
                                            if (response.Type == "Error.OK")
                                            {
                                                ciphertext = Runner.Network.Node.Key.UUID + "!" + ciphertext;
                                                response   = auth.Value.Key.Encrypt(true, UTF8Encoding.UTF8.GetBytes(ciphertext), out ciphertext);
                                                if (response.Type == "Error.OK")
                                                {
                                                    ciphertext     = auth.Key.ToString() + "!" + ciphertext;
                                                    Challenge.Data = ciphertext;
                                                    this.Send(Challenge);
                                                    ending = true;
                                                    break;
                                                }
                                                else
                                                {
                                                    retval = 1;
                                                    ending = true;
                                                }
                                            }
                                            else
                                            {
                                                retval = 1;
                                                ending = true;
                                            }
                                        }
                                    }
                                }
                                break;
                            }
                        }
                        ending = false;
                        while (ending == false)
                        {
                            IMessage rmsg = this.Receive(true);
                            switch (rmsg.Type)
                            {
                            case "Control.Auth.OK":
                                container.Node = node;
                                node.Version   = Parameters["version"];
                                retval         = 0;
                                ending         = true;
                                break;

                            default:
                                retval = 1;
                                ending = true;
                                break;
                            }
                        }
                    }
                    Runner.DebugMessage("Debug.Info.Auth", "Remote Node is: " + node.ToString());
                    retval = 0;
                }
                else
                {
                    retval = 1;
                }
                break;

            case "NONE":
                if (Runner.Network.NodeList.TryGetValue(Parameters["node.uuid"], out node) == true)
                {
                    container.Node = node;
                    node.Version   = Parameters["version"];
                    Runner.DebugMessage("Debug.Info.Auth", "Remote Node is: " + node.ToString());
                    retval = 0;
                }
                else
                {
                    retval = 1;
                }
                break;
            }
            return(retval);
        }