Example #1
0
        private async Task HandleAuthSession(WorldPacket wp)
        {
            _authsession                 = new AuthSession();
            _authsession.build           = wp.ReadUInt32();
            _authsession.loginServerId   = wp.ReadUInt32();
            _authsession.account         = wp.ReadString();
            _authsession.loginServerType = wp.ReadUInt32();
            _authsession.localChallenge  = wp.ReadBytes(4, true);
            _authsession.regionId        = wp.ReadUInt32();
            _authsession.battlegroupId   = wp.ReadUInt32();
            _authsession.realmId         = wp.ReadUInt32();
            _authsession.dosResponse     = wp.ReadUInt64();
            _authsession.digest          = wp.ReadBytes(20);
            //there's 4 bytes in here that i should probably read....
            _authsession.addonInfo = wp.ReadBytes(wp.Length - wp._rpos);
            //_authsession.unk0 = await _reader.ReadBytesAsync(len);

            _info = Program.authDatabase.Accounts.Single(a => a.username == _authsession.account);
            var sessionKey = MimicUtils.HexStringToByteArray(_info.sessionkey, 40);

            Debug.WriteLine(_info.sessionkey);

            _ac = new AuthCrypt(sessionKey);
            // Debug.WriteLine(_authsession);

            _session = new WorldSession(this, _info);
            _session.ReadAddonsInfo(_authsession.addonInfo);


            SHA1 sh = SHA1.Create();

            sh.Initialize();
            byte[] username = Encoding.UTF8.GetBytes(_authsession.account);
            sh.TransformBlock(username, 0, username.Length, username, 0);
            byte[] pad = new byte[4];
            sh.TransformBlock(pad, 0, pad.Length, pad, 0);
            byte[] localChal = _authsession.localChallenge;
            sh.TransformBlock(localChal, 0, localChal.Length, localChal, 0);
            sh.TransformBlock(_mseed, 0, _mseed.Length, _mseed, 0);
            sh.TransformBlock(sessionKey, 0, sessionKey.Length, sessionKey, 0);
            byte[] zer = new byte[0];
            sh.TransformFinalBlock(zer, 0, 0);
            byte[] d = sh.Hash;

            WorldPacket pck = new WorldPacket(WorldCommand.SMSG_AUTH_RESPONSE, this);

            if (!d.SequenceEqual(_authsession.digest)) //Didn't auth properly
            {
                Debug.WriteLine(BitConverter.ToString(d).Replace("-", ""));
                Debug.WriteLine(BitConverter.ToString(_authsession.digest).Replace("-", ""));
                Debug.WriteLine("Didn't auth properly");
                pck.append((byte)14);
                Close();
                return;
            }
            else
            {
                Debug.WriteLine("Client <" + _authsession.account + "> authed on build " + _authsession.build + " (0x1ED)");
                pck.append((byte)12);
                pck.append(0);
                pck.append((byte)0);
                pck.append(0);
                pck.append((byte)2);
                _status = AuthStatus.AUTHED;
            }
            Program.world.AddSession(_session);

            byte[] pdata = pck.result();
            _writer.Write(pdata);
        }
Example #2
0
        private async Task HandleLogonChallengeAsync()
        {
            var error = await _reader.ReadUInt8Async(); // always 3

            var size = await _reader.ReadUInt16Async();

            if (_client.Available < size)
            {
                await CloseAsync(AuthStatus.ProtocolError);

                return;
            }

            var gameName = await _reader.ReadUInt32Async();

            if (gameName != GameName)
            {
                await CloseAsync(AuthStatus.ProtocolError);

                return;
            }

            var versionMajor = await _reader.ReadUInt8Async();

            var versionMinor = await _reader.ReadUInt8Async();

            var versionPatch = await _reader.ReadUInt8Async();

            _buildNumber = await _reader.ReadUInt16Async();

            var platform = (Architecture)await _reader.ReadUInt32Async();

            var os = (OperatingSystem)await _reader.ReadUInt32Async();

            var locale = (Locale)await _reader.ReadUInt32Async();

            var timezoneBias = await _reader.ReadUInt32Async();

            var ipAddress   = new IPAddress(await _reader.ReadUInt32Async());
            var realAddress = (_client.Client.RemoteEndPoint as IPEndPoint).Address;

            var accountNameLength = await _reader.ReadUInt8Async();

            var accountName = await _reader.ReadStringAsync(accountNameLength);

            accountName = accountName.ToUpperInvariant();

            _info = Program.authDatabase.Accounts.Single(a => a.username == accountName);

            _info.last_ip = realAddress.ToString();
            //_info.last_login = new DateTime().ToUniversalTime().ToString();
            _info.os = os.ToString();
            //_info.locale = (int)locale; <not the same>

            byte[]     passhash = MimicUtils.HexStringToByteArray(_info.pass_hash);
            BigInteger s, v;

            if (_info.s != "" && _info.v != "")
            {
                s = SrpHandler.BigIntFromHexString(_info.s);
                v = SrpHandler.BigIntFromHexString(_info.v);
            }
            else
            {
                s = BigInteger.Zero;
                v = BigInteger.Zero;
            }
            _authentication.ComputePrivateFields(accountName, passhash, s, v);

            List <byte> data = new List <byte>();

            data.Add((byte)_currentCommand);
            data.Add(0);

            data.Add((byte)AuthStatus.Success);

            data.AddRange(_authentication.PublicKey); // B

            data.Add((byte)_authentication.Generator.Length);
            data.AddRange(_authentication.Generator); // g

            data.Add((byte)_authentication.SafePrime.Length);
            data.AddRange(_authentication.SafePrime); // N

            data.AddRange(_authentication.Salt);      // s

            data.AddRange(Enumerable.Repeat((byte)0, 16));

            data.Add(0); // security flags;

            await _clientStream.WriteAsync(data.ToArray(), 0, data.Count);
        }