Пример #1
0
        public static void Activate(UserLogin user, string phoneNumber)
        {
            Console.WriteLine("Activating 2FA for user \"{0}\" with phone number \"{1}\"", user.Username, phoneNumber);

            var auth = new AuthenticatorLinker(user.Session);

            auth.PhoneNumber = phoneNumber;

            var linkResult = auth.AddAuthenticator();

            Console.WriteLine("AddAuthenticator() returned \"{0}\"", linkResult);

            if (linkResult != AuthenticatorLinker.LinkResult.AwaitingFinalization)
            {
                return;
            }

            Console.WriteLine("Waiting for SMS code...");

            var finalizeResult = auth.FinalizeAddAuthenticator(Console.ReadLine());

            Console.WriteLine("FinalizeAddAuthenticator() returned \"{0}\"", finalizeResult);

            if (finalizeResult == AuthenticatorLinker.FinalizeResult.Success)
            {
                var steamGuard = auth.LinkedAccount;
                Console.WriteLine("SharedSecret = \"{0}\"", steamGuard.SharedSecret);
                Console.WriteLine("RevocationCode = \"{0}\"", steamGuard.RevocationCode);
            }
        }
        private void LoginBtn_Click(object sender, RoutedEventArgs e)
        {
            PhoneNum.IsTabStop    = SMSCode.IsTabStop = false;
            ErrorLabel.Visibility = LoginBtn.Visibility = Visibility.Collapsed;
            Progress.Visibility   = Visibility.Visible;
            PhoneNum.IsTabStop    = SMSCode.IsTabStop = true;

            if (PhoneNumGrid.Visibility == Visibility.Visible)
            {
                this.linker.PhoneNumber = FilterPhoneNumber(PhoneNum.Text);
                linker.AddAuthenticator(LinkResponse);
            }
            else if (RevocationGrid.Visibility == Visibility.Visible)
            {
                Progress.Visibility = RevocationGrid.Visibility = Visibility.Collapsed;
                LoginBtn.Visibility = SMSGrid.Visibility = Visibility.Visible;
            }
            else if (SMSGrid.Visibility == Visibility.Visible)
            {
                linker.FinalizeAddAuthenticator(async response =>
                {
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        FinaliseResponse(response);
                    });
                }, SMSCode.Text);
            }
        }
Пример #3
0
        static void Setup(string username = "", string passkey = "")
        {
            if (Verbose)
            {
                Console.WriteLine("Opening manifest...");
            }
            Manifest = Manifest.GetManifest(true);

            if (string.IsNullOrWhiteSpace(username))
            {
                Console.Write("Username: "******"Password: "******"Logging in {username}... ");
                LoginResult loginResult = login.DoLogin();
                Console.WriteLine(loginResult);
                if (loginResult == LoginResult.NeedEmail)
                {
                    Console.Write("Email code: ");
                    emailCode = Console.ReadLine();
                    continue;
                }
                else if (loginResult == LoginResult.Need2FA)
                {
                    Console.Write("2FA code: ");
                    twoFactorCode = Console.ReadLine();
                    continue;
                }
                if (!login.LoggedIn)
                {
                    return;
                }
                break;
            }

            AuthenticatorLinker linker = new AuthenticatorLinker(login.Session);

            AuthenticatorLinker.LinkResult linkResult = AuthenticatorLinker.LinkResult.GeneralFailure;

            do
            {
                linkResult = linker.AddAuthenticator();
                Console.WriteLine($"Link result: {linkResult}");
                switch (linkResult)
                {
                case AuthenticatorLinker.LinkResult.MustProvidePhoneNumber:
                    var phonenumber = "";
                    do
                    {
                        Console.WriteLine("Enter your mobile phone number in the following format: +{cC} phoneNumber. EG, +1 123-456-7890");
                        phonenumber        = Console.ReadLine();
                        phonenumber        = FilterPhoneNumber(phonenumber);
                        linker.PhoneNumber = phonenumber;
                    } while (!PhoneNumberOkay(phonenumber));
                    break;

                case AuthenticatorLinker.LinkResult.MustRemovePhoneNumber:
                    linker.PhoneNumber = null;
                    break;

                case AuthenticatorLinker.LinkResult.AwaitingFinalization:
                    break;

                case AuthenticatorLinker.LinkResult.GeneralFailure:
                    Console.WriteLine("error: Unable to add your phone number. Steam returned GeneralFailure");
                    return;

                case AuthenticatorLinker.LinkResult.AuthenticatorPresent:
                    Console.WriteLine("An authenticator is already present.");
                    Console.WriteLine("If you have the revocation code (Rxxxxx), this program can remove it for you.");
                    Console.Write("Would you like to remove the current authenticator using your revocation code? (y/n) ");
                    var answer = Console.ReadLine();
                    if (answer != "y")
                    {
                        continue;
                    }
                    Console.Write("Revocation code (Rxxxxx): ");
                    var revocationCode = Console.ReadLine();
                    var account        = new SteamGuardAccount();
                    account.Session        = login.Session;
                    account.RevocationCode = revocationCode;
                    if (account.DeactivateAuthenticator())
                    {
                        Console.WriteLine("Successfully deactivated the current authenticator.");
                    }
                    else
                    {
                        Console.WriteLine("Deactivating the current authenticator was unsuccessful.");
                    }
                    continue;

                default:
                    Console.WriteLine($"error: Unexpected linker result: {linkResult}");
                    return;
                }
            } while (linkResult != AuthenticatorLinker.LinkResult.AwaitingFinalization);

            string passKey = null;

            if (Manifest.Entries.Count == 0)
            {
                Console.WriteLine("Looks like we are setting up your first account.");
                passKey = Manifest.PromptSetupPassKey(true);
            }
            else if (Manifest.Entries.Count > 0 && Manifest.Encrypted)
            {
                if (string.IsNullOrEmpty(passkey))
                {
                    passkey = Manifest.PromptForPassKey();
                }
            }

            //Save the file immediately; losing this would be bad.
            if (!Manifest.SaveAccount(linker.LinkedAccount, passKey != null, passKey))
            {
                Manifest.RemoveAccount(linker.LinkedAccount);
                Console.WriteLine("Unable to save mobile authenticator file. The mobile authenticator has not been linked.");
                return;
            }

            Console.WriteLine(
                $"The Mobile Authenticator has not yet been linked. Before finalizing the authenticator, please write down your revocation code: {linker.LinkedAccount.RevocationCode}");

            AuthenticatorLinker.FinalizeResult finalizeResponse = AuthenticatorLinker.FinalizeResult.GeneralFailure;
            do
            {
                Console.Write("Please input the SMS message sent to your phone number: ");
                string smsCode = Console.ReadLine();

                finalizeResponse = linker.FinalizeAddAuthenticator(smsCode);
                if (Verbose)
                {
                    Console.WriteLine(finalizeResponse);
                }

                switch (finalizeResponse)
                {
                case AuthenticatorLinker.FinalizeResult.BadSMSCode:
                    continue;

                case AuthenticatorLinker.FinalizeResult.UnableToGenerateCorrectCodes:
                    Console.WriteLine(
                        "Unable to generate the proper codes to finalize this authenticator. The authenticator should not have been linked.");
                    Console.WriteLine(
                        $"In the off-chance it was, please write down your revocation code, as this is the last chance to see it: {linker.LinkedAccount.RevocationCode}");
                    Manifest.RemoveAccount(linker.LinkedAccount);
                    return;

                case AuthenticatorLinker.FinalizeResult.GeneralFailure:
                    Console.WriteLine("Unable to finalize this authenticator. The authenticator should not have been linked.");
                    Console.WriteLine(
                        $"In the off-chance it was, please write down your revocation code, as this is the last chance to see it: {linker.LinkedAccount.RevocationCode}");
                    Manifest.RemoveAccount(linker.LinkedAccount);
                    return;
                }
            } while (finalizeResponse != AuthenticatorLinker.FinalizeResult.Success);

            //Linked, finally. Re-save with FullyEnrolled property.
            Manifest.SaveAccount(linker.LinkedAccount, passKey != null, passKey);
            Console.WriteLine(
                $"Mobile authenticator successfully linked. Please actually write down your revocation code: {linker.LinkedAccount.RevocationCode}");
        }
Пример #4
0
        static void Main(string[] args)
        {
            //This basic loop will log into user accounts you specify, enable the mobile authenticator, and save a maFile (mobile authenticator file)
            while (true)
            {
                Console.WriteLine("Enter user/password: "******"Please enter your email code: ");
                        string code = Console.ReadLine();
                        login.EmailCode = code;
                        break;

                    case LoginResult.NeedCaptcha:
                        System.Diagnostics.Process.Start(APIEndpoints.COMMUNITY_BASE + "/public/captcha.php?gid=" + login.CaptchaGID);     //Open a web browser to the captcha image
                        Console.WriteLine("Please enter captcha text: ");
                        string captchaText = Console.ReadLine();
                        login.CaptchaText = captchaText;
                        break;

                    case LoginResult.Need2FA:
                        Console.WriteLine("Please enter your mobile authenticator code: ");
                        code = Console.ReadLine();
                        login.TwoFactorCode = code;
                        break;
                    }
                }

                AuthenticatorLinker linker = new AuthenticatorLinker(login.Session);
                linker.PhoneNumber = null; //Set this to non-null to add a new phone number to the account.
                var result = linker.AddAuthenticator();

                if (result != AuthenticatorLinker.LinkResult.AwaitingFinalization)
                {
                    Console.WriteLine("Failed to add authenticator: " + result);
                    continue;
                }

                try
                {
                    string sgFile   = JsonConvert.SerializeObject(linker.LinkedAccount, Formatting.Indented);
                    string fileName = linker.LinkedAccount.AccountName + ".maFile";
                    File.WriteAllText(fileName, sgFile);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    Console.WriteLine("EXCEPTION saving maFile. For security, authenticator will not be finalized.");
                    continue;
                }

                Console.WriteLine("Please enter SMS code: ");
                string smsCode    = Console.ReadLine();
                var    linkResult = linker.FinalizeAddAuthenticator(smsCode);

                if (linkResult != AuthenticatorLinker.FinalizeResult.Success)
                {
                    Console.WriteLine("Unable to finalize authenticator: " + linkResult);
                }
            }
        }
Пример #5
0
        private void btnSteamLogin_Click(object sender, EventArgs e)
        {
            string username = txtUsername.Text;
            string password = txtPassword.Text;

            if (LoginReason == LoginType.Refresh)
            {
                RefreshLogin(username, password);
                return;
            }

            var         userLogin = new UserLogin(username, password);
            LoginResult response  = LoginResult.BadCredentials;

            while ((response = userLogin.DoLogin()) != LoginResult.LoginOkay)
            {
                switch (response)
                {
                case LoginResult.NeedEmail:
                    InputForm emailForm = new InputForm("Enter the code sent to your email:");
                    emailForm.ShowDialog();
                    if (emailForm.Canceled)
                    {
                        this.Close();
                        return;
                    }

                    userLogin.EmailCode = emailForm.txtBox.Text;
                    break;

                case LoginResult.NeedCaptcha:
                    CaptchaForm captchaForm = new CaptchaForm(userLogin.CaptchaGID);
                    captchaForm.ShowDialog();
                    if (captchaForm.Canceled)
                    {
                        this.Close();
                        return;
                    }

                    userLogin.CaptchaText = captchaForm.CaptchaCode;
                    break;

                case LoginResult.Need2FA:
                    MessageBox.Show("此帐户已经有一个与其绑定的移动身份验证器。在添入新的验证器之前,请把您的Steam帐户从旧的验证器中删除。", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;

                case LoginResult.BadRSA:
                    MessageBox.Show("错误记录:Steam返回“BadRSA”。", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;

                case LoginResult.BadCredentials:
                    MessageBox.Show("错误记录:用户名或密码不正确。", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;

                case LoginResult.TooManyFailedLogins:
                    MessageBox.Show("错误记录:太多次失败的登录,稍后再试。", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;

                case LoginResult.GeneralFailure:
                    MessageBox.Show("错误记录:Steam返回“GeneralFailure”。", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;
                }
            }

            //Login succeeded

            SessionData         session = userLogin.Session;
            AuthenticatorLinker linker  = new AuthenticatorLinker(session);

            AuthenticatorLinker.LinkResult linkResponse = AuthenticatorLinker.LinkResult.GeneralFailure;

            while ((linkResponse = linker.AddAuthenticator()) != AuthenticatorLinker.LinkResult.AwaitingFinalization)
            {
                switch (linkResponse)
                {
                case AuthenticatorLinker.LinkResult.MustProvidePhoneNumber:
                    string phoneNumber = "";
                    while (!PhoneNumberOkay(phoneNumber))
                    {
                        InputForm phoneNumberForm = new InputForm("以下列格式输入您的电话号码:+{区号}电话号码。+86 12345678910");
                        phoneNumberForm.txtBox.Text = "+1 ";
                        phoneNumberForm.ShowDialog();
                        if (phoneNumberForm.Canceled)
                        {
                            this.Close();
                            return;
                        }

                        phoneNumber = FilterPhoneNumber(phoneNumberForm.txtBox.Text);
                    }
                    linker.PhoneNumber = phoneNumber;
                    break;

                case AuthenticatorLinker.LinkResult.MustRemovePhoneNumber:
                    linker.PhoneNumber = null;
                    break;

                case AuthenticatorLinker.LinkResult.MustConfirmEmail:
                    MessageBox.Show("Steam会先发一封确认添加手机号码的邮件,请先去点击邮件中的添加手机号码按钮,然后点击确认。");
                    break;

                case AuthenticatorLinker.LinkResult.GeneralFailure:
                    MessageBox.Show("添加电话号码时出错。Steam返回“GeneralFailure”。");
                    this.Close();
                    return;
                }
            }

            Manifest manifest = Manifest.GetManifest();
            string   passKey  = null;

            if (manifest.Entries.Count == 0)
            {
                passKey = manifest.PromptSetupPassKey("请输入加密密码。留下空白或点击取消不加密都非常不安全。");
            }
            else if (manifest.Entries.Count > 0 && manifest.Encrypted)
            {
                bool passKeyValid = false;
                while (!passKeyValid)
                {
                    InputForm passKeyForm = new InputForm("请输入您当前的加密密码。");
                    passKeyForm.ShowDialog();
                    if (!passKeyForm.Canceled)
                    {
                        passKey      = passKeyForm.txtBox.Text;
                        passKeyValid = manifest.VerifyPasskey(passKey);
                        if (!passKeyValid)
                        {
                            MessageBox.Show("此密码无效。请输入您用于其他帐户的密码。");
                        }
                    }
                    else
                    {
                        this.Close();
                        return;
                    }
                }
            }

            //Save the file immediately; losing this would be bad.
            if (!manifest.SaveAccount(linker.LinkedAccount, passKey != null, passKey))
            {
                manifest.RemoveAccount(linker.LinkedAccount);
                MessageBox.Show("无法保存移动身份验证器文件。 移动身份验证器尚未连接。");
                this.Close();
                return;
            }

            MessageBox.Show("移动身份验证器尚未连接。 在最终确认使用桌面验证器之前,请写下您的撤销代码:" + linker.LinkedAccount.RevocationCode);

            AuthenticatorLinker.FinalizeResult finalizeResponse = AuthenticatorLinker.FinalizeResult.GeneralFailure;
            while (finalizeResponse != AuthenticatorLinker.FinalizeResult.Success)
            {
                InputForm smsCodeForm = new InputForm("请输入发送到您手机的短信代码。");
                smsCodeForm.ShowDialog();
                if (smsCodeForm.Canceled)
                {
                    manifest.RemoveAccount(linker.LinkedAccount);
                    this.Close();
                    return;
                }

                InputForm confirmRevocationCode = new InputForm("请输入您的撤销代码,以确保您已保存它。");
                confirmRevocationCode.ShowDialog();
                if (confirmRevocationCode.txtBox.Text.ToUpper() != linker.LinkedAccount.RevocationCode)
                {
                    MessageBox.Show("撤销代码不正确;无法连接桌面验证器。");
                    manifest.RemoveAccount(linker.LinkedAccount);
                    this.Close();
                    return;
                }

                string smsCode = smsCodeForm.txtBox.Text;
                finalizeResponse = linker.FinalizeAddAuthenticator(smsCode);

                switch (finalizeResponse)
                {
                case AuthenticatorLinker.FinalizeResult.BadSMSCode:
                    continue;

                case AuthenticatorLinker.FinalizeResult.UnableToGenerateCorrectCodes:
                    MessageBox.Show("无法生成正确的代码来完成此身份验证器。 验证器没有被连接。 应该是偶发状况,请写下你的撤销代码,因为这是最后一次看到它的机会:" + linker.LinkedAccount.RevocationCode);
                    manifest.RemoveAccount(linker.LinkedAccount);
                    this.Close();
                    return;

                case AuthenticatorLinker.FinalizeResult.GeneralFailure:
                    MessageBox.Show("无法生成正确的代码来完成此身份验证器。 验证器没有被连接。 应该是偶发状况,请写下你的撤销代码,因为这是最后一次看到它的机会:" + linker.LinkedAccount.RevocationCode);
                    manifest.RemoveAccount(linker.LinkedAccount);
                    this.Close();
                    return;
                }
            }

            //Linked, finally. Re-save with FullyEnrolled property.
            manifest.SaveAccount(linker.LinkedAccount, passKey != null, passKey);
            MessageBox.Show("成功连接移动验证器。 请写下你的撤销代码:" + linker.LinkedAccount.RevocationCode);
            this.Close();
        }
Пример #6
0
        private void btnSteamLogin_Click(object sender, EventArgs e)
        {
            string username = txtUsername.Text;
            string password = txtPassword.Text;

            if (LoginReason == LoginType.Android)
            {
                FinishExtract(username, password);
                return;
            }
            else if (LoginReason == LoginType.Refresh)
            {
                RefreshLogin(username, password);
                return;
            }

            var         userLogin = new UserLogin(username, password);
            LoginResult response  = LoginResult.BadCredentials;

            while ((response = userLogin.DoLogin()) != LoginResult.LoginOkay)
            {
                switch (response)
                {
                case LoginResult.NeedEmail:
                    InputForm emailForm = new InputForm("Enter the code sent to your email:");
                    emailForm.ShowDialog();
                    if (emailForm.Canceled)
                    {
                        this.Close();
                        return;
                    }

                    userLogin.EmailCode = emailForm.txtBox.Text;
                    break;

                case LoginResult.NeedCaptcha:
                    CaptchaForm captchaForm = new CaptchaForm(userLogin.CaptchaGID);
                    captchaForm.ShowDialog();
                    if (captchaForm.Canceled)
                    {
                        this.Close();
                        return;
                    }

                    userLogin.CaptchaText = captchaForm.CaptchaCode;
                    break;

                case LoginResult.Need2FA:
                    MessageBox.Show("This account already has a mobile authenticator linked to it.\nRemove the old authenticator from your Steam account before adding a new one.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;

                case LoginResult.BadRSA:
                    MessageBox.Show("Error logging in: Steam returned \"BadRSA\".", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;

                case LoginResult.BadCredentials:
                    MessageBox.Show("Error logging in: Username or password was incorrect.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;

                case LoginResult.TooManyFailedLogins:
                    MessageBox.Show("Error logging in: Too many failed logins, try again later.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;

                case LoginResult.GeneralFailure:
                    MessageBox.Show("Error logging in: Steam returned \"GeneralFailure\".", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;
                }
            }

            //Login succeeded

            SessionData         session = userLogin.Session;
            AuthenticatorLinker linker  = new AuthenticatorLinker(session);

            AuthenticatorLinker.LinkResult linkResponse = AuthenticatorLinker.LinkResult.GeneralFailure;

            while ((linkResponse = linker.AddAuthenticator()) != AuthenticatorLinker.LinkResult.AwaitingFinalization)
            {
                switch (linkResponse)
                {
                case AuthenticatorLinker.LinkResult.MustProvidePhoneNumber:
                    string phoneNumber = "";
                    while (!PhoneNumberOkay(phoneNumber))
                    {
                        InputForm phoneNumberForm = new InputForm("Enter your phone number in the following format: +{cC} phoneNumber. EG, +1 123-456-7890");
                        phoneNumberForm.txtBox.Text = "+1 ";
                        phoneNumberForm.ShowDialog();
                        if (phoneNumberForm.Canceled)
                        {
                            this.Close();
                            return;
                        }

                        phoneNumber = FilterPhoneNumber(phoneNumberForm.txtBox.Text);
                    }
                    linker.PhoneNumber = phoneNumber;
                    break;

                case AuthenticatorLinker.LinkResult.MustRemovePhoneNumber:
                    linker.PhoneNumber = null;
                    break;

                case AuthenticatorLinker.LinkResult.GeneralFailure:
                    MessageBox.Show("Error adding your phone number. Steam returned \"GeneralFailure\".");
                    this.Close();
                    return;
                }
            }

            Manifest manifest = Manifest.GetManifest();
            string   passKey  = null;

            if (manifest.Entries.Count == 0)
            {
                passKey = manifest.PromptSetupPassKey("Please enter an encryption passkey. Leave blank or hit cancel to not encrypt (VERY INSECURE).");
            }
            else if (manifest.Entries.Count > 0 && manifest.Encrypted)
            {
                bool passKeyValid = false;
                while (!passKeyValid)
                {
                    InputForm passKeyForm = new InputForm("Please enter your current encryption passkey.");
                    passKeyForm.ShowDialog();
                    if (!passKeyForm.Canceled)
                    {
                        passKey      = passKeyForm.txtBox.Text;
                        passKeyValid = manifest.VerifyPasskey(passKey);
                        if (!passKeyValid)
                        {
                            MessageBox.Show("That passkey is invalid. Please enter the same passkey you used for your other accounts.");
                        }
                    }
                    else
                    {
                        this.Close();
                        return;
                    }
                }
            }

            //Save the file immediately; losing this would be bad.
            if (!manifest.SaveAccount(linker.LinkedAccount, passKey != null, passKey))
            {
                manifest.RemoveAccount(linker.LinkedAccount);
                MessageBox.Show("Unable to save mobile authenticator file. The mobile authenticator has not been linked.");
                this.Close();
                return;
            }

            MessageBox.Show("The Mobile Authenticator has not yet been linked. Before finalizing the authenticator, please write down your revocation code: " + linker.LinkedAccount.RevocationCode);

            AuthenticatorLinker.FinalizeResult finalizeResponse = AuthenticatorLinker.FinalizeResult.GeneralFailure;
            while (finalizeResponse != AuthenticatorLinker.FinalizeResult.Success)
            {
                InputForm smsCodeForm = new InputForm("Please input the SMS code sent to your phone.");
                smsCodeForm.ShowDialog();
                if (smsCodeForm.Canceled)
                {
                    manifest.RemoveAccount(linker.LinkedAccount);
                    this.Close();
                    return;
                }

                InputForm confirmRevocationCode = new InputForm("Please enter your revocation code to ensure you've saved it.");
                confirmRevocationCode.ShowDialog();
                if (confirmRevocationCode.txtBox.Text.ToUpper() != linker.LinkedAccount.RevocationCode)
                {
                    MessageBox.Show("Revocation code incorrect; the authenticator has not been linked.");
                    manifest.RemoveAccount(linker.LinkedAccount);
                    this.Close();
                    return;
                }

                string smsCode = smsCodeForm.txtBox.Text;
                finalizeResponse = linker.FinalizeAddAuthenticator(smsCode);

                switch (finalizeResponse)
                {
                case AuthenticatorLinker.FinalizeResult.BadSMSCode:
                    continue;

                case AuthenticatorLinker.FinalizeResult.UnableToGenerateCorrectCodes:
                    MessageBox.Show("Unable to generate the proper codes to finalize this authenticator. The authenticator should not have been linked. In the off-chance it was, please write down your revocation code, as this is the last chance to see it: " + linker.LinkedAccount.RevocationCode);
                    manifest.RemoveAccount(linker.LinkedAccount);
                    this.Close();
                    return;

                case AuthenticatorLinker.FinalizeResult.GeneralFailure:
                    MessageBox.Show("Unable to finalize this authenticator. The authenticator should not have been linked. In the off-chance it was, please write down your revocation code, as this is the last chance to see it: " + linker.LinkedAccount.RevocationCode);
                    manifest.RemoveAccount(linker.LinkedAccount);
                    this.Close();
                    return;
                }
            }

            //Linked, finally. Re-save with FullyEnrolled property.
            manifest.SaveAccount(linker.LinkedAccount, passKey != null, passKey);
            MessageBox.Show("Mobile authenticator successfully linked. Please write down your revocation code: " + linker.LinkedAccount.RevocationCode);
            this.Close();
        }
Пример #7
0
        private void SteamAuthLogin()
        {
            var         authLogin = new UserLogin(cfg.SteamLogin, cfg.SteamPassword);
            LoginResult result;

            do
            {
                result = authLogin.DoLogin();
                switch (result)
                {
                case LoginResult.NeedEmail:
                    Console.Write("An email was sent to this account's address, please enter the code here to continue: ");
                    authLogin.EmailCode = Console.ReadLine();
                    break;

                case LoginResult.NeedCaptcha:
                    Console.WriteLine("https://steamcommunity.com/public/captcha.php?gid=" + authLogin.CaptchaGID);
                    Console.Write("Please enter the captcha that just opened up on your default browser: ");
                    authLogin.CaptchaText = Console.ReadLine();
                    break;

                case LoginResult.Need2FA:
                    Console.Write("Please enter in your authenticator code: ");
                    authLogin.TwoFactorCode = Console.ReadLine();
                    break;

                default:
                    throw new Exception("Case was not accounted for. Case: " + result);
                }
            } while (result != LoginResult.LoginOkay);

            AuthenticatorLinker linker = new AuthenticatorLinker(authLogin.Session);

            Console.Write("Please enter the number you wish to associate this account in the format +1XXXXXXXXXX where +1 is your country code, leave blank if no new number is desired: ");

            string phoneNumber = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(phoneNumber))
            {
                phoneNumber = null;
            }
            linker.PhoneNumber = phoneNumber;

            AuthenticatorLinker.LinkResult linkResult = linker.AddAuthenticator();
            if (linkResult != AuthenticatorLinker.LinkResult.AwaitingFinalization)
            {
                Console.WriteLine("Could not add authenticator: " + linkResult);
                Console.WriteLine(
                    "If you attempted to link an already linked account, please tell FatherFoxxy to get off his ass and implement the new stuff.");
                return;
            }

            if (!SaveMobileAuth(linker))
            {
                Console.WriteLine("Issue saving auth file, link operation abandoned.");
                return;
            }

            Console.WriteLine(
                "You should have received an SMS code, please input it here. If the code does not arrive, please input a blank line to abandon the operation.");
            AuthenticatorLinker.FinalizeResult finalizeResult;
            do
            {
                Console.Write("SMS Code: ");
                string smsCode = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(smsCode))
                {
                    return;
                }
                finalizeResult = linker.FinalizeAddAuthenticator(smsCode);
            } while (finalizeResult != AuthenticatorLinker.FinalizeResult.BadSMSCode);
        }
 public void FinalizeAddAuthenticator(string smsCode)
 {
     App.Logger.Info($"AuthWrapper.FinalizeAddAuthenticator...");
     AuthenticatorLinker.FinalizeResult result = _linker.FinalizeAddAuthenticator(smsCode);
     AuthFinalizeEvent?.Invoke(this, new AuthFinalizeEventArgs(result));
 }
Пример #9
0
        private void LoginUser()
        {
            string       username = txtUsername.Text;
            SecureString password = txtPassword.SecurePassword;

            if (LoginReason == LoginType.Android)
            {
                FinishExtract(username, password);
                return;
            }
            else if (LoginReason == LoginType.Refresh)
            {
                RefreshLogin(username, password);
                return;
            }

            var         userLogin = new UserLogin(username, password);
            LoginResult response  = LoginResult.BadCredentials;

            while ((response = userLogin.DoLogin()) != LoginResult.LoginOkay)
            {
                switch (response)
                {
                case LoginResult.NeedEmail:
                    InputForm emailForm = new InputForm(Properties.strings.LoginEnterEmailCode);
                    emailForm.ShowDialog(this);
                    if (emailForm.Canceled)
                    {
                        Close();
                        return;
                    }

                    userLogin.EmailCode = emailForm.txtBox.Text;
                    break;


                case LoginResult.NeedCaptcha:
                    Captcha captchaForm = new Captcha(userLogin.CaptchaGID);
                    captchaForm.ShowDialog();
                    if (captchaForm.Canceled)
                    {
                        Close();
                        return;
                    }

                    userLogin.CaptchaText = captchaForm.Code;
                    break;

                case LoginResult.Need2FA:
                    MessageBox.Show(Properties.strings.LoginAleadLinked, Properties.strings.LoginErrorT, MessageBoxButton.OK, MessageBoxImage.Error);
                    Close();
                    return;

                case LoginResult.BadRSA:
                    MessageBox.Show(Properties.strings.LoginBadRSA, Properties.strings.LoginErrorT, MessageBoxButton.OK, MessageBoxImage.Error);
                    Close();
                    return;

                case LoginResult.BadCredentials:
                    MessageBox.Show(Properties.strings.LoginBadCreds, Properties.strings.LoginErrorT, MessageBoxButton.OK, MessageBoxImage.Error);
                    Close();
                    return;

                case LoginResult.TooManyFailedLogins:
                    MessageBox.Show(Properties.strings.LoginTooManyFailedAttempts, Properties.strings.LoginErrorT, MessageBoxButton.OK, MessageBoxImage.Error);
                    Close();
                    return;

                case LoginResult.GeneralFailure:
                    MessageBox.Show(Properties.strings.LoginGeneralFailure, Properties.strings.LoginErrorT, MessageBoxButton.OK, MessageBoxImage.Error);
                    Close();
                    return;
                }
            }

            //Login succeeded

            SessionData         session = userLogin.Session;
            AuthenticatorLinker linker  = new AuthenticatorLinker(session);

            AuthenticatorLinker.LinkResult linkResponse = AuthenticatorLinker.LinkResult.GeneralFailure;

            while ((linkResponse = linker.AddAuthenticator()) != AuthenticatorLinker.LinkResult.AwaitingFinalization)
            {
                switch (linkResponse)
                {
                case AuthenticatorLinker.LinkResult.MustProvidePhoneNumber:
                    string phoneNumber = "";
                    while (!PhoneNumberOkay(phoneNumber))
                    {
                        InputForm phoneNumberForm = new InputForm(Properties.strings.LoginEnterPhoneNumber);
                        phoneNumberForm.txtBox.Text = "+1 ";
                        phoneNumberForm.ShowDialog(this);
                        if (phoneNumberForm.Canceled)
                        {
                            Close();
                            return;
                        }

                        phoneNumber = FilterPhoneNumber(phoneNumberForm.txtBox.Text);
                    }
                    linker.PhoneNumber = phoneNumber;
                    break;

                case AuthenticatorLinker.LinkResult.MustRemovePhoneNumber:
                    linker.PhoneNumber = null;
                    break;

                case AuthenticatorLinker.LinkResult.GeneralFailure:
                    MessageBox.Show(Properties.strings.LoginErrorAddingNumber);
                    Close();
                    return;
                }
            }

            Manifest     manifest = Manifest.GetManifest();
            SecureString passKey  = null;

            if (manifest.Entries.Count == 0)
            {
                passKey = manifest.PromptSetupPasskey(Properties.strings.LoginEnterPasskey);
            }
            else if (manifest.Entries.Count > 0 && manifest.Encrypted)
            {
                bool passKeyValid = false;
                while (!passKeyValid)
                {
                    InputForm passKeyForm = new InputForm(Properties.strings.ManifestEnterKey, true);
                    passKeyForm.ShowDialog(this);
                    if (!passKeyForm.Canceled)
                    {
                        passKey      = passKeyForm.GetPassword();
                        passKeyValid = manifest.VerifyPasskey(passKey);
                        if (!passKeyValid)
                        {
                            MessageBox.Show(Properties.strings.LoginInvaildPasskey);
                        }
                    }
                    else
                    {
                        Close();
                        return;
                    }
                }
            }

            //Save the file immediately; losing this would be bad.
            if (!manifest.SaveAccount(linker.LinkedAccount, passKey != null, passKey))
            {
                manifest.RemoveAccount(linker.LinkedAccount);
                MessageBox.Show(Properties.strings.LoginUnableToSaveFile);
                Close();
                return;
            }

            MessageBox.Show(String.Format(Properties.strings.LoginWriteRevocation, linker.LinkedAccount.RevocationCode));

            AuthenticatorLinker.FinalizeResult finalizeResponse = AuthenticatorLinker.FinalizeResult.GeneralFailure;
            while (finalizeResponse != AuthenticatorLinker.FinalizeResult.Success)
            {
                InputForm smsCodeForm = new InputForm(Properties.strings.LoginEnterSMS);
                smsCodeForm.ShowDialog(this);
                if (smsCodeForm.Canceled)
                {
                    manifest.RemoveAccount(linker.LinkedAccount);
                    Close();
                    return;
                }

                InputForm confirmRevocationCode = new InputForm(Properties.strings.LoginEnterRevocation);
                confirmRevocationCode.ShowDialog(this);
                if (confirmRevocationCode.txtBox.Text.ToUpper() != linker.LinkedAccount.RevocationCode)
                {
                    MessageBox.Show(Properties.strings.LoginRevocationIncorrect);
                    manifest.RemoveAccount(linker.LinkedAccount);
                    Close();
                    return;
                }

                string smsCode = smsCodeForm.txtBox.Text;
                finalizeResponse = linker.FinalizeAddAuthenticator(smsCode);

                switch (finalizeResponse)
                {
                case AuthenticatorLinker.FinalizeResult.BadSMSCode:
                    continue;

                case AuthenticatorLinker.FinalizeResult.UnableToGenerateCorrectCodes:
                    MessageBox.Show(String.Format(Properties.strings.LoginUnableToGenerateCodes, linker.LinkedAccount.RevocationCode));
                    manifest.RemoveAccount(linker.LinkedAccount);
                    Close();
                    return;

                case AuthenticatorLinker.FinalizeResult.GeneralFailure:
                    MessageBox.Show(String.Format(Properties.strings.LoginUnableToFinalize, linker.LinkedAccount.RevocationCode));
                    manifest.RemoveAccount(linker.LinkedAccount);
                    Close();
                    return;
                }
            }

            //Linked, finally. Re-save with FullyEnrolled property.
            manifest.SaveAccount(linker.LinkedAccount, passKey != null, passKey);
            MessageBox.Show(String.Format(Properties.strings.LoginSuccessfulAdd, linker.LinkedAccount.RevocationCode));
            Close();
        }
Пример #10
0
        /// <summary>
        /// Login button
        /// </summary>
        private void loginButton_Click(object sender, EventArgs e)
        {
            string susername = usernameText.Text;
            string spassword = passwordText.Text;

            if (susername.Length > 0 && spassword.Length > 0)
            {
                userLogin = new UserLogin(susername, spassword);
                LoginResult loginres = LoginResult.BadCredentials;

                while ((loginres = userLogin.DoLogin()) != LoginResult.LoginOkay)
                {
                    /*We need to enter the email code to access the account*/
                    if (loginres == LoginResult.NeedEmail)
                    {
                        InputForm emailForm = new InputForm("Enter the code sent to the email account associated with the account.");
                        emailForm.ShowDialog();
                        if (emailForm.inputCancelled)
                        {
                            Close();
                            return;
                        }

                        userLogin.EmailCode = emailForm.inputText.Text;
                        continue;
                    }

                    /*We need the captcha ...*/
                    if (loginres == LoginResult.NeedCaptcha)
                    {
                        Process.Start(string.Format("{0}/public/captcha.php?gid={1}", APIEndpoints.COMMUNITY_BASE, userLogin.CaptchaGID));

                        InputForm captchaForm = new InputForm("Enter the captcha code that is showing in your browser.");
                        captchaForm.ShowDialog();
                        if (captchaForm.inputCancelled)
                        {
                            Close();
                            return;
                        }

                        userLogin.CaptchaText = captchaForm.inputText.Text;
                        continue;
                    }

                    /*We need mobile auth code ...*/
                    /*The user needs to remove existing authenticator before we can proceed, so we'll just bail out*/
                    if (loginres == LoginResult.Need2FA)
                    {
                        MessageBox.Show("Please remove the existing authenticator device you have attatched to your account to in order to proceed.");
                        Close();
                        return;
                    }

                    /*Incorrect password or similar*/
                    if (loginres == LoginResult.GeneralFailure)
                    {
                        MessageBox.Show("Trouble logging in.\nWrong password?");
                        Close();
                        return;
                    }
                }

                /*Login successful, proceed*/
                SessionData                    sessionData = userLogin.Session;
                AuthenticatorLinker            authLinker  = new AuthenticatorLinker((sessionData));
                AuthenticatorLinker.LinkResult authResult  = AuthenticatorLinker.LinkResult.GeneralFailure;
                while ((authResult = authLinker.AddAuthenticator()) != AuthenticatorLinker.LinkResult.AwaitingFinalization)
                {
                    /*We need phone number to proceed*/
                    if (authResult == AuthenticatorLinker.LinkResult.MustProvidePhoneNumber)
                    {
                        string phoneNumber = string.Empty;
                        while (!ValidPhoneNumberInput(phoneNumber))
                        {
                            InputForm phoneNumberForm = new InputForm("Enter your phone number in the following format:\n+1 123-456-7890");
                            phoneNumberForm.inputText.Text = "+1 ";
                            phoneNumberForm.ShowDialog();
                            if (phoneNumberForm.inputCancelled)
                            {
                                Close();
                                return;
                            }

                            phoneNumber = FilterPhoneNumber(phoneNumberForm.inputText.Text);
                        }

                        authLinker.PhoneNumber = phoneNumber;
                        continue;
                    }

                    /*Remove previous number attatched to the account*/
                    if (authResult == AuthenticatorLinker.LinkResult.MustRemovePhoneNumber)
                    {
                        authLinker.PhoneNumber = string.Empty;
                        continue;
                    }

                    /*Oops*/
                    if (authResult == AuthenticatorLinker.LinkResult.GeneralFailure)
                    {
                        MessageBox.Show("Something bad happened...");
                        Close();
                        return;
                    }
                }

                /*Taking a pause to save the information that we've gathered thus far*/
                if (!FileHandler.SaveSGAFile(authLinker.LinkedAccount))
                {
                    MessageBox.Show("Unable to save the current data. The authenticator has not been linked.", "Error");
                    Close();
                    return;
                }

                /*Final checks*/
                AuthenticatorLinker.FinalizeResult finalRes = AuthenticatorLinker.FinalizeResult.GeneralFailure;
                while (finalRes != AuthenticatorLinker.FinalizeResult.Success)
                {
                    /*Get SMS code that was sent to users phone, providing the number was correct*/
                    InputForm smsForm = new InputForm("Enter the SMS code you received on your phone.");
                    smsForm.ShowDialog();
                    if (smsForm.inputCancelled)
                    {
                        /*Delete file here*/
                        FileHandler.DeleteSGAFile(authLinker.LinkedAccount);
                        Close();
                        return;
                    }

                    /*Finalize the process and check last things*/
                    finalRes = authLinker.FinalizeAddAuthenticator(smsForm.inputText.Text);

                    /*Check if the SMS code was bad*/
                    if (finalRes == AuthenticatorLinker.FinalizeResult.BadSMSCode)
                    {
                        MessageBox.Show("Incorrect SMS code. Try again.");
                        continue;
                    }

                    /*General failure number one*/
                    if (finalRes == AuthenticatorLinker.FinalizeResult.UnableToGenerateCorrectCodes ||
                        finalRes == AuthenticatorLinker.FinalizeResult.GeneralFailure)
                    {
                        MessageBox.Show(string.Format("Unable to generate correct codes.\nThe authenticator has not been linked.\n\n"
                                                      + "However, please write the revocation code down just incase:\n\n  {0}", authLinker.LinkedAccount.RevocationCode), "Error");

                        /*Delete file here*/
                        FileHandler.DeleteSGAFile(authLinker.LinkedAccount);
                        Close();
                        return;
                    }
                }

                /*Finally done - save everything*/
                if (!FileHandler.SaveSGAFile(authLinker.LinkedAccount))
                {
                    MessageBox.Show("Save failed.");
                    //Do something about it
                }

                MessageBox.Show("Mobile authenticator successfully linked.\nRevocation code: " + authLinker.LinkedAccount.RevocationCode, "Success!");
                Close();
            }
            else
            {
                MessageBox.Show("Missing login details.");
            }
        }
Пример #11
0
        private void btnSteamLogin_Click(object sender, EventArgs e)
        {
            string username = txtUsername.Text;
            string password = txtPassword.Text;

            mUserLogin = new UserLogin(username, password);
            LoginResult response = LoginResult.BadCredentials;

            while ((response = mUserLogin.DoLogin()) != LoginResult.LoginOkay)
            {
                switch (response)
                {
                case LoginResult.NeedEmail:
                    InputForm emailForm = new InputForm("Enter the code sent to your email:");
                    emailForm.ShowDialog();
                    if (emailForm.Canceled)
                    {
                        this.Close();
                        return;
                    }

                    mUserLogin.EmailCode = emailForm.txtBox.Text;
                    break;

                case LoginResult.NeedCaptcha:
                    System.Diagnostics.Process.Start(String.Format("{0}/public/captcha.php?gid={1}", APIEndpoints.COMMUNITY_BASE, mUserLogin.CaptchaGID));

                    InputForm captchaForm = new InputForm("Enter the captcha that opened in your browser:");
                    captchaForm.ShowDialog();
                    if (captchaForm.Canceled)
                    {
                        this.Close();
                        return;
                    }

                    mUserLogin.CaptchaText = captchaForm.txtBox.Text;
                    break;

                case LoginResult.Need2FA:
                    MessageBox.Show("This account already has a mobile authenticator linked to it. Please remove that first.");
                    this.Close();
                    return;

                    break;
                }
            }

            //Login succeeded

            SessionData         session = mUserLogin.Session;
            AuthenticatorLinker linker  = new AuthenticatorLinker(session);

            AuthenticatorLinker.LinkResult linkResponse = AuthenticatorLinker.LinkResult.GeneralFailure;

            while ((linkResponse = linker.AddAuthenticator()) != AuthenticatorLinker.LinkResult.AwaitingFinalization)
            {
                switch (linkResponse)
                {
                case AuthenticatorLinker.LinkResult.MustProvidePhoneNumber:
                    string phoneNumber = "";
                    while (!PhoneNumberOkay(phoneNumber))
                    {
                        InputForm phoneNumberForm = new InputForm("Enter your phone number in the following format: +{cC} phoneNumber. EG, +1 123-456-7890");
                        phoneNumberForm.txtBox.Text = "+1 ";
                        phoneNumberForm.ShowDialog();
                        if (phoneNumberForm.Canceled)
                        {
                            this.Close();
                            return;
                        }

                        phoneNumber = FilterPhoneNumber(phoneNumberForm.txtBox.Text);
                    }
                    linker.PhoneNumber = phoneNumber;
                    break;

                case AuthenticatorLinker.LinkResult.MustRemovePhoneNumber:
                    linker.PhoneNumber = null;
                    break;

                case AuthenticatorLinker.LinkResult.GeneralFailure:
                    this.Close();
                    return;

                    break;
                }
            }

            //Save the file immediately; losing this would be bad.
            if (!MobileAuthenticatorFileHandler.SaveMaFile(linker.LinkedAccount))
            {
                MessageBox.Show("Unable to save mobile authenticator file. The mobile authenticator has not been linked.");
                this.Close();
                return;
            }

            MessageBox.Show("The Mobile Authenticator has not yet been linked. Before finalizing the authenticator, please write down your revocation code: " + linker.LinkedAccount.RevocationCode);

            AuthenticatorLinker.FinalizeResult finalizeResponse = AuthenticatorLinker.FinalizeResult.GeneralFailure;
            while (finalizeResponse != AuthenticatorLinker.FinalizeResult.Success)
            {
                InputForm smsCodeForm = new InputForm("Please input the SMS code sent to your phone.");
                smsCodeForm.ShowDialog();
                if (smsCodeForm.Canceled)
                {
                    MobileAuthenticatorFileHandler.DeleteMaFile(linker.LinkedAccount);
                    this.Close();
                    return;
                }

                InputForm confirmRevocationCode = new InputForm("Please enter your revocation code to ensure you've saved it.");
                confirmRevocationCode.ShowDialog();
                if (confirmRevocationCode.txtBox.Text.ToUpper() != linker.LinkedAccount.RevocationCode)
                {
                    MessageBox.Show("Revocation code incorrect; the authenticator has not been linked.");
                    MobileAuthenticatorFileHandler.DeleteMaFile(linker.LinkedAccount);
                    this.Close();
                    return;
                }

                string smsCode = smsCodeForm.txtBox.Text;
                finalizeResponse = linker.FinalizeAddAuthenticator(smsCode);

                switch (finalizeResponse)
                {
                case AuthenticatorLinker.FinalizeResult.BadSMSCode:
                    continue;
                    break;

                case AuthenticatorLinker.FinalizeResult.UnableToGenerateCorrectCodes:
                    MessageBox.Show("Unable to generate the proper codes to finalize this authenticator. The authenticator should not have been linked. In the off-chance it was, please write down your revocation code, as this is the last chance to see it: " + linker.LinkedAccount.RevocationCode);
                    MobileAuthenticatorFileHandler.DeleteMaFile(linker.LinkedAccount);
                    this.Close();
                    return;

                    break;

                case AuthenticatorLinker.FinalizeResult.GeneralFailure:
                    MessageBox.Show("Unable to finalize this authenticator. The authenticator should not have been linked. In the off-chance it was, please write down your revocation code, as this is the last chance to see it: " + linker.LinkedAccount.RevocationCode);
                    MobileAuthenticatorFileHandler.DeleteMaFile(linker.LinkedAccount);
                    this.Close();
                    return;
                }
            }

            //Linked, finally. Re-save with FullyEnrolled property.
            MobileAuthenticatorFileHandler.SaveMaFile(linker.LinkedAccount);
            MessageBox.Show("Mobile authenticator successfully linked. Please write down your revocation code: " + linker.LinkedAccount.RevocationCode);
            this.Close();
        }