コード例 #1
0
ファイル: RealmListHandler.cs プロジェクト: madbroths/Encore
        public static void HandleRealmList(IClient client, IncomingAuthPacket packet)
        {
            Contract.Requires(client != null);
            Contract.Requires(packet != null);

            packet.ReadInt32(); // unk, ignored

            var realmNames = RealmList.RealmNames;

            var realmsSize = 0;
            foreach (string realmName in realmNames)
            {
                Realm realm = RealmList.GetRealm(realmName);
                realmsSize += 3;
                // +1 for the null character at the end
                realmsSize += realm.Name.Length + 1;
                realmsSize += realm.Address.Length + 1;
                realmsSize += 6;
                if ((realm.Color & 4) != 0)
                    realmsSize += 5;
            }

            using (var outPacket = new OutgoingAuthPacket(GruntOpCode.RealmList, 10 + realmsSize))
            {
                outPacket.Write((short)(6 + realmsSize + 2));
                outPacket.Write(0);
                outPacket.Write((short)realmNames.Count());
                foreach (string realmName in realmNames)
                {
                    Realm realm = RealmList.GetRealm(realmName);
                    var numChars = 0; //Realm.GetNumChars(/*client.UserData.SRP.Username*/);

                    outPacket.Write(realm.Icon);
                    outPacket.Write(realm.Lock);
                    outPacket.Write(realm.Color);
                    outPacket.WriteCString(realm.Name);
                    outPacket.WriteCString(realm.Address);
                    outPacket.Write(realm.PopulationLevel);
                    outPacket.Write(numChars);
                    outPacket.Write(realm.TimeZone);
                    outPacket.Write((byte)0x2C);
                    if ((realm.Color & 0x04) != 0)
                    {
                        outPacket.Write((byte)0);
                        outPacket.Write((byte)0);
                        outPacket.Write((byte)0);
                        outPacket.Write((short)0);
                    }
                }
                outPacket.Write((byte)0x10);
                outPacket.Write((byte)0x00);
                client.Send(outPacket);
            }
        }
コード例 #2
0
        public static void HandleAuthLogOnChallenge(IClient client, IncomingAuthPacket packet)
        {
            Contract.Requires(client != null);
            Contract.Requires(packet != null);

            packet.ReadByte(); // unk
            packet.ReadInt16(); // size
            packet.ReadFourCC(); // gameName
            packet.ReadByte(); // version1
            packet.ReadByte(); // version2
            packet.ReadByte(); // version3
            packet.ReadInt16(); // build
            packet.ReadFourCC(); // platform
            packet.ReadFourCC(); // os
            packet.ReadFourCC(); // country
            packet.ReadInt32(); // timeZoneBias
            packet.ReadInt32(); // ip
            var usernameLength = packet.ReadByte();
            var usernameBytes = packet.ReadBytes(usernameLength);
            var username = Encoding.ASCII.GetString(usernameBytes);
            SRPServer srpData = GetSRPDataForUserName(username);
            if (srpData == null)
            {
                SendAuthenticationChallengeFailure(client, AuthResult.FailUnknownAccount);
            }
            else
            {
                client.UserData.SRP = srpData;

                // make sure the result is at least 32 bytes long
                var peData = srpData.PublicEphemeralValueB.GetBytes(32);
                var publicEphemeral = new BigInteger(peData);

                var rand = new BigInteger(new FastRandom(), 16 * 8);
                SendAuthenticationChallengeSuccess(client,
                                                   publicEphemeral,
                                                   srpData.Parameters.Generator,
                                                   srpData.Parameters.Modulus,
                                                   srpData.Salt,
                                                   rand);
            }
        }
コード例 #3
0
        public static void HandleAuthLogOnProof(IClient client, IncomingAuthPacket packet)
        {
            Contract.Requires(client != null);
            Contract.Requires(packet != null);

            var clientPublicEphemeralA = packet.ReadBigInteger(32);
            // Client Proof.
            // SHA1 of { SHA1(Modulus) ^ SHA1(Generator), SHA1(USERNAME), salt, PublicA, PublicB, SessionKey }
            var clientResult = packet.ReadBigInteger(20);
            // SHA1 hash of the PublicA and HMACSHA1 of the contents of WoW.exe and unicows.dll. HMAC seed is the 16 bytes at the end of the challenge sent by the server.
            packet.ReadBytes(20); // these can safely be ignored, clientFileHash

            // the client tends to send 0, but just in case it's safer to implement this.
            var numKeys = packet.ReadByte();
            if (numKeys > 0)
            {
                // only initialize the array if we actually HAVE keys
                AuthLogonKey[] keys = new AuthLogonKey[numKeys];
                for (byte key = 0; key < numKeys; key++)
                {
                    var unk1 = packet.ReadInt16();
                    var unk2 = packet.ReadInt32();
                    var unk3 = packet.ReadBytes(4);
                    // SHA of { PublicA, PublicB, byte[20] unknown data }
                    var shaHash = packet.ReadBytes(20);
                    Contract.Assume(unk3.Length == 4);
                    Contract.Assume(shaHash.Length == 20);
                    keys[key] = new AuthLogonKey(unk1, unk2, unk3, shaHash);
                }
            }

            var securityFlags = (ExtraSecurityFlags)packet.ReadByte(); // can be safely ignored

            if (securityFlags.HasFlag(ExtraSecurityFlags.PIN))
            {
                packet.ReadBytes(16); // pinRandom
                packet.ReadBytes(20); // pinSha1
            }

            if (securityFlags.HasFlag(ExtraSecurityFlags.Matrix))
            {
                packet.ReadBytes(20); // matrixHmacResult
            }

            if (securityFlags.HasFlag(ExtraSecurityFlags.SecurityToken))
            {
                var tokenLength = packet.ReadByte();
                packet.ReadBytes(tokenLength); // token
            }

            SRPServer srpData = client.UserData.SRP;
            srpData.PublicEphemeralValueA = clientPublicEphemeralA;
            var success = srpData.Validator.IsClientProofValid(clientResult);
            if (success)
            {
                SendAuthenticationLogOnProofSuccess(client, srpData.Validator.ServerSessionKeyProof);
                client.AddPermission(new AuthenticatedPermission());
            }
            else
                SendAuthenticationLogOnProofFailure(client, AuthResult.FailUnknownAccount);
        }
コード例 #4
0
        public static void HandleReconnectProof(IClient client, IncomingAuthPacket packet)
        {
            // MD5 hash of { AccountName, byte[16] random data }
            BigInteger r1 = packet.ReadBigInteger(16);
            // SHA1 hash of { AccountName, MD5 from above, ReconnectProof, SessionKey }
            BigInteger r2 = packet.ReadBigInteger(20);
            // SHA1 hash of { MD5 from above, byte[16] of 0's }
            var r3 = packet.ReadBigInteger(20); // r3Data

            var numKeys = packet.ReadByte();
            if (numKeys > 0)
            {
                // only initialize the array if we actually HAVE keys
                AuthLogonKey[] keys = new AuthLogonKey[numKeys];
                for (byte key = 0; key < numKeys; key++)
                {
                    var unk1 = packet.ReadInt16();
                    var unk2 = packet.ReadInt32();
                    var unk3 = packet.ReadBytes(4);
                    var shaHash = packet.ReadBytes(20);
                    keys[key] = new AuthLogonKey(unk1, unk2, unk3, shaHash);
                }
            }

            SRPServer srpData = client.UserData.SRP;
            string username = client.UserData.Username;
            BigInteger rand = client.UserData.ReconnectRand;

            // TODO fetch this from the database (or some other persistent storage)
            //BigInteger sessionKey = null ?? new BigInteger(0);
            BigInteger hash = srpData.Hash(new HashDataBroker(Encoding.ASCII.GetBytes(username)), r1, rand);
            if (hash == r2)
            {
                SendReconnectProofSuccess(client);
                client.AddPermission(new AuthenticatedPermission());
            }
            else
                client.Disconnect();
        }
コード例 #5
0
        public static void HandleReconnectChallenge(IClient client, IncomingAuthPacket packet)
        {
            // structure is the same as AuthenticationLogOnChallenge
            Contract.Requires(client != null);
            Contract.Requires(packet != null);

            packet.ReadByte(); // unk
            packet.ReadInt16(); // size
            packet.ReadFourCC(); // gameName
            packet.ReadByte(); // version1
            packet.ReadByte(); // version2
            packet.ReadByte(); // version3
            packet.ReadInt16(); // build
            packet.ReadFourCC(); // platform
            packet.ReadFourCC(); // os
            packet.ReadFourCC(); // country
            packet.ReadInt32(); // timeZoneBias
            packet.ReadInt32(); // ip
            var usernameLength = packet.ReadByte();
            var usernameBytes = packet.ReadBytes(usernameLength);
            Encoding.ASCII.GetString(usernameBytes); // username

            // TODO fetch this from the database (or some other persistent storage)
            BigInteger sessionKey = null;
            if (sessionKey == null) {
                client.Disconnect();
                return;
            }

            //BigInteger rand = new BigInteger(new FastRandom(), 16 * 8);
            //SendReconnectChallengeSuccess(client, rand);
            //client.UserData.ReconnectRand = rand;
            //client.UserData.Username = username;
        }