Esempio n. 1
0
 protected override void Dispose(bool disposing)
 {
     m_lastPacketData = null;
     m_encrypt        = null;
     m_encryptfirst   = null;
     m_firstkey       = null;
     base.Dispose(disposing);
 }
Esempio n. 2
0
        //收到公钥数据
        private void OnReceivePublicKey(PacketReader reader)
        {
#if _NC_Compress
            if (m_secure_connection == false || reader.Size != 148)
            {
                this.CloseConnection();
                return;
            }
            int secflag = reader.ReadInt32();
            m_compressneedchecksum = (secflag == (int)PacketFlag.Compress_Need_Checksum);
            byte[] firstkey = reader.ReadBuffer(16);
            byte[] checksum = reader.ReadBuffer(16);

            if (m_encryptfirst == null)
            {
                m_encryptfirst = new TeaEncryption();
            }
            m_encryptfirst.Key = firstkey;
            m_encryptfirst.Decrypt(checksum, 0, checksum.Length);
            for (int i = 0; i < 16; i++)
            {
                if (firstkey[i] != checksum[i])
                {
                    CloseConnection();
                    return;
                }
            }
            if (m_encrypt == null)
            {
                m_encrypt = new TeaEncryption();
                m_encrypt.GenericKey();
            }
            byte[] pairkey = new byte[16];
            Array.Copy(m_encrypt.Key, pairkey, 16);
            m_encryptfirst.Encrypt(pairkey, 0, 16);
            byte[] sendkey = new byte[128];
            Utility.Randomizer.NextBytes(sendkey);
            Buffer.BlockCopy(pairkey, 0, sendkey, 0, 16);
            m_encryptfirst.Decrypt(pairkey, 0, 16);
            SendSessionKeyPacket packet = new SendSessionKeyPacket(sendkey);
            SendPacket(packet, false);
            firstkey          = null;   //clear temp key
            m_connectionState = ConnectionState.Connected;
            //callback
            if (m_listener != null)
            {
                m_listener.OnSecureAccepted(this);
            }
#endif
        }
Esempio n. 3
0
 protected override void Dispose(bool disposing)
 {
     m_lastPacketData     = null;
     tls_sendSecureBuffer = null;
     m_encrypt            = null;
     m_encryptfirst       = null;
     m_firstkey           = null;
     if (m_recvqueue != null)
     {
         m_recvqueue.Clear();
     }
     m_recvqueue = null;
     m_reactor   = null;
     base.Dispose(disposing);
 }
Esempio n. 4
0
        //发送公钥数据
        protected override void StartSecureValidate()
        {
#if _NC_Compress
            m_firstkey = new byte[16];
            byte[] keydata = new byte[128];
            Utility.Randomizer.NextBytes(keydata);
            Utility.Randomizer.NextBytes(m_firstkey);
            Buffer.BlockCopy(m_firstkey, 0, keydata, 0, m_firstkey.Length);
            Buffer.BlockCopy(m_firstkey, 0, keydata, m_firstkey.Length, m_firstkey.Length);
            if (m_encryptfirst == null)
            {
                m_encryptfirst = new TeaEncryption();
            }
            m_encryptfirst.Key = m_firstkey;
            m_encryptfirst.Encrypt(keydata, m_firstkey.Length, m_firstkey.Length);
            SendPublicKeyPacket packet = new SendPublicKeyPacket((int)PacketFlag.Compress_Need_Checksum, keydata);
            this.SendPacket(packet, false);
#endif
        }
Esempio n. 5
0
        //收到会话密钥数据
        private void OnReceiveSessionKey(PacketReader reader)
        {
#if _NC_Compress
            if (m_secure_connection == false)
            {
                CloseConnection();
                return;
            }
            byte[] sessionkey = reader.ReadBuffer(16);
            if (reader.Size != 144 || sessionkey == null)
            {
                CloseConnection();
                return;
            }
            if (m_encryptfirst == null)
            {
                m_encryptfirst     = new TeaEncryption();
                m_encryptfirst.Key = m_firstkey;
            }

            m_encryptfirst.Decrypt(sessionkey, 0, 16);
            if (m_encrypt == null)
            {
                m_encrypt = new TeaEncryption();
            }

            m_encrypt.Key     = sessionkey;
            m_connectionState = ConnectionState.Connected;

            if (m_isAsyncNetCallBack)
            {
                OnConnectedCallback(null);
            }
            else
            {
                lock (this)
                {
                    m_netStateChange |= (int)NetStateChange.State_Connect_Success;
                }
            }
#endif
        }