Logic to handle missing hash database if coreComponentsAreActive() is 'false' (dialogs are disabled)

This commit is contained in:
Eugene Livis 2016-06-24 13:11:38 -04:00
parent 5dc4d8af7d
commit e1a2fe77f5
2 changed files with 25 additions and 5 deletions

View File

@ -93,6 +93,9 @@ public class HashDbIngestModule implements FileIngestModule {
@Override @Override
public void startUp(org.sleuthkit.autopsy.ingest.IngestJobContext context) throws IngestModuleException { public void startUp(org.sleuthkit.autopsy.ingest.IngestJobContext context) throws IngestModuleException {
jobId = context.getJobId(); jobId = context.getJobId();
if (!hashDbManager.verifyAllDatabasesLoadedCorrectly()) {
throw new IngestModuleException("Could not load all hash databases");
}
updateEnabledHashSets(hashDbManager.getKnownBadFileHashSets(), knownBadHashSets); updateEnabledHashSets(hashDbManager.getKnownBadFileHashSets(), knownBadHashSets);
updateEnabledHashSets(hashDbManager.getKnownFileHashSets(), knownHashSets); updateEnabledHashSets(hashDbManager.getKnownFileHashSets(), knownHashSets);

View File

@ -38,6 +38,7 @@ import org.apache.commons.io.FilenameUtils;
import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.progress.ProgressHandle;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.openide.util.NbBundle.Messages; import org.openide.util.NbBundle.Messages;
import org.sleuthkit.autopsy.core.RuntimeProperties;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
import org.sleuthkit.autopsy.ingest.IngestManager; import org.sleuthkit.autopsy.ingest.IngestManager;
@ -63,6 +64,7 @@ public class HashDbManager implements PropertyChangeListener {
private Set<String> hashSetPaths = new HashSet<>(); private Set<String> hashSetPaths = new HashSet<>();
PropertyChangeSupport changeSupport = new PropertyChangeSupport(HashDbManager.class); PropertyChangeSupport changeSupport = new PropertyChangeSupport(HashDbManager.class);
private static final Logger logger = Logger.getLogger(HashDbManager.class.getName()); private static final Logger logger = Logger.getLogger(HashDbManager.class.getName());
private boolean allDatabasesLoadedCorrectly = true;
/** /**
* Property change event support In events: For both of these enums, the old * Property change event support In events: For both of these enums, the old
@ -93,6 +95,10 @@ public class HashDbManager implements PropertyChangeListener {
public synchronized void removePropertyChangeListener(PropertyChangeListener listener) { public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
changeSupport.removePropertyChangeListener(listener); changeSupport.removePropertyChangeListener(listener);
} }
public synchronized boolean verifyAllDatabasesLoadedCorrectly(){
return allDatabasesLoadedCorrectly;
}
private HashDbManager() { private HashDbManager() {
loadHashsetsConfiguration(); loadHashsetsConfiguration();
@ -457,7 +463,7 @@ public class HashDbManager implements PropertyChangeListener {
*/ */
@Messages({"# {0} - database name", "HashDbManager.noDbPath.message=Couldn't get valid database path for: {0}"}) @Messages({"# {0} - database name", "HashDbManager.noDbPath.message=Couldn't get valid database path for: {0}"})
private void configureSettings(HashLookupSettings settings) { private void configureSettings(HashLookupSettings settings) {
boolean dbInfoRemoved = false; allDatabasesLoadedCorrectly = true;
List<HashDbInfo> hashDbInfoList = settings.getHashDbInfo(); List<HashDbInfo> hashDbInfoList = settings.getHashDbInfo();
for (HashDbInfo hashDb : hashDbInfoList) { for (HashDbInfo hashDb : hashDbInfoList) {
try { try {
@ -466,7 +472,7 @@ public class HashDbManager implements PropertyChangeListener {
addHashDatabase(SleuthkitJNI.openHashDatabase(dbPath), hashDb.getHashSetName(), hashDb.getSearchDuringIngest(), hashDb.getSendIngestMessages(), hashDb.getKnownFilesType()); addHashDatabase(SleuthkitJNI.openHashDatabase(dbPath), hashDb.getHashSetName(), hashDb.getSearchDuringIngest(), hashDb.getSendIngestMessages(), hashDb.getKnownFilesType());
} else { } else {
logger.log(Level.WARNING, Bundle.HashDbManager_noDbPath_message(hashDb.getHashSetName())); logger.log(Level.WARNING, Bundle.HashDbManager_noDbPath_message(hashDb.getHashSetName()));
dbInfoRemoved = true; allDatabasesLoadedCorrectly = false;
} }
} catch (TskCoreException ex) { } catch (TskCoreException ex) {
Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error opening hash database", ex); //NON-NLS Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error opening hash database", ex); //NON-NLS
@ -475,13 +481,23 @@ public class HashDbManager implements PropertyChangeListener {
"HashDbManager.unableToOpenHashDbMsg", hashDb.getHashSetName()), "HashDbManager.unableToOpenHashDbMsg", hashDb.getHashSetName()),
NbBundle.getMessage(this.getClass(), "HashDbManager.openHashDbErr"), NbBundle.getMessage(this.getClass(), "HashDbManager.openHashDbErr"),
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
dbInfoRemoved = true; allDatabasesLoadedCorrectly = false;
} }
} }
if (dbInfoRemoved) {
/* NOTE: When RuntimeProperties.coreComponentsAreActive() is "false",
I don't think we should overwrite hash db settings file because we
were unable to load a database. The user should have to fix the issue or
remove the database from settings. Overwiting the settings effectively removes
the database from HashLookupSettings and the user may not know about this
because the dialogs are not being displayed. The next time user starts Autopsy, HashDB
will load without errors and the user may think that the problem was solved.*/
if (!allDatabasesLoadedCorrectly && RuntimeProperties.coreComponentsAreActive()) {
try { try {
HashLookupSettings.writeSettings(new HashLookupSettings(this.knownHashSets, this.knownBadHashSets)); HashLookupSettings.writeSettings(new HashLookupSettings(this.knownHashSets, this.knownBadHashSets));
allDatabasesLoadedCorrectly = true;
} catch (HashLookupSettings.HashLookupSettingsException ex) { } catch (HashLookupSettings.HashLookupSettingsException ex) {
allDatabasesLoadedCorrectly = false;
logger.log(Level.SEVERE, "Could not overwrite hash database settings.", ex); logger.log(Level.SEVERE, "Could not overwrite hash database settings.", ex);
} }
} }
@ -496,7 +512,8 @@ public class HashDbManager implements PropertyChangeListener {
// Give the user an opportunity to find the desired file. // Give the user an opportunity to find the desired file.
String newPath = null; String newPath = null;
if (JOptionPane.showConfirmDialog(null, if (RuntimeProperties.coreComponentsAreActive() &&
JOptionPane.showConfirmDialog(null,
NbBundle.getMessage(this.getClass(), "HashDbManager.dlgMsg.dbNotFoundAtLoc", NbBundle.getMessage(this.getClass(), "HashDbManager.dlgMsg.dbNotFoundAtLoc",
hashSetName, configuredPath), hashSetName, configuredPath),
NbBundle.getMessage(this.getClass(), "HashDbManager.dlgTitle.MissingDb"), NbBundle.getMessage(this.getClass(), "HashDbManager.dlgTitle.MissingDb"),