Exemple #1
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);
            }
        }
Exemple #2
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);
        }
Exemple #3
0
        /// <summary>
        /// Exports accounts from the credential manager to maFiles
        /// </summary>
        /// <returns>Whether or not it succeeded</returns>
        public bool ExportAccounts()
        {
            try
            {
                if (Entries.Count > 0) // Without this there'll be an infinite loop on first run
                {
                    Manifest man = new Manifest();
                    man = Manifest.GetManifest();
                    string maDir = GetExecutableDir() + "/maFiles/";
                    foreach (CredManifestEntry entry in Entries)
                    {
                        string contents = entry.Contents;
                        if (!Manifest.UseDPAPI)
                        {
                            contents = Encryptor.DPAPIUnprotect(contents, Encryptor.AccountEntropy);
                        }

                        File.WriteAllText(maDir + entry.SteamID + ".maFile", contents);
                        man.Entries.Add(new ManifestEntry()
                        {
                            FileName  = entry.SteamID.ToString() + ".maFile",
                            SteamID   = entry.SteamID,
                            IV        = entry.IV,
                            Salt      = entry.Salt,
                            Encrypted = entry.Encrypted
                        });
                        if (UseWindowsFileEncryption)
                        {
                            File.Encrypt(maDir + entry.SteamID + ".maFile");
                        }
                        else
                        {
                            File.Decrypt(maDir + entry.SteamID + ".maFile");
                        }
                    }
                    man.Save();
                    Entries = new List <CredManifestEntry>();
                    Save();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemple #4
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()));
            }
        }
Exemple #5
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);
        }
Exemple #6
0
        private static Manifest _generateNewManifest(bool scanDir = false)
        {
            // No directory means no manifest file anyways.
            Manifest newManifest = new Manifest
            {
                Version                       = new Version(1, 0),
                Encrypted                     = false,
                CredentialLocker              = false,
                AutoUnlockEncryptionManager   = false,
                UseMaFiles                    = true,
                AutoEntry                     = true,
                DeveloperMode                 = false,
                AutoRefreshSession            = false,
                PeriodicCheckingInterval      = 5,
                PeriodicChecking              = false,
                AutoConfirmMarketTransactions = false,
                AutoConfirmTrades             = false,
                DisplaySearch                 = false,
                SortAlpha                     = false,
                CheckForUpdates               = true,
                AllowBetaUpdates              = false,
                Entries                       = new List <ManifestEntry>(),

                BaseTheme    = Theme.Dark,
                PrimaryColor = Colors.Teal,
                AccentColor  = Colors.Pink,

                FirstRun = true
            };


            // Take a pre-manifest version and generate a manifest for it.
            if (scanDir)
            {
                string maDir = GetExecutableDir() + "\\maFiles\\";
                if (Directory.Exists(maDir))
                {
                    DirectoryInfo dir   = new DirectoryInfo(maDir);
                    var           files = dir.GetFiles();

                    foreach (var file in files)
                    {
                        if (file.Extension != ".maFile")
                        {
                            continue;
                        }

                        string            contents = File.ReadAllText(file.FullName);
                        SteamGuardAccount account  = new SteamGuardAccount();
                        account = JsonConvert.DeserializeObject <SteamGuardAccount>(Encryptor.DPAPIUnprotect(contents, Encryptor.AccountEntropy));

                        ManifestEntry newEntry = new ManifestEntry()
                        {
                            FileName  = file.Name,
                            SteamID   = account.Session.SteamID,
                            Encrypted = false,
                        };
                        newManifest.Entries.Add(newEntry);
                    }

                    if (newManifest.Entries.Count > 0)
                    {
                        newManifest.Save();
                        newManifest.PromptSetupPasskey(Properties.strings.ManifestPropmptSetupKey);
                    }
                }
            }

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

            return(null);
        }
Exemple #7
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);
            }
        }
Exemple #8
0
        public bool Save()
        {
            if (_originalCred != null)
            {
                try
                {
                    try // To delete the current stuff, you have to know the old stuff...
                    {
                        new PasswordVault().Remove(new PasswordCredential("SteamAuthenticator", "Storage", Encryptor.DPAPIUnprotect(_originalCred)));
                    }
                    catch (Exception)
                    {
                        //    System.Windows.MessageBox.Show("Failed to remove existing manifest!", "CredManifest");
                    }
                }
                catch (Exception)
                {
                    return(false);
                }
            }

            if (!Manifest.RememberPasskey)
            {
                UnsecureKey = ""; // 'Flush' it from memory then save the manifest. Note: unless the key gets resubmitted to CredManifest, it wont know the key until a program restart
            }
            else
            {
                Key = Key; // This refreshes the unsecure and secure copy
            }
            _originalCred = JsonConvert.SerializeObject(this);
            if (Manifest.UseDPAPI)
            {
                new PasswordVault().Add(new PasswordCredential("SteamAuthenticator", "Storage", Encryptor.DPAPIProtect(_originalCred)));
            }
            else
            {
                new PasswordVault().Add(new PasswordCredential("SteamAuthenticator", "Storage", _originalCred));
            }
            return(true);
        }