Exemple #1
0
        public void SecureRemotePasswordConstructorTest3()
        {
            bool isServer = false; // TODO: 初始化为适当的值
            SecureRemotePassword target = new SecureRemotePassword(isServer);

            Assert.Inconclusive("TODO: 实现用来验证目标的代码");
        }
        private static void QueryAccountCallback(IAuthClient client, Account acct)
        {
            if (!client.IsConnected)
            {
                return;
            }

            var accName = client.AccountName;

            if (acct == null)
            {
                // Account doesn't exist yet -> Check for auto creation
                if (AuthServerConfiguration.AutocreateAccounts)
                {
                    if (!AccountMgr.NameValidator(ref accName))
                    {
                        OnLoginError(client, AccountStatus.InvalidInformation);
                        return;
                    }

                    // Fill in this client's info with the username they gave.
                    // We have to go through the authentication phase, and if
                    // the password ends up matching the username, we know it's
                    // an autocreation attempt.

                    var passHash = SecureRemotePassword.GenerateCredentialsHash(accName, accName);

                    client.Authenticator = new Authenticator(new SecureRemotePassword(accName, passHash, true));
                    SendAuthChallengeSuccessReply(client);
                }
                else
                {
                    OnLoginError(client, AccountStatus.InvalidInformation);
                }
            }
            else
            {
                // check if Account may be used
                if (acct.CheckActive())
                {
                    client.Account       = acct;
                    client.Authenticator = new Authenticator(new SecureRemotePassword(accName, acct.Password, true));
                    SendAuthChallengeSuccessReply(client);
                }
                else
                {
                    // Account has been deactivated
                    if (client.Account.StatusUntil == null)
                    {
                        // temporarily suspended
                        OnLoginError(client, AccountStatus.AccountBanned);
                    }
                    else
                    {
                        // deactivated
                        OnLoginError(client, AccountStatus.AccountFrozen);
                    }
                }
            }
        }
Exemple #3
0
        //internal class AuthLogonChallenge_Result
        //{
        //    public byte m_iCommand = (byte)RealmListOpCode.CMSG_AUTH_CHALLENGE_RESULT; // 0x00 CMD_AUTH_LOGON_CHALLENGE
        //    public byte m_iError = 0;		           // 0 - ok
        //    public byte m_iUnk = 0;		           // 0x00
        //    public byte[] m_iB = new byte[32];
        //    public byte m_iGLen = 1;		           // 0x01
        //    public byte[] m_iG = new byte[1];
        //    public byte m_iNLen = 32;		           // 0x20
        //    public byte[] m_iN = new byte[32];
        //    public byte[] m_iS = new byte[32];
        //    public byte[] m_iUnk2 = new byte[16];
        //    public byte m_iUnk3 = 0;
        //}

        /// <summary>
        /// 等于 AuthLogonChallenge_Result 结构
        /// </summary>
        public Auth_AuthChallengeResult(SecureRemotePassword srp)
            : base((long)AuthOpCode.CMSG_AUTH_CHALLENGE_RESULT, 0)
        {
            WriterStream.Write((byte)AuthOpCode.CMSG_AUTH_CHALLENGE_RESULT);
            WriterStream.Write((byte)LogineErrorInfo.LOGIN_SUCCESS);
            //////////////////////////////////////////////////////////////////////////

            WriterStream.Write((byte)0);

            WriterStream.Write(srp.PublicEphemeralValueB.GetBytes(32), 0, 32);

            WriterStream.Write((byte)1);
            WriterStream.Write(srp.Generator.GetBytes(1), 0, 1);

            WriterStream.Write((byte)32);
            WriterStream.Write(srp.Modulus.GetBytes(32), 0, 32);

            WriterStream.Write(srp.Salt.GetBytes(32), 0, 32);

            BigInteger unknown = new BigInteger();

            unknown.GenRandomBits(128 /* 16 * 8 */, new Random(10));     /* 随机数 16字节 */
            WriterStream.Write(unknown.GetBytes(16), 0, 16);

            WriterStream.Write((byte)0);
        }
Exemple #4
0
        public void RandomNumberTest()
        {
            BigInteger expected = null; // TODO: 初始化为适当的值
            BigInteger actual;

            actual = SecureRemotePassword.RandomNumber();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
Exemple #5
0
        public void SecureRemotePasswordConstructorTest4()
        {
            bool isServer = false;                                // TODO: 初始化为适当的值

            SecureRemotePassword.SRPParameters parameters = null; // TODO: 初始化为适当的值
            SecureRemotePassword target = new SecureRemotePassword(isServer, parameters);

            Assert.Inconclusive("TODO: 实现用来验证目标的代码");
        }
Exemple #6
0
        public void CredentialsTest()
        {
            bool isServer = false;                                            // TODO: 初始化为适当的值
            SecureRemotePassword target = new SecureRemotePassword(isServer); // TODO: 初始化为适当的值
            string actual;

            actual = target.Credentials;
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
Exemple #7
0
        public void IsServerTest()
        {
            bool isServer = false;                                            // TODO: 初始化为适当的值
            SecureRemotePassword target = new SecureRemotePassword(isServer); // TODO: 初始化为适当的值
            bool actual;

            actual = target.IsServer;
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
Exemple #8
0
        public void ScramblingParameterTest()
        {
            bool isServer = false;                                            // TODO: 初始化为适当的值
            SecureRemotePassword target = new SecureRemotePassword(isServer); // TODO: 初始化为适当的值
            BigInteger           actual;

            actual = target.ScramblingParameter;
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
Exemple #9
0
        public void SecureRemotePasswordConstructorTest1()
        {
            string               username = string.Empty; // TODO: 初始化为适当的值
            BigInteger           verifier = null;         // TODO: 初始化为适当的值
            BigInteger           salt     = null;         // TODO: 初始化为适当的值
            SecureRemotePassword target   = new SecureRemotePassword(username, verifier, salt);

            Assert.Inconclusive("TODO: 实现用来验证目标的代码");
        }
Exemple #10
0
        public void SessionKeyRawTest()
        {
            bool isServer = false;                                            // TODO: 初始化为适当的值
            SecureRemotePassword target = new SecureRemotePassword(isServer); // TODO: 初始化为适当的值
            BigInteger           actual;

            actual = target.SessionKeyRaw;
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
Exemple #11
0
        public void SecureRemotePasswordConstructorTest5()
        {
            bool   isServer             = false;        // TODO: 初始化为适当的值
            string username             = string.Empty; // TODO: 初始化为适当的值
            string password             = string.Empty; // TODO: 初始化为适当的值
            SecureRemotePassword target = new SecureRemotePassword(isServer, username, password);

            Assert.Inconclusive("TODO: 实现用来验证目标的代码");
        }
        private static void HandleLogonChallenge(IAuthClient client, IncomingAuthPacket packet)
        {
            packet.Position = 33;
            var username = packet.ReadPascalString();
            var passHash = SecureRemotePassword.GenerateCredentialsHash(username, "CHANGEME");

            client.Authenticator = new Authenticator(new SecureRemotePassword(username, passHash, true));

            SendLogonChallengeReply(client);
        }
Exemple #13
0
        /// <summary>
        /// Creates a game account.
        /// Make sure that the Account-name does not exist before calling this method.
        /// </summary>
        /// <param name="username">the username of the account</param>
        /// <param name="password">the plaintextpassword of the account</param>
        public Account CreateAccount(string username, string password,
                                     string email, string privLevel, ClientId clientId)
        {
            // Account-names are always upper case
            username = username.ToUpper();

            var passHash = SecureRemotePassword.GenerateCredentialsHash(username, password.ToUpper());

            return(CreateAccount(username, passHash, email, privLevel, clientId));
        }
Exemple #14
0
        public void InternalsToStringTest()
        {
            bool isServer = false;                                            // TODO: 初始化为适当的值
            SecureRemotePassword target = new SecureRemotePassword(isServer); // TODO: 初始化为适当的值
            string expected             = string.Empty;                       // TODO: 初始化为适当的值
            string actual;

            actual = target.InternalsToString();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
Exemple #15
0
        //internal class AuthLogonProof_Result
        //{
        //    public byte m_iCommand = 0;			       // 0x01 CMD_AUTH_LOGON_PROOF
        //    public byte m_iError = 0;
        //    public byte[] M2 = new byte[20];
        //    public uint m_iUnk = 0;
        //    public ushort m_iUnk2 = 0;
        //}

        /// <summary>
        /// 等于 AuthLogonProof_Result 结构
        /// </summary>
        public Auth_AuthProofResult(SecureRemotePassword srp)
            : base((long)AuthOpCode.CMSG_AUTH_PROOF_RESULT, 0)
        {
            WriterStream.Write((byte)AuthOpCode.CMSG_AUTH_PROOF_RESULT);
            WriterStream.Write((byte)LogineErrorInfo.LOGIN_SUCCESS);
            //////////////////////////////////////////////////////////////////////////

            WriterStream.Write(srp.ServerSessionKeyProof.GetBytes(20), 0, 20);

            WriterStream.Fill(0x0, 6);
        }
Exemple #16
0
 protected override void SetPassword(byte[] value)
 {
     if (_usernameByteCount == Byte.MinValue)
     {
         _usernameByteCount = (byte)Encoding.ASCII.GetByteCount(_username.ToUpper() + ":");
     }
     byte[] source = new byte[_usernameByteCount + value.Length];
     Encoding.ASCII.GetBytes(_username.ToUpper() + ":", 0, _username.Length + 1, source, 0);
     Buffer.BlockCopy(value, 0, source, _usernameByteCount, value.Length);
     _password = SecureRemotePassword.GenerateCredentialsHash(source);
 }
Exemple #17
0
        public void ParametersTest()
        {
            bool isServer = false;                                            // TODO: 初始化为适当的值
            SecureRemotePassword target = new SecureRemotePassword(isServer); // TODO: 初始化为适当的值

            SecureRemotePassword.SRPParameters expected = null;               // TODO: 初始化为适当的值
            SecureRemotePassword.SRPParameters actual;
            target.Parameters = expected;
            actual            = target.Parameters;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
Exemple #18
0
        public void VerifierTest()
        {
            bool isServer = false;                                              // TODO: 初始化为适当的值
            SecureRemotePassword target   = new SecureRemotePassword(isServer); // TODO: 初始化为适当的值
            BigInteger           expected = null;                               // TODO: 初始化为适当的值
            BigInteger           actual;

            target.Verifier = expected;
            actual          = target.Verifier;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
Exemple #19
0
        public void IsClientProofValidTest()
        {
            bool isServer = false;                                                  // TODO: 初始化为适当的值
            SecureRemotePassword target       = new SecureRemotePassword(isServer); // TODO: 初始化为适当的值
            BigInteger           client_proof = null;                               // TODO: 初始化为适当的值
            bool expected = false;                                                  // TODO: 初始化为适当的值
            bool actual;

            actual = target.IsClientProofValid(client_proof);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
Exemple #20
0
 /// <summary>
 /// Sets the password for this account and sends it to the Authserver to be saved.
 /// Blocking call. Make sure to call this from outside the Map-Thread.
 /// </summary>
 /// <returns>true if the e-mail address was set; false otherwise</returns>
 public bool SetPass(string oldPassStr, string passStr)
 {
     byte[] pass;
     if (oldPassStr != null)
     {
         pass = SecureRemotePassword.GenerateCredentialsHash(Name, passStr);
     }
     else
     {
         pass = null;
     }
     return(RealmServer.Instance.AuthClient.Channel.SetAccountPass(AccountId, oldPassStr, pass));
 }
Exemple #21
0
        public void HashTest()
        {
            bool isServer = false;                                            // TODO: 初始化为适当的值
            SecureRemotePassword target = new SecureRemotePassword(isServer); // TODO: 初始化为适当的值

            HashUtilities.HashDataBroker[] brokers = null;                    // TODO: 初始化为适当的值
            BigInteger expected = null;                                       // TODO: 初始化为适当的值
            BigInteger actual;

            actual = target.Hash(brokers);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
Exemple #22
0
                public override void Process(CmdTrigger <AuthServerCmdArgs> trigger)
                {
                    var pass = trigger.Text.NextWord();

                    if (pass.Length < SecureRemotePassword.MinPassLength)
                    {
                        trigger.Reply("Account password must at least be {0} characters long.", SecureRemotePassword.MinPassLength);
                    }
                    else if (pass.Length > SecureRemotePassword.MaxPassLength)
                    {
                        trigger.Reply("Account password length must not exceed {0} characters.", SecureRemotePassword.MaxPassLength);
                    }
                    else
                    {
                        trigger.Args.Account.Password = SecureRemotePassword.GenerateCredentialsHash(trigger.Args.Account.Name, pass);
                        trigger.Args.Account.SaveAndFlush();
                        trigger.Reply("Password has been changed.");
                    }
                }
Exemple #23
0
        private static void QueryAccountCallback(IAuthClient client, Account acct)
        {
            string accName = client.CurrentUser;

            if (acct == null)
            {
                if (AuthServerConfiguration.AutocreateAccounts)
                {
                    // Fill in this client's info with the username they gave.
                    // We have to go through the authentication phase, and if
                    // the password ends up matching the username, we know it's
                    // an autocreation attempt.

                    client.IsAutocreated = true;

                    var passHash = new BigInteger(SecureRemotePassword.GenerateCredentialsHash(accName, accName));

                    client.Authenticator = new Authenticator(new SecureRemotePassword(accName, passHash, true));
                    SendAuthChallengeSuccessReply(client);
                }
                else
                {
                    s_log.Debug(Resources.AccountNotFound, accName);

                    OnLoginError(client, AccountStatus.InvalidInformation);
                }
            }
            else
            {
                // check if Account may be used
                if (acct.Status != AccountStatus.Success)
                {
                    SendAuthChallengeErrorReply(client, acct.Status);
                }
                else
                {
                    client.Authenticator = new Authenticator(new SecureRemotePassword(accName, acct.Password, true));
                    acct.OnLogin(client);
                }
            }
        }
Exemple #24
0
        /// <summary>
        ///
        /// </summary>
        public Realm_RequestSessionResult(uint iSerial, WowAccount account, SecureRemotePassword srp)
            : base((long)RealmOpCode.CMSG_REQUEST_SESSION_RESULT, 0 /* ProcessNet.REALM_HEAD_SIZE + ? */)
        {
            WriterStream.Write((byte)RealmOpCode.CMSG_REQUEST_SESSION_RESULT);      // ×ֶαàºÅ
            WriterStream.Write((ushort)0);                                          // ×Ö¶ÎÊ£Óà´óС
            //////////////////////////////////////////////////////////////////////////

            WriterStream.Write((uint)iSerial);
            WriterStream.Write(true);       // ³É¹¦

            WriterStream.Write((uint)account.AccountGuid);
            WriterStream.Write((int)account.AccessLevel);
            WriterStream.Write((bool)account.IsTBC);

            byte[] byteSessionKey = srp.SessionKey.GetBytes(40);
            WriterStream.Write(byteSessionKey, 0, 40);

            //////////////////////////////////////////////////////////////////////////
            WriterStream.Seek(1, SeekOrigin.Begin);
            WriterStream.Write((ushort)(WriterStream.Length - ProcessNet.REALM_HEAD_SIZE));
        }
Exemple #25
0
        /// <summary>
        /// Validates the auth-info sent by the client.
        /// Called within the IO-Queue's Context
        /// </summary>
        /// <returns>The session key or null if authentication failed</returns>
        private static bool ValidateAuthentication(IRealmClient client, string accountName)
        {
            var authInfo = RealmServer.Instance.GetAuthenticationInfo(accountName);

            if (authInfo == null)
            {
                RealmServer.Instance.Error(client, Resources.FailedToRetrieveAccount, accountName);

                LoginHandler.SendAuthSessionErrorReply(client, LoginErrorCode.AUTH_FAILED);
            }
            else
            {
                try
                {
                    client.SessionKey = authInfo.SessionKey;
                    client.Info       = ClientInformation.Deserialize(authInfo.SystemInformation);

                    var srp = new SecureRemotePassword(accountName, authInfo.Verifier, authInfo.Salt);

                    BigInteger clientVerifier = srp.Hash(srp.Username, new byte[4], client.ClientSeed, RealmServer.Instance.AuthSeed, client.SessionKey);

                    if (clientVerifier != client.ClientDigest)
                    {
                        LoginHandler.SendAuthSessionErrorReply(client, LoginErrorCode.AUTH_FAILED);
                    }
                    else
                    {
                        return(true);
                    }
                }
                catch (Exception e)
                {
                    LogUtil.ErrorException(e, false, "Failed to validate authentication of Account " + accountName);
                    LoginHandler.SendAuthSessionErrorReply(client, LoginErrorCode.AUTH_FAILED);
                }
            }
            return(false);
        }
Exemple #26
0
        public bool SetAccountPass(long id, string oldPassStr, byte[] pass)
        {
            var acc = AccountMgr.GetAccount(id);

            if (acc != null)
            {
                if (oldPassStr != null)
                {
                    var oldPass = SecureRemotePassword.GenerateCredentialsHash(acc.Name, oldPassStr);
                    if (!oldPass.SequenceEqual(acc.Password))
                    {
                        return(false);
                    }
                }

                acc.Password = pass;

                AuthenticationServer.IOQueue.AddMessage(acc.SaveAndFlush);
                return(true);
            }

            return(false);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="netState"></param>
        /// <param name="packetReader"></param>
        public static void Realm_HandleRequestSession(NetState netState, PacketReader packetReader)
        {
            RealmExtendData extendData = netState.GetComponent <RealmExtendData>(RealmExtendData.COMPONENT_ID);

            if (extendData == null)
            {
                Debug.WriteLine("Realm_PacketHandlers.Realm_HandleRequestSession(...) - extendData == null error!");
                return;
            }

            if (extendData.IsLoggedIn == false)
            {
                Debug.WriteLine("Realm_PacketHandlers.Realm_HandleRequestSession(...) - extendData.IsLoggedIn == false error!");
                return;
            }

            uint   iSerial        = packetReader.ReadUInt32();
            string strAccountName = packetReader.ReadUTF8StringSafe();

            WowAccount wowAccount = WowAccountHandler.GetAccount(strAccountName);

            if (wowAccount == null)
            {
                netState.Send(new Realm_RequestSessionResultError(iSerial));
                return;
            }

            SecureRemotePassword srp = SrpHandler.GetSRP(strAccountName);

            if (srp == null)
            {
                netState.Send(new Realm_RequestSessionResultError(iSerial));
                return;
            }

            netState.Send(new Realm_RequestSessionResult(iSerial, wowAccount, srp));
        }
        public static void AuthSessionRequest(RealmClient client, RealmPacketIn packet)
        {
            packet.SkipBytes(8);
            string                   accName      = packet.ReadString();
            uint                     clientSeed   = packet.ReadUInt32();
            BigInteger               clientDigest = packet.ReadBigInteger(20);
            AuthenticationInfo       authInfo;
            SecureRemotePassword     srp;
            AuthenticationErrorCodes errorCode = AuthenticationErrorCodes.AuthFailed;

            client.Account = new Account(client, accName);

            if (!client.Account.Initialize())
            {
                errorCode = AuthenticationErrorCodes.UnknownAccount;

                goto sendErrorReply;
            }

            if (client.Server.RequestAuthenticationInfo(accName, out authInfo))
            {
                srp = new SecureRemotePassword(accName, authInfo.Verifier, new BigInteger(authInfo.Salt, 32));

                client.Account.SessionKey = authInfo.SessionKey;
                client.SystemInfo         = SystemInformation.Deserialize(authInfo.SystemInformation);
            }
            else
            {
                goto sendErrorReply;
            }

            BigInteger clientVerifier = srp.Hash(srp.Username, new byte[4], clientSeed, client.Server.AuthSeed,
                                                 client.Account.SessionKey);

            client.IsEncrypted = true;             // all packets from here on are encrypted, including the AuthSessionReplys

            if (clientVerifier == clientDigest)
            {
                AddonHandler.ReadAddOns(client, packet);

                client.Server.LoginAccount(client.Account.Username);

                if (AuthQueue.QueuedClients > 0 ||
                    client.Server.NumberOfClients > client.Server.Config.ServerCapacity)
                {
                    AuthQueue.EnqueueClient(client);

                    return;
                }

                SendAuthSessionSuccess(client);

                return;
            }
            else
            {
                goto sendErrorReply;
            }

sendErrorReply:
            SendAuthSessionErrorReply(client, errorCode);

            client.Disconnect();
        }
Exemple #29
0
		public static void AuthSessionRequest(RealmClient client, RealmPacketIn packet)
		{
			packet.SkipBytes(8);
			string accName = packet.ReadString();
			uint clientSeed = packet.ReadUInt32();
			BigInteger clientDigest = packet.ReadBigInteger(20);
			AuthenticationInfo authInfo;
			SecureRemotePassword srp;
			AuthenticationErrorCodes errorCode = AuthenticationErrorCodes.AuthFailed;

			client.Account = new Account(client, accName);

			if (!client.Account.Initialize())
			{
				errorCode = AuthenticationErrorCodes.UnknownAccount;

				goto sendErrorReply;
			}

			if (client.Server.RequestAuthenticationInfo(accName, out authInfo))
			{
				srp = new SecureRemotePassword(accName, authInfo.Verifier, new BigInteger(authInfo.Salt, 32));

				client.Account.SessionKey = authInfo.SessionKey;
				client.SystemInfo = SystemInformation.Deserialize(authInfo.SystemInformation);
			}
			else
			{
				goto sendErrorReply;
			}

			BigInteger clientVerifier = srp.Hash(srp.Username, new byte[4], clientSeed, client.Server.AuthSeed,
													client.Account.SessionKey);

			client.IsEncrypted = true; // all packets from here on are encrypted, including the AuthSessionReplys

			if (clientVerifier == clientDigest)
			{
                AddonHandler.ReadAddOns(client, packet);

				client.Server.LoginAccount(client.Account.Username);

				if (AuthQueue.QueuedClients > 0 ||
					client.Server.NumberOfClients > client.Server.Config.ServerCapacity)
				{
					AuthQueue.EnqueueClient(client);

					return;
				}

				SendAuthSessionSuccess(client);

				return;
			}
			else
			{
				goto sendErrorReply;
			}

		sendErrorReply:
			SendAuthSessionErrorReply(client, errorCode);

			client.Disconnect();
		}
Exemple #30
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="serial"></param>
 /// <param name="realm"></param>
 public static void AddSRP(string strAccountName, SecureRemotePassword srp)
 {
     s_SRPs.Add(strAccountName, srp);
 }
Exemple #31
0
 public void TestTest()
 {
     SecureRemotePassword.Test();
     Assert.Inconclusive("无法验证不返回值的方法。");
 }