Esempio n. 1
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();
     }
 }
Esempio n. 2
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);
 }
Esempio n. 3
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); }
            }
        }