From 3ab8a95165becd7676221012ade1af2f7c806830 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Fri, 10 Nov 2017 12:44:48 -0500 Subject: [PATCH] Enable any central repo has sets the user personally creates by default. --- .../modules/hashdatabase/HashDbManager.java | 45 ++++++++++++++++++- .../hashdatabase/HashLookupSettingsPanel.java | 19 ++++---- 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index cd0b1339b7..8d03c4e37a 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -46,6 +46,7 @@ import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalSet; import org.sleuthkit.autopsy.core.RuntimeProperties; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; +import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.ingest.IngestManager; import org.sleuthkit.autopsy.modules.hashdatabase.HashLookupSettings.HashDbInfo; import org.sleuthkit.datamodel.AbstractFile; @@ -70,6 +71,8 @@ public class HashDbManager implements PropertyChangeListener { PropertyChangeSupport changeSupport = new PropertyChangeSupport(HashDbManager.class); private static final Logger logger = Logger.getLogger(HashDbManager.class.getName()); private boolean allDatabasesLoadedCorrectly = false; + private static final String CENTRAL_REPO_HASH_SET_SETTINGS = "CentralRepoHashSets"; + private static final String CENTRAL_REPO_HASH_SET_LOCAL_KEY = "LocallyCreatedHashsets"; /** * Property change event support In events: For both of these enums, the old @@ -697,6 +700,44 @@ public class HashDbManager implements PropertyChangeListener { } } } + + /** + * Save any newly created central repo databases to the properties file. + * @param newHashSets + */ + static void saveNewCentralRepoDatabases(List newHashSets){ + + if(! newHashSets.isEmpty()){ + String newDbs = ""; + for(CentralRepoHashDb db:newHashSets){ + newDbs += makeCentralRepoHashSetString(db); + } + String oldSetting = ModuleSettings.getConfigSetting(CENTRAL_REPO_HASH_SET_SETTINGS, CENTRAL_REPO_HASH_SET_LOCAL_KEY); + String newSetting = ""; + if((oldSetting != null) && (! oldSetting.isEmpty())){ + newSetting = oldSetting; + } + newSetting += newDbs; + ModuleSettings.setConfigSetting(CENTRAL_REPO_HASH_SET_SETTINGS, CENTRAL_REPO_HASH_SET_LOCAL_KEY, newSetting); + } + } + + /** + * Check whether a given central repository hash set was created on this machine. + * @return true if it was created on this machine, false otherwise + */ + static boolean centralRepoWasCreatedLocally(CentralRepoHashDb db){ + String setting = ModuleSettings.getConfigSetting(CENTRAL_REPO_HASH_SET_SETTINGS, CENTRAL_REPO_HASH_SET_LOCAL_KEY); + String dbStr = makeCentralRepoHashSetString(db); + if(setting == null){ + return false; + } + return setting.contains(dbStr); + } + + private static String makeCentralRepoHashSetString(CentralRepoHashDb db){ + return "|" + db.getReferenceSetID() + "." + db.getHashSetName() + "." + db.getVersion() + "|"; + } private boolean hashDbInfoIsNew(HashDbInfo dbInfo){ for(HashDatabase db:this.hashSets){ @@ -1258,8 +1299,8 @@ public class HashDbManager implements PropertyChangeListener { @Override public boolean getDefaultSearchDuringIngest(){ - // Central repo hash sets are off by default - return false; + // Central repo hash sets are off by default, unless created on this machine + return centralRepoWasCreatedLocally(this); } @Override diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java index 0a299a6e87..4b40c60386 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java @@ -27,7 +27,6 @@ import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import javax.swing.JComponent; -import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JTable; import javax.swing.ListSelectionModel; @@ -66,7 +65,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan .getMessage(HashLookupSettingsPanel.class, "HashDbConfigPanel.errorGettingIndexStatusText"); private final HashDbManager hashSetManager = HashDbManager.getInstance(); private final HashSetTableModel hashSetTableModel = new HashSetTableModel(); - private final List newReferenceSetIDs = new ArrayList<>(); + private final List newReferenceSets = new ArrayList<>(); public HashLookupSettingsPanel() { initComponents(); @@ -328,7 +327,8 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan try { hashSetManager.save(); - newReferenceSetIDs.clear(); + HashDbManager.getInstance().saveNewCentralRepoDatabases(newReferenceSets); + newReferenceSets.clear(); } catch (HashDbManager.HashDbManagerException ex) { SwingUtilities.invokeLater(() -> { JOptionPane.showMessageDialog(null, Bundle.HashLookupSettingsPanel_saveFail_message(), Bundle.HashLookupSettingsPanel_saveFail_title(), JOptionPane.ERROR_MESSAGE); @@ -355,10 +355,10 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan */ if (IngestManager.getInstance().isIngestRunning() == false) { // Remove any new central repo hash sets from the database - for(int refID:newReferenceSetIDs){ + for(CentralRepoHashDb db:newReferenceSets){ try{ if(EamDb.isEnabled()){ - EamDb.getInstance().deleteReferenceSet(refID); + EamDb.getInstance().deleteReferenceSet(db.getReferenceSetID()); } else { // This is the case where the user imported a database, then switched over to the central // repo panel and disabled it before cancelling. We can't delete the database at this point. @@ -368,6 +368,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan Logger.getLogger(HashLookupSettingsPanel.class.getName()).log(Level.SEVERE, "Error reverting central repository hash sets", ex); //NON-NLS } } + newReferenceSets.clear(); HashDbManager.getInstance().loadLastSavedConfiguration(); } @@ -922,8 +923,8 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan HashDatabase hashDb = new HashDbCreateDatabaseDialog().getHashDatabase(); if (null != hashDb) { if(hashDb instanceof CentralRepoHashDb){ - int newDbIndex = ((CentralRepoHashDb)hashDb).getReferenceSetID(); - newReferenceSetIDs.add(newDbIndex); + CentralRepoHashDb crDb = (CentralRepoHashDb)hashDb; + newReferenceSets.add(crDb); } hashSetTableModel.refreshModel(); @@ -976,8 +977,8 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan HashDatabase hashDb = new HashDbImportDatabaseDialog().getHashDatabase(); if (null != hashDb) { if(hashDb instanceof CentralRepoHashDb){ - int newReferenceSetID = ((CentralRepoHashDb)hashDb).getReferenceSetID(); - newReferenceSetIDs.add(newReferenceSetID); + CentralRepoHashDb crDb = (CentralRepoHashDb)hashDb; + newReferenceSets.add(crDb); } hashSetTableModel.refreshModel();