diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 1c03b401a..1c7a8651c 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -1792,11 +1792,11 @@ namespace ArchiSteamFarm { return; } - byte[] sentryHash = null; + byte[] sentryFileHash = null; if (File.Exists(SentryFile)) { try { byte[] sentryFileContent = File.ReadAllBytes(SentryFile); - sentryHash = SteamKit2.CryptoHelper.SHAHash(sentryFileContent); + sentryFileHash = SteamKit2.CryptoHelper.SHAHash(sentryFileContent); } catch (Exception e) { Logging.LogGenericException(e, BotName); } @@ -1816,15 +1816,21 @@ namespace ArchiSteamFarm { password = Regex.Replace(password, @"[^\u0000-\u007F]+", ""); } + // Decrypt login key if needed + string loginKey = BotDatabase.LoginKey; + if (!string.IsNullOrEmpty(loginKey) && (loginKey.Length > 19)) { + loginKey = CryptoHelper.Decrypt(BotConfig.PasswordFormat, loginKey); + } + SteamUser.LogOnDetails logOnDetails = new SteamUser.LogOnDetails { Username = BotConfig.SteamLogin, Password = password, AuthCode = AuthCode, CellID = Program.GlobalDatabase.CellID, LoginID = LoginID, - LoginKey = BotDatabase.LoginKey, + LoginKey = loginKey, TwoFactorCode = TwoFactorCode, - SentryFileHash = sentryHash, + SentryFileHash = sentryFileHash, ShouldRememberPassword = true }; @@ -2201,7 +2207,12 @@ namespace ArchiSteamFarm { return; } - BotDatabase.LoginKey = callback.LoginKey; + string loginKey = callback.LoginKey; + if (!string.IsNullOrEmpty(loginKey)) { + loginKey = CryptoHelper.Encrypt(BotConfig.PasswordFormat, loginKey); + } + + BotDatabase.LoginKey = loginKey; SteamUser.AcceptNewLoginKey(callback); } diff --git a/ArchiSteamFarm/BotConfig.cs b/ArchiSteamFarm/BotConfig.cs index fbac3bb12..8490f2ec6 100644 --- a/ArchiSteamFarm/BotConfig.cs +++ b/ArchiSteamFarm/BotConfig.cs @@ -59,6 +59,9 @@ namespace ArchiSteamFarm { [JsonProperty] internal string SteamPassword { get; set; } + [JsonProperty(Required = Required.DisallowNull)] + internal readonly CryptoHelper.ECryptoMethod PasswordFormat = CryptoHelper.ECryptoMethod.PlainText; + [JsonProperty] internal string SteamParentalPIN { get; set; } = "0"; @@ -125,9 +128,6 @@ namespace ArchiSteamFarm { [JsonProperty(Required = Required.DisallowNull)] internal readonly HashSet GamesPlayedWhileIdle = new HashSet(); - [JsonProperty(Required = Required.DisallowNull)] - private readonly CryptoHelper.ECryptoMethod PasswordFormat = CryptoHelper.ECryptoMethod.PlainText; - internal static BotConfig Load(string filePath) { if (string.IsNullOrEmpty(filePath)) { Logging.LogNullError(nameof(filePath)); diff --git a/ArchiSteamFarm/BotDatabase.cs b/ArchiSteamFarm/BotDatabase.cs index 77138cf59..6b1ea6b0f 100644 --- a/ArchiSteamFarm/BotDatabase.cs +++ b/ArchiSteamFarm/BotDatabase.cs @@ -37,6 +37,7 @@ namespace ArchiSteamFarm { get { return _LoginKey; } + set { if (_LoginKey == value) { return; @@ -54,6 +55,7 @@ namespace ArchiSteamFarm { get { return _MobileAuthenticator; } + set { if (_MobileAuthenticator == value) { return; diff --git a/ArchiSteamFarm/CryptoHelper.cs b/ArchiSteamFarm/CryptoHelper.cs index 6afc927e2..806687f7e 100644 --- a/ArchiSteamFarm/CryptoHelper.cs +++ b/ArchiSteamFarm/CryptoHelper.cs @@ -132,7 +132,7 @@ namespace ArchiSteamFarm { try { byte[] encryptedData = ProtectedData.Protect( Encoding.UTF8.GetBytes(decrypted), - EncryptionKey, // This is used as salt only + EncryptionKey, // This is used as salt only and it's fine that it's known DataProtectionScope.CurrentUser ); @@ -152,7 +152,7 @@ namespace ArchiSteamFarm { try { byte[] decryptedData = ProtectedData.Unprotect( Convert.FromBase64String(encrypted), - EncryptionKey, // This is used as salt only + EncryptionKey, // This is used as salt only and it's fine that it's known DataProtectionScope.CurrentUser );