added Manifest.GetAccount method

added convertion to base64 when saving accounts
This commit is contained in:
Carson McManus 2016-08-22 18:42:44 -04:00
parent 6fab87b485
commit d33ddc0d4a

View file

@ -205,15 +205,8 @@ public class Manifest
} }
} while (newPassKey != confirmPassKey); } while (newPassKey != confirmPassKey);
if (!this.ChangeEncryptionKey(null, newPassKey))
{
Console.WriteLine("Unable to set passkey."); Console.WriteLine("Unable to set passkey.");
return null; return null;
}
else
{
Console.WriteLine("Passkey successfully set.");
}
return newPassKey; return newPassKey;
} }
@ -224,6 +217,19 @@ public class Manifest
List<SteamAuth.SteamGuardAccount> accounts = new List<SteamAuth.SteamGuardAccount>(); List<SteamAuth.SteamGuardAccount> accounts = new List<SteamAuth.SteamGuardAccount>();
foreach (var entry in this.Entries) foreach (var entry in this.Entries)
{
var account = GetAccount(entry, passKey);
if (account == null) continue;
accounts.Add(account);
if (limit != -1 && limit >= accounts.Count)
break;
}
return accounts.ToArray();
}
public SteamGuardAccount GetAccount(ManifestEntry entry, string passKey = null)
{ {
string fileText = ""; string fileText = "";
Stream stream = null; Stream stream = null;
@ -258,20 +264,7 @@ public class Manifest
} }
stream.Close(); stream.Close();
var account = JsonConvert.DeserializeObject<SteamAuth.SteamGuardAccount>(fileText); return JsonConvert.DeserializeObject<SteamAuth.SteamGuardAccount>(fileText);
if (account == null) continue;
accounts.Add(account);
if (limit != -1 && limit >= accounts.Count)
break;
}
return accounts.ToArray();
}
public bool ChangeEncryptionKey(string oldKey, string newKey)
{
throw new NotSupportedException("Encrypted maFiles are not supported at this time.");
} }
public bool VerifyPasskey(string passkey) public bool VerifyPasskey(string passkey)
@ -359,10 +352,12 @@ public class Manifest
{ {
Stream stream = null; Stream stream = null;
FileStream fileStream = File.OpenWrite(Path.Combine(Program.SteamGuardPath, newEntry.Filename)); FileStream fileStream = File.OpenWrite(Path.Combine(Program.SteamGuardPath, newEntry.Filename));
MemoryStream ms = null;
RijndaelManaged aes256; RijndaelManaged aes256;
if (this.Encrypted) if (Encrypted)
{ {
ms = new MemoryStream();
byte[] key = GetEncryptionKey(passKey, newEntry.Salt); byte[] key = GetEncryptionKey(passKey, newEntry.Salt);
aes256 = new RijndaelManaged aes256 = new RijndaelManaged
@ -374,7 +369,7 @@ public class Manifest
}; };
ICryptoTransform decryptor = aes256.CreateDecryptor(aes256.Key, aes256.IV); ICryptoTransform decryptor = aes256.CreateDecryptor(aes256.Key, aes256.IV);
stream = new CryptoStream(fileStream, decryptor, CryptoStreamMode.Write); stream = new CryptoStream(ms, decryptor, CryptoStreamMode.Write);
} }
else else
{ {
@ -385,6 +380,12 @@ public class Manifest
{ {
writer.Write(jsonAccount); writer.Write(jsonAccount);
} }
if (Encrypted)
{
File.WriteAllText(Convert.ToBase64String(ms.ToArray()), Path.Combine(Program.SteamGuardPath, newEntry.Filename));
}
stream.Close(); stream.Close();
return true; return true;
} }