Code cleanup

This commit is contained in:
JustArchi 2018-08-19 14:37:23 +02:00
parent 57a2cdb684
commit 13e835c3b7
7 changed files with 22 additions and 21 deletions

View file

@ -23,9 +23,10 @@ using System;
using System.Security.Cryptography;
using System.Text;
using ArchiSteamFarm.Localization;
using SteamKit2;
namespace ArchiSteamFarm {
internal static class CryptoHelper {
internal static class ArchiCryptoHelper {
private static byte[] EncryptionKey = Encoding.UTF8.GetBytes(nameof(ArchiSteamFarm));
internal static string Decrypt(ECryptoMethod cryptoMethod, string encrypted) {
@ -88,7 +89,7 @@ namespace ArchiSteamFarm {
}
byte[] decryptedData = Convert.FromBase64String(encrypted);
decryptedData = SteamKit2.CryptoHelper.SymmetricDecrypt(decryptedData, key);
decryptedData = CryptoHelper.SymmetricDecrypt(decryptedData, key);
return Encoding.UTF8.GetString(decryptedData);
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
@ -132,7 +133,7 @@ namespace ArchiSteamFarm {
}
byte[] encryptedData = Encoding.UTF8.GetBytes(decrypted);
encryptedData = SteamKit2.CryptoHelper.SymmetricEncrypt(encryptedData, key);
encryptedData = CryptoHelper.SymmetricEncrypt(encryptedData, key);
return Convert.ToBase64String(encryptedData);
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);
@ -169,4 +170,4 @@ namespace ArchiSteamFarm {
ProtectedDataForCurrentUser
}
}
}
}

View file

@ -984,7 +984,7 @@ namespace ArchiSteamFarm {
string sessionID = Convert.ToBase64String(Encoding.UTF8.GetBytes(steamID.ToString()));
// Generate an AES session key
byte[] sessionKey = SteamKit2.CryptoHelper.GenerateRandomBlock(32);
byte[] sessionKey = CryptoHelper.GenerateRandomBlock(32);
// RSA encrypt it with the public key for the universe we're on
byte[] cryptedSessionKey;
@ -997,7 +997,7 @@ namespace ArchiSteamFarm {
Array.Copy(Encoding.ASCII.GetBytes(webAPIUserNonce), loginKey, webAPIUserNonce.Length);
// AES encrypt the loginkey with our session key
byte[] cryptedLoginKey = SteamKit2.CryptoHelper.SymmetricEncrypt(loginKey, sessionKey);
byte[] cryptedLoginKey = CryptoHelper.SymmetricEncrypt(loginKey, sessionKey);
// Do the magic
Bot.ArchiLogger.LogGenericInfo(string.Format(Strings.LoggingIn, ISteamUserAuth));

View file

@ -1832,7 +1832,7 @@ namespace ArchiSteamFarm {
if (File.Exists(SentryFilePath)) {
try {
byte[] sentryFileContent = await RuntimeCompatibility.File.ReadAllBytesAsync(SentryFilePath).ConfigureAwait(false);
sentryFileHash = SteamKit2.CryptoHelper.SHAHash(sentryFileContent);
sentryFileHash = CryptoHelper.SHAHash(sentryFileContent);
} catch (Exception e) {
ArchiLogger.LogGenericException(e);
@ -1850,8 +1850,8 @@ namespace ArchiSteamFarm {
loginKey = BotDatabase.LoginKey;
// Decrypt login key if needed
if (!string.IsNullOrEmpty(loginKey) && (loginKey.Length > 19) && (BotConfig.PasswordFormat != CryptoHelper.ECryptoMethod.PlainText)) {
loginKey = CryptoHelper.Decrypt(BotConfig.PasswordFormat, loginKey);
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
@ -2344,8 +2344,8 @@ namespace ArchiSteamFarm {
}
string loginKey = callback.LoginKey;
if (BotConfig.PasswordFormat != CryptoHelper.ECryptoMethod.PlainText) {
loginKey = CryptoHelper.Encrypt(BotConfig.PasswordFormat, loginKey);
if (BotConfig.PasswordFormat != ArchiCryptoHelper.ECryptoMethod.PlainText) {
loginKey = ArchiCryptoHelper.Encrypt(BotConfig.PasswordFormat, loginKey);
}
await BotDatabase.SetLoginKey(loginKey).ConfigureAwait(false);
@ -4127,7 +4127,7 @@ namespace ArchiSteamFarm {
return FormatBotResponse(string.Format(Strings.ErrorIsEmpty, nameof(BotConfig.SteamPassword)));
}
string response = FormatBotResponse(string.Format(Strings.BotEncryptedPassword, CryptoHelper.ECryptoMethod.AES, CryptoHelper.Encrypt(CryptoHelper.ECryptoMethod.AES, BotConfig.SteamPassword))) + FormatBotResponse(string.Format(Strings.BotEncryptedPassword, CryptoHelper.ECryptoMethod.ProtectedDataForCurrentUser, CryptoHelper.Encrypt(CryptoHelper.ECryptoMethod.ProtectedDataForCurrentUser, BotConfig.SteamPassword)));
string response = FormatBotResponse(string.Format(Strings.BotEncryptedPassword, ArchiCryptoHelper.ECryptoMethod.AES, ArchiCryptoHelper.Encrypt(ArchiCryptoHelper.ECryptoMethod.AES, BotConfig.SteamPassword))) + FormatBotResponse(string.Format(Strings.BotEncryptedPassword, ArchiCryptoHelper.ECryptoMethod.ProtectedDataForCurrentUser, ArchiCryptoHelper.Encrypt(ArchiCryptoHelper.ECryptoMethod.ProtectedDataForCurrentUser, BotConfig.SteamPassword)));
return response;
}

View file

@ -45,7 +45,7 @@ namespace ArchiSteamFarm {
private const bool DefaultIdlePriorityQueueOnly = false;
private const bool DefaultIdleRefundableGames = true;
private const EPersonaState DefaultOnlineStatus = EPersonaState.Online;
private const CryptoHelper.ECryptoMethod DefaultPasswordFormat = CryptoHelper.ECryptoMethod.PlainText;
private const ArchiCryptoHelper.ECryptoMethod DefaultPasswordFormat = ArchiCryptoHelper.ECryptoMethod.PlainText;
private const bool DefaultPaused = false;
private const ERedeemingPreferences DefaultRedeemingPreferences = ERedeemingPreferences.None;
private const bool DefaultSendOnFarmingFinished = false;
@ -109,7 +109,7 @@ namespace ArchiSteamFarm {
internal readonly EPersonaState OnlineStatus = DefaultOnlineStatus;
[JsonProperty(Required = Required.DisallowNull)]
internal readonly CryptoHelper.ECryptoMethod PasswordFormat = DefaultPasswordFormat;
internal readonly ArchiCryptoHelper.ECryptoMethod PasswordFormat = DefaultPasswordFormat;
[JsonProperty(Required = Required.DisallowNull)]
internal readonly bool Paused = DefaultPaused;
@ -155,7 +155,7 @@ namespace ArchiSteamFarm {
return null;
}
return PasswordFormat == CryptoHelper.ECryptoMethod.PlainText ? EncryptedSteamPassword : CryptoHelper.Decrypt(PasswordFormat, EncryptedSteamPassword);
return PasswordFormat == ArchiCryptoHelper.ECryptoMethod.PlainText ? EncryptedSteamPassword : ArchiCryptoHelper.Decrypt(PasswordFormat, EncryptedSteamPassword);
}
set {
if (string.IsNullOrEmpty(value)) {
@ -163,7 +163,7 @@ namespace ArchiSteamFarm {
return;
}
EncryptedSteamPassword = PasswordFormat == CryptoHelper.ECryptoMethod.PlainText ? value : CryptoHelper.Encrypt(PasswordFormat, value);
EncryptedSteamPassword = PasswordFormat == ArchiCryptoHelper.ECryptoMethod.PlainText ? value : ArchiCryptoHelper.Encrypt(PasswordFormat, value);
}
}
@ -245,7 +245,7 @@ namespace ArchiSteamFarm {
return null;
}
if (!Enum.IsDefined(typeof(CryptoHelper.ECryptoMethod), botConfig.PasswordFormat)) {
if (!Enum.IsDefined(typeof(ArchiCryptoHelper.ECryptoMethod), botConfig.PasswordFormat)) {
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorConfigPropertyInvalid, nameof(botConfig.PasswordFormat), botConfig.PasswordFormat));
return null;
}

View file

@ -851,7 +851,7 @@ namespace ArchiSteamFarm {
GamesToFarm.Clear();
List<Task> tasks = new List<Task>();
HashSet<Task> tasks = new HashSet<Task>();
Task mainTask = CheckPage(htmlDocument);
switch (Program.GlobalConfig.OptimizationMode) {
@ -1072,4 +1072,4 @@ namespace ArchiSteamFarm {
public override int GetHashCode() => (int) (AppID - 1 - int.MaxValue);
}
}
}
}

View file

@ -28,7 +28,7 @@ namespace ArchiSteamFarm.JSON {
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]
internal sealed class ReleaseResponse {
[JsonProperty(PropertyName = "assets", Required = Required.Always)]
internal readonly List<Asset> Assets;
internal readonly HashSet<Asset> Assets;
[JsonProperty(PropertyName = "tag_name", Required = Required.Always)]
internal readonly string Tag;

View file

@ -158,7 +158,7 @@ namespace ArchiSteamFarm {
return;
}
CryptoHelper.SetEncryptionKey(cryptKey);
ArchiCryptoHelper.SetEncryptionKey(cryptKey);
}
private static void HandlePathArgument(string path) {