示例#1
0
        public SteamGuardAccount[] GetAllAccounts(SecureString passkey = null, int limit = -1)
        {
            List <SteamGuardAccount> accounts = new List <SteamGuardAccount>();

            if (passkey == null && Encrypted)
            {
                return(new SteamGuardAccount[0]);
            }
            if (!UseMaFiles)
            {
                credMan = CredManifest.GetManifest();
                for (int i = 0; i < credMan.Entries.Count; i++)
                {
                    accounts.Add(GetAccount(passkey, i));

                    if (limit != -1 && limit >= accounts.Count)
                    {
                        break;
                    }
                }
            }
            else
            {
                for (int i = 0; i < Entries.Count; i++)
                {
                    accounts.Add(GetAccount(passkey, i));

                    if (limit != -1 && limit >= accounts.Count)
                    {
                        break;
                    }
                }
            }
            return(accounts.ToArray());
        }
示例#2
0
 public void MoveEntry(int from, int to)
 {
     if (UseMaFiles)
     {
         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();
     }
     else
     {
         credMan = CredManifest.GetManifest();
         if (from < 0 || to < 0 || from > credMan.Entries.Count || to > credMan.Entries.Count - 1)
         {
             return;
         }
         CredManifestEntry sel = credMan.Entries[from];
         credMan.Entries.RemoveAt(from);
         credMan.Entries.Insert(to, sel);
         credMan.Save();
     }
 }
示例#3
0
        public SteamGuardAccount GetAccount(SecureString passkey = null, int index = 0)
        {
            SteamGuardAccount account = new SteamGuardAccount();

            if (passkey == null && Encrypted)
            {
                return(account);
            }
            if (!UseMaFiles)
            {
                credMan = CredManifest.GetManifest();
                string fileText = credMan.Entries[index].Contents;

                fileText = Encryptor.DPAPIUnprotect(fileText, Encryptor.AccountEntropy);

                if (fileText.StartsWith("Encrypted"))
                {
                    string decryptedText = Encryptor.DecryptData(passkey, credMan.Entries[index].Salt, credMan.Entries[index].IV, fileText.Remove(0, 9)); if (decryptedText == null)
                    {
                        return(account);
                    }
                    fileText = decryptedText;
                }

                var acc = JsonConvert.DeserializeObject <SteamGuardAccount>(fileText);
                if (acc == null)
                {
                    return(account);
                }
                return(acc);
            }
            else
            {
                if (passkey == null && Encrypted)
                {
                    return(new SteamGuardAccount());
                }
                string maDir = GetExecutableDir() + "/maFiles/";

                string fileText = File.ReadAllText(maDir + Entries[index].FileName);

                fileText = Encryptor.DPAPIUnprotect(fileText, Encryptor.AccountEntropy);

                if (fileText.StartsWith("Encrypted"))
                {
                    string decryptedText = Encryptor.DecryptData(passkey, Entries[index].Salt, Entries[index].IV, fileText.Remove(0, 9)); if (decryptedText == null)
                    {
                        return(account);
                    }
                    fileText = decryptedText;
                }

                var acc = JsonConvert.DeserializeObject <SteamGuardAccount>(fileText);
                if (acc == null)
                {
                    return(account);
                }
                return(acc);
            }
        }
示例#4
0
        /// <summary>
        /// Decrypts/Encrypts all account files (depending on DPAPI setting)
        /// </summary>
        /// <returns></returns>
        public bool UpdateDPAPI()
        {
            credMan = CredManifest.GetManifest();
            if (UseMaFiles)
            {
                string maDir = GetExecutableDir() + "/maFiles/";
                for (int i = 0; i < Entries.Count; i++)
                {
                    ManifestEntry entry    = Entries[i];
                    string        filename = maDir + entry.FileName;
                    if (!File.Exists(filename))
                    {
                        continue;
                    }

                    string fileContents = File.ReadAllText(filename);

                    fileContents = Encryptor.DPAPIUnprotect(fileContents, Encryptor.AccountEntropy);

                    string toWriteFileContents = fileContents;

                    if (UseDPAPI == true)
                    {
                        toWriteFileContents = Encryptor.DPAPIProtect(toWriteFileContents, Encryptor.AccountEntropy);
                    }

                    File.WriteAllText(filename, toWriteFileContents);
                    if (UseWindowsFileEncryption)
                    {
                        File.Encrypt(filename);
                    }
                    else
                    {
                        File.Decrypt(filename);
                    }
                }
            }
            else
            {
                foreach (CredManifestEntry entry in credMan.Entries)
                {
                    string fileContents = entry.Contents;

                    string toWriteFileContents = Encryptor.DPAPIUnprotect(fileContents, Encryptor.AccountEntropy);

                    if (UseDPAPI)
                    {
                        toWriteFileContents = Encryptor.DPAPIProtect(toWriteFileContents, Encryptor.AccountEntropy);
                    }

                    entry.Contents = toWriteFileContents;
                }
                credMan.Save();
            }

            Save();

            return(true);
        }
示例#5
0
        public SecureString PromptForPasskey()
        {
            if (!Encrypted)
            {
                throw new ManifestNotEncryptedException();
            }


            bool         passkeyValid = false;
            SecureString passkey      = null;

            try
            {
                if (CredentialLocker)
                {
                    credMan = CredManifest.GetManifest();
                    if (credMan.Key.Length >= 1)
                    {
                        if (VerifyPasskey(credMan.Key))
                        {
                            passkeyValid = true;
                            passkey      = credMan.Key;
                        }
                    }
                }
            }
            catch (Exception) { }

            while (!passkeyValid)
            {
                InputForm passkeyForm = new InputForm(Properties.strings.ManifestEnterKey, true);
                passkeyForm.ShowDialog(Application.Current.Windows.OfType <Window>().SingleOrDefault(x => x.IsActive)); // Gets the current active window and passes that to the input form (so it can center)
                if (!passkeyForm.Canceled)
                {
                    passkey = passkeyForm.txtPass.SecurePassword;
                    if (!VerifyPasskey(passkey))
                    {
                        MessageBox.Show(Properties.strings.ManifestKeyInvalid);
                    }
                    else
                    {
                        passkeyValid = true;
                        if (CredentialLocker)
                        {
                            credMan     = CredManifest.GetManifest();
                            credMan.Key = passkey;
                            credMan.Save();
                        }
                    }
                }
                else
                {
                    return(null);
                }
            }
            return(passkey);
        }
示例#6
0
 public int GetAccountCount()
 {
     credMan = CredManifest.GetManifest();
     if (UseMaFiles)
     {
         return(Entries.Count);
     }
     else
     {
         return(credMan.Entries.Count);
     }
 }
示例#7
0
        private static CredManifest _generateNewManifest(SecureString key)
        {
            // No directory means no manifest file anyways.
            CredManifest newManifest = new CredManifest
            {
                Key     = key,
                Entries = new List <CredManifestEntry>()
            };

            if (newManifest.Save())
            {
                return(newManifest);
            }

            return(null);
        }
示例#8
0
 public bool RemoveAccount(SteamGuardAccount account, bool deleteMaFile = true)
 {
     if (UseMaFiles)
     {
         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 maDir    = GetExecutableDir() + "/maFiles/";
         string filename = maDir + entry.FileName;
         this.Entries.Remove(entry);
         if (Entries.Count == 0)
         {
             Encrypted = false;
         }
         if (Save() && deleteMaFile)
         {
             try
             {
                 File.Delete(filename);
                 return(true);
             }
             catch (Exception)
             {
                 return(false);
             }
         }
     }
     else
     {
         credMan = CredManifest.GetManifest();
         CredManifestEntry entry = (from e in credMan.Entries where e.SteamID == account.Session.SteamID select e).FirstOrDefault();
         if (entry == null)
         {
             return(true);
         }
         credMan.Entries.Remove(entry);
         if (credMan.Entries.Count == 0)
         {
             Encrypted = false;
         }
         return(credMan.Save());
     }
     return(false);
 }
示例#9
0
        public static CredManifest GetManifest(bool forceLoad = false)
        {
            if (_cred != null && !forceLoad)
            {
                return(_cred);
            }

            try
            {
                Retreiving = true;
                PasswordCredential credential = null; var vault = new PasswordVault();
                credential = vault.Retrieve("SteamAuthenticator", "Storage");
                if (credential != null)
                {
                    credential.RetrievePassword();
                }
                else
                {
                    return(_generateNewManifest(new SecureString()));
                }

                string manifestContents = credential.Password.ToString();
                manifestContents = Encryptor.DPAPIUnprotect(credential.Password.ToString());
                _cred            = JsonConvert.DeserializeObject <CredManifest>(manifestContents);
                _originalCred    = credential.Password.ToString();

                foreach (char c in UnsecureKey.ToCharArray())
                {
                    SecureKey.AppendChar(c);
                }

                UnsecureKey = null;
                GC.Collect(); // security at its finest
                GC.WaitForPendingFinalizers();

                Retreiving = false;

                return(_cred);
            }
            catch (Exception)
            {
                Retreiving = false;
                return(_generateNewManifest(new SecureString()));
            }
        }
示例#10
0
        public bool Save()
        {
            string maDir       = GetExecutableDir() + @"\maFiles\";
            string filename    = maDir + "manifest.json";
            bool   notFirstRun = true;

            if (!Directory.Exists(maDir))
            {
                try
                {
                    notFirstRun = false;
                    Directory.CreateDirectory(maDir);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            try
            {
                try
                {
                    if (!UseMaFiles && Entries.Count > 0 && credMan.Entries.Count < Entries.Count) // Move the accounts over to CredMan
                    {
                        credMan = CredManifest.GetManifest();
                        if (!credMan.ImportAccounts())
                        {
                            UseMaFiles = true;
                        }
                    }
                    else if (UseMaFiles && notFirstRun)
                    {
                        credMan = CredManifest.GetManifest();
                        if (credMan.Entries.Count > 0 && Entries.Count < credMan.Entries.Count)
                        {
                            if (!credMan.ExportAccounts())
                            {
                                UseMaFiles = false;
                            }
                        }
                    }
                }
                catch { }

                if (UseDPAPI)
                {
                    File.WriteAllText(filename, Encryptor.DPAPIProtect(JsonConvert.SerializeObject(this)));
                }
                else
                {
                    File.WriteAllText(filename, JsonConvert.SerializeObject(this));
                }

                if (UseWindowsFileEncryption)
                {
                    File.Encrypt(filename);
                }
                else
                {
                    File.Decrypt(filename);
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#11
0
        public bool SaveAccount(SteamGuardAccount account, bool encrypt, SecureString passkey = null)
        {
            if (encrypt && passkey != null && passkey.Length >= 1)
            {
                return(false);
            }
            if (!encrypt && this.Encrypted)
            {
                return(false);
            }
            if (account == null)
            {
                return(false);
            }

            if (UseMaFiles)
            {
                string salt        = null;
                string iV          = null;
                string jsonAccount = JsonConvert.SerializeObject(account);

                if (encrypt)
                {
                    salt = Encryptor.GetRandomSalt();
                    iV   = Encryptor.GetInitializationVector();
                    string encrypted = "Encrypted" + Encryptor.EncryptData(passkey, salt, iV, jsonAccount);
                    if (encrypted == null)
                    {
                        return(false);
                    }
                    jsonAccount = encrypted;
                }

                if (UseDPAPI)
                {
                    jsonAccount = Encryptor.DPAPIProtect(jsonAccount, Encryptor.AccountEntropy);
                }

                string maDir    = GetExecutableDir() + "/maFiles/";
                string filename = account.Session.SteamID.ToString() + ".maFile";

                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 (Entries[i].SteamID == account.Session.SteamID)
                    {
                        Entries[i]         = newEntry;
                        foundExistingEntry = true;
                        break;
                    }
                }

                if (!foundExistingEntry)
                {
                    Entries.Add(newEntry);
                }

                bool wasEncrypted = Encrypted;
                Encrypted = encrypt || Encrypted;

                if (!Save())
                {
                    Encrypted = wasEncrypted;
                    return(false);
                }

                try
                {
                    File.WriteAllText(maDir + filename, jsonAccount);
                    if (UseWindowsFileEncryption)
                    {
                        File.Encrypt(maDir + filename);
                    }
                    else
                    {
                        File.Decrypt(maDir + filename);
                    }
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            else
            {
                try
                {
                    credMan = CredManifest.GetManifest();
                    string salt = null; string iV = null;
                    string jsonAccount   = JsonConvert.SerializeObject(account);
                    bool   fileEncrypted = false;

                    if (encrypt)
                    {
                        salt = Encryptor.GetRandomSalt();
                        iV   = Encryptor.GetInitializationVector();
                        string encrypted = "Encrypted" + Encryptor.EncryptData(passkey, salt, iV, jsonAccount);
                        if (encrypted == null)
                        {
                            return(false);
                        }
                        jsonAccount   = encrypted;
                        fileEncrypted = true;
                    }

                    if (UseDPAPI)
                    {
                        jsonAccount = Encryptor.DPAPIProtect(jsonAccount, Encryptor.AccountEntropy);
                    }

                    CredManifestEntry newEntry = new CredManifestEntry()
                    {
                        SteamID   = account.Session.SteamID,
                        IV        = iV,
                        Salt      = salt,
                        Contents  = jsonAccount,
                        Encrypted = fileEncrypted,
                    };
                    bool foundExistingEntry = false;
                    for (int i = 0; i < credMan.Entries.Count; i++)
                    {
                        if (credMan.Entries[i].SteamID == account.Session.SteamID)
                        {
                            credMan.Entries[i] = newEntry;
                            foundExistingEntry = true;
                            break;
                        }
                    }

                    if (!foundExistingEntry)
                    {
                        credMan.Entries.Add(newEntry);
                    }

                    credMan.Save();

                    bool wasEncrypted = Encrypted;
                    Encrypted = encrypt || Encrypted;

                    if (!Save())
                    {
                        Encrypted = wasEncrypted;
                        return(false);
                    }
                    return(true);
                }
                catch (Exception) { return(false); }
            }
        }
示例#12
0
        public bool ChangeEncryptionKey(SecureString oldKey, SecureString newKey)
        {
            if (Encrypted)
            {
                if (!VerifyPasskey(oldKey))
                {
                    return(false);
                }
            }
            bool toEncrypt = newKey != null;

            credMan = CredManifest.GetManifest();
            if (UseMaFiles)
            {
                string maDir = GetExecutableDir() + "/maFiles/";
                for (int i = 0; i < Entries.Count; i++)
                {
                    ManifestEntry entry    = Entries[i];
                    string        filename = maDir + entry.FileName;
                    if (!File.Exists(filename))
                    {
                        continue;
                    }

                    string fileContents = File.ReadAllText(filename);

                    fileContents = Encryptor.DPAPIUnprotect(fileContents, Encryptor.AccountEntropy);

                    if (fileContents.StartsWith("Encrypted"))
                    {
                        fileContents = Encryptor.DecryptData(oldKey, entry.Salt, entry.IV, fileContents.Remove(0, 9));
                    }

                    string newSalt             = null;
                    string newIV               = null;
                    string toWriteFileContents = fileContents;

                    if (toEncrypt)
                    {
                        newSalt             = Encryptor.GetRandomSalt();
                        newIV               = Encryptor.GetInitializationVector();
                        toWriteFileContents = "Encrypted" + Encryptor.EncryptData(newKey, newSalt, newIV, fileContents);
                    }

                    if (UseDPAPI)
                    {
                        toWriteFileContents = Encryptor.DPAPIProtect(toWriteFileContents, Encryptor.AccountEntropy);
                    }


                    File.WriteAllText(filename, toWriteFileContents);
                    if (UseWindowsFileEncryption)
                    {
                        File.Encrypt(filename);
                    }
                    else
                    {
                        File.Decrypt(filename);
                    }
                    entry.IV   = newIV;
                    entry.Salt = newSalt;
                }
            }
            else
            {
                foreach (CredManifestEntry entry in credMan.Entries)
                {
                    string fileContents = entry.Contents;

                    fileContents = Encryptor.DPAPIUnprotect(fileContents, Encryptor.AccountEntropy);

                    if (fileContents.StartsWith("Encrypted"))
                    {
                        fileContents = Encryptor.DecryptData(oldKey, entry.Salt, entry.IV, fileContents.Remove(0, 9));
                    }

                    string newSalt             = null;
                    string newIV               = null;
                    string toWriteFileContents = fileContents;

                    if (toEncrypt)
                    {
                        newSalt             = Encryptor.GetRandomSalt();
                        newIV               = Encryptor.GetInitializationVector();
                        toWriteFileContents = "Encrypted" + Encryptor.EncryptData(newKey, newSalt, newIV, fileContents);
                    }
                    else
                    {
                        entry.Encrypted = false;
                    }

                    if (UseDPAPI)
                    {
                        toWriteFileContents = Encryptor.DPAPIProtect(toWriteFileContents, Encryptor.AccountEntropy);
                    }

                    entry.Contents = toWriteFileContents;
                    entry.IV       = newIV;
                    entry.Salt     = newSalt;
                }
                credMan.Key = newKey;
                credMan.Save();
            }

            Encrypted = toEncrypt;

            Save();
            return(true);
        }
示例#13
0
        public static Manifest GetManifest(bool forceLoad = false)
        {
            // Find config dir and manifest file

            string maDir        = GetExecutableDir() + "\\maFiles\\";
            string manifestFile = maDir + "manifest.json";

            // Check if already statically loaded
            if (_manifest != null && !forceLoad)
            {
                return(_manifest);
            }

            // If there's no config dir, create it
            if (!Directory.Exists(maDir))
            {
                return(_generateNewManifest());
            }

            // If there's no manifest, create it
            if (!File.Exists(manifestFile))
            {
                _manifest = _generateNewManifest(true);
                return(_manifest);
            }

            try
            {
                string manifestContents = File.ReadAllText(manifestFile);
                manifestContents = Encryptor.DPAPIUnprotect(manifestContents);
                _manifest        = JsonConvert.DeserializeObject <Manifest>(manifestContents);

                if (_manifest.Encrypted && _manifest.Entries.Count == 0 && _manifest.UseMaFiles)
                {
                    _manifest.Encrypted = false;
                    _manifest.Save();
                }
                else if (_manifest.Encrypted && !_manifest.UseMaFiles)
                {
                    CredManifest credMan = new CredManifest();
                    credMan = CredManifest.GetManifest();
                    if (credMan.Entries.Count == 0)
                    {
                        _manifest.Encrypted = false;
                        _manifest.Save();
                    }
                }

                _manifest.RecomputeExistingEntries();

#if !DEBUG
                _manifest.DeveloperMode = false;
#endif

                return(_manifest);
            }
            catch (Exception)
            {
                return(null);
            }
        }