From 59ae27c0d0ea838d2157954f83ddd31368f538dc Mon Sep 17 00:00:00 2001 From: Archi Date: Tue, 25 May 2021 00:08:16 +0200 Subject: [PATCH] Avoid even asking for login keys if it's not needed ASF is already smart enough to not >use< a login key when it's not needed, but the sole fact of asking for it might screw up Valve's backend and in result cause issues for the client, totally for no reason, as we're not going to use it anyway. The original idea was to keep it around "just in case" if the user removed his password or 2FA, but that is completely moot the moment we realize the alone fact of that bool property being set can cause the problems. Login keys should only be used if both: a) User left it enabled in the config b) We can't guarantee all the details during login procedure, that is mainly a missing password in the config and/or lack of ASF 2FA. We're not going to enhance the logic for completely insecure accounts as they should opt into SteamGuard or 2FA ASAP, making the login key needed. Also fix setter visibility for BotConfig while at it, if plugins want to set those properties themselves, they have Bot.SetUserInput() function instead. --- ArchiSteamFarm/Steam/Bot.cs | 25 ++++++++++++++--------- ArchiSteamFarm/Steam/Storage/BotConfig.cs | 18 ++++++++-------- ArchiSteamFarm/Storage/GlobalConfig.cs | 2 +- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/ArchiSteamFarm/Steam/Bot.cs b/ArchiSteamFarm/Steam/Bot.cs index d65fe9f7c..1a404be0d 100644 --- a/ArchiSteamFarm/Steam/Bot.cs +++ b/ArchiSteamFarm/Steam/Bot.cs @@ -177,6 +177,11 @@ namespace ArchiSteamFarm.Steam { } } + /// + /// Login keys are not guaranteed to be valid, we should use them only if we don't have full details available from the user + /// + private bool ShouldUseLoginKeys => BotConfig.UseLoginKeys && (!BotConfig.IsSteamPasswordSet || string.IsNullOrEmpty(BotConfig.DecryptedSteamPassword) || !HasMobileAuthenticator); + [JsonProperty(PropertyName = SharedInfo.UlongCompatibilityStringPrefix + nameof(SteamID))] private string SSteamID => SteamID.ToString(CultureInfo.InvariantCulture); @@ -961,10 +966,12 @@ namespace ArchiSteamFarm.Steam { switch (inputType) { case ASF.EUserInputType.Login: BotConfig.SteamLogin = inputValue; + BotConfig.IsSteamLoginSet = false; break; case ASF.EUserInputType.Password: BotConfig.DecryptedSteamPassword = inputValue; + BotConfig.IsSteamPasswordSet = false; break; case ASF.EUserInputType.SteamGuard: @@ -981,6 +988,7 @@ namespace ArchiSteamFarm.Steam { } BotConfig.SteamParentalCode = inputValue; + BotConfig.IsSteamParentalCodeSet = false; break; case ASF.EUserInputType.TwoFactorAuthentication: @@ -2320,15 +2328,12 @@ namespace ArchiSteamFarm.Steam { string? loginKey = null; - if (BotConfig.UseLoginKeys) { - // Login keys are not guaranteed to be valid, we should use them only if we don't have full details available from the user - if (string.IsNullOrEmpty(BotConfig.DecryptedSteamPassword) || (string.IsNullOrEmpty(AuthCode) && string.IsNullOrEmpty(TwoFactorCode) && !HasMobileAuthenticator)) { - loginKey = BotDatabase.LoginKey; + if (ShouldUseLoginKeys && string.IsNullOrEmpty(AuthCode) && string.IsNullOrEmpty(TwoFactorCode)) { + loginKey = BotDatabase.LoginKey; - // Decrypt login key if needed - if (!string.IsNullOrEmpty(loginKey) && (loginKey!.Length > 19) && (BotConfig.PasswordFormat != ArchiCryptoHelper.ECryptoMethod.PlainText)) { - loginKey = ArchiCryptoHelper.Decrypt(BotConfig.PasswordFormat, loginKey); - } + // Decrypt login key if needed + if (!string.IsNullOrEmpty(loginKey) && (loginKey!.Length > 19) && (BotConfig.PasswordFormat != ArchiCryptoHelper.ECryptoMethod.PlainText)) { + loginKey = ArchiCryptoHelper.Decrypt(BotConfig.PasswordFormat, loginKey); } } else { // If we're not using login keys, ensure we don't have any saved @@ -2388,7 +2393,7 @@ namespace ArchiSteamFarm.Steam { LoginKey = loginKey, Password = password, SentryFileHash = sentryFileHash, - ShouldRememberPassword = BotConfig.UseLoginKeys, + ShouldRememberPassword = ShouldUseLoginKeys, TwoFactorCode = TwoFactorCode, Username = username }; @@ -3004,7 +3009,7 @@ namespace ArchiSteamFarm.Steam { throw new ArgumentNullException(nameof(callback)); } - if (!BotConfig.UseLoginKeys) { + if (!ShouldUseLoginKeys) { return; } diff --git a/ArchiSteamFarm/Steam/Storage/BotConfig.cs b/ArchiSteamFarm/Steam/Storage/BotConfig.cs index 69083e7f2..419d1785f 100644 --- a/ArchiSteamFarm/Steam/Storage/BotConfig.cs +++ b/ArchiSteamFarm/Steam/Storage/BotConfig.cs @@ -212,7 +212,7 @@ namespace ArchiSteamFarm.Steam.Storage { public string? SteamLogin { get => BackingSteamLogin; - set { + internal set { IsSteamLoginSet = true; BackingSteamLogin = value; } @@ -225,7 +225,7 @@ namespace ArchiSteamFarm.Steam.Storage { public string? SteamParentalCode { get => BackingSteamParentalCode; - set { + internal set { IsSteamParentalCodeSet = true; BackingSteamParentalCode = value; } @@ -235,7 +235,7 @@ namespace ArchiSteamFarm.Steam.Storage { public string? SteamPassword { get => BackingSteamPassword; - set { + internal set { IsSteamPasswordSet = true; BackingSteamPassword = value; } @@ -296,9 +296,9 @@ namespace ArchiSteamFarm.Steam.Storage { } } - internal bool IsSteamLoginSet { get; private set; } - internal bool IsSteamParentalCodeSet { get; private set; } - internal bool IsSteamPasswordSet { get; private set; } + internal bool IsSteamLoginSet { get; set; } + internal bool IsSteamParentalCodeSet { get; set; } + internal bool IsSteamPasswordSet { get; set; } internal bool Saving { get; set; } private string? BackingSteamLogin = DefaultSteamLogin; @@ -561,10 +561,10 @@ namespace ArchiSteamFarm.Steam.Storage { public bool ShouldSerializeShutdownOnFarmingFinished() => !Saving || (ShutdownOnFarmingFinished != DefaultShutdownOnFarmingFinished); public bool ShouldSerializeSkipRefundableGames() => !Saving || (SkipRefundableGames != DefaultSkipRefundableGames); public bool ShouldSerializeSSteamMasterClanID() => !Saving; - public bool ShouldSerializeSteamLogin() => Saving && (SteamLogin != DefaultSteamLogin); + public bool ShouldSerializeSteamLogin() => Saving && IsSteamLoginSet && (SteamLogin != DefaultSteamLogin); public bool ShouldSerializeSteamMasterClanID() => !Saving || (SteamMasterClanID != DefaultSteamMasterClanID); - public bool ShouldSerializeSteamParentalCode() => Saving && (SteamParentalCode != DefaultSteamParentalCode); - public bool ShouldSerializeSteamPassword() => Saving && (SteamPassword != DefaultSteamPassword); + public bool ShouldSerializeSteamParentalCode() => Saving && IsSteamParentalCodeSet && (SteamParentalCode != DefaultSteamParentalCode); + public bool ShouldSerializeSteamPassword() => Saving && IsSteamPasswordSet && (SteamPassword != DefaultSteamPassword); public bool ShouldSerializeSteamTradeToken() => !Saving || (SteamTradeToken != DefaultSteamTradeToken); public bool ShouldSerializeSteamUserPermissions() => !Saving || ((SteamUserPermissions != DefaultSteamUserPermissions) && ((SteamUserPermissions.Count != DefaultSteamUserPermissions.Count) || SteamUserPermissions.Except(DefaultSteamUserPermissions).Any())); public bool ShouldSerializeTradingPreferences() => !Saving || (TradingPreferences != DefaultTradingPreferences); diff --git a/ArchiSteamFarm/Storage/GlobalConfig.cs b/ArchiSteamFarm/Storage/GlobalConfig.cs index dd8e9ed72..5282d10d0 100644 --- a/ArchiSteamFarm/Storage/GlobalConfig.cs +++ b/ArchiSteamFarm/Storage/GlobalConfig.cs @@ -444,7 +444,7 @@ namespace ArchiSteamFarm.Storage { public bool ShouldSerializeUpdateChannel() => !Saving || (UpdateChannel != DefaultUpdateChannel); public bool ShouldSerializeUpdatePeriod() => !Saving || (UpdatePeriod != DefaultUpdatePeriod); public bool ShouldSerializeWebLimiterDelay() => !Saving || (WebLimiterDelay != DefaultWebLimiterDelay); - public bool ShouldSerializeWebProxyPassword() => Saving && (WebProxyPassword != DefaultWebProxyPassword); + public bool ShouldSerializeWebProxyPassword() => Saving && IsWebProxyPasswordSet && (WebProxyPassword != DefaultWebProxyPassword); public bool ShouldSerializeWebProxyText() => !Saving || (WebProxyText != DefaultWebProxyText); public bool ShouldSerializeWebProxyUsername() => !Saving || (WebProxyUsername != DefaultWebProxyUsername);