diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 7c728b8c9..740abb718 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -1007,7 +1007,7 @@ namespace ArchiSteamFarm { break; case ASF.EUserInputType.Password: if (BotConfig != null) { - BotConfig.SteamPassword = inputValue; + BotConfig.OriginalSteamPassword = inputValue; } break; @@ -1407,7 +1407,7 @@ namespace ArchiSteamFarm { SetUserInput(ASF.EUserInputType.Login, steamLogin); } - if (requiresPassword && string.IsNullOrEmpty(BotConfig.SteamPassword)) { + if (requiresPassword && string.IsNullOrEmpty(BotConfig.OriginalSteamPassword)) { string steamPassword = Program.GetUserInput(ASF.EUserInputType.Password, BotName); if (string.IsNullOrEmpty(steamPassword)) { return false; @@ -1591,7 +1591,7 @@ namespace ArchiSteamFarm { string username = Regex.Replace(BotConfig.SteamLogin, nonAsciiPattern, "", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase); - string password = BotConfig.SteamPassword; + string password = BotConfig.OriginalSteamPassword; if (!string.IsNullOrEmpty(password)) { password = Regex.Replace(password, nonAsciiPattern, "", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase); } diff --git a/ArchiSteamFarm/BotConfig.cs b/ArchiSteamFarm/BotConfig.cs index 9669fd68d..63143e82b 100644 --- a/ArchiSteamFarm/BotConfig.cs +++ b/ArchiSteamFarm/BotConfig.cs @@ -40,7 +40,6 @@ namespace ArchiSteamFarm { private const string DefaultCustomGamePlayedWhileFarming = null; private const string DefaultCustomGamePlayedWhileIdle = null; private const bool DefaultEnabled = false; - private const string DefaultEncryptedSteamPassword = null; private const byte DefaultHoursUntilCardDrops = 3; private const bool DefaultIdlePriorityQueueOnly = false; private const bool DefaultIdleRefundableGames = true; @@ -54,6 +53,7 @@ namespace ArchiSteamFarm { private const string DefaultSteamLogin = null; private const ulong DefaultSteamMasterClanID = 0; private const string DefaultSteamParentalPIN = "0"; + private const string DefaultSteamPassword = null; private const string DefaultSteamTradeToken = null; private const ETradingPreferences DefaultTradingPreferences = ETradingPreferences.None; private const bool DefaultUseLoginKeys = true; @@ -138,8 +138,33 @@ namespace ArchiSteamFarm { [JsonProperty(Required = Required.DisallowNull)] internal readonly bool UseLoginKeys = DefaultUseLoginKeys; - [JsonProperty(PropertyName = nameof(SteamPassword))] - internal string EncryptedSteamPassword { get; private set; } = DefaultEncryptedSteamPassword; + internal string OriginalSteamPassword { + get { + if (string.IsNullOrEmpty(SteamPassword)) { + return null; + } + + if (PasswordFormat == ArchiCryptoHelper.ECryptoMethod.PlainText) { + return SteamPassword; + } + + string decryptedPassword = ArchiCryptoHelper.Decrypt(PasswordFormat, SteamPassword); + if (string.IsNullOrEmpty(decryptedPassword)) { + ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsInvalid, nameof(SteamPassword))); + return null; + } + + return decryptedPassword; + } + set { + if (string.IsNullOrEmpty(value)) { + ASF.ArchiLogger.LogNullError(nameof(value)); + return; + } + + SteamPassword = PasswordFormat == ArchiCryptoHelper.ECryptoMethod.PlainText ? value : ArchiCryptoHelper.Encrypt(PasswordFormat, value); + } + } internal bool ShouldSerializeEverything { private get; set; } = true; @@ -152,26 +177,11 @@ namespace ArchiSteamFarm { [JsonProperty] internal string SteamParentalPIN { get; set; } = DefaultSteamParentalPIN; - internal string SteamPassword { - get { - if (string.IsNullOrEmpty(EncryptedSteamPassword)) { - return null; - } - - return PasswordFormat == ArchiCryptoHelper.ECryptoMethod.PlainText ? EncryptedSteamPassword : ArchiCryptoHelper.Decrypt(PasswordFormat, EncryptedSteamPassword); - } - set { - if (string.IsNullOrEmpty(value)) { - ASF.ArchiLogger.LogNullError(nameof(value)); - return; - } - - EncryptedSteamPassword = PasswordFormat == ArchiCryptoHelper.ECryptoMethod.PlainText ? value : ArchiCryptoHelper.Encrypt(PasswordFormat, value); - } - } - private bool ShouldSerializeSensitiveDetails = true; + [JsonProperty] + private string SteamPassword = DefaultSteamPassword; + [JsonProperty(PropertyName = SharedInfo.UlongCompatibilityStringPrefix + nameof(SteamMasterClanID), Required = Required.DisallowNull)] private string SSteamMasterClanID { get => SteamMasterClanID.ToString(); @@ -373,7 +383,6 @@ namespace ArchiSteamFarm { public bool ShouldSerializeCustomGamePlayedWhileFarming() => ShouldSerializeEverything || (CustomGamePlayedWhileFarming != DefaultCustomGamePlayedWhileFarming); public bool ShouldSerializeCustomGamePlayedWhileIdle() => ShouldSerializeEverything || (CustomGamePlayedWhileIdle != DefaultCustomGamePlayedWhileIdle); public bool ShouldSerializeEnabled() => ShouldSerializeEverything || (Enabled != DefaultEnabled); - public bool ShouldSerializeEncryptedSteamPassword() => ShouldSerializeSensitiveDetails && (ShouldSerializeEverything || (EncryptedSteamPassword != DefaultEncryptedSteamPassword)); public bool ShouldSerializeFarmingOrders() => ShouldSerializeEverything || ((FarmingOrders != DefaultFarmingOrders) && !FarmingOrders.SetEquals(DefaultFarmingOrders)); public bool ShouldSerializeGamesPlayedWhileIdle() => ShouldSerializeEverything || ((GamesPlayedWhileIdle != DefaultGamesPlayedWhileIdle) && !GamesPlayedWhileIdle.SetEquals(DefaultGamesPlayedWhileIdle)); public bool ShouldSerializeHoursUntilCardDrops() => ShouldSerializeEverything || (HoursUntilCardDrops != DefaultHoursUntilCardDrops); @@ -392,6 +401,7 @@ namespace ArchiSteamFarm { public bool ShouldSerializeSteamLogin() => ShouldSerializeSensitiveDetails && (ShouldSerializeEverything || (SteamLogin != DefaultSteamLogin)); public bool ShouldSerializeSteamMasterClanID() => ShouldSerializeEverything || (SteamMasterClanID != DefaultSteamMasterClanID); public bool ShouldSerializeSteamParentalPIN() => ShouldSerializeSensitiveDetails && (ShouldSerializeEverything || (SteamParentalPIN != DefaultSteamParentalPIN)); + public bool ShouldSerializeSteamPassword() => ShouldSerializeSensitiveDetails && (ShouldSerializeEverything || (SteamPassword != DefaultSteamPassword)); public bool ShouldSerializeSteamTradeToken() => ShouldSerializeEverything || (SteamTradeToken != DefaultSteamTradeToken); public bool ShouldSerializeSteamUserPermissions() => ShouldSerializeEverything || ((SteamUserPermissions != DefaultSteamUserPermissions) && ((SteamUserPermissions.Count != DefaultSteamUserPermissions.Count) || SteamUserPermissions.Except(DefaultSteamUserPermissions).Any())); public bool ShouldSerializeTradingPreferences() => ShouldSerializeEverything || (TradingPreferences != DefaultTradingPreferences); diff --git a/ArchiSteamFarm/Commands.cs b/ArchiSteamFarm/Commands.cs index 2e80822e4..d890b3d75 100644 --- a/ArchiSteamFarm/Commands.cs +++ b/ArchiSteamFarm/Commands.cs @@ -1649,11 +1649,11 @@ namespace ArchiSteamFarm { return null; } - if (string.IsNullOrEmpty(Bot.BotConfig.SteamPassword)) { - return FormatBotResponse(string.Format(Strings.ErrorIsEmpty, nameof(BotConfig.SteamPassword))); + if (string.IsNullOrEmpty(Bot.BotConfig.OriginalSteamPassword)) { + return FormatBotResponse(string.Format(Strings.ErrorIsEmpty, nameof(BotConfig.OriginalSteamPassword))); } - string response = FormatBotResponse(string.Format(Strings.BotEncryptedPassword, ArchiCryptoHelper.ECryptoMethod.AES, ArchiCryptoHelper.Encrypt(ArchiCryptoHelper.ECryptoMethod.AES, Bot.BotConfig.SteamPassword))) + FormatBotResponse(string.Format(Strings.BotEncryptedPassword, ArchiCryptoHelper.ECryptoMethod.ProtectedDataForCurrentUser, ArchiCryptoHelper.Encrypt(ArchiCryptoHelper.ECryptoMethod.ProtectedDataForCurrentUser, Bot.BotConfig.SteamPassword))); + string response = FormatBotResponse(string.Format(Strings.BotEncryptedPassword, ArchiCryptoHelper.ECryptoMethod.AES, ArchiCryptoHelper.Encrypt(ArchiCryptoHelper.ECryptoMethod.AES, Bot.BotConfig.OriginalSteamPassword))) + FormatBotResponse(string.Format(Strings.BotEncryptedPassword, ArchiCryptoHelper.ECryptoMethod.ProtectedDataForCurrentUser, ArchiCryptoHelper.Encrypt(ArchiCryptoHelper.ECryptoMethod.ProtectedDataForCurrentUser, Bot.BotConfig.OriginalSteamPassword))); return response; } diff --git a/ArchiSteamFarm/IPC/Controllers/Api/BotController.cs b/ArchiSteamFarm/IPC/Controllers/Api/BotController.cs index f09a6c249..955061ea9 100644 --- a/ArchiSteamFarm/IPC/Controllers/Api/BotController.cs +++ b/ArchiSteamFarm/IPC/Controllers/Api/BotController.cs @@ -98,8 +98,8 @@ namespace ArchiSteamFarm.IPC.Controllers.Api { request.BotConfig.SteamParentalPIN = bot.BotConfig.SteamParentalPIN; } - if (string.IsNullOrEmpty(request.BotConfig.SteamPassword) && !string.IsNullOrEmpty(bot.BotConfig.SteamPassword)) { - request.BotConfig.SteamPassword = bot.BotConfig.SteamPassword; + if (string.IsNullOrEmpty(request.BotConfig.OriginalSteamPassword) && !string.IsNullOrEmpty(bot.BotConfig.OriginalSteamPassword)) { + request.BotConfig.OriginalSteamPassword = bot.BotConfig.OriginalSteamPassword; } }