示例#1
0
        private void OnLineSecured(INetworkConnection con, Packet p)
        {
            PacketLineSecured msg = p as PacketLineSecured;

            Log.LogMsg("Got Rijndael reply. Verifying key...");
            // Server got our encrypted Rijndael key.  Make sure it's all good still.
            if (m_ConnectionKey.Equals(CryptoManager.RijDecrypt(msg.Key, m_ConnectionKey)) && msg.ReplyCode == ReplyType.OK)
            {
                KillConnection("Failed to secure the connection.  Closing socket. " + msg.ReplyMessage);
                return;
            }
            Log.LogMsg("Line secured. Sending login request.");

            // FireLineSecuredEvent
            FireSocketSecured(this, EventArgs.Empty);

            // Send the login request, encrypting our user name and password
            PacketLoginRequest plr = (PacketLoginRequest)CreatePacket((int)PacketType.LoginRequest, 0, true, true);

            plr.AccountName         = m_AccountName;
            plr.Password            = m_Password;
            plr.IsNewAccount        = IsNewAccount;
            plr.LoginConnectionType = m_ConnectionType;
            OnBeforeLoginRequest(plr);
            Send(plr);
        }
示例#2
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);
            }
        }