static bool Decrypt(string passkey = "") { Utils.Verbose("Opening manifest..."); Manifest = Manifest.GetManifest(true); Utils.Verbose("Reading accounts from manifest..."); if (Manifest.Encrypted) { if (string.IsNullOrEmpty(passkey)) { passkey = Manifest.PromptForPassKey(); } SteamGuardAccounts = Manifest.GetAllAccounts(passkey); } else { Utils.Verbose("Decryption not required."); return(true); } for (int i = 0; i < SteamGuardAccounts.Length; i++) { var account = SteamGuardAccounts[i]; bool success = Manifest.SaveAccount(account, false); Utils.Verbose("Decrypted {0}: {1}", account.AccountName, success); if (!success) { return(false); } } return(true); }
static bool Encrypt(string passkey = "") { // NOTE: in this context, `passkey` refers to the old passkey, if there was one Utils.Verbose("Opening manifest..."); Manifest = Manifest.GetManifest(true); Utils.Verbose("Reading accounts from manifest..."); if (Manifest.Encrypted) { if (string.IsNullOrEmpty(passkey)) { passkey = Manifest.PromptForPassKey(); } SteamGuardAccounts = Manifest.GetAllAccounts(passkey); } else { SteamGuardAccounts = Manifest.GetAllAccounts(); } string newPassKey = Manifest.PromptSetupPassKey(); for (int i = 0; i < SteamGuardAccounts.Length; i++) { var account = SteamGuardAccounts[i]; var salt = Manifest.GetRandomSalt(); var iv = Manifest.GetInitializationVector(); bool success = Manifest.SaveAccount(account, true, newPassKey, salt, iv); Utils.Verbose("Encrypted {0}: {1}", account.AccountName, success); if (!success) { return(false); } } return(true); }
static void AcceptAllTrades(string user = "", string passkey = "") { Utils.Verbose("Opening manifest..."); Manifest = Manifest.GetManifest(true); Utils.Verbose("Reading accounts from manifest..."); if (Manifest.Encrypted) { if (string.IsNullOrEmpty(passkey)) { passkey = Manifest.PromptForPassKey(); } SteamGuardAccounts = Manifest.GetAllAccounts(passkey); } else { SteamGuardAccounts = Manifest.GetAllAccounts(); } if (SteamGuardAccounts.Length == 0) { Console.WriteLine("error: No accounts read."); return; } for (int i = 0; i < SteamGuardAccounts.Length; i++) { SteamGuardAccount account = SteamGuardAccounts[i]; if ((user != "" && account.AccountName.ToLower() == user.ToLower()) || user == "") { Console.WriteLine($"Accepting Confirmations on {account.AccountName}"); Utils.Verbose("Refeshing Session..."); if (account.RefreshSession()) { Utils.Verbose("Session refreshed"); Manifest.SaveAccount(account, Manifest.Encrypted); } else { Utils.Verbose("Failed to refresh session, prompting user..."); if (!promptRefreshSession(account)) { Console.WriteLine("Failed to refresh session, aborting..."); } } Utils.Verbose("Fetching Confirmations..."); var tradesTask = account.FetchConfirmationsAsync(); tradesTask.Wait(); Confirmation[] confirmations = tradesTask.Result; Utils.Verbose("Accepting Confirmations..."); account.AcceptMultipleConfirmations(confirmations); if (user != "") { break; } } } }
static void GenerateCode(string user = "", string passkey = "") { Utils.Verbose("Aligning time..."); TimeAligner.AlignTime(); Utils.Verbose("Opening manifest..."); Manifest = Manifest.GetManifest(true); Utils.Verbose("Reading accounts from manifest..."); if (Manifest.Encrypted) { if (string.IsNullOrEmpty(passkey)) { passkey = Manifest.PromptForPassKey(); } SteamGuardAccounts = Manifest.GetAllAccounts(passkey); } else { SteamGuardAccounts = Manifest.GetAllAccounts(); } if (SteamGuardAccounts.Length == 0) { Console.WriteLine("error: No accounts read."); return; } Utils.Verbose("Selecting account..."); string code = ""; for (int i = 0; i < SteamGuardAccounts.Length; i++) { SteamGuardAccount account = SteamGuardAccounts[i]; if (user != "") { if (account.AccountName.ToLower() == user.ToLower()) { Utils.Verbose("Generating code for {0}...", account.AccountName); code = account.GenerateSteamGuardCode(); break; } } else { Utils.Verbose("Generating code for {0}...", account.AccountName); code = account.GenerateSteamGuardCode(); break; } } if (code != "") { Console.WriteLine(code); } else { Console.WriteLine("error: No Steam accounts found in {0}", SteamGuardAccounts); } }
static void Trade(string user = "", string passkey = "") { if (Verbose) { Console.WriteLine("Opening manifest..."); } Manifest = Manifest.GetManifest(true); if (Verbose) { Console.WriteLine("Reading accounts from manifest..."); } if (Manifest.Encrypted) { if (string.IsNullOrEmpty(passkey)) { passkey = Manifest.PromptForPassKey(); } SteamGuardAccounts = Manifest.GetAllAccounts(passkey); } else { SteamGuardAccounts = Manifest.GetAllAccounts(); } if (SteamGuardAccounts.Length == 0) { Console.WriteLine("error: No accounts read."); return; } foreach (var account in SteamGuardAccounts) { if (user != "") { if (!string.Equals(account.AccountName, user, StringComparison.CurrentCultureIgnoreCase)) { break; } } processConfirmations(account); } }
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}"); }