Example #1
0
        private void HandleAuthLogonProof(ClientConnection connection, Packet inPacket)
        {
            var outPacket = new RealmPacket(AuthServerOpCode.AUTH_LOGON_PROOF);
            var a = new byte[32];
            var m1 = new byte[20];

            Array.Copy(inPacket.Data, 1, a, 0, 32);
            Array.Copy(inPacket.Data, 1, m1, 0, 20);

            Account acc = Account.Find(connection);
            acc.Srp6.CalculateU(a);
            acc.Srp6.CalculateM2(m1);

            CalculateAccountHash(connection.Account);

            // TODO: Is this right?
            if (!IsCorrectHash(acc, a, m1))
            {
                outPacket.Writer.Write((byte) AccountStatus.UnknownAccount);
            }
            else
            {
                outPacket.Writer.Write((byte) AccountStatus.Ok);
            }

            outPacket.Writer.Write(acc.Srp6.M2);

            //write 10 null bytes
            outPacket.Writer.WriteNull(10);

            Send(connection, outPacket.Data);
        }
Example #2
0
    private void ReceiveData(IAsyncResult iar)
    {
        Socket remote = (Socket)iar.AsyncState;
        int    recv   = remote.EndReceive(iar);

        RealmPacket packet = new RealmPacket(data);

        Console.WriteLine("Packet received : {0}", packet.Opcode);
        switch (packet.Opcode)
        {
        case RealmOpcodes.AUTH_LOGON_CHALLENGE:
            handleAuthLogonChallenge(packet);
            sendAuthLogonProof();
            break;

        case RealmOpcodes.AUTH_LOGON_PROOF:
            handleAuthLogonProof(packet);
            sendRealmList();
            break;

        case RealmOpcodes.REALM_LIST:
            handleRealmList(packet);
            break;

        default:
            Console.WriteLine("Unknown Opcode {0}", packet.Opcode);
            break;
        }

        // continue to wait for datas
        client.BeginReceive(data, 0, size, SocketFlags.None, new AsyncCallback(ReceiveData), client);
    }
Example #3
0
    private void handleAuthLogonChallenge(RealmPacket packet)
    {
        packet.readByte(); // read unknown
        packet.readByte(); // read error
        srp.B = new BigInteger(packet.readBytes(32));

        int SRP_g_len = packet.readByte(); // SRP_g length
        srp.g = new BigInteger(packet.readBytes(SRP_g_len)); // SRP_g

        int SRP_N_len = packet.readByte(); // SRP_N length
        srp.N = new BigInteger(packet.readBytes(SRP_N_len)); // SRP_N

        srp.s = packet.readBytes(32); // SRP salt

        packet.readString(16);  // CRC, not checked
        packet.readByte();      // security flag

        // Calculate the SRP values
        srp.calculateSRP_A();
        srp.calculateSRP_x();
        srp.calculateSRP_v();
        srp.calculateSRP_u();
        srp.calculateSRP_S();
        srp.calculateSRP_K();
        srp.calculateSRP_M1();
        srp.calculateSRP_M2();
    }
Example #4
0
    private void handleAuthLogonChallenge(RealmPacket packet)
    {
        packet.readByte(); // read unknown
        packet.readByte(); // read error
        srp.B = new BigInteger(packet.readBytes(32));

        int SRP_g_len = packet.readByte();                   // SRP_g length

        srp.g = new BigInteger(packet.readBytes(SRP_g_len)); // SRP_g

        int SRP_N_len = packet.readByte();                   // SRP_N length

        srp.N = new BigInteger(packet.readBytes(SRP_N_len)); // SRP_N

        srp.s = packet.readBytes(32);                        // SRP salt

        packet.readString(16);                               // CRC, not checked
        packet.readByte();                                   // security flag

        // Calculate the SRP values
        srp.calculateSRP_A();
        srp.calculateSRP_x();
        srp.calculateSRP_v();
        srp.calculateSRP_u();
        srp.calculateSRP_S();
        srp.calculateSRP_K();
        srp.calculateSRP_M1();
        srp.calculateSRP_M2();
    }
Example #5
0
 private void ClientSending(object pmMain = null)
 {
     try
     {
         while (this.working)
         {
             RealmPacket rp = outRPQueue.Dequeue();
             if (rp != null)
             {
                 int sentLength = clientSocket.Send(rp.GetPacketBuffer());
                 if (sentLength < 1)
                 {
                     MLogger.NetworkLogger.Error("Realm client socket sent 0 bytes : " + this.clientSocket.Handle);
                     this.StopSession();
                 }
             }
             Thread.Sleep(10);
         }
     }
     catch (Exception exp)
     {
         MLogger.NetworkLogger.Error("Realm client sending exp :" + this.clientSocket.Handle + " " + exp.Message);
         this.StopSession();
     }
 }
Example #6
0
    private void handleRealmList(RealmPacket packet)
    {
        SRealmList realmList = SRealmList.getInstance();

        packet.readUint16();                // size
        packet.readUint32();                // unk1
        int nbrealms = packet.readUint16(); // nb realms

        for (int i = 0; i < nbrealms; i++)
        {
            Realm r = new Realm();
            r.Icon         = packet.readByte();    // icon
            r.IsLock       = packet.readByte();    // lock
            r.Color        = packet.readByte();    // color
            r.Name         = packet.readCString(); // name
            r.Address      = packet.readCString(); // address
            r.Population   = packet.readFloat();   // population
            r.NbCharacters = packet.readByte();    // nb characters
            r.Timezone     = packet.readByte();    // timezone
            packet.readByte();                     // unk

            realmList.add(r);
        }

        packet.readByte(); // unk2
        packet.readByte(); // unk3
    }
Example #7
0
        private void HandleRealmList(ClientConnection connection, Packet inPacket)
        {
            var outPacket = new RealmPacket(AuthServerOpCode.REALM_LIST);

            outPacket.Writer.Write(0);
            outPacket.Writer.Write((ushort) Realms.Count);
            foreach (Realm r in Realms)
            {
                outPacket.Writer.Write((byte) r.ServerType);
                outPacket.Writer.Write((byte) r.ServerStatus);
                outPacket.Writer.Write((byte) r.Color);

                outPacket.Writer.Write(r.RealmName);
                outPacket.Writer.Write();

                outPacket.Writer.Write(r.Ip.ToString());
                outPacket.Writer.Write();

                outPacket.Writer.Write(r.Population);

                outPacket.Writer.Write();

                outPacket.Writer.Write((byte) r.TimeZone);
                outPacket.Writer.Write();
            }

            outPacket.Writer.Write((byte) 0x17);
            outPacket.Writer.Write();

            Send(connection, outPacket.Data);
        }
Example #8
0
    private void sendRealmList()
    {
        RealmPacket packet = new RealmPacket(RealmOpcodes.REALM_LIST);

        packet.writeUint32(0);

        client.BeginSend(packet.getFinalizedPacket(), 0, packet.Size, SocketFlags.None, new AsyncCallback(SendData), client);
    }
Example #9
0
 private void handleAuthLogonProof(RealmPacket packet)
 {
     // *TODO* Do the proper checks
     packet.readByte(); // error
     byte[] M2 = packet.readBytes(20); // M2
     packet.readUint32(); // unk1
     packet.readUint32(); // unk2
     packet.readUint16(); // unk3
 }
Example #10
0
 private void handleAuthLogonProof(RealmPacket packet)
 {
     // *TODO* Do the proper checks
     packet.readByte();                // error
     byte[] M2 = packet.readBytes(20); // M2
     packet.readUint32();              // unk1
     packet.readUint32();              // unk2
     packet.readUint16();              // unk3
 }
Example #11
0
    private void sendAuthLogonProof()
    {
        RealmPacket packet = new RealmPacket(RealmOpcodes.AUTH_LOGON_PROOF);

        packet.writeBigInteger(srp.A, 32); // A
        packet.writeBytes(srp.M1);         // M1
        packet.writeBytes(new byte[20]);   // crc
        packet.writeInt16(0);              //

        client.BeginSend(packet.getFinalizedPacket(), 0, packet.Size, SocketFlags.None, new AsyncCallback(SendData), client);
    }
Example #12
0
 public CmsgAuthSession(RealmPacket packet)
 {
     ClientBuild = packet.ReadUInt32();
     Unk2        = packet.ReadUInt32();
     Account     = packet.ReadCString();
     Unk3        = packet.ReadUInt32();
     ClientSeed  = packet.ReadUInt32();
     Unk4        = packet.ReadUInt64();
     Unk5        = packet.ReadUInt32();
     Unk6        = packet.ReadUInt32();
     Unk7        = packet.ReadUInt32();
 }
Example #13
0
        private static async void AcceptClientActionAsync(TcpClient rawClient)
        {
            Console.WriteLine("Accepting Realm Client");
            var client = new RealmRemoteClient(rawClient);

            var clientGuid = Guid.Empty;

            Console.WriteLine($"Using realm seed: 0x{client.Seed:x}");

            try
            {
                clientGuid = RealmServices.RemoteClients.AddClient(client);

                var packet = new RealmPacket(true)
                {
                    Opcode = 0x1ec
                };

                packet.WriteUInt32(1); // unk1
                packet.WriteUInt32(client.Seed);
                packet.WriteUInt32(0); // unk2
                packet.WriteUInt32(0); // unk3
                packet.WriteUInt32(0); // unk4
                packet.WriteUInt32(0); // unk5

                Task.Run(async() =>
                {
                    // Give us time to start listening
                    await Task.Delay(500);
                    await client.SendDataAsync(new RealmMetaPacket(packet.FinalizePacket()));
                }).RunAsync();

                await client.ListenForDataTask();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Unhandled exception in {nameof(AcceptClientActionAsync)}: {ex}");
            }
            finally
            {
                if (clientGuid != Guid.Empty)
                {
                    RealmServices.RemoteClients.RemoveClient(clientGuid);
                }
                Console.WriteLine($"Client disconnected");
            }
        }
Example #14
0
    private void sendAuthLogonChallenge()
    {
        RealmPacket packet = new RealmPacket(RealmOpcodes.AUTH_LOGON_CHALLENGE);

        packet.writeByte(8);                             // error code
        packet.writeUint16((UInt16)(30 + srp.I.Length)); // Packet Size
        packet.writeString("WoW", 4);                    // Game name
        packet.writeBytes(new byte[] { 3, 2, 2 });       // WoW Version
        packet.writeUint16(10505);                       // WoW build
        packet.writeString("68x", 4);                    // platform
        packet.writeString("niW", 4);                    // Operating System
        packet.writeString("RFrf", 4);                   // Country
        packet.writeUint32(0);
        packet.writeBytes(new byte[] { 127, 0, 0, 1 });  // IP
        packet.writePascalString(srp.I);

        client.BeginSend(packet.getFinalizedPacket(), 0, packet.Size, SocketFlags.None, new AsyncCallback(SendData), client);
    }
Example #15
0
    private void sendAuthLogonChallenge()
    {
        RealmPacket packet = new RealmPacket(RealmOpcodes.AUTH_LOGON_CHALLENGE);
        packet.writeByte(8);    // error code
        packet.writeUint16((UInt16)(30 + srp.I.Length));    // Packet Size
        packet.writeString("WoW", 4);   // Game name
        packet.writeBytes(new byte[] { 3, 2, 2 }); // WoW Version
        packet.writeUint16(10505);      // WoW build
        packet.writeString("68x", 4);   // platform
        packet.writeString("niW", 4);   // Operating System
        packet.writeString("RFrf", 4);  // Country
        packet.writeUint32(0);
        packet.writeBytes(new byte[] {127, 0, 0, 1});   // IP
        packet.writePascalString(srp.I);

        client.BeginSend(packet.getFinalizedPacket(), 0, packet.Size, SocketFlags.None, new AsyncCallback(SendData), client);
    }
Example #16
0
    private void sendAuthLogonProof()
    {
        RealmPacket packet = new RealmPacket(RealmOpcodes.AUTH_LOGON_PROOF);

        packet.writeBigInteger(srp.A, 32); // A
        packet.writeBytes(srp.M1); // M1
        packet.writeBytes(new byte[20]); // crc
        packet.writeInt16(0); //

        client.BeginSend(packet.getFinalizedPacket(), 0, packet.Size, SocketFlags.None, new AsyncCallback(SendData), client);
    }
Example #17
0
    private void sendRealmList()
    {
        RealmPacket packet = new RealmPacket(RealmOpcodes.REALM_LIST);

        packet.writeUint32(0);

        client.BeginSend(packet.getFinalizedPacket(), 0, packet.Size, SocketFlags.None, new AsyncCallback(SendData), client);
    }
Example #18
0
    private void handleRealmList(RealmPacket packet)
    {
        SRealmList realmList = SRealmList.getInstance();

        packet.readUint16(); // size
        packet.readUint32(); // unk1
        int nbrealms = packet.readUint16(); // nb realms

        for (int i = 0; i < nbrealms; i++)
        {
            Realm r = new Realm();
            r.Icon = packet.readByte(); // icon
            r.IsLock = packet.readByte(); // lock
            r.Color = packet.readByte(); // color
            r.Name = packet.readCString(); // name
            r.Address = packet.readCString(); // address
            r.Population = packet.readFloat(); // population
            r.NbCharacters = packet.readByte(); // nb characters
            r.Timezone = packet.readByte(); // timezone
            packet.readByte(); // unk

            realmList.add(r);
        }

        packet.readByte(); // unk2
        packet.readByte(); // unk3
    }
Example #19
0
        private void HandleAuthLogonChallenge(ClientConnection connection, Packet inPacket)
        {
            Logging.WriteDebug("HandleAuthLogonChallenge entered (" + connection.ClientIp + ")");
            inPacket.Reader.BaseStream.Position += 8;

            // Because this is just plain easier to work with, and we can pass it around as much as we want.
            var version = new Version(inPacket.Data[9],
                                      BitConverter.ToInt16(new[] {inPacket.Data[11], inPacket.Data[12]}, 0),
                                      inPacket.Data[10]);

            //Before we go any further, make sure the user has a valid game version for this server.
            //if (version.Major > Config.GetValue<uint>(Config.LogonServerConfig, "Max"))
            // {
            //     SendChallengeError(connection, AccountStatus.BadVersion);
            //     return;
            // }
            // else if (version.Minor < Config.GetValue<uint>(Config.LogonServerConfig, "Min"))
            // {
            //     //TODO: Initialize patching sequence!... then comment these two lines out.
            //    SendChallengeError(connection, AccountStatus.BadVersion);
            //    return;
            // }

            IPAddress ip = inPacket.Reader.ReadIpAddress(); // 4 bytes [0x1D-0x21]

            // Uncomment/change the following line if the byte for the string length changes.
            //inPacket.Reader.BaseStream.Seek(33, SeekOrigin.Begin);

            // Account name *should* be in upper case, but may not.
            string accountName = inPacket.Reader.ReadPascalString(1);

            Logging.WriteDebug("Logon Challenge: Client " + version);
            Logging.WriteDebug("Account: " + accountName + " IP: " + ip);

            var acc = new Account();

            if (Account.Exists(accountName))
            {
                DataTable dt = Account.QueryAccountInfo(accountName);

                acc.Username = dt.Rows[0]["login"].ToString();
                acc.Password = dt.Rows[0]["password"].ToString();

                byte[] userBytes = Encoding.UTF8.GetBytes(acc.Username.ToUpper());
                byte[] passBytes = Encoding.UTF8.GetBytes(acc.Password.ToUpper());

                acc.Srp6.CalculateX(userBytes, passBytes);

                acc.IP = ip;
                acc.ID = connection.ClientId;

                var outPacket = new RealmPacket(AuthServerOpCode.AUTH_LOGON_CHALLENGE);
                outPacket.Writer.Write();
                outPacket.Writer.Write((byte) AccountStatus.Ok);
                outPacket.Writer.Write(acc.Srp6.B);
                outPacket.Writer.Write((byte) 1);
                outPacket.Writer.Write(acc.Srp6.g[0]);
                outPacket.Writer.Write((byte) acc.Srp6.N.Length);
                outPacket.Writer.Write(acc.Srp6.N);
                outPacket.Writer.Write(acc.Srp6.salt);

                outPacket.Writer.WriteNull(17);

                Send(connection, outPacket.Data);
                connection.Account = acc;
                ClientConnection.Connections.Add(connection);
            }
            else
            {
                SendProofError(connection, AccountStatus.UnknownAccount);
                return;
            }
        }
Example #20
0
    private void ReceiveData(IAsyncResult iar)
    {
        Socket remote = (Socket)iar.AsyncState;
        int recv = remote.EndReceive(iar);

        RealmPacket packet = new RealmPacket(data);
        Console.WriteLine("Packet received : {0}", packet.Opcode);
        switch (packet.Opcode)
        {
            case RealmOpcodes.AUTH_LOGON_CHALLENGE:
                handleAuthLogonChallenge(packet);
                sendAuthLogonProof();
                break;
            case RealmOpcodes.AUTH_LOGON_PROOF:
                handleAuthLogonProof(packet);
                sendRealmList();
                break;
            case RealmOpcodes.REALM_LIST:
                handleRealmList(packet);
                break;
            default:
                Console.WriteLine("Unknown Opcode {0}", packet.Opcode);
                break;
        }

        // continue to wait for datas
        client.BeginReceive(data, 0, size, SocketFlags.None, new AsyncCallback(ReceiveData), client);
    }