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 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}"); }
private static Manifest _generateNewManifest(bool scanDir = false) { if (Program.Verbose) { Console.WriteLine("Generating new manifest..."); } // No directory means no manifest file anyways. Manifest newManifest = new Manifest(); newManifest.Encrypted = false; newManifest.PeriodicCheckingInterval = 5; newManifest.PeriodicChecking = false; newManifest.AutoConfirmMarketTransactions = false; newManifest.AutoConfirmTrades = false; newManifest.Entries = new List <ManifestEntry>(); newManifest.FirstRun = true; // Take a pre-manifest version and generate a manifest for it. if (scanDir) { if (Directory.Exists(Program.SteamGuardPath)) { DirectoryInfo dir = new DirectoryInfo(Program.SteamGuardPath); var files = dir.GetFiles(); foreach (var file in files) { if (file.Extension != ".maFile") { continue; } string contents = File.ReadAllText(file.FullName); try { SteamGuardAccount account = JsonConvert.DeserializeObject <SteamGuardAccount>(contents); ManifestEntry newEntry = new ManifestEntry() { Filename = file.Name, SteamID = account.Session.SteamID }; newManifest.Entries.Add(newEntry); } catch (Exception ex) { if (Program.Verbose) { Console.WriteLine("warn: {0}", ex.Message); } } } if (newManifest.Entries.Count > 0) { newManifest.Save(); newManifest.PromptSetupPassKey(true); } } } if (newManifest.Save()) { return(newManifest); } return(null); }