Use selected PasswordFormat also for login keys

This commit is contained in:
JustArchi
2016-10-15 21:09:53 +02:00
parent 7580544e27
commit 6aec98d3d0
4 changed files with 23 additions and 10 deletions

View File

@@ -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);
}

View File

@@ -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<uint> GamesPlayedWhileIdle = new HashSet<uint>();
[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));

View File

@@ -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;

View File

@@ -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
);