/// <summary>
        /// Client passed login challenge and can be logged in
        /// </summary>
        /// <param name="client"></param>
        private static void LoginClient(IAuthClient client)
        {
            var acc = client.Account;

            if (acc == null)
            {
                //Resync accounts first
                AccountMgr.Instance.Resync();

                // Pass and username are identical so an Account can be auto-created
                // the corresponding check happened before
                s_log.Debug(resources.AutocreatingAccount, client.AccountName);

                if (AccountMgr.DoesAccountExist(client.AccountName))
                {
                    // account was already created
                    SendAuthProofErrorReply(client, AccountStatus.Failure);
                    return;
                }
                client.Account = acc = AutoCreateAccount(client);
            }

            var authInfo = new AuthenticationInfo
            {
                SessionKey        = client.Authenticator.SRP.SessionKey.GetBytes(40),
                Salt              = client.Authenticator.SRP.Salt.GetBytes(32),
                Verifier          = client.Authenticator.SRP.Verifier.GetBytes(),
                SystemInformation = ClientInformation.Serialize(client.Info)
            };

            client.Server.StoreAuthenticationInfo(client.AccountName, authInfo);

            acc.OnLogin(client);
            SendAuthProofSuccessReply(client);
        }
Exemple #2
0
        private static void AutocreateAccountCallback(IAuthClient client, Account acct)
        {
            if (acct == null)
            {
                OnLoginError(client, AccountStatus.InvalidInformation);

                return;
            }

            var authInfo = new AuthenticationInfo {
                SessionKey        = client.Authenticator.SRP.SessionKey.GetBytes(40),
                Salt              = client.Authenticator.SRP.Salt.GetBytes(32),
                Verifier          = client.Authenticator.SRP.Verifier.GetBytes(),
                SystemInformation = ClientInformation.Serialize(client.ClientInfo)
            };

            client.Server.StoreAuthenticationInfo(client.CurrentUser, authInfo);

            SendAuthProofSuccessReply(client);
        }
Exemple #3
0
        public static void AuthProofRequest(IAuthClient client, AuthPacketIn packet)
        {
            if (client.Authenticator == null)
            {
                client.Server.DisconnectClient(client);
            }
            else
            {
                if (client.Authenticator.IsClientProofValid(packet))
                {
                    if (client.IsAutocreated)
                    {
                        // Their stuff matched, which means they gave us the same password
                        // as their username, which is what must occur to autocreate. Create
                        // the account for them before proceeding.

                        s_log.Debug(Resources.AutocreatingAccount, client.CurrentUser);

                        string role;
                        if (IPAddress.IsLoopback(client.ClientAddress))
                        {
                            // local users get the highest role
                            role = RoleGroupInfo.HighestRole.Name;
                        }
                        else
                        {
                            // remote users get default role
                            role = AuthServerConfiguration.DefaultRole;
                        }

                        var acctCreateQuery = QueryFactory.CreateResultQuery(
                            () => AccountMgr.Instance.CreateAccount(
                                client.CurrentUser,
                                client.Authenticator.SRP.Credentials.GetBytes(20),
                                null,
                                role,
                                ClientId.Wotlk
                                ),
                            AutocreateAccountCallback,
                            client
                            );

                        client.Server.EnqueueTask(acctCreateQuery);
                    }
                    else
                    {
                        // The following was sent twice
                        var authInfo = new AuthenticationInfo {
                            SessionKey        = client.Authenticator.SRP.SessionKey.GetBytes(40),
                            Salt              = client.Authenticator.SRP.Salt.GetBytes(32),
                            Verifier          = client.Authenticator.SRP.Verifier.GetBytes(),
                            SystemInformation = ClientInformation.Serialize(client.ClientInfo)
                        };

                        client.Server.StoreAuthenticationInfo(client.CurrentUser, authInfo);

                        SendAuthProofSuccessReply(client);
                    }
                }
                else
                {
                    s_log.Debug(Resources.InvalidClientProof, client.CurrentUser);

                    OnLoginError(client, AccountStatus.InvalidInformation);
                }
            }
        }