/// <summary> /// Decrypts files and populates list UI with accounts /// </summary> private void loadAccountsList() { currentAccount = null; listAccounts.Items.Clear(); listAccounts.SelectedIndex = -1; trayAccountList.Items.Clear(); trayAccountList.SelectedIndex = -1; allAccounts = manifest.GetAllAccounts(passKey); if (allAccounts.Length > 0) { for (int i = 0; i < allAccounts.Length; i++) { SteamGuardAccount account = allAccounts[i]; listAccounts.Items.Add(account.AccountName); trayAccountList.Items.Add(account.AccountName); } listAccounts.SelectedIndex = 0; trayAccountList.SelectedIndex = 0; listAccounts.Sorted = true; trayAccountList.Sorted = true; } menuDeactivateAuthenticator.Enabled = btnTradeConfirmations.Enabled = allAccounts.Length > 0; }
/// <summary> /// Refresh this account's session data using their OAuth Token /// </summary> /// <param name="account">The account to refresh</param> /// <param name="attemptRefreshLogin">Whether or not to prompt the user to re-login if their OAuth token is expired.</param> /// <returns></returns> private async Task <bool> RefreshAccountSession(SteamGuardAccount account, bool attemptRefreshLogin = true) { if (account == null) { return(false); } try { bool refreshed = await account.RefreshSessionAsync(); return(refreshed); //No exception thrown means that we either successfully refreshed the session or there was a different issue preventing us from doing so. } catch (SteamGuardAccount.WGTokenExpiredException) { if (!attemptRefreshLogin) { return(false); } PromptRefreshLogin(account); return(await RefreshAccountSession(account, false)); } }
/// <summary> /// Class constructor /// Gets the steam guard account from file /// </summary> /// <param name="settings">Settings class for bot</param> public Authentication(AppSettings.BotSettings settings) { if ((mAccount = GetAccount(settings.username)) == null) { Console.WriteLine("An authenticator needs to be added to this account manually."); return; } }
private static Manifest _generateNewManifest(bool scanDir = false) { // No directory means no manifest file anyways. Manifest newManifest = new Manifest(); newManifest.Encrypted = false; newManifest.PeriodicCheckingInterval = 5; newManifest.PeriodicChecking = false; newManifest.Entries = new List <ManifestEntry>(); newManifest.FirstRun = true; // Take a pre-manifest version and generate a manifest for it. if (scanDir) { string maDir = Manifest.GetExecutableDir() + "/maFiles/"; if (Directory.Exists(maDir)) { DirectoryInfo dir = new DirectoryInfo(maDir); 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) { } } if (newManifest.Entries.Count > 0) { newManifest.Save(); newManifest.PromptSetupPassKey("This version of SDA has encryption. Please enter a passkey below, or hit cancel to remain unencrypted"); } } } if (newManifest.Save()) { return(newManifest); } return(null); }
public SteamManager( string login, string password, SteamGuardAccount mafile, string apiKey, bool forceSessionRefresh = false) { this.Guard = mafile; this.SteamClient = new UserLogin(login, password) { TwoFactorCode = this.GenerateSteamGuardCode() }; this.Guard.DeviceID = this.GetDeviceId(); var isSessionRefreshed = this.Guard.RefreshSession(); if (isSessionRefreshed == false || forceSessionRefresh) { Logger.Debug($"Saved steam session for {login} is expired. Refreshing session."); LoginResult loginResult; var tryCount = 0; do { loginResult = this.SteamClient.DoLogin(); if (loginResult == LoginResult.LoginOkay) { continue; } Logger.Warning($"Login status is - {loginResult}"); if (++tryCount == 3) { throw new WebException("Login failed after 3 attempts!"); } Thread.Sleep(3000); }while (loginResult != LoginResult.LoginOkay); this.Guard.Session = this.SteamClient.Session; this.SaveAccount(this.Guard); } this.ApiKey = apiKey; this.TradeOfferWeb = new TradeOfferWebApi(apiKey); this.OfferSession = new OfferSession(this.TradeOfferWeb, this.Cookies, this.Guard.Session.SessionID); this.Guard.Session.AddCookies(this.Cookies); var market = new SteamMarketHandler(ELanguage.English, "user-agent"); var auth = new Auth(market, this.Cookies) { IsAuthorized = true }; this.FetchTradeToken(); market.Auth = auth; this.MarketClient = new MarketClient(market); this.Inventory = new Inventory(); }
public SharedSecret(TitanAccount account) { _log = LogCreator.Create("Shared Secret - " + account.JsonAccount.Username); _steamGuardAccount = new SteamGuardAccount { SharedSecret = account.JsonAccount.SharedSecret }; }
public void TestLegacyBug() { this.localSettings.Values["steamUser-"] = TestSteamid; this.localSettings.Values["steamGuard-" + TestSteamid] = "{\"shared_secret\":\"##TEST##\",\"account_name\":\"testUser\",\"Session\":{\"SteamID\":" + TestSteamid + "}}"; SteamGuardAccount test = Storage.GetSteamGuardAccount("test"); Assert.AreEqual("##TEST##", test.SharedSecret); Assert.AreEqual(this.localSettings.Values["steamUser-testUser"], TestSteamid); }
protected override void OnNavigatedTo(NavigationEventArgs e) { ConfirmationWeb.ScriptNotify += WebNotify; ConfirmationWeb.NavigationCompleted += InjectCode; HardwareButtons.BackPressed += BackPressed; this.account = Storage.SGAFromStore(); SteamGuardButton_Click(null, null); }
/// <summary> /// Returns all accounts available in a list /// </summary> /// <returns>Returns list of accounts</returns> public static List <Config.LoadSteamGuardAccount> GetAllAccounts() { /*Locate the .SGA save files*/ var sgaList = new List <Config.LoadSteamGuardAccount>(); DirectoryInfo info = new DirectoryInfo(Path.Combine(Application.StartupPath, "SGAFiles")); FileInfo[] files = info.GetFiles("*.SGA"); foreach (FileInfo file in files) { bool skipDeserialize = false; try { string contentStr = File.ReadAllText(file.FullName); if (contentStr.Length > 0) { /*N1 way to determine if it's hashed*/ if (contentStr.EndsWith("=")) { /*If user skips password the secret will be empty, so don't bother with these accounts*/ if (Crypto.crySecret.Length > 0) { contentStr = Crypto.DecryptStringAES(contentStr); } else { skipDeserialize = true; } } /*Try to deserialize content to account class*/ var accountHolder = new Config.LoadSteamGuardAccount(); SteamGuardAccount account = null; if (!skipDeserialize) { /*We don't want to attempt to deserialize this string, but we still want to add the other information*/ account = JsonConvert.DeserializeObject <SteamGuardAccount>(contentStr); accountHolder.account = account; } /*Load the rest of information about the file*/ accountHolder.loaded = (account != null); accountHolder.filename = Path.GetFileNameWithoutExtension(file.Name); /*Add account holder to list that we will return*/ sgaList.Add(accountHolder); } } catch (Exception ex) { /*Whoops - what happend here?*/ MessageBox.Show(ex.ToString()); } } return(sgaList); }
static void Main(string[] args) { SteamGuardAccount account = new SteamGuardAccount(); account.SharedSecret = args[0]; string loginCode = account.GenerateSteamGuardCode(); Console.Write(loginCode); }
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; } } } }
/// <summary> /// Gets the auth code from an account by clicking on the submenu item for the account /// </summary> private void menuGetCode_Click(object sender, EventArgs e) { SteamGuardAccount account = GetAccountFromMenuItem(sender); if (account != null) { Clipboard.SetText(account.GenerateSteamGuardCodeForTime(steamTime)); Console.Beep(800, 50); } }
public void Initialize(string filePath) { if (String.IsNullOrEmpty(filePath) || !File.Exists(filePath)) { throw new ArgumentException($"Invalid account file path [{Path.GetDirectoryName(filePath)}]", nameof(filePath)); } _currentSteamGuardAccount = CreateSteamGuardAccountFromFilePath(filePath); AccountFilePath = filePath; }
private string Generate2FACode(string shared_secret) { SteamGuardAccount authaccount = new SteamGuardAccount { SharedSecret = shared_secret }; string code = authaccount.GenerateSteamGuardCode(); return(code); }
/// <summary> /// Loads all account from file /// </summary> private void loadAccounts() { /*Reset current values*/ accountCurrent = null; accountList.Clear(); accountListBox.Items.Clear(); /*Get accounts from save list and load them up*/ var unloadedList = new List <string>(); var accList = FileHandler.GetAllAccounts(); if (accList.Count > 0) { lock (accList) { foreach (var accHolder in accList) { if (!accHolder.loaded) { /*This account wasn't loaded successfully*/ /*We'll add it in a seperate list to display*/ unloadedList.Add(accHolder.filename); continue; } else { /*This was loaded*/ accountList.Add(accHolder.account); } /*Add the account*/ accountListBox.Items.Add(accHolder.account.AccountName); if (!notifyMenu.Items.ContainsKey(accHolder.account.AccountName)) { /*Add account to notifyMenu (contextMenuStrip attatched to notifyIcon) so user can access things quickly*/ ToolStripMenuItem tsm = new ToolStripMenuItem(); tsm.Text = accHolder.account.AccountName; tsm.DropDownItems.Add("Copy Steam Guard code", null, new EventHandler(menuGetCode_Click)); tsm.DropDownItems.Add("Accept all trades", null, new EventHandler(menuAcceptTrades_Click)); notifyMenu.Items.Add(tsm); } } } accountListBox.SelectedIndex = 0; } /*If we haven't already displayed the list of unloaded accounts, do it here*/ if (!applicationShownUnloadedAccounts && unloadedList.Count > 0) { notloadedForm = new NotloadedForm(unloadedList); notloadedBtn.Text = string.Format("{0} accounts not loaded", unloadedList.Count); notloadedBtn.Visible = true; applicationShownUnloadedAccounts = true; } }
/// <summary> /// Adds all accounts from specified Manifest file. /// </summary> /// <param name="folder">Folder containing Manifest.</param> public static async Task <LoadFileResult> LoadFile(StorageFolder folder) { StorageFile toload = await folder.GetFileAsync("manifest.json"); // asks user for password string password = await GetPassword("Decryption"); string manifestJson = await FileIO.ReadTextAsync(toload); Manifest manifest = JsonConvert.DeserializeObject <Manifest>(manifestJson) ?? new Manifest(); // checks password for encrypted files. if (!await CheckPassword(manifest, folder, password)) { return(new LoadFileResult(ELoadFileResult.PasswordIncorrect, 0)); } int loaded = 0; foreach (ManifestEntry entry in manifest.Entries) { try { // retrieves file StorageFile entryFile = await folder.GetFileAsync(entry.Filename); string encrypted = await FileIO.ReadTextAsync(entryFile); string decrypted = password.Length != 0 ? FileEncryptor.DecryptData(password, entry.Salt, entry.Iv, encrypted) : encrypted; if (decrypted == null) { continue; } var toadd = JsonConvert.DeserializeObject <SteamGuardAccount>(decrypted); SteamGuardAccount old = Storage.GetSteamGuardAccount(toadd.Session.SteamID); // Only update if the file was linked more recently than ours // or our current file isn't linked if ((toadd.FullyEnrolled && toadd.ServerTime > old.ServerTime) || !old.FullyEnrolled) { Storage.PushStore(toadd); loaded++; } } catch (FileNotFoundException) { // Oh well } } // if no error returned - return success return(new LoadFileResult(ELoadFileResult.Success, loaded)); }
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); } }
private SteamGuardAccount CreateSteamGuardAccountFromFilePath(string filePath) { SteamGuardAccount result = null; if (!String.IsNullOrEmpty(filePath) && File.Exists(filePath)) { result = JsonConvert.DeserializeObject <SteamGuardAccount>(File.ReadAllText(filePath)); } return(result); }
private void loadAccountsList() { mCurrentAccount = null; listAccounts.Items.Clear(); listAccounts.SelectedIndex = -1; string passKey = null; if (mManifest.Encrypted) { bool passKeyValid = false; while (!passKeyValid) { InputForm passKeyForm = new InputForm("Please enter your encryption passkey.", true); passKeyForm.ShowDialog(); if (!passKeyForm.Canceled) { passKey = passKeyForm.txtBox.Text; passKeyValid = this.mManifest.VerifyPasskey(passKey); if (!passKeyValid) { MessageBox.Show("That passkey is invalid."); } } else { this.Close(); return; } } btnManageEncryption.Text = "Manage Encryption"; } else { btnManageEncryption.Text = "Setup Encryption"; } btnManageEncryption.Enabled = mManifest.Entries.Count > 0; allAccounts = mManifest.GetAllAccounts(passKey); if (allAccounts.Length > 0) { for (int i = 0; i < allAccounts.Length; i++) { SteamGuardAccount account = allAccounts[i]; listAccounts.Items.Add(account.AccountName); } listAccounts.SelectedIndex = 0; } btnDelete.Enabled = btnTradeConfirmations.Enabled = allAccounts.Length > 0; }
private static void Fill2FACode() { var account = new SteamGuardAccount() { SharedSecret = SharedSecret }; var code = account.GenerateSteamGuardCode(); Copy(code); SendKeys.SendWait("^V{ENTER}"); }
private void button_generate_Click(object sender, EventArgs e) { var username = textBox_account_name.Text.Trim(); var password = textBox_password.Text.Trim(); var sharedSecret = textBox_shared_secret.Text.Trim(); var identitySecret = textBox_identity_secret.Text.Trim(); button_generate.Enabled = false; button_generate.Text = Resources.Form1_button_generate_Click_Generating___; new Thread(() => { var authFile = Path.Combine("authfiles", string.Format("{0}.auth", username)); Directory.CreateDirectory(Path.Combine(Application.StartupPath, "authfiles")); var steamGuardAccount = new SteamGuardAccount { SharedSecret = sharedSecret, IdentitySecret = identitySecret }; var login = new UserLogin(username, password); var loginResult = login.DoLogin(); if (loginResult == LoginResult.Need2FA) { for (var i = 0; i < 3; i++) { TimeAligner.AlignTime(); login.TwoFactorCode = steamGuardAccount.GenerateSteamGuardCode(); loginResult = login.DoLogin(); if (loginResult == LoginResult.LoginOkay) { break; } } if (loginResult == LoginResult.LoginOkay) { steamGuardAccount.DeviceID = AuthenticatorLinker.GenerateDeviceID(); steamGuardAccount.Session = login.Session; File.WriteAllText(authFile, Newtonsoft.Json.JsonConvert.SerializeObject(steamGuardAccount)); MessageBox.Show(Resources.Form1_button_generate_Click_Successfully_generated_your_auth_file_, Resources.Form1_button_generate_Click_Success); ResetGenerateButton(); } else { MessageBox.Show(Resources.Form1_button_generate_Click_Error_logging_in__ + loginResult, Resources.Form1_button_generate_Click_Error); ResetGenerateButton(); } } else { MessageBox.Show(Resources.Form1_button_generate_Click_This_account_does_not_appear_to_have_2FA_enabled__Login_result__ + loginResult, Resources.Form1_button_generate_Click_Error); ResetGenerateButton(); } }).Start(); }
private string GetMobileAuthCode() { var authFile = String.Format("{0}.auth", loginInfo.Username); if (File.Exists(authFile)) { steamGuardAccount = Newtonsoft.Json.JsonConvert.DeserializeObject <SteamAuth.SteamGuardAccount>(File.ReadAllText(authFile)); return(steamGuardAccount.GenerateSteamGuardCode()); } return(string.Empty); }
public User(ulong steamId, long lastCurrent, string content) { this.SteamId = steamId; this.SteamGuardAccount = Storage.GetSteamGuardAccount(steamId); // skip notifying in constructor this.title = this.SteamGuardAccount.DisplayName; this.content = content; this.AccountName = this.SteamGuardAccount.AccountName ?? this.SteamGuardAccount.Session.Username; this.Avatar = new Avatar(steamId); this.LastCurrent = lastCurrent; }
/// <summary> /// Changes the current account depending on which is selected in the listbox /// </summary> private void accountListBox_SelectedIndexChanged(object sender, EventArgs e) { foreach (SteamGuardAccount account in accountList) { if (account.AccountName == (string)accountListBox.SelectedItem) { accountCurrent = account; loadAccountInfo(); break; } } }
public bool SaveAccount(SteamGuardAccount account) { try { SavedSteamAccount.UpdateByLogin(account.AccountName, account); return(true); } catch (Exception ex) { Logger.Error("Error on session save", ex); return(false); } }
internal static SteamGuardAccount SGAFromStore(string username) { SteamGuardAccount response = null; ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; if (localSettings.Values.ContainsKey("steamUser-" + username)) { response = SGAFromStore((ulong)localSettings.Values["steamUser-" + username]); } return(response); }
/// <summary> /// Accepts all pending trade for the account from clicking on the submenu item for the account /// </summary> private void menuAcceptTrades_Click(object sender, EventArgs e) { SteamGuardAccount account = GetAccountFromMenuItem(sender); if (account != null) { foreach (Confirmation confirmation in LoadConfirmations(account)) { account.AcceptConfirmation(confirmation); } Console.Beep(800, 50); } }
private static void AcceptConfirmationsLoop(SteamGuardAccount sgAccount) { sgAccount.Session.SteamLogin = _account.FindCookieByName("steamlogin").Value; sgAccount.Session.SteamLoginSecure = _account.FindCookieByName("steamloginsecure").Value; while (true) //permanent loop, can be changed { Thread.Sleep(10000); foreach (Confirmation confirmation in sgAccount.FetchConfirmations()) { sgAccount.AcceptConfirmation(confirmation); } } }
public static void UpdateByLogin(string login, SteamGuardAccount account) { var allAccounts = Get(); var foundAccount = allAccounts.FindIndex(all => all.Login.Equals(login)); if (foundAccount == -1) { return; } allAccounts[foundAccount].MaFile = account; UpdateAll(allAccounts); }
private void listAccounts_SelectedValueChanged(object sender, EventArgs e) { // Triggered when list item is clicked for (int i = 0; i < allAccounts.Length; i++) { SteamGuardAccount account = allAccounts[i]; if (account.AccountName == (string)listAccounts.Items[listAccounts.SelectedIndex]) { mCurrentAccount = account; loadAccountInfo(); } } }