Esempio n. 1
0
        protected override byte[] OnBeforeSendPacket(byte[] body, bool encrypt, bool compress, Pointer bodyPointer)
        {
            if (encrypt && m_ConnectionKey.Length > 0)
            {
                body = CryptoManager.RijEncrypt(body, 0, bodyPointer.Position, m_ConnectionKey);
                bodyPointer.Position = body.Length;
            }

            if (compress)
            {
                body = Compression.CompressData(body, bodyPointer);
            }

            return(body);
        }
Esempio n. 2
0
        protected override byte[] OnBeforeSendPacket(byte[] body, bool encrypt, bool compress, Pointer bodyPointer)
        {
            if (encrypt && m_ConnectionKey.Length > 0)
            {
                // Log.LogMsg("Pre Encryption packet size " + body.Length.ToString());
                body = CryptoManager.RijEncrypt(body, 0, bodyPointer.Position, m_ConnectionKey);
                // Log.LogMsg("Encrypted packet size " + body.Length.ToString());
                bodyPointer.Position = body.Length;
            }

            if (compress)
            {
                body = Compression.CompressData(body, bodyPointer);
            }

            return(body);
        }
Esempio n. 3
0
        /// <summary>
        /// Encryption helper method.
        /// </summary>
        private void OnRijndaelExchange(INetworkConnection con, Packet pck)
        {
            PacketRijndaelExchange msg = pck as PacketRijndaelExchange;

            try
            {
                m_ConnectionKey = CryptoManager.DecryptRijndaelKey(msg.RijndaelExchangeData);
                PacketLineSecured p = (PacketLineSecured)CreatePacket((int)PacketType.LineSecured, 0, false, true);
                p.Key           = CryptoManager.RijEncrypt(m_ConnectionKey, 0, m_ConnectionKey.Length, m_ConnectionKey);
                p.ReplyCode     = ReplyType.OK;
                msg.ReplyPacket = p;
                RemoteRsaKey    = msg.PublicRSAKey;
            }
            catch (Exception e)
            {
                KillConnection("Encryption key exchange error. Disconnecting client connection. " + e.Message);
            }
        }