Ejemplo n.º 1
0
        public ClientSession(Socket pSocket) : base(pSocket)
        {
            IP = BitConverter.ToUInt32(IPAddress.Parse(GetIP()).GetAddressBytes(), 0);

            InitiateReceive(2, true);
            CRYPT_KEY  = CryptoGenerators.GenerateKey();
            CRYPT_HMAC = CryptoGenerators.GenerateKey();
            byte[] TEMP_PREFIX = CryptoGenerators.GeneratePrefix();

            using (OutPacket oPacket = new OutPacket(CenterOpcodes.SET_SECURITY_KEY_NOT))
            {
                oPacket.WriteBytes(TEMP_PREFIX);
                oPacket.WriteInt((int)8);
                oPacket.WriteBytes(CRYPT_HMAC);
                oPacket.WriteInt((int)8);
                oPacket.WriteBytes(CRYPT_KEY);
                oPacket.WriteHexString("00 00 00 01 00 00 00 00 00 00 00 00");

                oPacket.Assemble(CryptoConstants.GC_DES_KEY, CryptoConstants.GC_HMAC_KEY, CRYPT_PREFIX, ++CRYPT_COUNT);
                Send(oPacket);
            }
            CRYPT_PREFIX = TEMP_PREFIX;

            using (OutPacket oPacket = new OutPacket(CenterOpcodes.ENU_WAIT_TIME_NOT))
            {
                oPacket.WriteHexString("00 00 27 10");

                oPacket.Assemble(CRYPT_KEY, CRYPT_HMAC, CRYPT_PREFIX, ++CRYPT_COUNT);
                Send(oPacket);
            }
        }
Ejemplo n.º 2
0
        public ClientSession(Socket pSocket) : base(pSocket)
        {
            IP = BitConverter.ToUInt32(IPAddress.Parse(GetIP()).GetAddressBytes(), 0);

            InitiateReceive(2, true);

            CurrentChannel = null;
            CurrentRoom    = null;

            CRYPT_KEY  = CryptoGenerators.GenerateKey();
            CRYPT_HMAC = CryptoGenerators.GenerateKey();
            byte[] TEMP_PREFIX = CryptoGenerators.GeneratePrefix(); // Prefix

            LogFactory.GetLog("Main").LogHex("IV: ", CRYPT_KEY);
            LogFactory.GetLog("Main").LogHex("HMAC: ", CRYPT_HMAC);

            using (OutPacket oPacket = new OutPacket(GameOpcodes.EVENT_ACCEPT_CONNECTION_NOT))
            {
                oPacket.WriteBytes(TEMP_PREFIX);
                oPacket.WriteInt((int)8);
                oPacket.WriteBytes(CRYPT_HMAC);
                oPacket.WriteInt((int)8);
                oPacket.WriteBytes(CRYPT_KEY);
                oPacket.WriteHexString("00 00 00 01 00 00 00 00 00 00 00 00");

                oPacket.Assemble(CryptoConstants.GC_DES_KEY, CryptoConstants.GC_HMAC_KEY, CRYPT_PREFIX, ++CRYPT_COUNT);
                Send(oPacket);
            }

            // Prefix
            CRYPT_PREFIX = TEMP_PREFIX;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 패킷을 보낼 수 있도록 가공한다. (zlib 압축 데이터 여기서 생성)
        /// </summary>
        /// <param name="key">Encryption key</param>
        /// <param name="hmacKey">HMAC generation key</param>
        /// <param name="prefix">The 6 bytes between the packet size and the IV</param>
        public void CompressAndAssemble(byte[] key, byte[] hmacKey, byte[] prefix, int count)
        {
            // 버퍼를 복구할 수 있도록.
            _buffer_before_assemble = _buffer;

            byte[] data = Compression.Compress(_buffer);

            byte[] Op  = BitConverter.GetBytes((short)Opcode);
            byte[] Len = BitConverter.GetBytes((int)data.Length + 4); // 버퍼 + 압축내용
            Array.Reverse(Op);
            Array.Reverse(Len);

            byte[] TempData;
            TempData = BytesUtil.ConcatBytes(Op, Len);
            TempData = BytesUtil.ConcatBytes(TempData, BitConverter.GetBytes((bool)true));          // 압축임
            TempData = BytesUtil.ConcatBytes(TempData, BitConverter.GetBytes((int)_buffer.Length)); // 실제 크기
            _buffer  = BytesUtil.ConcatBytes(TempData, data);

            byte[] IV = CryptoGenerators.GenerateIV();

            byte[] dataToAssemble = BytesUtil.ConcatBytes(
                BytesUtil.ConcatBytes(prefix, BitConverter.GetBytes(count)),
                BytesUtil.ConcatBytes(IV, CryptoFunctions.EncryptPacket(_buffer, key, IV)));
            _buffer = CryptoFunctions.ClearPacket(dataToAssemble, hmacKey);
        }