remove all the old C# stuff
This commit is contained in:
parent
5153bcd1dc
commit
3c05e95fda
10 changed files with 0 additions and 1569 deletions
|
@ -1,36 +0,0 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
|
||||
[assembly: AssemblyTitle("steamguard-cli")]
|
||||
[assembly: AssemblyDescription("https://github.com/dyc3/steamguard-cli")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("steamguard-cli")]
|
||||
[assembly: AssemblyCopyright("")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
[assembly: AssemblyVersion("0.3.5.1")]
|
||||
[assembly: AssemblyFileVersion("0.3.5.1")]
|
546
Manifest.cs
546
Manifest.cs
|
@ -1,546 +0,0 @@
|
|||
using Newtonsoft.Json;
|
||||
using SteamAuth;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace SteamGuard
|
||||
{
|
||||
public class Manifest
|
||||
{
|
||||
private const int PBKDF2_ITERATIONS = 50000; //Set to 50k to make program not unbearably slow. May increase in future.
|
||||
private const int SALT_LENGTH = 8;
|
||||
private const int KEY_SIZE_BYTES = 32;
|
||||
private const int IV_LENGTH = 16;
|
||||
|
||||
[JsonProperty("encrypted")]
|
||||
public bool Encrypted { get; set; }
|
||||
|
||||
[JsonProperty("first_run")]
|
||||
public bool FirstRun { get; set; } = true;
|
||||
|
||||
[JsonProperty("entries")]
|
||||
public List<ManifestEntry> Entries { get; set; }
|
||||
|
||||
[JsonProperty("periodic_checking")]
|
||||
public bool PeriodicChecking { get; set; } = false;
|
||||
|
||||
[JsonProperty("periodic_checking_interval")]
|
||||
public int PeriodicCheckingInterval { get; set; } = 5;
|
||||
|
||||
[JsonProperty("periodic_checking_checkall")]
|
||||
public bool CheckAllAccounts { get; set; } = false;
|
||||
|
||||
[JsonProperty("auto_confirm_market_transactions")]
|
||||
public bool AutoConfirmMarketTransactions { get; set; } = false;
|
||||
|
||||
[JsonProperty("auto_confirm_trades")]
|
||||
public bool AutoConfirmTrades { get; set; } = false;
|
||||
|
||||
private static Manifest _manifest { get; set; }
|
||||
|
||||
public static Manifest GetManifest(bool forceLoad = false)
|
||||
{
|
||||
// Check if already staticly loaded
|
||||
if (_manifest != null && !forceLoad)
|
||||
{
|
||||
return _manifest;
|
||||
}
|
||||
|
||||
// Find config dir and manifest file
|
||||
string maFile = Path.Combine(Program.SteamGuardPath, "manifest.json");
|
||||
|
||||
// If there's no config dir, create it
|
||||
if (!Directory.Exists(Program.SteamGuardPath))
|
||||
{
|
||||
_manifest = _generateNewManifest();
|
||||
return _manifest;
|
||||
}
|
||||
|
||||
// If there's no manifest, create it
|
||||
if (!File.Exists(maFile))
|
||||
{
|
||||
Utils.Verbose("warn: No manifest file found at {0}", maFile);
|
||||
bool? createNewManifest = Program.SteamGuardPath ==
|
||||
Program.defaultSteamGuardPath.Replace("~", Environment.GetEnvironmentVariable("HOME")) ? true : (bool?) null;
|
||||
while (createNewManifest == null)
|
||||
{
|
||||
Console.Write($"Generate new manifest.json in {Program.SteamGuardPath}? [Y/n]");
|
||||
var answer = Console.ReadLine();
|
||||
if (answer != null)
|
||||
createNewManifest = !answer.StartsWith("n") && !answer.StartsWith("N");
|
||||
}
|
||||
if ((bool) createNewManifest)
|
||||
{
|
||||
_manifest = _generateNewManifest(true);
|
||||
return _manifest;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string manifestContents = File.ReadAllText(maFile);
|
||||
_manifest = JsonConvert.DeserializeObject<Manifest>(manifestContents);
|
||||
|
||||
if (_manifest.Encrypted && _manifest.Entries.Count == 0)
|
||||
{
|
||||
_manifest.Encrypted = false;
|
||||
_manifest.Save();
|
||||
}
|
||||
|
||||
_manifest.RecomputeExistingEntries();
|
||||
|
||||
Utils.Verbose($"{_manifest.Entries.Count} accounts loaded");
|
||||
return _manifest;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("error: Could not open manifest file: {0}", ex.ToString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Manifest _generateNewManifest(bool scanDir = false)
|
||||
{
|
||||
Utils.Verbose("Generating new manifest...");
|
||||
|
||||
// No directory means no manifest file anyways.
|
||||
Manifest newManifest = new Manifest();
|
||||
newManifest.Encrypted = false;
|
||||
newManifest.PeriodicCheckingInterval = 5;
|
||||
newManifest.PeriodicChecking = false;
|
||||
newManifest.AutoConfirmMarketTransactions = false;
|
||||
newManifest.AutoConfirmTrades = false;
|
||||
newManifest.Entries = new List<ManifestEntry>();
|
||||
newManifest.FirstRun = true;
|
||||
|
||||
// Take a pre-manifest version and generate a manifest for it.
|
||||
if (scanDir)
|
||||
{
|
||||
if (Directory.Exists(Program.SteamGuardPath))
|
||||
{
|
||||
DirectoryInfo dir = new DirectoryInfo(Program.SteamGuardPath);
|
||||
var files = dir.GetFiles();
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
if (file.Extension != ".maFile") continue;
|
||||
|
||||
string contents = File.ReadAllText(file.FullName);
|
||||
try
|
||||
{
|
||||
SteamGuardAccount account = JsonConvert.DeserializeObject<SteamGuardAccount>(contents);
|
||||
ManifestEntry newEntry = new ManifestEntry()
|
||||
{
|
||||
Filename = file.Name,
|
||||
SteamID = account.Session.SteamID
|
||||
};
|
||||
newManifest.Entries.Add(newEntry);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utils.Verbose("warn: {0}", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
if (newManifest.Entries.Count > 0)
|
||||
{
|
||||
newManifest.Save();
|
||||
newManifest.PromptSetupPassKey(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (newManifest.Save())
|
||||
{
|
||||
return newManifest;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public class IncorrectPassKeyException : Exception { }
|
||||
public class ManifestNotEncryptedException : Exception { }
|
||||
|
||||
// TODO: move PromptForPassKey to Program.cs
|
||||
// TODO: make PromptForPassKey more secure
|
||||
public string PromptForPassKey()
|
||||
{
|
||||
if (!this.Encrypted)
|
||||
{
|
||||
throw new ManifestNotEncryptedException();
|
||||
}
|
||||
|
||||
bool passKeyValid = false;
|
||||
string passKey = "";
|
||||
while (!passKeyValid)
|
||||
{
|
||||
Console.WriteLine("Please enter encryption password: ");
|
||||
passKey = Utils.ReadLineSecure();
|
||||
if (passKey == "")
|
||||
continue;
|
||||
passKeyValid = this.VerifyPasskey(passKey);
|
||||
if (!passKeyValid)
|
||||
{
|
||||
Console.WriteLine("Incorrect.");
|
||||
}
|
||||
}
|
||||
return passKey;
|
||||
}
|
||||
|
||||
// TODO: move PromptSetupPassKey to Program.cs
|
||||
public string PromptSetupPassKey(bool inAccountSetupProcess = false)
|
||||
{
|
||||
if (inAccountSetupProcess)
|
||||
{
|
||||
Console.Write("Would you like to use encryption? [Y/n] ");
|
||||
string doEncryptAnswer = Console.ReadLine();
|
||||
if (doEncryptAnswer == "n" || doEncryptAnswer == "N")
|
||||
{
|
||||
Console.WriteLine("WARNING: You chose to not encrypt your files. Doing so imposes a security risk for yourself. If an attacker were to gain access to your computer, they could completely lock you out of your account and steal all your items.");
|
||||
Console.WriteLine("You may add encryption later using the --encrypt argument.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
string newPassKey = "";
|
||||
string confirmPassKey = "";
|
||||
do
|
||||
{
|
||||
Console.Write("Enter" + (inAccountSetupProcess ? " " : " new ") + "passkey: ");
|
||||
newPassKey = Utils.ReadLineSecure();
|
||||
Console.Write("Confirm" + (inAccountSetupProcess ? " " : " new ") + "passkey: ");
|
||||
confirmPassKey = Utils.ReadLineSecure();
|
||||
|
||||
if (newPassKey != confirmPassKey)
|
||||
{
|
||||
Console.WriteLine("Passkeys do not match.");
|
||||
}
|
||||
} while (newPassKey != confirmPassKey || newPassKey == "");
|
||||
|
||||
return newPassKey;
|
||||
}
|
||||
|
||||
public SteamAuth.SteamGuardAccount[] GetAllAccounts(string passKey = null, int limit = -1)
|
||||
{
|
||||
if (passKey == null && this.Encrypted) return new SteamGuardAccount[0];
|
||||
|
||||
List<SteamAuth.SteamGuardAccount> accounts = new List<SteamAuth.SteamGuardAccount>();
|
||||
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 = "";
|
||||
Stream stream = null;
|
||||
RijndaelManaged aes256;
|
||||
|
||||
string filename = Path.Combine(Program.SteamGuardPath, entry.Filename);
|
||||
if (this.Encrypted)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream(Convert.FromBase64String(File.ReadAllText(filename)));
|
||||
byte[] key = GetEncryptionKey(passKey, entry.Salt);
|
||||
|
||||
aes256 = new RijndaelManaged
|
||||
{
|
||||
IV = Convert.FromBase64String(entry.IV),
|
||||
Key = key,
|
||||
Padding = PaddingMode.PKCS7,
|
||||
Mode = CipherMode.CBC
|
||||
};
|
||||
|
||||
ICryptoTransform decryptor = aes256.CreateDecryptor(aes256.Key, aes256.IV);
|
||||
stream = new CryptoStream(ms, decryptor, CryptoStreamMode.Read);
|
||||
Utils.Verbose($"Decrypting {filename}...");
|
||||
}
|
||||
else
|
||||
{
|
||||
FileStream fileStream = File.OpenRead(filename);
|
||||
stream = fileStream;
|
||||
}
|
||||
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
{
|
||||
fileText = reader.ReadToEnd();
|
||||
}
|
||||
stream.Close();
|
||||
|
||||
return JsonConvert.DeserializeObject<SteamAuth.SteamGuardAccount>(fileText);
|
||||
}
|
||||
|
||||
public bool VerifyPasskey(string passkey)
|
||||
{
|
||||
if (!this.Encrypted || this.Entries.Count == 0) return true;
|
||||
|
||||
var accounts = this.GetAllAccounts(passkey, 1);
|
||||
return accounts != null && accounts.Length == 1;
|
||||
}
|
||||
|
||||
public bool RemoveAccount(SteamGuardAccount account, bool deleteMaFile = true)
|
||||
{
|
||||
ManifestEntry entry = (from e in this.Entries where e.SteamID == account.Session.SteamID select e).FirstOrDefault();
|
||||
if (entry == null) return true; // If something never existed, did you do what they asked?
|
||||
|
||||
string filename = Path.Combine(Program.SteamGuardPath, entry.Filename);
|
||||
this.Entries.Remove(entry);
|
||||
|
||||
if (this.Entries.Count == 0)
|
||||
{
|
||||
this.Encrypted = false;
|
||||
}
|
||||
|
||||
if (this.Save() && deleteMaFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(filename);
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool SaveAccount(SteamGuardAccount account, bool encrypt, string passKey = null, string salt = null, string iV = null)
|
||||
{
|
||||
if (encrypt && (String.IsNullOrEmpty(passKey) || String.IsNullOrEmpty(salt) || String.IsNullOrEmpty(iV))) return false;
|
||||
|
||||
string jsonAccount = JsonConvert.SerializeObject(account);
|
||||
|
||||
string filename = account.Session.SteamID.ToString() + ".maFile";
|
||||
Utils.Verbose($"Saving account {account.AccountName} to {filename}...");
|
||||
|
||||
ManifestEntry newEntry = new ManifestEntry()
|
||||
{
|
||||
SteamID = account.Session.SteamID,
|
||||
IV = iV,
|
||||
Salt = salt,
|
||||
Filename = filename
|
||||
};
|
||||
|
||||
bool foundExistingEntry = false;
|
||||
for (int i = 0; i < this.Entries.Count; i++)
|
||||
{
|
||||
if (this.Entries[i].SteamID == account.Session.SteamID)
|
||||
{
|
||||
this.Entries[i] = newEntry;
|
||||
foundExistingEntry = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundExistingEntry)
|
||||
{
|
||||
this.Entries.Add(newEntry);
|
||||
}
|
||||
|
||||
bool wasEncrypted = this.Encrypted;
|
||||
this.Encrypted = encrypt;
|
||||
|
||||
if (!this.Save())
|
||||
{
|
||||
this.Encrypted = wasEncrypted;
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Stream stream = null;
|
||||
MemoryStream ms = null;
|
||||
RijndaelManaged aes256;
|
||||
|
||||
if (encrypt)
|
||||
{
|
||||
ms = new MemoryStream();
|
||||
byte[] key = GetEncryptionKey(passKey, newEntry.Salt);
|
||||
|
||||
aes256 = new RijndaelManaged
|
||||
{
|
||||
IV = Convert.FromBase64String(newEntry.IV),
|
||||
Key = key,
|
||||
Padding = PaddingMode.PKCS7,
|
||||
Mode = CipherMode.CBC
|
||||
};
|
||||
|
||||
ICryptoTransform encryptor = aes256.CreateEncryptor(aes256.Key, aes256.IV);
|
||||
stream = new CryptoStream(ms, encryptor, CryptoStreamMode.Write);
|
||||
}
|
||||
else
|
||||
{
|
||||
// An unencrypted maFile is shorter than the encrypted version,
|
||||
// so when an unencrypted maFile gets written this way, the file does not get wiped
|
||||
// leaving encrypted text after the final } bracket. Deleting and recreating the file fixes this.
|
||||
File.Delete(Path.Combine(Program.SteamGuardPath, newEntry.Filename));
|
||||
stream = File.OpenWrite(Path.Combine(Program.SteamGuardPath, newEntry.Filename)); // open or create
|
||||
}
|
||||
|
||||
using (StreamWriter writer = new StreamWriter(stream))
|
||||
{
|
||||
writer.Write(jsonAccount);
|
||||
}
|
||||
|
||||
if (encrypt)
|
||||
{
|
||||
File.WriteAllText(Path.Combine(Program.SteamGuardPath, newEntry.Filename), Convert.ToBase64String(ms.ToArray()));
|
||||
}
|
||||
|
||||
stream.Close();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utils.Verbose("error: {0}", ex.ToString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Save()
|
||||
{
|
||||
string filename = Path.Combine(Program.SteamGuardPath, "manifest.json");
|
||||
if (!Directory.Exists(Program.SteamGuardPath))
|
||||
{
|
||||
try
|
||||
{
|
||||
Utils.Verbose("Creating {0}", Program.SteamGuardPath);
|
||||
Directory.CreateDirectory(Program.SteamGuardPath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utils.Verbose($"error: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string contents = JsonConvert.SerializeObject(this);
|
||||
File.WriteAllText(filename, contents);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utils.Verbose($"error: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void RecomputeExistingEntries()
|
||||
{
|
||||
List<ManifestEntry> newEntries = new List<ManifestEntry>();
|
||||
|
||||
foreach (var entry in this.Entries)
|
||||
{
|
||||
string filename = Path.Combine(Program.SteamGuardPath, entry.Filename);
|
||||
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
newEntries.Add(entry);
|
||||
}
|
||||
}
|
||||
|
||||
this.Entries = newEntries;
|
||||
|
||||
if (this.Entries.Count == 0)
|
||||
{
|
||||
this.Encrypted = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveEntry(int from, int to)
|
||||
{
|
||||
if (from < 0 || to < 0 || from > Entries.Count || to > Entries.Count - 1) return;
|
||||
ManifestEntry sel = Entries[from];
|
||||
Entries.RemoveAt(from);
|
||||
Entries.Insert(to, sel);
|
||||
Save();
|
||||
}
|
||||
|
||||
public class ManifestEntry
|
||||
{
|
||||
[JsonProperty("encryption_iv")]
|
||||
public string IV { get; set; }
|
||||
|
||||
[JsonProperty("encryption_salt")]
|
||||
public string Salt { get; set; }
|
||||
|
||||
[JsonProperty("filename")]
|
||||
public string Filename { get; set; }
|
||||
|
||||
[JsonProperty("steamid")]
|
||||
public ulong SteamID { get; set; }
|
||||
}
|
||||
|
||||
/*
|
||||
Crypto Functions
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// Returns an 8-byte cryptographically random salt in base64 encoding
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetRandomSalt()
|
||||
{
|
||||
byte[] salt = new byte[SALT_LENGTH];
|
||||
using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider())
|
||||
{
|
||||
rng.GetBytes(salt);
|
||||
}
|
||||
return Convert.ToBase64String(salt);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a 16-byte cryptographically random initialization vector (IV) in base64 encoding
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetInitializationVector()
|
||||
{
|
||||
byte[] IV = new byte[IV_LENGTH];
|
||||
using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider())
|
||||
{
|
||||
rng.GetBytes(IV);
|
||||
}
|
||||
return Convert.ToBase64String(IV);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates an encryption key derived using a password, a random salt, and specified number of rounds of PBKDF2
|
||||
/// </summary>
|
||||
/// <param name="password"></param>
|
||||
/// <param name="salt"></param>
|
||||
/// <returns></returns>
|
||||
private static byte[] GetEncryptionKey(string password, string salt)
|
||||
{
|
||||
if (string.IsNullOrEmpty(password))
|
||||
{
|
||||
throw new ArgumentException("Password is empty");
|
||||
}
|
||||
if (string.IsNullOrEmpty(salt))
|
||||
{
|
||||
throw new ArgumentException("Salt is empty");
|
||||
}
|
||||
using (Rfc2898DeriveBytes pbkdf2 = new Rfc2898DeriveBytes(password, Convert.FromBase64String(salt), PBKDF2_ITERATIONS))
|
||||
{
|
||||
return pbkdf2.GetBytes(KEY_SIZE_BYTES);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
795
Program.cs
795
Program.cs
|
@ -1,795 +0,0 @@
|
|||
using Newtonsoft.Json;
|
||||
using SteamAuth;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SteamGuard
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public const string defaultSteamGuardPath = "~/maFiles";
|
||||
|
||||
public static string SteamGuardPath { get; set; } = defaultSteamGuardPath;
|
||||
public static Manifest Manifest { get; set; }
|
||||
public static SteamGuardAccount[] SteamGuardAccounts { get; set; }
|
||||
public static bool Verbose { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
string action = "";
|
||||
string user = "";
|
||||
string passkey = "";
|
||||
|
||||
// Parse cli arguments
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
{
|
||||
if (args[i].StartsWith("-"))
|
||||
{
|
||||
// TODO: there's gotta be some framework or tool or something for this
|
||||
if (args[i] == "-v" || args[i] == "--verbose")
|
||||
{
|
||||
Verbose = true;
|
||||
}
|
||||
else if (args[i] == "-m" || args[i] == "--mafiles-path")
|
||||
{
|
||||
i++;
|
||||
if (i < args.Length)
|
||||
{
|
||||
SteamGuardPath = args[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Expected path after {args[i-1]}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (args[i] == "-p" || args[i] == "--passkey")
|
||||
{
|
||||
i++;
|
||||
if (i < args.Length)
|
||||
{
|
||||
passkey = args[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Expected encryption passkey after {args[i-1]}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (args[i] == "--help" || args[i] == "-h")
|
||||
{
|
||||
ShowHelp();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else // Parse as action or username
|
||||
{
|
||||
if (string.IsNullOrEmpty(action))
|
||||
{
|
||||
if (args[i] == "add" || args[i] == "setup")
|
||||
{
|
||||
action = "setup";
|
||||
}
|
||||
else if (args[i] == "trade")
|
||||
{
|
||||
action = "trade";
|
||||
}
|
||||
else if (args[i] == "encrypt")
|
||||
{
|
||||
action = "encrypt";
|
||||
}
|
||||
else if (args[i] == "decrypt")
|
||||
{
|
||||
action = "decrypt";
|
||||
}
|
||||
else if (args[i] == "remove")
|
||||
{
|
||||
action = "remove";
|
||||
}
|
||||
else if (args[i] == "2fa" || args[i] == "code" || args[i] == "generate-code")
|
||||
{
|
||||
action = "generate-code";
|
||||
}
|
||||
else if (args[i] == "accept-all")
|
||||
{
|
||||
action = "accept-all";
|
||||
}
|
||||
else if (string.IsNullOrEmpty(user))
|
||||
{
|
||||
user = args[i];
|
||||
}
|
||||
}
|
||||
else if (string.IsNullOrEmpty(user))
|
||||
{
|
||||
user = args[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(action))
|
||||
{
|
||||
action = "generate-code";
|
||||
}
|
||||
|
||||
// Do some configuring
|
||||
SteamGuardPath = SteamGuardPath.Replace("~", Environment.GetEnvironmentVariable("HOME"));
|
||||
if (!Directory.Exists(SteamGuardPath))
|
||||
{
|
||||
if (SteamGuardPath == defaultSteamGuardPath.Replace("~", Environment.GetEnvironmentVariable("HOME")))
|
||||
{
|
||||
Utils.Verbose("warn: {0} does not exist, creating...", SteamGuardPath);
|
||||
Directory.CreateDirectory(SteamGuardPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("error: {0} does not exist.", SteamGuardPath);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Utils.Verbose($"Action: {action}");
|
||||
if (user.Length > 0)
|
||||
{
|
||||
Utils.Verbose($"User: {user}");
|
||||
}
|
||||
Utils.Verbose($"Passkey: {passkey.Length > 0 ? "[specified]" : "[not specified]" }");
|
||||
Utils.Verbose($"maFiles path: {SteamGuardPath}");
|
||||
|
||||
// Perform desired action
|
||||
switch (action)
|
||||
{
|
||||
case "generate-code":
|
||||
GenerateCode(user, passkey);
|
||||
break;
|
||||
case "encrypt": // Can also be used to change passkey
|
||||
Console.WriteLine(Encrypt(passkey));
|
||||
break;
|
||||
case "decrypt":
|
||||
Console.WriteLine(Decrypt(passkey));
|
||||
break;
|
||||
case "setup":
|
||||
Setup(user, passkey);
|
||||
break;
|
||||
case "trade":
|
||||
Trade(user, passkey);
|
||||
break;
|
||||
case "accept-all":
|
||||
AcceptAllTrades(user, passkey);
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("error: Unknown action: {0}", action);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void ShowHelp()
|
||||
{
|
||||
var descPadding = 26;
|
||||
var descWidth = Console.BufferWidth - descPadding;
|
||||
if (descWidth < 20)
|
||||
descWidth = 20;
|
||||
|
||||
var flags = new Dictionary<string, string>
|
||||
{
|
||||
{ "-h, --help", "Display this help message." },
|
||||
{ "-v, --verbose", "Display some extra information when the program is running." },
|
||||
{ "-m, --mafiles-path", "Specify which folder your maFiles are in. Ex: ~/maFiles" },
|
||||
{ "-p, --passkey", "Specify your encryption passkey." },
|
||||
};
|
||||
var actions = new Dictionary<string, string>
|
||||
{
|
||||
{ "code", "Generate a Steam Guard code for the specified user (if any) and exit. (default)" },
|
||||
{ "encrypt", "Encrypt your maFiles or change your encryption passkey." },
|
||||
{ "decrypt", "Remove encryption from your maFiles." },
|
||||
{ "add", "Set up Steam Guard for 2 factor authentication." },
|
||||
{ "trade", "Opens an interactive prompt to handle trade confirmations." },
|
||||
{ "accept-all", "Accepts all trade confirmations." }
|
||||
};
|
||||
|
||||
Console.WriteLine($"steamguard-cli - v{Assembly.GetExecutingAssembly().GetName().Version}");
|
||||
Console.WriteLine("usage: steamguard ACTION [STEAM USERNAME] [OPTIONS]...");
|
||||
Console.WriteLine();
|
||||
foreach (var flag in flags)
|
||||
{
|
||||
// word wrap the descriptions, if needed
|
||||
var desc = flag.Value;
|
||||
if (desc.Length > descWidth)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
for (int i = 0; i < desc.Length; i += descWidth)
|
||||
{
|
||||
if (i > 0)
|
||||
sb.Append("".PadLeft((flag.Key.StartsWith("--") ? 5 : 2) + descPadding));
|
||||
sb.AppendLine(desc.Substring(i, i + descWidth > desc.Length ? desc.Length - i : descWidth).Trim());
|
||||
}
|
||||
desc = sb.ToString().TrimEnd('\n');
|
||||
}
|
||||
Console.WriteLine($"{(flag.Key.StartsWith("--") ? " " : " " )}{flag.Key.PadRight(descPadding)}{desc}");
|
||||
}
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Actions:");
|
||||
foreach (var action in actions)
|
||||
{
|
||||
// word wrap the descriptions, if needed
|
||||
var desc = action.Value;
|
||||
if (desc.Length > descWidth)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
for (int i = 0; i < desc.Length; i += descWidth)
|
||||
{
|
||||
if (i > 0)
|
||||
sb.Append("".PadLeft(descPadding + 2));
|
||||
sb.AppendLine(desc.Substring(i, i + descWidth > desc.Length ? desc.Length - i : descWidth).Trim());
|
||||
}
|
||||
desc = sb.ToString().TrimEnd('\n');
|
||||
}
|
||||
Console.WriteLine($" {action.Key.PadRight(descPadding)}{desc}");
|
||||
}
|
||||
}
|
||||
|
||||
static void GenerateCode(string user = "", string passkey = "")
|
||||
{
|
||||
Utils.Verbose("Aligning time...");
|
||||
TimeAligner.AlignTime();
|
||||
Utils.Verbose("Opening manifest...");
|
||||
Manifest = Manifest.GetManifest(true);
|
||||
Utils.Verbose("Reading accounts from manifest...");
|
||||
if (Manifest.Encrypted)
|
||||
{
|
||||
if (string.IsNullOrEmpty(passkey))
|
||||
{
|
||||
passkey = Manifest.PromptForPassKey();
|
||||
}
|
||||
SteamGuardAccounts = Manifest.GetAllAccounts(passkey);
|
||||
}
|
||||
else
|
||||
{
|
||||
SteamGuardAccounts = Manifest.GetAllAccounts();
|
||||
}
|
||||
if (SteamGuardAccounts.Length == 0)
|
||||
{
|
||||
Console.WriteLine("error: No accounts read.");
|
||||
return;
|
||||
}
|
||||
Utils.Verbose("Selecting account...");
|
||||
string code = "";
|
||||
for (int i = 0; i < SteamGuardAccounts.Length; i++)
|
||||
{
|
||||
SteamGuardAccount account = SteamGuardAccounts[i];
|
||||
if (user != "")
|
||||
{
|
||||
if (account.AccountName.ToLower() == user.ToLower())
|
||||
{
|
||||
Utils.Verbose("Generating code for {0}...", account.AccountName);
|
||||
code = account.GenerateSteamGuardCode();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.Verbose("Generating code for {0}...", account.AccountName);
|
||||
code = account.GenerateSteamGuardCode();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (code != "")
|
||||
Console.WriteLine(code);
|
||||
else
|
||||
Console.WriteLine("error: No Steam accounts found in {0}", SteamGuardAccounts);
|
||||
}
|
||||
|
||||
static bool Encrypt(string passkey = "")
|
||||
{
|
||||
// NOTE: in this context, `passkey` refers to the old passkey, if there was one
|
||||
Utils.Verbose("Opening manifest...");
|
||||
Manifest = Manifest.GetManifest(true);
|
||||
Utils.Verbose("Reading accounts from manifest...");
|
||||
if (Manifest.Encrypted)
|
||||
{
|
||||
if (string.IsNullOrEmpty(passkey))
|
||||
{
|
||||
passkey = Manifest.PromptForPassKey();
|
||||
}
|
||||
SteamGuardAccounts = Manifest.GetAllAccounts(passkey);
|
||||
}
|
||||
else
|
||||
{
|
||||
SteamGuardAccounts = Manifest.GetAllAccounts();
|
||||
}
|
||||
|
||||
string newPassKey = Manifest.PromptSetupPassKey();
|
||||
|
||||
for (int i = 0; i < SteamGuardAccounts.Length; i++)
|
||||
{
|
||||
var account = SteamGuardAccounts[i];
|
||||
var salt = Manifest.GetRandomSalt();
|
||||
var iv = Manifest.GetInitializationVector();
|
||||
bool success = Manifest.SaveAccount(account, true, newPassKey, salt, iv);
|
||||
Utils.Verbose("Encrypted {0}: {1}", account.AccountName, success);
|
||||
if (!success) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool Decrypt(string passkey = "")
|
||||
{
|
||||
Utils.Verbose("Opening manifest...");
|
||||
Manifest = Manifest.GetManifest(true);
|
||||
Utils.Verbose("Reading accounts from manifest...");
|
||||
if (Manifest.Encrypted)
|
||||
{
|
||||
if (string.IsNullOrEmpty(passkey))
|
||||
{
|
||||
passkey = Manifest.PromptForPassKey();
|
||||
}
|
||||
SteamGuardAccounts = Manifest.GetAllAccounts(passkey);
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.Verbose("Decryption not required.");
|
||||
return true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < SteamGuardAccounts.Length; i++)
|
||||
{
|
||||
var account = SteamGuardAccounts[i];
|
||||
bool success = Manifest.SaveAccount(account, false);
|
||||
Utils.Verbose("Decrypted {0}: {1}", account.AccountName, success);
|
||||
if (!success) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void Setup(string username = "", string passkey = "")
|
||||
{
|
||||
Utils.Verbose("Opening manifest...");
|
||||
Manifest = Manifest.GetManifest(true);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(username))
|
||||
{
|
||||
Console.Write("Username: ");
|
||||
username = Console.ReadLine();
|
||||
}
|
||||
Console.Write("Password: ");
|
||||
var password = Utils.ReadLineSecure();
|
||||
|
||||
UserLogin login = new UserLogin(username, password);
|
||||
LoginResult loginResult;
|
||||
do
|
||||
{
|
||||
Console.Write($"Logging in {username}... ");
|
||||
loginResult = login.DoLogin();
|
||||
Console.WriteLine(loginResult);
|
||||
switch (loginResult)
|
||||
{
|
||||
case LoginResult.NeedEmail:
|
||||
Console.Write("Email code: ");
|
||||
login.EmailCode = Console.ReadLine();
|
||||
break;
|
||||
case LoginResult.Need2FA:
|
||||
Console.Write("2FA code: ");
|
||||
login.TwoFactorCode = Console.ReadLine();
|
||||
break;
|
||||
case LoginResult.NeedCaptcha:
|
||||
Console.WriteLine($"Please open: https://steamcommunity.com/public/captcha.php?gid={login.CaptchaGID}");
|
||||
Console.Write("Captcha text: ");
|
||||
login.CaptchaText = Console.ReadLine();
|
||||
break;
|
||||
case LoginResult.BadCredentials:
|
||||
Console.WriteLine("error: Bad Credentials");
|
||||
return;
|
||||
case LoginResult.TooManyFailedLogins:
|
||||
Console.WriteLine("error: Too many failed logins. Wait a bit before trying again.");
|
||||
return;
|
||||
case LoginResult.LoginOkay:
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine($"Unknown login result: {loginResult}");
|
||||
break;
|
||||
}
|
||||
} while (loginResult != LoginResult.LoginOkay);
|
||||
|
||||
AuthenticatorLinker linker = new AuthenticatorLinker(login.Session);
|
||||
AuthenticatorLinker.LinkResult linkResult = AuthenticatorLinker.LinkResult.GeneralFailure;
|
||||
|
||||
do
|
||||
{
|
||||
linkResult = linker.AddAuthenticator();
|
||||
Console.WriteLine($"Link result: {linkResult}");
|
||||
switch (linkResult)
|
||||
{
|
||||
case AuthenticatorLinker.LinkResult.MustProvidePhoneNumber:
|
||||
var phonenumber = "";
|
||||
do
|
||||
{
|
||||
Console.WriteLine("Enter your mobile phone number in the following format: +{cC} phoneNumber. EG, +1 123-456-7890");
|
||||
phonenumber = Console.ReadLine();
|
||||
phonenumber = FilterPhoneNumber(phonenumber);
|
||||
linker.PhoneNumber = phonenumber;
|
||||
} while (!PhoneNumberOkay(phonenumber));
|
||||
break;
|
||||
case AuthenticatorLinker.LinkResult.MustConfirmEmail:
|
||||
Console.WriteLine("Check your email. Before continuing, click the link in the email to confirm your phone number. Press enter to continue...");
|
||||
Console.ReadLine();
|
||||
break;
|
||||
case AuthenticatorLinker.LinkResult.MustRemovePhoneNumber:
|
||||
linker.PhoneNumber = null;
|
||||
break;
|
||||
case AuthenticatorLinker.LinkResult.AwaitingFinalization:
|
||||
break;
|
||||
case AuthenticatorLinker.LinkResult.GeneralFailure:
|
||||
Console.WriteLine("error: Unable to add your phone number. Steam returned GeneralFailure");
|
||||
return;
|
||||
case AuthenticatorLinker.LinkResult.AuthenticatorPresent:
|
||||
Console.WriteLine("An authenticator is already present.");
|
||||
Console.WriteLine("If you have the revocation code (Rxxxxx), this program can remove it for you.");
|
||||
Console.Write("Would you like to remove the current authenticator using your revocation code? (y/n) ");
|
||||
var answer = Console.ReadLine();
|
||||
if (answer != "y")
|
||||
continue;
|
||||
Console.Write("Revocation code (Rxxxxx): ");
|
||||
var revocationCode = Console.ReadLine();
|
||||
var account = new SteamGuardAccount();
|
||||
account.Session = login.Session;
|
||||
account.RevocationCode = revocationCode;
|
||||
if (account.DeactivateAuthenticator())
|
||||
Console.WriteLine("Successfully deactivated the current authenticator.");
|
||||
else
|
||||
Console.WriteLine("Deactivating the current authenticator was unsuccessful.");
|
||||
continue;
|
||||
default:
|
||||
Console.WriteLine($"error: Unexpected linker result: {linkResult}");
|
||||
return;
|
||||
}
|
||||
} while (linkResult != AuthenticatorLinker.LinkResult.AwaitingFinalization);
|
||||
|
||||
string passKey = null;
|
||||
if (Manifest.Entries.Count == 0)
|
||||
{
|
||||
Console.WriteLine("Looks like we are setting up your first account.");
|
||||
passKey = Manifest.PromptSetupPassKey(true);
|
||||
}
|
||||
else if (Manifest.Entries.Count > 0 && Manifest.Encrypted)
|
||||
{
|
||||
if (string.IsNullOrEmpty(passkey))
|
||||
{
|
||||
passkey = Manifest.PromptForPassKey();
|
||||
}
|
||||
}
|
||||
|
||||
//Save the file immediately; losing this would be bad.
|
||||
if (!Manifest.SaveAccount(linker.LinkedAccount, passKey != null, passKey))
|
||||
{
|
||||
Manifest.RemoveAccount(linker.LinkedAccount);
|
||||
Console.WriteLine("Unable to save mobile authenticator file. The mobile authenticator has not been linked.");
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine(
|
||||
$"The Mobile Authenticator has not yet been linked. Before finalizing the authenticator, please write down your revocation code: {linker.LinkedAccount.RevocationCode}");
|
||||
|
||||
AuthenticatorLinker.FinalizeResult finalizeResponse = AuthenticatorLinker.FinalizeResult.GeneralFailure;
|
||||
do
|
||||
{
|
||||
Console.Write("Please input the SMS message sent to your phone number: ");
|
||||
string smsCode = Console.ReadLine();
|
||||
|
||||
finalizeResponse = linker.FinalizeAddAuthenticator(smsCode);
|
||||
Utils.Verbose(finalizeResponse);
|
||||
|
||||
switch (finalizeResponse)
|
||||
{
|
||||
case AuthenticatorLinker.FinalizeResult.BadSMSCode:
|
||||
continue;
|
||||
|
||||
case AuthenticatorLinker.FinalizeResult.UnableToGenerateCorrectCodes:
|
||||
Console.WriteLine(
|
||||
"Unable to generate the proper codes to finalize this authenticator. The authenticator should not have been linked.");
|
||||
Console.WriteLine(
|
||||
$"In the off-chance it was, please write down your revocation code, as this is the last chance to see it: {linker.LinkedAccount.RevocationCode}");
|
||||
Manifest.RemoveAccount(linker.LinkedAccount);
|
||||
return;
|
||||
|
||||
case AuthenticatorLinker.FinalizeResult.GeneralFailure:
|
||||
Console.WriteLine("Unable to finalize this authenticator. The authenticator should not have been linked.");
|
||||
Console.WriteLine(
|
||||
$"In the off-chance it was, please write down your revocation code, as this is the last chance to see it: {linker.LinkedAccount.RevocationCode}");
|
||||
Manifest.RemoveAccount(linker.LinkedAccount);
|
||||
return;
|
||||
}
|
||||
} while (finalizeResponse != AuthenticatorLinker.FinalizeResult.Success);
|
||||
|
||||
//Linked, finally. Re-save with FullyEnrolled property.
|
||||
Manifest.SaveAccount(linker.LinkedAccount, passKey != null, passKey);
|
||||
Console.WriteLine(
|
||||
$"Mobile authenticator successfully linked. Please actually write down your revocation code: {linker.LinkedAccount.RevocationCode}");
|
||||
}
|
||||
|
||||
public static string FilterPhoneNumber(string phoneNumber)
|
||||
=> phoneNumber.Replace("-", "").Replace("(", "").Replace(")", "");
|
||||
|
||||
public static bool PhoneNumberOkay(string phoneNumber)
|
||||
{
|
||||
if (phoneNumber == null || phoneNumber.Length == 0) return false;
|
||||
if (phoneNumber[0] != '+') return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void Trade(string user = "", string passkey = "")
|
||||
{
|
||||
Utils.Verbose("Opening manifest...");
|
||||
Manifest = Manifest.GetManifest(true);
|
||||
Utils.Verbose("Reading accounts from manifest...");
|
||||
if (Manifest.Encrypted)
|
||||
{
|
||||
if (string.IsNullOrEmpty(passkey))
|
||||
{
|
||||
passkey = Manifest.PromptForPassKey();
|
||||
}
|
||||
SteamGuardAccounts = Manifest.GetAllAccounts(passkey);
|
||||
}
|
||||
else
|
||||
{
|
||||
SteamGuardAccounts = Manifest.GetAllAccounts();
|
||||
}
|
||||
if (SteamGuardAccounts.Length == 0)
|
||||
{
|
||||
Console.WriteLine("error: No accounts read.");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var account in SteamGuardAccounts)
|
||||
{
|
||||
if (user != "")
|
||||
if (!string.Equals(account.AccountName, user, StringComparison.CurrentCultureIgnoreCase))
|
||||
continue;
|
||||
|
||||
processConfirmations(account);
|
||||
}
|
||||
}
|
||||
|
||||
enum TradeAction
|
||||
{
|
||||
Accept = 1,
|
||||
Deny = 0,
|
||||
Ignore = -1
|
||||
}
|
||||
|
||||
static bool promptRefreshSession(SteamGuardAccount account)
|
||||
{
|
||||
Console.WriteLine("Your Steam credentials have expired. For trade and market confirmations to work properly, please login again.");
|
||||
string username = account.AccountName;
|
||||
Console.WriteLine($"Username: {username}");
|
||||
Console.Write("Password: ");
|
||||
var password = Console.ReadLine();
|
||||
|
||||
UserLogin login = new UserLogin(username, password);
|
||||
Console.Write($"Logging in {username}... ");
|
||||
LoginResult loginResult = login.DoLogin();
|
||||
if (loginResult == LoginResult.Need2FA && !string.IsNullOrEmpty(account.SharedSecret))
|
||||
{
|
||||
// if we need a 2fa code, and we can generate it, generate a 2fa code and log in.
|
||||
Utils.Verbose(loginResult);
|
||||
TimeAligner.AlignTime();
|
||||
login.TwoFactorCode = account.GenerateSteamGuardCode();
|
||||
Utils.Verbose($"Logging in {username}... ");
|
||||
loginResult = login.DoLogin();
|
||||
}
|
||||
Console.WriteLine(loginResult);
|
||||
if (loginResult == LoginResult.LoginOkay)
|
||||
{
|
||||
account.Session = login.Session;
|
||||
}
|
||||
|
||||
if (account.RefreshSession())
|
||||
{
|
||||
Utils.Verbose("Session refreshed");
|
||||
Manifest.SaveAccount(account, Manifest.Encrypted);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void processConfirmations(SteamGuardAccount account)
|
||||
{
|
||||
Utils.Verbose("Refeshing Session...");
|
||||
if (account.RefreshSession())
|
||||
{
|
||||
Utils.Verbose("Session refreshed");
|
||||
Manifest.SaveAccount(account, Manifest.Encrypted);
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.Verbose("Failed to refresh session, prompting user...");
|
||||
if (!promptRefreshSession(account))
|
||||
{
|
||||
Console.WriteLine("Failed to refresh session, aborting...");
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Retrieving trade confirmations...");
|
||||
var tradesTask = account.FetchConfirmationsAsync();
|
||||
tradesTask.Wait();
|
||||
var trades = tradesTask.Result;
|
||||
var tradeActions = new TradeAction[trades.Length];
|
||||
for (var i = 0; i < tradeActions.Length; i++)
|
||||
{
|
||||
tradeActions[i] = TradeAction.Ignore;
|
||||
}
|
||||
if (trades.Length == 0)
|
||||
{
|
||||
Console.WriteLine($"No trade confirmations for {account.AccountName}.");
|
||||
return;
|
||||
}
|
||||
var selected = 0;
|
||||
var colorAccept = ConsoleColor.Green;
|
||||
var colorDeny = ConsoleColor.Red;
|
||||
var colorIgnore = ConsoleColor.Gray;
|
||||
var colorSelected = ConsoleColor.Yellow;
|
||||
var confirm = false;
|
||||
|
||||
do
|
||||
{
|
||||
Console.Clear();
|
||||
if (selected >= trades.Length)
|
||||
selected = trades.Length - 1;
|
||||
else if (selected < 0)
|
||||
selected = 0;
|
||||
Console.ResetColor();
|
||||
Console.WriteLine($"Trade confirmations for {account.AccountName}...");
|
||||
Console.WriteLine("No action will be made without your confirmation.");
|
||||
Console.WriteLine("[a]ccept [d]eny [i]gnore [enter] Confirm [q]uit"); // accept = 1, deny = 0, ignore = -1
|
||||
Console.WriteLine();
|
||||
|
||||
for (var t = 0; t < trades.Length; t++)
|
||||
{
|
||||
ConsoleColor itemColor;
|
||||
switch (tradeActions[t])
|
||||
{
|
||||
case TradeAction.Accept:
|
||||
itemColor = colorAccept;
|
||||
break;
|
||||
case TradeAction.Deny:
|
||||
itemColor = colorDeny;
|
||||
break;
|
||||
case TradeAction.Ignore:
|
||||
itemColor = colorIgnore;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
Console.ForegroundColor = t == selected ? colorSelected : itemColor;
|
||||
|
||||
Console.WriteLine($" [{t}] [{tradeActions[t]}] {trades[t].ConfType} {trades[t].Creator} {trades[t].Description}");
|
||||
}
|
||||
var key = Console.ReadKey();
|
||||
switch (key.Key)
|
||||
{
|
||||
case ConsoleKey.UpArrow:
|
||||
case ConsoleKey.W:
|
||||
selected--;
|
||||
break;
|
||||
case ConsoleKey.DownArrow:
|
||||
case ConsoleKey.S:
|
||||
selected++;
|
||||
break;
|
||||
case ConsoleKey.A:
|
||||
tradeActions[selected] = TradeAction.Accept;
|
||||
break;
|
||||
case ConsoleKey.D:
|
||||
tradeActions[selected] = TradeAction.Deny;
|
||||
break;
|
||||
case ConsoleKey.I:
|
||||
tradeActions[selected] = TradeAction.Ignore;
|
||||
break;
|
||||
case ConsoleKey.Enter:
|
||||
confirm = true;
|
||||
break;
|
||||
case ConsoleKey.Escape:
|
||||
case ConsoleKey.Q:
|
||||
Console.ResetColor();
|
||||
Console.WriteLine("Quitting...");
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while (!confirm);
|
||||
Console.ResetColor();
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Processing...");
|
||||
for (var t = 0; t < trades.Length; t++)
|
||||
{
|
||||
bool success = false;
|
||||
switch (tradeActions[t])
|
||||
{
|
||||
case TradeAction.Accept:
|
||||
if (Verbose) Console.Write($"Accepting {trades[t].ConfType} {trades[t].Creator} {trades[t].Description}...");
|
||||
success = account.AcceptConfirmation(trades[t]);
|
||||
break;
|
||||
case TradeAction.Deny:
|
||||
if (Verbose) Console.Write($"Denying {trades[t].ConfType} {trades[t].Creator} {trades[t].Description}...");
|
||||
success = account.DenyConfirmation(trades[t]);
|
||||
break;
|
||||
case TradeAction.Ignore:
|
||||
if (Verbose) Console.Write($"Ignoring {trades[t].ConfType} {trades[t].Creator} {trades[t].Description}...");
|
||||
success = true;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
Utils.Verbose(success);
|
||||
}
|
||||
Console.WriteLine("Done.");
|
||||
}
|
||||
|
||||
static void AcceptAllTrades(string user = "", string passkey = "")
|
||||
{
|
||||
Utils.Verbose("Opening manifest...");
|
||||
Manifest = Manifest.GetManifest(true);
|
||||
Utils.Verbose("Reading accounts from manifest...");
|
||||
if (Manifest.Encrypted)
|
||||
{
|
||||
if (string.IsNullOrEmpty(passkey))
|
||||
{
|
||||
passkey = Manifest.PromptForPassKey();
|
||||
}
|
||||
SteamGuardAccounts = Manifest.GetAllAccounts(passkey);
|
||||
}
|
||||
else
|
||||
{
|
||||
SteamGuardAccounts = Manifest.GetAllAccounts();
|
||||
}
|
||||
if (SteamGuardAccounts.Length == 0)
|
||||
{
|
||||
Console.WriteLine("error: No accounts read.");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < SteamGuardAccounts.Length; i++)
|
||||
{
|
||||
SteamGuardAccount account = SteamGuardAccounts[i];
|
||||
if ((user != "" && account.AccountName.ToLower() == user.ToLower()) || user == "")
|
||||
{
|
||||
Console.WriteLine($"Accepting Confirmations on {account.AccountName}");
|
||||
Utils.Verbose("Refeshing Session...");
|
||||
if (account.RefreshSession())
|
||||
{
|
||||
Utils.Verbose("Session refreshed");
|
||||
Manifest.SaveAccount(account, Manifest.Encrypted);
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.Verbose("Failed to refresh session, prompting user...");
|
||||
if (!promptRefreshSession(account))
|
||||
{
|
||||
Console.WriteLine("Failed to refresh session, aborting...");
|
||||
}
|
||||
}
|
||||
Utils.Verbose("Fetching Confirmations...");
|
||||
var tradesTask = account.FetchConfirmationsAsync();
|
||||
tradesTask.Wait();
|
||||
Confirmation[] confirmations = tradesTask.Result;
|
||||
Utils.Verbose("Accepting Confirmations...");
|
||||
account.AcceptMultipleConfirmations(confirmations);
|
||||
if (user != "")
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
Subproject commit e0619528fbe8f4c6f74135283b3f991219e73cf4
|
38
Utils.cs
38
Utils.cs
|
@ -1,38 +0,0 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace SteamGuard
|
||||
{
|
||||
public static class Utils
|
||||
{
|
||||
public static string ReadLineSecure()
|
||||
{
|
||||
// Have bash handle the password input, because apparently it's impossible in C#,
|
||||
// and we don't need to worry about windows compatibility.
|
||||
string bash_cmd = @"read -s -p ""Password: "" password; echo $password";
|
||||
Process p = new Process();
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.StartInfo.FileName = "bash";
|
||||
p.StartInfo.Arguments = string.Format("-c '{0}'", bash_cmd);
|
||||
p.StartInfo.RedirectStandardOutput = true;
|
||||
p.Start();
|
||||
|
||||
p.WaitForExit();
|
||||
Console.WriteLine();
|
||||
return p.StandardOutput.ReadToEnd().Trim();
|
||||
}
|
||||
|
||||
public static void Verbose(object obj)
|
||||
{
|
||||
Verbose(obj.ToString(), null);
|
||||
}
|
||||
|
||||
public static void Verbose(string format, params object[] arg)
|
||||
{
|
||||
if (Program.Verbose)
|
||||
{
|
||||
Console.WriteLine(format, arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
_steamguard()
|
||||
{
|
||||
local cur prev opts
|
||||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
opts="--help --verbose --maFiles-path --passkey"
|
||||
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
return 0
|
||||
}
|
||||
|
||||
complete -F _steamguard steamguard
|
27
makefile
27
makefile
|
@ -1,27 +0,0 @@
|
|||
$(eval SHELL:=/bin/bash)
|
||||
|
||||
all: Program.cs
|
||||
mkdir -p build/ ;\
|
||||
nuget restore SteamAuth/SteamAuth/SteamAuth.sln ;\
|
||||
NEWTONSOFT_JSON_PATH=$$(find -name Newtonsoft.Json.dll | grep \/net45\/ | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n | tail -n 1) ;\
|
||||
mcs -target:library -out:build/SteamAuth.dll -r:"$$NEWTONSOFT_JSON_PATH" SteamAuth/SteamAuth/APIEndpoints.cs SteamAuth/SteamAuth/AuthenticatorLinker.cs SteamAuth/SteamAuth/Confirmation.cs SteamAuth/SteamAuth/SessionData.cs SteamAuth/SteamAuth/SteamGuardAccount.cs SteamAuth/SteamAuth/SteamWeb.cs SteamAuth/SteamAuth/TimeAligner.cs SteamAuth/SteamAuth/UserLogin.cs SteamAuth/SteamAuth/Util.cs SteamAuth/SteamAuth/Properties/AssemblyInfo.cs ;\
|
||||
cp "$$NEWTONSOFT_JSON_PATH" build/ ;\
|
||||
mcs -out:build/steamguard -r:build/SteamAuth.dll -r:build/Newtonsoft.Json.dll -r:/usr/lib/mono/4.5/System.Security.dll Program.cs Manifest.cs AssemblyInfo.cs Utils.cs
|
||||
|
||||
run:
|
||||
build/steamguard -v
|
||||
|
||||
clean:
|
||||
rm -r build/
|
||||
|
||||
install:
|
||||
cp build/steamguard /usr/local/bin/
|
||||
cp build/Newtonsoft.Json.dll /usr/local/bin/
|
||||
cp build/SteamAuth.dll /usr/local/bin/
|
||||
cp bash-tab-completion /etc/bash_completion.d/steamguard
|
||||
|
||||
uninstall:
|
||||
rm -f /usr/local/bin/steamguard
|
||||
rm -f /usr/local/bin/Newtonsoft.Json.dll
|
||||
rm -f /usr/local/bin/SteamAuth.dll
|
||||
rm -f /etc/bash_completion.d/steamguard
|
|
@ -1,24 +0,0 @@
|
|||
all: Program.cs
|
||||
mkdir -p build/
|
||||
nuget restore SteamAuth/SteamAuth/SteamAuth.sln
|
||||
mcs -target:library -out:build/SteamAuth.dll -r:SteamAuth/SteamAuth/packages/Newtonsoft.Json.11.0.1/lib/net45/Newtonsoft.Json.dll SteamAuth/SteamAuth/APIEndpoints.cs SteamAuth/SteamAuth/AuthenticatorLinker.cs SteamAuth/SteamAuth/Confirmation.cs SteamAuth/SteamAuth/SessionData.cs SteamAuth/SteamAuth/SteamGuardAccount.cs SteamAuth/SteamAuth/SteamWeb.cs SteamAuth/SteamAuth/TimeAligner.cs SteamAuth/SteamAuth/UserLogin.cs SteamAuth/SteamAuth/Util.cs SteamAuth/SteamAuth/Properties/AssemblyInfo.cs
|
||||
cp SteamAuth/SteamAuth/packages/Newtonsoft.Json.11.0.1/lib/net45/Newtonsoft.Json.dll build/
|
||||
mcs -out:build/steamguard -r:build/SteamAuth.dll -r:build/Newtonsoft.Json.dll -r:/usr/local/lib/mono/4.5/System.Security.dll Program.cs Manifest.cs AssemblyInfo.cs Utils.cs
|
||||
|
||||
run:
|
||||
mono build/steamguard -v
|
||||
|
||||
clean:
|
||||
rm -r build/
|
||||
|
||||
install:
|
||||
cp build/steamguard /usr/local/bin/
|
||||
cp build/Newtonsoft.Json.dll /usr/local/bin/
|
||||
cp build/SteamAuth.dll /usr/local/bin/
|
||||
cp bash-tab-completion /etc/bash_completion.d/steamguard
|
||||
|
||||
uninstall:
|
||||
rm -f /usr/local/bin/steamguard
|
||||
rm -f /usr/local/bin/Newtonsoft.Json.dll
|
||||
rm -f /usr/local/bin/SteamAuth.dll
|
||||
rm -f /etc/bash_completion.d/steamguard
|
|
@ -1,67 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>12E8E57D-A11A-4FDF-BAEC-AAFDE916E732</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>steamguard_cli</RootNamespace>
|
||||
<AssemblyName>steamguard-cli</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Content Include=".\makefile">
|
||||
<Link>makefile</Link>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include=".\Manifest.cs">
|
||||
<Link>Manifest.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include=".\Program.cs">
|
||||
<Link>Program.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
|
||||
<HintPath>.\build\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SteamAuth, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>.\build\SteamAuth.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<HintPath>..\..\..\..\..\usr\lib\mono\4.5\System.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
|
@ -1,22 +0,0 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.0.0
|
||||
MinimumVisualStudioVersion = 10.0.0.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "steamguard_cli", "steamguard-cli.csproj", "{12E8E57D-A11A-4FDF-BAEC-AAFDE916E732}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{12E8E57D-A11A-4FDF-BAEC-AAFDE916E732}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{12E8E57D-A11A-4FDF-BAEC-AAFDE916E732}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{12E8E57D-A11A-4FDF-BAEC-AAFDE916E732}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{12E8E57D-A11A-4FDF-BAEC-AAFDE916E732}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
Loading…
Reference in a new issue