Esempio n. 1
0
        public static FavoriteConfigurationElementCollection GetFavorites(bool isDatabaseFavorite)
        {
            if (!isDatabaseFavorite)
            {
                TerminalsConfigurationSection section = GetSection();
                if (section != null)
                {
                    return(section.Favorites);
                }
            }
            else
            {
                FavoriteConfigurationElementCollection collection = new FavoriteConfigurationElementCollection();

                using (TerminalsObjectContext dc = TerminalsObjectContext.Create())
                {
                    if (dc == null)
                    {
                        return(null);
                    }

                    foreach (var connection in dc.Connections)
                    {
                        FavoriteConfigurationElement favorite = connection.ToFavorite();
                        collection.Add(favorite);
                    }
                }

                return(collection);
            }

            return(null);
        }
Esempio n. 2
0
        /// <summary>
        ///     During this procedure, the old master key material should be still present.
        ///     This finds all stored passwords and updates them to reflect new key material.
        /// </summary>
        private static void UpdateAllFavoritesPasswords(TerminalsConfigurationSection configSection, string newMasterPassword)
        {
            string newKeyMaterial = GetKeyMaterial(newMasterPassword);

            configSection.UpdatePasswordsByNewKeyMaterial(newKeyMaterial);
            UpdateFavoritePasswordsByNewKeyMaterial(newKeyMaterial);
            StoredCredentials.UpdatePasswordsByNewKeyMaterial(newKeyMaterial);
        }
Esempio n. 3
0
        private static void ConfigFileChanged(object sender, EventArgs e)
        {
            TerminalsConfigurationSection old = GetSection();

            ForceReload();
            ConfigurationChangedEventArgs args = ConfigurationChangedEventArgs.CreateFromSettings(old, GetSection());

            FireConfigurationChanged(args);
        }
Esempio n. 4
0
        internal FavoriteConfigurationElementCollection GetFavorites()
        {
            TerminalsConfigurationSection section = GetSection();

            if (section != null)
            {
                return(section.Favorites);
            }
            return(null);
        }
Esempio n. 5
0
        internal FavoriteConfigurationElement GetDefaultFavorite()
        {
            TerminalsConfigurationSection section = GetSection();

            if (section != null && section.DefaultFavorite.Count > 0)
            {
                return(section.DefaultFavorite[0]);
            }
            return(null);
        }
Esempio n. 6
0
        private void UpdateStoredPasswords(string newKeyMaterial)
        {
            TerminalsConfigurationSection configSection = GetSection();

            configSection.EncryptedDefaultPassword   = PasswordFunctions2.EncryptPassword(DefaultPassword, newKeyMaterial);
            configSection.EncryptedAmazonAccessKey   = PasswordFunctions2.EncryptPassword(AmazonAccessKey, newKeyMaterial);
            configSection.EncryptedAmazonSecretKey   = PasswordFunctions2.EncryptPassword(AmazonSecretKey, newKeyMaterial);
            configSection.EncryptedConnectionString  = PasswordFunctions2.EncryptPassword(ConnectionString, newKeyMaterial);
            configSection.DatabaseMasterPasswordHash = PasswordFunctions2.EncryptPassword(DatabaseMasterPassword, newKeyMaterial);
        }
        internal static ConfigurationChangedEventArgs CreateFromSettings(
          TerminalsConfigurationSection oldSettings,
          TerminalsConfigurationSection newSettings)
        {
            var args = new ConfigurationChangedEventArgs();

              args.OldFavorites = oldSettings.Favorites.ToList();
              args.NewFavorites = newSettings.Favorites.ToList();
              args.OldTags = oldSettings.Tags.ToList();
              args.NewTags = newSettings.Tags.ToList();

              return args;
        }
Esempio n. 8
0
        internal static ConfigurationChangedEventArgs CreateFromSettings(
            TerminalsConfigurationSection oldSettings,
            TerminalsConfigurationSection newSettings)
        {
            var args = new ConfigurationChangedEventArgs();

            args.OldFavorites = oldSettings.Favorites.ToList();
            args.NewFavorites = newSettings.Favorites.ToList();
            args.OldTags      = oldSettings.Tags.ToList();
            args.NewTags      = newSettings.Tags.ToList();

            return(args);
        }
Esempio n. 9
0
        public static void UpdateMasterPassword(string newPassword)
        {
            TerminalsConfigurationSection configSection = GetSection();

            UpdateAllFavoritesPasswords(configSection, newPassword);
            // start of not secured transaction. Old key is still present,
            // but passwords are already encrypted by newKey
            configSection.TerminalsPassword = newPassword;
            SaveImmediatelyIfRequested();

            // finish transaction, the passwords now reflect the new key
            UpdateKeyMaterial(newPassword);
        }
Esempio n. 10
0
 private static void EditFavoriteInSettings(FavoriteConfigurationElement favorite, string oldName)
 {
     if (!favorite.IsDatabaseFavorite)
     {
         TerminalsConfigurationSection section = GetSection();
         section.Favorites[oldName] = favorite.Clone() as FavoriteConfigurationElement;
         SaveImmediatelyIfRequested();
     }
     else
     {
         using (TerminalsObjectContext dc = TerminalsObjectContext.Create())
         {
             Sql.Connections connection = favorite.ToConnection(dc, dc.Connections.Where(x => x.Name == oldName).FirstOrDefault());
             dc.SaveChanges();
         }
     }
 }
Esempio n. 11
0
        private static TerminalsConfigurationSection GetSection()
        {
            if (remappingInProgress && remappingSection != null)
            {
                return(remappingSection);
            }

            try
            {
                remappingSection = null;
                return(Config.GetSection("settings") as TerminalsConfigurationSection);
            }
            catch (Exception ex)
            {
                if (!(remappingInProgress && remappingSection == null))
                {
                    Log.Warn("Warning remapping configuration file: " + ex.Message, ex);
                }

                try
                {
                    // kick into the import routine
                    _config = ImportConfiguration();
                    _config = GetConfiguration();

                    remappingSection = _config.GetSection("settings") as TerminalsConfigurationSection;

                    return(remappingSection);
                }
                catch (Exception importException)
                {
                    Log.Info("Terminals was able to automatically upgrade your existing connections.", importException);
                    return(new TerminalsConfigurationSection());
                }
            }
        }
Esempio n. 12
0
 private static TerminalsConfigurationSection GetSection()
 {
 	if (remappingInProgress && remappingSection != null)
 		return remappingSection;
 	
     try
     {
     	remappingSection = null;
         return Config.GetSection("settings") as TerminalsConfigurationSection;
     }
     catch (Exception ex)
     {
     	if (!(remappingInProgress && remappingSection == null))
     		Log.Warn("Warning remapping configuration file: " + ex.Message, ex);
     	
         try
         {
             // kick into the import routine
             _config = ImportConfiguration();
             _config = GetConfiguration();
             
             remappingSection = _config.GetSection("settings") as TerminalsConfigurationSection;
             
             return remappingSection;
         }
         catch (Exception importException)
         {
             Log.Info("Terminals was able to automatically upgrade your existing connections.", importException);
             return new TerminalsConfigurationSection();
         }
     }
 }