Exemplo n.º 1
0
 public void NetworkProtocol(ref networkServer.networkClientInterface NetworkClient, string message)
 {
     //Public for the Unit Tests
     CCstData.GetInstance(Application).Logger.writeInLog(3, LogCategory.OK, Support.LoggerType.SERVER, "Protocol received: " + message);
     try
     {
         //Öañ4\u001b3[\b\nÎbÞö}\u0010VDYZ‚\u009d\u0005sQ˜e@p•\u001e\ab{󥟛¨YÉ`\\wõˆ¹éî\0
         if (message[message.Length - 1] == '\0')
         {
             message = message.Substring(0, message.Length - 1);
         }
         //Decrypt received protocol
         // QUESTION: Can we somehow see if we get something that isn't encrypted like traffic?
         // QUESTION: Is it possible to decrypt something that isn't enchrypted and send it to the ProtocolController?
         // QUESTION: Or does the decryption function checck all this?
         List <char> Chars = message.ToList();
         message = AES_Converter.DecryptFromCBC(CCstData.GetInstance(Application).EncryptionKey, CCstData.GetInstance(Application).EncryptionIV, message);
         if (message[message.Length - 1] == '\0')
         {
             message = message.Substring(0, message.Length - 1);
         }
     }
     catch (Exception e)
     {
         //If decryption failed, something was probably manipulated -> Log it
         CCstData.GetInstance(Application).Logger.writeInLog(1, LogCategory.CRITICAL, Support.LoggerType.SERVER, "Protocol Decryption failed! Message: " + message + ", Error: " + e.ToString());
         return;
     }
     CCstData.GetInstance(Application).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.SERVER, "Protocol received decrypted: " + message);
     ProtocolController.ReceivedProtocol(NetworkClient, message);
 }
Exemplo n.º 2
0
        public void SendProtocol(string Protocol, networkServer.networkClientInterface ClientInterface)
        {
            //encrypt protocol
            string EncryptedProt  = AES_Converter.EncryptWithCBC(CCstData.GetInstance(Application).EncryptionKey, CCstData.GetInstance(Application).EncryptionIV, Protocol);
            string LengthAddition = EncryptedProt.Length.ToString();

            while (LengthAddition.Length < 3)
            {
                LengthAddition = "0" + LengthAddition;
            }
            EncryptedProt = LengthAddition + EncryptedProt;
            CCstData.GetInstance(Application).Logger.writeInLog(3, LogCategory.OK, Support.LoggerType.SERVER, String.Format("Protocol encrypted: {0} ({1})", EncryptedProt, Protocol));

            TcpServer.sendMessage(EncryptedProt, ClientInterface);
        }