From b31b4a0f258a826880394a76125de4374fb50c3a Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Fri, 6 Oct 2017 11:31:56 -0400 Subject: [PATCH 01/41] Made new HashDatabase interface. Now records whether the HashDatabase is enabled in the object, not in the module settings. --- .../AddContentToHashDbAction.java | 10 +- .../AddHashValuesToDatabaseDialog.java | 6 +- ...AddHashValuesToDatabaseProgressDialog.java | 6 +- .../HashDbCreateDatabaseDialog.java | 6 +- .../HashDbImportDatabaseDialog.java | 6 +- .../hashdatabase/HashDbIngestModule.java | 26 +- .../modules/hashdatabase/HashDbManager.java | 310 ++++++++++++++---- .../hashdatabase/HashLookupModuleFactory.java | 8 +- .../HashLookupModuleSettings.java | 99 +++--- .../HashLookupModuleSettingsPanel.java | 94 +++--- .../hashdatabase/HashLookupSettings.java | 112 +++++-- .../hashdatabase/HashLookupSettingsPanel.java | 41 +-- .../modules/hashdatabase/ModalNoButtons.java | 13 +- .../taggedhashes/AddTaggedHashesToHashDb.java | 4 +- .../AddTaggedHashesToHashDbConfigPanel.java | 12 +- 15 files changed, 505 insertions(+), 248 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddContentToHashDbAction.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddContentToHashDbAction.java index 5ec70ce3b9..8c9df922bf 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddContentToHashDbAction.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddContentToHashDbAction.java @@ -32,10 +32,10 @@ import org.openide.util.Utilities; import org.openide.util.actions.Presenter; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.ingest.IngestManager; -import static org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.HashUtility; import org.sleuthkit.datamodel.TskCoreException; +import static org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; /** * Instances of this Action allow users to content to a hash database. @@ -106,9 +106,9 @@ final class AddContentToHashDbAction extends AbstractAction implements Presenter // Get the current set of updateable hash databases and add each // one to the menu as a separate menu item. Selecting a hash database // adds the selected files to the selected database. - final List hashDatabases = HashDbManager.getInstance().getUpdateableHashSets(); + final List hashDatabases = HashDbManager.getInstance().getUpdateableHashSetsNew(); if (!hashDatabases.isEmpty()) { - for (final HashDb database : hashDatabases) { + for (final HashDatabase database : hashDatabases) { JMenuItem databaseItem = add(database.getHashSetName()); databaseItem.addActionListener(new ActionListener() { @Override @@ -134,7 +134,7 @@ final class AddContentToHashDbAction extends AbstractAction implements Presenter newHashSetItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - HashDb hashDb = new HashDbCreateDatabaseDialog().getHashDatabase(); + HashDatabase hashDb = new HashDbCreateDatabaseDialog().getHashDatabase(); if (null != hashDb) { addFilesToHashSet(selectedFiles, hashDb); } @@ -143,7 +143,7 @@ final class AddContentToHashDbAction extends AbstractAction implements Presenter add(newHashSetItem); } - private void addFilesToHashSet(final Collection files, HashDb hashSet) { + private void addFilesToHashSet(final Collection files, HashDatabase hashSet) { for (AbstractFile file : files) { String md5Hash = file.getMd5Hash(); if (null != md5Hash) { diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseDialog.java index 40db15718f..debe46f47c 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseDialog.java @@ -31,8 +31,8 @@ import javax.swing.JPopupMenu; import javax.swing.SwingUtilities; import org.openide.util.NbBundle; import org.openide.windows.WindowManager; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; import org.sleuthkit.datamodel.HashEntry; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; /** * @@ -40,7 +40,7 @@ import org.sleuthkit.datamodel.HashEntry; */ public class AddHashValuesToDatabaseDialog extends javax.swing.JDialog { - HashDb hashDb; + HashDatabase hashDb; Pattern md5Pattern = Pattern.compile("^[a-fA-F0-9]{32}$"); List hashes = new ArrayList<>(); List invalidHashes = new ArrayList<>(); @@ -49,7 +49,7 @@ public class AddHashValuesToDatabaseDialog extends javax.swing.JDialog { * Displays a dialog that allows a user to add hash values to the selected * database. */ - AddHashValuesToDatabaseDialog(HashDb hashDb) { + AddHashValuesToDatabaseDialog(HashDatabase hashDb) { super((JFrame) WindowManager.getDefault().getMainWindow(), NbBundle.getMessage(AddHashValuesToDatabaseDialog.class, "AddHashValuesToDatabaseDialog.JDialog.Title", hashDb.getHashSetName()), true); diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseProgressDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseProgressDialog.java index f712a965fd..77483e1d42 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseProgressDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseProgressDialog.java @@ -31,9 +31,9 @@ import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.SwingWorker; import org.openide.util.NbBundle; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; import org.sleuthkit.datamodel.HashEntry; import org.sleuthkit.datamodel.TskCoreException; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; /** * @@ -43,7 +43,7 @@ public class AddHashValuesToDatabaseProgressDialog extends javax.swing.JDialog { private final AddHashValuesToDatabaseDialog parentRef; private boolean disposeParent = false; - private final HashDb hashDb; + private final HashDatabase hashDb; private final List hashes; private final List invalidHashes; private final Pattern md5Pattern; @@ -58,7 +58,7 @@ public class AddHashValuesToDatabaseProgressDialog extends javax.swing.JDialog { * @param hashDb * @param text */ - AddHashValuesToDatabaseProgressDialog(AddHashValuesToDatabaseDialog parent, HashDb hashDb, String text) { + AddHashValuesToDatabaseProgressDialog(AddHashValuesToDatabaseDialog parent, HashDatabase hashDb, String text) { super(parent); initComponents(); display(); diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java index d07f5a034c..0bea515d14 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java @@ -33,9 +33,9 @@ import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.PlatformUtil; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb.KnownFilesType; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDbManagerException; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; /** * Instances of this class allow a user to create a new hash database and add it @@ -47,7 +47,7 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog { private static final String DEFAULT_FILE_NAME = NbBundle .getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.defaultFileName"); private JFileChooser fileChooser = null; - private HashDb newHashDb = null; + private HashDatabase newHashDb = null; private final static String LAST_FILE_PATH_KEY = "HashDbCreate_Path"; /** @@ -67,7 +67,7 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog { * * @return A HashDb object or null. */ - HashDb getHashDatabase() { + HashDatabase getHashDatabase() { return newHashDb; } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java index e3d49d534d..a533babaea 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java @@ -34,9 +34,9 @@ import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.PlatformUtil; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb.KnownFilesType; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDbManagerException; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; /** * Instances of this class allow a user to select an existing hash database and @@ -47,7 +47,7 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { private JFileChooser fileChooser = new JFileChooser(); private String selectedFilePath = ""; - private HashDb selectedHashDb = null; + private HashDatabase selectedHashDb = null; private final static String LAST_FILE_PATH_KEY = "HashDbImport_Path"; /** @@ -69,7 +69,7 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { * * @return A HashDb object or null. */ - HashDb getHashDatabase() { + HashDatabase getHashDatabase() { return selectedHashDb; } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java index 3dd7416872..f87aa47d52 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java @@ -36,7 +36,7 @@ import org.sleuthkit.autopsy.ingest.IngestMessage; import org.sleuthkit.autopsy.ingest.IngestModuleReferenceCounter; import org.sleuthkit.autopsy.ingest.IngestServices; import org.sleuthkit.autopsy.ingest.ModuleDataEvent; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE; @@ -63,8 +63,8 @@ public class HashDbIngestModule implements FileIngestModule { private final SleuthkitCase skCase = Case.getCurrentCase().getSleuthkitCase(); private final HashDbManager hashDbManager = HashDbManager.getInstance(); private final HashLookupModuleSettings settings; - private List knownBadHashSets = new ArrayList<>(); - private List knownHashSets = new ArrayList<>(); + private List knownBadHashSets = new ArrayList<>(); + private List knownHashSets = new ArrayList<>(); private long jobId; private static final HashMap totalsForIngestJobs = new HashMap<>(); private static final IngestModuleReferenceCounter refCounter = new IngestModuleReferenceCounter(); @@ -96,8 +96,8 @@ public class HashDbIngestModule implements FileIngestModule { if (!hashDbManager.verifyAllDatabasesLoadedCorrectly()) { throw new IngestModuleException("Could not load all hash databases"); } - updateEnabledHashSets(hashDbManager.getKnownBadFileHashSets(), knownBadHashSets); - updateEnabledHashSets(hashDbManager.getKnownFileHashSets(), knownHashSets); + updateEnabledHashSets(hashDbManager.getKnownBadFileHashSetsNew(), knownBadHashSets); + updateEnabledHashSets(hashDbManager.getKnownFileHashSetsNew(), knownHashSets); if (refCounter.incrementAndGet(jobId) == 1) { // initialize job totals @@ -126,12 +126,12 @@ public class HashDbIngestModule implements FileIngestModule { * @param allHashSets List of all hashsets from DB manager * @param enabledHashSets List of enabled ones to return. */ - private void updateEnabledHashSets(List allHashSets, List enabledHashSets) { + private void updateEnabledHashSets(List allHashSets, List enabledHashSets) { enabledHashSets.clear(); - for (HashDb db : allHashSets) { - if (settings.isHashSetEnabled(db.getHashSetName())) { + for (HashDatabase db : allHashSets) { + if (db.getSearchDuringIngest()) { try { - if (db.hasIndex()) { + if (db.isValid()) { enabledHashSets.add(db); } } catch (TskCoreException ex) { @@ -196,7 +196,7 @@ public class HashDbIngestModule implements FileIngestModule { // look up in notable first boolean foundBad = false; ProcessResult ret = ProcessResult.OK; - for (HashDb db : knownBadHashSets) { + for (HashDatabase db : knownBadHashSets) { try { long lookupstart = System.currentTimeMillis(); HashHitInfo hashInfo = db.lookupMD5(file); @@ -257,7 +257,7 @@ public class HashDbIngestModule implements FileIngestModule { // Any hit is sufficient to classify it as known, and there is no need to create // a hit artifact or send a message to the application inbox. if (!foundBad) { - for (HashDb db : knownHashSets) { + for (HashDatabase db : knownHashSets) { try { long lookupstart = System.currentTimeMillis(); if (db.lookupMD5Quick(file)) { @@ -359,7 +359,7 @@ public class HashDbIngestModule implements FileIngestModule { } private static synchronized void postSummary(long jobId, - List knownBadHashSets, List knownHashSets) { + List knownBadHashSets, List knownHashSets) { IngestJobTotals jobTotals = getTotalsForIngestJobs(jobId); totalsForIngestJobs.remove(jobId); @@ -384,7 +384,7 @@ public class HashDbIngestModule implements FileIngestModule { detailsSb.append("

") //NON-NLS .append(NbBundle.getMessage(HashDbIngestModule.class, "HashDbIngestModule.complete.databasesUsed")) .append("

\n
    "); //NON-NLS - for (HashDb db : knownBadHashSets) { + for (HashDatabase db : knownBadHashSets) { detailsSb.append("
  • ").append(db.getHashSetName()).append("
  • \n"); //NON-NLS } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index f10f16e3f9..6864cf9c58 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -58,8 +58,9 @@ public class HashDbManager implements PropertyChangeListener { private static final String HASH_DATABASE_FILE_EXTENSON = "kdb"; //NON-NLS private static HashDbManager instance = null; - private List knownHashSets = new ArrayList<>(); - private List knownBadHashSets = new ArrayList<>(); + //private List knownHashSets = new ArrayList<>(); + //private List knownBadHashSets = new ArrayList<>(); + private List hashSets = new ArrayList<>(); private Set hashSetNames = new HashSet<>(); private Set hashSetPaths = new HashSet<>(); PropertyChangeSupport changeSupport = new PropertyChangeSupport(HashDbManager.class); @@ -167,7 +168,7 @@ public class HashDbManager implements PropertyChangeListener { throw new HashDbManagerException(NbBundle.getMessage(HashDbManager.class, "HashDbManager.duplicateHashSetNameExceptionMsg", hashSetName)); } - hashDb = addHashDatabase(SleuthkitJNI.openHashDatabase(path), hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType); + hashDb = addFileTypeHashDatabase(SleuthkitJNI.openHashDatabase(path), hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType); } catch (TskCoreException ex) { throw new HashDbManagerException(ex.getMessage()); } @@ -224,14 +225,24 @@ public class HashDbManager implements PropertyChangeListener { throw new HashDbManagerException(NbBundle.getMessage(HashDbManager.class, "HashDbManager.duplicateHashSetNameExceptionMsg", hashSetName)); } - hashDb = addHashDatabase(SleuthkitJNI.createHashDatabase(path), hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType); + hashDb = addFileTypeHashDatabase(SleuthkitJNI.createHashDatabase(path), hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType); } catch (TskCoreException ex) { throw new HashDbManagerException(ex.getMessage()); } return hashDb; } + + static HashDatabase convertHashDbInfo(HashDbInfo info, int handle) throws TskCoreException{ + if(info.isFileDatabaseType()){ + return new HashDb(handle, info.getHashSetName(), info.getSearchDuringIngest(), info.getSendIngestMessages(), + info.getKnownFilesType()); + } else if(info.isCentralRepoDatabaseType()){ + throw new TskCoreException("Not done"); + } + throw new TskCoreException("Invalid database type in HashDbInfo"); + } - private HashDb addHashDatabase(int handle, String hashSetName, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws TskCoreException { + private HashDb addFileTypeHashDatabase(int handle, String hashSetName, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws TskCoreException { // Wrap an object around the handle. HashDb hashDb = new HashDb(handle, hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType); @@ -250,12 +261,8 @@ public class HashDbManager implements PropertyChangeListener { hashSetPaths.add(indexPath); } - // Add the hash database to the appropriate collection for its type. - if (hashDb.getKnownFilesType() == HashDb.KnownFilesType.KNOWN) { - knownHashSets.add(hashDb); - } else { - knownBadHashSets.add(hashDb); - } + // Add the hash database to the collection + hashSets.add(hashDb); // Let any external listeners know that there's a new set try { @@ -270,7 +277,7 @@ public class HashDbManager implements PropertyChangeListener { return hashDb; } - synchronized void indexHashDatabase(HashDb hashDb) { + synchronized void indexHashDatabase(HashDatabase hashDb) { hashDb.addPropertyChangeListener(this); HashDbIndexer creator = new HashDbIndexer(hashDb); creator.execute(); @@ -306,7 +313,12 @@ public class HashDbManager implements PropertyChangeListener { this.save(); } - public synchronized void removeHashDatabaseNoSave(HashDb hashDb) throws HashDbManagerException { + // public synchronized void removeHashDatabaseNoSave(HashDb hashDb) throws HashDbManagerException { + // removeHashDatabaseNoSave((UnnamedHashSet)hashDb); + // + // } + + public synchronized void removeHashDatabaseNoSave(HashDatabase hashDb) throws HashDbManagerException { // Don't remove a database if ingest is running boolean ingestIsRunning = IngestManager.getInstance().isIngestRunning(); if (ingestIsRunning) { @@ -317,16 +329,19 @@ public class HashDbManager implements PropertyChangeListener { // hash set names are used, before undertaking These operations will succeed and constitute // a mostly effective removal, even if the subsequent operations fail. String hashSetName = hashDb.getHashSetName(); - knownHashSets.remove(hashDb); - knownBadHashSets.remove(hashDb); hashSetNames.remove(hashSetName); + hashSets.remove(hashDb); // Now undertake the operations that could throw. + try { - hashSetPaths.remove(hashDb.getIndexPath()); + if(hashDb.hasIndex()){ + hashSetPaths.remove(hashDb.getIndexPath()); + } } catch (TskCoreException ex) { Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error getting index path of " + hashDb.getHashSetName() + " hash database when removing the database", ex); //NON-NLS - } + } + try { if (!hashDb.hasIndexOnly()) { hashSetPaths.remove(hashDb.getDatabasePath()); @@ -334,6 +349,7 @@ public class HashDbManager implements PropertyChangeListener { } catch (TskCoreException ex) { Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error getting database path of " + hashDb.getHashSetName() + " hash database when removing the database", ex); //NON-NLS } + try { hashDb.close(); } catch (TskCoreException ex) { @@ -354,7 +370,7 @@ public class HashDbManager implements PropertyChangeListener { void save() throws HashDbManagerException { try { - if (!HashLookupSettings.writeSettings(new HashLookupSettings(this.knownHashSets, this.knownBadHashSets))) { + if (!HashLookupSettings.writeSettings(new HashLookupSettings(HashLookupSettings.convertHashSetList(this.hashSets)))) { throw new HashDbManagerException(NbBundle.getMessage(this.getClass(), "HashDbManager.saveErrorExceptionMsg")); } } catch (HashLookupSettings.HashLookupSettingsException ex) { @@ -368,10 +384,18 @@ public class HashDbManager implements PropertyChangeListener { * * @return A list, possibly empty, of hash databases. */ + @Deprecated public synchronized List getAllHashSets() { List hashDbs = new ArrayList<>(); - hashDbs.addAll(knownHashSets); - hashDbs.addAll(knownBadHashSets); + this.hashSets.stream().filter((thisSet) -> (thisSet instanceof HashDb)).forEach((thisSet) -> { + hashDbs.add((HashDb)thisSet); + }); + return hashDbs; + } + + public synchronized List getAllHashSetsNew(){ + List hashDbs = new ArrayList<>(); + hashDbs.addAll(this.hashSets); return hashDbs; } @@ -380,20 +404,42 @@ public class HashDbManager implements PropertyChangeListener { * * @return A list, possibly empty, of hash databases. */ + @Deprecated public synchronized List getKnownFileHashSets() { List hashDbs = new ArrayList<>(); - hashDbs.addAll(knownHashSets); + this.hashSets.stream().filter((thisSet) -> ((thisSet instanceof HashDb) && (thisSet.getKnownFilesType() == HashDb.KnownFilesType.KNOWN))).forEach((thisSet) -> { + hashDbs.add((HashDb)thisSet); + }); return hashDbs; } + + public synchronized List getKnownFileHashSetsNew() { + List hashDbs = new ArrayList<>(); + this.hashSets.stream().filter((db) -> (db.getKnownFilesType() == HashDb.KnownFilesType.KNOWN)).forEach((db) -> { + hashDbs.add(db); + }); + return hashDbs; + } /** * Gets all of the hash databases used to classify files as notable. * * @return A list, possibly empty, of hash databases. */ + @Deprecated public synchronized List getKnownBadFileHashSets() { List hashDbs = new ArrayList<>(); - hashDbs.addAll(knownBadHashSets); + this.hashSets.stream().filter((thisSet) -> ((thisSet instanceof HashDb) && (thisSet.getKnownFilesType() == HashDb.KnownFilesType.KNOWN_BAD))).forEach((thisSet) -> { + hashDbs.add((HashDb)thisSet); + }); + return hashDbs; + } + + public synchronized List getKnownBadFileHashSetsNew() { + List hashDbs = new ArrayList<>(); + this.hashSets.stream().filter((db) -> (db.getKnownFilesType() == HashDb.KnownFilesType.KNOWN_BAD)).forEach((db) -> { + hashDbs.add(db); + }); return hashDbs; } @@ -402,15 +448,23 @@ public class HashDbManager implements PropertyChangeListener { * * @return A list, possibly empty, of hash databases. */ + @Deprecated public synchronized List getUpdateableHashSets() { - List updateableDbs = getUpdateableHashSets(knownHashSets); - updateableDbs.addAll(getUpdateableHashSets(knownBadHashSets)); + List updateableDbs = new ArrayList<>(); + List updateableHashSets = getUpdateableHashSets(this.hashSets); + updateableHashSets.stream().filter((db) -> (db instanceof HashDb)).forEach((db) -> { + updateableDbs.add((HashDb)db); + }); return updateableDbs; } + + public synchronized List getUpdateableHashSetsNew(){ + return getUpdateableHashSets(this.hashSets); + } - private List getUpdateableHashSets(List hashDbs) { - ArrayList updateableDbs = new ArrayList<>(); - for (HashDb db : hashDbs) { + private List getUpdateableHashSets(List hashDbs) { + ArrayList updateableDbs = new ArrayList<>(); + for (HashDatabase db : hashDbs) { try { if (db.isUpdateable()) { updateableDbs.add(db); @@ -427,16 +481,15 @@ public class HashDbManager implements PropertyChangeListener { * cancellation of configuration panels. */ public synchronized void loadLastSavedConfiguration() { - closeHashDatabases(knownHashSets); - closeHashDatabases(knownBadHashSets); + closeHashDatabases(this.hashSets); hashSetNames.clear(); hashSetPaths.clear(); loadHashsetsConfiguration(); } - private void closeHashDatabases(List hashDatabases) { - for (HashDb database : hashDatabases) { + private void closeHashDatabases(List hashDatabases) { + for (HashDatabase database : hashDatabases) { try { database.close(); } catch (TskCoreException ex) { @@ -465,20 +518,24 @@ public class HashDbManager implements PropertyChangeListener { private void configureSettings(HashLookupSettings settings) { allDatabasesLoadedCorrectly = true; List hashDbInfoList = settings.getHashDbInfo(); - for (HashDbInfo hashDb : hashDbInfoList) { + for (HashDbInfo hashDbInfo : hashDbInfoList) { try { - String dbPath = this.getValidFilePath(hashDb.getHashSetName(), hashDb.getPath()); - if (dbPath != null) { - addHashDatabase(SleuthkitJNI.openHashDatabase(dbPath), hashDb.getHashSetName(), hashDb.getSearchDuringIngest(), hashDb.getSendIngestMessages(), hashDb.getKnownFilesType()); + if(hashDbInfo.isFileDatabaseType()){ + String dbPath = this.getValidFilePath(hashDbInfo.getHashSetName(), hashDbInfo.getPath()); + if (dbPath != null) { + addFileTypeHashDatabase(SleuthkitJNI.openHashDatabase(dbPath), hashDbInfo.getHashSetName(), hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), hashDbInfo.getKnownFilesType()); + } else { + logger.log(Level.WARNING, Bundle.HashDbManager_noDbPath_message(hashDbInfo.getHashSetName())); + allDatabasesLoadedCorrectly = false; + } } else { - logger.log(Level.WARNING, Bundle.HashDbManager_noDbPath_message(hashDb.getHashSetName())); - allDatabasesLoadedCorrectly = false; + Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "CR not implemented!"); //NON-NLS } } catch (TskCoreException ex) { Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error opening hash database", ex); //NON-NLS JOptionPane.showMessageDialog(null, NbBundle.getMessage(this.getClass(), - "HashDbManager.unableToOpenHashDbMsg", hashDb.getHashSetName()), + "HashDbManager.unableToOpenHashDbMsg", hashDbInfo.getHashSetName()), NbBundle.getMessage(this.getClass(), "HashDbManager.openHashDbErr"), JOptionPane.ERROR_MESSAGE); allDatabasesLoadedCorrectly = false; @@ -494,7 +551,7 @@ public class HashDbManager implements PropertyChangeListener { will load without errors and the user may think that the problem was solved.*/ if (!allDatabasesLoadedCorrectly && RuntimeProperties.runningWithGUI()) { try { - HashLookupSettings.writeSettings(new HashLookupSettings(this.knownHashSets, this.knownBadHashSets)); + HashLookupSettings.writeSettings(new HashLookupSettings(HashLookupSettings.convertHashSetList(this.hashSets))); allDatabasesLoadedCorrectly = true; } catch (HashLookupSettings.HashLookupSettingsException ex) { allDatabasesLoadedCorrectly = false; @@ -549,12 +606,92 @@ public class HashDbManager implements PropertyChangeListener { } return filePath; } + + public static interface HashDatabase { + enum DatabaseType{ + FILE, + CENTRAL_REPOSITORY + }; + + public String getHashSetName(); + + public String getDatabasePath() throws TskCoreException; + + public HashDb.KnownFilesType getKnownFilesType(); + + public boolean getSearchDuringIngest(); + + void setSearchDuringIngest(boolean useForIngest); + + public boolean getSendIngestMessages(); + + void setSendIngestMessages(boolean showInboxMessages); + + /** + * Indicates whether the hash database accepts updates. + * + * @return True if the database accepts updates, false otherwise. + * + * @throws org.sleuthkit.datamodel.TskCoreException + */ + public boolean isUpdateable() throws TskCoreException; + + /** + * Adds hashes of content (if calculated) to the hash database. + * + * @param content The content for which the calculated hashes, if any, + * are to be added to the hash database. + * + * @throws TskCoreException + */ + public void addHashes(Content content) throws TskCoreException; + + public void addHashes(Content content, String comment) throws TskCoreException; + + public void addHashes(List hashes) throws TskCoreException; + + public boolean lookupMD5Quick(Content content) throws TskCoreException; + + public HashHitInfo lookupMD5(Content content) throws TskCoreException; + + public String getIndexPath() throws TskCoreException; + + public boolean hasIndex() throws TskCoreException; + + public boolean hasIndexOnly() throws TskCoreException; + + public boolean isIndexing(); + + public void setIndexing(boolean indexing); + + public boolean canBeReIndexed() throws TskCoreException; + + /** + * Returns whether this database can be enabled. + * For file type, this is the same as checking that it has an index + * @return true if is valid, false otherwise + * @throws TskCoreException + */ + public boolean isValid() throws TskCoreException; + + public int getHandle(); + + public void firePropertyChange(String propertyName, Object oldValue, Object newValue); + + public void addPropertyChangeListener(PropertyChangeListener pcl); + + public void removePropertyChangeListener(PropertyChangeListener pcl); + + void close() throws TskCoreException; + + DatabaseType getDatabaseType(); + } /** * Instances of this class represent hash databases used to classify files * as known or know bad. */ - public static class HashDb { + public static class HashDb implements HashDatabase{ /** * Indicates how files with hashes stored in a particular hash database @@ -587,7 +724,7 @@ public class HashDbManager implements PropertyChangeListener { private final String hashSetName; private boolean searchDuringIngest; private boolean sendIngestMessages; - private final KnownFilesType knownFilesType; + private final HashDb.KnownFilesType knownFilesType; private boolean indexing; private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); @@ -602,9 +739,11 @@ public class HashDbManager implements PropertyChangeListener { /** * Adds a listener for the events defined in HashDb.Event. + * Listeners are used during indexing. * * @param pcl */ + @Override public void addPropertyChangeListener(PropertyChangeListener pcl) { propertyChangeSupport.addPropertyChangeListener(pcl); } @@ -614,39 +753,71 @@ public class HashDbManager implements PropertyChangeListener { * * @param pcl */ + @Override public void removePropertyChangeListener(PropertyChangeListener pcl) { propertyChangeSupport.removePropertyChangeListener(pcl); } + + @Override + public int getHandle(){ + return handle; + } + @Override public String getHashSetName() { return hashSetName; } + @Override public String getDatabasePath() throws TskCoreException { return SleuthkitJNI.getHashDatabasePath(handle); } + + @Override + public void setIndexing(boolean indexing){ + this.indexing = indexing; + } + + @Override + public DatabaseType getDatabaseType(){ + if(this instanceof HashDb){ + return DatabaseType.FILE; + } else { + return DatabaseType.CENTRAL_REPOSITORY; + } + } + + public boolean hasIndexFile() { + return true; + } + @Override public String getIndexPath() throws TskCoreException { return SleuthkitJNI.getHashDatabaseIndexPath(handle); } + @Override public KnownFilesType getKnownFilesType() { return knownFilesType; } + @Override public boolean getSearchDuringIngest() { return searchDuringIngest; } - void setSearchDuringIngest(boolean useForIngest) { + @Override + public void setSearchDuringIngest(boolean useForIngest) { this.searchDuringIngest = useForIngest; } + @Override public boolean getSendIngestMessages() { return sendIngestMessages; } - void setSendIngestMessages(boolean showInboxMessages) { + @Override + public void setSendIngestMessages(boolean showInboxMessages) { this.sendIngestMessages = showInboxMessages; } @@ -657,6 +828,7 @@ public class HashDbManager implements PropertyChangeListener { * * @throws org.sleuthkit.datamodel.TskCoreException */ + @Override public boolean isUpdateable() throws TskCoreException { return SleuthkitJNI.isUpdateableHashDatabase(this.handle); } @@ -669,6 +841,7 @@ public class HashDbManager implements PropertyChangeListener { * * @throws TskCoreException */ + @Override public void addHashes(Content content) throws TskCoreException { addHashes(content, null); } @@ -683,6 +856,7 @@ public class HashDbManager implements PropertyChangeListener { * * @throws TskCoreException */ + @Override public void addHashes(Content content, String comment) throws TskCoreException { // This only works for AbstractFiles and MD5 hashes at present. assert content instanceof AbstractFile; @@ -701,6 +875,7 @@ public class HashDbManager implements PropertyChangeListener { * * @throws TskCoreException */ + @Override public void addHashes(List hashes) throws TskCoreException { SleuthkitJNI.addToHashDatabase(hashes, handle); } @@ -714,6 +889,7 @@ public class HashDbManager implements PropertyChangeListener { * * @throws TskCoreException */ + @Override public boolean lookupMD5Quick(Content content) throws TskCoreException { boolean result = false; assert content instanceof AbstractFile; @@ -735,6 +911,7 @@ public class HashDbManager implements PropertyChangeListener { * * @throws TskCoreException */ + @Override public HashHitInfo lookupMD5(Content content) throws TskCoreException { HashHitInfo result = null; // This only works for AbstractFiles and MD5 hashes at present. @@ -747,24 +924,45 @@ public class HashDbManager implements PropertyChangeListener { } return result; } + + /** + * Returns whether this database can be enabled. + * For file type, this is the same as checking that it has an index + * @return true if is valid, false otherwise + * @throws TskCoreException + */ + @Override + public boolean isValid() throws TskCoreException { + return hasIndex(); + } - boolean hasIndex() throws TskCoreException { + @Override + public boolean hasIndex() throws TskCoreException { return SleuthkitJNI.hashDatabaseHasLookupIndex(handle); } + @Override public boolean hasIndexOnly() throws TskCoreException { return SleuthkitJNI.hashDatabaseIsIndexOnly(handle); } - boolean canBeReIndexed() throws TskCoreException { + @Override + public boolean canBeReIndexed() throws TskCoreException { return SleuthkitJNI.hashDatabaseCanBeReindexed(handle); } - boolean isIndexing() { + @Override + public boolean isIndexing() { return indexing; } + + @Override + public void firePropertyChange(String propertyName, Object oldValue, Object newValue){ + this.propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue); + } - private void close() throws TskCoreException { + @Override + public void close() throws TskCoreException { SleuthkitJNI.closeHashDatabase(handle); } @@ -809,23 +1007,21 @@ public class HashDbManager implements PropertyChangeListener { private class HashDbIndexer extends SwingWorker { private ProgressHandle progress = null; - private HashDb hashDb = null; + private HashDatabase hashDb = null; - HashDbIndexer(HashDb hashDb) { + HashDbIndexer(HashDatabase hashDb) { this.hashDb = hashDb; } - ; - @Override protected Object doInBackground() { - hashDb.indexing = true; + hashDb.setIndexing(true); progress = ProgressHandle.createHandle( - NbBundle.getMessage(this.getClass(), "HashDbManager.progress.indexingHashSet", hashDb.hashSetName)); + NbBundle.getMessage(this.getClass(), "HashDbManager.progress.indexingHashSet", hashDb.getHashSetName())); progress.start(); progress.switchToIndeterminate(); try { - SleuthkitJNI.createLookupIndexForHashDatabase(hashDb.handle); + SleuthkitJNI.createLookupIndexForHashDatabase(hashDb.getHandle()); } catch (TskCoreException ex) { Logger.getLogger(HashDb.class.getName()).log(Level.SEVERE, "Error indexing hash database", ex); //NON-NLS JOptionPane.showMessageDialog(null, @@ -840,7 +1036,7 @@ public class HashDbManager implements PropertyChangeListener { @Override protected void done() { - hashDb.indexing = false; + hashDb.setIndexing(false); progress.finish(); // see if we got any errors @@ -857,8 +1053,8 @@ public class HashDbManager implements PropertyChangeListener { } try { - hashDb.propertyChangeSupport.firePropertyChange(HashDb.Event.INDEXING_DONE.toString(), null, hashDb); - hashDb.propertyChangeSupport.firePropertyChange(HashDbManager.SetEvt.DB_INDEXED.toString(), null, hashDb.getHashSetName()); + hashDb.firePropertyChange(HashDb.Event.INDEXING_DONE.toString(), null, hashDb); + hashDb.firePropertyChange(HashDbManager.SetEvt.DB_INDEXED.toString(), null, hashDb.getHashSetName()); } catch (Exception e) { logger.log(Level.SEVERE, "HashDbManager listener threw exception", e); //NON-NLS MessageNotifyUtil.Notify.show( diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java index 8388367130..78f71ed365 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java @@ -60,10 +60,10 @@ public class HashLookupModuleFactory extends IngestModuleFactoryAdapter { @Override public IngestModuleIngestJobSettings getDefaultIngestJobSettings() { // All available hash sets are enabled and always calculate hashes is true by default. - HashDbManager hashDbManager = HashDbManager.getInstance(); - List knownHashSetNames = getHashSetNames(hashDbManager.getKnownFileHashSets()); - List knownBadHashSetNames = getHashSetNames(hashDbManager.getKnownBadFileHashSets()); - return new HashLookupModuleSettings(true, knownHashSetNames, knownBadHashSetNames); + //HashDbManager hashDbManager = HashDbManager.getInstance(); + //List knownHashSetNames = getHashSetNames(hashDbManager.getKnownFileHashSets()); + //List knownBadHashSetNames = getHashSetNames(hashDbManager.getKnownBadFileHashSets()); + return new HashLookupModuleSettings(true); } private List getHashSetNames(List hashDbs) { diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java index e9f7b6cf8f..a51cf1ef48 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java @@ -29,12 +29,19 @@ import org.sleuthkit.autopsy.ingest.IngestModuleIngestJobSettings; final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { private static final long serialVersionUID = 1L; + private boolean shouldCalculateHashes = true; + + // These should no longer be used. They are present only for upgrading to the + // newer format (enabled/disabled status saved in the HashDatabase object) private HashSet namesOfEnabledKnownHashSets; private HashSet namesOfDisabledKnownHashSets; // Added in version 1.1 private HashSet namesOfEnabledKnownBadHashSets; private HashSet namesOfDisabledKnownBadHashSets; // Added in version 1.1 - private boolean shouldCalculateHashes = true; + HashLookupModuleSettings(boolean shouldCalculateHashes){ + this.shouldCalculateHashes = shouldCalculateHashes; + } + /** * Constructs ingest job settings for the hash lookup module. * @@ -44,11 +51,11 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { * @param namesOfEnabledKnownBadHashSets A list of enabled notable hash * sets. */ - HashLookupModuleSettings(boolean shouldCalculateHashes, - List namesOfEnabledKnownHashSets, - List namesOfEnabledKnownBadHashSets) { - this(shouldCalculateHashes, namesOfEnabledKnownHashSets, namesOfEnabledKnownBadHashSets, new ArrayList<>(), new ArrayList<>()); - } + //HashLookupModuleSettings(boolean shouldCalculateHashes, + // List namesOfEnabledKnownHashSets, + // List namesOfEnabledKnownBadHashSets) { + // this(shouldCalculateHashes, namesOfEnabledKnownHashSets, namesOfEnabledKnownBadHashSets, new ArrayList<>(), new ArrayList<>()); + //} /** * Constructs ingest job settings for the hash lookup module. @@ -63,17 +70,17 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { * @param namesOfDisabledKnownBadHashSets A list of disabled notable hash * sets. */ - HashLookupModuleSettings(boolean shouldCalculateHashes, - List namesOfEnabledKnownHashSets, - List namesOfEnabledKnownBadHashSets, - List namesOfDisabledKnownHashSets, - List namesOfDisabledKnownBadHashSets) { - this.shouldCalculateHashes = shouldCalculateHashes; - this.namesOfEnabledKnownHashSets = new HashSet<>(namesOfEnabledKnownHashSets); - this.namesOfEnabledKnownBadHashSets = new HashSet<>(namesOfEnabledKnownBadHashSets); - this.namesOfDisabledKnownHashSets = new HashSet<>(namesOfDisabledKnownHashSets); - this.namesOfDisabledKnownBadHashSets = new HashSet<>(namesOfDisabledKnownBadHashSets); - } + //HashLookupModuleSettings(boolean shouldCalculateHashes, + // List namesOfEnabledKnownHashSets, + // List namesOfEnabledKnownBadHashSets, + // List namesOfDisabledKnownHashSets, + // List namesOfDisabledKnownBadHashSets) { + // this.shouldCalculateHashes = shouldCalculateHashes; + // this.namesOfEnabledKnownHashSets = new HashSet<>(namesOfEnabledKnownHashSets); + // this.namesOfEnabledKnownBadHashSets = new HashSet<>(namesOfEnabledKnownBadHashSets); + // this.namesOfDisabledKnownHashSets = new HashSet<>(namesOfDisabledKnownHashSets); + // this.namesOfDisabledKnownBadHashSets = new HashSet<>(namesOfDisabledKnownBadHashSets); + //} /** * @inheritDoc @@ -103,62 +110,68 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { * * @return True if the hash set is enabled, false otherwise. */ - boolean isHashSetEnabled(String hashSetName) { - this.upgradeFromOlderVersions(); - return !(this.namesOfDisabledKnownHashSets.contains(hashSetName) || this.namesOfDisabledKnownBadHashSets.contains(hashSetName)); - } + //boolean isHashSetEnabled(String hashSetName) { + // this.upgradeFromOlderVersions(); + // return !(this.namesOfDisabledKnownHashSets.contains(hashSetName) || this.namesOfDisabledKnownBadHashSets.contains(hashSetName)); + //} /** * Get the names of all explicitly enabled known files hash sets. * * @return The list of names. */ - List getNamesOfEnabledKnownHashSets() { - this.upgradeFromOlderVersions(); - return new ArrayList<>(this.namesOfEnabledKnownHashSets); - } + //List getNamesOfEnabledKnownHashSets() { + // this.upgradeFromOlderVersions(); + // return new ArrayList<>(this.namesOfEnabledKnownHashSets); + //} /** * Get the names of all explicitly disabled known files hash sets. * * @return The list of names. */ - List getNamesOfDisabledKnownHashSets() { - this.upgradeFromOlderVersions(); - return new ArrayList<>(namesOfDisabledKnownHashSets); - } + //List getNamesOfDisabledKnownHashSets() { + // this.upgradeFromOlderVersions(); + // return new ArrayList<>(namesOfDisabledKnownHashSets); + //} /** * Get the names of all explicitly enabled notable files hash sets. * * @return The list of names. */ - List getNamesOfEnabledKnownBadHashSets() { - this.upgradeFromOlderVersions(); - return new ArrayList<>(this.namesOfEnabledKnownBadHashSets); - } + //List getNamesOfEnabledKnownBadHashSets() { + // this.upgradeFromOlderVersions(); + // return new ArrayList<>(this.namesOfEnabledKnownBadHashSets); + //} /** * Get the names of all explicitly disabled notable files hash sets. * * @return The list of names. */ - List getNamesOfDisabledKnownBadHashSets() { - this.upgradeFromOlderVersions(); - return new ArrayList<>(this.namesOfDisabledKnownBadHashSets); - } + //List getNamesOfDisabledKnownBadHashSets() { + // this.upgradeFromOlderVersions(); + // return new ArrayList<>(this.namesOfDisabledKnownBadHashSets); + //} /** * Initialize fields set to null when an instance of a previous, but still * compatible, version of this class is de-serialized. */ private void upgradeFromOlderVersions() { - if (null == this.namesOfDisabledKnownHashSets) { - this.namesOfDisabledKnownHashSets = new HashSet<>(); - } - if (null == this.namesOfDisabledKnownBadHashSets) { - this.namesOfDisabledKnownBadHashSets = new HashSet<>(); - } + //if (null == this.namesOfDisabledKnownHashSets) { + // this.namesOfDisabledKnownHashSets = new HashSet<>(); + //} + //if (null == this.namesOfDisabledKnownBadHashSets) { + // this.namesOfDisabledKnownBadHashSets = new HashSet<>(); + //} + + // I think I need to see if there's any data in the old lists when they + // get deserialized, and use that to update the HashDatabase objects + // TO DO + System.out.println("upgradeFromOlderVersions"); + } } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java index 2a78b2b5b5..585098a94e 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java @@ -27,13 +27,16 @@ import java.util.Map; import java.util.logging.Level; import javax.swing.JScrollPane; import javax.swing.JTable; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; import javax.swing.table.AbstractTableModel; import javax.swing.table.TableColumn; +import javax.swing.table.TableModel; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.ingest.IngestModuleIngestJobSettings; import org.sleuthkit.autopsy.ingest.IngestModuleIngestJobSettingsPanel; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; import org.sleuthkit.datamodel.TskCoreException; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; /** * Ingest job settings panel for hash lookup file ingest modules. @@ -54,15 +57,15 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe } private void initializeHashSetModels(HashLookupModuleSettings settings) { - initializeHashSetModels(settings, hashDbManager.getKnownFileHashSets(), knownHashSetModels); - initializeHashSetModels(settings, hashDbManager.getKnownBadFileHashSets(), knownBadHashSetModels); + initializeHashSetModels(settings, hashDbManager.getKnownFileHashSetsNew(), knownHashSetModels); + initializeHashSetModels(settings, hashDbManager.getKnownBadFileHashSetsNew(), knownBadHashSetModels); } - private void initializeHashSetModels(HashLookupModuleSettings settings, List hashDbs, List hashSetModels) { + private void initializeHashSetModels(HashLookupModuleSettings settings, List hashDbs, List hashSetModels) { hashSetModels.clear(); - for (HashDb db : hashDbs) { + for (HashDatabase db : hashDbs) { String name = db.getHashSetName(); - hashSetModels.add(new HashSetModel(name, settings.isHashSetEnabled(name), isHashDbIndexed(db))); + hashSetModels.add(new HashSetModel(db)); } } @@ -102,20 +105,12 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe @Override public IngestModuleIngestJobSettings getSettings() { - List enabledKnownHashSetNames = new ArrayList<>(); - List disabledKnownHashSetNames = new ArrayList<>(); - List enabledKnownBadHashSetNames = new ArrayList<>(); - List disabledKnownBadHashSetNames = new ArrayList<>(); - getHashSetNames(knownHashSetModels, enabledKnownHashSetNames, disabledKnownHashSetNames); - getHashSetNames(knownBadHashSetModels, enabledKnownBadHashSetNames, disabledKnownBadHashSetNames); - return new HashLookupModuleSettings(alwaysCalcHashesCheckbox.isSelected(), - enabledKnownHashSetNames, enabledKnownBadHashSetNames, - disabledKnownHashSetNames, disabledKnownBadHashSetNames); + return new HashLookupModuleSettings(alwaysCalcHashesCheckbox.isSelected()); } private void getHashSetNames(List hashSetModels, List enabledHashSetNames, List disabledHashSetNames) { for (HashSetModel model : hashSetModels) { - if (model.isEnabled() && model.isIndexed()) { + if (model.isEnabled() && model.isValid()) { enabledHashSetNames.add(model.getName()); } else { disabledHashSetNames.add(model.getName()); @@ -130,13 +125,13 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe } private void updateHashSetModels() { - updateHashSetModels(hashDbManager.getKnownFileHashSets(), knownHashSetModels); - updateHashSetModels(hashDbManager.getKnownBadFileHashSets(), knownBadHashSetModels); + updateHashSetModels(hashDbManager.getKnownFileHashSetsNew(), knownHashSetModels); + updateHashSetModels(hashDbManager.getKnownBadFileHashSetsNew(), knownBadHashSetModels); } - void updateHashSetModels(List hashDbs, List hashSetModels) { - Map hashSetDbs = new HashMap<>(); - for (HashDb db : hashDbs) { + void updateHashSetModels(List hashDbs, List hashSetModels) { + Map hashSetDbs = new HashMap<>(); + for (HashDatabase db : hashDbs) { hashSetDbs.put(db.getHashSetName(), db); } @@ -145,8 +140,8 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe for (HashSetModel model : hashSetModels) { String hashSetName = model.getName(); if (hashSetDbs.containsKey(hashSetName)) { - HashDb db = hashSetDbs.get(hashSetName); - model.setIndexed(isHashDbIndexed(db)); + HashDatabase db = hashSetDbs.get(hashSetName); + model.setValid(isHashDbValid(db)); hashSetDbs.remove(hashSetName); } else { deletedHashSetModels.add(model); @@ -159,9 +154,9 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe } // Add any new hash sets. All new sets are enabled by default. - for (HashDb db : hashSetDbs.values()) { + for (HashDatabase db : hashSetDbs.values()) { String name = db.getHashSetName(); - hashSetModels.add(new HashSetModel(name, true, isHashDbIndexed(db))); + hashSetModels.add(new HashSetModel(db)); } } @@ -172,46 +167,48 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe knownBadHashSetsTableModel.fireTableDataChanged(); } - private boolean isHashDbIndexed(HashDb hashDb) { - boolean indexed = false; + private boolean isHashDbValid(HashDatabase hashDb) { + boolean isValid = false; try { - indexed = hashDb.hasIndex(); + isValid = hashDb.isValid(); } catch (TskCoreException ex) { - Logger.getLogger(HashLookupModuleSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting indexed status info for hash set (name = " + hashDb.getHashSetName() + ")", ex); //NON-NLS + Logger.getLogger(HashLookupModuleSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting valid status info for hash set (name = " + hashDb.getHashSetName() + ")", ex); //NON-NLS } - return indexed; + return isValid; } private static final class HashSetModel { - private final String name; - private boolean indexed; - private boolean enabled; + private HashDatabase db; - HashSetModel(String name, boolean enabled, boolean indexed) { - this.name = name; - this.enabled = enabled; - this.indexed = indexed; + HashSetModel(HashDatabase db) { + this.db = db; } String getName() { - return name; + return db.getHashSetName(); } void setEnabled(boolean enabled) { - this.enabled = enabled; + db.setSearchDuringIngest(enabled); } boolean isEnabled() { - return enabled; + return db.getSearchDuringIngest(); } - void setIndexed(boolean indexed) { - this.indexed = indexed; + void setValid(boolean valid) { + // I don't think I need this + //this.valid = valid; } - boolean isIndexed() { - return indexed; + boolean isValid() { + try{ + return db.isValid(); + } catch (TskCoreException ex){ + Logger.getLogger(HashLookupModuleSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting valid status info for hash set (name = " + db.getHashSetName() + ")", ex); //NON-NLS + return false; + } } } @@ -245,13 +242,20 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe @Override public boolean isCellEditable(int rowIndex, int columnIndex) { - return (columnIndex == 0 && hashSets.get(rowIndex).isIndexed()); + return (columnIndex == 0 && hashSets.get(rowIndex).isValid()); } @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { + if (columnIndex == 0) { + System.out.println("Setting value of row " + rowIndex + " to " + ((Boolean) aValue)); hashSets.get(rowIndex).setEnabled((Boolean) aValue); + try{ + HashDbManager.getInstance().save(); + } catch (HashDbManager.HashDbManagerException ex){ + Logger.getLogger(HashLookupModuleSettingsPanel.class.getName()).log(Level.SEVERE, "Error saving hash database settings", ex); //NON-NLS + } } } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java index 1adcab7a35..4672f979c0 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java @@ -35,6 +35,7 @@ import org.sleuthkit.autopsy.core.RuntimeProperties; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.PlatformUtil; import org.sleuthkit.autopsy.coreutils.XMLUtil; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase.DatabaseType; import org.sleuthkit.datamodel.TskCoreException; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -69,40 +70,17 @@ final class HashLookupSettings implements Serializable { HashLookupSettings(List hashDbInfoList) { this.hashDbInfoList = hashDbInfoList; } - - /** - * Constructs a settings object to be serialized for hash lookups - * - * @param knownHashSets The list known hash sets for the settings. - * @param knownBadHashSets The list of notable hash sets for the settings. - */ - HashLookupSettings(List knownHashSets, List knownBadHashSets) throws HashLookupSettingsException { - hashDbInfoList = new ArrayList<>(); - this.addHashesToList(knownHashSets); - this.addHashesToList(knownBadHashSets); - } - - /** - * Adds each HashDb to the settings. - * - * @param hashSetList The list of HashDb to add to the settings - * - * @throws * pacannot be obtained - */ - private void addHashesToList(List hashSetList) throws HashLookupSettingsException { - for (HashDbManager.HashDb hashDb : hashSetList) { - try { - String dbPath; - if (hashDb.hasIndexOnly()) { - dbPath = hashDb.getIndexPath(); - } else { - dbPath = hashDb.getDatabasePath(); - } - hashDbInfoList.add(new HashDbInfo(hashDb.getHashSetName(), hashDb.getKnownFilesType(), hashDb.getSearchDuringIngest(), hashDb.getSendIngestMessages(), dbPath)); - } catch (TskCoreException ex) { - throw new HashLookupSettingsException("Couldn't add hash database named: " + hashDb.getHashSetName(), ex); + + static List convertHashSetList(List hashSets) throws HashLookupSettingsException{ + List dbInfoList = new ArrayList<>(); + for(HashDbManager.HashDatabase db:hashSets){ + try{ + dbInfoList.add(new HashDbInfo(db)); + } catch (TskCoreException ex){ + logger.log(Level.SEVERE, "Could not load database settings for {0}", db.getHashSetName()); } } + return dbInfoList; } /** @@ -299,11 +277,21 @@ final class HashLookupSettings implements Serializable { * @return Whether or not the settings were written successfully */ static boolean writeSettings(HashLookupSettings settings) { + + System.out.println("\n#####\nwriteSettings"); + for(HashDbInfo info:settings.hashDbInfoList){ + System.out.println(info.hashSetName); + System.out.println(" DB type: " + info.dbType.toString()); + System.out.println(" Enabled: " + info.searchDuringIngest); + System.out.println(" Type: " + info.knownFilesType.getDisplayName()); + + } + try (NbObjectOutputStream out = new NbObjectOutputStream(new FileOutputStream(SERIALIZATION_FILE_PATH))) { out.writeObject(settings); return true; } catch (Exception ex) { - logger.log(Level.SEVERE, "Could not wtite hash database settings."); + logger.log(Level.SEVERE, "Could not write hash database settings."); return false; } } @@ -314,16 +302,18 @@ final class HashLookupSettings implements Serializable { * hash lookups. */ static final class HashDbInfo implements Serializable { - + private static final long serialVersionUID = 1L; private final String hashSetName; private final HashDbManager.HashDb.KnownFilesType knownFilesType; private final boolean searchDuringIngest; private final boolean sendIngestMessages; private final String path; + private final int centralRepoIndex; + private final DatabaseType dbType; /** - * Constructs a HashDbInfo object + * Constructs a HashDbInfo object for files type * * @param hashSetName The name of the hash set * @param knownFilesType The known files type @@ -338,6 +328,42 @@ final class HashLookupSettings implements Serializable { this.searchDuringIngest = searchDuringIngest; this.sendIngestMessages = sendIngestMessages; this.path = path; + this.centralRepoIndex = -1; + this.dbType = DatabaseType.FILE; + } + + HashDbInfo(String hashSetName, int centralRepoIndex, HashDbManager.HashDb.KnownFilesType knownFilesType, boolean searchDuringIngest, boolean sendIngestMessages){ + this.hashSetName = hashSetName; + this.centralRepoIndex = centralRepoIndex; + this.knownFilesType = knownFilesType; + this.searchDuringIngest = searchDuringIngest; + this.sendIngestMessages = sendIngestMessages; + this.path = ""; + dbType = DatabaseType.CENTRAL_REPOSITORY; + } + + HashDbInfo(HashDbManager.HashDatabase db) throws TskCoreException{ + if(db.getDatabaseType() == DatabaseType.FILE){ + this.hashSetName = db.getHashSetName(); + this.knownFilesType = db.getKnownFilesType(); + this.searchDuringIngest = db.getSearchDuringIngest(); + this.sendIngestMessages = db.getSendIngestMessages(); + this.centralRepoIndex = -1; + this.dbType = DatabaseType.FILE; + if (db.hasIndexOnly()) { + this.path = db.getIndexPath(); + } else { + this.path = db.getDatabasePath(); + } + } else { + this.hashSetName = db.getHashSetName(); + this.knownFilesType = db.getKnownFilesType(); + this.searchDuringIngest = db.getSearchDuringIngest(); + this.sendIngestMessages = db.getSendIngestMessages(); + this.path = ""; + this.centralRepoIndex = -1; + this.dbType = DatabaseType.CENTRAL_REPOSITORY; + } } /** @@ -384,6 +410,22 @@ final class HashLookupSettings implements Serializable { String getPath() { return path; } + + int getCentralRepoIndex(){ + return centralRepoIndex; + } + + /** + * Returns whether the database is a normal file type. + * @return true if database is type FILE + */ + boolean isFileDatabaseType(){ + return dbType == DatabaseType.FILE; + } + + boolean isCentralRepoDatabaseType(){ + return dbType == DatabaseType.CENTRAL_REPOSITORY; + } } /** diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java index 7d2b782ec1..7533aa1797 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java @@ -46,6 +46,7 @@ import org.sleuthkit.autopsy.ingest.IngestModuleGlobalSettingsPanel; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb.KnownFilesType; import org.sleuthkit.datamodel.TskCoreException; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; /** * Instances of this class provide a comprehensive UI for managing the hash sets @@ -103,7 +104,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan } private void updateComponents() { - HashDb db = ((HashSetTable) hashSetTable).getSelection(); + HashDatabase db = ((HashSetTable) hashSetTable).getSelection(); if (db != null) { updateComponentsForSelection(db); } else { @@ -142,7 +143,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan ingestWarningLabel.setVisible(ingestIsRunning); } - private void updateComponentsForSelection(HashDb db) { + private void updateComponentsForSelection(HashDatabase db) { boolean ingestIsRunning = IngestManager.getInstance().isIngestRunning(); // Update descriptive labels. @@ -257,8 +258,8 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan "HashLookupSettingsPanel.saveFail.title=Save Fail"}) public void saveSettings() { //Checking for for any unindexed databases - List unindexed = new ArrayList<>(); - for (HashDb hashSet : hashSetManager.getAllHashSets()) { + List unindexed = new ArrayList<>(); + for (HashDatabase hashSet : hashSetManager.getAllHashSetsNew()) { try { if (!hashSet.hasIndex()) { unindexed.add(hashSet); @@ -306,8 +307,8 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan } @Messages({"# {0} - hash lookup name", "HashLookupSettingsPanel.removeDatabaseFailure.message=Failed to remove hash lookup: {0}"}) - void removeThese(List toRemove) { - for (HashDb hashDb : toRemove) { + void removeThese(List toRemove) { + for (HashDatabase hashDb : toRemove) { try { hashSetManager.removeHashDatabaseNoSave(hashDb); } catch (HashDbManager.HashDbManagerException ex) { @@ -325,10 +326,10 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan * @param plural Whether or not there are multiple unindexed databases * @param unindexed The list of unindexed databases. Can be of size 1. */ - private void showInvalidIndex(boolean plural, List unindexed) { + private void showInvalidIndex(boolean plural, List unindexed) { String total = ""; String message; - for (HashDb hdb : unindexed) { + for (HashDatabase hdb : unindexed) { total += "\n" + hdb.getHashSetName(); } if (plural) { @@ -381,7 +382,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan return cellRenderer; } - public HashDb getSelection() { + public HashDatabase getSelection() { return hashSetTableModel.getHashSetAt(getSelectionModel().getMinSelectionIndex()); } @@ -402,7 +403,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan */ private class HashSetTableModel extends AbstractTableModel { - List hashSets = HashDbManager.getInstance().getAllHashSets(); + List hashSets = HashDbManager.getInstance().getAllHashSetsNew(); @Override public int getColumnCount() { @@ -449,7 +450,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan return getValueAt(0, c).getClass(); } - HashDb getHashSetAt(int index) { + HashDatabase getHashSetAt(int index) { if (!hashSets.isEmpty() && index >= 0 && index < hashSets.size()) { return hashSets.get(index); } else { @@ -467,7 +468,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan } void refreshModel() { - hashSets = HashDbManager.getInstance().getAllHashSets(); + hashSets = HashDbManager.getInstance().getAllHashSetsNew(); refreshDisplay(); } @@ -788,12 +789,12 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan private void addHashesToDatabaseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addHashesToDatabaseButtonActionPerformed - HashDb hashDb = ((HashSetTable) hashSetTable).getSelection(); + HashDatabase hashDb = ((HashSetTable) hashSetTable).getSelection(); AddHashValuesToDatabaseDialog dialog = new AddHashValuesToDatabaseDialog(hashDb); }//GEN-LAST:event_addHashesToDatabaseButtonActionPerformed private void createDatabaseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createDatabaseButtonActionPerformed - HashDb hashDb = new HashDbCreateDatabaseDialog().getHashDatabase(); + HashDatabase hashDb = new HashDbCreateDatabaseDialog().getHashDatabase(); if (null != hashDb) { hashSetTableModel.refreshModel(); ((HashSetTable) hashSetTable).selectRowByName(hashDb.getHashSetName()); @@ -802,7 +803,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan }//GEN-LAST:event_createDatabaseButtonActionPerformed private void sendIngestMessagesCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendIngestMessagesCheckBoxActionPerformed - HashDb hashDb = ((HashSetTable) hashSetTable).getSelection(); + HashDatabase hashDb = ((HashSetTable) hashSetTable).getSelection(); if (hashDb != null) { hashDb.setSendIngestMessages(sendIngestMessagesCheckBox.isSelected()); firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); @@ -810,7 +811,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan }//GEN-LAST:event_sendIngestMessagesCheckBoxActionPerformed private void indexButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_indexButtonActionPerformed - final HashDb hashDb = ((HashSetTable) hashSetTable).getSelection(); + final HashDatabase hashDb = ((HashSetTable) hashSetTable).getSelection(); assert hashDb != null; // Add a listener for the INDEXING_DONE event. This listener will update @@ -819,7 +820,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals(HashDb.Event.INDEXING_DONE.toString())) { - HashDb selectedHashDb = ((HashSetTable) hashSetTable).getSelection(); + HashDatabase selectedHashDb = ((HashSetTable) hashSetTable).getSelection(); if (selectedHashDb != null && hashDb != null && hashDb.equals(selectedHashDb)) { updateComponents(); } @@ -840,7 +841,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan }//GEN-LAST:event_indexButtonActionPerformed private void importDatabaseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importDatabaseButtonActionPerformed - HashDb hashDb = new HashDbImportDatabaseDialog().getHashDatabase(); + HashDatabase hashDb = new HashDbImportDatabaseDialog().getHashDatabase(); if (null != hashDb) { hashSetTableModel.refreshModel(); ((HashSetTable) hashSetTable).selectRowByName(hashDb.getHashSetName()); @@ -856,7 +857,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.deleteDbActionMsg"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) { - HashDb hashDb = ((HashSetTable) hashSetTable).getSelection(); + HashDatabase hashDb = ((HashSetTable) hashSetTable).getSelection(); if (hashDb != null) { try { hashSetManager.removeHashDatabaseNoSave(hashDb); @@ -871,7 +872,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan private void hashSetTableKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_hashSetTableKeyPressed if (evt.getKeyCode() == KeyEvent.VK_DELETE) { - HashDb hashDb = ((HashSetTable) hashSetTable).getSelection(); + HashDatabase hashDb = ((HashSetTable) hashSetTable).getSelection(); if (hashDb != null) { try { hashSetManager.removeHashDatabaseNoSave(hashDb); diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ModalNoButtons.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ModalNoButtons.java index 33f65488d2..735923bae2 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ModalNoButtons.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ModalNoButtons.java @@ -27,6 +27,7 @@ import javax.swing.JOptionPane; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; /** * This class exists as a stop-gap measure to force users to have an indexed @@ -43,8 +44,8 @@ import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; */ class ModalNoButtons extends javax.swing.JDialog implements PropertyChangeListener { - List unindexed; - HashDb toIndex; + List unindexed; + HashDatabase toIndex; HashLookupSettingsPanel hdbmp; int length = 0; int currentcount = 1; @@ -58,7 +59,7 @@ class ModalNoButtons extends javax.swing.JDialog implements PropertyChangeListen * @param parent Swing parent frame. * @param unindexed the list of unindexed databases to index. */ - ModalNoButtons(HashLookupSettingsPanel hdbmp, java.awt.Frame parent, List unindexed) { + ModalNoButtons(HashLookupSettingsPanel hdbmp, java.awt.Frame parent, List unindexed) { super(parent, NbBundle.getMessage(ModalNoButtons.class, "ModalNoButtons.indexingDbsTitle"), true); this.unindexed = unindexed; this.toIndex = null; @@ -75,7 +76,7 @@ class ModalNoButtons extends javax.swing.JDialog implements PropertyChangeListen * @param parent Swing parent frame. * @param unindexed The unindexed database to index. */ - ModalNoButtons(HashLookupSettingsPanel hdbmp, java.awt.Frame parent, HashDb unindexed) { + ModalNoButtons(HashLookupSettingsPanel hdbmp, java.awt.Frame parent, HashDatabase unindexed) { super(parent, NbBundle.getMessage(ModalNoButtons.class, "ModalNoButtons.indexingDbTitle"), true); this.unindexed = null; this.toIndex = unindexed; @@ -183,7 +184,7 @@ class ModalNoButtons extends javax.swing.JDialog implements PropertyChangeListen "ModalNoButtons.dlgTitle.unfinishedIndexing"), JOptionPane.YES_NO_OPTION); if (res == JOptionPane.YES_OPTION) { - List remove = new ArrayList<>(); + List remove = new ArrayList<>(); if (this.toIndex == null) { remove = this.unindexed; } else { @@ -230,7 +231,7 @@ class ModalNoButtons extends javax.swing.JDialog implements PropertyChangeListen private void indexThese() { length = this.unindexed.size(); this.INDEXING_PROGBAR.setIndeterminate(true); - for (HashDb db : this.unindexed) { + for (HashDatabase db : this.unindexed) { currentDb = db.getHashSetName(); this.CURRENTDB_LABEL.setText("(" + currentDb + ")"); this.CURRENTLYON_LABEL.setText( diff --git a/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDb.java b/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDb.java index 1de1db7eaa..233aad0202 100755 --- a/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDb.java +++ b/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDb.java @@ -27,7 +27,6 @@ import javax.swing.JPanel; import org.openide.util.lookup.ServiceProvider; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.services.TagsManager; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; import org.sleuthkit.autopsy.report.GeneralReportModule; import org.sleuthkit.autopsy.report.ReportProgressPanel; import org.sleuthkit.datamodel.AbstractFile; @@ -35,6 +34,7 @@ import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; /** * Instances of this class plug in to the reporting infrastructure to provide a @@ -69,7 +69,7 @@ public class AddTaggedHashesToHashDb implements GeneralReportModule { progressPanel.start(); progressPanel.updateStatusLabel("Adding hashes..."); - HashDb hashSet = configPanel.getSelectedHashDatabase(); + HashDatabase hashSet = configPanel.getSelectedHashDatabase(); if (hashSet != null) { progressPanel.updateStatusLabel("Adding hashes to " + hashSet.getHashSetName() + " hash set..."); diff --git a/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.java b/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.java index 93dad76f89..9721b787b3 100755 --- a/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.java +++ b/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.java @@ -36,11 +36,11 @@ import javax.swing.ListModel; import javax.swing.event.ListDataListener; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager; import org.sleuthkit.autopsy.modules.hashdatabase.HashLookupSettingsPanel; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; /** * Instances of this class are used to configure the report module plug in that @@ -54,8 +54,8 @@ class AddTaggedHashesToHashDbConfigPanel extends javax.swing.JPanel { private final Map tagNameSelections = new LinkedHashMap<>(); private final TagNamesListModel tagsNamesListModel = new TagNamesListModel(); private final TagsNamesListCellRenderer tagsNamesRenderer = new TagsNamesListCellRenderer(); - private final Map hashSets = new HashMap<>(); - private HashDb selectedHashSet = null; + private final Map hashSets = new HashMap<>(); + private HashDatabase selectedHashSet = null; AddTaggedHashesToHashDbConfigPanel() { initComponents(); @@ -109,9 +109,9 @@ class AddTaggedHashesToHashDbConfigPanel extends javax.swing.JPanel { // Get the updateable hash databases and add their hash set names to the // JComboBox component. - List updateableHashSets = HashDbManager.getInstance().getUpdateableHashSets(); + List updateableHashSets = HashDbManager.getInstance().getUpdateableHashSetsNew(); if (!updateableHashSets.isEmpty()) { - for (HashDb hashDb : updateableHashSets) { + for (HashDatabase hashDb : updateableHashSets) { hashSets.put(hashDb.getHashSetName(), hashDb); hashSetsComboBox.addItem(hashDb.getHashSetName()); } @@ -142,7 +142,7 @@ class AddTaggedHashesToHashDbConfigPanel extends javax.swing.JPanel { * * @return A HashDb object representing the database or null. */ - HashDb getSelectedHashDatabase() { + HashDatabase getSelectedHashDatabase() { return selectedHashSet; } From 840f4aaa997a4f61f9ada6882eaea8233bb67b02 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Fri, 6 Oct 2017 16:37:48 -0400 Subject: [PATCH 02/41] Keep separate list in the job settings --- .../hashdatabase/HashLookupModuleFactory.java | 2 +- .../HashLookupModuleSettings.java | 75 ++++++++++++++++--- .../HashLookupModuleSettingsPanel.java | 53 ++++++++----- .../hashdatabase/HashLookupSettings.java | 30 +++++++- 4 files changed, 128 insertions(+), 32 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java index 78f71ed365..61a0cb4e26 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java @@ -63,7 +63,7 @@ public class HashLookupModuleFactory extends IngestModuleFactoryAdapter { //HashDbManager hashDbManager = HashDbManager.getInstance(); //List knownHashSetNames = getHashSetNames(hashDbManager.getKnownFileHashSets()); //List knownBadHashSetNames = getHashSetNames(hashDbManager.getKnownBadFileHashSets()); - return new HashLookupModuleSettings(true); + return new HashLookupModuleSettings(true, HashDbManager.getInstance().getAllHashSetsNew()); } private List getHashSetNames(List hashDbs) { diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java index a51cf1ef48..7960493e77 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java @@ -21,6 +21,10 @@ package org.sleuthkit.autopsy.modules.hashdatabase; import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.io.IOException; +import java.util.logging.Level; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; import org.sleuthkit.autopsy.ingest.IngestModuleIngestJobSettings; /** @@ -33,13 +37,35 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { // These should no longer be used. They are present only for upgrading to the // newer format (enabled/disabled status saved in the HashDatabase object) - private HashSet namesOfEnabledKnownHashSets; - private HashSet namesOfDisabledKnownHashSets; // Added in version 1.1 - private HashSet namesOfEnabledKnownBadHashSets; - private HashSet namesOfDisabledKnownBadHashSets; // Added in version 1.1 + private HashSet namesOfEnabledKnownHashSets = null; + private HashSet namesOfDisabledKnownHashSets = null; // Added in version 1.1 + private HashSet namesOfEnabledKnownBadHashSets = null; + private HashSet namesOfDisabledKnownBadHashSets = null; // Added in version 1.1 + + private List databaseInfoList; - HashLookupModuleSettings(boolean shouldCalculateHashes){ + HashLookupModuleSettings(boolean shouldCalculateHashes, List hashDbList){ this.shouldCalculateHashes = shouldCalculateHashes; + try{ + databaseInfoList = HashLookupSettings.convertHashSetList(hashDbList); + } catch (HashLookupSettings.HashLookupSettingsException ex){ + Logger.getLogger(HashLookupModuleSettings.class.getName()).log(Level.SEVERE, "Error creating hash database settings.", ex); //NON-NLS + databaseInfoList = new ArrayList<>(); + } + } + + /** + * This overrides the default deserialization code so we can + * copy the enabled/disabled status into the DatabaseType objects + * @param stream + * @throws IOException + * @throws ClassNotFoundException + */ + private void readObject(java.io.ObjectInputStream stream) + throws IOException, ClassNotFoundException { + + stream.defaultReadObject(); + upgradeFromOlderVersions(); } /** @@ -87,7 +113,7 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { */ @Override public long getVersionNumber() { - this.upgradeFromOlderVersions(); + //this.upgradeFromOlderVersions(); return HashLookupModuleSettings.serialVersionUID; } @@ -98,7 +124,7 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { * @return True if hashes are to be calculated, false otherwise. */ boolean shouldCalculateHashes() { - this.upgradeFromOlderVersions(); + //this.upgradeFromOlderVersions(); return this.shouldCalculateHashes; } @@ -167,11 +193,40 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { // this.namesOfDisabledKnownBadHashSets = new HashSet<>(); //} - // I think I need to see if there's any data in the old lists when they - // get deserialized, and use that to update the HashDatabase objects - // TO DO System.out.println("upgradeFromOlderVersions"); + + if(databaseInfoList != null){ + System.out.println(" No upgrade needed"); + return; + } + try{ + databaseInfoList = HashLookupSettings.convertHashSetList(HashDbManager.getInstance().getAllHashSetsNew()); + } catch (HashLookupSettings.HashLookupSettingsException ex){ + Logger.getLogger(HashLookupModuleSettings.class.getName()).log(Level.SEVERE, "Error updating hash database settings.", ex); //NON-NLS + return; + } + + List disabledHashSetNames = new ArrayList<>(); + if(namesOfDisabledKnownHashSets != null){ + disabledHashSetNames.addAll(namesOfDisabledKnownHashSets); + } + if(namesOfDisabledKnownBadHashSets != null){ + disabledHashSetNames.addAll(namesOfDisabledKnownBadHashSets); + } + + for(HashLookupSettings.HashDbInfo db:databaseInfoList){ + if(disabledHashSetNames.contains(db.getHashSetName())){ + db.setSearchDuringIngest(false); + } else { + db.setSearchDuringIngest(true); + } + } + + namesOfDisabledKnownHashSets = null; + namesOfDisabledKnownBadHashSets = null; + namesOfEnabledKnownHashSets = null; + namesOfEnabledKnownBadHashSets = null; } } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java index 585098a94e..1947be9894 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java @@ -105,17 +105,26 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe @Override public IngestModuleIngestJobSettings getSettings() { - return new HashLookupModuleSettings(alwaysCalcHashesCheckbox.isSelected()); + return new HashLookupModuleSettings(alwaysCalcHashesCheckbox.isSelected(), getHashSetList()); } - private void getHashSetNames(List hashSetModels, List enabledHashSetNames, List disabledHashSetNames) { - for (HashSetModel model : hashSetModels) { - if (model.isEnabled() && model.isValid()) { - enabledHashSetNames.add(model.getName()); - } else { - disabledHashSetNames.add(model.getName()); + private List getHashSetList() { + List hashDatabases = new ArrayList<>(); + for (HashSetModel model : this.knownBadHashSetModels) { + if (! model.isValid()) { + model.setEnabled(false); } + hashDatabases.add(model.getDatabase()); + } + for (HashSetModel model : this.knownHashSetModels) { + if (! model.isValid()) { + model.setEnabled(false); + } + hashDatabases.add(model.getDatabase()); + + } + return hashDatabases; } void update() { @@ -135,6 +144,7 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe hashSetDbs.put(db.getHashSetName(), db); } + // TODO compare based on more than name // Update the hash sets and detect deletions. List deletedHashSetModels = new ArrayList<>(); for (HashSetModel model : hashSetModels) { @@ -179,10 +189,23 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe private static final class HashSetModel { - private HashDatabase db; + private final HashDatabase db; + private boolean valid; + private boolean enabled; HashSetModel(HashDatabase db) { this.db = db; + try{ + this.valid = db.isValid(); + } catch (TskCoreException ex){ + Logger.getLogger(HashLookupModuleSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting valid status info for hash set (name = " + db.getHashSetName() + ")", ex); //NON-NLS + this.valid = false; + } + this.enabled = db.getSearchDuringIngest(); + } + + HashDatabase getDatabase(){ + return db; } String getName() { @@ -190,25 +213,19 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe } void setEnabled(boolean enabled) { - db.setSearchDuringIngest(enabled); + this.enabled = enabled; } boolean isEnabled() { - return db.getSearchDuringIngest(); + return enabled; } void setValid(boolean valid) { - // I don't think I need this - //this.valid = valid; + this.valid = valid; } boolean isValid() { - try{ - return db.isValid(); - } catch (TskCoreException ex){ - Logger.getLogger(HashLookupModuleSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting valid status info for hash set (name = " + db.getHashSetName() + ")", ex); //NON-NLS - return false; - } + return valid; } } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java index 4672f979c0..d8d6bb325f 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java @@ -284,7 +284,6 @@ final class HashLookupSettings implements Serializable { System.out.println(" DB type: " + info.dbType.toString()); System.out.println(" Enabled: " + info.searchDuringIngest); System.out.println(" Type: " + info.knownFilesType.getDisplayName()); - } try (NbObjectOutputStream out = new NbObjectOutputStream(new FileOutputStream(SERIALIZATION_FILE_PATH))) { @@ -306,11 +305,11 @@ final class HashLookupSettings implements Serializable { private static final long serialVersionUID = 1L; private final String hashSetName; private final HashDbManager.HashDb.KnownFilesType knownFilesType; - private final boolean searchDuringIngest; + private boolean searchDuringIngest; private final boolean sendIngestMessages; private final String path; private final int centralRepoIndex; - private final DatabaseType dbType; + private DatabaseType dbType; /** * Constructs a HashDbInfo object for files type @@ -392,6 +391,14 @@ final class HashLookupSettings implements Serializable { boolean getSearchDuringIngest() { return searchDuringIngest; } + + /** + * Sets the search during ingest setting. + * + */ + void setSearchDuringIngest(boolean searchDuringIngest) { + this.searchDuringIngest = searchDuringIngest; + } /** * Gets the send ingest messages setting. @@ -426,6 +433,23 @@ final class HashLookupSettings implements Serializable { boolean isCentralRepoDatabaseType(){ return dbType == DatabaseType.CENTRAL_REPOSITORY; } + + /** + * This overrides the default deserialization code so we can + * properly set the dbType enum and other new fields + * given an old settings file. + * @param stream + * @throws IOException + * @throws ClassNotFoundException + */ + private void readObject(java.io.ObjectInputStream stream) + throws IOException, ClassNotFoundException { + stream.defaultReadObject(); + + if(dbType == null){ + dbType = DatabaseType.FILE; + } + } } /** From 82cb5fa8e30602d2701c32687376a4e44b6cc98e Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Tue, 10 Oct 2017 11:12:20 -0400 Subject: [PATCH 03/41] Reverting some per-job settings code --- .../hashdatabase/HashDbIngestModule.java | 2 +- .../HashLookupModuleSettings.java | 110 +++++++----------- .../HashLookupModuleSettingsPanel.java | 83 +++++-------- 3 files changed, 76 insertions(+), 119 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java index f87aa47d52..6aa9729b07 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java @@ -129,7 +129,7 @@ public class HashDbIngestModule implements FileIngestModule { private void updateEnabledHashSets(List allHashSets, List enabledHashSets) { enabledHashSets.clear(); for (HashDatabase db : allHashSets) { - if (db.getSearchDuringIngest()) { + if (settings.isHashSetEnabled(db)) { try { if (db.isValid()) { enabledHashSets.add(db); diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java index 7960493e77..95272206ae 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java @@ -21,11 +21,11 @@ package org.sleuthkit.autopsy.modules.hashdatabase; import java.util.ArrayList; import java.util.HashSet; import java.util.List; -import java.io.IOException; import java.util.logging.Level; +import java.io.IOException; +import org.sleuthkit.autopsy.ingest.IngestModuleIngestJobSettings; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; -import org.sleuthkit.autopsy.ingest.IngestModuleIngestJobSettings; /** * Ingest job settings for the hash lookup module. @@ -33,15 +33,11 @@ import org.sleuthkit.autopsy.ingest.IngestModuleIngestJobSettings; final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { private static final long serialVersionUID = 1L; + private HashSet namesOfEnabledKnownHashSets; + private HashSet namesOfDisabledKnownHashSets; // Added in version 1.1 + private HashSet namesOfEnabledKnownBadHashSets; + private HashSet namesOfDisabledKnownBadHashSets; // Added in version 1.1 private boolean shouldCalculateHashes = true; - - // These should no longer be used. They are present only for upgrading to the - // newer format (enabled/disabled status saved in the HashDatabase object) - private HashSet namesOfEnabledKnownHashSets = null; - private HashSet namesOfDisabledKnownHashSets = null; // Added in version 1.1 - private HashSet namesOfEnabledKnownBadHashSets = null; - private HashSet namesOfDisabledKnownBadHashSets = null; // Added in version 1.1 - private List databaseInfoList; HashLookupModuleSettings(boolean shouldCalculateHashes, List hashDbList){ @@ -67,21 +63,6 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { stream.defaultReadObject(); upgradeFromOlderVersions(); } - - /** - * Constructs ingest job settings for the hash lookup module. - * - * @param shouldCalculateHashes Whether or not hashes should be - * calculated. - * @param namesOfEnabledKnownHashSets A list of enabled known hash sets. - * @param namesOfEnabledKnownBadHashSets A list of enabled notable hash - * sets. - */ - //HashLookupModuleSettings(boolean shouldCalculateHashes, - // List namesOfEnabledKnownHashSets, - // List namesOfEnabledKnownBadHashSets) { - // this(shouldCalculateHashes, namesOfEnabledKnownHashSets, namesOfEnabledKnownBadHashSets, new ArrayList<>(), new ArrayList<>()); - //} /** * Constructs ingest job settings for the hash lookup module. @@ -96,24 +77,24 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { * @param namesOfDisabledKnownBadHashSets A list of disabled notable hash * sets. */ - //HashLookupModuleSettings(boolean shouldCalculateHashes, - // List namesOfEnabledKnownHashSets, - // List namesOfEnabledKnownBadHashSets, - // List namesOfDisabledKnownHashSets, - // List namesOfDisabledKnownBadHashSets) { - // this.shouldCalculateHashes = shouldCalculateHashes; - // this.namesOfEnabledKnownHashSets = new HashSet<>(namesOfEnabledKnownHashSets); - // this.namesOfEnabledKnownBadHashSets = new HashSet<>(namesOfEnabledKnownBadHashSets); - // this.namesOfDisabledKnownHashSets = new HashSet<>(namesOfDisabledKnownHashSets); - // this.namesOfDisabledKnownBadHashSets = new HashSet<>(namesOfDisabledKnownBadHashSets); - //} + HashLookupModuleSettings(boolean shouldCalculateHashes, + List namesOfEnabledKnownHashSets, + List namesOfEnabledKnownBadHashSets, + List namesOfDisabledKnownHashSets, + List namesOfDisabledKnownBadHashSets) { + this.shouldCalculateHashes = shouldCalculateHashes; + this.namesOfEnabledKnownHashSets = new HashSet<>(namesOfEnabledKnownHashSets); + this.namesOfEnabledKnownBadHashSets = new HashSet<>(namesOfEnabledKnownBadHashSets); + this.namesOfDisabledKnownHashSets = new HashSet<>(namesOfDisabledKnownHashSets); + this.namesOfDisabledKnownBadHashSets = new HashSet<>(namesOfDisabledKnownBadHashSets); + } /** * @inheritDoc */ @Override public long getVersionNumber() { - //this.upgradeFromOlderVersions(); + this.upgradeFromOlderVersions(); return HashLookupModuleSettings.serialVersionUID; } @@ -124,7 +105,7 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { * @return True if hashes are to be calculated, false otherwise. */ boolean shouldCalculateHashes() { - //this.upgradeFromOlderVersions(); + this.upgradeFromOlderVersions(); return this.shouldCalculateHashes; } @@ -132,67 +113,62 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { * Checks whether or not a hash set is enabled. If there is no setting for * the requested hash set, it is deemed to be enabled. * - * @param hashSetName The name of the hash set to check. + * @param db The hash set to check. * * @return True if the hash set is enabled, false otherwise. */ - //boolean isHashSetEnabled(String hashSetName) { - // this.upgradeFromOlderVersions(); - // return !(this.namesOfDisabledKnownHashSets.contains(hashSetName) || this.namesOfDisabledKnownBadHashSets.contains(hashSetName)); - //} + boolean isHashSetEnabled(HashDatabase db) { + //this.upgradeFromOlderVersions(); + // TEMP TEMP TEMP TEMP + return db.getSearchDuringIngest(); + //return !(this.namesOfDisabledKnownHashSets.contains(hashSetName) || this.namesOfDisabledKnownBadHashSets.contains(hashSetName)); + } /** * Get the names of all explicitly enabled known files hash sets. * * @return The list of names. */ - //List getNamesOfEnabledKnownHashSets() { - // this.upgradeFromOlderVersions(); - // return new ArrayList<>(this.namesOfEnabledKnownHashSets); - //} + List getNamesOfEnabledKnownHashSets() { + this.upgradeFromOlderVersions(); + return new ArrayList<>(this.namesOfEnabledKnownHashSets); + } /** * Get the names of all explicitly disabled known files hash sets. * * @return The list of names. */ - //List getNamesOfDisabledKnownHashSets() { - // this.upgradeFromOlderVersions(); - // return new ArrayList<>(namesOfDisabledKnownHashSets); - //} + List getNamesOfDisabledKnownHashSets() { + this.upgradeFromOlderVersions(); + return new ArrayList<>(namesOfDisabledKnownHashSets); + } /** * Get the names of all explicitly enabled notable files hash sets. * * @return The list of names. */ - //List getNamesOfEnabledKnownBadHashSets() { - // this.upgradeFromOlderVersions(); - // return new ArrayList<>(this.namesOfEnabledKnownBadHashSets); - //} + List getNamesOfEnabledKnownBadHashSets() { + this.upgradeFromOlderVersions(); + return new ArrayList<>(this.namesOfEnabledKnownBadHashSets); + } /** * Get the names of all explicitly disabled notable files hash sets. * * @return The list of names. */ - //List getNamesOfDisabledKnownBadHashSets() { - // this.upgradeFromOlderVersions(); - // return new ArrayList<>(this.namesOfDisabledKnownBadHashSets); - //} + List getNamesOfDisabledKnownBadHashSets() { + this.upgradeFromOlderVersions(); + return new ArrayList<>(this.namesOfDisabledKnownBadHashSets); + } /** * Initialize fields set to null when an instance of a previous, but still * compatible, version of this class is de-serialized. */ private void upgradeFromOlderVersions() { - //if (null == this.namesOfDisabledKnownHashSets) { - // this.namesOfDisabledKnownHashSets = new HashSet<>(); - //} - //if (null == this.namesOfDisabledKnownBadHashSets) { - // this.namesOfDisabledKnownBadHashSets = new HashSet<>(); - //} - System.out.println("upgradeFromOlderVersions"); if(databaseInfoList != null){ @@ -226,7 +202,7 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { namesOfDisabledKnownHashSets = null; namesOfDisabledKnownBadHashSets = null; namesOfEnabledKnownHashSets = null; - namesOfEnabledKnownBadHashSets = null; + namesOfEnabledKnownBadHashSets = null; } } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java index 1947be9894..d51834dea8 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java @@ -27,16 +27,14 @@ import java.util.Map; import java.util.logging.Level; import javax.swing.JScrollPane; import javax.swing.JTable; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; import javax.swing.table.AbstractTableModel; import javax.swing.table.TableColumn; -import javax.swing.table.TableModel; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.ingest.IngestModuleIngestJobSettings; import org.sleuthkit.autopsy.ingest.IngestModuleIngestJobSettingsPanel; -import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; +import org.sleuthkit.datamodel.TskCoreException; + /** * Ingest job settings panel for hash lookup file ingest modules. @@ -64,8 +62,7 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe private void initializeHashSetModels(HashLookupModuleSettings settings, List hashDbs, List hashSetModels) { hashSetModels.clear(); for (HashDatabase db : hashDbs) { - String name = db.getHashSetName(); - hashSetModels.add(new HashSetModel(db)); + hashSetModels.add(new HashSetModel(db, settings.isHashSetEnabled(db), isHashDbValid(db))); } } @@ -105,26 +102,25 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe @Override public IngestModuleIngestJobSettings getSettings() { - return new HashLookupModuleSettings(alwaysCalcHashesCheckbox.isSelected(), getHashSetList()); + List enabledKnownHashSetNames = new ArrayList<>(); + List disabledKnownHashSetNames = new ArrayList<>(); + List enabledKnownBadHashSetNames = new ArrayList<>(); + List disabledKnownBadHashSetNames = new ArrayList<>(); + getHashSetNames(knownHashSetModels, enabledKnownHashSetNames, disabledKnownHashSetNames); + getHashSetNames(knownBadHashSetModels, enabledKnownBadHashSetNames, disabledKnownBadHashSetNames); + return new HashLookupModuleSettings(alwaysCalcHashesCheckbox.isSelected(), + enabledKnownHashSetNames, enabledKnownBadHashSetNames, + disabledKnownHashSetNames, disabledKnownBadHashSetNames); } - private List getHashSetList() { - List hashDatabases = new ArrayList<>(); - for (HashSetModel model : this.knownBadHashSetModels) { - if (! model.isValid()) { - model.setEnabled(false); + private void getHashSetNames(List hashSetModels, List enabledHashSetNames, List disabledHashSetNames) { + for (HashSetModel model : hashSetModels) { + if (model.isEnabled() && model.isValid()) { + enabledHashSetNames.add(model.getName()); + } else { + disabledHashSetNames.add(model.getName()); } - hashDatabases.add(model.getDatabase()); - } - for (HashSetModel model : this.knownHashSetModels) { - if (! model.isValid()) { - model.setEnabled(false); - } - hashDatabases.add(model.getDatabase()); - - } - return hashDatabases; } void update() { @@ -139,19 +135,16 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe } void updateHashSetModels(List hashDbs, List hashSetModels) { - Map hashSetDbs = new HashMap<>(); - for (HashDatabase db : hashDbs) { - hashSetDbs.put(db.getHashSetName(), db); - } - // TODO compare based on more than name + // TEMP TEMP SKIP TEMP + /* // Update the hash sets and detect deletions. List deletedHashSetModels = new ArrayList<>(); for (HashSetModel model : hashSetModels) { String hashSetName = model.getName(); if (hashSetDbs.containsKey(hashSetName)) { - HashDatabase db = hashSetDbs.get(hashSetName); - model.setValid(isHashDbValid(db)); + HashDb db = hashSetDbs.get(hashSetName); + model.setIndexed(isHashDbValid(db)); hashSetDbs.remove(hashSetName); } else { deletedHashSetModels.add(model); @@ -164,10 +157,10 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe } // Add any new hash sets. All new sets are enabled by default. - for (HashDatabase db : hashSetDbs.values()) { + for (HashDb db : hashSetDbs.values()) { String name = db.getHashSetName(); - hashSetModels.add(new HashSetModel(db)); - } + hashSetModels.add(new HashSetModel(name, true, isHashDbValid(db))); + }*/ } void reset(HashLookupModuleSettings newSettings) { @@ -178,13 +171,13 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe } private boolean isHashDbValid(HashDatabase hashDb) { - boolean isValid = false; + boolean indexed = false; try { - isValid = hashDb.isValid(); + indexed = hashDb.isValid(); } catch (TskCoreException ex) { - Logger.getLogger(HashLookupModuleSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting valid status info for hash set (name = " + hashDb.getHashSetName() + ")", ex); //NON-NLS + Logger.getLogger(HashLookupModuleSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting indexed status info for hash set (name = " + hashDb.getHashSetName() + ")", ex); //NON-NLS } - return isValid; + return indexed; } private static final class HashSetModel { @@ -193,15 +186,10 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe private boolean valid; private boolean enabled; - HashSetModel(HashDatabase db) { + HashSetModel(HashDatabase db, boolean enabled, boolean valid) { this.db = db; - try{ - this.valid = db.isValid(); - } catch (TskCoreException ex){ - Logger.getLogger(HashLookupModuleSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting valid status info for hash set (name = " + db.getHashSetName() + ")", ex); //NON-NLS - this.valid = false; - } - this.enabled = db.getSearchDuringIngest(); + this.enabled = enabled; + this.valid = valid; } HashDatabase getDatabase(){ @@ -264,15 +252,8 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { - if (columnIndex == 0) { - System.out.println("Setting value of row " + rowIndex + " to " + ((Boolean) aValue)); hashSets.get(rowIndex).setEnabled((Boolean) aValue); - try{ - HashDbManager.getInstance().save(); - } catch (HashDbManager.HashDbManagerException ex){ - Logger.getLogger(HashLookupModuleSettingsPanel.class.getName()).log(Level.SEVERE, "Error saving hash database settings", ex); //NON-NLS - } } } From 2305664e114ce63bc0cd779cde419a558863325c Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Wed, 11 Oct 2017 11:22:46 -0400 Subject: [PATCH 04/41] Finished updating settings code --- .../modules/hashdatabase/HashDbManager.java | 18 +-- .../hashdatabase/HashLookupModuleFactory.java | 11 -- .../HashLookupModuleSettings.java | 112 +++++++----------- .../HashLookupModuleSettingsPanel.java | 50 ++++---- .../hashdatabase/HashLookupSettings.java | 70 +++++++++++ .../hashdatabase/HashLookupSettingsPanel.java | 19 ++- 6 files changed, 155 insertions(+), 125 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index 6864cf9c58..26796e10a8 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -237,7 +237,7 @@ public class HashDbManager implements PropertyChangeListener { return new HashDb(handle, info.getHashSetName(), info.getSearchDuringIngest(), info.getSendIngestMessages(), info.getKnownFilesType()); } else if(info.isCentralRepoDatabaseType()){ - throw new TskCoreException("Not done"); + throw new TskCoreException("Not implemented yet"); } throw new TskCoreException("Invalid database type in HashDbInfo"); } @@ -780,15 +780,7 @@ public class HashDbManager implements PropertyChangeListener { @Override public DatabaseType getDatabaseType(){ - if(this instanceof HashDb){ - return DatabaseType.FILE; - } else { - return DatabaseType.CENTRAL_REPOSITORY; - } - } - - public boolean hasIndexFile() { - return true; + return DatabaseType.FILE; } @Override @@ -988,12 +980,6 @@ public class HashDbManager implements PropertyChangeListener { if (!Objects.equals(this.hashSetName, other.hashSetName)) { return false; } - if (this.searchDuringIngest != other.searchDuringIngest) { - return false; - } - if (this.sendIngestMessages != other.sendIngestMessages) { - return false; - } if (this.knownFilesType != other.knownFilesType) { return false; } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java index 61a0cb4e26..4e06f2805b 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java @@ -60,20 +60,9 @@ public class HashLookupModuleFactory extends IngestModuleFactoryAdapter { @Override public IngestModuleIngestJobSettings getDefaultIngestJobSettings() { // All available hash sets are enabled and always calculate hashes is true by default. - //HashDbManager hashDbManager = HashDbManager.getInstance(); - //List knownHashSetNames = getHashSetNames(hashDbManager.getKnownFileHashSets()); - //List knownBadHashSetNames = getHashSetNames(hashDbManager.getKnownBadFileHashSets()); return new HashLookupModuleSettings(true, HashDbManager.getInstance().getAllHashSetsNew()); } - private List getHashSetNames(List hashDbs) { - List hashSetNames = new ArrayList<>(); - for (HashDbManager.HashDb db : hashDbs) { - hashSetNames.add(db.getHashSetName()); - } - return hashSetNames; - } - @Override public boolean hasIngestJobSettingsPanel() { return true; diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java index 95272206ae..3b2de9ed7b 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java @@ -24,8 +24,10 @@ import java.util.List; import java.util.logging.Level; import java.io.IOException; import org.sleuthkit.autopsy.ingest.IngestModuleIngestJobSettings; +import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; +import org.sleuthkit.autopsy.modules.hashdatabase.HashLookupSettings.HashDbInfo; /** * Ingest job settings for the hash lookup module. @@ -33,12 +35,12 @@ import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { private static final long serialVersionUID = 1L; - private HashSet namesOfEnabledKnownHashSets; - private HashSet namesOfDisabledKnownHashSets; // Added in version 1.1 - private HashSet namesOfEnabledKnownBadHashSets; - private HashSet namesOfDisabledKnownBadHashSets; // Added in version 1.1 + private HashSet namesOfEnabledKnownHashSets; // The four lists of hash set names are only used for upgrading + private HashSet namesOfDisabledKnownHashSets; // from older settings files. All data should be stored in + private HashSet namesOfEnabledKnownBadHashSets; // the databaseInfoList list. + private HashSet namesOfDisabledKnownBadHashSets; private boolean shouldCalculateHashes = true; - private List databaseInfoList; + private List databaseInfoList; HashLookupModuleSettings(boolean shouldCalculateHashes, List hashDbList){ this.shouldCalculateHashes = shouldCalculateHashes; @@ -52,7 +54,7 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { /** * This overrides the default deserialization code so we can - * copy the enabled/disabled status into the DatabaseType objects + * copy the enabled/disabled status into the DatabaseType objects. * @param stream * @throws IOException * @throws ClassNotFoundException @@ -69,24 +71,34 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { * * @param shouldCalculateHashes Whether or not hashes should be * calculated. - * @param namesOfEnabledKnownHashSets A list of enabled known hash sets. - * @param namesOfEnabledKnownBadHashSets A list of enabled notable hash - * sets. - * @param namesOfDisabledKnownHashSets A list of disabled known hash - * sets. - * @param namesOfDisabledKnownBadHashSets A list of disabled notable hash - * sets. + * @param enabledHashSets A list of enabled hash sets. + * @param disabledHashSets A list of disabled hash sets. */ HashLookupModuleSettings(boolean shouldCalculateHashes, - List namesOfEnabledKnownHashSets, - List namesOfEnabledKnownBadHashSets, - List namesOfDisabledKnownHashSets, - List namesOfDisabledKnownBadHashSets) { + List enabledHashSets, + List disabledHashSets) { this.shouldCalculateHashes = shouldCalculateHashes; - this.namesOfEnabledKnownHashSets = new HashSet<>(namesOfEnabledKnownHashSets); - this.namesOfEnabledKnownBadHashSets = new HashSet<>(namesOfEnabledKnownBadHashSets); - this.namesOfDisabledKnownHashSets = new HashSet<>(namesOfDisabledKnownHashSets); - this.namesOfDisabledKnownBadHashSets = new HashSet<>(namesOfDisabledKnownBadHashSets); + + databaseInfoList = new ArrayList<>(); + for(HashDatabase db:enabledHashSets){ + try{ + HashDbInfo dbInfo = new HashDbInfo(db); + dbInfo.setSearchDuringIngest(true); + databaseInfoList.add(dbInfo); + } catch (TskCoreException ex){ + Logger.getLogger(HashLookupModuleSettings.class.getName()).log(Level.SEVERE, "Error creating hash database settings for " + db.getHashSetName(), ex); //NON-NLS + } + } + for(HashDatabase db:disabledHashSets){ + try{ + HashDbInfo dbInfo = new HashDbInfo(db); + dbInfo.setSearchDuringIngest(false); + databaseInfoList.add(dbInfo); + } catch (TskCoreException ex){ + Logger.getLogger(HashLookupModuleSettings.class.getName()).log(Level.SEVERE, "Error creating hash database settings for " + db.getHashSetName(), ex); //NON-NLS + } + } + } /** @@ -94,7 +106,6 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { */ @Override public long getVersionNumber() { - this.upgradeFromOlderVersions(); return HashLookupModuleSettings.serialVersionUID; } @@ -105,7 +116,6 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { * @return True if hashes are to be calculated, false otherwise. */ boolean shouldCalculateHashes() { - this.upgradeFromOlderVersions(); return this.shouldCalculateHashes; } @@ -118,50 +128,14 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { * @return True if the hash set is enabled, false otherwise. */ boolean isHashSetEnabled(HashDatabase db) { - //this.upgradeFromOlderVersions(); - // TEMP TEMP TEMP TEMP - return db.getSearchDuringIngest(); - //return !(this.namesOfDisabledKnownHashSets.contains(hashSetName) || this.namesOfDisabledKnownBadHashSets.contains(hashSetName)); - } - - /** - * Get the names of all explicitly enabled known files hash sets. - * - * @return The list of names. - */ - List getNamesOfEnabledKnownHashSets() { - this.upgradeFromOlderVersions(); - return new ArrayList<>(this.namesOfEnabledKnownHashSets); - } - - /** - * Get the names of all explicitly disabled known files hash sets. - * - * @return The list of names. - */ - List getNamesOfDisabledKnownHashSets() { - this.upgradeFromOlderVersions(); - return new ArrayList<>(namesOfDisabledKnownHashSets); - } - - /** - * Get the names of all explicitly enabled notable files hash sets. - * - * @return The list of names. - */ - List getNamesOfEnabledKnownBadHashSets() { - this.upgradeFromOlderVersions(); - return new ArrayList<>(this.namesOfEnabledKnownBadHashSets); - } - - /** - * Get the names of all explicitly disabled notable files hash sets. - * - * @return The list of names. - */ - List getNamesOfDisabledKnownBadHashSets() { - this.upgradeFromOlderVersions(); - return new ArrayList<>(this.namesOfDisabledKnownBadHashSets); + for(HashDbInfo dbInfo:databaseInfoList){ + if(dbInfo.matches(db)){ + return dbInfo.getSearchDuringIngest(); + } + } + + // We didn't find it, so return true + return true; } /** @@ -169,10 +143,8 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { * compatible, version of this class is de-serialized. */ private void upgradeFromOlderVersions() { - System.out.println("upgradeFromOlderVersions"); if(databaseInfoList != null){ - System.out.println(" No upgrade needed"); return; } @@ -192,7 +164,7 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { } for(HashLookupSettings.HashDbInfo db:databaseInfoList){ - if(disabledHashSetNames.contains(db.getHashSetName())){ + if(db.isFileDatabaseType() && disabledHashSetNames.contains(db.getHashSetName())){ db.setSearchDuringIngest(false); } else { db.setSearchDuringIngest(true); diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java index d51834dea8..279a9796a1 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java @@ -21,9 +21,7 @@ package org.sleuthkit.autopsy.modules.hashdatabase; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.logging.Level; import javax.swing.JScrollPane; import javax.swing.JTable; @@ -102,23 +100,20 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe @Override public IngestModuleIngestJobSettings getSettings() { - List enabledKnownHashSetNames = new ArrayList<>(); - List disabledKnownHashSetNames = new ArrayList<>(); - List enabledKnownBadHashSetNames = new ArrayList<>(); - List disabledKnownBadHashSetNames = new ArrayList<>(); - getHashSetNames(knownHashSetModels, enabledKnownHashSetNames, disabledKnownHashSetNames); - getHashSetNames(knownBadHashSetModels, enabledKnownBadHashSetNames, disabledKnownBadHashSetNames); + List enabledHashSets = new ArrayList<>(); + List disabledHashSets = new ArrayList<>(); + addHashSets(knownHashSetModels, enabledHashSets, disabledHashSets); + addHashSets(knownBadHashSetModels, enabledHashSets, disabledHashSets); return new HashLookupModuleSettings(alwaysCalcHashesCheckbox.isSelected(), - enabledKnownHashSetNames, enabledKnownBadHashSetNames, - disabledKnownHashSetNames, disabledKnownBadHashSetNames); + enabledHashSets, disabledHashSets); } - private void getHashSetNames(List hashSetModels, List enabledHashSetNames, List disabledHashSetNames) { + private void addHashSets(List hashSetModels, List enabledHashSets, List disabledHashSets) { for (HashSetModel model : hashSetModels) { if (model.isEnabled() && model.isValid()) { - enabledHashSetNames.add(model.getName()); + enabledHashSets.add(model.getDatabase()); } else { - disabledHashSetNames.add(model.getName()); + disabledHashSets.add(model.getDatabase()); } } } @@ -135,18 +130,22 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe } void updateHashSetModels(List hashDbs, List hashSetModels) { - - // TEMP TEMP SKIP TEMP - /* + + List hashDatabases = new ArrayList<>(hashDbs); + // Update the hash sets and detect deletions. List deletedHashSetModels = new ArrayList<>(); for (HashSetModel model : hashSetModels) { - String hashSetName = model.getName(); - if (hashSetDbs.containsKey(hashSetName)) { - HashDb db = hashSetDbs.get(hashSetName); - model.setIndexed(isHashDbValid(db)); - hashSetDbs.remove(hashSetName); - } else { + boolean foundDatabase = false; + for(HashDatabase db : hashDatabases){ + if(model.getDatabase().equals(db)){ + model.setValid(isHashDbValid(db)); + hashDatabases.remove(db); + foundDatabase = true; + break; + } + } + if(! foundDatabase){ deletedHashSetModels.add(model); } } @@ -157,10 +156,9 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe } // Add any new hash sets. All new sets are enabled by default. - for (HashDb db : hashSetDbs.values()) { - String name = db.getHashSetName(); - hashSetModels.add(new HashSetModel(name, true, isHashDbValid(db))); - }*/ + for (HashDatabase db : hashDatabases) { + hashSetModels.add(new HashSetModel(db, true, isHashDbValid(db))); + } } void reset(HashLookupModuleSettings newSettings) { diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java index d8d6bb325f..2efba5eee1 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java @@ -25,6 +25,7 @@ import java.io.IOException; import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.logging.Level; import javax.swing.JOptionPane; import org.apache.commons.io.FileUtils; @@ -35,6 +36,7 @@ import org.sleuthkit.autopsy.core.RuntimeProperties; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.PlatformUtil; import org.sleuthkit.autopsy.coreutils.XMLUtil; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase.DatabaseType; import org.sleuthkit.datamodel.TskCoreException; import org.w3c.dom.Document; @@ -434,6 +436,74 @@ final class HashLookupSettings implements Serializable { return dbType == DatabaseType.CENTRAL_REPOSITORY; } + boolean matches(HashDatabase hashDb){ + if(hashDb == null){ + return false; + } + + if( ! this.knownFilesType.equals(hashDb.getKnownFilesType())){ + return false; + } + + if( ! this.dbType.equals(hashDb.getDatabaseType())){ + return false; + } + + if( ! this.hashSetName.equals(hashDb.getHashSetName())){ + return false; + } + + if(this.dbType.equals(DatabaseType.FILE)){ + // FILE types will always have unique names, so no more testing required + return true; + } + + // TODO TODO central repo check + return true; + + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + + if (getClass() != obj.getClass()) { + return false; + } + + final HashDbInfo other = (HashDbInfo) obj; + + if(! this.dbType.equals(other.dbType)){ + return false; + } + + if(this.dbType.equals(DatabaseType.FILE)){ + // For files, we expect the name and known type to match + return (this.hashSetName.equals(other.hashSetName) + && this.knownFilesType.equals(other.knownFilesType)); + } else { + // For central repo, the name, index, and known files type should match + return (this.hashSetName.equals(other.hashSetName) + && (this.centralRepoIndex == other.centralRepoIndex) + && this.knownFilesType.equals(other.knownFilesType)); + } + } + + @Override + public int hashCode() { + int hash = 5; + hash = 89 * hash + Objects.hashCode(this.hashSetName); + hash = 89 * hash + Objects.hashCode(this.knownFilesType); + hash = 89 * hash + Objects.hashCode(this.dbType); + if(this.dbType.equals(DatabaseType.CENTRAL_REPOSITORY)){ + hash = 89 * hash + this.centralRepoIndex; + } + + return hash; + } + /** * This overrides the default deserialization code so we can * properly set the dbType enum and other new fields diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java index 7533aa1797..e28a1d5224 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java @@ -391,7 +391,12 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan getSelectionModel().setSelectionInterval(index, index); } } + + public void selectRowByDatabase(HashDatabase db){ + setSelection(hashSetTableModel.getIndexByDatabase(db)); + } + @Deprecated public void selectRowByName(String name) { setSelection(hashSetTableModel.getIndexByName(name)); } @@ -458,6 +463,16 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan } } + int getIndexByDatabase(HashDatabase db){ + for (int i = 0; i < hashSets.size(); ++i) { + if (hashSets.get(i).equals(db)) { + return i; + } + } + return -1; + } + + @Deprecated int getIndexByName(String name) { for (int i = 0; i < hashSets.size(); ++i) { if (hashSets.get(i).getHashSetName().equals(name)) { @@ -797,7 +812,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan HashDatabase hashDb = new HashDbCreateDatabaseDialog().getHashDatabase(); if (null != hashDb) { hashSetTableModel.refreshModel(); - ((HashSetTable) hashSetTable).selectRowByName(hashDb.getHashSetName()); + ((HashSetTable) hashSetTable).selectRowByDatabase(hashDb); firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); } }//GEN-LAST:event_createDatabaseButtonActionPerformed @@ -844,7 +859,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan HashDatabase hashDb = new HashDbImportDatabaseDialog().getHashDatabase(); if (null != hashDb) { hashSetTableModel.refreshModel(); - ((HashSetTable) hashSetTable).selectRowByName(hashDb.getHashSetName()); + ((HashSetTable) hashSetTable).selectRowByDatabase(hashDb); firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); } }//GEN-LAST:event_importDatabaseButtonActionPerformed From 35789eabeb6655d18d357b8fb8f9adb443724c18 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Wed, 11 Oct 2017 13:11:53 -0400 Subject: [PATCH 05/41] Changed combo box to store HashDatabase objects instead of strings. --- .../autopsy/modules/hashdatabase/HashDbManager.java | 10 ++++++++++ .../AddTaggedHashesToHashDbConfigPanel.form | 2 +- .../AddTaggedHashesToHashDbConfigPanel.java | 13 +++---------- 3 files changed, 14 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 26796e10a8..85faaab82a 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -684,7 +684,11 @@ public class HashDbManager implements PropertyChangeListener { void close() throws TskCoreException; + public String toString(); + DatabaseType getDatabaseType(); + + } /** @@ -957,6 +961,12 @@ public class HashDbManager implements PropertyChangeListener { public void close() throws TskCoreException { SleuthkitJNI.closeHashDatabase(handle); } + + @Override + public String toString(){ + return getHashSetName(); + } + @Override public int hashCode() { diff --git a/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.form b/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.form index 377dad7826..20cec74d82 100755 --- a/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.form +++ b/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.form @@ -124,7 +124,7 @@ - + diff --git a/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.java b/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.java index 9721b787b3..cca3271760 100755 --- a/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.java +++ b/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.java @@ -22,7 +22,6 @@ import java.awt.Component; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -49,12 +48,10 @@ import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; class AddTaggedHashesToHashDbConfigPanel extends javax.swing.JPanel { private static final long serialVersionUID = 1L; - private final static String NO_DATABASES_TEXT = "No updateable hash sets"; private List tagNames; private final Map tagNameSelections = new LinkedHashMap<>(); private final TagNamesListModel tagsNamesListModel = new TagNamesListModel(); private final TagsNamesListCellRenderer tagsNamesRenderer = new TagsNamesListCellRenderer(); - private final Map hashSets = new HashMap<>(); private HashDatabase selectedHashSet = null; AddTaggedHashesToHashDbConfigPanel() { @@ -104,7 +101,6 @@ class AddTaggedHashesToHashDbConfigPanel extends javax.swing.JPanel { private void populateHashSetComponents() { // Clear the components because this method is called both during construction // and when the user changes the hash set configuration. - hashSets.clear(); hashSetsComboBox.removeAllItems(); // Get the updateable hash databases and add their hash set names to the @@ -112,12 +108,10 @@ class AddTaggedHashesToHashDbConfigPanel extends javax.swing.JPanel { List updateableHashSets = HashDbManager.getInstance().getUpdateableHashSetsNew(); if (!updateableHashSets.isEmpty()) { for (HashDatabase hashDb : updateableHashSets) { - hashSets.put(hashDb.getHashSetName(), hashDb); - hashSetsComboBox.addItem(hashDb.getHashSetName()); + hashSetsComboBox.addItem(hashDb); } hashSetsComboBox.setEnabled(true); } else { - hashSetsComboBox.addItem(NO_DATABASES_TEXT); hashSetsComboBox.setEnabled(false); } } @@ -290,8 +284,7 @@ class AddTaggedHashesToHashDbConfigPanel extends javax.swing.JPanel { }//GEN-LAST:event_selectAllButtonActionPerformed private void hashSetsComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hashSetsComboBoxActionPerformed - String key = (String)hashSetsComboBox.getSelectedItem(); - selectedHashSet = hashSets.get(key); + selectedHashSet = (HashDatabase)hashSetsComboBox.getSelectedItem(); }//GEN-LAST:event_hashSetsComboBoxActionPerformed private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deselectAllButtonActionPerformed @@ -316,7 +309,7 @@ class AddTaggedHashesToHashDbConfigPanel extends javax.swing.JPanel { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton configureHashDatabasesButton; private javax.swing.JButton deselectAllButton; - private javax.swing.JComboBox hashSetsComboBox; + private javax.swing.JComboBox hashSetsComboBox; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JScrollPane jScrollPane1; From ecf81085614605cc594837df1d65decdd00b545a Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Thu, 12 Oct 2017 12:43:02 -0400 Subject: [PATCH 06/41] Renaming --- .../AddContentToHashDbAction.java | 2 +- .../HashDbCreateDatabaseDialog.java | 2 +- .../HashDbImportDatabaseDialog.java | 2 +- .../hashdatabase/HashDbIngestModule.java | 4 +- .../modules/hashdatabase/HashDbManager.java | 66 +++++++++++++++---- .../hashdatabase/HashLookupModuleFactory.java | 2 +- .../HashLookupModuleSettings.java | 3 +- .../HashLookupModuleSettingsPanel.java | 8 +-- .../hashdatabase/HashLookupSettings.java | 16 +---- .../hashdatabase/HashLookupSettingsPanel.java | 6 +- .../AddTaggedHashesToHashDbConfigPanel.java | 2 +- .../configuration/SharedConfiguration.java | 4 +- 12 files changed, 73 insertions(+), 44 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddContentToHashDbAction.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddContentToHashDbAction.java index 8c9df922bf..6c58402fd6 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddContentToHashDbAction.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddContentToHashDbAction.java @@ -106,7 +106,7 @@ final class AddContentToHashDbAction extends AbstractAction implements Presenter // Get the current set of updateable hash databases and add each // one to the menu as a separate menu item. Selecting a hash database // adds the selected files to the selected database. - final List hashDatabases = HashDbManager.getInstance().getUpdateableHashSetsNew(); + final List hashDatabases = HashDbManager.getInstance().getUpdateableHashDatabases(); if (!hashDatabases.isEmpty()) { for (final HashDatabase database : hashDatabases) { JMenuItem databaseItem = add(database.getHashSetName()); diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java index 0bea515d14..ab3efb8afb 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java @@ -338,7 +338,7 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog { String errorMessage = NbBundle .getMessage(this.getClass(), "HashDbCreateDatabaseDialog.errMsg.hashDbCreationErr"); try { - newHashDb = HashDbManager.getInstance().addNewHashDatabaseNoSave(hashSetNameTextField.getText(), fileChooser.getSelectedFile().getCanonicalPath(), true, sendIngestMessagesCheckbox.isSelected(), type); + newHashDb = HashDbManager.getInstance().addNewFileTypeHashDatabase(hashSetNameTextField.getText(), fileChooser.getSelectedFile().getCanonicalPath(), true, sendIngestMessagesCheckbox.isSelected(), type); } catch (IOException ex) { Logger.getLogger(HashDbCreateDatabaseDialog.class.getName()).log(Level.WARNING, errorMessage, ex); JOptionPane.showMessageDialog(this, diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java index a533babaea..f440b4e9ac 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java @@ -341,7 +341,7 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { "HashDbImportDatabaseDialog.errorMessage.failedToOpenHashDbMsg", selectedFilePath); try { - selectedHashDb = HashDbManager.getInstance().addExistingHashDatabaseNoSave(hashSetNameTextField.getText(), selectedFilePath, true, sendIngestMessagesCheckbox.isSelected(), type); + selectedHashDb = HashDbManager.getInstance().addExistingFileTypeHashDatabase(hashSetNameTextField.getText(), selectedFilePath, true, sendIngestMessagesCheckbox.isSelected(), type); } catch (HashDbManagerException ex) { Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.WARNING, errorMessage, ex); JOptionPane.showMessageDialog(this, diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java index 6aa9729b07..55d91b5fbd 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java @@ -96,8 +96,8 @@ public class HashDbIngestModule implements FileIngestModule { if (!hashDbManager.verifyAllDatabasesLoadedCorrectly()) { throw new IngestModuleException("Could not load all hash databases"); } - updateEnabledHashSets(hashDbManager.getKnownBadFileHashSetsNew(), knownBadHashSets); - updateEnabledHashSets(hashDbManager.getKnownFileHashSetsNew(), knownHashSets); + updateEnabledHashSets(hashDbManager.getNotableFileHashDatabases(), knownBadHashSets); + updateEnabledHashSets(hashDbManager.getKnownFileHashDatabases(), knownHashSets); if (refCounter.incrementAndGet(jobId) == 1) { // initialize job totals diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index 85faaab82a..8403b2114a 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -58,8 +58,6 @@ public class HashDbManager implements PropertyChangeListener { private static final String HASH_DATABASE_FILE_EXTENSON = "kdb"; //NON-NLS private static HashDbManager instance = null; - //private List knownHashSets = new ArrayList<>(); - //private List knownBadHashSets = new ArrayList<>(); private List hashSets = new ArrayList<>(); private Set hashSetNames = new HashSet<>(); private Set hashSetPaths = new HashSet<>(); @@ -146,6 +144,7 @@ public class HashDbManager implements PropertyChangeListener { * * @throws HashDbManagerException */ + @Deprecated public synchronized HashDb addExistingHashDatabase(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws HashDbManagerException { HashDb hashDb = null; hashDb = this.addExistingHashDatabaseNoSave(hashSetName, path, searchDuringIngest, sendIngestMessages, knownFilesType); @@ -153,7 +152,12 @@ public class HashDbManager implements PropertyChangeListener { return hashDb; } + @Deprecated synchronized HashDb addExistingHashDatabaseNoSave(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws HashDbManagerException { + return (HashDb)addExistingFileTypeHashDatabase(hashSetName, path, searchDuringIngest, sendIngestMessages, knownFilesType); + } + + synchronized HashDatabase addExistingFileTypeHashDatabase(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws HashDbManagerException { HashDb hashDb = null; try { if (!new File(path).exists()) { @@ -193,6 +197,7 @@ public class HashDbManager implements PropertyChangeListener { * * @throws HashDbManagerException */ + @Deprecated public synchronized HashDb addNewHashDatabase(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws HashDbManagerException { @@ -204,8 +209,14 @@ public class HashDbManager implements PropertyChangeListener { return hashDb; } + @Deprecated public synchronized HashDb addNewHashDatabaseNoSave(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws HashDbManagerException { + return (HashDb)addNewFileTypeHashDatabase(hashSetName, path, searchDuringIngest, sendIngestMessages, knownFilesType); + } + + public synchronized HashDatabase addNewFileTypeHashDatabase(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, + HashDb.KnownFilesType knownFilesType) throws HashDbManagerException { HashDb hashDb = null; try { File file = new File(path); @@ -241,7 +252,7 @@ public class HashDbManager implements PropertyChangeListener { } throw new TskCoreException("Invalid database type in HashDbInfo"); } - + private HashDb addFileTypeHashDatabase(int handle, String hashSetName, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws TskCoreException { // Wrap an object around the handle. HashDb hashDb = new HashDb(handle, hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType); @@ -308,16 +319,11 @@ public class HashDbManager implements PropertyChangeListener { * * @throws HashDbManagerException */ - public synchronized void removeHashDatabase(HashDb hashDb) throws HashDbManagerException { + public synchronized void removeHashDatabase(HashDatabase hashDb) throws HashDbManagerException { this.removeHashDatabaseNoSave(hashDb); this.save(); } - // public synchronized void removeHashDatabaseNoSave(HashDb hashDb) throws HashDbManagerException { - // removeHashDatabaseNoSave((UnnamedHashSet)hashDb); - // - // } - public synchronized void removeHashDatabaseNoSave(HashDatabase hashDb) throws HashDbManagerException { // Don't remove a database if ingest is running boolean ingestIsRunning = IngestManager.getInstance().isIngestRunning(); @@ -386,14 +392,30 @@ public class HashDbManager implements PropertyChangeListener { */ @Deprecated public synchronized List getAllHashSets() { + return getAllFileTypeHashSets(); + } + + /** + * Gets all of the file type hash databases used to classify files as known or known + * bad. + * + * @return A list, possibly empty, of hash databases. + */ + public synchronized List getAllFileTypeHashSets() { List hashDbs = new ArrayList<>(); this.hashSets.stream().filter((thisSet) -> (thisSet instanceof HashDb)).forEach((thisSet) -> { hashDbs.add((HashDb)thisSet); }); return hashDbs; - } + } - public synchronized List getAllHashSetsNew(){ + /** + * Gets all of the hash databases used to classify files as known or known + * bad. + * + * @return A list, possibly empty, of hash databases. + */ + public synchronized List getAllHashDatabases(){ List hashDbs = new ArrayList<>(); hashDbs.addAll(this.hashSets); return hashDbs; @@ -413,7 +435,12 @@ public class HashDbManager implements PropertyChangeListener { return hashDbs; } - public synchronized List getKnownFileHashSetsNew() { + /** + * Gets all of the hash databases used to classify files as known. + * + * @return A list, possibly empty, of hash databases. + */ + public synchronized List getKnownFileHashDatabases() { List hashDbs = new ArrayList<>(); this.hashSets.stream().filter((db) -> (db.getKnownFilesType() == HashDb.KnownFilesType.KNOWN)).forEach((db) -> { hashDbs.add(db); @@ -435,7 +462,12 @@ public class HashDbManager implements PropertyChangeListener { return hashDbs; } - public synchronized List getKnownBadFileHashSetsNew() { + /** + * Gets all of the hash databases used to classify files as notable. + * + * @return A list, possibly empty, of hash databases. + */ + public synchronized List getNotableFileHashDatabases() { List hashDbs = new ArrayList<>(); this.hashSets.stream().filter((db) -> (db.getKnownFilesType() == HashDb.KnownFilesType.KNOWN_BAD)).forEach((db) -> { hashDbs.add(db); @@ -458,7 +490,12 @@ public class HashDbManager implements PropertyChangeListener { return updateableDbs; } - public synchronized List getUpdateableHashSetsNew(){ + /** + * Gets all of the hash databases that accept updates. + * + * @return A list, possibly empty, of hash databases. + */ + public synchronized List getUpdateableHashDatabases(){ return getUpdateableHashSets(this.hashSets); } @@ -684,6 +721,7 @@ public class HashDbManager implements PropertyChangeListener { void close() throws TskCoreException; + @Override public String toString(); DatabaseType getDatabaseType(); diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java index 4e06f2805b..52ae48c8cd 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java @@ -60,7 +60,7 @@ public class HashLookupModuleFactory extends IngestModuleFactoryAdapter { @Override public IngestModuleIngestJobSettings getDefaultIngestJobSettings() { // All available hash sets are enabled and always calculate hashes is true by default. - return new HashLookupModuleSettings(true, HashDbManager.getInstance().getAllHashSetsNew()); + return new HashLookupModuleSettings(true, HashDbManager.getInstance().getAllHashDatabases()); } @Override diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java index 3b2de9ed7b..49f45a57d8 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java @@ -55,6 +55,7 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { /** * This overrides the default deserialization code so we can * copy the enabled/disabled status into the DatabaseType objects. + * Ignore the Netbeans warning that this method is unused. * @param stream * @throws IOException * @throws ClassNotFoundException @@ -149,7 +150,7 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { } try{ - databaseInfoList = HashLookupSettings.convertHashSetList(HashDbManager.getInstance().getAllHashSetsNew()); + databaseInfoList = HashLookupSettings.convertHashSetList(HashDbManager.getInstance().getAllHashDatabases()); } catch (HashLookupSettings.HashLookupSettingsException ex){ Logger.getLogger(HashLookupModuleSettings.class.getName()).log(Level.SEVERE, "Error updating hash database settings.", ex); //NON-NLS return; diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java index 279a9796a1..ae2e4e7331 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java @@ -53,8 +53,8 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe } private void initializeHashSetModels(HashLookupModuleSettings settings) { - initializeHashSetModels(settings, hashDbManager.getKnownFileHashSetsNew(), knownHashSetModels); - initializeHashSetModels(settings, hashDbManager.getKnownBadFileHashSetsNew(), knownBadHashSetModels); + initializeHashSetModels(settings, hashDbManager.getKnownFileHashDatabases(), knownHashSetModels); + initializeHashSetModels(settings, hashDbManager.getNotableFileHashDatabases(), knownBadHashSetModels); } private void initializeHashSetModels(HashLookupModuleSettings settings, List hashDbs, List hashSetModels) { @@ -125,8 +125,8 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe } private void updateHashSetModels() { - updateHashSetModels(hashDbManager.getKnownFileHashSetsNew(), knownHashSetModels); - updateHashSetModels(hashDbManager.getKnownBadFileHashSetsNew(), knownBadHashSetModels); + updateHashSetModels(hashDbManager.getKnownFileHashDatabases(), knownHashSetModels); + updateHashSetModels(hashDbManager.getNotableFileHashDatabases(), knownBadHashSetModels); } void updateHashSetModels(List hashDbs, List hashSetModels) { diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java index 2efba5eee1..8e9adbf00a 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java @@ -279,14 +279,6 @@ final class HashLookupSettings implements Serializable { * @return Whether or not the settings were written successfully */ static boolean writeSettings(HashLookupSettings settings) { - - System.out.println("\n#####\nwriteSettings"); - for(HashDbInfo info:settings.hashDbInfoList){ - System.out.println(info.hashSetName); - System.out.println(" DB type: " + info.dbType.toString()); - System.out.println(" Enabled: " + info.searchDuringIngest); - System.out.println(" Type: " + info.knownFilesType.getDisplayName()); - } try (NbObjectOutputStream out = new NbObjectOutputStream(new FileOutputStream(SERIALIZATION_FILE_PATH))) { out.writeObject(settings); @@ -457,9 +449,8 @@ final class HashLookupSettings implements Serializable { // FILE types will always have unique names, so no more testing required return true; } - - // TODO TODO central repo check - return true; + // To do: central repo tests + return false; } @@ -506,8 +497,7 @@ final class HashLookupSettings implements Serializable { /** * This overrides the default deserialization code so we can - * properly set the dbType enum and other new fields - * given an old settings file. + * properly set the dbType enum given an old settings file. * @param stream * @throws IOException * @throws ClassNotFoundException diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java index e28a1d5224..d18fe9e0ad 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java @@ -259,7 +259,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan public void saveSettings() { //Checking for for any unindexed databases List unindexed = new ArrayList<>(); - for (HashDatabase hashSet : hashSetManager.getAllHashSetsNew()) { + for (HashDatabase hashSet : hashSetManager.getAllHashDatabases()) { try { if (!hashSet.hasIndex()) { unindexed.add(hashSet); @@ -408,7 +408,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan */ private class HashSetTableModel extends AbstractTableModel { - List hashSets = HashDbManager.getInstance().getAllHashSetsNew(); + List hashSets = HashDbManager.getInstance().getAllHashDatabases(); @Override public int getColumnCount() { @@ -483,7 +483,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan } void refreshModel() { - hashSets = HashDbManager.getInstance().getAllHashSetsNew(); + hashSets = HashDbManager.getInstance().getAllHashDatabases(); refreshDisplay(); } diff --git a/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.java b/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.java index cca3271760..4dea291734 100755 --- a/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.java +++ b/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.java @@ -105,7 +105,7 @@ class AddTaggedHashesToHashDbConfigPanel extends javax.swing.JPanel { // Get the updateable hash databases and add their hash set names to the // JComboBox component. - List updateableHashSets = HashDbManager.getInstance().getUpdateableHashSetsNew(); + List updateableHashSets = HashDbManager.getInstance().getUpdateableHashDatabases(); if (!updateableHashSets.isEmpty()) { for (HashDatabase hashDb : updateableHashSets) { hashSetsComboBox.addItem(hashDb); diff --git a/Experimental/src/org/sleuthkit/autopsy/experimental/configuration/SharedConfiguration.java b/Experimental/src/org/sleuthkit/autopsy/experimental/configuration/SharedConfiguration.java index ccb2e49e54..b715b7d309 100755 --- a/Experimental/src/org/sleuthkit/autopsy/experimental/configuration/SharedConfiguration.java +++ b/Experimental/src/org/sleuthkit/autopsy/experimental/configuration/SharedConfiguration.java @@ -1016,7 +1016,7 @@ public class SharedConfiguration { // If a copy of the database is loaded, close it before deleting and copying. if (localDb.exists()) { - List hashDbs = HashDbManager.getInstance().getAllHashSets(); + List hashDbs = HashDbManager.getInstance().getAllFileTypeHashSets(); HashDbManager.HashDb matchingDb = null; for (HashDbManager.HashDb db : hashDbs) { try { @@ -1122,7 +1122,7 @@ public class SharedConfiguration { try { HashDbManager hashDbManager = HashDbManager.getInstance(); hashDbManager.loadLastSavedConfiguration(); - for (HashDb hashDb : hashDbManager.getAllHashSets()) { + for (HashDb hashDb : hashDbManager.getAllFileTypeHashSets()) { if (hashDb.hasIndexOnly()) { results.add(hashDb.getIndexPath()); } else { From 44aeb6ca5d920766929130c6dec6338fefceb47a Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Mon, 16 Oct 2017 13:41:26 -0400 Subject: [PATCH 07/41] Central repo hashsets can now be used for lookups. Added temporary button to settings panel to create them. --- .../datamodel/AbstractSqlEamDb.java | 57 +++ .../centralrepository/datamodel/EamDb.java | 21 + .../datamodel/SqliteEamDb.java | 16 + .../ImportHashDatabaseDialog.java | 31 +- .../modules/hashdatabase/Bundle.properties | 14 + .../modules/hashdatabase/Bundle_ja.properties | 10 + .../modules/hashdatabase/HashDbManager.java | 390 ++++++++++++++++++ .../hashdatabase/HashLookupSettings.java | 41 +- .../hashdatabase/HashLookupSettingsPanel.form | 23 +- .../hashdatabase/HashLookupSettingsPanel.java | 31 +- 10 files changed, 606 insertions(+), 28 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java index 689d5a22fb..9677eeec9d 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java @@ -1245,6 +1245,42 @@ public abstract class AbstractSqlEamDb implements EamDb { return caseNames.stream().collect(Collectors.toList()); } + + /** + * Check if the given hash is in a specific reference set + * @param hash + * @param index + * @return + */ + @Override + public boolean isHashInReferenceSet(String hash, int index) throws EamDbException{ + + Connection conn = connect(); + + Long matchingInstances = 0L; + PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + String sql = "SELECT count(*) FROM %s WHERE value=? AND reference_set_id=?"; + + String fileTableName = EamDbUtil.correlationTypeToReferenceTableName(getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID)); + + try { + preparedStatement = conn.prepareStatement(String.format(sql, fileTableName)); + preparedStatement.setString(1, hash); + preparedStatement.setInt(2, index); + resultSet = preparedStatement.executeQuery(); + resultSet.next(); + matchingInstances = resultSet.getLong(1); + } catch (SQLException ex) { + throw new EamDbException("Error determining if file is in reference set.", ex); // NON-NLS + } finally { + EamDbUtil.closePreparedStatement(preparedStatement); + EamDbUtil.closeResultSet(resultSet); + EamDbUtil.closeConnection(conn); + } + + return 0 < matchingInstances; + } /** * Is the artifact known as bad according to the reference entries? @@ -1382,6 +1418,27 @@ public abstract class AbstractSqlEamDb implements EamDb { EamDbUtil.closeConnection(conn); } } + + /** + * Add a new Global Set + * + * @param orgID + * @param setName + * @param version + * @param importDate + * @return + * @throws EamDbException + */ + @Override + public int newReferenceSet(int orgID, String setName, String version) throws EamDbException { + EamDb dbManager = EamDb.getInstance(); + EamGlobalSet eamGlobalSet = new EamGlobalSet( + orgID, + setName, + version, + LocalDate.now()); + return dbManager.newReferencelSet(eamGlobalSet); + } /** * Add a new Global Set diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java index c3f3c09730..302c32f1c4 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java @@ -18,6 +18,7 @@ */ package org.sleuthkit.autopsy.centralrepository.datamodel; +import java.time.LocalDate; import java.util.List; import java.util.Set; import org.sleuthkit.datamodel.TskData; @@ -353,6 +354,14 @@ public interface EamDb { */ List getListCasesHavingArtifactInstancesKnownBad(CorrelationAttribute.Type aType, String value) throws EamDbException; + /** + * Check if the given hash is in a specific reference set + * @param hash + * @param index + * @return + */ + public boolean isHashInReferenceSet(String hash, int index) throws EamDbException; + /** * Is the artifact known as bad according to the reference entries? * @@ -403,6 +412,18 @@ public interface EamDb { */ int newReferencelSet(EamGlobalSet eamGlobalSet) throws EamDbException; + /** + * Add a new Global Set + * + * @param orgID + * @param setName + * @param version + * + * @return The ID of the new global set + * @throws EamDbException + */ + int newReferenceSet(int orgID, String setName, String version) throws EamDbException; + /** * Get a global set by ID * diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java index a048d95f9c..140a708c48 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java @@ -635,6 +635,22 @@ public class SqliteEamDb extends AbstractSqlEamDb { } } + /** + * Check if the given hash is in a specific reference set + * @param hash + * @param index + * @return + */ + @Override + public boolean isHashInReferenceSet(String hash, int index) throws EamDbException{ + try{ + acquireSharedLock(); + return super.isHashInReferenceSet(hash, index); + } finally { + releaseSharedLock(); + } + } + /** * Is the artifact known as bad according to the reference entries? * diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportHashDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportHashDatabaseDialog.java index e041f87a03..2bc81226dc 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportHashDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportHashDatabaseDialog.java @@ -60,6 +60,7 @@ import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalSet; import org.sleuthkit.autopsy.centralrepository.datamodel.EamOrganization; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager; import org.sleuthkit.datamodel.TskData; /** @@ -67,7 +68,7 @@ import org.sleuthkit.datamodel.TskData; * add it to the set of hash databases used to classify files as unknown, known, * or notable. */ -final class ImportHashDatabaseDialog extends javax.swing.JDialog { +final public class ImportHashDatabaseDialog extends javax.swing.JDialog { private static final Logger LOGGER = Logger.getLogger(ImportHashDatabaseDialog.class.getName()); private final JFileChooser fileChooser = new JFileChooser(); @@ -77,6 +78,7 @@ final class ImportHashDatabaseDialog extends javax.swing.JDialog { private List orgs = null; private final Collection textBoxes; private final TextBoxChangedListener textBoxChangedListener; + private HashDbManager.HashDatabase selectedHashDb = null; /** @@ -85,7 +87,7 @@ final class ImportHashDatabaseDialog extends javax.swing.JDialog { * unknown, known, or notable. */ @Messages({"ImportHashDatabaseDialog.importHashDbMsg=Import Hash Database"}) - ImportHashDatabaseDialog() { + public ImportHashDatabaseDialog() { super((JFrame) WindowManager.getDefault().getMainWindow(), Bundle.ImportHashDatabaseDialog_importHashDbMsg(), true); // NON-NLS @@ -122,6 +124,10 @@ final class ImportHashDatabaseDialog extends javax.swing.JDialog { setTextBoxListeners(); enableOkButton(false); } + + public HashDbManager.HashDatabase getHashDatabase(){ + return this.selectedHashDb; + } /** * Register for notifications when the text boxes get updated. @@ -513,6 +519,23 @@ final class ImportHashDatabaseDialog extends javax.swing.JDialog { return; } + HashDbManager.HashDb.KnownFilesType known; + if (knownRadioButton.isSelected()) { + known = HashDbManager.HashDb.KnownFilesType.KNOWN; + } else{ + known = HashDbManager.HashDb.KnownFilesType.KNOWN_BAD; + } + + try{ + HashDbManager.getInstance().importCentralRepoHashSet(tfDatabaseName.getText().trim(), tfDatabaseVersion.getText().trim(), + selectedOrg.getOrgID(), true, true, + known, selectedFilePath); + } catch (Exception ex){ + + } finally { + dispose(); + } + /* // create global set int globalSetID; try { @@ -542,7 +565,7 @@ final class ImportHashDatabaseDialog extends javax.swing.JDialog { } catch (EamDbException | UnknownHostException ex) { Logger.getLogger(ImportHashDatabaseDialog.class.getName()).log(Level.SEVERE, errorMessage, ex); lbWarningMsg.setText(ex.getMessage()); - } + }*/ }//GEN-LAST:event_okButtonActionPerformed @@ -571,7 +594,7 @@ final class ImportHashDatabaseDialog extends javax.swing.JDialog { }//GEN-LAST:event_comboboxSourceOrganizationActionPerformed @NbBundle.Messages({"ImportHashDatabaseDialog.ImportHashDatabaseWorker.displayName=Importing Hash Database"}) - private class ImportHashDatabaseWorker extends SwingWorker { + public class ImportHashDatabaseWorker extends SwingWorker { private final File file; private final TskData.FileKnown knownStatus; diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties index b0f8eba6c3..30f795fb50 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties @@ -211,3 +211,17 @@ HashLookupSettingsPanel.hashDatabasesLabel.text=Hash Databases: HashLookupSettingsPanel.importDatabaseButton.toolTipText= HashLookupSettingsPanel.importDatabaseButton.text=Import database HashLookupSettingsPanel.deleteDatabaseButton.text=Delete database +HashLookupSettingsPanel.hashDbTypeLabel1.text=No database selected +HashLookupSettingsPanel.importDatabaseButton1.text=Import database +HashLookupSettingsPanel.jLabel1.text=Version: +HashLookupSettingsPanel.hashDatabasesLabel1.text=Hash Databases: +HashLookupSettingsPanel.hashDbNameLabel1.text=No database selected +HashLookupSettingsPanel.ingestWarningLabel1.text=Ingest is ongoing, some settings will be unavailable until it finishes. +HashLookupSettingsPanel.informationLabel1.text=Information +HashLookupSettingsPanel.jLabel3.text=jLabel3 +HashLookupSettingsPanel.optionsLabel1.text=Options +HashLookupSettingsPanel.nameLabel1.text=Hash Set Name: +HashLookupSettingsPanel.sendIngestMessagesCheckBox1.text=Send ingest inbox message for each hit +HashLookupSettingsPanel.importDatabaseButton1.toolTipText= +HashLookupSettingsPanel.typeLabel1.text=Type: +HashLookupSettingsPanel.jButton1.text=Import CR Hashset diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle_ja.properties b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle_ja.properties index 3a1eac32f4..ebe1466e05 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle_ja.properties +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle_ja.properties @@ -209,3 +209,13 @@ HashLookupSettingsPanel.hashDbNameLabel.text=\u30c7\u30fc\u30bf\u30d9\u30fc\u30b HashLookupSettingsPanel.nameLabel.text=\u30cf\u30c3\u30b7\u30e5\u30bb\u30c3\u30c8\u540d\uff1a HashLookupSettingsPanel.hashDatabasesLabel.text=\u30cf\u30c3\u30b7\u30e5\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\uff1a HashLookupSettingsPanel.importDatabaseButton.text=\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u30a4\u30f3\u30dd\u30fc\u30c8 +HashLookupSettingsPanel.typeLabel1.text=\u30bf\u30a4\u30d7\uff1a +HashLookupSettingsPanel.hashDbTypeLabel1.text=\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304c\u9078\u629e\u3055\u308c\u3066\u3044\u307e\u305b\u3093 +HashLookupSettingsPanel.importDatabaseButton1.text=\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u30a4\u30f3\u30dd\u30fc\u30c8 +HashLookupSettingsPanel.hashDatabasesLabel1.text=\u30cf\u30c3\u30b7\u30e5\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\uff1a +HashLookupSettingsPanel.hashDbNameLabel1.text=\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304c\u9078\u629e\u3055\u308c\u3066\u3044\u307e\u305b\u3093 +HashLookupSettingsPanel.ingestWarningLabel1.text=\u30a4\u30f3\u30b8\u30a7\u30b9\u30c8\u4e2d\u3067\u3059\u3002\u5b8c\u4e86\u3059\u308b\u307e\u3067\u4e00\u90e8\u306e\u8a2d\u5b9a\u306f\u5229\u7528\u3067\u304d\u307e\u305b\u3093\u3002 +HashLookupSettingsPanel.informationLabel1.text=\u60c5\u5831 +HashLookupSettingsPanel.optionsLabel1.text=\u30aa\u30d7\u30b7\u30e7\u30f3 +HashLookupSettingsPanel.nameLabel1.text=\u30cf\u30c3\u30b7\u30e5\u30bb\u30c3\u30c8\u540d\uff1a +HashLookupSettingsPanel.sendIngestMessagesCheckBox1.text=\u30d2\u30c3\u30c8\u6bce\u306b\u30a4\u30f3\u30b8\u30a7\u30b9\u30c8\u30a4\u30f3\u30dc\u30c3\u30af\u30b9\u306b\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9001\u308b diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index 8403b2114a..d6fd4d522c 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -21,8 +21,12 @@ package org.sleuthkit.autopsy.modules.hashdatabase; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; +import java.io.BufferedReader; import java.io.File; +import java.io.FileReader; import java.io.IOException; +import java.net.UnknownHostException; +import java.nio.file.Files; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -32,12 +36,18 @@ import java.util.concurrent.ExecutionException; import java.util.logging.Level; import javax.swing.JFileChooser; import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; import javax.swing.SwingWorker; import javax.swing.filechooser.FileNameExtensionFilter; import org.apache.commons.io.FilenameUtils; import org.netbeans.api.progress.ProgressHandle; import org.openide.util.NbBundle; import org.openide.util.NbBundle.Messages; +import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttribute; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalFileInstance; +import org.sleuthkit.autopsy.centralrepository.optionspanel.ImportHashDatabaseDialog; import org.sleuthkit.autopsy.core.RuntimeProperties; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; @@ -49,6 +59,7 @@ import org.sleuthkit.datamodel.HashEntry; import org.sleuthkit.datamodel.HashHitInfo; import org.sleuthkit.datamodel.SleuthkitJNI; import org.sleuthkit.datamodel.TskCoreException; +import org.sleuthkit.datamodel.TskData; /** * This class implements a singleton that manages the set of hash databases used @@ -287,6 +298,87 @@ public class HashDbManager implements PropertyChangeListener { } return hashDb; } + + public CentralRepoHashDb importCentralRepoHashSet(String hashSetName, String version, int orgId, + boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType, + String importFile) throws TskCoreException { + + try{ + // Create an empty hashset in the central repository + int crIndex = EamDb.getInstance().newReferenceSet(orgId, hashSetName, version); + + // Import the hashes + + TskData.FileKnown knownStatus = TskData.FileKnown.UNKNOWN; + if (knownFilesType.equals(HashDb.KnownFilesType.KNOWN)) { + knownStatus = TskData.FileKnown.KNOWN; + } else { + knownStatus = TskData.FileKnown.BAD; + } + + // Future, make UI handle more than the "FILES" type. + + EamDb dbManager = EamDb.getInstance(); + CorrelationAttribute.Type contentType = dbManager.getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID); // get "FILES" type + BufferedReader reader = new BufferedReader(new FileReader(importFile)); + String line; + Set globalInstances = new HashSet<>(); + + long totalLines = Files.lines(new File(importFile).toPath()).count(); + + int numLines = 0; + while ((line = reader.readLine()) != null) { + + String[] parts = line.split("\\|"); + + // Header lines start with a 41 character dummy hash, 1 character longer than a SHA-1 hash + if (parts.length != 2 || parts[0].length() == 41) { + continue; + } + + EamGlobalFileInstance eamGlobalFileInstance = new EamGlobalFileInstance( + crIndex, + parts[0].toLowerCase(), + knownStatus, + ""); + + globalInstances.add(eamGlobalFileInstance); + + if(numLines % 1000 == 0){ + dbManager.bulkInsertReferenceTypeEntries(globalInstances, contentType); + globalInstances.clear(); + } + } + + dbManager.bulkInsertReferenceTypeEntries(globalInstances, contentType); + + // this should wait until after init + CentralRepoHashDb hashDb = new CentralRepoHashDb(hashSetName, version, crIndex, + searchDuringIngest, sendIngestMessages, knownFilesType); + + // Add the hash database to the collection + hashSets.add(hashDb); + + + + // Let any external listeners know that there's a new set + try { + changeSupport.firePropertyChange(SetEvt.DB_ADDED.toString(), null, hashSetName); + } catch (Exception e) { + logger.log(Level.SEVERE, "HashDbManager listener threw exception", e); //NON-NLS + MessageNotifyUtil.Notify.show( + NbBundle.getMessage(this.getClass(), "HashDbManager.moduleErr"), + NbBundle.getMessage(this.getClass(), "HashDbManager.moduleErrorListeningToUpdatesMsg"), + MessageNotifyUtil.MessageType.ERROR); + } + return hashDb; + + } catch (Exception ex){ + // TODO + ex.printStackTrace(); + throw new TskCoreException(ex.getLocalizedMessage()); + } + } synchronized void indexHashDatabase(HashDatabase hashDb) { hashDb.addPropertyChangeListener(this); @@ -1035,6 +1127,304 @@ public class HashDbManager implements PropertyChangeListener { } } + /** + * Instances of this class represent hash databases used to classify files + * as known or know bad. + */ + public static class CentralRepoHashDb implements HashDatabase{ + + private static final long serialVersionUID = 1L; + private final String hashSetName; + private boolean searchDuringIngest; + private boolean sendIngestMessages; + private final HashDb.KnownFilesType knownFilesType; + private final int centralRepoIndex; + private final String version; + private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); + + private CentralRepoHashDb(String hashSetName, String version, int centralRepoIndex, + boolean useForIngest, boolean sendHitMessages, HashDb.KnownFilesType knownFilesType) { + this.hashSetName = hashSetName; + this.version = version; + this.centralRepoIndex = centralRepoIndex; + this.searchDuringIngest = useForIngest; + this.sendIngestMessages = sendHitMessages; + this.knownFilesType = knownFilesType; + } + + /** + * Adds a listener for the events defined in HashDb.Event. + * Listeners are used during indexing. + * + * @param pcl + */ + @Override + public void addPropertyChangeListener(PropertyChangeListener pcl) { + propertyChangeSupport.addPropertyChangeListener(pcl); + } + + /** + * Removes a listener for the events defined in HashDb.Event. + * + * @param pcl + */ + @Override + public void removePropertyChangeListener(PropertyChangeListener pcl) { + propertyChangeSupport.removePropertyChangeListener(pcl); + } + + @Override + public int getHandle(){ + return 0; + } + + @Override + public String getHashSetName() { + return hashSetName; + } + + public String getVersion(){ + return version; + } + + public int getCentralRepoIndex(){ + return centralRepoIndex; + } + + @Override + public String getDatabasePath() throws TskCoreException { + return ""; + } + + @Override + public void setIndexing(boolean indexing){ + + } + + @Override + public DatabaseType getDatabaseType(){ + return DatabaseType.FILE; + } + + @Override + public String getIndexPath() throws TskCoreException { + return ""; + } + + @Override + public HashDb.KnownFilesType getKnownFilesType() { + return knownFilesType; + } + + @Override + public boolean getSearchDuringIngest() { + return searchDuringIngest; + } + + @Override + public void setSearchDuringIngest(boolean useForIngest) { + this.searchDuringIngest = useForIngest; + } + + @Override + public boolean getSendIngestMessages() { + return sendIngestMessages; + } + + @Override + public void setSendIngestMessages(boolean showInboxMessages) { + this.sendIngestMessages = showInboxMessages; + } + + /** + * Indicates whether the hash database accepts updates. + * + * @return True if the database accepts updates, false otherwise. + * + * @throws org.sleuthkit.datamodel.TskCoreException + */ + @Override + public boolean isUpdateable() throws TskCoreException { + return false; + } + + /** + * Adds hashes of content (if calculated) to the hash database. + * + * @param content The content for which the calculated hashes, if any, + * are to be added to the hash database. + * + * @throws TskCoreException + */ + @Override + public void addHashes(Content content) throws TskCoreException { + addHashes(content, null); + } + + /** + * Adds hashes of content (if calculated) to the hash database. + * + * @param content The content for which the calculated hashes, if any, + * are to be added to the hash database. + * @param comment A comment to associate with the hashes, e.g., the name + * of the case in which the content was encountered. + * + * @throws TskCoreException + */ + @Override + public void addHashes(Content content, String comment) throws TskCoreException { + + } + + /** + * Adds a list of hashes to the hash database at once + * + * @param hashes List of hashes + * + * @throws TskCoreException + */ + @Override + public void addHashes(List hashes) throws TskCoreException { + + } + + /** + * Perform a basic boolean lookup of the file's hash. + * + * @param content + * + * @return True if file's MD5 is in the hash database + * + * @throws TskCoreException + */ + @Override + public boolean lookupMD5Quick(Content content) throws TskCoreException { + // This only works for AbstractFiles and MD5 hashes + assert content instanceof AbstractFile; + if (content instanceof AbstractFile) { + AbstractFile file = (AbstractFile) content; + if (null != file.getMd5Hash()) { + try{ + return EamDb.getInstance().isHashInReferenceSet(file.getMd5Hash(), this.centralRepoIndex); + } catch (EamDbException ex){ + Logger.getLogger(HashDb.class.getName()).log(Level.SEVERE, "Error performing central reposiotry hash lookup", ex); //NON-NLS + throw new TskCoreException(ex.getLocalizedMessage()); + } + } + } + return false; + } + + /** + * Lookup hash value in DB and provide details on file. + * + * @param content + * + * @return null if file is not in database. + * + * @throws TskCoreException + */ + @Override + public HashHitInfo lookupMD5(Content content) throws TskCoreException { + HashHitInfo result = null; + // This only works for AbstractFiles and MD5 hashes + assert content instanceof AbstractFile; + if (content instanceof AbstractFile) { + AbstractFile file = (AbstractFile) content; + if (null != file.getMd5Hash()) { + try{ + if(EamDb.getInstance().isHashInReferenceSet(file.getMd5Hash(), this.centralRepoIndex)){ + // Make a bare-bones HashHitInfo for now + result = new HashHitInfo(file.getMd5Hash(), "", ""); + } + } catch (EamDbException ex){ + Logger.getLogger(HashDb.class.getName()).log(Level.SEVERE, "Error performing central reposiotry hash lookup", ex); //NON-NLS + throw new TskCoreException(ex.getLocalizedMessage()); + } + } + } + return result; + } + + /** + * Returns whether this database can be enabled. + * For file type, this is the same as checking that it has an index + * @return true if is valid, false otherwise + * @throws TskCoreException + */ + @Override + public boolean isValid() throws TskCoreException { + return true; + } + + @Override + public boolean hasIndex() throws TskCoreException { + return false; + } + + @Override + public boolean hasIndexOnly() throws TskCoreException { + return false; + } + + @Override + public boolean canBeReIndexed() throws TskCoreException { + return false; + } + + @Override + public boolean isIndexing() { + return false; + } + + @Override + public void firePropertyChange(String propertyName, Object oldValue, Object newValue){ + this.propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue); + } + + @Override + public void close() throws TskCoreException { + + } + + @Override + public String toString(){ + return getHashSetName(); + } + + + @Override + public int hashCode() { + int code = 23; + code = 47 * code + Objects.hashCode(this.hashSetName); + code = 47 * code + Objects.hashCode(this.version); + code = 47 * code + Integer.hashCode(this.centralRepoIndex); + code = 47 * code + Objects.hashCode(this.knownFilesType); + return code; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final CentralRepoHashDb other = (CentralRepoHashDb) obj; + if (!Objects.equals(this.hashSetName, other.hashSetName)) { + return false; + } + if (!Objects.equals(this.version, other.version)) { + return false; + } + if (this.knownFilesType != other.knownFilesType) { + return false; + } + return true; + } + } + /** * Worker thread to make an index of a database */ diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java index 8e9adbf00a..21c689cc70 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java @@ -302,6 +302,7 @@ final class HashLookupSettings implements Serializable { private boolean searchDuringIngest; private final boolean sendIngestMessages; private final String path; + private final String version; private final int centralRepoIndex; private DatabaseType dbType; @@ -322,11 +323,13 @@ final class HashLookupSettings implements Serializable { this.sendIngestMessages = sendIngestMessages; this.path = path; this.centralRepoIndex = -1; + this.version = ""; this.dbType = DatabaseType.FILE; } - HashDbInfo(String hashSetName, int centralRepoIndex, HashDbManager.HashDb.KnownFilesType knownFilesType, boolean searchDuringIngest, boolean sendIngestMessages){ + HashDbInfo(String hashSetName, String version, int centralRepoIndex, HashDbManager.HashDb.KnownFilesType knownFilesType, boolean searchDuringIngest, boolean sendIngestMessages){ this.hashSetName = hashSetName; + this.version = version; this.centralRepoIndex = centralRepoIndex; this.knownFilesType = knownFilesType; this.searchDuringIngest = searchDuringIngest; @@ -336,27 +339,33 @@ final class HashLookupSettings implements Serializable { } HashDbInfo(HashDbManager.HashDatabase db) throws TskCoreException{ - if(db.getDatabaseType() == DatabaseType.FILE){ - this.hashSetName = db.getHashSetName(); - this.knownFilesType = db.getKnownFilesType(); - this.searchDuringIngest = db.getSearchDuringIngest(); - this.sendIngestMessages = db.getSendIngestMessages(); + if(db instanceof HashDbManager.HashDb){ + HashDbManager.HashDb fileTypeDb = (HashDbManager.HashDb)db; + this.hashSetName = fileTypeDb.getHashSetName(); + this.knownFilesType = fileTypeDb.getKnownFilesType(); + this.searchDuringIngest = fileTypeDb.getSearchDuringIngest(); + this.sendIngestMessages = fileTypeDb.getSendIngestMessages(); this.centralRepoIndex = -1; + this.version = ""; this.dbType = DatabaseType.FILE; - if (db.hasIndexOnly()) { - this.path = db.getIndexPath(); + if (fileTypeDb.hasIndexOnly()) { + this.path = fileTypeDb.getIndexPath(); } else { - this.path = db.getDatabasePath(); + this.path = fileTypeDb.getDatabasePath(); } - } else { - this.hashSetName = db.getHashSetName(); - this.knownFilesType = db.getKnownFilesType(); - this.searchDuringIngest = db.getSearchDuringIngest(); - this.sendIngestMessages = db.getSendIngestMessages(); + } else {// if(db instanceof HashDbManager.CentralRepoHashDb){ + HashDbManager.CentralRepoHashDb centralRepoDb = (HashDbManager.CentralRepoHashDb)db; + this.hashSetName = centralRepoDb.getHashSetName(); + this.version = centralRepoDb.getVersion(); + this.knownFilesType = centralRepoDb.getKnownFilesType(); + this.searchDuringIngest = centralRepoDb.getSearchDuringIngest(); + this.sendIngestMessages = centralRepoDb.getSendIngestMessages(); this.path = ""; - this.centralRepoIndex = -1; + this.centralRepoIndex = centralRepoDb.getCentralRepoIndex(); this.dbType = DatabaseType.CENTRAL_REPOSITORY; - } + } //else { + // throw new TskCoreException("Unknown hash database type"); + //} } /** diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.form b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.form index c089bea77b..b472445216 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.form +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.form @@ -138,14 +138,17 @@ - - - - + + + + + + + @@ -222,6 +225,8 @@ + + @@ -582,6 +587,16 @@ + + + + + + + + + + diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java index d18fe9e0ad..745e8e9ee4 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java @@ -47,6 +47,7 @@ import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb.KnownFilesType; import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; +import org.sleuthkit.autopsy.centralrepository.optionspanel.ImportHashDatabaseDialog; /** * Instances of this class provide a comprehensive UI for managing the hash sets @@ -530,6 +531,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan indexPathLabelLabel = new javax.swing.JLabel(); indexPathLabel = new javax.swing.JLabel(); addHashesToDatabaseButton = new javax.swing.JButton(); + jButton1 = new javax.swing.JButton(); jLabel2.setFont(jLabel2.getFont().deriveFont(jLabel2.getFont().getStyle() & ~java.awt.Font.BOLD, 11)); org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(HashLookupSettingsPanel.class, "HashLookupSettingsPanel.jLabel2.text")); // NOI18N @@ -668,6 +670,13 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan } }); + org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(HashLookupSettingsPanel.class, "HashLookupSettingsPanel.jButton1.text")); // NOI18N + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( @@ -713,12 +722,14 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan .addGroup(jPanel1Layout.createSequentialGroup() .addGap(70, 70, 70) .addComponent(informationSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(jPanel1Layout.createSequentialGroup() - .addGap(10, 10, 10) - .addComponent(ingestWarningLabel)) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(25, 25, 25) - .addComponent(sendIngestMessagesCheckBox))) + .addComponent(sendIngestMessagesCheckBox)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addGap(10, 10, 10) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(ingestWarningLabel) + .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGap(50, 50, 50)))) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -776,6 +787,8 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan .addComponent(sendIngestMessagesCheckBox) .addGap(18, 18, 18) .addComponent(ingestWarningLabel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jButton1) .addGap(0, 0, Short.MAX_VALUE)) .addComponent(jScrollPane1)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) @@ -900,6 +913,15 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan } }//GEN-LAST:event_hashSetTableKeyPressed + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + HashDatabase hashDb = new ImportHashDatabaseDialog().getHashDatabase(); + if (null != hashDb) { + hashSetTableModel.refreshModel(); + ((HashSetTable) hashSetTable).selectRowByDatabase(hashDb); + firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); + } + }//GEN-LAST:event_jButton1ActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton addHashesToDatabaseButton; private javax.swing.JButton createDatabaseButton; @@ -918,6 +940,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan private javax.swing.JLabel informationLabel; private javax.swing.JSeparator informationSeparator; private javax.swing.JLabel ingestWarningLabel; + private javax.swing.JButton jButton1; private javax.swing.JButton jButton3; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel4; From e733d20dd910fd6dade9e3eda6306ae8100da3f2 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Tue, 17 Oct 2017 14:00:57 -0400 Subject: [PATCH 08/41] Work on importing central repo dbs --- .../datamodel/AbstractSqlEamDb.java | 102 ++++++++++ .../centralrepository/datamodel/EamDb.java | 25 +++ .../datamodel/SqliteEamDb.java | 32 ++++ .../optionspanel/Bundle.properties | 27 ++- .../optionspanel/GlobalSettingsPanel.java | 4 +- ...m => ImportCentralRepoDatabaseDialog.form} | 174 ++++++++---------- ...a => ImportCentralRepoDatabaseDialog.java} | 166 ++++++++--------- .../modules/hashdatabase/Bundle.properties | 18 ++ .../modules/hashdatabase/HashDbManager.java | 153 +++++++-------- .../hashdatabase/HashLookupSettings.java | 12 ++ .../hashdatabase/HashLookupSettingsPanel.java | 132 +++++++------ .../modules/hashdatabase/ModalNoButtons.java | 13 +- 12 files changed, 511 insertions(+), 347 deletions(-) rename Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/{ImportHashDatabaseDialog.form => ImportCentralRepoDatabaseDialog.form} (62%) rename Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/{ImportHashDatabaseDialog.java => ImportCentralRepoDatabaseDialog.java} (76%) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java index 9677eeec9d..bceb4c4cd7 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java @@ -1246,6 +1246,77 @@ public abstract class AbstractSqlEamDb implements EamDb { return caseNames.stream().collect(Collectors.toList()); } + /** + * Remove a reference set and all hashes contained in it. + * @param centralRepoIndex + * @throws EamDbException + */ + @Override + public void deleteReferenceSet(int centralRepoIndex) throws EamDbException{ + deleteReferenceSetFiles(centralRepoIndex); + deleteReferenceSetEntry(centralRepoIndex); + } + + private void deleteReferenceSetEntry(int centralRepoIndex) throws EamDbException{ + Connection conn = connect(); + + PreparedStatement preparedStatement = null; + String sql = "DELETE FROM reference_sets WHERE id=?"; + + try { + preparedStatement = conn.prepareStatement(sql); + preparedStatement.setInt(1, centralRepoIndex); + preparedStatement.executeUpdate(); + } catch (SQLException ex) { + throw new EamDbException("Error deleting reference set", ex); // NON-NLS + } finally { + EamDbUtil.closePreparedStatement(preparedStatement); + EamDbUtil.closeConnection(conn); + } + } + + + private void deleteReferenceSetFiles(int centralRepoIndex) throws EamDbException{ + Connection conn = connect(); + + PreparedStatement preparedStatement = null; + String sql = "DELETE FROM %s WHERE reference_set_id=?"; + + String fileTableName = EamDbUtil.correlationTypeToReferenceTableName(getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID)); + + try { + preparedStatement = conn.prepareStatement(String.format(sql, fileTableName)); + preparedStatement.setInt(1, centralRepoIndex); + preparedStatement.executeUpdate(); + } catch (SQLException ex) { + throw new EamDbException("Error deleting files from reference set", ex); // NON-NLS + } finally { + EamDbUtil.closePreparedStatement(preparedStatement); + EamDbUtil.closeConnection(conn); + } + } + + /** + * Check whether the given reference set exists in the central repository. + * @param centralRepoIndex + * @param hashSetName + * @param version + * @return + */ + @Override + public boolean referenceSetIsValid(int centralRepoIndex, String hashSetName, String version) throws EamDbException{ + System.out.println("###\nChecking if " + centralRepoIndex + " : " + hashSetName + " " + version + " is valid"); + EamGlobalSet refSet = this.getReferenceSetByID(centralRepoIndex); + if(refSet == null){ + System.out.println(" Not valid - no matching index"); + return false; + } + + boolean res = refSet.getSetName().equals(hashSetName) && refSet.getVersion().equals(version); + System.out.println(" res: " + res + " (" + refSet.getSetName() + ", " + refSet.getVersion() + ")"); + return(refSet.getSetName().equals(hashSetName) && refSet.getVersion().equals(version)); + } + /** * Check if the given hash is in a specific reference set * @param hash @@ -1552,6 +1623,37 @@ public abstract class AbstractSqlEamDb implements EamDb { EamDbUtil.closeConnection(conn); } } + + /** + * Check whether a reference set with the given name/version is in the central repo + * @param hashSetName + * @param version + * @return + * @throws EamDbException + */ + @Override + public boolean referenceSetExists(String hashSetName, String version) throws EamDbException{ + Connection conn = connect(); + + PreparedStatement preparedStatement1 = null; + ResultSet resultSet = null; + String sql1 = "SELECT * FROM reference_sets WHERE set_name=? AND version=?"; + + try { + preparedStatement1 = conn.prepareStatement(sql1); + preparedStatement1.setString(1, hashSetName); + preparedStatement1.setString(2, version); + resultSet = preparedStatement1.executeQuery(); + return (resultSet.next()); + + } catch (SQLException ex) { + throw new EamDbException("Error getting reference instances by type and value.", ex); // NON-NLS + } finally { + EamDbUtil.closePreparedStatement(preparedStatement1); + EamDbUtil.closeResultSet(resultSet); + EamDbUtil.closeConnection(conn); + } + } /** * Insert the bulk collection of Reference Type Instances diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java index 302c32f1c4..4ad2033dbf 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java @@ -354,6 +354,31 @@ public interface EamDb { */ List getListCasesHavingArtifactInstancesKnownBad(CorrelationAttribute.Type aType, String value) throws EamDbException; + /** + * Remove a reference set and all hashes contained in it. + * @param centralRepoIndex + * @throws EamDbException + */ + public void deleteReferenceSet(int centralRepoIndex) throws EamDbException; + + /** + * Check whether the given reference set exists in the central repository. + * @param centralRepoIndex + * @param hashSetName + * @param version + * @return + */ + public boolean referenceSetIsValid(int centralRepoIndex, String hashSetName, String version) throws EamDbException; + + /** + * Check whether a reference set with the given name/version is in the central repo + * @param hashSetName + * @param version + * @return + * @throws EamDbException + */ + public boolean referenceSetExists(String hashSetName, String version) throws EamDbException; + /** * Check if the given hash is in a specific reference set * @param hash diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java index 140a708c48..ede91676f8 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java @@ -635,6 +635,21 @@ public class SqliteEamDb extends AbstractSqlEamDb { } } + /** + * Remove a reference set and all hashes contained in it. + * @param centralRepoIndex + * @throws EamDbException + */ + @Override + public void deleteReferenceSet(int centralRepoIndex) throws EamDbException{ + try{ + acquireExclusiveLock(); + super.deleteReferenceSet(centralRepoIndex); + } finally { + releaseExclusiveLock(); + } + } + /** * Check if the given hash is in a specific reference set * @param hash @@ -651,6 +666,23 @@ public class SqliteEamDb extends AbstractSqlEamDb { } } + /** + * Check whether a reference set with the given name/version is in the central repo + * @param hashSetName + * @param version + * @return + * @throws EamDbException + */ + @Override + public boolean referenceSetExists(String hashSetName, String version) throws EamDbException { + try{ + acquireSharedLock(); + return super.referenceSetExists(hashSetName, version); + } finally { + releaseSharedLock(); + } + } + /** * Is the artifact known as bad according to the reference entries? * diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties index 32a8938df1..79b852ab15 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties @@ -19,17 +19,6 @@ EamSqliteSettingsDialog.tfDatabasePath.text= EamSqliteSettingsDialog.lbDatabasePath.text=Database Path : ImportHashDatabaseDialog.tfDatabaseName.tooltip=Name for this database ImportHashDatabaseDialog.tfDatabaseVersion.tooltip.text=Database Version Number -ImportHashDatabaseDialog.knownRadioButton.text=Known (NSRL or other) -ImportHashDatabaseDialog.openButton.text=Open... -ImportHashDatabaseDialog.cancelButton.text=Cancel -ImportHashDatabaseDialog.lbDatabaseVersion.text=Database Version: -ImportHashDatabaseDialog.okButton.text=OK -ImportHashDatabaseDialog.lbDatabaseName.text=Database Name: -ImportHashDatabaseDialog.lbSourceOrganization.text=Source Organization: -ImportHashDatabaseDialog.lbDatabaseAttribution.text=Database Attribution: -ImportHashDatabaseDialog.lbDatabaseType.text=Type of database: -ImportHashDatabaseDialog.knownBadRadioButton.text=Notable -ImportHashDatabaseDialog.bnNewOrganization.text=Add New Organization ImportHashDatabaseDialog.tfDatabaseName.tooltip=Name for this database ImportHashDatabaseDialog.tfDatabaseVersion.tooltip.text=Database Version Number GlobalSettingsPanel.bnImportDatabase.actionCommand= @@ -71,8 +60,18 @@ ManageCorrelationPropertiesDialog.lbWarningMsg.text=Warning Message ManageCorrelationPropertiesDialog.cancelButton.text=Cancel ManageCorrelationPropertiesDialog.okButton.text=OK GlobalSettingsPanel.bnManageProperties.text=Manage Correlation Properties -ImportHashDatabaseDialog.lbInstructions.text=Choose an .idx file to import into the central repository. -ImportHashDatabaseDialog.lbFilePath.text=File Path: -ImportHashDatabaseDialog.tfFilePath.text= +ImportHashDatabaseDialog.lbFilePath.text=Database Path: EamDbSettingsDialog.lbDatabaseDesc.text=Database File: EamDbSettingsDialog.lbFullDbPath.text=jLabel2 +ImportCentralRepoDatabaseDialog.cancelButton.text=Cancel +ImportCentralRepoDatabaseDialog.lbDatabaseVersion.text=Hash Set Version: +ImportCentralRepoDatabaseDialog.okButton.text=OK +ImportCentralRepoDatabaseDialog.lbDatabaseName.text=Hash Set Name: +ImportCentralRepoDatabaseDialog.lbSourceOrganization.text=Source Organization: +ImportCentralRepoDatabaseDialog.lbDatabaseType.text=Type of database: +ImportCentralRepoDatabaseDialog.knownBadRadioButton.text=Notable +ImportCentralRepoDatabaseDialog.bnNewOrganization.text=Add New Organization +ImportCentralRepoDatabaseDialog.knownRadioButton.text=Known (NSRL or other) +ImportCentralRepoDatabaseDialog.openButton.text=Open... +ImportCentralRepoDatabaseDialog.tfFilePath.text= +ImportCentralRepoDatabaseDialog.cbInboxMessages.text=Send ingest inbox messages for each hit diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java index 77b9a63288..06d8210d8d 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java @@ -333,8 +333,8 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i private void bnImportDatabaseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnImportDatabaseActionPerformed store(); - ImportHashDatabaseDialog dialog = new ImportHashDatabaseDialog(); - firePropertyChange(OptionsPanelController.PROP_VALID, null, null); + //ImportHashDatabaseDialog dialog = new ImportHashDatabaseDialog(); + //firePropertyChange(OptionsPanelController.PROP_VALID, null, null); }//GEN-LAST:event_bnImportDatabaseActionPerformed private void bnManageTagsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnManageTagsActionPerformed diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportHashDatabaseDialog.form b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportCentralRepoDatabaseDialog.form similarity index 62% rename from Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportHashDatabaseDialog.form rename to Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportCentralRepoDatabaseDialog.form index 0865173651..cb51bb9dd8 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportHashDatabaseDialog.form +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportCentralRepoDatabaseDialog.form @@ -30,47 +30,28 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - @@ -82,11 +63,22 @@ - + + + + + + + + + + + + + - @@ -95,56 +87,44 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -153,7 +133,7 @@ - + @@ -163,7 +143,7 @@ - + @@ -173,14 +153,14 @@ - + - + @@ -193,7 +173,7 @@ - + @@ -204,14 +184,14 @@ - + - + @@ -222,31 +202,24 @@ - - - - - - - - + - + - + @@ -285,7 +258,7 @@ - + @@ -302,13 +275,10 @@ - + - - - - + diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportHashDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportCentralRepoDatabaseDialog.java similarity index 76% rename from Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportHashDatabaseDialog.java rename to Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportCentralRepoDatabaseDialog.java index 2bc81226dc..c47b598e68 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportHashDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportCentralRepoDatabaseDialog.java @@ -68,8 +68,8 @@ import org.sleuthkit.datamodel.TskData; * add it to the set of hash databases used to classify files as unknown, known, * or notable. */ -final public class ImportHashDatabaseDialog extends javax.swing.JDialog { - private static final Logger LOGGER = Logger.getLogger(ImportHashDatabaseDialog.class.getName()); +final public class ImportCentralRepoDatabaseDialog extends javax.swing.JDialog { + private static final Logger LOGGER = Logger.getLogger(ImportCentralRepoDatabaseDialog.class.getName()); private final JFileChooser fileChooser = new JFileChooser(); private final static String LAST_FILE_PATH_KEY = "CentralRepositoryImport_Path"; // NON-NLS @@ -87,7 +87,7 @@ final public class ImportHashDatabaseDialog extends javax.swing.JDialog { * unknown, known, or notable. */ @Messages({"ImportHashDatabaseDialog.importHashDbMsg=Import Hash Database"}) - public ImportHashDatabaseDialog() { + public ImportCentralRepoDatabaseDialog() { super((JFrame) WindowManager.getDefault().getMainWindow(), Bundle.ImportHashDatabaseDialog_importHashDbMsg(), true); // NON-NLS @@ -276,7 +276,6 @@ final public class ImportHashDatabaseDialog extends javax.swing.JDialog { knownBadRadioButton = new javax.swing.JRadioButton(); lbDatabaseType = new javax.swing.JLabel(); lbDatabasePath = new javax.swing.JLabel(); - lbDatabaseAttribution = new javax.swing.JLabel(); lbSourceOrganization = new javax.swing.JLabel(); lbDatabaseName = new javax.swing.JLabel(); lbDatabaseVersion = new javax.swing.JLabel(); @@ -285,27 +284,27 @@ final public class ImportHashDatabaseDialog extends javax.swing.JDialog { tfDatabaseVersion = new javax.swing.JTextField(); bnNewOrganization = new javax.swing.JButton(); lbWarningMsg = new javax.swing.JLabel(); - lbInstructions = new javax.swing.JLabel(); + cbInboxMessages = new javax.swing.JCheckBox(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(ImportHashDatabaseDialog.class, "ImportHashDatabaseDialog.okButton.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.okButton.text")); // NOI18N okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { okButtonActionPerformed(evt); } }); - org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(ImportHashDatabaseDialog.class, "ImportHashDatabaseDialog.cancelButton.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.cancelButton.text")); // NOI18N cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelButtonActionPerformed(evt); } }); - tfFilePath.setText(org.openide.util.NbBundle.getMessage(ImportHashDatabaseDialog.class, "ImportHashDatabaseDialog.tfFilePath.text")); // NOI18N + tfFilePath.setText(org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.tfFilePath.text")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(openButton, org.openide.util.NbBundle.getMessage(ImportHashDatabaseDialog.class, "ImportHashDatabaseDialog.openButton.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(openButton, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.openButton.text")); // NOI18N openButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { openButtonActionPerformed(evt); @@ -313,23 +312,21 @@ final public class ImportHashDatabaseDialog extends javax.swing.JDialog { }); buttonGroup1.add(knownRadioButton); - org.openide.awt.Mnemonics.setLocalizedText(knownRadioButton, org.openide.util.NbBundle.getMessage(ImportHashDatabaseDialog.class, "ImportHashDatabaseDialog.knownRadioButton.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(knownRadioButton, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.knownRadioButton.text")); // NOI18N buttonGroup1.add(knownBadRadioButton); knownBadRadioButton.setSelected(true); - org.openide.awt.Mnemonics.setLocalizedText(knownBadRadioButton, org.openide.util.NbBundle.getMessage(ImportHashDatabaseDialog.class, "ImportHashDatabaseDialog.knownBadRadioButton.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(knownBadRadioButton, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.knownBadRadioButton.text")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseType, org.openide.util.NbBundle.getMessage(ImportHashDatabaseDialog.class, "ImportHashDatabaseDialog.lbDatabaseType.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseType, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.lbDatabaseType.text")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(lbDatabasePath, org.openide.util.NbBundle.getMessage(ImportHashDatabaseDialog.class, "ImportHashDatabaseDialog.lbFilePath.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(lbDatabasePath, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportHashDatabaseDialog.lbFilePath.text")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseAttribution, org.openide.util.NbBundle.getMessage(ImportHashDatabaseDialog.class, "ImportHashDatabaseDialog.lbDatabaseAttribution.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(lbSourceOrganization, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.lbSourceOrganization.text")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(lbSourceOrganization, org.openide.util.NbBundle.getMessage(ImportHashDatabaseDialog.class, "ImportHashDatabaseDialog.lbSourceOrganization.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseName, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.lbDatabaseName.text")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseName, org.openide.util.NbBundle.getMessage(ImportHashDatabaseDialog.class, "ImportHashDatabaseDialog.lbDatabaseName.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseVersion, org.openide.util.NbBundle.getMessage(ImportHashDatabaseDialog.class, "ImportHashDatabaseDialog.lbDatabaseVersion.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseVersion, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.lbDatabaseVersion.text")); // NOI18N comboboxSourceOrganization.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); comboboxSourceOrganization.addActionListener(new java.awt.event.ActionListener() { @@ -338,11 +335,11 @@ final public class ImportHashDatabaseDialog extends javax.swing.JDialog { } }); - tfDatabaseName.setToolTipText(org.openide.util.NbBundle.getMessage(ImportHashDatabaseDialog.class, "ImportHashDatabaseDialog.tfDatabaseName.tooltip")); // NOI18N + tfDatabaseName.setToolTipText(org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportHashDatabaseDialog.tfDatabaseName.tooltip")); // NOI18N - tfDatabaseVersion.setToolTipText(org.openide.util.NbBundle.getMessage(ImportHashDatabaseDialog.class, "ImportHashDatabaseDialog.tfDatabaseVersion.tooltip.text")); // NOI18N + tfDatabaseVersion.setToolTipText(org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportHashDatabaseDialog.tfDatabaseVersion.tooltip.text")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(bnNewOrganization, org.openide.util.NbBundle.getMessage(ImportHashDatabaseDialog.class, "ImportHashDatabaseDialog.bnNewOrganization.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(bnNewOrganization, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.bnNewOrganization.text")); // NOI18N bnNewOrganization.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { bnNewOrganizationActionPerformed(evt); @@ -352,8 +349,7 @@ final public class ImportHashDatabaseDialog extends javax.swing.JDialog { lbWarningMsg.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N lbWarningMsg.setForeground(new java.awt.Color(255, 0, 0)); - lbInstructions.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(lbInstructions, org.openide.util.NbBundle.getMessage(ImportHashDatabaseDialog.class, "ImportHashDatabaseDialog.lbInstructions.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(cbInboxMessages, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.cbInboxMessages.text")); // NOI18N javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); @@ -362,38 +358,24 @@ final public class ImportHashDatabaseDialog extends javax.swing.JDialog { .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(lbInstructions, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addComponent(okButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cancelButton)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addComponent(lbDatabasePath) + .addComponent(lbWarningMsg, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(lbDatabasePath) + .addComponent(lbDatabaseName)) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(tfFilePath, javax.swing.GroupLayout.PREFERRED_SIZE, 277, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(tfFilePath)) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addGap(23, 23, 23) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(lbDatabaseVersion) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(tfDatabaseVersion, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(0, 0, Short.MAX_VALUE)) - .addGroup(layout.createSequentialGroup() - .addComponent(lbSourceOrganization) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(bnNewOrganization)) - .addGroup(layout.createSequentialGroup() - .addComponent(lbDatabaseName) - .addGap(12, 12, 12) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(comboboxSourceOrganization, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(tfDatabaseName)))))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(openButton)) + .addComponent(openButton)) + .addComponent(tfDatabaseName))) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(lbDatabaseType) @@ -402,9 +384,18 @@ final public class ImportHashDatabaseDialog extends javax.swing.JDialog { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(knownRadioButton) .addComponent(knownBadRadioButton))) - .addComponent(lbDatabaseAttribution)) - .addGap(0, 0, Short.MAX_VALUE)) - .addComponent(lbWarningMsg, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addComponent(lbDatabaseVersion) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(tfDatabaseVersion, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addComponent(lbSourceOrganization) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(comboboxSourceOrganization, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(bnNewOrganization)) + .addComponent(cbInboxMessages)) + .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) ); @@ -414,46 +405,38 @@ final public class ImportHashDatabaseDialog extends javax.swing.JDialog { layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() - .addComponent(lbInstructions, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(openButton) .addComponent(tfFilePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lbDatabasePath)) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(lbDatabaseType) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(knownRadioButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(knownBadRadioButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(lbDatabaseAttribution) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(bnNewOrganization) - .addGroup(layout.createSequentialGroup() - .addGap(3, 3, 3) - .addComponent(lbSourceOrganization, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(comboboxSourceOrganization, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(tfDatabaseName) - .addComponent(lbDatabaseName, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(lbDatabaseVersion, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(tfDatabaseVersion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(lbWarningMsg, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(44, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(okButton) - .addComponent(cancelButton)) - .addContainerGap()))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(lbDatabaseName, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(tfDatabaseName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(lbDatabaseVersion, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(tfDatabaseVersion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(lbSourceOrganization, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(comboboxSourceOrganization, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(bnNewOrganization)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE) + .addComponent(lbDatabaseType) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(knownRadioButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(knownBadRadioButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cbInboxMessages) + .addGap(117, 117, 117) + .addComponent(lbWarningMsg, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(okButton) + .addComponent(cancelButton)) + .addContainerGap()) ); pack(); @@ -470,7 +453,7 @@ final public class ImportHashDatabaseDialog extends javax.swing.JDialog { } ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY, databaseFile.getParent()); } catch (IOException ex) { - Logger.getLogger(ImportHashDatabaseDialog.class.getName()).log(Level.SEVERE, "Failed to get path of selected database", ex); // NON-NLS + Logger.getLogger(ImportCentralRepoDatabaseDialog.class.getName()).log(Level.SEVERE, "Failed to get path of selected database", ex); // NON-NLS lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_failedToGetDbPathMsg()); } } @@ -627,7 +610,7 @@ final public class ImportHashDatabaseDialog extends javax.swing.JDialog { try { get(); } catch (InterruptedException | ExecutionException ex) { - Logger.getLogger(ImportHashDatabaseDialog.class.getName()).log(Level.SEVERE, Bundle.ImportHashDatabaseDialog_ImportHashDatabaseWorker_error(), ex); + Logger.getLogger(ImportCentralRepoDatabaseDialog.class.getName()).log(Level.SEVERE, Bundle.ImportHashDatabaseDialog_ImportHashDatabaseWorker_error(), ex); MessageNotifyUtil.Notify.show(Bundle.ImportHashDatabaseDialog_ImportHashDatabaseWorker_error(), ex.getMessage(), MessageNotifyUtil.MessageType.ERROR); @@ -689,15 +672,14 @@ final public class ImportHashDatabaseDialog extends javax.swing.JDialog { private javax.swing.JButton bnNewOrganization; private javax.swing.ButtonGroup buttonGroup1; private javax.swing.JButton cancelButton; + private javax.swing.JCheckBox cbInboxMessages; private javax.swing.JComboBox comboboxSourceOrganization; private javax.swing.JRadioButton knownBadRadioButton; private javax.swing.JRadioButton knownRadioButton; - private javax.swing.JLabel lbDatabaseAttribution; private javax.swing.JLabel lbDatabaseName; private javax.swing.JLabel lbDatabasePath; private javax.swing.JLabel lbDatabaseType; private javax.swing.JLabel lbDatabaseVersion; - private javax.swing.JLabel lbInstructions; private javax.swing.JLabel lbSourceOrganization; private javax.swing.JLabel lbWarningMsg; private javax.swing.JButton okButton; diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties index 30f795fb50..5c22510eda 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties @@ -225,3 +225,21 @@ HashLookupSettingsPanel.sendIngestMessagesCheckBox1.text=Send ingest inbox messa HashLookupSettingsPanel.importDatabaseButton1.toolTipText= HashLookupSettingsPanel.typeLabel1.text=Type: HashLookupSettingsPanel.jButton1.text=Import CR Hashset +ImportCentralRepoDatabaseDialog.cbInboxMessages.text=Send ingest inbox message for each hit +ImportCentralRepoDatabaseDialog.cancelButton.text=Cancel +ImportCentralRepoDatabaseDialog.lbDatabaseVersion.text=Hash Set Version: +ImportCentralRepoDatabaseDialog.okButton.text=OK +ImportCentralRepoDatabaseDialog.lbDatabaseName.text=Hash Set Name: +ImportCentralRepoDatabaseDialog.lbSourceOrganization.text=Source Organization: +ImportCentralRepoDatabaseDialog.lbDatabaseType.text=Type of database: +ImportCentralRepoDatabaseDialog.knownBadRadioButton.text=Notable +ImportCentralRepoDatabaseDialog.bnNewOrganization.text=Add New Organization +ImportCentralRepoDatabaseDialog.knownRadioButton.text=Known (NSRL or other) +ImportCentralRepoDatabaseDialog.openButton.text=Open... +ImportCentralRepoDatabaseDialog.tfFilePath.text= +ImportHashDatabaseDialog.lbFilePath.text=Database Path: +ImportHashDatabaseDialog.tfDatabaseName.tooltip=Name for this database +ImportHashDatabaseDialog.tfDatabaseVersion.tooltip.text=Database Version Number +ImportHashDatabaseDialog.tfDatabaseName.tooltip=Name for this database +ImportHashDatabaseDialog.tfDatabaseVersion.tooltip.text=Database Version Number + diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index d6fd4d522c..2796eaa9b2 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -47,7 +47,7 @@ import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttribute; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException; import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalFileInstance; -import org.sleuthkit.autopsy.centralrepository.optionspanel.ImportHashDatabaseDialog; +import org.sleuthkit.autopsy.centralrepository.optionspanel.ImportCentralRepoDatabaseDialog; import org.sleuthkit.autopsy.core.RuntimeProperties; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; @@ -299,14 +299,51 @@ public class HashDbManager implements PropertyChangeListener { return hashDb; } + public CentralRepoHashDb addExistingCentralRepoHashSet(String hashSetName, String version, int centralRepoIndex, + boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws TskCoreException{ + + if(! EamDb.isEnabled()){ + throw new TskCoreException("Could not load central repository database " + hashSetName + " - central repository is not enabled"); + } + + CentralRepoHashDb db = new CentralRepoHashDb(hashSetName, version, centralRepoIndex, searchDuringIngest, + sendIngestMessages, knownFilesType); + + if(! db.isValid()){ + throw new TskCoreException("Error finding database " + hashSetName + " in central repository"); + } + + // Add the hash database to the collection + hashSets.add(db); + + // Let any external listeners know that there's a new set + try { + changeSupport.firePropertyChange(SetEvt.DB_ADDED.toString(), null, hashSetName); + } catch (Exception e) { + logger.log(Level.SEVERE, "HashDbManager listener threw exception", e); //NON-NLS + MessageNotifyUtil.Notify.show( + NbBundle.getMessage(this.getClass(), "HashDbManager.moduleErr"), + NbBundle.getMessage(this.getClass(), "HashDbManager.moduleErrorListeningToUpdatesMsg"), + MessageNotifyUtil.MessageType.ERROR); + } + return db; + + } + public CentralRepoHashDb importCentralRepoHashSet(String hashSetName, String version, int orgId, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType, String importFile) throws TskCoreException { + int crIndex; + try{ // Create an empty hashset in the central repository - int crIndex = EamDb.getInstance().newReferenceSet(orgId, hashSetName, version); - + crIndex = EamDb.getInstance().newReferenceSet(orgId, hashSetName, version); + } catch (EamDbException ex){ + throw new TskCoreException(ex.getLocalizedMessage()); + } + + try{ // Import the hashes TskData.FileKnown knownStatus = TskData.FileKnown.UNKNOWN; @@ -380,7 +417,7 @@ public class HashDbManager implements PropertyChangeListener { } } - synchronized void indexHashDatabase(HashDatabase hashDb) { + synchronized void indexHashDatabase(HashDb hashDb) { hashDb.addPropertyChangeListener(this); HashDbIndexer creator = new HashDbIndexer(hashDb); creator.execute(); @@ -416,7 +453,7 @@ public class HashDbManager implements PropertyChangeListener { this.save(); } - public synchronized void removeHashDatabaseNoSave(HashDatabase hashDb) throws HashDbManagerException { + public synchronized void removeHashDatabaseNoSave(HashDatabase hashDatabase) throws HashDbManagerException { // Don't remove a database if ingest is running boolean ingestIsRunning = IngestManager.getInstance().isIngestRunning(); if (ingestIsRunning) { @@ -426,32 +463,36 @@ public class HashDbManager implements PropertyChangeListener { // and remove its hash set name from the hash set used to ensure unique // hash set names are used, before undertaking These operations will succeed and constitute // a mostly effective removal, even if the subsequent operations fail. - String hashSetName = hashDb.getHashSetName(); + String hashSetName = hashDatabase.getHashSetName(); hashSetNames.remove(hashSetName); - hashSets.remove(hashDb); + hashSets.remove(hashDatabase); // Now undertake the operations that could throw. - try { - if(hashDb.hasIndex()){ - hashSetPaths.remove(hashDb.getIndexPath()); + // Indexing is only relevanet for file type hashsets + if(hashDatabase instanceof HashDb){ + HashDb hashDb = (HashDb)hashDatabase; + try { + if(hashDb.hasIndex()){ + hashSetPaths.remove(hashDb.getIndexPath()); + } + } catch (TskCoreException ex) { + Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error getting index path of " + hashDb.getHashSetName() + " hash database when removing the database", ex); //NON-NLS + } + + try { + if (!hashDb.hasIndexOnly()) { + hashSetPaths.remove(hashDb.getDatabasePath()); + } + } catch (TskCoreException ex) { + Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error getting database path of " + hashDb.getHashSetName() + " hash database when removing the database", ex); //NON-NLS } - } catch (TskCoreException ex) { - Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error getting index path of " + hashDb.getHashSetName() + " hash database when removing the database", ex); //NON-NLS - } - - try { - if (!hashDb.hasIndexOnly()) { - hashSetPaths.remove(hashDb.getDatabasePath()); - } - } catch (TskCoreException ex) { - Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error getting database path of " + hashDb.getHashSetName() + " hash database when removing the database", ex); //NON-NLS } try { - hashDb.close(); + hashDatabase.close(); } catch (TskCoreException ex) { - Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error closing " + hashDb.getHashSetName() + " hash database when removing the database", ex); //NON-NLS + Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error closing " + hashDatabase.getHashSetName() + " hash database when removing the database", ex); //NON-NLS } // Let any external listeners know that a set has been deleted @@ -468,6 +509,10 @@ public class HashDbManager implements PropertyChangeListener { void save() throws HashDbManagerException { try { + System.out.println("######\nHashDbManager: Saving Hash Lookup settings"); + for(HashDatabase db: this.hashSets){ + System.out.println(" " + db.getHashSetName() + " " + db.getDatabaseType().name()); + } if (!HashLookupSettings.writeSettings(new HashLookupSettings(HashLookupSettings.convertHashSetList(this.hashSets)))) { throw new HashDbManagerException(NbBundle.getMessage(this.getClass(), "HashDbManager.saveErrorExceptionMsg")); } @@ -658,7 +703,8 @@ public class HashDbManager implements PropertyChangeListener { allDatabasesLoadedCorrectly = false; } } else { - Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "CR not implemented!"); //NON-NLS + addExistingCentralRepoHashSet(hashDbInfo.getHashSetName(), hashDbInfo.getVersion(), hashDbInfo.getCentralRepoIndex(), + hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), hashDbInfo.getKnownFilesType()); } } catch (TskCoreException ex) { Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error opening hash database", ex); //NON-NLS @@ -783,18 +829,6 @@ public class HashDbManager implements PropertyChangeListener { public HashHitInfo lookupMD5(Content content) throws TskCoreException; - public String getIndexPath() throws TskCoreException; - - public boolean hasIndex() throws TskCoreException; - - public boolean hasIndexOnly() throws TskCoreException; - - public boolean isIndexing(); - - public void setIndexing(boolean indexing); - - public boolean canBeReIndexed() throws TskCoreException; - /** * Returns whether this database can be enabled. * For file type, this is the same as checking that it has an index @@ -907,7 +941,6 @@ public class HashDbManager implements PropertyChangeListener { return SleuthkitJNI.getHashDatabasePath(handle); } - @Override public void setIndexing(boolean indexing){ this.indexing = indexing; } @@ -917,7 +950,6 @@ public class HashDbManager implements PropertyChangeListener { return DatabaseType.FILE; } - @Override public String getIndexPath() throws TskCoreException { return SleuthkitJNI.getHashDatabaseIndexPath(handle); } @@ -1062,22 +1094,18 @@ public class HashDbManager implements PropertyChangeListener { return hasIndex(); } - @Override public boolean hasIndex() throws TskCoreException { return SleuthkitJNI.hashDatabaseHasLookupIndex(handle); } - @Override public boolean hasIndexOnly() throws TskCoreException { return SleuthkitJNI.hashDatabaseIsIndexOnly(handle); } - @Override public boolean canBeReIndexed() throws TskCoreException { return SleuthkitJNI.hashDatabaseCanBeReindexed(handle); } - @Override public boolean isIndexing() { return indexing; } @@ -1196,17 +1224,11 @@ public class HashDbManager implements PropertyChangeListener { return ""; } - @Override - public void setIndexing(boolean indexing){ - - } - @Override public DatabaseType getDatabaseType(){ - return DatabaseType.FILE; + return DatabaseType.CENTRAL_REPOSITORY; } - @Override public String getIndexPath() throws TskCoreException { return ""; } @@ -1348,33 +1370,20 @@ public class HashDbManager implements PropertyChangeListener { /** * Returns whether this database can be enabled. - * For file type, this is the same as checking that it has an index + * * @return true if is valid, false otherwise * @throws TskCoreException */ @Override public boolean isValid() throws TskCoreException { - return true; - } - - @Override - public boolean hasIndex() throws TskCoreException { - return false; - } - - @Override - public boolean hasIndexOnly() throws TskCoreException { - return false; - } - - @Override - public boolean canBeReIndexed() throws TskCoreException { - return false; - } - - @Override - public boolean isIndexing() { - return false; + if(! EamDb.isEnabled()) { + return false; + } + try{ + return EamDb.getInstance().referenceSetIsValid(this.centralRepoIndex, this.hashSetName, this.version); + } catch (EamDbException ex){ + throw new TskCoreException(ex.getLocalizedMessage()); + } } @Override @@ -1431,9 +1440,9 @@ public class HashDbManager implements PropertyChangeListener { private class HashDbIndexer extends SwingWorker { private ProgressHandle progress = null; - private HashDatabase hashDb = null; + private HashDb hashDb = null; - HashDbIndexer(HashDatabase hashDb) { + HashDbIndexer(HashDb hashDb) { this.hashDb = hashDb; } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java index 21c689cc70..00bac6cf4e 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java @@ -124,6 +124,10 @@ final class HashLookupSettings implements Serializable { try { try (NbObjectInputStream in = new NbObjectInputStream(new FileInputStream(SERIALIZATION_FILE_PATH))) { HashLookupSettings filesSetsSettings = (HashLookupSettings) in.readObject(); + System.out.println("#####\nHashLookupSettings"); + for(HashDbInfo dbInfo:filesSetsSettings.hashDbInfoList){ + System.out.println(" " + dbInfo.getHashSetName() + " File type: " + dbInfo.isFileDatabaseType()); + } return filesSetsSettings; } } catch (IOException | ClassNotFoundException ex) { @@ -376,6 +380,14 @@ final class HashLookupSettings implements Serializable { String getHashSetName() { return hashSetName; } + + /** + * Get the version for the hash set + * @return version + */ + String getVersion(){ + return version; + } /** * Gets the known files type setting. diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java index 745e8e9ee4..36aa535567 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java @@ -38,6 +38,7 @@ import javax.swing.table.TableCellRenderer; import org.netbeans.spi.options.OptionsPanelController; import org.openide.util.NbBundle; import org.openide.util.NbBundle.Messages; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; import org.sleuthkit.autopsy.corecomponents.OptionsPanel; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.events.AutopsyEvent; @@ -47,7 +48,6 @@ import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb.KnownFilesType; import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; -import org.sleuthkit.autopsy.centralrepository.optionspanel.ImportHashDatabaseDialog; /** * Instances of this class provide a comprehensive UI for managing the hash sets @@ -158,13 +158,6 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan hashDbLocationLabel.setText(ERROR_GETTING_PATH_TEXT); } - try { - indexPathLabel.setText(shortenPath(db.getIndexPath())); - } catch (TskCoreException ex) { - Logger.getLogger(HashLookupSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting index path of " + db.getHashSetName() + " hash database", ex); //NON-NLS - indexPathLabel.setText(ERROR_GETTING_PATH_TEXT); - } - try { addHashesToDatabaseButton.setEnabled(!ingestIsRunning && db.isUpdateable()); } catch (TskCoreException ex) { @@ -172,45 +165,55 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan addHashesToDatabaseButton.setEnabled(false); } - // Update indexing components. - try { - if (db.isIndexing()) { - indexButton.setText( - NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.indexButtonText.indexing")); - hashDbIndexStatusLabel.setText( - NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.indexStatusText.indexGen")); - hashDbIndexStatusLabel.setForeground(Color.black); - indexButton.setEnabled(false); - } else if (db.hasIndex()) { - if (db.hasIndexOnly()) { - hashDbIndexStatusLabel.setText( - NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.indexStatusText.indexOnly")); - } else { - hashDbIndexStatusLabel.setText( - NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.indexStatusText.indexed")); - } - hashDbIndexStatusLabel.setForeground(Color.black); - if (db.canBeReIndexed()) { + if(db instanceof HashDb){ + HashDb hashDb = (HashDb)db; + try { + indexPathLabel.setText(shortenPath(hashDb.getIndexPath())); + } catch (TskCoreException ex) { + Logger.getLogger(HashLookupSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting index path of " + db.getHashSetName() + " hash database", ex); //NON-NLS + indexPathLabel.setText(ERROR_GETTING_PATH_TEXT); + } + + // Update indexing components. + try { + if (hashDb.isIndexing()) { indexButton.setText( - NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.indexButtonText.reIndex")); - indexButton.setEnabled(true); - } else { - indexButton.setText(NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.indexButtonText.index")); + NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.indexButtonText.indexing")); + hashDbIndexStatusLabel.setText( + NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.indexStatusText.indexGen")); + hashDbIndexStatusLabel.setForeground(Color.black); indexButton.setEnabled(false); + } else if (hashDb.hasIndex()) { + if (hashDb.hasIndexOnly()) { + hashDbIndexStatusLabel.setText( + NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.indexStatusText.indexOnly")); + } else { + hashDbIndexStatusLabel.setText( + NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.indexStatusText.indexed")); + } + hashDbIndexStatusLabel.setForeground(Color.black); + if (hashDb.canBeReIndexed()) { + indexButton.setText( + NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.indexButtonText.reIndex")); + indexButton.setEnabled(true); + } else { + indexButton.setText(NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.indexButtonText.index")); + indexButton.setEnabled(false); + } + } else { + hashDbIndexStatusLabel.setText( + NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.indexStatusText.noIndex")); + hashDbIndexStatusLabel.setForeground(Color.red); + indexButton.setText(NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.indexButtonText.index")); + indexButton.setEnabled(true); } - } else { - hashDbIndexStatusLabel.setText( - NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.indexStatusText.noIndex")); + } catch (TskCoreException ex) { + Logger.getLogger(HashLookupSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting index state of hash database", ex); //NON-NLS + hashDbIndexStatusLabel.setText(ERROR_GETTING_INDEX_STATUS_TEXT); hashDbIndexStatusLabel.setForeground(Color.red); indexButton.setText(NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.indexButtonText.index")); - indexButton.setEnabled(true); + indexButton.setEnabled(false); } - } catch (TskCoreException ex) { - Logger.getLogger(HashLookupSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting index state of hash database", ex); //NON-NLS - hashDbIndexStatusLabel.setText(ERROR_GETTING_INDEX_STATUS_TEXT); - hashDbIndexStatusLabel.setForeground(Color.red); - indexButton.setText(NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.indexButtonText.index")); - indexButton.setEnabled(false); } // Disable the indexing button if ingest is in progress. @@ -259,14 +262,17 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan "HashLookupSettingsPanel.saveFail.title=Save Fail"}) public void saveSettings() { //Checking for for any unindexed databases - List unindexed = new ArrayList<>(); + List unindexed = new ArrayList<>(); for (HashDatabase hashSet : hashSetManager.getAllHashDatabases()) { - try { - if (!hashSet.hasIndex()) { - unindexed.add(hashSet); + if(hashSet instanceof HashDb){ + HashDb db = (HashDb)hashSet; + try { + if (!db.hasIndex()) { + unindexed.add(db); + } + } catch (TskCoreException ex) { + Logger.getLogger(HashLookupSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting index info for hash database", ex); //NON-NLS } - } catch (TskCoreException ex) { - Logger.getLogger(HashLookupSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting index info for hash database", ex); //NON-NLS } } @@ -308,8 +314,8 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan } @Messages({"# {0} - hash lookup name", "HashLookupSettingsPanel.removeDatabaseFailure.message=Failed to remove hash lookup: {0}"}) - void removeThese(List toRemove) { - for (HashDatabase hashDb : toRemove) { + void removeThese(List toRemove) { + for (HashDb hashDb : toRemove) { try { hashSetManager.removeHashDatabaseNoSave(hashDb); } catch (HashDbManager.HashDbManagerException ex) { @@ -327,7 +333,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan * @param plural Whether or not there are multiple unindexed databases * @param unindexed The list of unindexed databases. Can be of size 1. */ - private void showInvalidIndex(boolean plural, List unindexed) { + private void showInvalidIndex(boolean plural, List unindexed) { String total = ""; String message; for (HashDatabase hdb : unindexed) { @@ -433,7 +439,10 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan private boolean indexExists(int rowIndex) { try { - return hashSets.get(rowIndex).hasIndex(); + if(hashSets.get(rowIndex) instanceof HashDb){ + return ((HashDb)(hashSets.get(rowIndex))).hasIndex(); + } + return false; } catch (TskCoreException ex) { Logger.getLogger(HashSetTableModel.class.getName()).log(Level.SEVERE, "Error getting index info for hash database", ex); //NON-NLS return false; @@ -839,11 +848,13 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan }//GEN-LAST:event_sendIngestMessagesCheckBoxActionPerformed private void indexButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_indexButtonActionPerformed - final HashDatabase hashDb = ((HashSetTable) hashSetTable).getSelection(); - assert hashDb != null; + final HashDatabase hashDatabase = ((HashSetTable) hashSetTable).getSelection(); + assert hashDatabase != null; + assert hashDatabase instanceof HashDb; // Add a listener for the INDEXING_DONE event. This listener will update // the UI. + HashDb hashDb = (HashDb)hashDatabase; hashDb.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { @@ -914,11 +925,16 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan }//GEN-LAST:event_hashSetTableKeyPressed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - HashDatabase hashDb = new ImportHashDatabaseDialog().getHashDatabase(); - if (null != hashDb) { - hashSetTableModel.refreshModel(); - ((HashSetTable) hashSetTable).selectRowByDatabase(hashDb); - firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); + if(EamDb.isEnabled()){ + HashDatabase hashDb = new ImportCentralRepoDatabaseDialog().getHashDatabase(); + if (null != hashDb) { + hashSetTableModel.refreshModel(); + ((HashSetTable) hashSetTable).selectRowByDatabase(hashDb); + firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); + } + } else { + // TEMP + JOptionPane.showMessageDialog(null, "Central repo not enabled"); } }//GEN-LAST:event_jButton1ActionPerformed diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ModalNoButtons.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ModalNoButtons.java index 735923bae2..33f65488d2 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ModalNoButtons.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ModalNoButtons.java @@ -27,7 +27,6 @@ import javax.swing.JOptionPane; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; /** * This class exists as a stop-gap measure to force users to have an indexed @@ -44,8 +43,8 @@ import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; */ class ModalNoButtons extends javax.swing.JDialog implements PropertyChangeListener { - List unindexed; - HashDatabase toIndex; + List unindexed; + HashDb toIndex; HashLookupSettingsPanel hdbmp; int length = 0; int currentcount = 1; @@ -59,7 +58,7 @@ class ModalNoButtons extends javax.swing.JDialog implements PropertyChangeListen * @param parent Swing parent frame. * @param unindexed the list of unindexed databases to index. */ - ModalNoButtons(HashLookupSettingsPanel hdbmp, java.awt.Frame parent, List unindexed) { + ModalNoButtons(HashLookupSettingsPanel hdbmp, java.awt.Frame parent, List unindexed) { super(parent, NbBundle.getMessage(ModalNoButtons.class, "ModalNoButtons.indexingDbsTitle"), true); this.unindexed = unindexed; this.toIndex = null; @@ -76,7 +75,7 @@ class ModalNoButtons extends javax.swing.JDialog implements PropertyChangeListen * @param parent Swing parent frame. * @param unindexed The unindexed database to index. */ - ModalNoButtons(HashLookupSettingsPanel hdbmp, java.awt.Frame parent, HashDatabase unindexed) { + ModalNoButtons(HashLookupSettingsPanel hdbmp, java.awt.Frame parent, HashDb unindexed) { super(parent, NbBundle.getMessage(ModalNoButtons.class, "ModalNoButtons.indexingDbTitle"), true); this.unindexed = null; this.toIndex = unindexed; @@ -184,7 +183,7 @@ class ModalNoButtons extends javax.swing.JDialog implements PropertyChangeListen "ModalNoButtons.dlgTitle.unfinishedIndexing"), JOptionPane.YES_NO_OPTION); if (res == JOptionPane.YES_OPTION) { - List remove = new ArrayList<>(); + List remove = new ArrayList<>(); if (this.toIndex == null) { remove = this.unindexed; } else { @@ -231,7 +230,7 @@ class ModalNoButtons extends javax.swing.JDialog implements PropertyChangeListen private void indexThese() { length = this.unindexed.size(); this.INDEXING_PROGBAR.setIndeterminate(true); - for (HashDatabase db : this.unindexed) { + for (HashDb db : this.unindexed) { currentDb = db.getHashSetName(); this.CURRENTDB_LABEL.setText("(" + currentDb + ")"); this.CURRENTLYON_LABEL.setText( From f26521515f0c25310e8e6f85848717463d807a2d Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Tue, 17 Oct 2017 14:06:14 -0400 Subject: [PATCH 09/41] Forgot new import dialog --- .../ImportCentralRepoDatabaseDialog.form | 290 +++++++ .../ImportCentralRepoDatabaseDialog.java | 712 ++++++++++++++++++ 2 files changed, 1002 insertions(+) create mode 100644 Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.form create mode 100644 Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.java diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.form b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.form new file mode 100644 index 0000000000..2f42a4ef79 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.form @@ -0,0 +1,290 @@ + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.java new file mode 100644 index 0000000000..9eff79bce5 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.java @@ -0,0 +1,712 @@ +/* + * Central Repository + * + * Copyright 2015-2017 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.modules.hashdatabase; + +import java.awt.Dimension; +import java.awt.Toolkit; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.net.UnknownHostException; +import java.nio.file.Files; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.logging.Level; +import javax.swing.JComboBox; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.swing.JTextField; +import javax.swing.SwingUtilities; +import javax.swing.SwingWorker; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.filechooser.FileNameExtensionFilter; +import org.netbeans.api.progress.ProgressHandle; +import org.netbeans.spi.options.OptionsPanelController; +import org.openide.util.Exceptions; +import org.openide.util.NbBundle; +import org.openide.util.NbBundle.Messages; +import org.openide.windows.WindowManager; +import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttribute; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.coreutils.ModuleSettings; +import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttributeInstance; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalFileInstance; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalSet; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamOrganization; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; +import org.sleuthkit.autopsy.centralrepository.optionspanel.AddNewOrganizationDialog; +import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager; +import org.sleuthkit.datamodel.TskData; + +/** + * Instances of this class allow a user to select an existing hash database and + * add it to the set of hash databases used to classify files as unknown, known, + * or notable. + */ +final public class ImportCentralRepoDatabaseDialog extends javax.swing.JDialog { + private static final Logger LOGGER = Logger.getLogger(ImportCentralRepoDatabaseDialog.class.getName()); + + private final JFileChooser fileChooser = new JFileChooser(); + private final static String LAST_FILE_PATH_KEY = "CentralRepositoryImport_Path"; // NON-NLS + private final int HASH_IMPORT_THRESHOLD = 10000; + private EamOrganization selectedOrg = null; + private List orgs = null; + private final Collection textBoxes; + private final TextBoxChangedListener textBoxChangedListener; + private HashDbManager.HashDatabase selectedHashDb = null; + + + /** + * Displays a dialog that allows a user to select an existing hash database + * and add it to the set of hash databases used to classify files as + * unknown, known, or notable. + */ + @Messages({"ImportCentralRepoDatabaseDialog.importHashDbMsg=Import Hash Database"}) + public ImportCentralRepoDatabaseDialog() { + super((JFrame) WindowManager.getDefault().getMainWindow(), + Bundle.ImportCentralRepoDatabaseDialog_importHashDbMsg(), + true); // NON-NLS + textBoxes = new ArrayList<>(); + textBoxChangedListener = new TextBoxChangedListener(); + initFileChooser(); + initComponents(); + customizeComponents(); + display(); + } + + @Messages({"ImportCentralRepoDatabaseDialog.fileNameExtFilter.text=Hash Database File",}) + private void initFileChooser() { + fileChooser.setDragEnabled(false); + fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + String[] EXTENSION = new String[]{"idx"}; //NON-NLS + FileNameExtensionFilter filter = new FileNameExtensionFilter( + Bundle.ImportCentralRepoDatabaseDialog_fileNameExtFilter_text(), + EXTENSION); // NON-NLS + fileChooser.setFileFilter(filter); + fileChooser.setMultiSelectionEnabled(false); + + if (ModuleSettings.settingExists(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY)) { + String lastBaseDirectory = ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY); + File hashDbFolder = new File(lastBaseDirectory); + if(hashDbFolder.exists()){ + fileChooser.setCurrentDirectory(hashDbFolder); + } + } + } + + private void customizeComponents() { + populateCombobox(); + setTextBoxListeners(); + enableOkButton(false); + } + + public HashDbManager.HashDatabase getHashDatabase(){ + return this.selectedHashDb; + } + + /** + * Register for notifications when the text boxes get updated. + */ + private void setTextBoxListeners() { + textBoxes.add(tfFilePath); + textBoxes.add(tfDatabaseName); + textBoxes.add(tfDatabaseVersion); + addDocumentListeners(textBoxes, textBoxChangedListener); + } + + private void populateCombobox() { + comboboxSourceOrganization.removeAllItems(); + try { + EamDb dbManager = EamDb.getInstance(); + orgs = dbManager.getOrganizations(); + orgs.forEach((org) -> { + comboboxSourceOrganization.addItem(org.getName()); + }); + if (!orgs.isEmpty()) { + selectedOrg = orgs.get(0); + } + valid(); + } catch (EamDbException ex) { + LOGGER.log(Level.SEVERE, "Failure populating combobox with organizations.", ex); + } + } + + /** + * Adds a change listener to a collection of text fields. + * + * @param textFields The text fields. + * @param listener The change listener. + */ + private static void addDocumentListeners(Collection textFields, TextBoxChangedListener listener) { + textFields.forEach((textField) -> { + textField.getDocument().addDocumentListener(listener); + }); + } + + /** + * Tests whether or not values have been entered in all of the required + * text fields. + * + * @return True or false. + */ + private boolean textFieldsArePopulated() { + return !tfDatabaseName.getText().trim().isEmpty() + && !tfDatabaseVersion.getText().trim().isEmpty() + && !tfFilePath.getText().trim().isEmpty(); + } + + /** + * Tests whether or not all of the settings components are populated. + * + * @return True or false. + */ + @Messages({"ImportHashDatabaseDialog.validation.incompleteFields=Fill in all values"}) + private boolean checkFields() { + boolean result = true; + + boolean allPopulated = textFieldsArePopulated(); + + if (!allPopulated) { + // We don't even have everything filled out + result = false; + lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_validation_incompleteFields()); + } + return result; + } + + /** + * Validates that the form is filled out correctly for our usage. + * + * @return true if it's okay, false otherwise. + */ + @Messages({"ImportHashDatabaseDialog.validation.notEnabled=Central Repository is not enabled."}) + public boolean valid() { + lbWarningMsg.setText(""); + if (!EamDb.isEnabled()) { + lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_validation_notEnabled()); + return false; + } + + return enableOkButton(checkFields() && null != selectedOrg); + } + + /** + * Enables the "OK" button to create the Global File Set and insert the instances. + * + * @param enable + * + * @return True or False + */ + private boolean enableOkButton(Boolean enable) { + okButton.setEnabled(enable); + return enable; + } + + /** + * Used to listen for changes in text boxes. It lets the panel know things + * have been updated and that validation needs to happen. + */ + private class TextBoxChangedListener implements DocumentListener { + + @Override + public void changedUpdate(DocumentEvent e) { + firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); + valid(); + } + + @Override + public void insertUpdate(DocumentEvent e) { + firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); + valid(); + } + + @Override + public void removeUpdate(DocumentEvent e) { + firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); + valid(); + } + } + + private void display() { + Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); + setLocation((screenDimension.width - getSize().width) / 2, (screenDimension.height - getSize().height) / 2); + setVisible(true); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + buttonGroup1 = new javax.swing.ButtonGroup(); + okButton = new javax.swing.JButton(); + cancelButton = new javax.swing.JButton(); + tfFilePath = new javax.swing.JTextField(); + openButton = new javax.swing.JButton(); + knownRadioButton = new javax.swing.JRadioButton(); + knownBadRadioButton = new javax.swing.JRadioButton(); + lbDatabaseType = new javax.swing.JLabel(); + lbDatabasePath = new javax.swing.JLabel(); + lbSourceOrganization = new javax.swing.JLabel(); + lbDatabaseName = new javax.swing.JLabel(); + lbDatabaseVersion = new javax.swing.JLabel(); + comboboxSourceOrganization = new javax.swing.JComboBox<>(); + tfDatabaseName = new javax.swing.JTextField(); + tfDatabaseVersion = new javax.swing.JTextField(); + bnNewOrganization = new javax.swing.JButton(); + lbWarningMsg = new javax.swing.JLabel(); + cbInboxMessages = new javax.swing.JCheckBox(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + + org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.okButton.text")); // NOI18N + okButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + okButtonActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.cancelButton.text")); // NOI18N + cancelButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + cancelButtonActionPerformed(evt); + } + }); + + tfFilePath.setText(org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.tfFilePath.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(openButton, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.openButton.text")); // NOI18N + openButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + openButtonActionPerformed(evt); + } + }); + + buttonGroup1.add(knownRadioButton); + org.openide.awt.Mnemonics.setLocalizedText(knownRadioButton, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.knownRadioButton.text")); // NOI18N + + buttonGroup1.add(knownBadRadioButton); + knownBadRadioButton.setSelected(true); + org.openide.awt.Mnemonics.setLocalizedText(knownBadRadioButton, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.knownBadRadioButton.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseType, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.lbDatabaseType.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(lbDatabasePath, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportHashDatabaseDialog.lbFilePath.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(lbSourceOrganization, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.lbSourceOrganization.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseName, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.lbDatabaseName.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseVersion, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.lbDatabaseVersion.text")); // NOI18N + + comboboxSourceOrganization.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); + comboboxSourceOrganization.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + comboboxSourceOrganizationActionPerformed(evt); + } + }); + + tfDatabaseName.setToolTipText(org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportHashDatabaseDialog.tfDatabaseName.tooltip")); // NOI18N + + tfDatabaseVersion.setToolTipText(org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportHashDatabaseDialog.tfDatabaseVersion.tooltip.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(bnNewOrganization, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.bnNewOrganization.text")); // NOI18N + bnNewOrganization.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + bnNewOrganizationActionPerformed(evt); + } + }); + + lbWarningMsg.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N + lbWarningMsg.setForeground(new java.awt.Color(255, 0, 0)); + + cbInboxMessages.setSelected(true); + org.openide.awt.Mnemonics.setLocalizedText(cbInboxMessages, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.cbInboxMessages.text")); // NOI18N + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(cbInboxMessages) + .addGap(0, 0, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(okButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cancelButton)) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(lbDatabaseName) + .addComponent(lbDatabaseVersion) + .addComponent(lbSourceOrganization)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(comboboxSourceOrganization, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(bnNewOrganization) + .addGap(0, 0, Short.MAX_VALUE)) + .addComponent(tfDatabaseName) + .addComponent(tfDatabaseVersion))) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addComponent(lbDatabasePath) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(tfFilePath, javax.swing.GroupLayout.PREFERRED_SIZE, 324, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(lbDatabaseType, javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addGap(19, 19, 19) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(knownRadioButton) + .addComponent(knownBadRadioButton)))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(openButton))) + .addGap(6, 6, 6)) + .addComponent(lbWarningMsg, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) + ); + + layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton}); + + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(lbDatabasePath) + .addComponent(tfFilePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(openButton)) + .addGap(6, 6, 6) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(lbDatabaseName, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(tfDatabaseName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(lbDatabaseVersion, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(tfDatabaseVersion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(lbSourceOrganization, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(comboboxSourceOrganization, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(bnNewOrganization)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(lbDatabaseType) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(knownRadioButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(knownBadRadioButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cbInboxMessages) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(lbWarningMsg, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(okButton) + .addComponent(cancelButton)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + @Messages({"ImportHashDatabaseDialog.failedToGetDbPathMsg=Failed to get the path of the selected database.",}) + private void openButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openButtonActionPerformed + if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { + File databaseFile = fileChooser.getSelectedFile(); + try { + tfFilePath.setText(databaseFile.getCanonicalPath()); + if (databaseFile.getName().toLowerCase().contains("nsrl")) { //NON-NLS + knownRadioButton.setSelected(true); + } + ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY, databaseFile.getParent()); + } catch (IOException ex) { + Logger.getLogger(ImportCentralRepoDatabaseDialog.class.getName()).log(Level.SEVERE, "Failed to get path of selected database", ex); // NON-NLS + lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_failedToGetDbPathMsg()); + } + } + valid(); + }//GEN-LAST:event_openButtonActionPerformed + + private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed + dispose(); + }//GEN-LAST:event_cancelButtonActionPerformed + + /** + * Create the new global set and return the ID number + * + * @return ID number of new global set + * @throws EamDbException + */ + private int createGlobalSet() throws EamDbException { + EamDb dbManager = EamDb.getInstance(); + EamGlobalSet eamGlobalSet = new EamGlobalSet( + selectedOrg.getOrgID(), + tfDatabaseName.getText().trim(), + tfDatabaseVersion.getText().trim(), + LocalDate.now()); + return dbManager.newReferencelSet(eamGlobalSet); + } + + @Messages({"ImportHashDatabaseDialog.createGlobalSet.failedMsg.text=Failed to store attribution details.", + "ImportHashDatabaseDialog.mustSelectHashDbFilePathMsg=Missing hash database file path.", + "ImportHashDatabaseDialog.hashDbDoesNotExistMsg=The selected hash database does not exist.", + "# {0} - selected file path", + "ImportHashDatabaseDialog.errorMessage.failedToOpenHashDbMsg=Failed to open hash database at {0}.", + "ImportHashDatabaseDialog.dbAlreadyExists=A database with that name and version already exists.", + "ImportHashDatabaseDialog.centralRepoError=Error accessing the central repository", +}) + private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed + // Note that the error handlers in this method call return without disposing of the + // dialog to allow the user to try again, if desired. + String selectedFilePath = tfFilePath.getText(); + + // have valid file path + if (selectedFilePath.isEmpty()) { + lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_mustSelectHashDbFilePathMsg()); + return; + } + File file = new File(selectedFilePath); + if (!file.exists()) { + lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_hashDbDoesNotExistMsg()); + return; + } + + String dbName = tfDatabaseName.getText().trim(); + String version = tfDatabaseVersion.getText().trim(); + + try{ + if(EamDb.getInstance().referenceSetExists(dbName, version)){ + lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_dbAlreadyExists()); + return; + } + } catch (EamDbException ex){ + lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_centralRepoError()); + LOGGER.log(Level.SEVERE, "Error searching for reference set in central repo", ex); + return; + } + + HashDbManager.HashDb.KnownFilesType known; + if (knownRadioButton.isSelected()) { + known = HashDbManager.HashDb.KnownFilesType.KNOWN; + } else{ + known = HashDbManager.HashDb.KnownFilesType.KNOWN_BAD; + } + + boolean sendMessages = this.cbInboxMessages.isSelected(); + + try{ + HashDbManager.getInstance().importCentralRepoHashSet(dbName, version, + selectedOrg.getOrgID(), true, sendMessages, + known, selectedFilePath); + } catch (Exception ex){ + ex.printStackTrace(); + } finally { + dispose(); + } + /* + // create global set + int globalSetID; + try { + globalSetID = createGlobalSet(); + } catch (EamDbException ex) { + LOGGER.log(Level.SEVERE, "Failed to create global set.", ex); + lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_createGlobalSet_failedMsg_text()); + return; + } + + // insert hashes + TskData.FileKnown knownStatus = TskData.FileKnown.UNKNOWN; + if (knownRadioButton.isSelected()) { + knownStatus = TskData.FileKnown.KNOWN; + } else if (knownBadRadioButton.isSelected()) { + knownStatus = TskData.FileKnown.BAD; + } + + String errorMessage = Bundle.ImportHashDatabaseDialog_errorMessage_failedToOpenHashDbMsg(selectedFilePath); + // Future, make UI handle more than the "FILES" type. + try { + EamDb dbManager = EamDb.getInstance(); + CorrelationAttribute.Type contentType = dbManager.getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID); // get "FILES" type + // run in the background and close dialog + SwingUtilities.invokeLater(new ImportHashDatabaseWorker(selectedFilePath, knownStatus, globalSetID, contentType)::execute); + dispose(); + } catch (EamDbException | UnknownHostException ex) { + Logger.getLogger(ImportHashDatabaseDialog.class.getName()).log(Level.SEVERE, errorMessage, ex); + lbWarningMsg.setText(ex.getMessage()); + }*/ + + }//GEN-LAST:event_okButtonActionPerformed + + @SuppressWarnings({"unchecked"}) + private void bnNewOrganizationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnNewOrganizationActionPerformed + AddNewOrganizationDialog dialogO = new AddNewOrganizationDialog(); + // update the combobox options + if (dialogO.isChanged()) { + populateCombobox(); + } + }//GEN-LAST:event_bnNewOrganizationActionPerformed + + @SuppressWarnings({"unchecked"}) + private void comboboxSourceOrganizationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboboxSourceOrganizationActionPerformed + JComboBox cb = (JComboBox)evt.getSource(); + String orgName = (String)cb.getSelectedItem(); + if (null == orgName) return; + + for (EamOrganization org : orgs) { + if (org.getName().equals(orgName)) { + selectedOrg = org; + return; + } + } + valid(); + }//GEN-LAST:event_comboboxSourceOrganizationActionPerformed + + @NbBundle.Messages({"ImportHashDatabaseDialog.ImportHashDatabaseWorker.displayName=Importing Hash Database"}) + public class ImportHashDatabaseWorker extends SwingWorker { + + private final File file; + private final TskData.FileKnown knownStatus; + private final int globalSetID; + private final ProgressHandle progress; + private final CorrelationAttribute.Type contentType; + + public ImportHashDatabaseWorker(String filename, TskData.FileKnown knownStatus, int globalSetID, CorrelationAttribute.Type contentType) throws EamDbException, UnknownHostException { + this.file = new File(filename); + this.knownStatus = knownStatus; + this.globalSetID = globalSetID; + this.contentType = contentType; + this.progress = ProgressHandle.createHandle(Bundle.ImportHashDatabaseDialog_ImportHashDatabaseWorker_displayName()); + + if (!EamDb.isEnabled()) { + throw new EamDbException("Central repository database is not enabled."); // NON-NLS + } + } + + @Override + protected Void doInBackground() throws Exception { + importHashDatabase(); + return null; + } + + @Override + @Messages({"ImportHashDatabaseDialog.ImportHashDatabaseWorker.error=Failed to import hash database."}) + protected void done() { + progress.finish(); + try { + get(); + } catch (InterruptedException | ExecutionException ex) { + Logger.getLogger(ImportCentralRepoDatabaseDialog.class.getName()).log(Level.SEVERE, Bundle.ImportHashDatabaseDialog_ImportHashDatabaseWorker_error(), ex); + MessageNotifyUtil.Notify.show(Bundle.ImportHashDatabaseDialog_ImportHashDatabaseWorker_error(), + ex.getMessage(), + MessageNotifyUtil.MessageType.ERROR); + } + } + + private long numberOfLinesInFile(File f) throws IOException { + return Files.lines(f.toPath()).count(); + } + + @Messages({"# {0} - value content", + "ImportHashDatabaseDialog.ImportHashDatabaseWorker.duplicate=Duplicate value {0} found in import file."}) + private void importHashDatabase() throws EamDbException, IOException { + BufferedReader reader = new BufferedReader(new FileReader(file)); + String line; + EamDb dbManager = EamDb.getInstance(); + Set globalInstances = new HashSet<>(); + + long totalLines = numberOfLinesInFile(file); + if (totalLines <= Integer.MAX_VALUE) { + progress.start((int) totalLines); + } else { + progress.start(); + } + + int numLines = 0; + LOGGER.log(Level.INFO, "Importing hash database {0}", file.getName()); + while ((line = reader.readLine()) != null) { + progress.progress(++numLines); + + String[] parts = line.split("\\|"); + + // Header lines start with a 41 character dummy hash, 1 character longer than a SHA-1 hash + if (parts.length != 2 || parts[0].length() == 41) { + continue; + } + + EamGlobalFileInstance eamGlobalFileInstance = new EamGlobalFileInstance( + globalSetID, + parts[0].toLowerCase(), + knownStatus, + ""); + + globalInstances.add(eamGlobalFileInstance); + + if(numLines % HASH_IMPORT_THRESHOLD == 0){ + dbManager.bulkInsertReferenceTypeEntries(globalInstances, contentType); + globalInstances.clear(); + } + } + + dbManager.bulkInsertReferenceTypeEntries(globalInstances, contentType); + LOGGER.log(Level.INFO, "Finished importing hash database. Total entries: {0}", numLines); + + } + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton bnNewOrganization; + private javax.swing.ButtonGroup buttonGroup1; + private javax.swing.JButton cancelButton; + private javax.swing.JCheckBox cbInboxMessages; + private javax.swing.JComboBox comboboxSourceOrganization; + private javax.swing.JRadioButton knownBadRadioButton; + private javax.swing.JRadioButton knownRadioButton; + private javax.swing.JLabel lbDatabaseName; + private javax.swing.JLabel lbDatabasePath; + private javax.swing.JLabel lbDatabaseType; + private javax.swing.JLabel lbDatabaseVersion; + private javax.swing.JLabel lbSourceOrganization; + private javax.swing.JLabel lbWarningMsg; + private javax.swing.JButton okButton; + private javax.swing.JButton openButton; + private javax.swing.JTextField tfDatabaseName; + private javax.swing.JTextField tfDatabaseVersion; + private javax.swing.JTextField tfFilePath; + // End of variables declaration//GEN-END:variables +} From 6694b055510a82743a932b9164024f6c8eca1473 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Thu, 19 Oct 2017 11:06:27 -0400 Subject: [PATCH 10/41] Adding progress dialog --- .../modules/hashdatabase/Bundle.properties | 5 +- .../modules/hashdatabase/HashDbManager.java | 2 +- .../ImportCentralRepoDatabaseDialog.java | 9 +- .../ImportCentralRepoDbProgressDialog.form | 115 ++++++ .../ImportCentralRepoDbProgressDialog.java | 366 ++++++++++++++++++ 5 files changed, 492 insertions(+), 5 deletions(-) create mode 100644 Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.form create mode 100644 Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties index 5c22510eda..b09e1f7e20 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties @@ -242,4 +242,7 @@ ImportHashDatabaseDialog.tfDatabaseName.tooltip=Name for this database ImportHashDatabaseDialog.tfDatabaseVersion.tooltip.text=Database Version Number ImportHashDatabaseDialog.tfDatabaseName.tooltip=Name for this database ImportHashDatabaseDialog.tfDatabaseVersion.tooltip.text=Database Version Number - +ImportCentralRepoDbProgressDialog.jButton1.text=jButton1 +ImportCentralRepoDbProgressDialog.lbProgress.text=jLabel1 +ImportCentralRepoDbProgressDialog.bnOk.text=OK +ImportCentralRepoDbProgressDialog.bnCancel.text=Cancel diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index 2796eaa9b2..648dc7b7ec 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -346,7 +346,7 @@ public class HashDbManager implements PropertyChangeListener { try{ // Import the hashes - TskData.FileKnown knownStatus = TskData.FileKnown.UNKNOWN; + TskData.FileKnown knownStatus; if (knownFilesType.equals(HashDb.KnownFilesType.KNOWN)) { knownStatus = TskData.FileKnown.KNOWN; } else { diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.java index 9eff79bce5..c10db21c7c 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.java @@ -92,6 +92,7 @@ final public class ImportCentralRepoDatabaseDialog extends javax.swing.JDialog { super((JFrame) WindowManager.getDefault().getMainWindow(), Bundle.ImportCentralRepoDatabaseDialog_importHashDbMsg(), true); // NON-NLS + textBoxes = new ArrayList<>(); textBoxChangedListener = new TextBoxChangedListener(); initFileChooser(); @@ -531,9 +532,11 @@ final public class ImportCentralRepoDatabaseDialog extends javax.swing.JDialog { boolean sendMessages = this.cbInboxMessages.isSelected(); try{ - HashDbManager.getInstance().importCentralRepoHashSet(dbName, version, - selectedOrg.getOrgID(), true, sendMessages, - known, selectedFilePath); + ImportCentralRepoDbProgressDialog progressDialog = new ImportCentralRepoDbProgressDialog(); + progressDialog.importFile(dbName, version, + selectedOrg.getOrgID(), true, sendMessages, known, selectedFilePath); + //HashDbManager.getInstance().importCentralRepoHashSet(dbName, version, + // selectedOrg.getOrgID(), true, sendMessages, known, selectedFilePath); } catch (Exception ex){ ex.printStackTrace(); } finally { diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.form b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.form new file mode 100644 index 0000000000..30e4a099d5 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.form @@ -0,0 +1,115 @@ + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java new file mode 100644 index 0000000000..c5ceb255d5 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java @@ -0,0 +1,366 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2011-2016 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.modules.hashdatabase; + +import java.awt.Cursor; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeEvent; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.nio.file.Files; +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.logging.Level; +import javax.swing.JFrame; +import javax.swing.JProgressBar; +import javax.swing.SwingWorker; +import org.openide.util.NbBundle; +import org.openide.windows.WindowManager; +import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttribute; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalFileInstance; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; +import org.sleuthkit.datamodel.TskCoreException; +import org.sleuthkit.datamodel.TskData; + +/** + * + */ +class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements PropertyChangeListener{ + + + long totalHashes; + private SwingWorker worker; + + + /** + * + * @param hashSetName + * @param version + * @param orgId + * @param searchDuringIngest + * @param sendIngestMessages + * @param knownFilesType + * @param importFile + */ + @NbBundle.Messages({"ImportCentralRepoDbProgressDialog.title.text=Central Repository Import Progress", + }) + ImportCentralRepoDbProgressDialog() { + super((JFrame) WindowManager.getDefault().getMainWindow(), + Bundle.ImportCentralRepoDbProgressDialog_title_text(), + true); + + initComponents(); + } + + void importFile(String hashSetName, String version, int orgId, + boolean searchDuringIngest, boolean sendIngestMessages, HashDbManager.HashDb.KnownFilesType knownFilesType, + String importFileName){ + setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + + File importFile = new File(importFileName); + worker = new ImportIDXWorker(hashSetName, version, orgId, searchDuringIngest, sendIngestMessages, + knownFilesType, importFile, totalHashes); + totalHashes = ((ImportIDXWorker)worker).getEstimatedTotalHashes(); + worker.addPropertyChangeListener(this); + worker.execute(); + + setLocationRelativeTo((JFrame) WindowManager.getDefault().getMainWindow()); + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + this.setVisible(true); + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + System.out.println("### Evt type: " + evt.getPropertyName()); + System.out.println(" newValue: " + evt.getNewValue().toString()); + System.out.println("### Setting progress to " + worker.getProgress()); + + if("progress".equals(evt.getPropertyName())){ + progressBar.setValue(worker.getProgress()); + String mes = "Count: " + worker.getProgress(); + lbProgress.setText(mes); + } else if ("state".equals(evt.getPropertyName()) + && (SwingWorker.StateValue.DONE.equals(evt.getNewValue()))) { + // Disable cancel and enable ok + bnCancel.setEnabled(false); + bnOk.setEnabled(true); + + progressBar.setValue(progressBar.getMaximum()); + String mes = "Count: " + worker.getProgress(); + lbProgress.setText(mes); + } + } + + class ImportIDXWorker extends SwingWorker{ + + private final int HASH_IMPORT_THRESHOLD = 10000; + private final String hashSetName; + private final String version; + private final int orgId; + private final boolean searchDuringIngest; + private final boolean sendIngestMessages; + private final HashDbManager.HashDb.KnownFilesType knownFilesType; + private final File importFile; + private final long totalLines; + private int crIndex = -1; + + ImportIDXWorker(String hashSetName, String version, int orgId, + boolean searchDuringIngest, boolean sendIngestMessages, HashDbManager.HashDb.KnownFilesType knownFilesType, + File importFile, long totalLines){ + + this.hashSetName = hashSetName; + this.version = version; + this.orgId = orgId; + this.searchDuringIngest = searchDuringIngest; + this.sendIngestMessages = sendIngestMessages; + this.knownFilesType = knownFilesType; + this.importFile = importFile; + this.totalLines = totalLines; + } + + /** + * Doing an actual count of the number of lines in a large idx file (such + * as the nsrl) is slow, so just get something in the general area for the + * progress bar. + * @return Approximate number of hashes in the file + */ + long getEstimatedTotalHashes(){ + long fileSize = importFile.length(); + return (fileSize / 0x33); // IDX file lines are generally 0x33 bytes long + } + + @Override + protected Void doInBackground() throws Exception { + + try{ + // Create an empty hashset in the central repository + crIndex = EamDb.getInstance().newReferenceSet(orgId, hashSetName, version); + } catch (EamDbException ex){ + throw new TskCoreException(ex.getLocalizedMessage()); + } + + try{ + + TskData.FileKnown knownStatus; + if (knownFilesType.equals(HashDbManager.HashDb.KnownFilesType.KNOWN)) { + knownStatus = TskData.FileKnown.KNOWN; + } else { + knownStatus = TskData.FileKnown.BAD; + } + + EamDb dbManager = EamDb.getInstance(); + CorrelationAttribute.Type contentType = dbManager.getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID); // get "FILES" type + BufferedReader reader = new BufferedReader(new FileReader(importFile)); + String line; + Set globalInstances = new HashSet<>(); + + long numLines = 0; + while ((line = reader.readLine()) != null) { + + String[] parts = line.split("\\|"); + + // Header lines start with a 41 character dummy hash, 1 character longer than a SHA-1 hash + if (parts.length != 2 || parts[0].length() == 41) { + continue; + } + + EamGlobalFileInstance eamGlobalFileInstance = new EamGlobalFileInstance( + crIndex, + parts[0].toLowerCase(), + knownStatus, + ""); + + globalInstances.add(eamGlobalFileInstance); + numLines++; + + if(numLines % HASH_IMPORT_THRESHOLD == 0){ + dbManager.bulkInsertReferenceTypeEntries(globalInstances, contentType); + globalInstances.clear(); + + int progress = (int)(numLines * 100 / totalLines); + if(progress < 100){ + this.setProgress(progress); + } else { + this.setProgress(99); + } + } + } + + dbManager.bulkInsertReferenceTypeEntries(globalInstances, contentType); + this.setProgress(100); + + return null; + } + catch (Exception ex){ + // TODO + ex.printStackTrace(); + throw new TskCoreException(ex.getLocalizedMessage()); + } + + + // Let any external listeners know that there's a new set + //try { + // changeSupport.firePropertyChange(HashDbManager.SetEvt.DB_ADDED.toString(), null, hashSetName); + //} catch (Exception e) { + // logger.log(Level.SEVERE, "HashDbManager listener threw exception", e); //NON-NLS + // MessageNotifyUtil.Notify.show( + // NbBundle.getMessage(this.getClass(), "HashDbManager.moduleErr"), + // NbBundle.getMessage(this.getClass(), "HashDbManager.moduleErrorListeningToUpdatesMsg"), + // MessageNotifyUtil.MessageType.ERROR); + //} + //return hashDb; + } + + @Override + protected void done() { + try { + get(); + try{ + System.out.println("### Finished - adding hashDb object"); + HashDbManager.CentralRepoHashDb hashDb = HashDbManager.getInstance().addExistingCentralRepoHashSet(hashSetName, version, crIndex, + searchDuringIngest, sendIngestMessages, knownFilesType); + } catch (TskCoreException ex){ + System.out.println("\n### Error!"); + } + } catch (InterruptedException | ExecutionException ex) { + + System.out.println("\n### Interrupted!"); + + // If the user hit cancel, delete this incomplete hash set from the central repo + if(crIndex >= 0){ + try{ + EamDb.getInstance().deleteReferenceSet(crIndex); + } catch (EamDbException ex2){ + + } + } + } + } + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + progressBar = new javax.swing.JProgressBar(); + lbProgress = new javax.swing.JLabel(); + jButton1 = new javax.swing.JButton(); + bnOk = new javax.swing.JButton(); + bnCancel = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + + org.openide.awt.Mnemonics.setLocalizedText(lbProgress, org.openide.util.NbBundle.getMessage(ImportCentralRepoDbProgressDialog.class, "ImportCentralRepoDbProgressDialog.lbProgress.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(ImportCentralRepoDbProgressDialog.class, "ImportCentralRepoDbProgressDialog.jButton1.text")); // NOI18N + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(bnOk, org.openide.util.NbBundle.getMessage(ImportCentralRepoDbProgressDialog.class, "ImportCentralRepoDbProgressDialog.bnOk.text")); // NOI18N + bnOk.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + bnOkActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(bnCancel, org.openide.util.NbBundle.getMessage(ImportCentralRepoDbProgressDialog.class, "ImportCentralRepoDbProgressDialog.bnCancel.text")); // NOI18N + bnCancel.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + bnCancelActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(27, 27, 27) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jButton1) + .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 346, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(27, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addComponent(lbProgress) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(bnOk) + .addGap(18, 18, 18) + .addComponent(bnCancel) + .addGap(24, 24, 24)))) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(112, 112, 112) + .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(lbProgress) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 89, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(bnOk) + .addComponent(bnCancel)) + .addGap(72, 72, 72))) + .addComponent(jButton1) + .addGap(42, 42, 42)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + this.dispose(); + }//GEN-LAST:event_jButton1ActionPerformed + + private void bnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnCancelActionPerformed + this.worker.cancel(true); + }//GEN-LAST:event_bnCancelActionPerformed + + private void bnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnOkActionPerformed + this.dispose(); + }//GEN-LAST:event_bnOkActionPerformed + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton bnCancel; + private javax.swing.JButton bnOk; + private javax.swing.JButton jButton1; + private javax.swing.JLabel lbProgress; + private javax.swing.JProgressBar progressBar; + // End of variables declaration//GEN-END:variables +} From d9b605af5065fb56b51a5b57bbe0a1e7efeab60c Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Tue, 24 Oct 2017 13:29:48 -0400 Subject: [PATCH 11/41] Importing dialog cancellation done --- .../ImportCentralRepoDatabaseDialog.java | 4 +- .../modules/hashdatabase/Bundle.properties | 10 +- .../modules/hashdatabase/HashDbManager.java | 12 +- .../hashdatabase/HashLookupSettings.java | 15 +- .../hashdatabase/HashLookupSettingsPanel.form | 125 ++++++++--- .../hashdatabase/HashLookupSettingsPanel.java | 161 ++++++++++---- .../ImportCentralRepoDbProgressDialog.form | 77 +++---- .../ImportCentralRepoDbProgressDialog.java | 201 +++++++++++------- 8 files changed, 418 insertions(+), 187 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportCentralRepoDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportCentralRepoDatabaseDialog.java index c47b598e68..4223b4b359 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportCentralRepoDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportCentralRepoDatabaseDialog.java @@ -489,7 +489,7 @@ final public class ImportCentralRepoDatabaseDialog extends javax.swing.JDialog { private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed // Note that the error handlers in this method call return without disposing of the // dialog to allow the user to try again, if desired. - String selectedFilePath = tfFilePath.getText(); + /*String selectedFilePath = tfFilePath.getText(); // have valid file path if (selectedFilePath.isEmpty()) { @@ -517,7 +517,7 @@ final public class ImportCentralRepoDatabaseDialog extends javax.swing.JDialog { } finally { dispose(); - } + }*/ /* // create global set int globalSetID; diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties index b09e1f7e20..d2e97172b9 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties @@ -242,7 +242,13 @@ ImportHashDatabaseDialog.tfDatabaseName.tooltip=Name for this database ImportHashDatabaseDialog.tfDatabaseVersion.tooltip.text=Database Version Number ImportHashDatabaseDialog.tfDatabaseName.tooltip=Name for this database ImportHashDatabaseDialog.tfDatabaseVersion.tooltip.text=Database Version Number -ImportCentralRepoDbProgressDialog.jButton1.text=jButton1 -ImportCentralRepoDbProgressDialog.lbProgress.text=jLabel1 +ImportCentralRepoDbProgressDialog.lbProgress.text=Starting import... ImportCentralRepoDbProgressDialog.bnOk.text=OK ImportCentralRepoDbProgressDialog.bnCancel.text=Cancel +HashLookupSettingsPanel.versionLabel.text_1=Version: +HashLookupSettingsPanel.hashDbVersionLabel.text_1=No database selected +HashLookupSettingsPanel.orgLabel.text_1=Organization: +HashLookupSettingsPanel.hashDbOrgLabel.text_1=No database selected +HashLookupSettingsPanel.readOnlyLabel.text_1=Read only: +HashLookupSettingsPanel.hashDbReadOnlyLabel.text_1=No database selected +ImportCentralRepoDbProgressDialog.jLabel1.text=Importing hash set into the central repository diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index 648dc7b7ec..8ade7d699e 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -329,7 +329,7 @@ public class HashDbManager implements PropertyChangeListener { return db; } - + /* public CentralRepoHashDb importCentralRepoHashSet(String hashSetName, String version, int orgId, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType, String importFile) throws TskCoreException { @@ -415,7 +415,7 @@ public class HashDbManager implements PropertyChangeListener { ex.printStackTrace(); throw new TskCoreException(ex.getLocalizedMessage()); } - } + }*/ synchronized void indexHashDatabase(HashDb hashDb) { hashDb.addPropertyChangeListener(this); @@ -703,7 +703,8 @@ public class HashDbManager implements PropertyChangeListener { allDatabasesLoadedCorrectly = false; } } else { - addExistingCentralRepoHashSet(hashDbInfo.getHashSetName(), hashDbInfo.getVersion(), hashDbInfo.getCentralRepoIndex(), + addExistingCentralRepoHashSet(hashDbInfo.getHashSetName(), hashDbInfo.getVersion(), + hashDbInfo.getCentralRepoIndex(), hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), hashDbInfo.getKnownFilesType()); } } catch (TskCoreException ex) { @@ -1168,6 +1169,7 @@ public class HashDbManager implements PropertyChangeListener { private final HashDb.KnownFilesType knownFilesType; private final int centralRepoIndex; private final String version; + private final String orgName = ""; private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); private CentralRepoHashDb(String hashSetName, String version, int centralRepoIndex, @@ -1215,6 +1217,10 @@ public class HashDbManager implements PropertyChangeListener { return version; } + public String getOrgName(){ + return "org name"; + } + public int getCentralRepoIndex(){ return centralRepoIndex; } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java index 00bac6cf4e..3307ee2c09 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java @@ -307,6 +307,7 @@ final class HashLookupSettings implements Serializable { private final boolean sendIngestMessages; private final String path; private final String version; + private final String orgName; private final int centralRepoIndex; private DatabaseType dbType; @@ -328,12 +329,14 @@ final class HashLookupSettings implements Serializable { this.path = path; this.centralRepoIndex = -1; this.version = ""; + this.orgName = ""; this.dbType = DatabaseType.FILE; } - HashDbInfo(String hashSetName, String version, int centralRepoIndex, HashDbManager.HashDb.KnownFilesType knownFilesType, boolean searchDuringIngest, boolean sendIngestMessages){ + HashDbInfo(String hashSetName, String version, String orgName, int centralRepoIndex, HashDbManager.HashDb.KnownFilesType knownFilesType, boolean searchDuringIngest, boolean sendIngestMessages){ this.hashSetName = hashSetName; this.version = version; + this.orgName = orgName; this.centralRepoIndex = centralRepoIndex; this.knownFilesType = knownFilesType; this.searchDuringIngest = searchDuringIngest; @@ -351,6 +354,7 @@ final class HashLookupSettings implements Serializable { this.sendIngestMessages = fileTypeDb.getSendIngestMessages(); this.centralRepoIndex = -1; this.version = ""; + this.orgName = ""; this.dbType = DatabaseType.FILE; if (fileTypeDb.hasIndexOnly()) { this.path = fileTypeDb.getIndexPath(); @@ -361,6 +365,7 @@ final class HashLookupSettings implements Serializable { HashDbManager.CentralRepoHashDb centralRepoDb = (HashDbManager.CentralRepoHashDb)db; this.hashSetName = centralRepoDb.getHashSetName(); this.version = centralRepoDb.getVersion(); + this.orgName = centralRepoDb.getOrgName(); this.knownFilesType = centralRepoDb.getKnownFilesType(); this.searchDuringIngest = centralRepoDb.getSearchDuringIngest(); this.sendIngestMessages = centralRepoDb.getSendIngestMessages(); @@ -388,6 +393,14 @@ final class HashLookupSettings implements Serializable { String getVersion(){ return version; } + + /** + * Get the organization name for the hash set + * @return org name + */ + String getOrgName(){ + return orgName; + } /** * Gets the known files type setting. diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.form b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.form index b472445216..a78094dc79 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.form +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.form @@ -94,7 +94,7 @@ - + @@ -102,29 +102,24 @@ - - - - - - - - + + + - + - - - + + + @@ -132,25 +127,48 @@ + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + + + + + - + @@ -202,6 +220,21 @@ + + + + + + + + + + + + + + + @@ -211,12 +244,12 @@ - + - + @@ -597,6 +630,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java index 36aa535567..b3eb556184 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java @@ -27,6 +27,7 @@ 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; @@ -45,6 +46,7 @@ import org.sleuthkit.autopsy.events.AutopsyEvent; import org.sleuthkit.autopsy.ingest.IngestManager; import org.sleuthkit.autopsy.ingest.IngestModuleGlobalSettingsPanel; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.CentralRepoHashDb; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb.KnownFilesType; import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; @@ -120,7 +122,11 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan hashDbNameLabel.setText(NO_SELECTION_TEXT); hashDbTypeLabel.setText(NO_SELECTION_TEXT); hashDbLocationLabel.setText(NO_SELECTION_TEXT); + hashDbVersionLabel.setText(NO_SELECTION_TEXT); + hashDbOrgLabel.setText(NO_SELECTION_TEXT); + hashDbReadOnlyLabel.setText(NO_SELECTION_TEXT); indexPathLabel.setText(NO_SELECTION_TEXT); + // Update indexing components. hashDbIndexStatusLabel.setText(NO_SELECTION_TEXT); @@ -144,18 +150,26 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan ingestWarningLabel.setVisible(ingestIsRunning); } + @NbBundle.Messages({"HashLookupSettingsPanel.readOnly=Read only", + "HashLookupSettingsPanel.editable=Editable", + "HashLookupSettingsPanel.updateStatusError=Error reading status", + "HashLookupSettingsPanel.notApplicable=N/A", + "HashLookupSettingsPanel.centralRepo=Central Repository" + }) private void updateComponentsForSelection(HashDatabase db) { boolean ingestIsRunning = IngestManager.getInstance().isIngestRunning(); // Update descriptive labels. hashDbNameLabel.setText(db.getHashSetName()); - hashDbTypeLabel.setText(db.getKnownFilesType().getDisplayName()); - - try { - hashDbLocationLabel.setText(shortenPath(db.getDatabasePath())); - } catch (TskCoreException ex) { - Logger.getLogger(HashLookupSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting database path of " + db.getHashSetName() + " hash database", ex); //NON-NLS - hashDbLocationLabel.setText(ERROR_GETTING_PATH_TEXT); + hashDbTypeLabel.setText(db.getKnownFilesType().getDisplayName()); + try{ + if(db.isUpdateable()){ + hashDbReadOnlyLabel.setText(Bundle.HashLookupSettingsPanel_editable()); + } else { + hashDbReadOnlyLabel.setText(Bundle.HashLookupSettingsPanel_readOnly()); + } + } catch (TskCoreException ex){ + hashDbReadOnlyLabel.setText(Bundle.HashLookupSettingsPanel_updateStatusError()); } try { @@ -167,6 +181,21 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan if(db instanceof HashDb){ HashDb hashDb = (HashDb)db; + + // Disable the central repo fields + hashDbVersionLabel.setText(Bundle.HashLookupSettingsPanel_notApplicable()); + hashDbOrgLabel.setText(Bundle.HashLookupSettingsPanel_notApplicable()); + + // Enable the delete button if ingest is not running + deleteDatabaseButton.setEnabled(!ingestIsRunning); + + try { + hashDbLocationLabel.setText(shortenPath(db.getDatabasePath())); + } catch (TskCoreException ex) { + Logger.getLogger(HashLookupSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting database path of " + db.getHashSetName() + " hash database", ex); //NON-NLS + hashDbLocationLabel.setText(ERROR_GETTING_PATH_TEXT); + } + try { indexPathLabel.setText(shortenPath(hashDb.getIndexPath())); } catch (TskCoreException ex) { @@ -214,6 +243,19 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan indexButton.setText(NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.indexButtonText.index")); indexButton.setEnabled(false); } + } else { + + // Disable the file type fields/buttons + indexPathLabel.setText(Bundle.HashLookupSettingsPanel_notApplicable()); + hashDbIndexStatusLabel.setText(Bundle.HashLookupSettingsPanel_notApplicable()); + hashDbLocationLabel.setText(Bundle.HashLookupSettingsPanel_centralRepo()); + indexButton.setEnabled(false); + deleteDatabaseButton.setEnabled(false); + + CentralRepoHashDb crDb = (CentralRepoHashDb)db; + + hashDbVersionLabel.setText(crDb.getVersion()); + hashDbOrgLabel.setText(crDb.getOrgName()); } // Disable the indexing button if ingest is in progress. @@ -230,7 +272,6 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan // Update database action buttons. createDatabaseButton.setEnabled(true); importDatabaseButton.setEnabled(true); - deleteDatabaseButton.setEnabled(!ingestIsRunning); // Update ingest in progress warning label. ingestWarningLabel.setVisible(ingestIsRunning); @@ -380,7 +421,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan // Give the user a visual indication of any hash sets with a hash // database that needs to be indexed by displaying the hash set name // in red. - if (hashSetTableModel.indexExists(row)) { + if (hashSetTableModel.isValid(row)) { cellRenderer.setForeground(Color.black); } else { cellRenderer.setForeground(Color.red); @@ -437,12 +478,9 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan return hashSets.get(rowIndex).getHashSetName(); } - private boolean indexExists(int rowIndex) { + private boolean isValid(int rowIndex) { try { - if(hashSets.get(rowIndex) instanceof HashDb){ - return ((HashDb)(hashSets.get(rowIndex))).hasIndex(); - } - return false; + return hashSets.get(rowIndex).isValid(); } catch (TskCoreException ex) { Logger.getLogger(HashSetTableModel.class.getName()).log(Level.SEVERE, "Error getting index info for hash database", ex); //NON-NLS return false; @@ -541,6 +579,12 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan indexPathLabel = new javax.swing.JLabel(); addHashesToDatabaseButton = new javax.swing.JButton(); jButton1 = new javax.swing.JButton(); + versionLabel = new javax.swing.JLabel(); + hashDbVersionLabel = new javax.swing.JLabel(); + orgLabel = new javax.swing.JLabel(); + hashDbOrgLabel = new javax.swing.JLabel(); + readOnlyLabel = new javax.swing.JLabel(); + hashDbReadOnlyLabel = new javax.swing.JLabel(); jLabel2.setFont(jLabel2.getFont().deriveFont(jLabel2.getFont().getStyle() & ~java.awt.Font.BOLD, 11)); org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(HashLookupSettingsPanel.class, "HashLookupSettingsPanel.jLabel2.text")); // NOI18N @@ -686,6 +730,18 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan } }); + org.openide.awt.Mnemonics.setLocalizedText(versionLabel, org.openide.util.NbBundle.getMessage(HashLookupSettingsPanel.class, "HashLookupSettingsPanel.versionLabel.text_1")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(hashDbVersionLabel, org.openide.util.NbBundle.getMessage(HashLookupSettingsPanel.class, "HashLookupSettingsPanel.hashDbVersionLabel.text_1")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(orgLabel, org.openide.util.NbBundle.getMessage(HashLookupSettingsPanel.class, "HashLookupSettingsPanel.orgLabel.text_1")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(hashDbOrgLabel, org.openide.util.NbBundle.getMessage(HashLookupSettingsPanel.class, "HashLookupSettingsPanel.hashDbOrgLabel.text_1")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(readOnlyLabel, org.openide.util.NbBundle.getMessage(HashLookupSettingsPanel.class, "HashLookupSettingsPanel.readOnlyLabel.text_1")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(hashDbReadOnlyLabel, org.openide.util.NbBundle.getMessage(HashLookupSettingsPanel.class, "HashLookupSettingsPanel.hashDbReadOnlyLabel.text_1")); // NOI18N + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( @@ -703,43 +759,56 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan .addGap(309, 309, 309)) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addComponent(optionsLabel) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(optionsSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(10, 10, 10) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(locationLabel) - .addComponent(indexButton, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(typeLabel) - .addComponent(indexLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(indexPathLabelLabel)) - .addGap(10, 10, 10) + .addComponent(versionLabel) + .addComponent(orgLabel) + .addComponent(readOnlyLabel)) + .addGap(55, 55, 55) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(hashDbTypeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(hashDbLocationLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(indexPathLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(hashDbIndexStatusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(addHashesToDatabaseButton))) + .addComponent(hashDbVersionLabel) + .addComponent(hashDbOrgLabel) + .addComponent(hashDbReadOnlyLabel))) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(nameLabel) .addGap(53, 53, 53) - .addComponent(hashDbNameLabel)))) + .addComponent(hashDbNameLabel)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(indexLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(indexPathLabelLabel)) + .addGap(64, 64, 64) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(indexPathLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(hashDbIndexStatusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(indexButton, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(10, 10, 10) + .addComponent(addHashesToDatabaseButton)))) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(70, 70, 70) .addComponent(informationSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(jPanel1Layout.createSequentialGroup() - .addGap(25, 25, 25) - .addComponent(sendIngestMessagesCheckBox)) - .addGroup(jPanel1Layout.createSequentialGroup() - .addGap(10, 10, 10) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(ingestWarningLabel) - .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)))) - .addGap(50, 50, 50)))) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() + .addComponent(optionsLabel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(optionsSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addGap(25, 25, 25) + .addComponent(sendIngestMessagesCheckBox)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addGap(10, 10, 10) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(ingestWarningLabel) + .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE))))) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(hashDatabasesLabel) @@ -777,6 +846,18 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan .addComponent(locationLabel) .addComponent(hashDbLocationLabel)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(versionLabel) + .addComponent(hashDbVersionLabel)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(orgLabel) + .addComponent(hashDbOrgLabel)) + .addGap(7, 7, 7) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(readOnlyLabel) + .addComponent(hashDbReadOnlyLabel)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(indexPathLabelLabel) .addComponent(indexPathLabel)) @@ -784,11 +865,11 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(indexLabel) .addComponent(hashDbIndexStatusLabel)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(indexButton) .addComponent(addHashesToDatabaseButton)) - .addGap(18, 18, 18) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(optionsLabel) .addComponent(optionsSeparator, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) @@ -946,7 +1027,10 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan private javax.swing.JLabel hashDbIndexStatusLabel; private javax.swing.JLabel hashDbLocationLabel; private javax.swing.JLabel hashDbNameLabel; + private javax.swing.JLabel hashDbOrgLabel; + private javax.swing.JLabel hashDbReadOnlyLabel; private javax.swing.JLabel hashDbTypeLabel; + private javax.swing.JLabel hashDbVersionLabel; private javax.swing.JTable hashSetTable; private javax.swing.JButton importDatabaseButton; private javax.swing.JButton indexButton; @@ -968,7 +1052,10 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan private javax.swing.JLabel nameLabel; private javax.swing.JLabel optionsLabel; private javax.swing.JSeparator optionsSeparator; + private javax.swing.JLabel orgLabel; + private javax.swing.JLabel readOnlyLabel; private javax.swing.JCheckBox sendIngestMessagesCheckBox; private javax.swing.JLabel typeLabel; + private javax.swing.JLabel versionLabel; // End of variables declaration//GEN-END:variables } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.form b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.form index 30e4a099d5..4d2ada136b 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.form +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.form @@ -24,49 +24,45 @@ - + - - - - - - + + + - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + - - + @@ -81,16 +77,6 @@ - - - - - - - - - - @@ -111,5 +97,12 @@ + + + + + + + diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java index c5ceb255d5..54ab545820 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java @@ -33,12 +33,16 @@ import java.util.logging.Level; import javax.swing.JFrame; import javax.swing.JProgressBar; import javax.swing.SwingWorker; +import javax.swing.WindowConstants; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.Executors; import org.openide.util.NbBundle; import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttribute; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException; import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalFileInstance; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamOrganization; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; import org.sleuthkit.datamodel.TskCoreException; @@ -49,9 +53,7 @@ import org.sleuthkit.datamodel.TskData; */ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements PropertyChangeListener{ - - long totalHashes; - private SwingWorker worker; + private CentralRepoImportWorker worker; /** @@ -70,8 +72,14 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P super((JFrame) WindowManager.getDefault().getMainWindow(), Bundle.ImportCentralRepoDbProgressDialog_title_text(), true); - - initComponents(); + + initComponents(); + customizeComponents(); + } + + private void customizeComponents(){ + setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); + bnOk.setEnabled(false); } void importFile(String hashSetName, String version, int orgId, @@ -81,8 +89,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P File importFile = new File(importFileName); worker = new ImportIDXWorker(hashSetName, version, orgId, searchDuringIngest, sendIngestMessages, - knownFilesType, importFile, totalHashes); - totalHashes = ((ImportIDXWorker)worker).getEstimatedTotalHashes(); + knownFilesType, importFile); worker.addPropertyChangeListener(this); worker.execute(); @@ -91,16 +98,16 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P this.setVisible(true); } + @NbBundle.Messages({"ImportCentralRepoDbProgressDialog.linesProcessed= lines processed"}) @Override public void propertyChange(PropertyChangeEvent evt) { System.out.println("### Evt type: " + evt.getPropertyName()); System.out.println(" newValue: " + evt.getNewValue().toString()); - System.out.println("### Setting progress to " + worker.getProgress()); + System.out.println("### Setting progress to " + worker.getProgressPercentage()); if("progress".equals(evt.getPropertyName())){ - progressBar.setValue(worker.getProgress()); - String mes = "Count: " + worker.getProgress(); - lbProgress.setText(mes); + progressBar.setValue(worker.getProgressPercentage()); + lbProgress.setText(getProgressString()); } else if ("state".equals(evt.getPropertyName()) && (SwingWorker.StateValue.DONE.equals(evt.getNewValue()))) { // Disable cancel and enable ok @@ -108,12 +115,24 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P bnOk.setEnabled(true); progressBar.setValue(progressBar.getMaximum()); - String mes = "Count: " + worker.getProgress(); - lbProgress.setText(mes); + lbProgress.setText(getProgressString()); } } - class ImportIDXWorker extends SwingWorker{ + private String getProgressString(){ + return worker.getLinesProcessed() + Bundle.ImportCentralRepoDbProgressDialog_linesProcessed(); + } + + private interface CentralRepoImportWorker{ + + void execute(); + boolean cancel(boolean mayInterruptIfRunning); + void addPropertyChangeListener(PropertyChangeListener dialog); + int getProgressPercentage(); + long getLinesProcessed(); + } + + class ImportIDXWorker extends SwingWorker implements CentralRepoImportWorker{ private final int HASH_IMPORT_THRESHOLD = 10000; private final String hashSetName; @@ -125,10 +144,11 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P private final File importFile; private final long totalLines; private int crIndex = -1; + private AtomicLong numLines = new AtomicLong(); ImportIDXWorker(String hashSetName, String version, int orgId, boolean searchDuringIngest, boolean sendIngestMessages, HashDbManager.HashDb.KnownFilesType knownFilesType, - File importFile, long totalLines){ + File importFile){ this.hashSetName = hashSetName; this.version = version; @@ -137,7 +157,9 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P this.sendIngestMessages = sendIngestMessages; this.knownFilesType = knownFilesType; this.importFile = importFile; - this.totalLines = totalLines; + this.numLines.set(0); + + this.totalLines = getEstimatedTotalHashes(); } /** @@ -146,11 +168,31 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P * progress bar. * @return Approximate number of hashes in the file */ - long getEstimatedTotalHashes(){ + final long getEstimatedTotalHashes(){ long fileSize = importFile.length(); return (fileSize / 0x33); // IDX file lines are generally 0x33 bytes long } + @Override + public long getLinesProcessed(){ + return numLines.get(); + } + + @Override + public int getProgressPercentage(){ + return this.getProgress(); + } + + //@Override + //public void addPropertyChangeListener(PropertyChangeListener dialog){ + // super.addPropertyChangeListener(dialog); + //} + + //@Override + //public void run(){ + // this.execute(); + //} + @Override protected Void doInBackground() throws Exception { @@ -176,8 +218,10 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P String line; Set globalInstances = new HashSet<>(); - long numLines = 0; while ((line = reader.readLine()) != null) { + if(isCancelled()){ + return null; + } String[] parts = line.split("\\|"); @@ -193,13 +237,13 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P ""); globalInstances.add(eamGlobalFileInstance); - numLines++; + numLines.incrementAndGet(); - if(numLines % HASH_IMPORT_THRESHOLD == 0){ + if(numLines.get() % HASH_IMPORT_THRESHOLD == 0){ dbManager.bulkInsertReferenceTypeEntries(globalInstances, contentType); globalInstances.clear(); - int progress = (int)(numLines * 100 / totalLines); + int progress = (int)(numLines.get() * 100 / totalLines); if(progress < 100){ this.setProgress(progress); } else { @@ -218,28 +262,40 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P ex.printStackTrace(); throw new TskCoreException(ex.getLocalizedMessage()); } + } + + private void deleteIncompleteSet(int crIndex){ + if(crIndex >= 0){ + System.out.println("Deleting incomplete reference set"); + + // This can be slow on large reference sets + Executors.newSingleThreadExecutor().execute(new Runnable() { + @Override + public void run() { + try{ + EamDb.getInstance().deleteReferenceSet(crIndex); + } catch (EamDbException ex2){ - - // Let any external listeners know that there's a new set - //try { - // changeSupport.firePropertyChange(HashDbManager.SetEvt.DB_ADDED.toString(), null, hashSetName); - //} catch (Exception e) { - // logger.log(Level.SEVERE, "HashDbManager listener threw exception", e); //NON-NLS - // MessageNotifyUtil.Notify.show( - // NbBundle.getMessage(this.getClass(), "HashDbManager.moduleErr"), - // NbBundle.getMessage(this.getClass(), "HashDbManager.moduleErrorListeningToUpdatesMsg"), - // MessageNotifyUtil.MessageType.ERROR); - //} - //return hashDb; + } + } + }); + } } @Override protected void done() { + if(isCancelled()){ + // If the user hit cancel, delete this incomplete hash set from the central repo + deleteIncompleteSet(crIndex); + return; + } + try { get(); try{ System.out.println("### Finished - adding hashDb object"); - HashDbManager.CentralRepoHashDb hashDb = HashDbManager.getInstance().addExistingCentralRepoHashSet(hashSetName, version, crIndex, + HashDbManager.CentralRepoHashDb hashDb = HashDbManager.getInstance().addExistingCentralRepoHashSet(hashSetName, version, + crIndex, searchDuringIngest, sendIngestMessages, knownFilesType); } catch (TskCoreException ex){ System.out.println("\n### Error!"); @@ -248,7 +304,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P System.out.println("\n### Interrupted!"); - // If the user hit cancel, delete this incomplete hash set from the central repo + // Delete this incomplete hash set from the central repo if(crIndex >= 0){ try{ EamDb.getInstance().deleteReferenceSet(crIndex); @@ -257,7 +313,12 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P } } } - } + } + + //@Override + //public boolean cancel(boolean mayInterruptIfRunning) { + // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + //} } /** @@ -271,21 +332,14 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P progressBar = new javax.swing.JProgressBar(); lbProgress = new javax.swing.JLabel(); - jButton1 = new javax.swing.JButton(); bnOk = new javax.swing.JButton(); bnCancel = new javax.swing.JButton(); + jLabel1 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); org.openide.awt.Mnemonics.setLocalizedText(lbProgress, org.openide.util.NbBundle.getMessage(ImportCentralRepoDbProgressDialog.class, "ImportCentralRepoDbProgressDialog.lbProgress.text")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(ImportCentralRepoDbProgressDialog.class, "ImportCentralRepoDbProgressDialog.jButton1.text")); // NOI18N - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - org.openide.awt.Mnemonics.setLocalizedText(bnOk, org.openide.util.NbBundle.getMessage(ImportCentralRepoDbProgressDialog.class, "ImportCentralRepoDbProgressDialog.bnOk.text")); // NOI18N bnOk.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { @@ -300,55 +354,52 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P } }); + org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(ImportCentralRepoDbProgressDialog.class, "ImportCentralRepoDbProgressDialog.jLabel1.text")); // NOI18N + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addGap(27, 27, 27) + .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jButton1) - .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 346, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap(27, Short.MAX_VALUE)) + .addComponent(progressBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap()) .addGroup(layout.createSequentialGroup() - .addComponent(lbProgress) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(bnOk) - .addGap(18, 18, 18) - .addComponent(bnCancel) - .addGap(24, 24, 24)))) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel1) + .addComponent(lbProgress)) + .addGap(0, 172, Short.MAX_VALUE)))) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(bnOk, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(bnCancel) + .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(112, 112, 112) - .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(lbProgress) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 89, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(bnOk) - .addComponent(bnCancel)) - .addGap(72, 72, 72))) - .addComponent(jButton1) - .addGap(42, 42, 42)) + .addContainerGap() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(lbProgress) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(bnCancel) + .addComponent(bnOk)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// //GEN-END:initComponents - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - this.dispose(); - }//GEN-LAST:event_jButton1ActionPerformed - private void bnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnCancelActionPerformed this.worker.cancel(true); + this.dispose(); }//GEN-LAST:event_bnCancelActionPerformed private void bnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnOkActionPerformed @@ -359,7 +410,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton bnCancel; private javax.swing.JButton bnOk; - private javax.swing.JButton jButton1; + private javax.swing.JLabel jLabel1; private javax.swing.JLabel lbProgress; private javax.swing.JProgressBar progressBar; // End of variables declaration//GEN-END:variables From a01cc6addb94af3ccdefb6a8dc5addfbf4aefd7f Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Tue, 24 Oct 2017 14:31:36 -0400 Subject: [PATCH 12/41] Starting on combined import panel --- .../modules/hashdatabase/Bundle.properties | 7 + .../HashDbImportDatabaseDialog.form | 162 +++++++++++++++--- .../HashDbImportDatabaseDialog.java | 150 +++++++++++++--- 3 files changed, 269 insertions(+), 50 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties index d2e97172b9..9b7a0997eb 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties @@ -252,3 +252,10 @@ HashLookupSettingsPanel.hashDbOrgLabel.text_1=No database selected HashLookupSettingsPanel.readOnlyLabel.text_1=Read only: HashLookupSettingsPanel.hashDbReadOnlyLabel.text_1=No database selected ImportCentralRepoDbProgressDialog.jLabel1.text=Importing hash set into the central repository +HashDbImportDatabaseDialog.lbVersion.text=Version: +HashDbImportDatabaseDialog.lbOrg.text=Source Organization: +HashDbImportDatabaseDialog.readOnlyCheckbox.text=Make database read-only +HashDbImportDatabaseDialog.orgButton.text=Manage Organizations +HashDbImportDatabaseDialog.versionTextField.text= +HashDbImportDatabaseDialog.fileTypeRadioButton.text=File Type +HashDbImportDatabaseDialog.centralRepoRadioButton.text=Central Repository diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.form b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.form index 088b0001f4..23db36a970 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.form +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.form @@ -4,6 +4,8 @@ + + @@ -30,30 +32,48 @@ - - + + - + - - + + - + + + + + + + + + + + + + + + + + + + @@ -63,6 +83,7 @@ + @@ -74,6 +95,11 @@ + + + + + @@ -85,27 +111,33 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -215,5 +247,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java index f440b4e9ac..fe711ccc17 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java @@ -31,6 +31,7 @@ import javax.swing.filechooser.FileNameExtensionFilter; import org.apache.commons.io.FilenameUtils; import org.openide.util.NbBundle; import org.openide.windows.WindowManager; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.PlatformUtil; @@ -61,6 +62,7 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { true); initFileChooser(); initComponents(); + enableComponents(); display(); } @@ -96,6 +98,24 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { } return shortenedPath; } + + private void enableComponents(){ + + if(! EamDb.isEnabled()){ + centralRepoRadioButton.setEnabled(false); + fileTypeRadioButton.setSelected(true); + } + + boolean isFileType = fileTypeRadioButton.isSelected(); + + // Central repo only + lbVersion.setEnabled(! isFileType); + versionTextField.setEnabled(! isFileType); + lbOrg.setEnabled(! isFileType); + orgButton.setEnabled(! isFileType); + orgComboBox.setEnabled(! isFileType); + readOnlyCheckbox.setEnabled(! isFileType); + } /** * This method is called from within the constructor to initialize the form. @@ -107,6 +127,7 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { private void initComponents() { buttonGroup1 = new javax.swing.ButtonGroup(); + storageTypeButtonGroup = new javax.swing.ButtonGroup(); okButton = new javax.swing.JButton(); cancelButton = new javax.swing.JButton(); databasePathTextField = new javax.swing.JTextField(); @@ -118,6 +139,14 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { jLabel2 = new javax.swing.JLabel(); sendIngestMessagesCheckbox = new javax.swing.JCheckBox(); jLabel3 = new javax.swing.JLabel(); + lbVersion = new javax.swing.JLabel(); + versionTextField = new javax.swing.JTextField(); + lbOrg = new javax.swing.JLabel(); + orgComboBox = new javax.swing.JComboBox<>(); + orgButton = new javax.swing.JButton(); + readOnlyCheckbox = new javax.swing.JCheckBox(); + fileTypeRadioButton = new javax.swing.JRadioButton(); + centralRepoRadioButton = new javax.swing.JRadioButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); @@ -178,6 +207,36 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.jLabel3.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(lbVersion, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.lbVersion.text")); // NOI18N + + versionTextField.setText(org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.versionTextField.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(lbOrg, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.lbOrg.text")); // NOI18N + + orgComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); + + org.openide.awt.Mnemonics.setLocalizedText(orgButton, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.orgButton.text")); // NOI18N + + readOnlyCheckbox.setSelected(true); + org.openide.awt.Mnemonics.setLocalizedText(readOnlyCheckbox, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.readOnlyCheckbox.text")); // NOI18N + + storageTypeButtonGroup.add(fileTypeRadioButton); + fileTypeRadioButton.setSelected(true); + org.openide.awt.Mnemonics.setLocalizedText(fileTypeRadioButton, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.fileTypeRadioButton.text")); // NOI18N + fileTypeRadioButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + fileTypeRadioButtonActionPerformed(evt); + } + }); + + storageTypeButtonGroup.add(centralRepoRadioButton); + org.openide.awt.Mnemonics.setLocalizedText(centralRepoRadioButton, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.centralRepoRadioButton.text")); // NOI18N + centralRepoRadioButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + centralRepoRadioButtonActionPerformed(evt); + } + }); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( @@ -186,31 +245,46 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) + .addGap(0, 325, Short.MAX_VALUE) .addComponent(okButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cancelButton)) - .addGroup(layout.createSequentialGroup() + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addComponent(jLabel1) + .addGroup(layout.createSequentialGroup() + .addComponent(lbOrg) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(hashSetNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 303, Short.MAX_VALUE)) + .addComponent(orgComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(orgButton)) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(databasePathTextField))) + .addComponent(databasePathTextField)) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel1) + .addComponent(lbVersion)) + .addGap(2, 2, 2) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(versionTextField) + .addComponent(hashSetNameTextField)))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(openButton)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(fileTypeRadioButton) + .addGap(26, 26, 26) + .addComponent(centralRepoRadioButton)) .addComponent(jLabel2) .addGroup(layout.createSequentialGroup() .addGap(19, 19, 19) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(knownRadioButton) .addComponent(knownBadRadioButton))) - .addComponent(sendIngestMessagesCheckbox)) + .addComponent(sendIngestMessagesCheckbox) + .addComponent(readOnlyCheckbox)) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) ); @@ -221,6 +295,10 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(fileTypeRadioButton) + .addComponent(centralRepoRadioButton)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(openButton) .addComponent(databasePathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) @@ -229,23 +307,30 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(hashSetNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 119, Short.MAX_VALUE) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(okButton) - .addComponent(cancelButton)) - .addContainerGap()) - .addGroup(layout.createSequentialGroup() - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(jLabel2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(knownRadioButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(knownBadRadioButton) - .addGap(18, 18, 18) - .addComponent(sendIngestMessagesCheckbox) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(versionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(lbVersion)) + .addGap(9, 9, 9) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(orgButton) + .addComponent(orgComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(lbOrg)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(knownRadioButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(knownBadRadioButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(readOnlyCheckbox) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(sendIngestMessagesCheckbox) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(okButton) + .addComponent(cancelButton)) + .addContainerGap()) ); pack(); @@ -359,18 +444,35 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { // TODO add your handling code here: }//GEN-LAST:event_sendIngestMessagesCheckboxActionPerformed + private void fileTypeRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileTypeRadioButtonActionPerformed + enableComponents(); + }//GEN-LAST:event_fileTypeRadioButtonActionPerformed + + private void centralRepoRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_centralRepoRadioButtonActionPerformed + enableComponents(); + }//GEN-LAST:event_centralRepoRadioButtonActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.ButtonGroup buttonGroup1; private javax.swing.JButton cancelButton; + private javax.swing.JRadioButton centralRepoRadioButton; private javax.swing.JTextField databasePathTextField; + private javax.swing.JRadioButton fileTypeRadioButton; private javax.swing.JTextField hashSetNameTextField; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JRadioButton knownBadRadioButton; private javax.swing.JRadioButton knownRadioButton; + private javax.swing.JLabel lbOrg; + private javax.swing.JLabel lbVersion; private javax.swing.JButton okButton; private javax.swing.JButton openButton; + private javax.swing.JButton orgButton; + private javax.swing.JComboBox orgComboBox; + private javax.swing.JCheckBox readOnlyCheckbox; private javax.swing.JCheckBox sendIngestMessagesCheckbox; + private javax.swing.ButtonGroup storageTypeButtonGroup; + private javax.swing.JTextField versionTextField; // End of variables declaration//GEN-END:variables } From a492b8233763122955f6233e18758f58be707583 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Wed, 25 Oct 2017 11:48:33 -0400 Subject: [PATCH 13/41] Making org combo box work --- .../modules/hashdatabase/Bundle.properties | 1 + .../HashDbImportDatabaseDialog.form | 40 ++++++--- .../HashDbImportDatabaseDialog.java | 83 ++++++++++++++++--- 3 files changed, 104 insertions(+), 20 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties index 9b7a0997eb..082874b385 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties @@ -259,3 +259,4 @@ HashDbImportDatabaseDialog.orgButton.text=Manage Organizations HashDbImportDatabaseDialog.versionTextField.text= HashDbImportDatabaseDialog.fileTypeRadioButton.text=File Type HashDbImportDatabaseDialog.centralRepoRadioButton.text=Central Repository +HashDbImportDatabaseDialog.jLabel4.text=Type: diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.form b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.form index 23db36a970..a95893cc54 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.form +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.form @@ -47,11 +47,6 @@ - - - - - @@ -63,17 +58,28 @@ + + + + + + + + + + + + + + + + - - - - - @@ -99,6 +105,7 @@ + @@ -279,6 +286,9 @@ + + + @@ -289,6 +299,9 @@ + + + @@ -325,5 +338,12 @@ + + + + + + + diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java index fe711ccc17..a70eb5f36b 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java @@ -23,7 +23,9 @@ import java.awt.Toolkit; import java.io.File; import java.io.IOException; import java.nio.file.Paths; +import java.util.List; import java.util.logging.Level; +import javax.swing.JComboBox; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JOptionPane; @@ -32,6 +34,9 @@ import org.apache.commons.io.FilenameUtils; import org.openide.util.NbBundle; import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamOrganization; +import org.sleuthkit.autopsy.centralrepository.optionspanel.AddNewOrganizationDialog; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.PlatformUtil; @@ -50,6 +55,8 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { private String selectedFilePath = ""; private HashDatabase selectedHashDb = null; private final static String LAST_FILE_PATH_KEY = "HashDbImport_Path"; + private EamOrganization selectedOrg = null; + private List orgs = null; /** * Displays a dialog that allows a user to select an existing hash database @@ -116,6 +123,22 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { orgComboBox.setEnabled(! isFileType); readOnlyCheckbox.setEnabled(! isFileType); } + +private void populateCombobox() { + orgComboBox.removeAllItems(); + try { + EamDb dbManager = EamDb.getInstance(); + orgs = dbManager.getOrganizations(); + orgs.forEach((org) -> { + orgComboBox.addItem(org.getName()); + }); + if (!orgs.isEmpty()) { + selectedOrg = orgs.get(0); + } + } catch (EamDbException ex) { + //LOGGER.log(Level.SEVERE, "Failure populating combobox with organizations.", ex); + } + } /** * This method is called from within the constructor to initialize the form. @@ -147,6 +170,7 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { readOnlyCheckbox = new javax.swing.JCheckBox(); fileTypeRadioButton = new javax.swing.JRadioButton(); centralRepoRadioButton = new javax.swing.JRadioButton(); + jLabel4 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); @@ -214,8 +238,18 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { org.openide.awt.Mnemonics.setLocalizedText(lbOrg, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.lbOrg.text")); // NOI18N orgComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); + orgComboBox.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + orgComboBoxActionPerformed(evt); + } + }); org.openide.awt.Mnemonics.setLocalizedText(orgButton, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.orgButton.text")); // NOI18N + orgButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + orgButtonActionPerformed(evt); + } + }); readOnlyCheckbox.setSelected(true); org.openide.awt.Mnemonics.setLocalizedText(readOnlyCheckbox, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.readOnlyCheckbox.text")); // NOI18N @@ -237,6 +271,8 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { } }); + org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.jLabel4.text")); // NOI18N + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( @@ -257,10 +293,6 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { .addComponent(orgComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(orgButton)) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addComponent(jLabel3) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(databasePathTextField)) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) @@ -268,15 +300,23 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { .addGap(2, 2, 2) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(versionTextField) - .addComponent(hashSetNameTextField)))) + .addComponent(hashSetNameTextField))) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel3) + .addComponent(jLabel4)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(fileTypeRadioButton) + .addGap(26, 26, 26) + .addComponent(centralRepoRadioButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(databasePathTextField)))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(openButton)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(fileTypeRadioButton) - .addGap(26, 26, 26) - .addComponent(centralRepoRadioButton)) .addComponent(jLabel2) .addGroup(layout.createSequentialGroup() .addGap(19, 19, 19) @@ -297,7 +337,8 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(fileTypeRadioButton) - .addComponent(centralRepoRadioButton)) + .addComponent(centralRepoRadioButton) + .addComponent(jLabel4)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(openButton) @@ -452,6 +493,27 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { enableComponents(); }//GEN-LAST:event_centralRepoRadioButtonActionPerformed + private void orgButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orgButtonActionPerformed + AddNewOrganizationDialog dialogO = new AddNewOrganizationDialog(); + // update the combobox options + if (dialogO.isChanged()) { + populateCombobox(); + } + }//GEN-LAST:event_orgButtonActionPerformed + + private void orgComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orgComboBoxActionPerformed + JComboBox cb = (JComboBox)evt.getSource(); + String orgName = (String)cb.getSelectedItem(); + if (null == orgName) return; + + for (EamOrganization org : orgs) { + if (org.getName().equals(orgName)) { + selectedOrg = org; + return; + } + } + }//GEN-LAST:event_orgComboBoxActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.ButtonGroup buttonGroup1; private javax.swing.JButton cancelButton; @@ -462,6 +524,7 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; private javax.swing.JRadioButton knownBadRadioButton; private javax.swing.JRadioButton knownRadioButton; private javax.swing.JLabel lbOrg; From e84809f2e933e51f8447661084f17ff58ee9b7dd Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Thu, 26 Oct 2017 11:02:09 -0400 Subject: [PATCH 14/41] Starting validity checks for central repo import --- .../HashDbImportDatabaseDialog.form | 1 - .../HashDbImportDatabaseDialog.java | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.form b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.form index a95893cc54..931fd85d32 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.form +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.form @@ -69,7 +69,6 @@ - diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java index a70eb5f36b..d8ea186e51 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java @@ -422,6 +422,9 @@ private void populateCombobox() { this.dispose(); }//GEN-LAST:event_cancelButtonActionPerformed + @NbBundle.Messages({"HashDbImportDatabaseDialog.missingVersion=Read only", + "HashDbImportDatabaseDialog.missingOrg=Editable" + }) private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed // Note that the error handlers in this method call return without disposing of the // dialog to allow the user to try again, if desired. @@ -435,6 +438,21 @@ private void populateCombobox() { JOptionPane.ERROR_MESSAGE); return; } + + if(centralRepoRadioButton.isSelected()){ + if(versionTextField.getText().isEmpty()){ + // Bundle.HashLookupSettingsPanel_editable() + JOptionPane.showMessageDialog(this, + NbBundle.getMessage(this.getClass(), + "HashDbCreateDatabaseDialog.missingVersion"), + NbBundle.getMessage(this.getClass(), + "HashDbImportDatabaseDialog.importHashDbErr"), + JOptionPane.ERROR_MESSAGE); + return; + } + + + } if (selectedFilePath.isEmpty()) { JOptionPane.showMessageDialog(this, From c43c8548a176fa30495876202092b6540f8dd148 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Fri, 27 Oct 2017 09:29:40 -0400 Subject: [PATCH 15/41] Import central repo hash is functional --- .../HashDbImportDatabaseDialog.form | 7 +-- .../HashDbImportDatabaseDialog.java | 61 ++++++++++++------- .../ImportCentralRepoDbProgressDialog.java | 23 ++++--- 3 files changed, 56 insertions(+), 35 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.form b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.form index 931fd85d32..9a3c6acf89 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.form +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.form @@ -277,12 +277,7 @@ - - - - - - + diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java index d8ea186e51..d63020c9d9 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java @@ -108,9 +108,12 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { private void enableComponents(){ + if(! EamDb.isEnabled()){ centralRepoRadioButton.setEnabled(false); fileTypeRadioButton.setSelected(true); + } else { + populateCombobox(); } boolean isFileType = fileTypeRadioButton.isSelected(); @@ -124,7 +127,7 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { readOnlyCheckbox.setEnabled(! isFileType); } -private void populateCombobox() { + private void populateCombobox() { orgComboBox.removeAllItems(); try { EamDb dbManager = EamDb.getInstance(); @@ -136,6 +139,7 @@ private void populateCombobox() { selectedOrg = orgs.get(0); } } catch (EamDbException ex) { + ex.printStackTrace(); //LOGGER.log(Level.SEVERE, "Failure populating combobox with organizations.", ex); } } @@ -237,7 +241,6 @@ private void populateCombobox() { org.openide.awt.Mnemonics.setLocalizedText(lbOrg, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.lbOrg.text")); // NOI18N - orgComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); orgComboBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { orgComboBoxActionPerformed(evt); @@ -310,8 +313,7 @@ private void populateCombobox() { .addGroup(layout.createSequentialGroup() .addComponent(fileTypeRadioButton) .addGap(26, 26, 26) - .addComponent(centralRepoRadioButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(centralRepoRadioButton)) .addComponent(databasePathTextField)))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(openButton)) @@ -422,8 +424,8 @@ private void populateCombobox() { this.dispose(); }//GEN-LAST:event_cancelButtonActionPerformed - @NbBundle.Messages({"HashDbImportDatabaseDialog.missingVersion=Read only", - "HashDbImportDatabaseDialog.missingOrg=Editable" + @NbBundle.Messages({"HashDbImportDatabaseDialog.missingVersion=A version must be entered", + "HashDbImportDatabaseDialog.missingOrg=An organization must be selected" }) private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed // Note that the error handlers in this method call return without disposing of the @@ -441,18 +443,25 @@ private void populateCombobox() { if(centralRepoRadioButton.isSelected()){ if(versionTextField.getText().isEmpty()){ - // Bundle.HashLookupSettingsPanel_editable() JOptionPane.showMessageDialog(this, NbBundle.getMessage(this.getClass(), - "HashDbCreateDatabaseDialog.missingVersion"), + "HashDbImportDatabaseDialog.missingVersion"), NbBundle.getMessage(this.getClass(), "HashDbImportDatabaseDialog.importHashDbErr"), JOptionPane.ERROR_MESSAGE); return; } - - } + if(selectedOrg == null){ + JOptionPane.showMessageDialog(this, + NbBundle.getMessage(this.getClass(), + "HashDbImportDatabaseDialog.missingOrg"), + NbBundle.getMessage(this.getClass(), + "HashDbImportDatabaseDialog.importHashDbErr"), + JOptionPane.ERROR_MESSAGE); + return; + } + } if (selectedFilePath.isEmpty()) { JOptionPane.showMessageDialog(this, @@ -482,18 +491,26 @@ private void populateCombobox() { } String errorMessage = NbBundle.getMessage(this.getClass(), - "HashDbImportDatabaseDialog.errorMessage.failedToOpenHashDbMsg", - selectedFilePath); - try { - selectedHashDb = HashDbManager.getInstance().addExistingFileTypeHashDatabase(hashSetNameTextField.getText(), selectedFilePath, true, sendIngestMessagesCheckbox.isSelected(), type); - } catch (HashDbManagerException ex) { - Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.WARNING, errorMessage, ex); - JOptionPane.showMessageDialog(this, - ex.getMessage(), - NbBundle.getMessage(this.getClass(), - "HashDbImportDatabaseDialog.importHashDbErr"), - JOptionPane.ERROR_MESSAGE); - return; + "HashDbImportDatabaseDialog.errorMessage.failedToOpenHashDbMsg", + selectedFilePath); + if(fileTypeRadioButton.isSelected()){ + + try { + selectedHashDb = HashDbManager.getInstance().addExistingFileTypeHashDatabase(hashSetNameTextField.getText(), selectedFilePath, true, sendIngestMessagesCheckbox.isSelected(), type); + } catch (HashDbManagerException ex) { + Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.WARNING, errorMessage, ex); + JOptionPane.showMessageDialog(this, + ex.getMessage(), + NbBundle.getMessage(this.getClass(), + "HashDbImportDatabaseDialog.importHashDbErr"), + JOptionPane.ERROR_MESSAGE); + return; + } + } else { + ImportCentralRepoDbProgressDialog progressDialog = new ImportCentralRepoDbProgressDialog(); + progressDialog.importFile(hashSetNameTextField.getText(), versionTextField.getText(), + selectedOrg.getOrgID(), true, sendIngestMessagesCheckbox.isSelected(), type, selectedFilePath); + selectedHashDb = progressDialog.getDatabase(); } dispose(); diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java index 54ab545820..24b42f0309 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java @@ -98,6 +98,13 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P this.setVisible(true); } + HashDbManager.HashDatabase getDatabase(){ + if(worker != null){ + return worker.getDatabase(); + } + return null; + } + @NbBundle.Messages({"ImportCentralRepoDbProgressDialog.linesProcessed= lines processed"}) @Override public void propertyChange(PropertyChangeEvent evt) { @@ -130,6 +137,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P void addPropertyChangeListener(PropertyChangeListener dialog); int getProgressPercentage(); long getLinesProcessed(); + HashDbManager.HashDatabase getDatabase(); } class ImportIDXWorker extends SwingWorker implements CentralRepoImportWorker{ @@ -144,7 +152,8 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P private final File importFile; private final long totalLines; private int crIndex = -1; - private AtomicLong numLines = new AtomicLong(); + private HashDbManager.CentralRepoHashDb newHashDb = null; + private final AtomicLong numLines = new AtomicLong(); ImportIDXWorker(String hashSetName, String version, int orgId, boolean searchDuringIngest, boolean sendIngestMessages, HashDbManager.HashDb.KnownFilesType knownFilesType, @@ -173,6 +182,11 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P return (fileSize / 0x33); // IDX file lines are generally 0x33 bytes long } + @Override + public HashDbManager.HashDatabase getDatabase(){ + return newHashDb; + } + @Override public long getLinesProcessed(){ return numLines.get(); @@ -294,7 +308,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P get(); try{ System.out.println("### Finished - adding hashDb object"); - HashDbManager.CentralRepoHashDb hashDb = HashDbManager.getInstance().addExistingCentralRepoHashSet(hashSetName, version, + newHashDb = HashDbManager.getInstance().addExistingCentralRepoHashSet(hashSetName, version, crIndex, searchDuringIngest, sendIngestMessages, knownFilesType); } catch (TskCoreException ex){ @@ -314,11 +328,6 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P } } } - - //@Override - //public boolean cancel(boolean mayInterruptIfRunning) { - // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - //} } /** From b458d005076b425e671b30d63637ffa2a78fdc5f Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Fri, 27 Oct 2017 13:36:59 -0400 Subject: [PATCH 16/41] Store read only flag and database type in central repo. --- .../datamodel/AbstractSqlEamDb.java | 49 +++++++++++++++++-- .../centralrepository/datamodel/EamDb.java | 13 ++++- .../datamodel/EamGlobalSet.java | 40 ++++++++++++++- .../datamodel/SqliteEamDb.java | 17 +++++++ .../datamodel/SqliteEamDbSettings.java | 2 + .../ImportCentralRepoDatabaseDialog.java | 4 +- .../modules/hashdatabase/HashDbManager.java | 45 +++++++++++++++-- .../ImportCentralRepoDatabaseDialog.java | 5 +- 8 files changed, 162 insertions(+), 13 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java index bceb4c4cd7..f90f7b26ef 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java @@ -36,6 +36,7 @@ import java.util.Set; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager; import org.sleuthkit.datamodel.TskData; /** @@ -1501,12 +1502,15 @@ public abstract class AbstractSqlEamDb implements EamDb { * @throws EamDbException */ @Override - public int newReferenceSet(int orgID, String setName, String version) throws EamDbException { + public int newReferenceSet(int orgID, String setName, String version, TskData.FileKnown knownStatus, + boolean isReadOnly) throws EamDbException { EamDb dbManager = EamDb.getInstance(); EamGlobalSet eamGlobalSet = new EamGlobalSet( orgID, setName, version, + knownStatus, + isReadOnly, LocalDate.now()); return dbManager.newReferencelSet(eamGlobalSet); } @@ -1527,15 +1531,17 @@ public abstract class AbstractSqlEamDb implements EamDb { PreparedStatement preparedStatement1 = null; PreparedStatement preparedStatement2 = null; ResultSet resultSet = null; - String sql1 = "INSERT INTO reference_sets(org_id, set_name, version, import_date) VALUES (?, ?, ?, ?)"; - String sql2 = "SELECT id FROM reference_sets WHERE org_id=? AND set_name=? AND version=? AND import_date=? LIMIT 1"; + String sql1 = "INSERT INTO reference_sets(org_id, set_name, version, known_status, read_only, import_date) VALUES (?, ?, ?, ?)"; + String sql2 = "SELECT id FROM reference_sets WHERE org_id=? AND set_name=? AND version=? AND read_only=? AND known_status=? AND import_date=? LIMIT 1"; try { preparedStatement1 = conn.prepareStatement(sql1); preparedStatement1.setInt(1, eamGlobalSet.getOrgID()); preparedStatement1.setString(2, eamGlobalSet.getSetName()); preparedStatement1.setString(3, eamGlobalSet.getVersion()); - preparedStatement1.setString(4, eamGlobalSet.getImportDate().toString()); + preparedStatement1.setInt(4, eamGlobalSet.getKnownStatus().getFileKnownValue()); + preparedStatement1.setBoolean(5, eamGlobalSet.isReadOnly()); + preparedStatement1.setString(6, eamGlobalSet.getImportDate().toString()); preparedStatement1.executeUpdate(); @@ -1591,6 +1597,39 @@ public abstract class AbstractSqlEamDb implements EamDb { EamDbUtil.closeConnection(conn); } } + + /** + * Get all reference sets + * + * @return The global set associated with the ID + * + * @throws EamDbException + */ + @Override + public List getAllReferenceSets() throws EamDbException{ + List results = new ArrayList<>(); + Connection conn = connect(); + + PreparedStatement preparedStatement1 = null; + ResultSet resultSet = null; + String sql1 = "SELECT * FROM reference_sets"; + + try { + preparedStatement1 = conn.prepareStatement(sql1); + resultSet = preparedStatement1.executeQuery(); + while (resultSet.next()) { + results.add(getEamGlobalSetFromResultSet(resultSet)); + } + + } catch (SQLException ex) { + throw new EamDbException("Error getting reference sets.", ex); // NON-NLS + } finally { + EamDbUtil.closePreparedStatement(preparedStatement1); + EamDbUtil.closeResultSet(resultSet); + EamDbUtil.closeConnection(conn); + } + return results; + } /** * Add a new reference instance @@ -2084,6 +2123,8 @@ public abstract class AbstractSqlEamDb implements EamDb { resultSet.getInt("org_id"), resultSet.getString("set_name"), resultSet.getString("version"), + TskData.FileKnown.valueOf(resultSet.getByte("known_status")), + resultSet.getBoolean("read_only"), LocalDate.parse(resultSet.getString("import_date")) ); diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java index 4ad2033dbf..909b6dc875 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Set; import org.sleuthkit.datamodel.TskData; import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager; /** * Main interface for interacting with the database @@ -447,7 +448,8 @@ public interface EamDb { * @return The ID of the new global set * @throws EamDbException */ - int newReferenceSet(int orgID, String setName, String version) throws EamDbException; + int newReferenceSet(int orgID, String setName, String version, TskData.FileKnown knownStatus, + boolean isReadOnly) throws EamDbException; /** * Get a global set by ID @@ -459,6 +461,15 @@ public interface EamDb { * @throws EamDbException */ EamGlobalSet getReferenceSetByID(int globalSetID) throws EamDbException; + + /** + * Get all reference sets + * + * @return The global set associated with the ID + * + * @throws EamDbException + */ + List getAllReferenceSets() throws EamDbException; /** * Add a new reference instance diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalSet.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalSet.java index 21b4bd282c..13525c00db 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalSet.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalSet.java @@ -19,6 +19,8 @@ package org.sleuthkit.autopsy.centralrepository.datamodel; import java.time.LocalDate; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager; +import org.sleuthkit.datamodel.TskData; /** * A global set in the Central Repository database @@ -29,6 +31,8 @@ public class EamGlobalSet { private int orgID; private String setName; private String version; + private TskData.FileKnown knownStatus; + private boolean isReadOnly; private LocalDate importDate; public EamGlobalSet( @@ -36,11 +40,15 @@ public class EamGlobalSet { int orgID, String setName, String version, + TskData.FileKnown knownStatus, + boolean isReadOnly, LocalDate importDate) { this.globalSetID = globalSetID; this.orgID = orgID; this.setName = setName; this.version = version; + this.knownStatus = knownStatus; + this.isReadOnly = isReadOnly; this.importDate = importDate; } @@ -48,8 +56,10 @@ public class EamGlobalSet { int orgID, String setName, String version, + TskData.FileKnown knownStatus, + boolean isReadOnly, LocalDate importDate) { - this(-1, orgID, setName, version, importDate); + this(-1, orgID, setName, version, knownStatus, isReadOnly, importDate); } /** @@ -107,6 +117,34 @@ public class EamGlobalSet { public void setVersion(String version) { this.version = version; } + + /** + * @return whether it is read only + */ + public boolean isReadOnly() { + return isReadOnly; + } + + /** + * @param isReadOnly + */ + public void setReadOnly(boolean isReadOnly) { + this.isReadOnly = isReadOnly; + } + + /** + * @return the known status + */ + public TskData.FileKnown getKnownStatus() { + return knownStatus; + } + + /** + * @param knownStatus the known status to set + */ + public void setKnownStatus(TskData.FileKnown knownStatus) { + this.knownStatus = knownStatus; + } /** * @return the importDate diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java index ede91676f8..a7bcdc98ec 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java @@ -792,6 +792,23 @@ public class SqliteEamDb extends AbstractSqlEamDb { } } + /** + * Get all reference sets + * + * @return The global set associated with the ID + * + * @throws EamDbException + */ + @Override + public List getAllReferenceSets() throws EamDbException{ + try{ + acquireSharedLock(); + return super.getAllReferenceSets(); + } finally { + releaseSharedLock(); + } + } + /** * Add a new reference instance * diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDbSettings.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDbSettings.java index 6deb5145e8..fa50118924 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDbSettings.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDbSettings.java @@ -311,6 +311,8 @@ public final class SqliteEamDbSettings { createReferenceSetsTable.append("org_id integer NOT NULL,"); createReferenceSetsTable.append("set_name text NOT NULL,"); createReferenceSetsTable.append("version text NOT NULL,"); + createReferenceSetsTable.append("known_status integer NOT NULL,"); + createReferenceSetsTable.append("read_only boolean NOT NULL,"); createReferenceSetsTable.append("import_date text NOT NULL,"); createReferenceSetsTable.append("foreign key (org_id) references organizations(id) ON UPDATE SET NULL ON DELETE SET NULL,"); createReferenceSetsTable.append("CONSTRAINT hash_set_unique UNIQUE (set_name, version)"); diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportCentralRepoDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportCentralRepoDatabaseDialog.java index 4223b4b359..39def95529 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportCentralRepoDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportCentralRepoDatabaseDialog.java @@ -472,12 +472,14 @@ final public class ImportCentralRepoDatabaseDialog extends javax.swing.JDialog { */ private int createGlobalSet() throws EamDbException { EamDb dbManager = EamDb.getInstance(); + /* EamGlobalSet eamGlobalSet = new EamGlobalSet( selectedOrg.getOrgID(), tfDatabaseName.getText().trim(), tfDatabaseVersion.getText().trim(), LocalDate.now()); - return dbManager.newReferencelSet(eamGlobalSet); + return dbManager.newReferencelSet(eamGlobalSet);*/ + return 0; } @Messages({"ImportHashDatabaseDialog.createGlobalSet.failedMsg.text=Failed to store attribution details.", diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index 8ade7d699e..6e668ad4c8 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -47,6 +47,8 @@ import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttribute; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException; import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalFileInstance; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalSet; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamOrganization; import org.sleuthkit.autopsy.centralrepository.optionspanel.ImportCentralRepoDatabaseDialog; import org.sleuthkit.autopsy.core.RuntimeProperties; import org.sleuthkit.autopsy.coreutils.Logger; @@ -649,6 +651,24 @@ public class HashDbManager implements PropertyChangeListener { } return updateableDbs; } + + private List getCentralRepoHashSetsFromDatabase(){ + List crHashSets = new ArrayList<>(); + if(EamDb.isEnabled()){ + try{ + List crSets = EamDb.getInstance().getAllReferenceSets(); + for(EamGlobalSet globalSet:crSets){ + EamOrganization org = EamDb.getInstance().getOrganizationByID(globalSet.getOrgID()); + // TEMP TEMP FIX + crHashSets.add(new HashDbInfo(globalSet.getSetName(), globalSet.getVersion(), org.getName(), + globalSet.getGlobalSetID(), HashDbManager.HashDb.KnownFilesType.KNOWN_BAD, true, true)); + } + } catch (EamDbException ex){ + ex.printStackTrace(); + } + } + return crHashSets; + } /** * Restores the last saved hash sets configuration. This supports @@ -702,11 +722,28 @@ public class HashDbManager implements PropertyChangeListener { logger.log(Level.WARNING, Bundle.HashDbManager_noDbPath_message(hashDbInfo.getHashSetName())); allDatabasesLoadedCorrectly = false; } - } else { - addExistingCentralRepoHashSet(hashDbInfo.getHashSetName(), hashDbInfo.getVersion(), + }// else { + // addExistingCentralRepoHashSet(hashDbInfo.getHashSetName(), hashDbInfo.getVersion(), + // hashDbInfo.getCentralRepoIndex(), + // hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), hashDbInfo.getKnownFilesType()); + //} + } catch (TskCoreException ex) { + Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error opening hash database", ex); //NON-NLS + JOptionPane.showMessageDialog(null, + NbBundle.getMessage(this.getClass(), + "HashDbManager.unableToOpenHashDbMsg", hashDbInfo.getHashSetName()), + NbBundle.getMessage(this.getClass(), "HashDbManager.openHashDbErr"), + JOptionPane.ERROR_MESSAGE); + allDatabasesLoadedCorrectly = false; + } + } + + List crHashDbInfoList = this.getCentralRepoHashSetsFromDatabase(); + for(HashDbInfo hashDbInfo : crHashDbInfoList) { + try{ + addExistingCentralRepoHashSet(hashDbInfo.getHashSetName(), hashDbInfo.getVersion(), hashDbInfo.getCentralRepoIndex(), - hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), hashDbInfo.getKnownFilesType()); - } + hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), hashDbInfo.getKnownFilesType()); } catch (TskCoreException ex) { Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error opening hash database", ex); //NON-NLS JOptionPane.showMessageDialog(null, diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.java index c10db21c7c..242f7c3a80 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.java @@ -475,13 +475,14 @@ final public class ImportCentralRepoDatabaseDialog extends javax.swing.JDialog { * @throws EamDbException */ private int createGlobalSet() throws EamDbException { - EamDb dbManager = EamDb.getInstance(); + /*EamDb dbManager = EamDb.getInstance(); EamGlobalSet eamGlobalSet = new EamGlobalSet( selectedOrg.getOrgID(), tfDatabaseName.getText().trim(), tfDatabaseVersion.getText().trim(), LocalDate.now()); - return dbManager.newReferencelSet(eamGlobalSet); + return dbManager.newReferencelSet(eamGlobalSet);*/ + return 0; } @Messages({"ImportHashDatabaseDialog.createGlobalSet.failedMsg.text=Failed to store attribution details.", From ac6b4e68eee49d2b96b86dee1cf1386bdc2b8d64 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Mon, 30 Oct 2017 15:35:50 -0400 Subject: [PATCH 17/41] Added read only and known status to central repo. Got organization display working. --- .../datamodel/AbstractSqlEamDb.java | 19 +++- .../centralrepository/datamodel/EamDb.java | 8 ++ .../datamodel/EamGlobalSet.java | 23 ++-- .../datamodel/PostgresEamDbSettings.java | 2 + .../datamodel/SqliteEamDb.java | 2 +- .../autopsy/filesearch/FileSearchDialog.java | 2 +- .../HashDbImportDatabaseDialog.java | 3 +- .../modules/hashdatabase/HashDbManager.java | 102 ++++++++++++++---- .../hashdatabase/HashLookupModuleFactory.java | 2 +- .../HashLookupModuleSettingsPanel.java | 5 + .../hashdatabase/HashLookupSettings.java | 34 +++--- .../hashdatabase/HashLookupSettingsPanel.java | 20 ++++ .../ImportCentralRepoDatabaseDialog.java | 4 +- .../ImportCentralRepoDbProgressDialog.java | 26 ++--- 14 files changed, 189 insertions(+), 63 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java index f90f7b26ef..e36aca5c89 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java @@ -1491,6 +1491,19 @@ public abstract class AbstractSqlEamDb implements EamDb { } } + /** + * Get the organization associated with the given reference set. + * @param globalSetID ID of the reference set + * @return The organization object + * @throws EamDbException + */ + @Override + public EamOrganization getReferenceSetOrganization(int globalSetID) throws EamDbException{ + + EamGlobalSet globalSet = getReferenceSetByID(globalSetID); + return (getOrganizationByID(globalSet.getOrgID())); + } + /** * Add a new Global Set * @@ -1531,15 +1544,15 @@ public abstract class AbstractSqlEamDb implements EamDb { PreparedStatement preparedStatement1 = null; PreparedStatement preparedStatement2 = null; ResultSet resultSet = null; - String sql1 = "INSERT INTO reference_sets(org_id, set_name, version, known_status, read_only, import_date) VALUES (?, ?, ?, ?)"; - String sql2 = "SELECT id FROM reference_sets WHERE org_id=? AND set_name=? AND version=? AND read_only=? AND known_status=? AND import_date=? LIMIT 1"; + String sql1 = "INSERT INTO reference_sets(org_id, set_name, version, known_status, read_only, import_date) VALUES (?, ?, ?, ?, ?, ?)"; + String sql2 = "SELECT id FROM reference_sets WHERE org_id=? AND set_name=? AND version=? AND import_date=? LIMIT 1"; try { preparedStatement1 = conn.prepareStatement(sql1); preparedStatement1.setInt(1, eamGlobalSet.getOrgID()); preparedStatement1.setString(2, eamGlobalSet.getSetName()); preparedStatement1.setString(3, eamGlobalSet.getVersion()); - preparedStatement1.setInt(4, eamGlobalSet.getKnownStatus().getFileKnownValue()); + preparedStatement1.setInt(4, eamGlobalSet.getFileKnownStatus().getFileKnownValue()); preparedStatement1.setBoolean(5, eamGlobalSet.isReadOnly()); preparedStatement1.setString(6, eamGlobalSet.getImportDate().toString()); diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java index 909b6dc875..1d2f3d858e 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java @@ -427,6 +427,14 @@ public interface EamDb { */ EamOrganization getOrganizationByID(int orgID) throws EamDbException; + /** + * Get the organization associated with the given reference set. + * @param globalSetID ID of the reference set + * @return The organization object + * @throws EamDbException + */ + EamOrganization getReferenceSetOrganization(int globalSetID) throws EamDbException; + /** * Add a new Global Set * diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalSet.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalSet.java index 13525c00db..e4292dc6ca 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalSet.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalSet.java @@ -31,7 +31,7 @@ public class EamGlobalSet { private int orgID; private String setName; private String version; - private TskData.FileKnown knownStatus; + private TskData.FileKnown fileKnownStatus; private boolean isReadOnly; private LocalDate importDate; @@ -47,7 +47,7 @@ public class EamGlobalSet { this.orgID = orgID; this.setName = setName; this.version = version; - this.knownStatus = knownStatus; + this.fileKnownStatus = knownStatus; this.isReadOnly = isReadOnly; this.importDate = importDate; } @@ -135,15 +135,26 @@ public class EamGlobalSet { /** * @return the known status */ - public TskData.FileKnown getKnownStatus() { - return knownStatus; + public TskData.FileKnown getFileKnownStatus() { + return fileKnownStatus; } /** * @param knownStatus the known status to set */ - public void setKnownStatus(TskData.FileKnown knownStatus) { - this.knownStatus = knownStatus; + public void setFileKnownStatus(TskData.FileKnown fileKnownStatus) { + this.fileKnownStatus = fileKnownStatus; + } + + /** + * Return the FileKnown status as a KnownFilesType + * @return KNOWN or KNOWN_BAD + */ + public HashDbManager.HashDb.KnownFilesType getKnownStatus(){ + if(fileKnownStatus.equals(TskData.FileKnown.BAD)){ + return HashDbManager.HashDb.KnownFilesType.KNOWN_BAD; + } + return HashDbManager.HashDb.KnownFilesType.KNOWN; } /** diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/PostgresEamDbSettings.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/PostgresEamDbSettings.java index 461a499663..6179a58342 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/PostgresEamDbSettings.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/PostgresEamDbSettings.java @@ -370,6 +370,8 @@ public final class PostgresEamDbSettings { createReferenceSetsTable.append("org_id integer NOT NULL,"); createReferenceSetsTable.append("set_name text NOT NULL,"); createReferenceSetsTable.append("version text NOT NULL,"); + createReferenceSetsTable.append("known_status integer NOT NULL,"); + createReferenceSetsTable.append("read_only boolean NOT NULL,"); createReferenceSetsTable.append("import_date text NOT NULL,"); createReferenceSetsTable.append("foreign key (org_id) references organizations(id) ON UPDATE SET NULL ON DELETE SET NULL,"); createReferenceSetsTable.append("CONSTRAINT hash_set_unique UNIQUE (set_name, version)"); diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java index a7bcdc98ec..8691a53186 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java @@ -752,7 +752,7 @@ public class SqliteEamDb extends AbstractSqlEamDb { } finally { releaseSharedLock(); } - } + } /** * Add a new Global Set diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchDialog.java b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchDialog.java index 66cca80df1..a66e49aa2a 100755 --- a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchDialog.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchDialog.java @@ -57,7 +57,7 @@ class FileSearchDialog extends javax.swing.JDialog { @Override public void actionPerformed(ActionEvent e) { dispose(); - } + } }); } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java index d63020c9d9..6e208a9475 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java @@ -509,7 +509,8 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { } else { ImportCentralRepoDbProgressDialog progressDialog = new ImportCentralRepoDbProgressDialog(); progressDialog.importFile(hashSetNameTextField.getText(), versionTextField.getText(), - selectedOrg.getOrgID(), true, sendIngestMessagesCheckbox.isSelected(), type, selectedFilePath); + selectedOrg.getOrgID(), true, sendIngestMessagesCheckbox.isSelected(), type, + this.readOnlyCheckbox.isSelected(), selectedFilePath); selectedHashDb = progressDialog.getDatabase(); } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index 6e668ad4c8..c9ba9b70ad 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -302,14 +302,15 @@ public class HashDbManager implements PropertyChangeListener { } public CentralRepoHashDb addExistingCentralRepoHashSet(String hashSetName, String version, int centralRepoIndex, - boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws TskCoreException{ + boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType, + boolean readOnly) throws TskCoreException{ if(! EamDb.isEnabled()){ throw new TskCoreException("Could not load central repository database " + hashSetName + " - central repository is not enabled"); } CentralRepoHashDb db = new CentralRepoHashDb(hashSetName, version, centralRepoIndex, searchDuringIngest, - sendIngestMessages, knownFilesType); + sendIngestMessages, knownFilesType, readOnly); if(! db.isValid()){ throw new TskCoreException("Error finding database " + hashSetName + " in central repository"); @@ -559,6 +560,20 @@ public class HashDbManager implements PropertyChangeListener { hashDbs.addAll(this.hashSets); return hashDbs; } + + /** + * Adds any new central repository databases to the list of hashes + * before returning a copy of the hash set list + * @return A list, possibly empty, of hash databases. + */ + public synchronized List refreshAndGetAllHashDatabases(){ + try{ + updateHashSetsFromCentralRepository(); + } catch (TskCoreException ex){ + Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error loading central repository hash sets", ex); //NON-NLS + } + return getAllHashDatabases(); + } /** * Gets all of the hash databases used to classify files as known. @@ -658,10 +673,13 @@ public class HashDbManager implements PropertyChangeListener { try{ List crSets = EamDb.getInstance().getAllReferenceSets(); for(EamGlobalSet globalSet:crSets){ - EamOrganization org = EamDb.getInstance().getOrganizationByID(globalSet.getOrgID()); - // TEMP TEMP FIX - crHashSets.add(new HashDbInfo(globalSet.getSetName(), globalSet.getVersion(), org.getName(), - globalSet.getGlobalSetID(), HashDbManager.HashDb.KnownFilesType.KNOWN_BAD, true, true)); + + // Defaults for fields not stored in the central repository: + // searchDuringIngest: false + // sendIngestMessages: true if the hash set is notable + boolean sendIngestMessages = globalSet.getKnownStatus().equals(HashDb.KnownFilesType.KNOWN_BAD); + crHashSets.add(new HashDbInfo(globalSet.getSetName(), globalSet.getVersion(), + globalSet.getGlobalSetID(), globalSet.getKnownStatus(), globalSet.isReadOnly(), false, sendIngestMessages)); } } catch (EamDbException ex){ ex.printStackTrace(); @@ -708,7 +726,8 @@ public class HashDbManager implements PropertyChangeListener { * * @param settings The settings to configure. */ - @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}", + "HashDbManager.centralRepoLoadError.message=Error loading central repository hash sets"}) private void configureSettings(HashLookupSettings settings) { allDatabasesLoadedCorrectly = true; List hashDbInfoList = settings.getHashDbInfo(); @@ -722,11 +741,14 @@ public class HashDbManager implements PropertyChangeListener { logger.log(Level.WARNING, Bundle.HashDbManager_noDbPath_message(hashDbInfo.getHashSetName())); allDatabasesLoadedCorrectly = false; } - }// else { - // addExistingCentralRepoHashSet(hashDbInfo.getHashSetName(), hashDbInfo.getVersion(), - // hashDbInfo.getCentralRepoIndex(), - // hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), hashDbInfo.getKnownFilesType()); - //} + } else { + if(EamDb.isEnabled()){ + addExistingCentralRepoHashSet(hashDbInfo.getHashSetName(), hashDbInfo.getVersion(), + hashDbInfo.getCentralRepoIndex(), + hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), + hashDbInfo.getKnownFilesType(), hashDbInfo.isReadOnly()); + } + } } catch (TskCoreException ex) { Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error opening hash database", ex); //NON-NLS JOptionPane.showMessageDialog(null, @@ -738,17 +760,14 @@ public class HashDbManager implements PropertyChangeListener { } } - List crHashDbInfoList = this.getCentralRepoHashSetsFromDatabase(); - for(HashDbInfo hashDbInfo : crHashDbInfoList) { + if(EamDb.isEnabled()){ try{ - addExistingCentralRepoHashSet(hashDbInfo.getHashSetName(), hashDbInfo.getVersion(), - hashDbInfo.getCentralRepoIndex(), - hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), hashDbInfo.getKnownFilesType()); - } catch (TskCoreException ex) { + updateHashSetsFromCentralRepository(); + } catch (TskCoreException ex){ Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error opening hash database", ex); //NON-NLS + JOptionPane.showMessageDialog(null, - NbBundle.getMessage(this.getClass(), - "HashDbManager.unableToOpenHashDbMsg", hashDbInfo.getHashSetName()), + Bundle.HashDbManager_centralRepoLoadError_message(), NbBundle.getMessage(this.getClass(), "HashDbManager.openHashDbErr"), JOptionPane.ERROR_MESSAGE); allDatabasesLoadedCorrectly = false; @@ -772,6 +791,29 @@ public class HashDbManager implements PropertyChangeListener { } } } + + void updateHashSetsFromCentralRepository() throws TskCoreException { + if(EamDb.isEnabled()){ + List crHashDbInfoList = getCentralRepoHashSetsFromDatabase(); + for(HashDbInfo hashDbInfo : crHashDbInfoList) { + if(hashDbInfoIsNew(hashDbInfo)){ + addExistingCentralRepoHashSet(hashDbInfo.getHashSetName(), hashDbInfo.getVersion(), + hashDbInfo.getCentralRepoIndex(), + hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), hashDbInfo.getKnownFilesType(), + hashDbInfo.isReadOnly()); + } + } + } + } + + private boolean hashDbInfoIsNew(HashDbInfo dbInfo){ + for(HashDatabase db:this.hashSets){ + if(dbInfo.matches(db)){ + return false; + } + } + return true; + } private String getValidFilePath(String hashSetName, String configuredPath) { // Check the configured path. @@ -1206,17 +1248,29 @@ public class HashDbManager implements PropertyChangeListener { private final HashDb.KnownFilesType knownFilesType; private final int centralRepoIndex; private final String version; - private final String orgName = ""; + private String orgName; + private final boolean readOnly; private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); + @Messages({"HashDbManager.CentralRepoHashDb.orgError=Error loading organization"}) private CentralRepoHashDb(String hashSetName, String version, int centralRepoIndex, - boolean useForIngest, boolean sendHitMessages, HashDb.KnownFilesType knownFilesType) { + boolean useForIngest, boolean sendHitMessages, HashDb.KnownFilesType knownFilesType, + boolean readOnly) + throws TskCoreException{ this.hashSetName = hashSetName; this.version = version; this.centralRepoIndex = centralRepoIndex; this.searchDuringIngest = useForIngest; this.sendIngestMessages = sendHitMessages; this.knownFilesType = knownFilesType; + this.readOnly = readOnly; + + try{ + orgName = EamDb.getInstance().getReferenceSetOrganization(centralRepoIndex).getName(); + } catch (EamDbException ex){ + Logger.getLogger(HashDb.class.getName()).log(Level.SEVERE, "Error looking up central repository organization", ex); //NON-NLS + orgName = Bundle.HashDbManager_CentralRepoHashDb_orgError(); + } } /** @@ -1255,7 +1309,7 @@ public class HashDbManager implements PropertyChangeListener { } public String getOrgName(){ - return "org name"; + return orgName; } public int getCentralRepoIndex(){ @@ -1311,6 +1365,8 @@ public class HashDbManager implements PropertyChangeListener { @Override public boolean isUpdateable() throws TskCoreException { return false; + // TEMP this will change as soon as adding to the database is supported + // return (! readOnly); } /** diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java index 52ae48c8cd..19a1d5ee21 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java @@ -60,7 +60,7 @@ public class HashLookupModuleFactory extends IngestModuleFactoryAdapter { @Override public IngestModuleIngestJobSettings getDefaultIngestJobSettings() { // All available hash sets are enabled and always calculate hashes is true by default. - return new HashLookupModuleSettings(true, HashDbManager.getInstance().getAllHashDatabases()); + return new HashLookupModuleSettings(true, HashDbManager.getInstance().refreshAndGetAllHashDatabases()); } @Override diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java index ae2e4e7331..32ea609b2f 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java @@ -53,6 +53,11 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe } private void initializeHashSetModels(HashLookupModuleSettings settings) { + try{ + hashDbManager.updateHashSetsFromCentralRepository(); + } catch (TskCoreException ex){ + Logger.getLogger(HashLookupModuleSettingsPanel.class.getName()).log(Level.SEVERE, "Error updating central repository hash sets", ex); //NON-NLS + } initializeHashSetModels(settings, hashDbManager.getKnownFileHashDatabases(), knownHashSetModels); initializeHashSetModels(settings, hashDbManager.getNotableFileHashDatabases(), knownBadHashSetModels); } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java index 3307ee2c09..25286936a4 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java @@ -38,6 +38,7 @@ import org.sleuthkit.autopsy.coreutils.PlatformUtil; import org.sleuthkit.autopsy.coreutils.XMLUtil; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase.DatabaseType; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.CentralRepoHashDb; import org.sleuthkit.datamodel.TskCoreException; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -307,7 +308,7 @@ final class HashLookupSettings implements Serializable { private final boolean sendIngestMessages; private final String path; private final String version; - private final String orgName; + private final boolean readOnly; private final int centralRepoIndex; private DatabaseType dbType; @@ -329,16 +330,16 @@ final class HashLookupSettings implements Serializable { this.path = path; this.centralRepoIndex = -1; this.version = ""; - this.orgName = ""; + this.readOnly = false; this.dbType = DatabaseType.FILE; } - HashDbInfo(String hashSetName, String version, String orgName, int centralRepoIndex, HashDbManager.HashDb.KnownFilesType knownFilesType, boolean searchDuringIngest, boolean sendIngestMessages){ + HashDbInfo(String hashSetName, String version, int centralRepoIndex, HashDbManager.HashDb.KnownFilesType knownFilesType, boolean readOnly, boolean searchDuringIngest, boolean sendIngestMessages){ this.hashSetName = hashSetName; this.version = version; - this.orgName = orgName; this.centralRepoIndex = centralRepoIndex; this.knownFilesType = knownFilesType; + this.readOnly = readOnly; this.searchDuringIngest = searchDuringIngest; this.sendIngestMessages = sendIngestMessages; this.path = ""; @@ -354,7 +355,7 @@ final class HashLookupSettings implements Serializable { this.sendIngestMessages = fileTypeDb.getSendIngestMessages(); this.centralRepoIndex = -1; this.version = ""; - this.orgName = ""; + this.readOnly = false; this.dbType = DatabaseType.FILE; if (fileTypeDb.hasIndexOnly()) { this.path = fileTypeDb.getIndexPath(); @@ -365,8 +366,8 @@ final class HashLookupSettings implements Serializable { HashDbManager.CentralRepoHashDb centralRepoDb = (HashDbManager.CentralRepoHashDb)db; this.hashSetName = centralRepoDb.getHashSetName(); this.version = centralRepoDb.getVersion(); - this.orgName = centralRepoDb.getOrgName(); this.knownFilesType = centralRepoDb.getKnownFilesType(); + this.readOnly = centralRepoDb.isUpdateable(); this.searchDuringIngest = centralRepoDb.getSearchDuringIngest(); this.sendIngestMessages = centralRepoDb.getSendIngestMessages(); this.path = ""; @@ -395,11 +396,11 @@ final class HashLookupSettings implements Serializable { } /** - * Get the organization name for the hash set - * @return org name + * Get whether the hash set is read only (only applies to central repo) + * @return readOnly */ - String getOrgName(){ - return orgName; + boolean isReadOnly(){ + return readOnly; } /** @@ -483,9 +484,18 @@ final class HashLookupSettings implements Serializable { // FILE types will always have unique names, so no more testing required return true; } - // To do: central repo tests - return false; + // Central repo tests + CentralRepoHashDb crDb = (CentralRepoHashDb) hashDb; + if(this.centralRepoIndex != crDb.getCentralRepoIndex()){ + return false; + } + + if(! version.equals(crDb.getVersion())){ + return false; + } + + return true; } @Override diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java index b3eb556184..5a84690b16 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java @@ -65,6 +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 newCentralRepoIndices = new ArrayList<>(); public HashLookupSettingsPanel() { initComponents(); @@ -350,6 +351,20 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan * closed while they are still being used. */ if (IngestManager.getInstance().isIngestRunning() == false) { + // Remove any new central repo hash sets from the database + for(int index:newCentralRepoIndices){ + try{ + if(EamDb.isEnabled()){ + EamDb.getInstance().deleteReferenceSet(index); + } else { + xx + Logger.getLogger(HashLookupSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting index info for hash database", ex); //NON-NLS + } + } catch (EamDbException ex){ + + } + } + HashDbManager.getInstance().loadLastSavedConfiguration(); } } @@ -963,6 +978,11 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan private void importDatabaseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importDatabaseButtonActionPerformed HashDatabase hashDb = new HashDbImportDatabaseDialog().getHashDatabase(); if (null != hashDb) { + if(hashDb instanceof CentralRepoHashDb){ + int newDbIndex = ((CentralRepoHashDb)hashDb).getCentralRepoIndex(); + newCentralRepoIndices.add(newDbIndex); + } + hashSetTableModel.refreshModel(); ((HashSetTable) hashSetTable).selectRowByDatabase(hashDb); firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.java index 242f7c3a80..a9a44839a8 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.java @@ -534,8 +534,8 @@ final public class ImportCentralRepoDatabaseDialog extends javax.swing.JDialog { try{ ImportCentralRepoDbProgressDialog progressDialog = new ImportCentralRepoDbProgressDialog(); - progressDialog.importFile(dbName, version, - selectedOrg.getOrgID(), true, sendMessages, known, selectedFilePath); + //progressDialog.importFile(dbName, version, + // selectedOrg.getOrgID(), true, sendMessages, known, selectedFilePath); //HashDbManager.getInstance().importCentralRepoHashSet(dbName, version, // selectedOrg.getOrgID(), true, sendMessages, known, selectedFilePath); } catch (Exception ex){ diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java index 24b42f0309..4fcf1f5879 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java @@ -84,12 +84,12 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P void importFile(String hashSetName, String version, int orgId, boolean searchDuringIngest, boolean sendIngestMessages, HashDbManager.HashDb.KnownFilesType knownFilesType, - String importFileName){ + boolean readOnly, String importFileName){ setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); File importFile = new File(importFileName); worker = new ImportIDXWorker(hashSetName, version, orgId, searchDuringIngest, sendIngestMessages, - knownFilesType, importFile); + knownFilesType, readOnly, importFile); worker.addPropertyChangeListener(this); worker.execute(); @@ -149,6 +149,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P private final boolean searchDuringIngest; private final boolean sendIngestMessages; private final HashDbManager.HashDb.KnownFilesType knownFilesType; + private final boolean readOnly; private final File importFile; private final long totalLines; private int crIndex = -1; @@ -157,7 +158,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P ImportIDXWorker(String hashSetName, String version, int orgId, boolean searchDuringIngest, boolean sendIngestMessages, HashDbManager.HashDb.KnownFilesType knownFilesType, - File importFile){ + boolean readOnly, File importFile){ this.hashSetName = hashSetName; this.version = version; @@ -165,6 +166,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P this.searchDuringIngest = searchDuringIngest; this.sendIngestMessages = sendIngestMessages; this.knownFilesType = knownFilesType; + this.readOnly = readOnly; this.importFile = importFile; this.numLines.set(0); @@ -210,22 +212,20 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P @Override protected Void doInBackground() throws Exception { + TskData.FileKnown knownStatus; + if (knownFilesType.equals(HashDbManager.HashDb.KnownFilesType.KNOWN)) { + knownStatus = TskData.FileKnown.KNOWN; + } else { + knownStatus = TskData.FileKnown.BAD; + } try{ // Create an empty hashset in the central repository - crIndex = EamDb.getInstance().newReferenceSet(orgId, hashSetName, version); + crIndex = EamDb.getInstance().newReferenceSet(orgId, hashSetName, version, knownStatus, readOnly); } catch (EamDbException ex){ throw new TskCoreException(ex.getLocalizedMessage()); } try{ - - TskData.FileKnown knownStatus; - if (knownFilesType.equals(HashDbManager.HashDb.KnownFilesType.KNOWN)) { - knownStatus = TskData.FileKnown.KNOWN; - } else { - knownStatus = TskData.FileKnown.BAD; - } - EamDb dbManager = EamDb.getInstance(); CorrelationAttribute.Type contentType = dbManager.getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID); // get "FILES" type BufferedReader reader = new BufferedReader(new FileReader(importFile)); @@ -310,7 +310,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P System.out.println("### Finished - adding hashDb object"); newHashDb = HashDbManager.getInstance().addExistingCentralRepoHashSet(hashSetName, version, crIndex, - searchDuringIngest, sendIngestMessages, knownFilesType); + searchDuringIngest, sendIngestMessages, knownFilesType, readOnly); } catch (TskCoreException ex){ System.out.println("\n### Error!"); } From bfa9502fa200bd934ef6a4e41a18054e645d5278 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Tue, 31 Oct 2017 11:00:07 -0400 Subject: [PATCH 18/41] Fix updating of central repo dbs. Added display name. Fixed default enabled status. --- .../modules/hashdatabase/HashDbManager.java | 26 +++++++++++++++++++ .../HashLookupModuleSettings.java | 6 ++--- .../HashLookupModuleSettingsPanel.java | 2 +- .../hashdatabase/HashLookupSettingsPanel.java | 12 +++++---- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index c9ba9b70ad..d75c03f015 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -869,12 +869,16 @@ public class HashDbManager implements PropertyChangeListener { }; public String getHashSetName(); + + public String getDisplayName(); public String getDatabasePath() throws TskCoreException; public HashDb.KnownFilesType getKnownFilesType(); public boolean getSearchDuringIngest(); + + public boolean getDefaultSearchDuringIngest(); void setSearchDuringIngest(boolean useForIngest); @@ -1015,6 +1019,11 @@ public class HashDbManager implements PropertyChangeListener { public String getHashSetName() { return hashSetName; } + + @Override + public String getDisplayName(){ + return getHashSetName(); + } @Override public String getDatabasePath() throws TskCoreException { @@ -1043,6 +1052,12 @@ public class HashDbManager implements PropertyChangeListener { public boolean getSearchDuringIngest() { return searchDuringIngest; } + + @Override + public boolean getDefaultSearchDuringIngest(){ + // File type hash sets are on by default + return true; + } @Override public void setSearchDuringIngest(boolean useForIngest) { @@ -1304,6 +1319,11 @@ public class HashDbManager implements PropertyChangeListener { return hashSetName; } + @Override + public String getDisplayName(){ + return getHashSetName() + " " + getVersion(); + } + public String getVersion(){ return version; } @@ -1339,6 +1359,12 @@ public class HashDbManager implements PropertyChangeListener { public boolean getSearchDuringIngest() { return searchDuringIngest; } + + @Override + public boolean getDefaultSearchDuringIngest(){ + // Central repo hash sets are off by default + return false; + } @Override public void setSearchDuringIngest(boolean useForIngest) { diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java index 49f45a57d8..9923c7f21b 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java @@ -122,7 +122,7 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { /** * Checks whether or not a hash set is enabled. If there is no setting for - * the requested hash set, it is deemed to be enabled. + * the requested hash set, return the default value * * @param db The hash set to check. * @@ -135,8 +135,8 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { } } - // We didn't find it, so return true - return true; + // We didn't find it, so use the default value + return db.getDefaultSearchDuringIngest(); } /** diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java index 32ea609b2f..517640f487 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java @@ -200,7 +200,7 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe } String getName() { - return db.getHashSetName(); + return db.getDisplayName(); } void setEnabled(boolean enabled) { diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java index 5a84690b16..0f371606bc 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java @@ -40,6 +40,7 @@ import org.netbeans.spi.options.OptionsPanelController; import org.openide.util.NbBundle; import org.openide.util.NbBundle.Messages; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException; import org.sleuthkit.autopsy.corecomponents.OptionsPanel; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.events.AutopsyEvent; @@ -266,7 +267,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan // Update ingest option components. sendIngestMessagesCheckBox.setSelected(db.getSendIngestMessages()); - sendIngestMessagesCheckBox.setEnabled(!ingestIsRunning && db.getSearchDuringIngest() && db.getKnownFilesType().equals(KnownFilesType.KNOWN_BAD)); + sendIngestMessagesCheckBox.setEnabled(!ingestIsRunning && db.getKnownFilesType().equals(KnownFilesType.KNOWN_BAD)); optionsLabel.setEnabled(!ingestIsRunning); optionsSeparator.setEnabled(!ingestIsRunning); @@ -357,11 +358,12 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan if(EamDb.isEnabled()){ EamDb.getInstance().deleteReferenceSet(index); } else { - xx - Logger.getLogger(HashLookupSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting index info for hash database", ex); //NON-NLS + // 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. + Logger.getLogger(HashLookupSettingsPanel.class.getName()).log(Level.WARNING, "Error reverting central repository hash sets"); //NON-NLS } } catch (EamDbException ex){ - + Logger.getLogger(HashLookupSettingsPanel.class.getName()).log(Level.SEVERE, "Error reverting central repository hash sets", ex); //NON-NLS } } @@ -546,7 +548,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan } void refreshModel() { - hashSets = HashDbManager.getInstance().getAllHashDatabases(); + hashSets = HashDbManager.getInstance().refreshAndGetAllHashDatabases(); refreshDisplay(); } From b1fb068cc1a9ee3f851a07c8c90c752d8bf7f1c1 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Tue, 31 Oct 2017 13:59:34 -0400 Subject: [PATCH 19/41] Removed unused ImportCentralRepoDatabaseDialog Starting cleanup --- .../datamodel/AbstractSqlEamDb.java | 6 - .../ImportCentralRepoDatabaseDialog.form | 286 -------- .../ImportCentralRepoDatabaseDialog.java | 693 ------------------ .../modules/hashdatabase/Bundle.properties | 1 - .../modules/hashdatabase/HashDbManager.java | 4 - .../hashdatabase/HashLookupSettings.java | 4 - .../hashdatabase/HashLookupSettingsPanel.form | 17 +- .../hashdatabase/HashLookupSettingsPanel.java | 29 +- .../ImportCentralRepoDbProgressDialog.java | 134 ++-- 9 files changed, 53 insertions(+), 1121 deletions(-) delete mode 100755 Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportCentralRepoDatabaseDialog.form delete mode 100755 Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportCentralRepoDatabaseDialog.java diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java index e36aca5c89..a211c49c50 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java @@ -34,9 +34,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; import org.sleuthkit.autopsy.casemodule.Case; - import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager; import org.sleuthkit.datamodel.TskData; /** @@ -1306,15 +1304,11 @@ public abstract class AbstractSqlEamDb implements EamDb { */ @Override public boolean referenceSetIsValid(int centralRepoIndex, String hashSetName, String version) throws EamDbException{ - System.out.println("###\nChecking if " + centralRepoIndex + " : " + hashSetName + " " + version + " is valid"); EamGlobalSet refSet = this.getReferenceSetByID(centralRepoIndex); if(refSet == null){ - System.out.println(" Not valid - no matching index"); return false; } - boolean res = refSet.getSetName().equals(hashSetName) && refSet.getVersion().equals(version); - System.out.println(" res: " + res + " (" + refSet.getSetName() + ", " + refSet.getVersion() + ")"); return(refSet.getSetName().equals(hashSetName) && refSet.getVersion().equals(version)); } diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportCentralRepoDatabaseDialog.form b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportCentralRepoDatabaseDialog.form deleted file mode 100755 index cb51bb9dd8..0000000000 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportCentralRepoDatabaseDialog.form +++ /dev/null @@ -1,286 +0,0 @@ - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportCentralRepoDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportCentralRepoDatabaseDialog.java deleted file mode 100755 index 39def95529..0000000000 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/ImportCentralRepoDatabaseDialog.java +++ /dev/null @@ -1,693 +0,0 @@ -/* - * Central Repository - * - * Copyright 2015-2017 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.centralrepository.optionspanel; - -import java.awt.Dimension; -import java.awt.Toolkit; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.net.UnknownHostException; -import java.nio.file.Files; -import java.time.LocalDate; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.logging.Level; -import javax.swing.JComboBox; -import javax.swing.JFileChooser; -import javax.swing.JFrame; -import javax.swing.JOptionPane; -import javax.swing.JTextField; -import javax.swing.SwingUtilities; -import javax.swing.SwingWorker; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; -import javax.swing.filechooser.FileNameExtensionFilter; -import org.netbeans.api.progress.ProgressHandle; -import org.netbeans.spi.options.OptionsPanelController; -import org.openide.util.Exceptions; -import org.openide.util.NbBundle; -import org.openide.util.NbBundle.Messages; -import org.openide.windows.WindowManager; -import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttribute; -import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.coreutils.ModuleSettings; -import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttributeInstance; -import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException; -import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalFileInstance; -import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalSet; -import org.sleuthkit.autopsy.centralrepository.datamodel.EamOrganization; -import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; -import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager; -import org.sleuthkit.datamodel.TskData; - -/** - * Instances of this class allow a user to select an existing hash database and - * add it to the set of hash databases used to classify files as unknown, known, - * or notable. - */ -final public class ImportCentralRepoDatabaseDialog extends javax.swing.JDialog { - private static final Logger LOGGER = Logger.getLogger(ImportCentralRepoDatabaseDialog.class.getName()); - - private final JFileChooser fileChooser = new JFileChooser(); - private final static String LAST_FILE_PATH_KEY = "CentralRepositoryImport_Path"; // NON-NLS - private final int HASH_IMPORT_THRESHOLD = 10000; - private EamOrganization selectedOrg = null; - private List orgs = null; - private final Collection textBoxes; - private final TextBoxChangedListener textBoxChangedListener; - private HashDbManager.HashDatabase selectedHashDb = null; - - - /** - * Displays a dialog that allows a user to select an existing hash database - * and add it to the set of hash databases used to classify files as - * unknown, known, or notable. - */ - @Messages({"ImportHashDatabaseDialog.importHashDbMsg=Import Hash Database"}) - public ImportCentralRepoDatabaseDialog() { - super((JFrame) WindowManager.getDefault().getMainWindow(), - Bundle.ImportHashDatabaseDialog_importHashDbMsg(), - true); // NON-NLS - textBoxes = new ArrayList<>(); - textBoxChangedListener = new TextBoxChangedListener(); - initFileChooser(); - initComponents(); - customizeComponents(); - display(); - } - - @Messages({"ImportHashDatabaseDialog.fileNameExtFilter.text=Hash Database File",}) - private void initFileChooser() { - fileChooser.setDragEnabled(false); - fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - String[] EXTENSION = new String[]{"idx"}; //NON-NLS - FileNameExtensionFilter filter = new FileNameExtensionFilter( - Bundle.ImportHashDatabaseDialog_fileNameExtFilter_text(), - EXTENSION); // NON-NLS - fileChooser.setFileFilter(filter); - fileChooser.setMultiSelectionEnabled(false); - - if (ModuleSettings.settingExists(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY)) { - String lastBaseDirectory = ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY); - File hashDbFolder = new File(lastBaseDirectory); - if(hashDbFolder.exists()){ - fileChooser.setCurrentDirectory(hashDbFolder); - } - } - } - - private void customizeComponents() { - populateCombobox(); - setTextBoxListeners(); - enableOkButton(false); - } - - public HashDbManager.HashDatabase getHashDatabase(){ - return this.selectedHashDb; - } - - /** - * Register for notifications when the text boxes get updated. - */ - private void setTextBoxListeners() { - textBoxes.add(tfFilePath); - textBoxes.add(tfDatabaseName); - textBoxes.add(tfDatabaseVersion); - addDocumentListeners(textBoxes, textBoxChangedListener); - } - - private void populateCombobox() { - comboboxSourceOrganization.removeAllItems(); - try { - EamDb dbManager = EamDb.getInstance(); - orgs = dbManager.getOrganizations(); - orgs.forEach((org) -> { - comboboxSourceOrganization.addItem(org.getName()); - }); - if (!orgs.isEmpty()) { - selectedOrg = orgs.get(0); - } - valid(); - } catch (EamDbException ex) { - LOGGER.log(Level.SEVERE, "Failure populating combobox with organizations.", ex); - } - } - - /** - * Adds a change listener to a collection of text fields. - * - * @param textFields The text fields. - * @param listener The change listener. - */ - private static void addDocumentListeners(Collection textFields, TextBoxChangedListener listener) { - textFields.forEach((textField) -> { - textField.getDocument().addDocumentListener(listener); - }); - } - - /** - * Tests whether or not values have been entered in all of the required - * text fields. - * - * @return True or false. - */ - private boolean textFieldsArePopulated() { - return !tfDatabaseName.getText().trim().isEmpty() - && !tfDatabaseVersion.getText().trim().isEmpty() - && !tfFilePath.getText().trim().isEmpty(); - } - - /** - * Tests whether or not all of the settings components are populated. - * - * @return True or false. - */ - @Messages({"ImportHashDatabaseDialog.validation.incompleteFields=Fill in all values"}) - private boolean checkFields() { - boolean result = true; - - boolean allPopulated = textFieldsArePopulated(); - - if (!allPopulated) { - // We don't even have everything filled out - result = false; - lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_validation_incompleteFields()); - } - return result; - } - - /** - * Validates that the form is filled out correctly for our usage. - * - * @return true if it's okay, false otherwise. - */ - @Messages({"ImportHashDatabaseDialog.validation.notEnabled=Central Repository is not enabled."}) - public boolean valid() { - lbWarningMsg.setText(""); - if (!EamDb.isEnabled()) { - lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_validation_notEnabled()); - return false; - } - - return enableOkButton(checkFields() && null != selectedOrg); - } - - /** - * Enables the "OK" button to create the Global File Set and insert the instances. - * - * @param enable - * - * @return True or False - */ - private boolean enableOkButton(Boolean enable) { - okButton.setEnabled(enable); - return enable; - } - - /** - * Used to listen for changes in text boxes. It lets the panel know things - * have been updated and that validation needs to happen. - */ - private class TextBoxChangedListener implements DocumentListener { - - @Override - public void changedUpdate(DocumentEvent e) { - firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); - valid(); - } - - @Override - public void insertUpdate(DocumentEvent e) { - firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); - valid(); - } - - @Override - public void removeUpdate(DocumentEvent e) { - firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); - valid(); - } - } - - private void display() { - Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); - setLocation((screenDimension.width - getSize().width) / 2, (screenDimension.height - getSize().height) / 2); - setVisible(true); - } - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - buttonGroup1 = new javax.swing.ButtonGroup(); - okButton = new javax.swing.JButton(); - cancelButton = new javax.swing.JButton(); - tfFilePath = new javax.swing.JTextField(); - openButton = new javax.swing.JButton(); - knownRadioButton = new javax.swing.JRadioButton(); - knownBadRadioButton = new javax.swing.JRadioButton(); - lbDatabaseType = new javax.swing.JLabel(); - lbDatabasePath = new javax.swing.JLabel(); - lbSourceOrganization = new javax.swing.JLabel(); - lbDatabaseName = new javax.swing.JLabel(); - lbDatabaseVersion = new javax.swing.JLabel(); - comboboxSourceOrganization = new javax.swing.JComboBox<>(); - tfDatabaseName = new javax.swing.JTextField(); - tfDatabaseVersion = new javax.swing.JTextField(); - bnNewOrganization = new javax.swing.JButton(); - lbWarningMsg = new javax.swing.JLabel(); - cbInboxMessages = new javax.swing.JCheckBox(); - - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - - org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.okButton.text")); // NOI18N - okButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - okButtonActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.cancelButton.text")); // NOI18N - cancelButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - cancelButtonActionPerformed(evt); - } - }); - - tfFilePath.setText(org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.tfFilePath.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(openButton, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.openButton.text")); // NOI18N - openButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - openButtonActionPerformed(evt); - } - }); - - buttonGroup1.add(knownRadioButton); - org.openide.awt.Mnemonics.setLocalizedText(knownRadioButton, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.knownRadioButton.text")); // NOI18N - - buttonGroup1.add(knownBadRadioButton); - knownBadRadioButton.setSelected(true); - org.openide.awt.Mnemonics.setLocalizedText(knownBadRadioButton, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.knownBadRadioButton.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseType, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.lbDatabaseType.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(lbDatabasePath, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportHashDatabaseDialog.lbFilePath.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(lbSourceOrganization, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.lbSourceOrganization.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseName, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.lbDatabaseName.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseVersion, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.lbDatabaseVersion.text")); // NOI18N - - comboboxSourceOrganization.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); - comboboxSourceOrganization.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboboxSourceOrganizationActionPerformed(evt); - } - }); - - tfDatabaseName.setToolTipText(org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportHashDatabaseDialog.tfDatabaseName.tooltip")); // NOI18N - - tfDatabaseVersion.setToolTipText(org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportHashDatabaseDialog.tfDatabaseVersion.tooltip.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(bnNewOrganization, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.bnNewOrganization.text")); // NOI18N - bnNewOrganization.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - bnNewOrganizationActionPerformed(evt); - } - }); - - lbWarningMsg.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N - lbWarningMsg.setForeground(new java.awt.Color(255, 0, 0)); - - org.openide.awt.Mnemonics.setLocalizedText(cbInboxMessages, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.cbInboxMessages.text")); // NOI18N - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(okButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cancelButton)) - .addComponent(lbWarningMsg, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(lbDatabasePath) - .addComponent(lbDatabaseName)) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(tfFilePath, javax.swing.GroupLayout.PREFERRED_SIZE, 277, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(openButton)) - .addComponent(tfDatabaseName))) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(lbDatabaseType) - .addGroup(layout.createSequentialGroup() - .addGap(19, 19, 19) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(knownRadioButton) - .addComponent(knownBadRadioButton))) - .addGroup(layout.createSequentialGroup() - .addComponent(lbDatabaseVersion) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(tfDatabaseVersion, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(layout.createSequentialGroup() - .addComponent(lbSourceOrganization) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(comboboxSourceOrganization, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(bnNewOrganization)) - .addComponent(cbInboxMessages)) - .addGap(0, 0, Short.MAX_VALUE))) - .addContainerGap()) - ); - - layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton}); - - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(openButton) - .addComponent(tfFilePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(lbDatabasePath)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(lbDatabaseName, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(tfDatabaseName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(lbDatabaseVersion, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(tfDatabaseVersion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(lbSourceOrganization, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(comboboxSourceOrganization, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(bnNewOrganization)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE) - .addComponent(lbDatabaseType) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(knownRadioButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(knownBadRadioButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cbInboxMessages) - .addGap(117, 117, 117) - .addComponent(lbWarningMsg, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(okButton) - .addComponent(cancelButton)) - .addContainerGap()) - ); - - pack(); - }// //GEN-END:initComponents - - @Messages({"ImportHashDatabaseDialog.failedToGetDbPathMsg=Failed to get the path of the selected database.",}) - private void openButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openButtonActionPerformed - if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { - File databaseFile = fileChooser.getSelectedFile(); - try { - tfFilePath.setText(databaseFile.getCanonicalPath()); - if (databaseFile.getName().toLowerCase().contains("nsrl")) { //NON-NLS - knownRadioButton.setSelected(true); - } - ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY, databaseFile.getParent()); - } catch (IOException ex) { - Logger.getLogger(ImportCentralRepoDatabaseDialog.class.getName()).log(Level.SEVERE, "Failed to get path of selected database", ex); // NON-NLS - lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_failedToGetDbPathMsg()); - } - } - valid(); - }//GEN-LAST:event_openButtonActionPerformed - - private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed - dispose(); - }//GEN-LAST:event_cancelButtonActionPerformed - - /** - * Create the new global set and return the ID number - * - * @return ID number of new global set - * @throws EamDbException - */ - private int createGlobalSet() throws EamDbException { - EamDb dbManager = EamDb.getInstance(); - /* - EamGlobalSet eamGlobalSet = new EamGlobalSet( - selectedOrg.getOrgID(), - tfDatabaseName.getText().trim(), - tfDatabaseVersion.getText().trim(), - LocalDate.now()); - return dbManager.newReferencelSet(eamGlobalSet);*/ - return 0; - } - - @Messages({"ImportHashDatabaseDialog.createGlobalSet.failedMsg.text=Failed to store attribution details.", - "ImportHashDatabaseDialog.mustSelectHashDbFilePathMsg=Missing hash database file path.", - "ImportHashDatabaseDialog.hashDbDoesNotExistMsg=The selected hash database does not exist.", - "# {0} - selected file path", - "ImportHashDatabaseDialog.errorMessage.failedToOpenHashDbMsg=Failed to open hash database at {0}.", -}) - private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed - // Note that the error handlers in this method call return without disposing of the - // dialog to allow the user to try again, if desired. - /*String selectedFilePath = tfFilePath.getText(); - - // have valid file path - if (selectedFilePath.isEmpty()) { - lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_mustSelectHashDbFilePathMsg()); - return; - } - File file = new File(selectedFilePath); - if (!file.exists()) { - lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_hashDbDoesNotExistMsg()); - return; - } - - HashDbManager.HashDb.KnownFilesType known; - if (knownRadioButton.isSelected()) { - known = HashDbManager.HashDb.KnownFilesType.KNOWN; - } else{ - known = HashDbManager.HashDb.KnownFilesType.KNOWN_BAD; - } - - try{ - HashDbManager.getInstance().importCentralRepoHashSet(tfDatabaseName.getText().trim(), tfDatabaseVersion.getText().trim(), - selectedOrg.getOrgID(), true, true, - known, selectedFilePath); - } catch (Exception ex){ - - } finally { - dispose(); - }*/ - /* - // create global set - int globalSetID; - try { - globalSetID = createGlobalSet(); - } catch (EamDbException ex) { - LOGGER.log(Level.SEVERE, "Failed to create global set.", ex); - lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_createGlobalSet_failedMsg_text()); - return; - } - - // insert hashes - TskData.FileKnown knownStatus = TskData.FileKnown.UNKNOWN; - if (knownRadioButton.isSelected()) { - knownStatus = TskData.FileKnown.KNOWN; - } else if (knownBadRadioButton.isSelected()) { - knownStatus = TskData.FileKnown.BAD; - } - - String errorMessage = Bundle.ImportHashDatabaseDialog_errorMessage_failedToOpenHashDbMsg(selectedFilePath); - // Future, make UI handle more than the "FILES" type. - try { - EamDb dbManager = EamDb.getInstance(); - CorrelationAttribute.Type contentType = dbManager.getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID); // get "FILES" type - // run in the background and close dialog - SwingUtilities.invokeLater(new ImportHashDatabaseWorker(selectedFilePath, knownStatus, globalSetID, contentType)::execute); - dispose(); - } catch (EamDbException | UnknownHostException ex) { - Logger.getLogger(ImportHashDatabaseDialog.class.getName()).log(Level.SEVERE, errorMessage, ex); - lbWarningMsg.setText(ex.getMessage()); - }*/ - - }//GEN-LAST:event_okButtonActionPerformed - - @SuppressWarnings({"unchecked"}) - private void bnNewOrganizationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnNewOrganizationActionPerformed - AddNewOrganizationDialog dialogO = new AddNewOrganizationDialog(); - // update the combobox options - if (dialogO.isChanged()) { - populateCombobox(); - } - }//GEN-LAST:event_bnNewOrganizationActionPerformed - - @SuppressWarnings({"unchecked"}) - private void comboboxSourceOrganizationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboboxSourceOrganizationActionPerformed - JComboBox cb = (JComboBox)evt.getSource(); - String orgName = (String)cb.getSelectedItem(); - if (null == orgName) return; - - for (EamOrganization org : orgs) { - if (org.getName().equals(orgName)) { - selectedOrg = org; - return; - } - } - valid(); - }//GEN-LAST:event_comboboxSourceOrganizationActionPerformed - - @NbBundle.Messages({"ImportHashDatabaseDialog.ImportHashDatabaseWorker.displayName=Importing Hash Database"}) - public class ImportHashDatabaseWorker extends SwingWorker { - - private final File file; - private final TskData.FileKnown knownStatus; - private final int globalSetID; - private final ProgressHandle progress; - private final CorrelationAttribute.Type contentType; - - public ImportHashDatabaseWorker(String filename, TskData.FileKnown knownStatus, int globalSetID, CorrelationAttribute.Type contentType) throws EamDbException, UnknownHostException { - this.file = new File(filename); - this.knownStatus = knownStatus; - this.globalSetID = globalSetID; - this.contentType = contentType; - this.progress = ProgressHandle.createHandle(Bundle.ImportHashDatabaseDialog_ImportHashDatabaseWorker_displayName()); - - if (!EamDb.isEnabled()) { - throw new EamDbException("Central repository database is not enabled."); // NON-NLS - } - } - - @Override - protected Void doInBackground() throws Exception { - importHashDatabase(); - return null; - } - - @Override - @Messages({"ImportHashDatabaseDialog.ImportHashDatabaseWorker.error=Failed to import hash database."}) - protected void done() { - progress.finish(); - try { - get(); - } catch (InterruptedException | ExecutionException ex) { - Logger.getLogger(ImportCentralRepoDatabaseDialog.class.getName()).log(Level.SEVERE, Bundle.ImportHashDatabaseDialog_ImportHashDatabaseWorker_error(), ex); - MessageNotifyUtil.Notify.show(Bundle.ImportHashDatabaseDialog_ImportHashDatabaseWorker_error(), - ex.getMessage(), - MessageNotifyUtil.MessageType.ERROR); - } - } - - private long numberOfLinesInFile(File f) throws IOException { - return Files.lines(f.toPath()).count(); - } - - @Messages({"# {0} - value content", - "ImportHashDatabaseDialog.ImportHashDatabaseWorker.duplicate=Duplicate value {0} found in import file."}) - private void importHashDatabase() throws EamDbException, IOException { - BufferedReader reader = new BufferedReader(new FileReader(file)); - String line; - EamDb dbManager = EamDb.getInstance(); - Set globalInstances = new HashSet<>(); - - long totalLines = numberOfLinesInFile(file); - if (totalLines <= Integer.MAX_VALUE) { - progress.start((int) totalLines); - } else { - progress.start(); - } - - int numLines = 0; - LOGGER.log(Level.INFO, "Importing hash database {0}", file.getName()); - while ((line = reader.readLine()) != null) { - progress.progress(++numLines); - - String[] parts = line.split("\\|"); - - // Header lines start with a 41 character dummy hash, 1 character longer than a SHA-1 hash - if (parts.length != 2 || parts[0].length() == 41) { - continue; - } - - EamGlobalFileInstance eamGlobalFileInstance = new EamGlobalFileInstance( - globalSetID, - parts[0].toLowerCase(), - knownStatus, - ""); - - globalInstances.add(eamGlobalFileInstance); - - if(numLines % HASH_IMPORT_THRESHOLD == 0){ - dbManager.bulkInsertReferenceTypeEntries(globalInstances, contentType); - globalInstances.clear(); - } - } - - dbManager.bulkInsertReferenceTypeEntries(globalInstances, contentType); - LOGGER.log(Level.INFO, "Finished importing hash database. Total entries: {0}", numLines); - - } - } - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton bnNewOrganization; - private javax.swing.ButtonGroup buttonGroup1; - private javax.swing.JButton cancelButton; - private javax.swing.JCheckBox cbInboxMessages; - private javax.swing.JComboBox comboboxSourceOrganization; - private javax.swing.JRadioButton knownBadRadioButton; - private javax.swing.JRadioButton knownRadioButton; - private javax.swing.JLabel lbDatabaseName; - private javax.swing.JLabel lbDatabasePath; - private javax.swing.JLabel lbDatabaseType; - private javax.swing.JLabel lbDatabaseVersion; - private javax.swing.JLabel lbSourceOrganization; - private javax.swing.JLabel lbWarningMsg; - private javax.swing.JButton okButton; - private javax.swing.JButton openButton; - private javax.swing.JTextField tfDatabaseName; - private javax.swing.JTextField tfDatabaseVersion; - private javax.swing.JTextField tfFilePath; - // End of variables declaration//GEN-END:variables -} diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties index 082874b385..ff3cf1c7f5 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties @@ -224,7 +224,6 @@ HashLookupSettingsPanel.nameLabel1.text=Hash Set Name: HashLookupSettingsPanel.sendIngestMessagesCheckBox1.text=Send ingest inbox message for each hit HashLookupSettingsPanel.importDatabaseButton1.toolTipText= HashLookupSettingsPanel.typeLabel1.text=Type: -HashLookupSettingsPanel.jButton1.text=Import CR Hashset ImportCentralRepoDatabaseDialog.cbInboxMessages.text=Send ingest inbox message for each hit ImportCentralRepoDatabaseDialog.cancelButton.text=Cancel ImportCentralRepoDatabaseDialog.lbDatabaseVersion.text=Hash Set Version: diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index d75c03f015..83b051aceb 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -512,10 +512,6 @@ public class HashDbManager implements PropertyChangeListener { void save() throws HashDbManagerException { try { - System.out.println("######\nHashDbManager: Saving Hash Lookup settings"); - for(HashDatabase db: this.hashSets){ - System.out.println(" " + db.getHashSetName() + " " + db.getDatabaseType().name()); - } if (!HashLookupSettings.writeSettings(new HashLookupSettings(HashLookupSettings.convertHashSetList(this.hashSets)))) { throw new HashDbManagerException(NbBundle.getMessage(this.getClass(), "HashDbManager.saveErrorExceptionMsg")); } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java index 25286936a4..8a99f5778a 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java @@ -125,10 +125,6 @@ final class HashLookupSettings implements Serializable { try { try (NbObjectInputStream in = new NbObjectInputStream(new FileInputStream(SERIALIZATION_FILE_PATH))) { HashLookupSettings filesSetsSettings = (HashLookupSettings) in.readObject(); - System.out.println("#####\nHashLookupSettings"); - for(HashDbInfo dbInfo:filesSetsSettings.hashDbInfoList){ - System.out.println(" " + dbInfo.getHashSetName() + " File type: " + dbInfo.isFileDatabaseType()); - } return filesSetsSettings; } } catch (IOException | ClassNotFoundException ex) { diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.form b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.form index a78094dc79..5be552d274 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.form +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.form @@ -161,10 +161,7 @@ - - - - + @@ -258,8 +255,6 @@ - - @@ -620,16 +615,6 @@
    - - - - - - - - - - diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java index 0f371606bc..2fbe9570d6 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java @@ -595,7 +595,6 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan indexPathLabelLabel = new javax.swing.JLabel(); indexPathLabel = new javax.swing.JLabel(); addHashesToDatabaseButton = new javax.swing.JButton(); - jButton1 = new javax.swing.JButton(); versionLabel = new javax.swing.JLabel(); hashDbVersionLabel = new javax.swing.JLabel(); orgLabel = new javax.swing.JLabel(); @@ -740,13 +739,6 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan } }); - org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(HashLookupSettingsPanel.class, "HashLookupSettingsPanel.jButton1.text")); // NOI18N - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - org.openide.awt.Mnemonics.setLocalizedText(versionLabel, org.openide.util.NbBundle.getMessage(HashLookupSettingsPanel.class, "HashLookupSettingsPanel.versionLabel.text_1")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(hashDbVersionLabel, org.openide.util.NbBundle.getMessage(HashLookupSettingsPanel.class, "HashLookupSettingsPanel.hashDbVersionLabel.text_1")); // NOI18N @@ -822,9 +814,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan .addComponent(sendIngestMessagesCheckBox)) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(10, 10, 10) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(ingestWarningLabel) - .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE))))) + .addComponent(ingestWarningLabel)))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -894,8 +884,6 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan .addComponent(sendIngestMessagesCheckBox) .addGap(18, 18, 18) .addComponent(ingestWarningLabel) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(jButton1) .addGap(0, 0, Short.MAX_VALUE)) .addComponent(jScrollPane1)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) @@ -1027,20 +1015,6 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan } }//GEN-LAST:event_hashSetTableKeyPressed - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - if(EamDb.isEnabled()){ - HashDatabase hashDb = new ImportCentralRepoDatabaseDialog().getHashDatabase(); - if (null != hashDb) { - hashSetTableModel.refreshModel(); - ((HashSetTable) hashSetTable).selectRowByDatabase(hashDb); - firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); - } - } else { - // TEMP - JOptionPane.showMessageDialog(null, "Central repo not enabled"); - } - }//GEN-LAST:event_jButton1ActionPerformed - // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton addHashesToDatabaseButton; private javax.swing.JButton createDatabaseButton; @@ -1062,7 +1036,6 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan private javax.swing.JLabel informationLabel; private javax.swing.JSeparator informationSeparator; private javax.swing.JLabel ingestWarningLabel; - private javax.swing.JButton jButton1; private javax.swing.JButton jButton3; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel4; diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java index 4fcf1f5879..1284263b65 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java @@ -24,27 +24,22 @@ import java.beans.PropertyChangeEvent; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; -import java.io.IOException; -import java.nio.file.Files; import java.util.HashSet; import java.util.Set; -import java.util.concurrent.ExecutionException; import java.util.logging.Level; import javax.swing.JFrame; -import javax.swing.JProgressBar; import javax.swing.SwingWorker; import javax.swing.WindowConstants; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.Executors; +import javax.swing.JOptionPane; import org.openide.util.NbBundle; import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttribute; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException; import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalFileInstance; -import org.sleuthkit.autopsy.centralrepository.datamodel.EamOrganization; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskData; @@ -53,8 +48,7 @@ import org.sleuthkit.datamodel.TskData; */ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements PropertyChangeListener{ - private CentralRepoImportWorker worker; - + private CentralRepoImportWorker worker; /** * @@ -108,9 +102,6 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P @NbBundle.Messages({"ImportCentralRepoDbProgressDialog.linesProcessed= lines processed"}) @Override public void propertyChange(PropertyChangeEvent evt) { - System.out.println("### Evt type: " + evt.getPropertyName()); - System.out.println(" newValue: " + evt.getNewValue().toString()); - System.out.println("### Setting progress to " + worker.getProgressPercentage()); if("progress".equals(evt.getPropertyName())){ progressBar.setValue(worker.getProgressPercentage()); @@ -199,16 +190,6 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P return this.getProgress(); } - //@Override - //public void addPropertyChangeListener(PropertyChangeListener dialog){ - // super.addPropertyChangeListener(dialog); - //} - - //@Override - //public void run(){ - // this.execute(); - //} - @Override protected Void doInBackground() throws Exception { @@ -218,69 +199,58 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P } else { knownStatus = TskData.FileKnown.BAD; } - try{ - // Create an empty hashset in the central repository - crIndex = EamDb.getInstance().newReferenceSet(orgId, hashSetName, version, knownStatus, readOnly); - } catch (EamDbException ex){ - throw new TskCoreException(ex.getLocalizedMessage()); - } + + // Create an empty hashset in the central repository + crIndex = EamDb.getInstance().newReferenceSet(orgId, hashSetName, version, knownStatus, readOnly); - try{ - EamDb dbManager = EamDb.getInstance(); - CorrelationAttribute.Type contentType = dbManager.getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID); // get "FILES" type - BufferedReader reader = new BufferedReader(new FileReader(importFile)); - String line; - Set globalInstances = new HashSet<>(); + EamDb dbManager = EamDb.getInstance(); + CorrelationAttribute.Type contentType = dbManager.getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID); // get "FILES" type + BufferedReader reader = new BufferedReader(new FileReader(importFile)); + String line; + Set globalInstances = new HashSet<>(); - while ((line = reader.readLine()) != null) { - if(isCancelled()){ - return null; - } - - String[] parts = line.split("\\|"); - - // Header lines start with a 41 character dummy hash, 1 character longer than a SHA-1 hash - if (parts.length != 2 || parts[0].length() == 41) { - continue; - } - - EamGlobalFileInstance eamGlobalFileInstance = new EamGlobalFileInstance( - crIndex, - parts[0].toLowerCase(), - knownStatus, - ""); - - globalInstances.add(eamGlobalFileInstance); - numLines.incrementAndGet(); - - if(numLines.get() % HASH_IMPORT_THRESHOLD == 0){ - dbManager.bulkInsertReferenceTypeEntries(globalInstances, contentType); - globalInstances.clear(); - - int progress = (int)(numLines.get() * 100 / totalLines); - if(progress < 100){ - this.setProgress(progress); - } else { - this.setProgress(99); - } - } + while ((line = reader.readLine()) != null) { + if(isCancelled()){ + return null; } - dbManager.bulkInsertReferenceTypeEntries(globalInstances, contentType); - this.setProgress(100); - - return null; - } - catch (Exception ex){ - // TODO - ex.printStackTrace(); - throw new TskCoreException(ex.getLocalizedMessage()); + String[] parts = line.split("\\|"); + + // Header lines start with a 41 character dummy hash, 1 character longer than a SHA-1 hash + if (parts.length != 2 || parts[0].length() == 41) { + continue; + } + + EamGlobalFileInstance eamGlobalFileInstance = new EamGlobalFileInstance( + crIndex, + parts[0].toLowerCase(), + knownStatus, + ""); + + globalInstances.add(eamGlobalFileInstance); + numLines.incrementAndGet(); + + if(numLines.get() % HASH_IMPORT_THRESHOLD == 0){ + dbManager.bulkInsertReferenceTypeEntries(globalInstances, contentType); + globalInstances.clear(); + + int progress = (int)(numLines.get() * 100 / totalLines); + if(progress < 100){ + this.setProgress(progress); + } else { + this.setProgress(99); + } + } } + + dbManager.bulkInsertReferenceTypeEntries(globalInstances, contentType); + this.setProgress(100); + + return null; } private void deleteIncompleteSet(int crIndex){ if(crIndex >= 0){ - System.out.println("Deleting incomplete reference set"); // This can be slow on large reference sets Executors.newSingleThreadExecutor().execute(new Runnable() { @@ -289,13 +259,14 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P try{ EamDb.getInstance().deleteReferenceSet(crIndex); } catch (EamDbException ex2){ - + Logger.getLogger(ImportCentralRepoDbProgressDialog.class.getName()).log(Level.SEVERE, "Error deleting incomplete hash set from central repository", ex2); } } }); } } + @NbBundle.Messages({"ImportCentralRepoDbProgressDialog.addDbError.message=Error adding new hash set"}) @Override protected void done() { if(isCancelled()){ @@ -307,23 +278,20 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P try { get(); try{ - System.out.println("### Finished - adding hashDb object"); newHashDb = HashDbManager.getInstance().addExistingCentralRepoHashSet(hashSetName, version, crIndex, searchDuringIngest, sendIngestMessages, knownFilesType, readOnly); } catch (TskCoreException ex){ - System.out.println("\n### Error!"); + JOptionPane.showMessageDialog(null, Bundle.ImportCentralRepoDbProgressDialog_addDbError_message()); + Logger.getLogger(ImportCentralRepoDbProgressDialog.class.getName()).log(Level.SEVERE, "Error adding imported hash set", ex); } - } catch (InterruptedException | ExecutionException ex) { - - System.out.println("\n### Interrupted!"); - + } catch (Exception ex) { // Delete this incomplete hash set from the central repo if(crIndex >= 0){ try{ EamDb.getInstance().deleteReferenceSet(crIndex); } catch (EamDbException ex2){ - + Logger.getLogger(ImportCentralRepoDbProgressDialog.class.getName()).log(Level.SEVERE, "Error deleting incomplete hash set from central repository", ex); } } } From ee3e12a88323fbb5a45645bd14351e10a4f911e3 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Tue, 31 Oct 2017 14:31:21 -0400 Subject: [PATCH 20/41] Cleanup --- .../optionspanel/Bundle.properties | 1 - .../optionspanel/GlobalSettingsPanel.form | 23 +- .../optionspanel/GlobalSettingsPanel.java | 28 +- .../autopsy/filesearch/FileSearchDialog.java | 2 +- .../modules/hashdatabase/Bundle.properties | 25 - .../modules/hashdatabase/Bundle_ja.properties | 10 - .../ImportCentralRepoDatabaseDialog.form | 290 ------- .../ImportCentralRepoDatabaseDialog.java | 716 ------------------ 8 files changed, 5 insertions(+), 1090 deletions(-) delete mode 100644 Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.form delete mode 100644 Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.java diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties index 4da5e45e93..b0c10ad498 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties @@ -21,7 +21,6 @@ ImportHashDatabaseDialog.tfDatabaseName.tooltip=Name for this database ImportHashDatabaseDialog.tfDatabaseVersion.tooltip.text=Database Version Number ImportHashDatabaseDialog.tfDatabaseName.tooltip=Name for this database ImportHashDatabaseDialog.tfDatabaseVersion.tooltip.text=Database Version Number -GlobalSettingsPanel.bnImportDatabase.actionCommand= GlobalSettingsPanel.bnManageTags.actionCommand= GlobalSettingsPanel.bnManageTags.toolTipText= GlobalSettingsPanel.bnManageTags.text=Manage Tags diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.form b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.form index 49d525511b..731c177818 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.form +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.form @@ -31,7 +31,6 @@ - @@ -55,9 +54,7 @@ - - - + @@ -177,22 +174,6 @@ - - - - - - - - - - - - - - - - @@ -415,7 +396,7 @@ - + diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java index de99aff998..37d18036d8 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/GlobalSettingsPanel.java @@ -71,9 +71,6 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i private void customizeComponents() { setName(Bundle.GlobalSettingsPanel_title()); - - // The hash set functions of central repo are not being included in the current release. - bnImportDatabase.setVisible(false); } private void addIngestJobEventsListener() { @@ -99,7 +96,6 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i lbDbNameValue = new javax.swing.JLabel(); lbDbLocationValue = new javax.swing.JLabel(); cbUseCentralRepo = new javax.swing.JCheckBox(); - bnImportDatabase = new javax.swing.JButton(); pnTagManagement = new javax.swing.JPanel(); bnManageTags = new javax.swing.JButton(); manageTagsScrollPane = new javax.swing.JScrollPane(); @@ -180,15 +176,6 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i } }); - bnImportDatabase.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/centralrepository/images/import16.png"))); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(bnImportDatabase, org.openide.util.NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.bnImportDatabase.label")); // NOI18N - bnImportDatabase.setActionCommand(org.openide.util.NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.bnImportDatabase.actionCommand")); // NOI18N - bnImportDatabase.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - bnImportDatabaseActionPerformed(evt); - } - }); - pnTagManagement.setBorder(javax.swing.BorderFactory.createTitledBorder(null, org.openide.util.NbBundle.getMessage(GlobalSettingsPanel.class, "GlobalSettingsPanel.pnTagManagement.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N pnTagManagement.setPreferredSize(new java.awt.Dimension(674, 97)); @@ -353,8 +340,7 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i .addComponent(pnCorrelationProperties, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(pnTagManagement, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(pnDatabaseConfiguration, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(cbUseCentralRepo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(bnImportDatabase, javax.swing.GroupLayout.Alignment.LEADING)) + .addComponent(cbUseCentralRepo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()))) ); layout.setVerticalGroup( @@ -373,20 +359,12 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i .addComponent(organizationPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, 0) .addComponent(tbOops, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(0, 0, 0) - .addComponent(bnImportDatabase) - .addContainerGap()) + .addGap(36, 36, 36)) ); pnTagManagement.getAccessibleContext().setAccessibleName(""); }// //GEN-END:initComponents - private void bnImportDatabaseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnImportDatabaseActionPerformed - store(); - //ImportHashDatabaseDialog dialog = new ImportHashDatabaseDialog(); - //firePropertyChange(OptionsPanelController.PROP_VALID, null, null); - }//GEN-LAST:event_bnImportDatabaseActionPerformed - private void bnManageTagsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnManageTagsActionPerformed store(); ManageTagsDialog dialog = new ManageTagsDialog(); @@ -567,7 +545,6 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i pnCorrelationProperties.setEnabled(enable && !ingestRunning); pnTagManagement.setEnabled(enable && !ingestRunning); bnManageTypes.setEnabled(enable && !ingestRunning); - bnImportDatabase.setEnabled(enable && !ingestRunning); bnManageTags.setEnabled(enable && !ingestRunning); manageTagsTextArea.setEnabled(enable && !ingestRunning); correlationPropertiesTextArea.setEnabled(enable && !ingestRunning); @@ -579,7 +556,6 @@ public final class GlobalSettingsPanel extends IngestModuleGlobalSettingsPanel i // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton bnDbConfigure; - private javax.swing.JButton bnImportDatabase; private javax.swing.JButton bnManageTags; private javax.swing.JButton bnManageTypes; private javax.swing.JCheckBox cbUseCentralRepo; diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchDialog.java b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchDialog.java index a66e49aa2a..66cca80df1 100755 --- a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchDialog.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchDialog.java @@ -57,7 +57,7 @@ class FileSearchDialog extends javax.swing.JDialog { @Override public void actionPerformed(ActionEvent e) { dispose(); - } + } }); } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties index ff3cf1c7f5..e802f9f9f5 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle.properties @@ -211,31 +211,6 @@ HashLookupSettingsPanel.hashDatabasesLabel.text=Hash Databases: HashLookupSettingsPanel.importDatabaseButton.toolTipText= HashLookupSettingsPanel.importDatabaseButton.text=Import database HashLookupSettingsPanel.deleteDatabaseButton.text=Delete database -HashLookupSettingsPanel.hashDbTypeLabel1.text=No database selected -HashLookupSettingsPanel.importDatabaseButton1.text=Import database -HashLookupSettingsPanel.jLabel1.text=Version: -HashLookupSettingsPanel.hashDatabasesLabel1.text=Hash Databases: -HashLookupSettingsPanel.hashDbNameLabel1.text=No database selected -HashLookupSettingsPanel.ingestWarningLabel1.text=Ingest is ongoing, some settings will be unavailable until it finishes. -HashLookupSettingsPanel.informationLabel1.text=Information -HashLookupSettingsPanel.jLabel3.text=jLabel3 -HashLookupSettingsPanel.optionsLabel1.text=Options -HashLookupSettingsPanel.nameLabel1.text=Hash Set Name: -HashLookupSettingsPanel.sendIngestMessagesCheckBox1.text=Send ingest inbox message for each hit -HashLookupSettingsPanel.importDatabaseButton1.toolTipText= -HashLookupSettingsPanel.typeLabel1.text=Type: -ImportCentralRepoDatabaseDialog.cbInboxMessages.text=Send ingest inbox message for each hit -ImportCentralRepoDatabaseDialog.cancelButton.text=Cancel -ImportCentralRepoDatabaseDialog.lbDatabaseVersion.text=Hash Set Version: -ImportCentralRepoDatabaseDialog.okButton.text=OK -ImportCentralRepoDatabaseDialog.lbDatabaseName.text=Hash Set Name: -ImportCentralRepoDatabaseDialog.lbSourceOrganization.text=Source Organization: -ImportCentralRepoDatabaseDialog.lbDatabaseType.text=Type of database: -ImportCentralRepoDatabaseDialog.knownBadRadioButton.text=Notable -ImportCentralRepoDatabaseDialog.bnNewOrganization.text=Add New Organization -ImportCentralRepoDatabaseDialog.knownRadioButton.text=Known (NSRL or other) -ImportCentralRepoDatabaseDialog.openButton.text=Open... -ImportCentralRepoDatabaseDialog.tfFilePath.text= ImportHashDatabaseDialog.lbFilePath.text=Database Path: ImportHashDatabaseDialog.tfDatabaseName.tooltip=Name for this database ImportHashDatabaseDialog.tfDatabaseVersion.tooltip.text=Database Version Number diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle_ja.properties b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle_ja.properties index ebe1466e05..3a1eac32f4 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle_ja.properties +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/Bundle_ja.properties @@ -209,13 +209,3 @@ HashLookupSettingsPanel.hashDbNameLabel.text=\u30c7\u30fc\u30bf\u30d9\u30fc\u30b HashLookupSettingsPanel.nameLabel.text=\u30cf\u30c3\u30b7\u30e5\u30bb\u30c3\u30c8\u540d\uff1a HashLookupSettingsPanel.hashDatabasesLabel.text=\u30cf\u30c3\u30b7\u30e5\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\uff1a HashLookupSettingsPanel.importDatabaseButton.text=\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u30a4\u30f3\u30dd\u30fc\u30c8 -HashLookupSettingsPanel.typeLabel1.text=\u30bf\u30a4\u30d7\uff1a -HashLookupSettingsPanel.hashDbTypeLabel1.text=\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304c\u9078\u629e\u3055\u308c\u3066\u3044\u307e\u305b\u3093 -HashLookupSettingsPanel.importDatabaseButton1.text=\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u30a4\u30f3\u30dd\u30fc\u30c8 -HashLookupSettingsPanel.hashDatabasesLabel1.text=\u30cf\u30c3\u30b7\u30e5\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\uff1a -HashLookupSettingsPanel.hashDbNameLabel1.text=\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304c\u9078\u629e\u3055\u308c\u3066\u3044\u307e\u305b\u3093 -HashLookupSettingsPanel.ingestWarningLabel1.text=\u30a4\u30f3\u30b8\u30a7\u30b9\u30c8\u4e2d\u3067\u3059\u3002\u5b8c\u4e86\u3059\u308b\u307e\u3067\u4e00\u90e8\u306e\u8a2d\u5b9a\u306f\u5229\u7528\u3067\u304d\u307e\u305b\u3093\u3002 -HashLookupSettingsPanel.informationLabel1.text=\u60c5\u5831 -HashLookupSettingsPanel.optionsLabel1.text=\u30aa\u30d7\u30b7\u30e7\u30f3 -HashLookupSettingsPanel.nameLabel1.text=\u30cf\u30c3\u30b7\u30e5\u30bb\u30c3\u30c8\u540d\uff1a -HashLookupSettingsPanel.sendIngestMessagesCheckBox1.text=\u30d2\u30c3\u30c8\u6bce\u306b\u30a4\u30f3\u30b8\u30a7\u30b9\u30c8\u30a4\u30f3\u30dc\u30c3\u30af\u30b9\u306b\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9001\u308b diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.form b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.form deleted file mode 100644 index 2f42a4ef79..0000000000 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.form +++ /dev/null @@ -1,290 +0,0 @@ - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.java deleted file mode 100644 index a9a44839a8..0000000000 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDatabaseDialog.java +++ /dev/null @@ -1,716 +0,0 @@ -/* - * Central Repository - * - * Copyright 2015-2017 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.modules.hashdatabase; - -import java.awt.Dimension; -import java.awt.Toolkit; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.net.UnknownHostException; -import java.nio.file.Files; -import java.time.LocalDate; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.logging.Level; -import javax.swing.JComboBox; -import javax.swing.JFileChooser; -import javax.swing.JFrame; -import javax.swing.JOptionPane; -import javax.swing.JTextField; -import javax.swing.SwingUtilities; -import javax.swing.SwingWorker; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; -import javax.swing.filechooser.FileNameExtensionFilter; -import org.netbeans.api.progress.ProgressHandle; -import org.netbeans.spi.options.OptionsPanelController; -import org.openide.util.Exceptions; -import org.openide.util.NbBundle; -import org.openide.util.NbBundle.Messages; -import org.openide.windows.WindowManager; -import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttribute; -import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.coreutils.ModuleSettings; -import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttributeInstance; -import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException; -import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalFileInstance; -import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalSet; -import org.sleuthkit.autopsy.centralrepository.datamodel.EamOrganization; -import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; -import org.sleuthkit.autopsy.centralrepository.optionspanel.AddNewOrganizationDialog; -import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager; -import org.sleuthkit.datamodel.TskData; - -/** - * Instances of this class allow a user to select an existing hash database and - * add it to the set of hash databases used to classify files as unknown, known, - * or notable. - */ -final public class ImportCentralRepoDatabaseDialog extends javax.swing.JDialog { - private static final Logger LOGGER = Logger.getLogger(ImportCentralRepoDatabaseDialog.class.getName()); - - private final JFileChooser fileChooser = new JFileChooser(); - private final static String LAST_FILE_PATH_KEY = "CentralRepositoryImport_Path"; // NON-NLS - private final int HASH_IMPORT_THRESHOLD = 10000; - private EamOrganization selectedOrg = null; - private List orgs = null; - private final Collection textBoxes; - private final TextBoxChangedListener textBoxChangedListener; - private HashDbManager.HashDatabase selectedHashDb = null; - - - /** - * Displays a dialog that allows a user to select an existing hash database - * and add it to the set of hash databases used to classify files as - * unknown, known, or notable. - */ - @Messages({"ImportCentralRepoDatabaseDialog.importHashDbMsg=Import Hash Database"}) - public ImportCentralRepoDatabaseDialog() { - super((JFrame) WindowManager.getDefault().getMainWindow(), - Bundle.ImportCentralRepoDatabaseDialog_importHashDbMsg(), - true); // NON-NLS - - textBoxes = new ArrayList<>(); - textBoxChangedListener = new TextBoxChangedListener(); - initFileChooser(); - initComponents(); - customizeComponents(); - display(); - } - - @Messages({"ImportCentralRepoDatabaseDialog.fileNameExtFilter.text=Hash Database File",}) - private void initFileChooser() { - fileChooser.setDragEnabled(false); - fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - String[] EXTENSION = new String[]{"idx"}; //NON-NLS - FileNameExtensionFilter filter = new FileNameExtensionFilter( - Bundle.ImportCentralRepoDatabaseDialog_fileNameExtFilter_text(), - EXTENSION); // NON-NLS - fileChooser.setFileFilter(filter); - fileChooser.setMultiSelectionEnabled(false); - - if (ModuleSettings.settingExists(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY)) { - String lastBaseDirectory = ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY); - File hashDbFolder = new File(lastBaseDirectory); - if(hashDbFolder.exists()){ - fileChooser.setCurrentDirectory(hashDbFolder); - } - } - } - - private void customizeComponents() { - populateCombobox(); - setTextBoxListeners(); - enableOkButton(false); - } - - public HashDbManager.HashDatabase getHashDatabase(){ - return this.selectedHashDb; - } - - /** - * Register for notifications when the text boxes get updated. - */ - private void setTextBoxListeners() { - textBoxes.add(tfFilePath); - textBoxes.add(tfDatabaseName); - textBoxes.add(tfDatabaseVersion); - addDocumentListeners(textBoxes, textBoxChangedListener); - } - - private void populateCombobox() { - comboboxSourceOrganization.removeAllItems(); - try { - EamDb dbManager = EamDb.getInstance(); - orgs = dbManager.getOrganizations(); - orgs.forEach((org) -> { - comboboxSourceOrganization.addItem(org.getName()); - }); - if (!orgs.isEmpty()) { - selectedOrg = orgs.get(0); - } - valid(); - } catch (EamDbException ex) { - LOGGER.log(Level.SEVERE, "Failure populating combobox with organizations.", ex); - } - } - - /** - * Adds a change listener to a collection of text fields. - * - * @param textFields The text fields. - * @param listener The change listener. - */ - private static void addDocumentListeners(Collection textFields, TextBoxChangedListener listener) { - textFields.forEach((textField) -> { - textField.getDocument().addDocumentListener(listener); - }); - } - - /** - * Tests whether or not values have been entered in all of the required - * text fields. - * - * @return True or false. - */ - private boolean textFieldsArePopulated() { - return !tfDatabaseName.getText().trim().isEmpty() - && !tfDatabaseVersion.getText().trim().isEmpty() - && !tfFilePath.getText().trim().isEmpty(); - } - - /** - * Tests whether or not all of the settings components are populated. - * - * @return True or false. - */ - @Messages({"ImportHashDatabaseDialog.validation.incompleteFields=Fill in all values"}) - private boolean checkFields() { - boolean result = true; - - boolean allPopulated = textFieldsArePopulated(); - - if (!allPopulated) { - // We don't even have everything filled out - result = false; - lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_validation_incompleteFields()); - } - return result; - } - - /** - * Validates that the form is filled out correctly for our usage. - * - * @return true if it's okay, false otherwise. - */ - @Messages({"ImportHashDatabaseDialog.validation.notEnabled=Central Repository is not enabled."}) - public boolean valid() { - lbWarningMsg.setText(""); - if (!EamDb.isEnabled()) { - lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_validation_notEnabled()); - return false; - } - - return enableOkButton(checkFields() && null != selectedOrg); - } - - /** - * Enables the "OK" button to create the Global File Set and insert the instances. - * - * @param enable - * - * @return True or False - */ - private boolean enableOkButton(Boolean enable) { - okButton.setEnabled(enable); - return enable; - } - - /** - * Used to listen for changes in text boxes. It lets the panel know things - * have been updated and that validation needs to happen. - */ - private class TextBoxChangedListener implements DocumentListener { - - @Override - public void changedUpdate(DocumentEvent e) { - firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); - valid(); - } - - @Override - public void insertUpdate(DocumentEvent e) { - firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); - valid(); - } - - @Override - public void removeUpdate(DocumentEvent e) { - firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); - valid(); - } - } - - private void display() { - Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); - setLocation((screenDimension.width - getSize().width) / 2, (screenDimension.height - getSize().height) / 2); - setVisible(true); - } - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - buttonGroup1 = new javax.swing.ButtonGroup(); - okButton = new javax.swing.JButton(); - cancelButton = new javax.swing.JButton(); - tfFilePath = new javax.swing.JTextField(); - openButton = new javax.swing.JButton(); - knownRadioButton = new javax.swing.JRadioButton(); - knownBadRadioButton = new javax.swing.JRadioButton(); - lbDatabaseType = new javax.swing.JLabel(); - lbDatabasePath = new javax.swing.JLabel(); - lbSourceOrganization = new javax.swing.JLabel(); - lbDatabaseName = new javax.swing.JLabel(); - lbDatabaseVersion = new javax.swing.JLabel(); - comboboxSourceOrganization = new javax.swing.JComboBox<>(); - tfDatabaseName = new javax.swing.JTextField(); - tfDatabaseVersion = new javax.swing.JTextField(); - bnNewOrganization = new javax.swing.JButton(); - lbWarningMsg = new javax.swing.JLabel(); - cbInboxMessages = new javax.swing.JCheckBox(); - - setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - - org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.okButton.text")); // NOI18N - okButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - okButtonActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.cancelButton.text")); // NOI18N - cancelButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - cancelButtonActionPerformed(evt); - } - }); - - tfFilePath.setText(org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.tfFilePath.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(openButton, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.openButton.text")); // NOI18N - openButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - openButtonActionPerformed(evt); - } - }); - - buttonGroup1.add(knownRadioButton); - org.openide.awt.Mnemonics.setLocalizedText(knownRadioButton, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.knownRadioButton.text")); // NOI18N - - buttonGroup1.add(knownBadRadioButton); - knownBadRadioButton.setSelected(true); - org.openide.awt.Mnemonics.setLocalizedText(knownBadRadioButton, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.knownBadRadioButton.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseType, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.lbDatabaseType.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(lbDatabasePath, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportHashDatabaseDialog.lbFilePath.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(lbSourceOrganization, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.lbSourceOrganization.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseName, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.lbDatabaseName.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseVersion, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.lbDatabaseVersion.text")); // NOI18N - - comboboxSourceOrganization.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); - comboboxSourceOrganization.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - comboboxSourceOrganizationActionPerformed(evt); - } - }); - - tfDatabaseName.setToolTipText(org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportHashDatabaseDialog.tfDatabaseName.tooltip")); // NOI18N - - tfDatabaseVersion.setToolTipText(org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportHashDatabaseDialog.tfDatabaseVersion.tooltip.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(bnNewOrganization, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.bnNewOrganization.text")); // NOI18N - bnNewOrganization.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - bnNewOrganizationActionPerformed(evt); - } - }); - - lbWarningMsg.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N - lbWarningMsg.setForeground(new java.awt.Color(255, 0, 0)); - - cbInboxMessages.setSelected(true); - org.openide.awt.Mnemonics.setLocalizedText(cbInboxMessages, org.openide.util.NbBundle.getMessage(ImportCentralRepoDatabaseDialog.class, "ImportCentralRepoDatabaseDialog.cbInboxMessages.text")); // NOI18N - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(cbInboxMessages) - .addGap(0, 0, Short.MAX_VALUE)) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addComponent(okButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cancelButton)) - .addGroup(layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(lbDatabaseName) - .addComponent(lbDatabaseVersion) - .addComponent(lbSourceOrganization)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(comboboxSourceOrganization, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(bnNewOrganization) - .addGap(0, 0, Short.MAX_VALUE)) - .addComponent(tfDatabaseName) - .addComponent(tfDatabaseVersion))) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addComponent(lbDatabasePath) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(tfFilePath, javax.swing.GroupLayout.PREFERRED_SIZE, 324, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addComponent(lbDatabaseType, javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() - .addGap(19, 19, 19) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(knownRadioButton) - .addComponent(knownBadRadioButton)))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(openButton))) - .addGap(6, 6, 6)) - .addComponent(lbWarningMsg, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - ); - - layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton}); - - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(lbDatabasePath) - .addComponent(tfFilePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(openButton)) - .addGap(6, 6, 6) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(lbDatabaseName, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(tfDatabaseName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(lbDatabaseVersion, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(tfDatabaseVersion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(lbSourceOrganization, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(comboboxSourceOrganization, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(bnNewOrganization)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(lbDatabaseType) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(knownRadioButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(knownBadRadioButton) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cbInboxMessages) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(lbWarningMsg, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(okButton) - .addComponent(cancelButton)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - - pack(); - }// //GEN-END:initComponents - - @Messages({"ImportHashDatabaseDialog.failedToGetDbPathMsg=Failed to get the path of the selected database.",}) - private void openButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openButtonActionPerformed - if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { - File databaseFile = fileChooser.getSelectedFile(); - try { - tfFilePath.setText(databaseFile.getCanonicalPath()); - if (databaseFile.getName().toLowerCase().contains("nsrl")) { //NON-NLS - knownRadioButton.setSelected(true); - } - ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY, databaseFile.getParent()); - } catch (IOException ex) { - Logger.getLogger(ImportCentralRepoDatabaseDialog.class.getName()).log(Level.SEVERE, "Failed to get path of selected database", ex); // NON-NLS - lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_failedToGetDbPathMsg()); - } - } - valid(); - }//GEN-LAST:event_openButtonActionPerformed - - private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed - dispose(); - }//GEN-LAST:event_cancelButtonActionPerformed - - /** - * Create the new global set and return the ID number - * - * @return ID number of new global set - * @throws EamDbException - */ - private int createGlobalSet() throws EamDbException { - /*EamDb dbManager = EamDb.getInstance(); - EamGlobalSet eamGlobalSet = new EamGlobalSet( - selectedOrg.getOrgID(), - tfDatabaseName.getText().trim(), - tfDatabaseVersion.getText().trim(), - LocalDate.now()); - return dbManager.newReferencelSet(eamGlobalSet);*/ - return 0; - } - - @Messages({"ImportHashDatabaseDialog.createGlobalSet.failedMsg.text=Failed to store attribution details.", - "ImportHashDatabaseDialog.mustSelectHashDbFilePathMsg=Missing hash database file path.", - "ImportHashDatabaseDialog.hashDbDoesNotExistMsg=The selected hash database does not exist.", - "# {0} - selected file path", - "ImportHashDatabaseDialog.errorMessage.failedToOpenHashDbMsg=Failed to open hash database at {0}.", - "ImportHashDatabaseDialog.dbAlreadyExists=A database with that name and version already exists.", - "ImportHashDatabaseDialog.centralRepoError=Error accessing the central repository", -}) - private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed - // Note that the error handlers in this method call return without disposing of the - // dialog to allow the user to try again, if desired. - String selectedFilePath = tfFilePath.getText(); - - // have valid file path - if (selectedFilePath.isEmpty()) { - lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_mustSelectHashDbFilePathMsg()); - return; - } - File file = new File(selectedFilePath); - if (!file.exists()) { - lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_hashDbDoesNotExistMsg()); - return; - } - - String dbName = tfDatabaseName.getText().trim(); - String version = tfDatabaseVersion.getText().trim(); - - try{ - if(EamDb.getInstance().referenceSetExists(dbName, version)){ - lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_dbAlreadyExists()); - return; - } - } catch (EamDbException ex){ - lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_centralRepoError()); - LOGGER.log(Level.SEVERE, "Error searching for reference set in central repo", ex); - return; - } - - HashDbManager.HashDb.KnownFilesType known; - if (knownRadioButton.isSelected()) { - known = HashDbManager.HashDb.KnownFilesType.KNOWN; - } else{ - known = HashDbManager.HashDb.KnownFilesType.KNOWN_BAD; - } - - boolean sendMessages = this.cbInboxMessages.isSelected(); - - try{ - ImportCentralRepoDbProgressDialog progressDialog = new ImportCentralRepoDbProgressDialog(); - //progressDialog.importFile(dbName, version, - // selectedOrg.getOrgID(), true, sendMessages, known, selectedFilePath); - //HashDbManager.getInstance().importCentralRepoHashSet(dbName, version, - // selectedOrg.getOrgID(), true, sendMessages, known, selectedFilePath); - } catch (Exception ex){ - ex.printStackTrace(); - } finally { - dispose(); - } - /* - // create global set - int globalSetID; - try { - globalSetID = createGlobalSet(); - } catch (EamDbException ex) { - LOGGER.log(Level.SEVERE, "Failed to create global set.", ex); - lbWarningMsg.setText(Bundle.ImportHashDatabaseDialog_createGlobalSet_failedMsg_text()); - return; - } - - // insert hashes - TskData.FileKnown knownStatus = TskData.FileKnown.UNKNOWN; - if (knownRadioButton.isSelected()) { - knownStatus = TskData.FileKnown.KNOWN; - } else if (knownBadRadioButton.isSelected()) { - knownStatus = TskData.FileKnown.BAD; - } - - String errorMessage = Bundle.ImportHashDatabaseDialog_errorMessage_failedToOpenHashDbMsg(selectedFilePath); - // Future, make UI handle more than the "FILES" type. - try { - EamDb dbManager = EamDb.getInstance(); - CorrelationAttribute.Type contentType = dbManager.getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID); // get "FILES" type - // run in the background and close dialog - SwingUtilities.invokeLater(new ImportHashDatabaseWorker(selectedFilePath, knownStatus, globalSetID, contentType)::execute); - dispose(); - } catch (EamDbException | UnknownHostException ex) { - Logger.getLogger(ImportHashDatabaseDialog.class.getName()).log(Level.SEVERE, errorMessage, ex); - lbWarningMsg.setText(ex.getMessage()); - }*/ - - }//GEN-LAST:event_okButtonActionPerformed - - @SuppressWarnings({"unchecked"}) - private void bnNewOrganizationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnNewOrganizationActionPerformed - AddNewOrganizationDialog dialogO = new AddNewOrganizationDialog(); - // update the combobox options - if (dialogO.isChanged()) { - populateCombobox(); - } - }//GEN-LAST:event_bnNewOrganizationActionPerformed - - @SuppressWarnings({"unchecked"}) - private void comboboxSourceOrganizationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboboxSourceOrganizationActionPerformed - JComboBox cb = (JComboBox)evt.getSource(); - String orgName = (String)cb.getSelectedItem(); - if (null == orgName) return; - - for (EamOrganization org : orgs) { - if (org.getName().equals(orgName)) { - selectedOrg = org; - return; - } - } - valid(); - }//GEN-LAST:event_comboboxSourceOrganizationActionPerformed - - @NbBundle.Messages({"ImportHashDatabaseDialog.ImportHashDatabaseWorker.displayName=Importing Hash Database"}) - public class ImportHashDatabaseWorker extends SwingWorker { - - private final File file; - private final TskData.FileKnown knownStatus; - private final int globalSetID; - private final ProgressHandle progress; - private final CorrelationAttribute.Type contentType; - - public ImportHashDatabaseWorker(String filename, TskData.FileKnown knownStatus, int globalSetID, CorrelationAttribute.Type contentType) throws EamDbException, UnknownHostException { - this.file = new File(filename); - this.knownStatus = knownStatus; - this.globalSetID = globalSetID; - this.contentType = contentType; - this.progress = ProgressHandle.createHandle(Bundle.ImportHashDatabaseDialog_ImportHashDatabaseWorker_displayName()); - - if (!EamDb.isEnabled()) { - throw new EamDbException("Central repository database is not enabled."); // NON-NLS - } - } - - @Override - protected Void doInBackground() throws Exception { - importHashDatabase(); - return null; - } - - @Override - @Messages({"ImportHashDatabaseDialog.ImportHashDatabaseWorker.error=Failed to import hash database."}) - protected void done() { - progress.finish(); - try { - get(); - } catch (InterruptedException | ExecutionException ex) { - Logger.getLogger(ImportCentralRepoDatabaseDialog.class.getName()).log(Level.SEVERE, Bundle.ImportHashDatabaseDialog_ImportHashDatabaseWorker_error(), ex); - MessageNotifyUtil.Notify.show(Bundle.ImportHashDatabaseDialog_ImportHashDatabaseWorker_error(), - ex.getMessage(), - MessageNotifyUtil.MessageType.ERROR); - } - } - - private long numberOfLinesInFile(File f) throws IOException { - return Files.lines(f.toPath()).count(); - } - - @Messages({"# {0} - value content", - "ImportHashDatabaseDialog.ImportHashDatabaseWorker.duplicate=Duplicate value {0} found in import file."}) - private void importHashDatabase() throws EamDbException, IOException { - BufferedReader reader = new BufferedReader(new FileReader(file)); - String line; - EamDb dbManager = EamDb.getInstance(); - Set globalInstances = new HashSet<>(); - - long totalLines = numberOfLinesInFile(file); - if (totalLines <= Integer.MAX_VALUE) { - progress.start((int) totalLines); - } else { - progress.start(); - } - - int numLines = 0; - LOGGER.log(Level.INFO, "Importing hash database {0}", file.getName()); - while ((line = reader.readLine()) != null) { - progress.progress(++numLines); - - String[] parts = line.split("\\|"); - - // Header lines start with a 41 character dummy hash, 1 character longer than a SHA-1 hash - if (parts.length != 2 || parts[0].length() == 41) { - continue; - } - - EamGlobalFileInstance eamGlobalFileInstance = new EamGlobalFileInstance( - globalSetID, - parts[0].toLowerCase(), - knownStatus, - ""); - - globalInstances.add(eamGlobalFileInstance); - - if(numLines % HASH_IMPORT_THRESHOLD == 0){ - dbManager.bulkInsertReferenceTypeEntries(globalInstances, contentType); - globalInstances.clear(); - } - } - - dbManager.bulkInsertReferenceTypeEntries(globalInstances, contentType); - LOGGER.log(Level.INFO, "Finished importing hash database. Total entries: {0}", numLines); - - } - } - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton bnNewOrganization; - private javax.swing.ButtonGroup buttonGroup1; - private javax.swing.JButton cancelButton; - private javax.swing.JCheckBox cbInboxMessages; - private javax.swing.JComboBox comboboxSourceOrganization; - private javax.swing.JRadioButton knownBadRadioButton; - private javax.swing.JRadioButton knownRadioButton; - private javax.swing.JLabel lbDatabaseName; - private javax.swing.JLabel lbDatabasePath; - private javax.swing.JLabel lbDatabaseType; - private javax.swing.JLabel lbDatabaseVersion; - private javax.swing.JLabel lbSourceOrganization; - private javax.swing.JLabel lbWarningMsg; - private javax.swing.JButton okButton; - private javax.swing.JButton openButton; - private javax.swing.JTextField tfDatabaseName; - private javax.swing.JTextField tfDatabaseVersion; - private javax.swing.JTextField tfFilePath; - // End of variables declaration//GEN-END:variables -} From 95cf6fb95fe646039eb229e5ff0824e260084b52 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Tue, 31 Oct 2017 14:34:01 -0400 Subject: [PATCH 21/41] Cleanup --- .../optionspanel/Bundle.properties | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties index b0c10ad498..b9ab823b1d 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/optionspanel/Bundle.properties @@ -59,18 +59,5 @@ ManageCorrelationPropertiesDialog.lbWarningMsg.text=Warning Message ManageCorrelationPropertiesDialog.cancelButton.text=Cancel ManageCorrelationPropertiesDialog.okButton.text=OK GlobalSettingsPanel.bnManageProperties.text=Manage Correlation Properties -ImportHashDatabaseDialog.lbFilePath.text=Database Path: EamDbSettingsDialog.lbDatabaseDesc.text=Database File: -ImportCentralRepoDatabaseDialog.cancelButton.text=Cancel -ImportCentralRepoDatabaseDialog.lbDatabaseVersion.text=Hash Set Version: -ImportCentralRepoDatabaseDialog.okButton.text=OK -ImportCentralRepoDatabaseDialog.lbDatabaseName.text=Hash Set Name: -ImportCentralRepoDatabaseDialog.lbSourceOrganization.text=Source Organization: -ImportCentralRepoDatabaseDialog.lbDatabaseType.text=Type of database: -ImportCentralRepoDatabaseDialog.knownBadRadioButton.text=Notable -ImportCentralRepoDatabaseDialog.bnNewOrganization.text=Add New Organization -ImportCentralRepoDatabaseDialog.knownRadioButton.text=Known (NSRL or other) -ImportCentralRepoDatabaseDialog.openButton.text=Open... -ImportCentralRepoDatabaseDialog.tfFilePath.text= -ImportCentralRepoDatabaseDialog.cbInboxMessages.text=Send ingest inbox messages for each hit EamDbSettingsDialog.lbFullDbPath.text= From 2e128fcbbdb9686b9595c9938e232b1369b681df Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Wed, 1 Nov 2017 13:19:42 -0400 Subject: [PATCH 22/41] Cleanup --- .../ingestmodule/IngestModule.java | 37 ------- .../HashDbImportDatabaseDialog.java | 17 +-- .../modules/hashdatabase/HashDbManager.java | 104 +----------------- .../HashLookupModuleSettingsPanel.java | 8 +- .../hashdatabase/HashLookupSettings.java | 6 +- .../ImportCentralRepoDbProgressDialog.java | 2 +- 6 files changed, 21 insertions(+), 153 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/ingestmodule/IngestModule.java b/Core/src/org/sleuthkit/autopsy/centralrepository/ingestmodule/IngestModule.java index 31d989d74a..30d374f133 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/ingestmodule/IngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/ingestmodule/IngestModule.java @@ -121,16 +121,6 @@ class IngestModule implements FileIngestModule { } } - // Make a TSK_HASHSET_HIT blackboard artifact for global notable files - try { - if (dbManager.isArtifactlKnownBadByReference(filesType, md5)) { - postCorrelatedHashHitToBlackboard(af); - } - } catch (EamDbException ex) { - LOGGER.log(Level.SEVERE, "Error retrieving global known status.", ex); // NON-NLS - return ProcessResult.ERROR; - } - try { CorrelationAttribute eamArtifact = new CorrelationAttribute(filesType, md5); CorrelationAttributeInstance cefi = new CorrelationAttributeInstance( @@ -307,33 +297,6 @@ class IngestModule implements FileIngestModule { } } - private void postCorrelatedHashHitToBlackboard(AbstractFile abstractFile) { - try { - String MODULE_NAME = IngestModuleFactory.getModuleName(); - BlackboardArtifact tifArtifact = abstractFile.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT); - BlackboardAttribute att = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME, MODULE_NAME, - Bundle.IngestModule_prevCaseComment_text()); - tifArtifact.addAttribute(att); - - try { - // index the artifact for keyword search - blackboard.indexArtifact(tifArtifact); - } catch (Blackboard.BlackboardException ex) { - LOGGER.log(Level.SEVERE, "Unable to index blackboard artifact " + tifArtifact.getArtifactID(), ex); //NON-NLS - } - - // send inbox message - sendBadFileInboxMessage(tifArtifact, abstractFile.getName(), abstractFile.getMd5Hash()); - - // fire event to notify UI of this new artifact - services.fireModuleDataEvent(new ModuleDataEvent(MODULE_NAME, BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT)); - } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "Failed to create BlackboardArtifact.", ex); // NON-NLS - } catch (IllegalStateException ex) { - LOGGER.log(Level.SEVERE, "Failed to create BlackboardAttribute.", ex); // NON-NLS - } - } - /** * Post a message to the ingest inbox alerting the user that a bad file was * found. diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java index 6e208a9475..7f243b7bc6 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java @@ -37,6 +37,7 @@ import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException; import org.sleuthkit.autopsy.centralrepository.datamodel.EamOrganization; import org.sleuthkit.autopsy.centralrepository.optionspanel.AddNewOrganizationDialog; +import org.sleuthkit.autopsy.centralrepository.optionspanel.ManageOrganizationsDialog; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.PlatformUtil; @@ -127,6 +128,7 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { readOnlyCheckbox.setEnabled(! isFileType); } + @NbBundle.Messages({"HashDbImportDatabaseDialog.populateOrgsError.message=Failure loading organizations."}) private void populateCombobox() { orgComboBox.removeAllItems(); try { @@ -139,8 +141,8 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { selectedOrg = orgs.get(0); } } catch (EamDbException ex) { - ex.printStackTrace(); - //LOGGER.log(Level.SEVERE, "Failure populating combobox with organizations.", ex); + JOptionPane.showMessageDialog(null, Bundle.HashDbImportDatabaseDialog_populateOrgsError_message()); + Logger.getLogger(ImportCentralRepoDbProgressDialog.class.getName()).log(Level.SEVERE, "Failure loading organizations", ex); } } @@ -530,18 +532,19 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { }//GEN-LAST:event_centralRepoRadioButtonActionPerformed private void orgButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orgButtonActionPerformed - AddNewOrganizationDialog dialogO = new AddNewOrganizationDialog(); + ManageOrganizationsDialog dialog = new ManageOrganizationsDialog(); // update the combobox options - if (dialogO.isChanged()) { + if (dialog.isChanged()) { populateCombobox(); } }//GEN-LAST:event_orgButtonActionPerformed private void orgComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orgComboBoxActionPerformed - JComboBox cb = (JComboBox)evt.getSource(); - String orgName = (String)cb.getSelectedItem(); - if (null == orgName) return; + //JComboBox cb = (JComboBox)evt.getSource(); + //String orgName = (String)cb.getSelectedItem(); + if (null == orgComboBox.getSelectedItem()) return; + String orgName = this.orgComboBox.getSelectedItem().toString(); for (EamOrganization org : orgs) { if (org.getName().equals(orgName)) { selectedOrg = org; diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index 1b448e43e5..7247bf685a 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -246,16 +246,6 @@ public class HashDbManager implements PropertyChangeListener { return hashDb; } - static HashDatabase convertHashDbInfo(HashDbInfo info, int handle) throws TskCoreException{ - if(info.isFileDatabaseType()){ - return new HashDb(handle, info.getHashSetName(), info.getSearchDuringIngest(), info.getSendIngestMessages(), - info.getKnownFilesType()); - } else if(info.isCentralRepoDatabaseType()){ - throw new TskCoreException("Not implemented yet"); - } - throw new TskCoreException("Invalid database type in HashDbInfo"); - } - private HashDb addFileTypeHashDatabase(int handle, String hashSetName, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws TskCoreException { // Wrap an object around the handle. HashDb hashDb = new HashDb(handle, hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType); @@ -322,93 +312,6 @@ public class HashDbManager implements PropertyChangeListener { return db; } - /* - public CentralRepoHashDb importCentralRepoHashSet(String hashSetName, String version, int orgId, - boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType, - String importFile) throws TskCoreException { - - int crIndex; - - try{ - // Create an empty hashset in the central repository - crIndex = EamDb.getInstance().newReferenceSet(orgId, hashSetName, version); - } catch (EamDbException ex){ - throw new TskCoreException(ex.getLocalizedMessage()); - } - - try{ - // Import the hashes - - TskData.FileKnown knownStatus; - if (knownFilesType.equals(HashDb.KnownFilesType.KNOWN)) { - knownStatus = TskData.FileKnown.KNOWN; - } else { - knownStatus = TskData.FileKnown.BAD; - } - - // Future, make UI handle more than the "FILES" type. - - EamDb dbManager = EamDb.getInstance(); - CorrelationAttribute.Type contentType = dbManager.getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID); // get "FILES" type - BufferedReader reader = new BufferedReader(new FileReader(importFile)); - String line; - Set globalInstances = new HashSet<>(); - - long totalLines = Files.lines(new File(importFile).toPath()).count(); - - int numLines = 0; - while ((line = reader.readLine()) != null) { - - String[] parts = line.split("\\|"); - - // Header lines start with a 41 character dummy hash, 1 character longer than a SHA-1 hash - if (parts.length != 2 || parts[0].length() == 41) { - continue; - } - - EamGlobalFileInstance eamGlobalFileInstance = new EamGlobalFileInstance( - crIndex, - parts[0].toLowerCase(), - knownStatus, - ""); - - globalInstances.add(eamGlobalFileInstance); - - if(numLines % 1000 == 0){ - dbManager.bulkInsertReferenceTypeEntries(globalInstances, contentType); - globalInstances.clear(); - } - } - - dbManager.bulkInsertReferenceTypeEntries(globalInstances, contentType); - - // this should wait until after init - CentralRepoHashDb hashDb = new CentralRepoHashDb(hashSetName, version, crIndex, - searchDuringIngest, sendIngestMessages, knownFilesType); - - // Add the hash database to the collection - hashSets.add(hashDb); - - - - // Let any external listeners know that there's a new set - try { - changeSupport.firePropertyChange(SetEvt.DB_ADDED.toString(), null, hashSetName); - } catch (Exception e) { - logger.log(Level.SEVERE, "HashDbManager listener threw exception", e); //NON-NLS - MessageNotifyUtil.Notify.show( - NbBundle.getMessage(this.getClass(), "HashDbManager.moduleErr"), - NbBundle.getMessage(this.getClass(), "HashDbManager.moduleErrorListeningToUpdatesMsg"), - MessageNotifyUtil.MessageType.ERROR); - } - return hashDb; - - } catch (Exception ex){ - // TODO - ex.printStackTrace(); - throw new TskCoreException(ex.getLocalizedMessage()); - } - }*/ synchronized void indexHashDatabase(HashDb hashDb) { hashDb.addPropertyChangeListener(this); @@ -668,7 +571,7 @@ public class HashDbManager implements PropertyChangeListener { globalSet.getGlobalSetID(), globalSet.getKnownStatus(), globalSet.isReadOnly(), false, sendIngestMessages)); } } catch (EamDbException ex){ - ex.printStackTrace(); + Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error loading central repository hash sets", ex); //NON-NLS } } return crHashSets; @@ -1486,14 +1389,15 @@ public class HashDbManager implements PropertyChangeListener { * @throws TskCoreException */ @Override - public boolean isValid() throws TskCoreException { + public boolean isValid() { if(! EamDb.isEnabled()) { return false; } try{ return EamDb.getInstance().referenceSetIsValid(this.centralRepoIndex, this.hashSetName, this.version); } catch (EamDbException ex){ - throw new TskCoreException(ex.getLocalizedMessage()); + Logger.getLogger(CentralRepoHashDb.class.getName()).log(Level.SEVERE, "Error validating hash database " + hashSetName, ex); //NON-NLS + return false; } } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java index 517640f487..1e83fb77c6 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java @@ -174,13 +174,13 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe } private boolean isHashDbValid(HashDatabase hashDb) { - boolean indexed = false; + boolean isValid = false; try { - indexed = hashDb.isValid(); + isValid = hashDb.isValid(); } catch (TskCoreException ex) { - Logger.getLogger(HashLookupModuleSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting indexed status info for hash set (name = " + hashDb.getHashSetName() + ")", ex); //NON-NLS + Logger.getLogger(HashLookupModuleSettingsPanel.class.getName()).log(Level.SEVERE, "Error checking validity for hash set (name = " + hashDb.getHashSetName() + ")", ex); //NON-NLS } - return indexed; + return isValid; } private static final class HashSetModel { diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java index 8a99f5778a..84f3bd744c 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java @@ -358,7 +358,7 @@ final class HashLookupSettings implements Serializable { } else { this.path = fileTypeDb.getDatabasePath(); } - } else {// if(db instanceof HashDbManager.CentralRepoHashDb){ + } else { HashDbManager.CentralRepoHashDb centralRepoDb = (HashDbManager.CentralRepoHashDb)db; this.hashSetName = centralRepoDb.getHashSetName(); this.version = centralRepoDb.getVersion(); @@ -369,9 +369,7 @@ final class HashLookupSettings implements Serializable { this.path = ""; this.centralRepoIndex = centralRepoDb.getCentralRepoIndex(); this.dbType = DatabaseType.CENTRAL_REPOSITORY; - } //else { - // throw new TskCoreException("Unknown hash database type"); - //} + } } /** diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java index 1284263b65..597cb8c39d 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java @@ -172,7 +172,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P */ final long getEstimatedTotalHashes(){ long fileSize = importFile.length(); - return (fileSize / 0x33); // IDX file lines are generally 0x33 bytes long + return (fileSize / 0x33 + 1); // IDX file lines are generally 0x33 bytes long, and we don't want this to be zero } @Override From 4cf2c33f0f44412b00d6f120389fb08fe11f1b8a Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Wed, 1 Nov 2017 13:35:04 -0400 Subject: [PATCH 23/41] Cleanup --- .../sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index 7247bf685a..562fc8b605 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -1344,7 +1344,7 @@ public class HashDbManager implements PropertyChangeListener { return EamDb.getInstance().isHashInReferenceSet(file.getMd5Hash(), this.centralRepoIndex); } catch (EamDbException ex){ Logger.getLogger(HashDb.class.getName()).log(Level.SEVERE, "Error performing central reposiotry hash lookup", ex); //NON-NLS - throw new TskCoreException(ex.getLocalizedMessage()); + throw new TskCoreException("Error performing central reposiotry hash lookup", ex); } } } @@ -1375,7 +1375,7 @@ public class HashDbManager implements PropertyChangeListener { } } catch (EamDbException ex){ Logger.getLogger(HashDb.class.getName()).log(Level.SEVERE, "Error performing central reposiotry hash lookup", ex); //NON-NLS - throw new TskCoreException(ex.getLocalizedMessage()); + throw new TskCoreException("Error performing central reposiotry hash lookup", ex); } } } From d44efea5b3ae6e87bb9465883c99f6c73ecf33b6 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Fri, 3 Nov 2017 10:26:39 -0400 Subject: [PATCH 24/41] Empty the list of new central repo hash sets when the settings are saved --- .../autopsy/modules/hashdatabase/HashLookupSettingsPanel.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java index 2fbe9570d6..fe2e4a5757 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java @@ -303,7 +303,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan @Override @Messages({"HashLookupSettingsPanel.saveFail.message=Couldn't save hash db settings.", "HashLookupSettingsPanel.saveFail.title=Save Fail"}) - public void saveSettings() { + public void saveSettings() { //Checking for for any unindexed databases List unindexed = new ArrayList<>(); for (HashDatabase hashSet : hashSetManager.getAllHashDatabases()) { @@ -325,8 +325,10 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan } else if (unindexed.size() > 1) { showInvalidIndex(true, unindexed); } + try { hashSetManager.save(); + newCentralRepoIndices.clear(); } catch (HashDbManager.HashDbManagerException ex) { SwingUtilities.invokeLater(() -> { JOptionPane.showMessageDialog(null, Bundle.HashLookupSettingsPanel_saveFail_message(), Bundle.HashLookupSettingsPanel_saveFail_title(), JOptionPane.ERROR_MESSAGE); From 399b7a4b3867232438b720af95753f806f770a0c Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Fri, 3 Nov 2017 11:57:52 -0400 Subject: [PATCH 25/41] Forgot duplicate entry check. --- .../HashDbImportDatabaseDialog.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java index 7f243b7bc6..7977360d40 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java @@ -427,7 +427,9 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { }//GEN-LAST:event_cancelButtonActionPerformed @NbBundle.Messages({"HashDbImportDatabaseDialog.missingVersion=A version must be entered", - "HashDbImportDatabaseDialog.missingOrg=An organization must be selected" + "HashDbImportDatabaseDialog.missingOrg=An organization must be selected", + "HashDbImportDatabaseDialog.duplicateName=A hashset with this name and version already exists", + "HashDbImportDatabaseDialog.databaseLookupError=Error accessing central repository" }) private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed // Note that the error handlers in this method call return without disposing of the @@ -509,6 +511,29 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { return; } } else { + + // Check if a hash set with the same name/version already exists + try{ + if(EamDb.getInstance().referenceSetExists(hashSetNameTextField.getText(), versionTextField.getText())){ + JOptionPane.showMessageDialog(this, + NbBundle.getMessage(this.getClass(), + "HashDbImportDatabaseDialog.duplicateName"), + NbBundle.getMessage(this.getClass(), + "HashDbImportDatabaseDialog.importHashDbErr"), + JOptionPane.ERROR_MESSAGE); + return; + } + } catch (EamDbException ex){ + Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE, "Error looking up reference set", ex); + JOptionPane.showMessageDialog(this, + NbBundle.getMessage(this.getClass(), + "HashDbImportDatabaseDialog.databaseLookupError"), + NbBundle.getMessage(this.getClass(), + "HashDbImportDatabaseDialog.importHashDbErr"), + JOptionPane.ERROR_MESSAGE); + return; + } + ImportCentralRepoDbProgressDialog progressDialog = new ImportCentralRepoDbProgressDialog(); progressDialog.importFile(hashSetNameTextField.getText(), versionTextField.getText(), selectedOrg.getOrgID(), true, sendIngestMessagesCheckbox.isSelected(), type, From bca71afa70135b83ee04c876adc92982aef8a4c1 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Fri, 3 Nov 2017 12:53:23 -0400 Subject: [PATCH 26/41] Fix storing of read only flag --- .../autopsy/modules/hashdatabase/HashLookupSettings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java index 84f3bd744c..ada8967be7 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java @@ -363,7 +363,7 @@ final class HashLookupSettings implements Serializable { this.hashSetName = centralRepoDb.getHashSetName(); this.version = centralRepoDb.getVersion(); this.knownFilesType = centralRepoDb.getKnownFilesType(); - this.readOnly = centralRepoDb.isUpdateable(); + this.readOnly = ! centralRepoDb.isUpdateable(); this.searchDuringIngest = centralRepoDb.getSearchDuringIngest(); this.sendIngestMessages = centralRepoDb.getSendIngestMessages(); this.path = ""; From 9ece65a3f0a546d89f8833d1abbc63ef8e07b649 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Tue, 7 Nov 2017 09:40:01 -0500 Subject: [PATCH 27/41] Added idx only file filter for central repo import --- .../HashDbImportDatabaseDialog.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java index 7977360d40..b0f48c544e 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java @@ -68,9 +68,9 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { super((JFrame) WindowManager.getDefault().getMainWindow(), NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.importHashDbMsg"), true); - initFileChooser(); initComponents(); enableComponents(); + initFileChooser(); display(); } @@ -86,12 +86,24 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { private void initFileChooser() { fileChooser.setDragEnabled(false); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - String[] EXTENSION = new String[]{"txt", "kdb", "idx", "hash", "Hash", "hsh"}; //NON-NLS - FileNameExtensionFilter filter = new FileNameExtensionFilter( - NbBundle.getMessage(this.getClass(), "HashDbImportDatabaseDialog.fileNameExtFilter.text"), EXTENSION); - fileChooser.setFileFilter(filter); + updateFileChooserFilter(); fileChooser.setMultiSelectionEnabled(false); } + + @NbBundle.Messages({"HashDbImportDatabaseDialog.centralRepoExtFilter.text=Hash Database File (.idx only)"}) + private void updateFileChooserFilter() { + if(centralRepoRadioButton.isSelected()){ + String[] EXTENSION = new String[]{"idx"}; //NON-NLS + FileNameExtensionFilter filter = new FileNameExtensionFilter( + NbBundle.getMessage(this.getClass(), "HashDbImportDatabaseDialog.centralRepoExtFilter.text"), EXTENSION); + fileChooser.setFileFilter(filter); + } else { + String[] EXTENSION = new String[]{"txt", "kdb", "idx", "hash", "Hash", "hsh"}; //NON-NLS + FileNameExtensionFilter filter = new FileNameExtensionFilter( + NbBundle.getMessage(this.getClass(), "HashDbImportDatabaseDialog.fileNameExtFilter.text"), EXTENSION); + fileChooser.setFileFilter(filter); + } + } private void display() { Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); @@ -392,6 +404,7 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { hashDbFolder.mkdir(); } fileChooser.setCurrentDirectory(hashDbFolder); + updateFileChooserFilter(); if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File databaseFile = fileChooser.getSelectedFile(); try { From 08c2e05fd427b6cf7fc028eacaedd0673a3044e3 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Tue, 7 Nov 2017 14:23:24 -0500 Subject: [PATCH 28/41] Fix file filter --- .../autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java index b0f48c544e..66037cccf9 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java @@ -92,6 +92,7 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { @NbBundle.Messages({"HashDbImportDatabaseDialog.centralRepoExtFilter.text=Hash Database File (.idx only)"}) private void updateFileChooserFilter() { + fileChooser.resetChoosableFileFilters(); if(centralRepoRadioButton.isSelected()){ String[] EXTENSION = new String[]{"idx"}; //NON-NLS FileNameExtensionFilter filter = new FileNameExtensionFilter( From 055c095a56b666b228e023829c847760fd44d622 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Wed, 8 Nov 2017 15:32:07 -0500 Subject: [PATCH 29/41] Standardized name of referenceSetID. Improved comments. --- .../datamodel/AbstractSqlEamDb.java | 60 +++++++++++-------- .../centralrepository/datamodel/EamDb.java | 33 +++++----- .../datamodel/SqliteEamDb.java | 20 +++---- .../modules/hashdatabase/HashDbManager.java | 28 ++++----- .../hashdatabase/HashLookupSettings.java | 22 +++---- .../hashdatabase/HashLookupSettingsPanel.java | 12 ++-- .../ImportCentralRepoDbProgressDialog.java | 20 +++---- 7 files changed, 102 insertions(+), 93 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java index 18479f91be..fad0196288 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java @@ -1252,16 +1252,21 @@ public abstract class AbstractSqlEamDb implements EamDb { /** * Remove a reference set and all hashes contained in it. - * @param centralRepoIndex + * @param referenceSetID * @throws EamDbException */ @Override - public void deleteReferenceSet(int centralRepoIndex) throws EamDbException{ - deleteReferenceSetFiles(centralRepoIndex); - deleteReferenceSetEntry(centralRepoIndex); + public void deleteReferenceSet(int referenceSetID) throws EamDbException{ + deleteReferenceSetFiles(referenceSetID); + deleteReferenceSetEntry(referenceSetID); } - private void deleteReferenceSetEntry(int centralRepoIndex) throws EamDbException{ + /** + * Remove the entry for this set from the reference_sets table + * @param referenceSetID + * @throws EamDbException + */ + private void deleteReferenceSetEntry(int referenceSetID) throws EamDbException{ Connection conn = connect(); PreparedStatement preparedStatement = null; @@ -1269,7 +1274,7 @@ public abstract class AbstractSqlEamDb implements EamDb { try { preparedStatement = conn.prepareStatement(sql); - preparedStatement.setInt(1, centralRepoIndex); + preparedStatement.setInt(1, referenceSetID); preparedStatement.executeUpdate(); } catch (SQLException ex) { throw new EamDbException("Error deleting reference set", ex); // NON-NLS @@ -1279,8 +1284,12 @@ public abstract class AbstractSqlEamDb implements EamDb { } } - - private void deleteReferenceSetFiles(int centralRepoIndex) throws EamDbException{ + /** + * Remove all entries for this reference set from the reference_file table + * @param referenceSetID + * @throws EamDbException + */ + private void deleteReferenceSetFiles(int referenceSetID) throws EamDbException{ Connection conn = connect(); PreparedStatement preparedStatement = null; @@ -1290,7 +1299,7 @@ public abstract class AbstractSqlEamDb implements EamDb { try { preparedStatement = conn.prepareStatement(String.format(sql, fileTableName)); - preparedStatement.setInt(1, centralRepoIndex); + preparedStatement.setInt(1, referenceSetID); preparedStatement.executeUpdate(); } catch (SQLException ex) { throw new EamDbException("Error deleting files from reference set", ex); // NON-NLS @@ -1302,14 +1311,15 @@ public abstract class AbstractSqlEamDb implements EamDb { /** * Check whether the given reference set exists in the central repository. - * @param centralRepoIndex + * @param referenceSetID * @param hashSetName * @param version - * @return + * @return true if a matching entry exists in the central repository + * @throws EamDbException */ @Override - public boolean referenceSetIsValid(int centralRepoIndex, String hashSetName, String version) throws EamDbException{ - EamGlobalSet refSet = this.getReferenceSetByID(centralRepoIndex); + public boolean referenceSetIsValid(int referenceSetID, String hashSetName, String version) throws EamDbException{ + EamGlobalSet refSet = this.getReferenceSetByID(referenceSetID); if(refSet == null){ return false; } @@ -1320,11 +1330,11 @@ public abstract class AbstractSqlEamDb implements EamDb { /** * Check if the given hash is in a specific reference set * @param hash - * @param index - * @return + * @param referenceSetID + * @return true if the hash is found in the reference set */ @Override - public boolean isHashInReferenceSet(String hash, int index) throws EamDbException{ + public boolean isHashInReferenceSet(String hash, int referenceSetID) throws EamDbException{ Connection conn = connect(); @@ -1338,7 +1348,7 @@ public abstract class AbstractSqlEamDb implements EamDb { try { preparedStatement = conn.prepareStatement(String.format(sql, fileTableName)); preparedStatement.setString(1, hash); - preparedStatement.setInt(2, index); + preparedStatement.setInt(2, referenceSetID); resultSet = preparedStatement.executeQuery(); resultSet.next(); matchingInstances = resultSet.getLong(1); @@ -1499,27 +1509,27 @@ public abstract class AbstractSqlEamDb implements EamDb { } } - /** + /** * Get the organization associated with the given reference set. - * @param globalSetID ID of the reference set + * @param referenceSetID ID of the reference set * @return The organization object * @throws EamDbException */ @Override - public EamOrganization getReferenceSetOrganization(int globalSetID) throws EamDbException{ + public EamOrganization getReferenceSetOrganization(int referenceSetID) throws EamDbException{ - EamGlobalSet globalSet = getReferenceSetByID(globalSetID); + EamGlobalSet globalSet = getReferenceSetByID(referenceSetID); return (getOrganizationByID(globalSet.getOrgID())); } /** - * Add a new Global Set + * Add a new reference set * * @param orgID * @param setName * @param version * @param importDate - * @return + * @return the reference set ID of the newly created set * @throws EamDbException */ @Override @@ -1684,7 +1694,7 @@ public abstract class AbstractSqlEamDb implements EamDb { /** * Get all reference sets * - * @return The global set associated with the ID + * @return List of all reference sets in the central repository * * @throws EamDbException */ @@ -1750,7 +1760,7 @@ public abstract class AbstractSqlEamDb implements EamDb { * Check whether a reference set with the given name/version is in the central repo * @param hashSetName * @param version - * @return + * @return true if a matching set is found * @throws EamDbException */ @Override diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java index b87ad47e3c..4edeb5b734 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java @@ -18,12 +18,10 @@ */ package org.sleuthkit.autopsy.centralrepository.datamodel; -import java.time.LocalDate; import java.util.List; import java.util.Set; import org.sleuthkit.datamodel.TskData; import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager; /** * Main interface for interacting with the database @@ -357,25 +355,26 @@ public interface EamDb { /** * Remove a reference set and all hashes contained in it. - * @param centralRepoIndex + * @param referenceSetID * @throws EamDbException */ - public void deleteReferenceSet(int centralRepoIndex) throws EamDbException; + public void deleteReferenceSet(int referenceSetID) throws EamDbException; /** * Check whether the given reference set exists in the central repository. - * @param centralRepoIndex + * @param referenceSetID * @param hashSetName * @param version - * @return + * @return true if a matching entry exists in the central repository + * @throws EamDbException */ - public boolean referenceSetIsValid(int centralRepoIndex, String hashSetName, String version) throws EamDbException; + public boolean referenceSetIsValid(int referenceSetID, String hashSetName, String version) throws EamDbException; /** * Check whether a reference set with the given name/version is in the central repo * @param hashSetName * @param version - * @return + * @return true if a matching set is found * @throws EamDbException */ public boolean referenceSetExists(String hashSetName, String version) throws EamDbException; @@ -383,10 +382,10 @@ public interface EamDb { /** * Check if the given hash is in a specific reference set * @param hash - * @param index - * @return + * @param referenceSetID + * @return true if the hash is found in the reference set */ - public boolean isHashInReferenceSet(String hash, int index) throws EamDbException; + public boolean isHashInReferenceSet(String hash, int referenceSetID) throws EamDbException; /** * Is the artifact known as bad according to the reference entries? @@ -431,11 +430,11 @@ public interface EamDb { /** * Get the organization associated with the given reference set. - * @param globalSetID ID of the reference set + * @param referenceSetID ID of the reference set * @return The organization object * @throws EamDbException */ - EamOrganization getReferenceSetOrganization(int globalSetID) throws EamDbException; + EamOrganization getReferenceSetOrganization(int referenceSetID) throws EamDbException; /** * Update an existing organization. @@ -468,13 +467,13 @@ public interface EamDb { int newReferencelSet(EamGlobalSet eamGlobalSet) throws EamDbException; /** - * Add a new Global Set + * Add a new reference set * * @param orgID * @param setName * @param version - * - * @return The ID of the new global set + * @param importDate + * @return the reference set ID of the newly created set * @throws EamDbException */ int newReferenceSet(int orgID, String setName, String version, TskData.FileKnown knownStatus, @@ -494,7 +493,7 @@ public interface EamDb { /** * Get all reference sets * - * @return The global set associated with the ID + * @return List of all reference sets in the central repository * * @throws EamDbException */ diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java index b7391dc80b..45a0388561 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java @@ -637,14 +637,14 @@ public class SqliteEamDb extends AbstractSqlEamDb { /** * Remove a reference set and all hashes contained in it. - * @param centralRepoIndex + * @param referenceSetID * @throws EamDbException */ @Override - public void deleteReferenceSet(int centralRepoIndex) throws EamDbException{ + public void deleteReferenceSet(int referenceSetID) throws EamDbException{ try{ acquireExclusiveLock(); - super.deleteReferenceSet(centralRepoIndex); + super.deleteReferenceSet(referenceSetID); } finally { releaseExclusiveLock(); } @@ -653,14 +653,14 @@ public class SqliteEamDb extends AbstractSqlEamDb { /** * Check if the given hash is in a specific reference set * @param hash - * @param index - * @return + * @param referenceSetID + * @return true if the hash is found in the reference set */ @Override - public boolean isHashInReferenceSet(String hash, int index) throws EamDbException{ + public boolean isHashInReferenceSet(String hash, int referenceSetID) throws EamDbException{ try{ acquireSharedLock(); - return super.isHashInReferenceSet(hash, index); + return super.isHashInReferenceSet(hash, referenceSetID); } finally { releaseSharedLock(); } @@ -670,7 +670,7 @@ public class SqliteEamDb extends AbstractSqlEamDb { * Check whether a reference set with the given name/version is in the central repo * @param hashSetName * @param version - * @return + * @return true if a matching set is found * @throws EamDbException */ @Override @@ -816,7 +816,7 @@ public class SqliteEamDb extends AbstractSqlEamDb { /** * Get all reference sets * - * @return The global set associated with the ID + * @return List of all reference sets in the central repository * * @throws EamDbException */ @@ -847,7 +847,7 @@ public class SqliteEamDb extends AbstractSqlEamDb { } finally { releaseExclusiveLock(); } - } + } /** * Insert the bulk collection of Reference Type Instances diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index 562fc8b605..ec28c31747 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -281,7 +281,7 @@ public class HashDbManager implements PropertyChangeListener { return hashDb; } - public CentralRepoHashDb addExistingCentralRepoHashSet(String hashSetName, String version, int centralRepoIndex, + public CentralRepoHashDb addExistingCentralRepoHashSet(String hashSetName, String version, int referenceSetID, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType, boolean readOnly) throws TskCoreException{ @@ -289,7 +289,7 @@ public class HashDbManager implements PropertyChangeListener { throw new TskCoreException("Could not load central repository database " + hashSetName + " - central repository is not enabled"); } - CentralRepoHashDb db = new CentralRepoHashDb(hashSetName, version, centralRepoIndex, searchDuringIngest, + CentralRepoHashDb db = new CentralRepoHashDb(hashSetName, version, referenceSetID, searchDuringIngest, sendIngestMessages, knownFilesType, readOnly); if(! db.isValid()){ @@ -633,7 +633,7 @@ public class HashDbManager implements PropertyChangeListener { } else { if(EamDb.isEnabled()){ addExistingCentralRepoHashSet(hashDbInfo.getHashSetName(), hashDbInfo.getVersion(), - hashDbInfo.getCentralRepoIndex(), + hashDbInfo.getReferenceSetID(), hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), hashDbInfo.getKnownFilesType(), hashDbInfo.isReadOnly()); } @@ -687,7 +687,7 @@ public class HashDbManager implements PropertyChangeListener { for(HashDbInfo hashDbInfo : crHashDbInfoList) { if(hashDbInfoIsNew(hashDbInfo)){ addExistingCentralRepoHashSet(hashDbInfo.getHashSetName(), hashDbInfo.getVersion(), - hashDbInfo.getCentralRepoIndex(), + hashDbInfo.getReferenceSetID(), hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), hashDbInfo.getKnownFilesType(), hashDbInfo.isReadOnly()); } @@ -1150,27 +1150,27 @@ public class HashDbManager implements PropertyChangeListener { private boolean searchDuringIngest; private boolean sendIngestMessages; private final HashDb.KnownFilesType knownFilesType; - private final int centralRepoIndex; + private final int referenceSetID; private final String version; private String orgName; private final boolean readOnly; private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); @Messages({"HashDbManager.CentralRepoHashDb.orgError=Error loading organization"}) - private CentralRepoHashDb(String hashSetName, String version, int centralRepoIndex, + private CentralRepoHashDb(String hashSetName, String version, int referenceSetID, boolean useForIngest, boolean sendHitMessages, HashDb.KnownFilesType knownFilesType, boolean readOnly) throws TskCoreException{ this.hashSetName = hashSetName; this.version = version; - this.centralRepoIndex = centralRepoIndex; + this.referenceSetID = referenceSetID; this.searchDuringIngest = useForIngest; this.sendIngestMessages = sendHitMessages; this.knownFilesType = knownFilesType; this.readOnly = readOnly; try{ - orgName = EamDb.getInstance().getReferenceSetOrganization(centralRepoIndex).getName(); + orgName = EamDb.getInstance().getReferenceSetOrganization(referenceSetID).getName(); } catch (EamDbException ex){ Logger.getLogger(HashDb.class.getName()).log(Level.SEVERE, "Error looking up central repository organization", ex); //NON-NLS orgName = Bundle.HashDbManager_CentralRepoHashDb_orgError(); @@ -1221,8 +1221,8 @@ public class HashDbManager implements PropertyChangeListener { return orgName; } - public int getCentralRepoIndex(){ - return centralRepoIndex; + public int getReferenceSetID(){ + return referenceSetID; } @Override @@ -1341,7 +1341,7 @@ public class HashDbManager implements PropertyChangeListener { AbstractFile file = (AbstractFile) content; if (null != file.getMd5Hash()) { try{ - return EamDb.getInstance().isHashInReferenceSet(file.getMd5Hash(), this.centralRepoIndex); + return EamDb.getInstance().isHashInReferenceSet(file.getMd5Hash(), this.referenceSetID); } catch (EamDbException ex){ Logger.getLogger(HashDb.class.getName()).log(Level.SEVERE, "Error performing central reposiotry hash lookup", ex); //NON-NLS throw new TskCoreException("Error performing central reposiotry hash lookup", ex); @@ -1369,7 +1369,7 @@ public class HashDbManager implements PropertyChangeListener { AbstractFile file = (AbstractFile) content; if (null != file.getMd5Hash()) { try{ - if(EamDb.getInstance().isHashInReferenceSet(file.getMd5Hash(), this.centralRepoIndex)){ + if(EamDb.getInstance().isHashInReferenceSet(file.getMd5Hash(), this.referenceSetID)){ // Make a bare-bones HashHitInfo for now result = new HashHitInfo(file.getMd5Hash(), "", ""); } @@ -1394,7 +1394,7 @@ public class HashDbManager implements PropertyChangeListener { return false; } try{ - return EamDb.getInstance().referenceSetIsValid(this.centralRepoIndex, this.hashSetName, this.version); + return EamDb.getInstance().referenceSetIsValid(this.referenceSetID, this.hashSetName, this.version); } catch (EamDbException ex){ Logger.getLogger(CentralRepoHashDb.class.getName()).log(Level.SEVERE, "Error validating hash database " + hashSetName, ex); //NON-NLS return false; @@ -1422,7 +1422,7 @@ public class HashDbManager implements PropertyChangeListener { int code = 23; code = 47 * code + Objects.hashCode(this.hashSetName); code = 47 * code + Objects.hashCode(this.version); - code = 47 * code + Integer.hashCode(this.centralRepoIndex); + code = 47 * code + Integer.hashCode(this.referenceSetID); code = 47 * code + Objects.hashCode(this.knownFilesType); return code; } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java index ada8967be7..89d807d507 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java @@ -305,7 +305,7 @@ final class HashLookupSettings implements Serializable { private final String path; private final String version; private final boolean readOnly; - private final int centralRepoIndex; + private final int referenceSetID; private DatabaseType dbType; /** @@ -324,16 +324,16 @@ final class HashLookupSettings implements Serializable { this.searchDuringIngest = searchDuringIngest; this.sendIngestMessages = sendIngestMessages; this.path = path; - this.centralRepoIndex = -1; + this.referenceSetID = -1; this.version = ""; this.readOnly = false; this.dbType = DatabaseType.FILE; } - HashDbInfo(String hashSetName, String version, int centralRepoIndex, HashDbManager.HashDb.KnownFilesType knownFilesType, boolean readOnly, boolean searchDuringIngest, boolean sendIngestMessages){ + HashDbInfo(String hashSetName, String version, int referenceSetID, HashDbManager.HashDb.KnownFilesType knownFilesType, boolean readOnly, boolean searchDuringIngest, boolean sendIngestMessages){ this.hashSetName = hashSetName; this.version = version; - this.centralRepoIndex = centralRepoIndex; + this.referenceSetID = referenceSetID; this.knownFilesType = knownFilesType; this.readOnly = readOnly; this.searchDuringIngest = searchDuringIngest; @@ -349,7 +349,7 @@ final class HashLookupSettings implements Serializable { this.knownFilesType = fileTypeDb.getKnownFilesType(); this.searchDuringIngest = fileTypeDb.getSearchDuringIngest(); this.sendIngestMessages = fileTypeDb.getSendIngestMessages(); - this.centralRepoIndex = -1; + this.referenceSetID = -1; this.version = ""; this.readOnly = false; this.dbType = DatabaseType.FILE; @@ -367,7 +367,7 @@ final class HashLookupSettings implements Serializable { this.searchDuringIngest = centralRepoDb.getSearchDuringIngest(); this.sendIngestMessages = centralRepoDb.getSendIngestMessages(); this.path = ""; - this.centralRepoIndex = centralRepoDb.getCentralRepoIndex(); + this.referenceSetID = centralRepoDb.getReferenceSetID(); this.dbType = DatabaseType.CENTRAL_REPOSITORY; } } @@ -441,8 +441,8 @@ final class HashLookupSettings implements Serializable { return path; } - int getCentralRepoIndex(){ - return centralRepoIndex; + int getReferenceSetID(){ + return referenceSetID; } /** @@ -481,7 +481,7 @@ final class HashLookupSettings implements Serializable { // Central repo tests CentralRepoHashDb crDb = (CentralRepoHashDb) hashDb; - if(this.centralRepoIndex != crDb.getCentralRepoIndex()){ + if(this.referenceSetID != crDb.getReferenceSetID()){ return false; } @@ -515,7 +515,7 @@ final class HashLookupSettings implements Serializable { } else { // For central repo, the name, index, and known files type should match return (this.hashSetName.equals(other.hashSetName) - && (this.centralRepoIndex == other.centralRepoIndex) + && (this.referenceSetID == other.referenceSetID) && this.knownFilesType.equals(other.knownFilesType)); } } @@ -527,7 +527,7 @@ final class HashLookupSettings implements Serializable { hash = 89 * hash + Objects.hashCode(this.knownFilesType); hash = 89 * hash + Objects.hashCode(this.dbType); if(this.dbType.equals(DatabaseType.CENTRAL_REPOSITORY)){ - hash = 89 * hash + this.centralRepoIndex; + hash = 89 * hash + this.referenceSetID; } return hash; diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java index fe2e4a5757..27249e1e5a 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java @@ -66,7 +66,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 newCentralRepoIndices = new ArrayList<>(); + private final List newReferenceSetIDs = new ArrayList<>(); public HashLookupSettingsPanel() { initComponents(); @@ -328,7 +328,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan try { hashSetManager.save(); - newCentralRepoIndices.clear(); + newReferenceSetIDs.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 index:newCentralRepoIndices){ + for(int refID:newReferenceSetIDs){ try{ if(EamDb.isEnabled()){ - EamDb.getInstance().deleteReferenceSet(index); + EamDb.getInstance().deleteReferenceSet(refID); } 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. @@ -971,8 +971,8 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan HashDatabase hashDb = new HashDbImportDatabaseDialog().getHashDatabase(); if (null != hashDb) { if(hashDb instanceof CentralRepoHashDb){ - int newDbIndex = ((CentralRepoHashDb)hashDb).getCentralRepoIndex(); - newCentralRepoIndices.add(newDbIndex); + int newReferenceSetID = ((CentralRepoHashDb)hashDb).getReferenceSetID(); + newReferenceSetIDs.add(newReferenceSetID); } hashSetTableModel.refreshModel(); diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java index 597cb8c39d..397b4948cf 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java @@ -143,7 +143,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P private final boolean readOnly; private final File importFile; private final long totalLines; - private int crIndex = -1; + private int referenceSetID = -1; private HashDbManager.CentralRepoHashDb newHashDb = null; private final AtomicLong numLines = new AtomicLong(); @@ -201,7 +201,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P } // Create an empty hashset in the central repository - crIndex = EamDb.getInstance().newReferenceSet(orgId, hashSetName, version, knownStatus, readOnly); + referenceSetID = EamDb.getInstance().newReferenceSet(orgId, hashSetName, version, knownStatus, readOnly); EamDb dbManager = EamDb.getInstance(); CorrelationAttribute.Type contentType = dbManager.getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID); // get "FILES" type @@ -222,7 +222,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P } EamGlobalFileInstance eamGlobalFileInstance = new EamGlobalFileInstance( - crIndex, + referenceSetID, parts[0].toLowerCase(), knownStatus, ""); @@ -249,15 +249,15 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P return null; } - private void deleteIncompleteSet(int crIndex){ - if(crIndex >= 0){ + private void deleteIncompleteSet(int idToDelete){ + if(idToDelete >= 0){ // This can be slow on large reference sets Executors.newSingleThreadExecutor().execute(new Runnable() { @Override public void run() { try{ - EamDb.getInstance().deleteReferenceSet(crIndex); + EamDb.getInstance().deleteReferenceSet(idToDelete); } catch (EamDbException ex2){ Logger.getLogger(ImportCentralRepoDbProgressDialog.class.getName()).log(Level.SEVERE, "Error deleting incomplete hash set from central repository", ex2); } @@ -271,7 +271,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P protected void done() { if(isCancelled()){ // If the user hit cancel, delete this incomplete hash set from the central repo - deleteIncompleteSet(crIndex); + deleteIncompleteSet(referenceSetID); return; } @@ -279,7 +279,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P get(); try{ newHashDb = HashDbManager.getInstance().addExistingCentralRepoHashSet(hashSetName, version, - crIndex, + referenceSetID, searchDuringIngest, sendIngestMessages, knownFilesType, readOnly); } catch (TskCoreException ex){ JOptionPane.showMessageDialog(null, Bundle.ImportCentralRepoDbProgressDialog_addDbError_message()); @@ -287,9 +287,9 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P } } catch (Exception ex) { // Delete this incomplete hash set from the central repo - if(crIndex >= 0){ + if(referenceSetID >= 0){ try{ - EamDb.getInstance().deleteReferenceSet(crIndex); + EamDb.getInstance().deleteReferenceSet(referenceSetID); } catch (EamDbException ex2){ Logger.getLogger(ImportCentralRepoDbProgressDialog.class.getName()).log(Level.SEVERE, "Error deleting incomplete hash set from central repository", ex); } From 56c5cd92cb0484646e111f9c7d2f37954a6720ba Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Mon, 13 Nov 2017 08:47:01 -0500 Subject: [PATCH 30/41] Revert changes to the public api --- .../HashDbCreateDatabaseDialog.java | 2 +- .../HashDbImportDatabaseDialog.java | 2 +- .../modules/hashdatabase/HashDbManager.java | 62 ++++++------------- .../hashdatabase/HashLookupModuleFactory.java | 2 +- .../hashdatabase/HashLookupSettingsPanel.java | 18 +++--- .../configuration/SharedConfiguration.java | 4 +- 6 files changed, 31 insertions(+), 59 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java index ab3efb8afb..0bea515d14 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java @@ -338,7 +338,7 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog { String errorMessage = NbBundle .getMessage(this.getClass(), "HashDbCreateDatabaseDialog.errMsg.hashDbCreationErr"); try { - newHashDb = HashDbManager.getInstance().addNewFileTypeHashDatabase(hashSetNameTextField.getText(), fileChooser.getSelectedFile().getCanonicalPath(), true, sendIngestMessagesCheckbox.isSelected(), type); + newHashDb = HashDbManager.getInstance().addNewHashDatabaseNoSave(hashSetNameTextField.getText(), fileChooser.getSelectedFile().getCanonicalPath(), true, sendIngestMessagesCheckbox.isSelected(), type); } catch (IOException ex) { Logger.getLogger(HashDbCreateDatabaseDialog.class.getName()).log(Level.WARNING, errorMessage, ex); JOptionPane.showMessageDialog(this, diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java index 66037cccf9..012544bdab 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java @@ -514,7 +514,7 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { if(fileTypeRadioButton.isSelected()){ try { - selectedHashDb = HashDbManager.getInstance().addExistingFileTypeHashDatabase(hashSetNameTextField.getText(), selectedFilePath, true, sendIngestMessagesCheckbox.isSelected(), type); + selectedHashDb = HashDbManager.getInstance().addExistingHashDatabaseNoSave(hashSetNameTextField.getText(), selectedFilePath, true, sendIngestMessagesCheckbox.isSelected(), type); } catch (HashDbManagerException ex) { Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.WARNING, errorMessage, ex); JOptionPane.showMessageDialog(this, diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index ec28c31747..fb2edad967 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -147,7 +147,6 @@ public class HashDbManager implements PropertyChangeListener { * * @throws HashDbManagerException */ - @Deprecated public synchronized HashDb addExistingHashDatabase(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws HashDbManagerException { HashDb hashDb = null; hashDb = this.addExistingHashDatabaseNoSave(hashSetName, path, searchDuringIngest, sendIngestMessages, knownFilesType); @@ -155,12 +154,7 @@ public class HashDbManager implements PropertyChangeListener { return hashDb; } - @Deprecated synchronized HashDb addExistingHashDatabaseNoSave(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws HashDbManagerException { - return (HashDb)addExistingFileTypeHashDatabase(hashSetName, path, searchDuringIngest, sendIngestMessages, knownFilesType); - } - - synchronized HashDatabase addExistingFileTypeHashDatabase(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws HashDbManagerException { HashDb hashDb = null; try { if (!new File(path).exists()) { @@ -175,7 +169,7 @@ public class HashDbManager implements PropertyChangeListener { throw new HashDbManagerException(NbBundle.getMessage(HashDbManager.class, "HashDbManager.duplicateHashSetNameExceptionMsg", hashSetName)); } - hashDb = addFileTypeHashDatabase(SleuthkitJNI.openHashDatabase(path), hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType); + hashDb = addFileHashDatabase(SleuthkitJNI.openHashDatabase(path), hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType); } catch (TskCoreException ex) { throw new HashDbManagerException(ex.getMessage()); } @@ -200,7 +194,6 @@ public class HashDbManager implements PropertyChangeListener { * * @throws HashDbManagerException */ - @Deprecated public synchronized HashDb addNewHashDatabase(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws HashDbManagerException { @@ -212,14 +205,8 @@ public class HashDbManager implements PropertyChangeListener { return hashDb; } - @Deprecated public synchronized HashDb addNewHashDatabaseNoSave(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws HashDbManagerException { - return (HashDb)addNewFileTypeHashDatabase(hashSetName, path, searchDuringIngest, sendIngestMessages, knownFilesType); - } - - public synchronized HashDatabase addNewFileTypeHashDatabase(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, - HashDb.KnownFilesType knownFilesType) throws HashDbManagerException { HashDb hashDb = null; try { File file = new File(path); @@ -239,14 +226,14 @@ public class HashDbManager implements PropertyChangeListener { throw new HashDbManagerException(NbBundle.getMessage(HashDbManager.class, "HashDbManager.duplicateHashSetNameExceptionMsg", hashSetName)); } - hashDb = addFileTypeHashDatabase(SleuthkitJNI.createHashDatabase(path), hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType); + hashDb = addFileHashDatabase(SleuthkitJNI.createHashDatabase(path), hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType); } catch (TskCoreException ex) { throw new HashDbManagerException(ex.getMessage()); } return hashDb; } - private HashDb addFileTypeHashDatabase(int handle, String hashSetName, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws TskCoreException { + private HashDb addFileHashDatabase(int handle, String hashSetName, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws TskCoreException { // Wrap an object around the handle. HashDb hashDb = new HashDb(handle, hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType); @@ -281,7 +268,7 @@ public class HashDbManager implements PropertyChangeListener { return hashDb; } - public CentralRepoHashDb addExistingCentralRepoHashSet(String hashSetName, String version, int referenceSetID, + CentralRepoHashDb addExistingCentralRepoHashSet(String hashSetName, String version, int referenceSetID, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType, boolean readOnly) throws TskCoreException{ @@ -414,23 +401,22 @@ public class HashDbManager implements PropertyChangeListener { } /** - * Gets all of the hash databases used to classify files as known or known - * bad. + * Gets all of the HashDbs used to classify files as known or known + * bad. Will not return central repository databases. * * @return A list, possibly empty, of hash databases. */ - @Deprecated public synchronized List getAllHashSets() { - return getAllFileTypeHashSets(); + return getAllFileHashSets(); } /** - * Gets all of the file type hash databases used to classify files as known or known + * Gets all of the file hash databases used to classify files as known or known * bad. * * @return A list, possibly empty, of hash databases. */ - public synchronized List getAllFileTypeHashSets() { + synchronized List getAllFileHashSets() { List hashDbs = new ArrayList<>(); this.hashSets.stream().filter((thisSet) -> (thisSet instanceof HashDb)).forEach((thisSet) -> { hashDbs.add((HashDb)thisSet); @@ -440,28 +426,21 @@ public class HashDbManager implements PropertyChangeListener { /** * Gets all of the hash databases used to classify files as known or known - * bad. + * bad. Will add any new central repository databases to the list before + * returning it. * * @return A list, possibly empty, of hash databases. */ - public synchronized List getAllHashDatabases(){ - List hashDbs = new ArrayList<>(); - hashDbs.addAll(this.hashSets); - return hashDbs; - } - - /** - * Adds any new central repository databases to the list of hashes - * before returning a copy of the hash set list - * @return A list, possibly empty, of hash databases. - */ - public synchronized List refreshAndGetAllHashDatabases(){ + synchronized List getAllHashDatabases(){ try{ updateHashSetsFromCentralRepository(); } catch (TskCoreException ex){ Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error loading central repository hash sets", ex); //NON-NLS } - return getAllHashDatabases(); + + List hashDbs = new ArrayList<>(); + hashDbs.addAll(this.hashSets); + return hashDbs; } /** @@ -469,7 +448,6 @@ public class HashDbManager implements PropertyChangeListener { * * @return A list, possibly empty, of hash databases. */ - @Deprecated public synchronized List getKnownFileHashSets() { List hashDbs = new ArrayList<>(); this.hashSets.stream().filter((thisSet) -> ((thisSet instanceof HashDb) && (thisSet.getKnownFilesType() == HashDb.KnownFilesType.KNOWN))).forEach((thisSet) -> { @@ -483,7 +461,7 @@ public class HashDbManager implements PropertyChangeListener { * * @return A list, possibly empty, of hash databases. */ - public synchronized List getKnownFileHashDatabases() { + synchronized List getKnownFileHashDatabases() { List hashDbs = new ArrayList<>(); this.hashSets.stream().filter((db) -> (db.getKnownFilesType() == HashDb.KnownFilesType.KNOWN)).forEach((db) -> { hashDbs.add(db); @@ -496,7 +474,6 @@ public class HashDbManager implements PropertyChangeListener { * * @return A list, possibly empty, of hash databases. */ - @Deprecated public synchronized List getKnownBadFileHashSets() { List hashDbs = new ArrayList<>(); this.hashSets.stream().filter((thisSet) -> ((thisSet instanceof HashDb) && (thisSet.getKnownFilesType() == HashDb.KnownFilesType.KNOWN_BAD))).forEach((thisSet) -> { @@ -510,7 +487,7 @@ public class HashDbManager implements PropertyChangeListener { * * @return A list, possibly empty, of hash databases. */ - public synchronized List getNotableFileHashDatabases() { + synchronized List getNotableFileHashDatabases() { List hashDbs = new ArrayList<>(); this.hashSets.stream().filter((db) -> (db.getKnownFilesType() == HashDb.KnownFilesType.KNOWN_BAD)).forEach((db) -> { hashDbs.add(db); @@ -523,7 +500,6 @@ public class HashDbManager implements PropertyChangeListener { * * @return A list, possibly empty, of hash databases. */ - @Deprecated public synchronized List getUpdateableHashSets() { List updateableDbs = new ArrayList<>(); List updateableHashSets = getUpdateableHashSets(this.hashSets); @@ -625,7 +601,7 @@ public class HashDbManager implements PropertyChangeListener { if(hashDbInfo.isFileDatabaseType()){ String dbPath = this.getValidFilePath(hashDbInfo.getHashSetName(), hashDbInfo.getPath()); if (dbPath != null) { - addFileTypeHashDatabase(SleuthkitJNI.openHashDatabase(dbPath), hashDbInfo.getHashSetName(), hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), hashDbInfo.getKnownFilesType()); + addFileHashDatabase(SleuthkitJNI.openHashDatabase(dbPath), hashDbInfo.getHashSetName(), hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), hashDbInfo.getKnownFilesType()); } else { logger.log(Level.WARNING, Bundle.HashDbManager_noDbPath_message(hashDbInfo.getHashSetName())); allDatabasesLoadedCorrectly = false; diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java index 19a1d5ee21..52ae48c8cd 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java @@ -60,7 +60,7 @@ public class HashLookupModuleFactory extends IngestModuleFactoryAdapter { @Override public IngestModuleIngestJobSettings getDefaultIngestJobSettings() { // All available hash sets are enabled and always calculate hashes is true by default. - return new HashLookupModuleSettings(true, HashDbManager.getInstance().refreshAndGetAllHashDatabases()); + return new HashLookupModuleSettings(true, HashDbManager.getInstance().getAllHashDatabases()); } @Override diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java index 27249e1e5a..46b636af82 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; @@ -306,16 +305,13 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan public void saveSettings() { //Checking for for any unindexed databases List unindexed = new ArrayList<>(); - for (HashDatabase hashSet : hashSetManager.getAllHashDatabases()) { - if(hashSet instanceof HashDb){ - HashDb db = (HashDb)hashSet; - try { - if (!db.hasIndex()) { - unindexed.add(db); - } - } catch (TskCoreException ex) { - Logger.getLogger(HashLookupSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting index info for hash database", ex); //NON-NLS + for (HashDb db : hashSetManager.getAllFileHashSets()) { + try { + if (!db.hasIndex()) { + unindexed.add(db); } + } catch (TskCoreException ex) { + Logger.getLogger(HashLookupSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting index info for hash database", ex); //NON-NLS } } @@ -550,7 +546,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan } void refreshModel() { - hashSets = HashDbManager.getInstance().refreshAndGetAllHashDatabases(); + hashSets = HashDbManager.getInstance().getAllHashDatabases(); refreshDisplay(); } diff --git a/Experimental/src/org/sleuthkit/autopsy/experimental/configuration/SharedConfiguration.java b/Experimental/src/org/sleuthkit/autopsy/experimental/configuration/SharedConfiguration.java index b715b7d309..ccb2e49e54 100755 --- a/Experimental/src/org/sleuthkit/autopsy/experimental/configuration/SharedConfiguration.java +++ b/Experimental/src/org/sleuthkit/autopsy/experimental/configuration/SharedConfiguration.java @@ -1016,7 +1016,7 @@ public class SharedConfiguration { // If a copy of the database is loaded, close it before deleting and copying. if (localDb.exists()) { - List hashDbs = HashDbManager.getInstance().getAllFileTypeHashSets(); + List hashDbs = HashDbManager.getInstance().getAllHashSets(); HashDbManager.HashDb matchingDb = null; for (HashDbManager.HashDb db : hashDbs) { try { @@ -1122,7 +1122,7 @@ public class SharedConfiguration { try { HashDbManager hashDbManager = HashDbManager.getInstance(); hashDbManager.loadLastSavedConfiguration(); - for (HashDb hashDb : hashDbManager.getAllFileTypeHashSets()) { + for (HashDb hashDb : hashDbManager.getAllHashSets()) { if (hashDb.hasIndexOnly()) { results.add(hashDb.getIndexPath()); } else { From 5c2b89995e74c9ee7f52135aca1ae61aa23a68aa Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Mon, 13 Nov 2017 13:56:40 -0500 Subject: [PATCH 31/41] Switched around names of HashDb and HashDatabase --- .../datamodel/EamGlobalSet.java | 6 +- .../AddContentToHashDbAction.java | 10 +- .../AddHashValuesToDatabaseDialog.java | 6 +- ...AddHashValuesToDatabaseProgressDialog.java | 6 +- .../HashDbCreateDatabaseDialog.java | 6 +- .../HashDbImportDatabaseDialog.java | 7 +- .../hashdatabase/HashDbIngestModule.java | 22 +- .../modules/hashdatabase/HashDbManager.java | 243 ++++++++---------- .../hashdatabase/HashLookupModuleFactory.java | 2 +- .../HashLookupModuleSettings.java | 16 +- .../HashLookupModuleSettingsPanel.java | 36 +-- .../hashdatabase/HashLookupSettings.java | 28 +- .../hashdatabase/HashLookupSettingsPanel.java | 58 ++--- .../ImportCentralRepoDbProgressDialog.java | 14 +- .../modules/hashdatabase/ModalNoButtons.java | 16 +- .../taggedhashes/AddTaggedHashesToHashDb.java | 4 +- .../AddTaggedHashesToHashDbConfigPanel.form | 2 +- .../AddTaggedHashesToHashDbConfigPanel.java | 14 +- .../configuration/SharedConfiguration.java | 30 ++- 19 files changed, 246 insertions(+), 280 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalSet.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalSet.java index e4292dc6ca..80e7d9cb8b 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalSet.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalSet.java @@ -150,11 +150,11 @@ public class EamGlobalSet { * Return the FileKnown status as a KnownFilesType * @return KNOWN or KNOWN_BAD */ - public HashDbManager.HashDb.KnownFilesType getKnownStatus(){ + public HashDbManager.HashDatabase.KnownFilesType getKnownStatus(){ if(fileKnownStatus.equals(TskData.FileKnown.BAD)){ - return HashDbManager.HashDb.KnownFilesType.KNOWN_BAD; + return HashDbManager.HashDatabase.KnownFilesType.KNOWN_BAD; } - return HashDbManager.HashDb.KnownFilesType.KNOWN; + return HashDbManager.HashDatabase.KnownFilesType.KNOWN; } /** diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddContentToHashDbAction.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddContentToHashDbAction.java index 6c58402fd6..effa123af9 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddContentToHashDbAction.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddContentToHashDbAction.java @@ -35,7 +35,7 @@ import org.sleuthkit.autopsy.ingest.IngestManager; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.HashUtility; import org.sleuthkit.datamodel.TskCoreException; -import static org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; +import static org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; /** * Instances of this Action allow users to content to a hash database. @@ -106,9 +106,9 @@ final class AddContentToHashDbAction extends AbstractAction implements Presenter // Get the current set of updateable hash databases and add each // one to the menu as a separate menu item. Selecting a hash database // adds the selected files to the selected database. - final List hashDatabases = HashDbManager.getInstance().getUpdateableHashDatabases(); + final List hashDatabases = HashDbManager.getInstance().getUpdateableHashSets(); if (!hashDatabases.isEmpty()) { - for (final HashDatabase database : hashDatabases) { + for (final HashDb database : hashDatabases) { JMenuItem databaseItem = add(database.getHashSetName()); databaseItem.addActionListener(new ActionListener() { @Override @@ -134,7 +134,7 @@ final class AddContentToHashDbAction extends AbstractAction implements Presenter newHashSetItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - HashDatabase hashDb = new HashDbCreateDatabaseDialog().getHashDatabase(); + HashDb hashDb = new HashDbCreateDatabaseDialog().getHashDatabase(); if (null != hashDb) { addFilesToHashSet(selectedFiles, hashDb); } @@ -143,7 +143,7 @@ final class AddContentToHashDbAction extends AbstractAction implements Presenter add(newHashSetItem); } - private void addFilesToHashSet(final Collection files, HashDatabase hashSet) { + private void addFilesToHashSet(final Collection files, HashDb hashSet) { for (AbstractFile file : files) { String md5Hash = file.getMd5Hash(); if (null != md5Hash) { diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseDialog.java index debe46f47c..1fe05701ce 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseDialog.java @@ -32,7 +32,7 @@ import javax.swing.SwingUtilities; import org.openide.util.NbBundle; import org.openide.windows.WindowManager; import org.sleuthkit.datamodel.HashEntry; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; /** * @@ -40,7 +40,7 @@ import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; */ public class AddHashValuesToDatabaseDialog extends javax.swing.JDialog { - HashDatabase hashDb; + HashDb hashDb; Pattern md5Pattern = Pattern.compile("^[a-fA-F0-9]{32}$"); List hashes = new ArrayList<>(); List invalidHashes = new ArrayList<>(); @@ -49,7 +49,7 @@ public class AddHashValuesToDatabaseDialog extends javax.swing.JDialog { * Displays a dialog that allows a user to add hash values to the selected * database. */ - AddHashValuesToDatabaseDialog(HashDatabase hashDb) { + AddHashValuesToDatabaseDialog(HashDb hashDb) { super((JFrame) WindowManager.getDefault().getMainWindow(), NbBundle.getMessage(AddHashValuesToDatabaseDialog.class, "AddHashValuesToDatabaseDialog.JDialog.Title", hashDb.getHashSetName()), true); diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseProgressDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseProgressDialog.java index 77483e1d42..3f3671c44f 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseProgressDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseProgressDialog.java @@ -33,7 +33,7 @@ import javax.swing.SwingWorker; import org.openide.util.NbBundle; import org.sleuthkit.datamodel.HashEntry; import org.sleuthkit.datamodel.TskCoreException; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; /** * @@ -43,7 +43,7 @@ public class AddHashValuesToDatabaseProgressDialog extends javax.swing.JDialog { private final AddHashValuesToDatabaseDialog parentRef; private boolean disposeParent = false; - private final HashDatabase hashDb; + private final HashDb hashDb; private final List hashes; private final List invalidHashes; private final Pattern md5Pattern; @@ -58,7 +58,7 @@ public class AddHashValuesToDatabaseProgressDialog extends javax.swing.JDialog { * @param hashDb * @param text */ - AddHashValuesToDatabaseProgressDialog(AddHashValuesToDatabaseDialog parent, HashDatabase hashDb, String text) { + AddHashValuesToDatabaseProgressDialog(AddHashValuesToDatabaseDialog parent, HashDb hashDb, String text) { super(parent); initComponents(); display(); diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java index 0bea515d14..a794ada72d 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java @@ -35,7 +35,7 @@ import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.PlatformUtil; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb.KnownFilesType; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDbManagerException; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; /** * Instances of this class allow a user to create a new hash database and add it @@ -47,7 +47,7 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog { private static final String DEFAULT_FILE_NAME = NbBundle .getMessage(HashDbCreateDatabaseDialog.class, "HashDbCreateDatabaseDialog.defaultFileName"); private JFileChooser fileChooser = null; - private HashDatabase newHashDb = null; + private HashDb newHashDb = null; private final static String LAST_FILE_PATH_KEY = "HashDbCreate_Path"; /** @@ -67,7 +67,7 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog { * * @return A HashDb object or null. */ - HashDatabase getHashDatabase() { + HashDb getHashDatabase() { return newHashDb; } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java index 012544bdab..c281e81db9 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbImportDatabaseDialog.java @@ -36,14 +36,13 @@ import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException; import org.sleuthkit.autopsy.centralrepository.datamodel.EamOrganization; -import org.sleuthkit.autopsy.centralrepository.optionspanel.AddNewOrganizationDialog; import org.sleuthkit.autopsy.centralrepository.optionspanel.ManageOrganizationsDialog; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.PlatformUtil; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb.KnownFilesType; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDbManagerException; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; /** * Instances of this class allow a user to select an existing hash database and @@ -54,7 +53,7 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { private JFileChooser fileChooser = new JFileChooser(); private String selectedFilePath = ""; - private HashDatabase selectedHashDb = null; + private HashDb selectedHashDb = null; private final static String LAST_FILE_PATH_KEY = "HashDbImport_Path"; private EamOrganization selectedOrg = null; private List orgs = null; @@ -79,7 +78,7 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog { * * @return A HashDb object or null. */ - HashDatabase getHashDatabase() { + HashDb getHashDatabase() { return selectedHashDb; } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java index 55d91b5fbd..75f477b585 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java @@ -36,7 +36,6 @@ import org.sleuthkit.autopsy.ingest.IngestMessage; import org.sleuthkit.autopsy.ingest.IngestModuleReferenceCounter; import org.sleuthkit.autopsy.ingest.IngestServices; import org.sleuthkit.autopsy.ingest.ModuleDataEvent; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE; @@ -48,6 +47,7 @@ import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskData; import org.sleuthkit.datamodel.TskException; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; @NbBundle.Messages({ "HashDbIngestModule.noKnownBadHashDbSetMsg=No notable hash database set.", @@ -63,8 +63,8 @@ public class HashDbIngestModule implements FileIngestModule { private final SleuthkitCase skCase = Case.getCurrentCase().getSleuthkitCase(); private final HashDbManager hashDbManager = HashDbManager.getInstance(); private final HashLookupModuleSettings settings; - private List knownBadHashSets = new ArrayList<>(); - private List knownHashSets = new ArrayList<>(); + private List knownBadHashSets = new ArrayList<>(); + private List knownHashSets = new ArrayList<>(); private long jobId; private static final HashMap totalsForIngestJobs = new HashMap<>(); private static final IngestModuleReferenceCounter refCounter = new IngestModuleReferenceCounter(); @@ -96,8 +96,8 @@ public class HashDbIngestModule implements FileIngestModule { if (!hashDbManager.verifyAllDatabasesLoadedCorrectly()) { throw new IngestModuleException("Could not load all hash databases"); } - updateEnabledHashSets(hashDbManager.getNotableFileHashDatabases(), knownBadHashSets); - updateEnabledHashSets(hashDbManager.getKnownFileHashDatabases(), knownHashSets); + updateEnabledHashSets(hashDbManager.getKnownBadFileHashSets(), knownBadHashSets); + updateEnabledHashSets(hashDbManager.getKnownFileHashSets(), knownHashSets); if (refCounter.incrementAndGet(jobId) == 1) { // initialize job totals @@ -126,9 +126,9 @@ public class HashDbIngestModule implements FileIngestModule { * @param allHashSets List of all hashsets from DB manager * @param enabledHashSets List of enabled ones to return. */ - private void updateEnabledHashSets(List allHashSets, List enabledHashSets) { + private void updateEnabledHashSets(List allHashSets, List enabledHashSets) { enabledHashSets.clear(); - for (HashDatabase db : allHashSets) { + for (HashDb db : allHashSets) { if (settings.isHashSetEnabled(db)) { try { if (db.isValid()) { @@ -196,7 +196,7 @@ public class HashDbIngestModule implements FileIngestModule { // look up in notable first boolean foundBad = false; ProcessResult ret = ProcessResult.OK; - for (HashDatabase db : knownBadHashSets) { + for (HashDb db : knownBadHashSets) { try { long lookupstart = System.currentTimeMillis(); HashHitInfo hashInfo = db.lookupMD5(file); @@ -257,7 +257,7 @@ public class HashDbIngestModule implements FileIngestModule { // Any hit is sufficient to classify it as known, and there is no need to create // a hit artifact or send a message to the application inbox. if (!foundBad) { - for (HashDatabase db : knownHashSets) { + for (HashDb db : knownHashSets) { try { long lookupstart = System.currentTimeMillis(); if (db.lookupMD5Quick(file)) { @@ -359,7 +359,7 @@ public class HashDbIngestModule implements FileIngestModule { } private static synchronized void postSummary(long jobId, - List knownBadHashSets, List knownHashSets) { + List knownBadHashSets, List knownHashSets) { IngestJobTotals jobTotals = getTotalsForIngestJobs(jobId); totalsForIngestJobs.remove(jobId); @@ -384,7 +384,7 @@ public class HashDbIngestModule implements FileIngestModule { detailsSb.append("

    ") //NON-NLS .append(NbBundle.getMessage(HashDbIngestModule.class, "HashDbIngestModule.complete.databasesUsed")) .append("

    \n
      "); //NON-NLS - for (HashDatabase db : knownBadHashSets) { + for (HashDb db : knownBadHashSets) { detailsSb.append("
    • ").append(db.getHashSetName()).append("
    • \n"); //NON-NLS } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index fb2edad967..59dcd998e0 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -61,7 +61,7 @@ public class HashDbManager implements PropertyChangeListener { private static final String HASH_DATABASE_FILE_EXTENSON = "kdb"; //NON-NLS private static HashDbManager instance = null; - private List hashSets = new ArrayList<>(); + private List hashSets = new ArrayList<>(); private Set hashSetNames = new HashSet<>(); private Set hashSetPaths = new HashSet<>(); PropertyChangeSupport changeSupport = new PropertyChangeSupport(HashDbManager.class); @@ -147,15 +147,15 @@ public class HashDbManager implements PropertyChangeListener { * * @throws HashDbManagerException */ - public synchronized HashDb addExistingHashDatabase(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws HashDbManagerException { - HashDb hashDb = null; + public synchronized HashDatabase addExistingHashDatabase(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDatabase.KnownFilesType knownFilesType) throws HashDbManagerException { + HashDatabase hashDb = null; hashDb = this.addExistingHashDatabaseNoSave(hashSetName, path, searchDuringIngest, sendIngestMessages, knownFilesType); this.save(); return hashDb; } - synchronized HashDb addExistingHashDatabaseNoSave(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws HashDbManagerException { - HashDb hashDb = null; + synchronized HashDatabase addExistingHashDatabaseNoSave(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDatabase.KnownFilesType knownFilesType) throws HashDbManagerException { + HashDatabase hashDb = null; try { if (!new File(path).exists()) { throw new HashDbManagerException(NbBundle.getMessage(HashDbManager.class, "HashDbManager.hashDbDoesNotExistExceptionMsg", path)); @@ -194,10 +194,10 @@ public class HashDbManager implements PropertyChangeListener { * * @throws HashDbManagerException */ - public synchronized HashDb addNewHashDatabase(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, - HashDb.KnownFilesType knownFilesType) throws HashDbManagerException { + public synchronized HashDatabase addNewHashDatabase(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, + HashDatabase.KnownFilesType knownFilesType) throws HashDbManagerException { - HashDb hashDb = null; + HashDatabase hashDb = null; hashDb = this.addNewHashDatabaseNoSave(hashSetName, path, searchDuringIngest, sendIngestMessages, knownFilesType); this.save(); @@ -205,9 +205,9 @@ public class HashDbManager implements PropertyChangeListener { return hashDb; } - public synchronized HashDb addNewHashDatabaseNoSave(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, - HashDb.KnownFilesType knownFilesType) throws HashDbManagerException { - HashDb hashDb = null; + public synchronized HashDatabase addNewHashDatabaseNoSave(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, + HashDatabase.KnownFilesType knownFilesType) throws HashDbManagerException { + HashDatabase hashDb = null; try { File file = new File(path); if (file.exists()) { @@ -233,9 +233,9 @@ public class HashDbManager implements PropertyChangeListener { return hashDb; } - private HashDb addFileHashDatabase(int handle, String hashSetName, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws TskCoreException { + private HashDatabase addFileHashDatabase(int handle, String hashSetName, boolean searchDuringIngest, boolean sendIngestMessages, HashDatabase.KnownFilesType knownFilesType) throws TskCoreException { // Wrap an object around the handle. - HashDb hashDb = new HashDb(handle, hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType); + HashDatabase hashDb = new HashDatabase(handle, hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType); // Get the indentity data before updating the collections since the // accessor methods may throw. @@ -300,7 +300,7 @@ public class HashDbManager implements PropertyChangeListener { } - synchronized void indexHashDatabase(HashDb hashDb) { + synchronized void indexHashDatabase(HashDatabase hashDb) { hashDb.addPropertyChangeListener(this); HashDbIndexer creator = new HashDbIndexer(hashDb); creator.execute(); @@ -308,8 +308,8 @@ public class HashDbManager implements PropertyChangeListener { @Override public void propertyChange(PropertyChangeEvent event) { - if (event.getPropertyName().equals(HashDb.Event.INDEXING_DONE.name())) { - HashDb hashDb = (HashDb) event.getNewValue(); + if (event.getPropertyName().equals(HashDatabase.Event.INDEXING_DONE.name())) { + HashDatabase hashDb = (HashDatabase) event.getNewValue(); if (null != hashDb) { try { String indexPath = hashDb.getIndexPath(); @@ -331,12 +331,12 @@ public class HashDbManager implements PropertyChangeListener { * * @throws HashDbManagerException */ - public synchronized void removeHashDatabase(HashDatabase hashDb) throws HashDbManagerException { + public synchronized void removeHashDatabase(HashDb hashDb) throws HashDbManagerException { this.removeHashDatabaseNoSave(hashDb); this.save(); } - public synchronized void removeHashDatabaseNoSave(HashDatabase hashDatabase) throws HashDbManagerException { + public synchronized void removeHashDatabaseNoSave(HashDb hashDb) throws HashDbManagerException { // Don't remove a database if ingest is running boolean ingestIsRunning = IngestManager.getInstance().isIngestRunning(); if (ingestIsRunning) { @@ -346,36 +346,36 @@ public class HashDbManager implements PropertyChangeListener { // and remove its hash set name from the hash set used to ensure unique // hash set names are used, before undertaking These operations will succeed and constitute // a mostly effective removal, even if the subsequent operations fail. - String hashSetName = hashDatabase.getHashSetName(); + String hashSetName = hashDb.getHashSetName(); hashSetNames.remove(hashSetName); - hashSets.remove(hashDatabase); + hashSets.remove(hashDb); // Now undertake the operations that could throw. // Indexing is only relevanet for file type hashsets - if(hashDatabase instanceof HashDb){ - HashDb hashDb = (HashDb)hashDatabase; + if(hashDb instanceof HashDatabase){ + HashDatabase hashDatabase = (HashDatabase)hashDb; try { - if(hashDb.hasIndex()){ - hashSetPaths.remove(hashDb.getIndexPath()); + if(hashDatabase.hasIndex()){ + hashSetPaths.remove(hashDatabase.getIndexPath()); } } catch (TskCoreException ex) { - Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error getting index path of " + hashDb.getHashSetName() + " hash database when removing the database", ex); //NON-NLS + Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error getting index path of " + hashDatabase.getHashSetName() + " hash database when removing the database", ex); //NON-NLS } try { - if (!hashDb.hasIndexOnly()) { - hashSetPaths.remove(hashDb.getDatabasePath()); + if (!hashDatabase.hasIndexOnly()) { + hashSetPaths.remove(hashDatabase.getDatabasePath()); } } catch (TskCoreException ex) { - Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error getting database path of " + hashDb.getHashSetName() + " hash database when removing the database", ex); //NON-NLS + Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error getting database path of " + hashDatabase.getHashSetName() + " hash database when removing the database", ex); //NON-NLS } } try { - hashDatabase.close(); + hashDb.close(); } catch (TskCoreException ex) { - Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error closing " + hashDatabase.getHashSetName() + " hash database when removing the database", ex); //NON-NLS + Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error closing " + hashDb.getHashSetName() + " hash database when removing the database", ex); //NON-NLS } // Let any external listeners know that a set has been deleted @@ -399,16 +399,6 @@ public class HashDbManager implements PropertyChangeListener { throw new HashDbManagerException(NbBundle.getMessage(this.getClass(), "HashDbManager.saveErrorExceptionMsg")); } } - - /** - * Gets all of the HashDbs used to classify files as known or known - * bad. Will not return central repository databases. - * - * @return A list, possibly empty, of hash databases. - */ - public synchronized List getAllHashSets() { - return getAllFileHashSets(); - } /** * Gets all of the file hash databases used to classify files as known or known @@ -416,10 +406,10 @@ public class HashDbManager implements PropertyChangeListener { * * @return A list, possibly empty, of hash databases. */ - synchronized List getAllFileHashSets() { - List hashDbs = new ArrayList<>(); - this.hashSets.stream().filter((thisSet) -> (thisSet instanceof HashDb)).forEach((thisSet) -> { - hashDbs.add((HashDb)thisSet); + synchronized List getAllFileHashSets() { + List hashDbs = new ArrayList<>(); + this.hashSets.stream().filter((thisSet) -> (thisSet instanceof HashDatabase)).forEach((thisSet) -> { + hashDbs.add((HashDatabase)thisSet); }); return hashDbs; } @@ -431,14 +421,14 @@ public class HashDbManager implements PropertyChangeListener { * * @return A list, possibly empty, of hash databases. */ - synchronized List getAllHashDatabases(){ + public synchronized List getAllHashSets(){ try{ updateHashSetsFromCentralRepository(); } catch (TskCoreException ex){ Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error loading central repository hash sets", ex); //NON-NLS } - List hashDbs = new ArrayList<>(); + List hashDbs = new ArrayList<>(); hashDbs.addAll(this.hashSets); return hashDbs; } @@ -450,24 +440,11 @@ public class HashDbManager implements PropertyChangeListener { */ public synchronized List getKnownFileHashSets() { List hashDbs = new ArrayList<>(); - this.hashSets.stream().filter((thisSet) -> ((thisSet instanceof HashDb) && (thisSet.getKnownFilesType() == HashDb.KnownFilesType.KNOWN))).forEach((thisSet) -> { - hashDbs.add((HashDb)thisSet); - }); - return hashDbs; - } - - /** - * Gets all of the hash databases used to classify files as known. - * - * @return A list, possibly empty, of hash databases. - */ - synchronized List getKnownFileHashDatabases() { - List hashDbs = new ArrayList<>(); - this.hashSets.stream().filter((db) -> (db.getKnownFilesType() == HashDb.KnownFilesType.KNOWN)).forEach((db) -> { + this.hashSets.stream().filter((db) -> (db.getKnownFilesType() == HashDatabase.KnownFilesType.KNOWN)).forEach((db) -> { hashDbs.add(db); }); return hashDbs; - } + } /** * Gets all of the hash databases used to classify files as notable. @@ -476,20 +453,7 @@ public class HashDbManager implements PropertyChangeListener { */ public synchronized List getKnownBadFileHashSets() { List hashDbs = new ArrayList<>(); - this.hashSets.stream().filter((thisSet) -> ((thisSet instanceof HashDb) && (thisSet.getKnownFilesType() == HashDb.KnownFilesType.KNOWN_BAD))).forEach((thisSet) -> { - hashDbs.add((HashDb)thisSet); - }); - return hashDbs; - } - - /** - * Gets all of the hash databases used to classify files as notable. - * - * @return A list, possibly empty, of hash databases. - */ - synchronized List getNotableFileHashDatabases() { - List hashDbs = new ArrayList<>(); - this.hashSets.stream().filter((db) -> (db.getKnownFilesType() == HashDb.KnownFilesType.KNOWN_BAD)).forEach((db) -> { + this.hashSets.stream().filter((db) -> (db.getKnownFilesType() == HashDatabase.KnownFilesType.KNOWN_BAD)).forEach((db) -> { hashDbs.add(db); }); return hashDbs; @@ -501,26 +465,12 @@ public class HashDbManager implements PropertyChangeListener { * @return A list, possibly empty, of hash databases. */ public synchronized List getUpdateableHashSets() { - List updateableDbs = new ArrayList<>(); - List updateableHashSets = getUpdateableHashSets(this.hashSets); - updateableHashSets.stream().filter((db) -> (db instanceof HashDb)).forEach((db) -> { - updateableDbs.add((HashDb)db); - }); - return updateableDbs; - } - - /** - * Gets all of the hash databases that accept updates. - * - * @return A list, possibly empty, of hash databases. - */ - public synchronized List getUpdateableHashDatabases(){ return getUpdateableHashSets(this.hashSets); } - private List getUpdateableHashSets(List hashDbs) { - ArrayList updateableDbs = new ArrayList<>(); - for (HashDatabase db : hashDbs) { + private List getUpdateableHashSets(List hashDbs) { + ArrayList updateableDbs = new ArrayList<>(); + for (HashDb db : hashDbs) { try { if (db.isUpdateable()) { updateableDbs.add(db); @@ -542,7 +492,7 @@ public class HashDbManager implements PropertyChangeListener { // Defaults for fields not stored in the central repository: // searchDuringIngest: false // sendIngestMessages: true if the hash set is notable - boolean sendIngestMessages = globalSet.getKnownStatus().equals(HashDb.KnownFilesType.KNOWN_BAD); + boolean sendIngestMessages = globalSet.getKnownStatus().equals(HashDatabase.KnownFilesType.KNOWN_BAD); crHashSets.add(new HashDbInfo(globalSet.getSetName(), globalSet.getVersion(), globalSet.getGlobalSetID(), globalSet.getKnownStatus(), globalSet.isReadOnly(), false, sendIngestMessages)); } @@ -565,8 +515,8 @@ public class HashDbManager implements PropertyChangeListener { loadHashsetsConfiguration(); } - private void closeHashDatabases(List hashDatabases) { - for (HashDatabase database : hashDatabases) { + private void closeHashDatabases(List hashDatabases) { + for (HashDb database : hashDatabases) { try { database.close(); } catch (TskCoreException ex) { @@ -672,7 +622,7 @@ public class HashDbManager implements PropertyChangeListener { } private boolean hashDbInfoIsNew(HashDbInfo dbInfo){ - for(HashDatabase db:this.hashSets){ + for(HashDb db:this.hashSets){ if(dbInfo.matches(db)){ return false; } @@ -727,7 +677,35 @@ public class HashDbManager implements PropertyChangeListener { return filePath; } - public static interface HashDatabase { + public static interface HashDb { + + /** + * Indicates how files with hashes stored in a particular hash database + * object should be classified. + */ + public enum KnownFilesType { + + KNOWN(NbBundle.getMessage(HashDbManager.class, "HashDbManager.known.text")), + KNOWN_BAD(NbBundle.getMessage(HashDbManager.class, "HashDbManager.knownBad.text")); + private final String displayName; + + private KnownFilesType(String displayName) { + this.displayName = displayName; + } + + public String getDisplayName() { + return this.displayName; + } + } + + /** + * Property change events published by hash database objects. + */ + public enum Event { + + INDEXING_DONE + } + enum DatabaseType{ FILE, CENTRAL_REPOSITORY @@ -739,7 +717,7 @@ public class HashDbManager implements PropertyChangeListener { public String getDatabasePath() throws TskCoreException; - public HashDb.KnownFilesType getKnownFilesType(); + public HashDatabase.KnownFilesType getKnownFilesType(); public boolean getSearchDuringIngest(); @@ -788,6 +766,10 @@ public class HashDbManager implements PropertyChangeListener { public int getHandle(); + public String getIndexPath() throws TskCoreException; + + public boolean hasIndexOnly() throws TskCoreException; + public void firePropertyChange(String propertyName, Object oldValue, Object newValue); public void addPropertyChangeListener(PropertyChangeListener pcl); @@ -808,44 +790,18 @@ public class HashDbManager implements PropertyChangeListener { * Instances of this class represent hash databases used to classify files * as known or know bad. */ - public static class HashDb implements HashDatabase{ - - /** - * Indicates how files with hashes stored in a particular hash database - * object should be classified. - */ - public enum KnownFilesType { - - KNOWN(NbBundle.getMessage(HashDbManager.class, "HashDbManager.known.text")), - KNOWN_BAD(NbBundle.getMessage(HashDbManager.class, "HashDbManager.knownBad.text")); - private final String displayName; - - private KnownFilesType(String displayName) { - this.displayName = displayName; - } - - public String getDisplayName() { - return this.displayName; - } - } - - /** - * Property change events published by hash database objects. - */ - public enum Event { - - INDEXING_DONE - } + public static class HashDatabase implements HashDb{ + private static final long serialVersionUID = 1L; private final int handle; private final String hashSetName; private boolean searchDuringIngest; private boolean sendIngestMessages; - private final HashDb.KnownFilesType knownFilesType; + private final HashDatabase.KnownFilesType knownFilesType; private boolean indexing; private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); - private HashDb(int handle, String hashSetName, boolean useForIngest, boolean sendHitMessages, KnownFilesType knownFilesType) { + private HashDatabase(int handle, String hashSetName, boolean useForIngest, boolean sendHitMessages, KnownFilesType knownFilesType) { this.handle = handle; this.hashSetName = hashSetName; this.searchDuringIngest = useForIngest; @@ -1058,6 +1014,7 @@ public class HashDbManager implements PropertyChangeListener { return SleuthkitJNI.hashDatabaseHasLookupIndex(handle); } + @Override public boolean hasIndexOnly() throws TskCoreException { return SleuthkitJNI.hashDatabaseIsIndexOnly(handle); } @@ -1104,7 +1061,7 @@ public class HashDbManager implements PropertyChangeListener { if (getClass() != obj.getClass()) { return false; } - final HashDb other = (HashDb) obj; + final HashDatabase other = (HashDatabase) obj; if (!Objects.equals(this.hashSetName, other.hashSetName)) { return false; } @@ -1119,13 +1076,13 @@ public class HashDbManager implements PropertyChangeListener { * Instances of this class represent hash databases used to classify files * as known or know bad. */ - public static class CentralRepoHashDb implements HashDatabase{ + public static class CentralRepoHashDb implements HashDb{ private static final long serialVersionUID = 1L; private final String hashSetName; private boolean searchDuringIngest; private boolean sendIngestMessages; - private final HashDb.KnownFilesType knownFilesType; + private final HashDatabase.KnownFilesType knownFilesType; private final int referenceSetID; private final String version; private String orgName; @@ -1134,7 +1091,7 @@ public class HashDbManager implements PropertyChangeListener { @Messages({"HashDbManager.CentralRepoHashDb.orgError=Error loading organization"}) private CentralRepoHashDb(String hashSetName, String version, int referenceSetID, - boolean useForIngest, boolean sendHitMessages, HashDb.KnownFilesType knownFilesType, + boolean useForIngest, boolean sendHitMessages, HashDatabase.KnownFilesType knownFilesType, boolean readOnly) throws TskCoreException{ this.hashSetName = hashSetName; @@ -1148,7 +1105,7 @@ public class HashDbManager implements PropertyChangeListener { try{ orgName = EamDb.getInstance().getReferenceSetOrganization(referenceSetID).getName(); } catch (EamDbException ex){ - Logger.getLogger(HashDb.class.getName()).log(Level.SEVERE, "Error looking up central repository organization", ex); //NON-NLS + Logger.getLogger(HashDatabase.class.getName()).log(Level.SEVERE, "Error looking up central repository organization", ex); //NON-NLS orgName = Bundle.HashDbManager_CentralRepoHashDb_orgError(); } } @@ -1178,6 +1135,11 @@ public class HashDbManager implements PropertyChangeListener { public int getHandle(){ return 0; } + + @Override + public boolean hasIndexOnly() throws TskCoreException{ + return true; + } @Override public String getHashSetName() { @@ -1211,12 +1173,13 @@ public class HashDbManager implements PropertyChangeListener { return DatabaseType.CENTRAL_REPOSITORY; } + @Override public String getIndexPath() throws TskCoreException { return ""; } @Override - public HashDb.KnownFilesType getKnownFilesType() { + public HashDatabase.KnownFilesType getKnownFilesType() { return knownFilesType; } @@ -1319,7 +1282,7 @@ public class HashDbManager implements PropertyChangeListener { try{ return EamDb.getInstance().isHashInReferenceSet(file.getMd5Hash(), this.referenceSetID); } catch (EamDbException ex){ - Logger.getLogger(HashDb.class.getName()).log(Level.SEVERE, "Error performing central reposiotry hash lookup", ex); //NON-NLS + Logger.getLogger(HashDatabase.class.getName()).log(Level.SEVERE, "Error performing central reposiotry hash lookup", ex); //NON-NLS throw new TskCoreException("Error performing central reposiotry hash lookup", ex); } } @@ -1350,7 +1313,7 @@ public class HashDbManager implements PropertyChangeListener { result = new HashHitInfo(file.getMd5Hash(), "", ""); } } catch (EamDbException ex){ - Logger.getLogger(HashDb.class.getName()).log(Level.SEVERE, "Error performing central reposiotry hash lookup", ex); //NON-NLS + Logger.getLogger(HashDatabase.class.getName()).log(Level.SEVERE, "Error performing central reposiotry hash lookup", ex); //NON-NLS throw new TskCoreException("Error performing central reposiotry hash lookup", ex); } } @@ -1431,9 +1394,9 @@ public class HashDbManager implements PropertyChangeListener { private class HashDbIndexer extends SwingWorker { private ProgressHandle progress = null; - private HashDb hashDb = null; + private HashDatabase hashDb = null; - HashDbIndexer(HashDb hashDb) { + HashDbIndexer(HashDatabase hashDb) { this.hashDb = hashDb; } @@ -1447,7 +1410,7 @@ public class HashDbManager implements PropertyChangeListener { try { SleuthkitJNI.createLookupIndexForHashDatabase(hashDb.getHandle()); } catch (TskCoreException ex) { - Logger.getLogger(HashDb.class.getName()).log(Level.SEVERE, "Error indexing hash database", ex); //NON-NLS + Logger.getLogger(HashDatabase.class.getName()).log(Level.SEVERE, "Error indexing hash database", ex); //NON-NLS JOptionPane.showMessageDialog(null, NbBundle.getMessage(this.getClass(), "HashDbManager.dlgMsg.errorIndexingHashSet", @@ -1477,7 +1440,7 @@ public class HashDbManager implements PropertyChangeListener { } try { - hashDb.firePropertyChange(HashDb.Event.INDEXING_DONE.toString(), null, hashDb); + hashDb.firePropertyChange(HashDatabase.Event.INDEXING_DONE.toString(), null, hashDb); hashDb.firePropertyChange(HashDbManager.SetEvt.DB_INDEXED.toString(), null, hashDb.getHashSetName()); } catch (Exception e) { logger.log(Level.SEVERE, "HashDbManager listener threw exception", e); //NON-NLS diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java index 52ae48c8cd..2fb515832b 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleFactory.java @@ -60,7 +60,7 @@ public class HashLookupModuleFactory extends IngestModuleFactoryAdapter { @Override public IngestModuleIngestJobSettings getDefaultIngestJobSettings() { // All available hash sets are enabled and always calculate hashes is true by default. - return new HashLookupModuleSettings(true, HashDbManager.getInstance().getAllHashDatabases()); + return new HashLookupModuleSettings(true, HashDbManager.getInstance().getAllHashSets()); } @Override diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java index 9923c7f21b..3e331cb1da 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettings.java @@ -26,8 +26,8 @@ import java.io.IOException; import org.sleuthkit.autopsy.ingest.IngestModuleIngestJobSettings; import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; import org.sleuthkit.autopsy.modules.hashdatabase.HashLookupSettings.HashDbInfo; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; /** * Ingest job settings for the hash lookup module. @@ -42,7 +42,7 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { private boolean shouldCalculateHashes = true; private List databaseInfoList; - HashLookupModuleSettings(boolean shouldCalculateHashes, List hashDbList){ + HashLookupModuleSettings(boolean shouldCalculateHashes, List hashDbList){ this.shouldCalculateHashes = shouldCalculateHashes; try{ databaseInfoList = HashLookupSettings.convertHashSetList(hashDbList); @@ -76,12 +76,12 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { * @param disabledHashSets A list of disabled hash sets. */ HashLookupModuleSettings(boolean shouldCalculateHashes, - List enabledHashSets, - List disabledHashSets) { + List enabledHashSets, + List disabledHashSets) { this.shouldCalculateHashes = shouldCalculateHashes; databaseInfoList = new ArrayList<>(); - for(HashDatabase db:enabledHashSets){ + for(HashDb db:enabledHashSets){ try{ HashDbInfo dbInfo = new HashDbInfo(db); dbInfo.setSearchDuringIngest(true); @@ -90,7 +90,7 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { Logger.getLogger(HashLookupModuleSettings.class.getName()).log(Level.SEVERE, "Error creating hash database settings for " + db.getHashSetName(), ex); //NON-NLS } } - for(HashDatabase db:disabledHashSets){ + for(HashDb db:disabledHashSets){ try{ HashDbInfo dbInfo = new HashDbInfo(db); dbInfo.setSearchDuringIngest(false); @@ -128,7 +128,7 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { * * @return True if the hash set is enabled, false otherwise. */ - boolean isHashSetEnabled(HashDatabase db) { + boolean isHashSetEnabled(HashDb db) { for(HashDbInfo dbInfo:databaseInfoList){ if(dbInfo.matches(db)){ return dbInfo.getSearchDuringIngest(); @@ -150,7 +150,7 @@ final class HashLookupModuleSettings implements IngestModuleIngestJobSettings { } try{ - databaseInfoList = HashLookupSettings.convertHashSetList(HashDbManager.getInstance().getAllHashDatabases()); + databaseInfoList = HashLookupSettings.convertHashSetList(HashDbManager.getInstance().getAllHashSets()); } catch (HashLookupSettings.HashLookupSettingsException ex){ Logger.getLogger(HashLookupModuleSettings.class.getName()).log(Level.SEVERE, "Error updating hash database settings.", ex); //NON-NLS return; diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java index 1e83fb77c6..c6d3e109fe 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java @@ -30,8 +30,8 @@ import javax.swing.table.TableColumn; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.ingest.IngestModuleIngestJobSettings; import org.sleuthkit.autopsy.ingest.IngestModuleIngestJobSettingsPanel; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; import org.sleuthkit.datamodel.TskCoreException; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; /** @@ -58,13 +58,13 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe } catch (TskCoreException ex){ Logger.getLogger(HashLookupModuleSettingsPanel.class.getName()).log(Level.SEVERE, "Error updating central repository hash sets", ex); //NON-NLS } - initializeHashSetModels(settings, hashDbManager.getKnownFileHashDatabases(), knownHashSetModels); - initializeHashSetModels(settings, hashDbManager.getNotableFileHashDatabases(), knownBadHashSetModels); + initializeHashSetModels(settings, hashDbManager.getKnownFileHashSets(), knownHashSetModels); + initializeHashSetModels(settings, hashDbManager.getKnownBadFileHashSets(), knownBadHashSetModels); } - private void initializeHashSetModels(HashLookupModuleSettings settings, List hashDbs, List hashSetModels) { + private void initializeHashSetModels(HashLookupModuleSettings settings, List hashDbs, List hashSetModels) { hashSetModels.clear(); - for (HashDatabase db : hashDbs) { + for (HashDb db : hashDbs) { hashSetModels.add(new HashSetModel(db, settings.isHashSetEnabled(db), isHashDbValid(db))); } } @@ -105,15 +105,15 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe @Override public IngestModuleIngestJobSettings getSettings() { - List enabledHashSets = new ArrayList<>(); - List disabledHashSets = new ArrayList<>(); + List enabledHashSets = new ArrayList<>(); + List disabledHashSets = new ArrayList<>(); addHashSets(knownHashSetModels, enabledHashSets, disabledHashSets); addHashSets(knownBadHashSetModels, enabledHashSets, disabledHashSets); return new HashLookupModuleSettings(alwaysCalcHashesCheckbox.isSelected(), enabledHashSets, disabledHashSets); } - private void addHashSets(List hashSetModels, List enabledHashSets, List disabledHashSets) { + private void addHashSets(List hashSetModels, List enabledHashSets, List disabledHashSets) { for (HashSetModel model : hashSetModels) { if (model.isEnabled() && model.isValid()) { enabledHashSets.add(model.getDatabase()); @@ -130,19 +130,19 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe } private void updateHashSetModels() { - updateHashSetModels(hashDbManager.getKnownFileHashDatabases(), knownHashSetModels); - updateHashSetModels(hashDbManager.getNotableFileHashDatabases(), knownBadHashSetModels); + updateHashSetModels(hashDbManager.getKnownFileHashSets(), knownHashSetModels); + updateHashSetModels(hashDbManager.getKnownBadFileHashSets(), knownBadHashSetModels); } - void updateHashSetModels(List hashDbs, List hashSetModels) { + void updateHashSetModels(List hashDbs, List hashSetModels) { - List hashDatabases = new ArrayList<>(hashDbs); + List hashDatabases = new ArrayList<>(hashDbs); // Update the hash sets and detect deletions. List deletedHashSetModels = new ArrayList<>(); for (HashSetModel model : hashSetModels) { boolean foundDatabase = false; - for(HashDatabase db : hashDatabases){ + for(HashDb db : hashDatabases){ if(model.getDatabase().equals(db)){ model.setValid(isHashDbValid(db)); hashDatabases.remove(db); @@ -161,7 +161,7 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe } // Add any new hash sets. All new sets are enabled by default. - for (HashDatabase db : hashDatabases) { + for (HashDb db : hashDatabases) { hashSetModels.add(new HashSetModel(db, true, isHashDbValid(db))); } } @@ -173,7 +173,7 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe knownBadHashSetsTableModel.fireTableDataChanged(); } - private boolean isHashDbValid(HashDatabase hashDb) { + private boolean isHashDbValid(HashDb hashDb) { boolean isValid = false; try { isValid = hashDb.isValid(); @@ -185,17 +185,17 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe private static final class HashSetModel { - private final HashDatabase db; + private final HashDb db; private boolean valid; private boolean enabled; - HashSetModel(HashDatabase db, boolean enabled, boolean valid) { + HashSetModel(HashDb db, boolean enabled, boolean valid) { this.db = db; this.enabled = enabled; this.valid = valid; } - HashDatabase getDatabase(){ + HashDb getDatabase(){ return db; } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java index 89d807d507..5dda017e54 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java @@ -36,13 +36,13 @@ import org.sleuthkit.autopsy.core.RuntimeProperties; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.PlatformUtil; import org.sleuthkit.autopsy.coreutils.XMLUtil; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase.DatabaseType; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb.DatabaseType; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.CentralRepoHashDb; import org.sleuthkit.datamodel.TskCoreException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; /** * Class to represent the settings to be serialized for hash lookup. @@ -74,9 +74,9 @@ final class HashLookupSettings implements Serializable { this.hashDbInfoList = hashDbInfoList; } - static List convertHashSetList(List hashSets) throws HashLookupSettingsException{ + static List convertHashSetList(List hashSets) throws HashLookupSettingsException{ List dbInfoList = new ArrayList<>(); - for(HashDbManager.HashDatabase db:hashSets){ + for(HashDbManager.HashDb db:hashSets){ try{ dbInfoList.add(new HashDbInfo(db)); } catch (TskCoreException ex){ @@ -202,7 +202,7 @@ final class HashLookupSettings implements Serializable { // Handle legacy known files types. if (knownFilesType.equals("NSRL")) { //NON-NLS - knownFilesType = HashDbManager.HashDb.KnownFilesType.KNOWN.toString(); + knownFilesType = HashDbManager.HashDatabase.KnownFilesType.KNOWN.toString(); updatedSchema = true; } @@ -236,7 +236,7 @@ final class HashLookupSettings implements Serializable { } else { throw new HashLookupSettingsException(String.format(elementErrorMessage, PATH_ELEMENT)); } - hashDbInfoList.add(new HashDbInfo(hashSetName, HashDbManager.HashDb.KnownFilesType.valueOf(knownFilesType), + hashDbInfoList.add(new HashDbInfo(hashSetName, HashDbManager.HashDatabase.KnownFilesType.valueOf(knownFilesType), searchDuringIngestFlag, sendIngestMessagesFlag, dbPath)); hashSetNames.add(hashSetName); } @@ -299,7 +299,7 @@ final class HashLookupSettings implements Serializable { private static final long serialVersionUID = 1L; private final String hashSetName; - private final HashDbManager.HashDb.KnownFilesType knownFilesType; + private final HashDbManager.HashDatabase.KnownFilesType knownFilesType; private boolean searchDuringIngest; private final boolean sendIngestMessages; private final String path; @@ -318,7 +318,7 @@ final class HashLookupSettings implements Serializable { * @param sendIngestMessages Whether or not ingest messages are sent * @param path The path to the db */ - HashDbInfo(String hashSetName, HashDbManager.HashDb.KnownFilesType knownFilesType, boolean searchDuringIngest, boolean sendIngestMessages, String path) { + HashDbInfo(String hashSetName, HashDbManager.HashDatabase.KnownFilesType knownFilesType, boolean searchDuringIngest, boolean sendIngestMessages, String path) { this.hashSetName = hashSetName; this.knownFilesType = knownFilesType; this.searchDuringIngest = searchDuringIngest; @@ -330,7 +330,7 @@ final class HashLookupSettings implements Serializable { this.dbType = DatabaseType.FILE; } - HashDbInfo(String hashSetName, String version, int referenceSetID, HashDbManager.HashDb.KnownFilesType knownFilesType, boolean readOnly, boolean searchDuringIngest, boolean sendIngestMessages){ + HashDbInfo(String hashSetName, String version, int referenceSetID, HashDbManager.HashDatabase.KnownFilesType knownFilesType, boolean readOnly, boolean searchDuringIngest, boolean sendIngestMessages){ this.hashSetName = hashSetName; this.version = version; this.referenceSetID = referenceSetID; @@ -342,9 +342,9 @@ final class HashLookupSettings implements Serializable { dbType = DatabaseType.CENTRAL_REPOSITORY; } - HashDbInfo(HashDbManager.HashDatabase db) throws TskCoreException{ - if(db instanceof HashDbManager.HashDb){ - HashDbManager.HashDb fileTypeDb = (HashDbManager.HashDb)db; + HashDbInfo(HashDbManager.HashDb db) throws TskCoreException{ + if(db instanceof HashDbManager.HashDatabase){ + HashDbManager.HashDatabase fileTypeDb = (HashDbManager.HashDatabase)db; this.hashSetName = fileTypeDb.getHashSetName(); this.knownFilesType = fileTypeDb.getKnownFilesType(); this.searchDuringIngest = fileTypeDb.getSearchDuringIngest(); @@ -402,7 +402,7 @@ final class HashLookupSettings implements Serializable { * * @return The known files type setting. */ - HashDbManager.HashDb.KnownFilesType getKnownFilesType() { + HashDbManager.HashDatabase.KnownFilesType getKnownFilesType() { return knownFilesType; } @@ -457,7 +457,7 @@ final class HashLookupSettings implements Serializable { return dbType == DatabaseType.CENTRAL_REPOSITORY; } - boolean matches(HashDatabase hashDb){ + boolean matches(HashDb hashDb){ if(hashDb == null){ return false; } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java index 46b636af82..ef8986af24 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java @@ -45,11 +45,11 @@ import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.events.AutopsyEvent; import org.sleuthkit.autopsy.ingest.IngestManager; import org.sleuthkit.autopsy.ingest.IngestModuleGlobalSettingsPanel; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.CentralRepoHashDb; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb.KnownFilesType; import org.sleuthkit.datamodel.TskCoreException; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; /** * Instances of this class provide a comprehensive UI for managing the hash sets @@ -108,7 +108,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan } private void updateComponents() { - HashDatabase db = ((HashSetTable) hashSetTable).getSelection(); + HashDb db = ((HashSetTable) hashSetTable).getSelection(); if (db != null) { updateComponentsForSelection(db); } else { @@ -157,7 +157,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan "HashLookupSettingsPanel.notApplicable=N/A", "HashLookupSettingsPanel.centralRepo=Central Repository" }) - private void updateComponentsForSelection(HashDatabase db) { + private void updateComponentsForSelection(HashDb db) { boolean ingestIsRunning = IngestManager.getInstance().isIngestRunning(); // Update descriptive labels. @@ -180,8 +180,8 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan addHashesToDatabaseButton.setEnabled(false); } - if(db instanceof HashDb){ - HashDb hashDb = (HashDb)db; + if(db instanceof HashDatabase){ + HashDatabase hashDb = (HashDatabase)db; // Disable the central repo fields hashDbVersionLabel.setText(Bundle.HashLookupSettingsPanel_notApplicable()); @@ -304,8 +304,8 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan "HashLookupSettingsPanel.saveFail.title=Save Fail"}) public void saveSettings() { //Checking for for any unindexed databases - List unindexed = new ArrayList<>(); - for (HashDb db : hashSetManager.getAllFileHashSets()) { + List unindexed = new ArrayList<>(); + for (HashDatabase db : hashSetManager.getAllFileHashSets()) { try { if (!db.hasIndex()) { unindexed.add(db); @@ -370,8 +370,8 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan } @Messages({"# {0} - hash lookup name", "HashLookupSettingsPanel.removeDatabaseFailure.message=Failed to remove hash lookup: {0}"}) - void removeThese(List toRemove) { - for (HashDb hashDb : toRemove) { + void removeThese(List toRemove) { + for (HashDatabase hashDb : toRemove) { try { hashSetManager.removeHashDatabaseNoSave(hashDb); } catch (HashDbManager.HashDbManagerException ex) { @@ -389,10 +389,10 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan * @param plural Whether or not there are multiple unindexed databases * @param unindexed The list of unindexed databases. Can be of size 1. */ - private void showInvalidIndex(boolean plural, List unindexed) { + private void showInvalidIndex(boolean plural, List unindexed) { String total = ""; String message; - for (HashDatabase hdb : unindexed) { + for (HashDb hdb : unindexed) { total += "\n" + hdb.getHashSetName(); } if (plural) { @@ -445,7 +445,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan return cellRenderer; } - public HashDatabase getSelection() { + public HashDb getSelection() { return hashSetTableModel.getHashSetAt(getSelectionModel().getMinSelectionIndex()); } @@ -455,7 +455,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan } } - public void selectRowByDatabase(HashDatabase db){ + public void selectRowByDatabase(HashDb db){ setSelection(hashSetTableModel.getIndexByDatabase(db)); } @@ -471,7 +471,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan */ private class HashSetTableModel extends AbstractTableModel { - List hashSets = HashDbManager.getInstance().getAllHashDatabases(); + List hashSets = HashDbManager.getInstance().getAllHashSets(); @Override public int getColumnCount() { @@ -518,7 +518,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan return getValueAt(0, c).getClass(); } - HashDatabase getHashSetAt(int index) { + HashDb getHashSetAt(int index) { if (!hashSets.isEmpty() && index >= 0 && index < hashSets.size()) { return hashSets.get(index); } else { @@ -526,7 +526,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan } } - int getIndexByDatabase(HashDatabase db){ + int getIndexByDatabase(HashDb db){ for (int i = 0; i < hashSets.size(); ++i) { if (hashSets.get(i).equals(db)) { return i; @@ -546,7 +546,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan } void refreshModel() { - hashSets = HashDbManager.getInstance().getAllHashDatabases(); + hashSets = HashDbManager.getInstance().getAllHashSets(); refreshDisplay(); } @@ -910,12 +910,12 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan private void addHashesToDatabaseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addHashesToDatabaseButtonActionPerformed - HashDatabase hashDb = ((HashSetTable) hashSetTable).getSelection(); + HashDb hashDb = ((HashSetTable) hashSetTable).getSelection(); AddHashValuesToDatabaseDialog dialog = new AddHashValuesToDatabaseDialog(hashDb); }//GEN-LAST:event_addHashesToDatabaseButtonActionPerformed private void createDatabaseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createDatabaseButtonActionPerformed - HashDatabase hashDb = new HashDbCreateDatabaseDialog().getHashDatabase(); + HashDb hashDb = new HashDbCreateDatabaseDialog().getHashDatabase(); if (null != hashDb) { hashSetTableModel.refreshModel(); ((HashSetTable) hashSetTable).selectRowByDatabase(hashDb); @@ -924,7 +924,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan }//GEN-LAST:event_createDatabaseButtonActionPerformed private void sendIngestMessagesCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendIngestMessagesCheckBoxActionPerformed - HashDatabase hashDb = ((HashSetTable) hashSetTable).getSelection(); + HashDb hashDb = ((HashSetTable) hashSetTable).getSelection(); if (hashDb != null) { hashDb.setSendIngestMessages(sendIngestMessagesCheckBox.isSelected()); firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null); @@ -932,18 +932,18 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan }//GEN-LAST:event_sendIngestMessagesCheckBoxActionPerformed private void indexButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_indexButtonActionPerformed - final HashDatabase hashDatabase = ((HashSetTable) hashSetTable).getSelection(); + final HashDb hashDatabase = ((HashSetTable) hashSetTable).getSelection(); assert hashDatabase != null; - assert hashDatabase instanceof HashDb; + assert hashDatabase instanceof HashDatabase; // Add a listener for the INDEXING_DONE event. This listener will update // the UI. - HashDb hashDb = (HashDb)hashDatabase; + HashDatabase hashDb = (HashDatabase)hashDatabase; hashDb.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName().equals(HashDb.Event.INDEXING_DONE.toString())) { - HashDatabase selectedHashDb = ((HashSetTable) hashSetTable).getSelection(); + if (evt.getPropertyName().equals(HashDatabase.Event.INDEXING_DONE.toString())) { + HashDb selectedHashDb = ((HashSetTable) hashSetTable).getSelection(); if (selectedHashDb != null && hashDb != null && hashDb.equals(selectedHashDb)) { updateComponents(); } @@ -964,7 +964,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan }//GEN-LAST:event_indexButtonActionPerformed private void importDatabaseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importDatabaseButtonActionPerformed - HashDatabase hashDb = new HashDbImportDatabaseDialog().getHashDatabase(); + HashDb hashDb = new HashDbImportDatabaseDialog().getHashDatabase(); if (null != hashDb) { if(hashDb instanceof CentralRepoHashDb){ int newReferenceSetID = ((CentralRepoHashDb)hashDb).getReferenceSetID(); @@ -985,7 +985,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan NbBundle.getMessage(this.getClass(), "HashDbConfigPanel.deleteDbActionMsg"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) { - HashDatabase hashDb = ((HashSetTable) hashSetTable).getSelection(); + HashDb hashDb = ((HashSetTable) hashSetTable).getSelection(); if (hashDb != null) { try { hashSetManager.removeHashDatabaseNoSave(hashDb); @@ -1000,7 +1000,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan private void hashSetTableKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_hashSetTableKeyPressed if (evt.getKeyCode() == KeyEvent.VK_DELETE) { - HashDatabase hashDb = ((HashSetTable) hashSetTable).getSelection(); + HashDb hashDb = ((HashSetTable) hashSetTable).getSelection(); if (hashDb != null) { try { hashSetManager.removeHashDatabaseNoSave(hashDb); diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java index 397b4948cf..6f14459eb6 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java @@ -77,7 +77,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P } void importFile(String hashSetName, String version, int orgId, - boolean searchDuringIngest, boolean sendIngestMessages, HashDbManager.HashDb.KnownFilesType knownFilesType, + boolean searchDuringIngest, boolean sendIngestMessages, HashDbManager.HashDatabase.KnownFilesType knownFilesType, boolean readOnly, String importFileName){ setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); @@ -92,7 +92,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P this.setVisible(true); } - HashDbManager.HashDatabase getDatabase(){ + HashDbManager.HashDb getDatabase(){ if(worker != null){ return worker.getDatabase(); } @@ -128,7 +128,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P void addPropertyChangeListener(PropertyChangeListener dialog); int getProgressPercentage(); long getLinesProcessed(); - HashDbManager.HashDatabase getDatabase(); + HashDbManager.HashDb getDatabase(); } class ImportIDXWorker extends SwingWorker implements CentralRepoImportWorker{ @@ -139,7 +139,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P private final int orgId; private final boolean searchDuringIngest; private final boolean sendIngestMessages; - private final HashDbManager.HashDb.KnownFilesType knownFilesType; + private final HashDbManager.HashDatabase.KnownFilesType knownFilesType; private final boolean readOnly; private final File importFile; private final long totalLines; @@ -148,7 +148,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P private final AtomicLong numLines = new AtomicLong(); ImportIDXWorker(String hashSetName, String version, int orgId, - boolean searchDuringIngest, boolean sendIngestMessages, HashDbManager.HashDb.KnownFilesType knownFilesType, + boolean searchDuringIngest, boolean sendIngestMessages, HashDbManager.HashDatabase.KnownFilesType knownFilesType, boolean readOnly, File importFile){ this.hashSetName = hashSetName; @@ -176,7 +176,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P } @Override - public HashDbManager.HashDatabase getDatabase(){ + public HashDbManager.HashDb getDatabase(){ return newHashDb; } @@ -194,7 +194,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P protected Void doInBackground() throws Exception { TskData.FileKnown knownStatus; - if (knownFilesType.equals(HashDbManager.HashDb.KnownFilesType.KNOWN)) { + if (knownFilesType.equals(HashDbManager.HashDatabase.KnownFilesType.KNOWN)) { knownStatus = TskData.FileKnown.KNOWN; } else { knownStatus = TskData.FileKnown.BAD; diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ModalNoButtons.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ModalNoButtons.java index 33f65488d2..5795233479 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ModalNoButtons.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ModalNoButtons.java @@ -26,7 +26,7 @@ import java.util.List; import javax.swing.JOptionPane; import org.openide.util.NbBundle; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; /** * This class exists as a stop-gap measure to force users to have an indexed @@ -43,8 +43,8 @@ import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; */ class ModalNoButtons extends javax.swing.JDialog implements PropertyChangeListener { - List unindexed; - HashDb toIndex; + List unindexed; + HashDatabase toIndex; HashLookupSettingsPanel hdbmp; int length = 0; int currentcount = 1; @@ -58,7 +58,7 @@ class ModalNoButtons extends javax.swing.JDialog implements PropertyChangeListen * @param parent Swing parent frame. * @param unindexed the list of unindexed databases to index. */ - ModalNoButtons(HashLookupSettingsPanel hdbmp, java.awt.Frame parent, List unindexed) { + ModalNoButtons(HashLookupSettingsPanel hdbmp, java.awt.Frame parent, List unindexed) { super(parent, NbBundle.getMessage(ModalNoButtons.class, "ModalNoButtons.indexingDbsTitle"), true); this.unindexed = unindexed; this.toIndex = null; @@ -75,7 +75,7 @@ class ModalNoButtons extends javax.swing.JDialog implements PropertyChangeListen * @param parent Swing parent frame. * @param unindexed The unindexed database to index. */ - ModalNoButtons(HashLookupSettingsPanel hdbmp, java.awt.Frame parent, HashDb unindexed) { + ModalNoButtons(HashLookupSettingsPanel hdbmp, java.awt.Frame parent, HashDatabase unindexed) { super(parent, NbBundle.getMessage(ModalNoButtons.class, "ModalNoButtons.indexingDbTitle"), true); this.unindexed = null; this.toIndex = unindexed; @@ -183,7 +183,7 @@ class ModalNoButtons extends javax.swing.JDialog implements PropertyChangeListen "ModalNoButtons.dlgTitle.unfinishedIndexing"), JOptionPane.YES_NO_OPTION); if (res == JOptionPane.YES_OPTION) { - List remove = new ArrayList<>(); + List remove = new ArrayList<>(); if (this.toIndex == null) { remove = this.unindexed; } else { @@ -230,7 +230,7 @@ class ModalNoButtons extends javax.swing.JDialog implements PropertyChangeListen private void indexThese() { length = this.unindexed.size(); this.INDEXING_PROGBAR.setIndeterminate(true); - for (HashDb db : this.unindexed) { + for (HashDatabase db : this.unindexed) { currentDb = db.getHashSetName(); this.CURRENTDB_LABEL.setText("(" + currentDb + ")"); this.CURRENTLYON_LABEL.setText( @@ -255,7 +255,7 @@ class ModalNoButtons extends javax.swing.JDialog implements PropertyChangeListen * this dialog if all indexing is complete. */ public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName().equals(HashDb.Event.INDEXING_DONE.name())) { + if (evt.getPropertyName().equals(HashDatabase.Event.INDEXING_DONE.name())) { if (currentcount >= length) { this.INDEXING_PROGBAR.setValue(100); this.setModal(false); diff --git a/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDb.java b/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDb.java index 233aad0202..e2c90b005c 100755 --- a/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDb.java +++ b/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDb.java @@ -34,7 +34,7 @@ import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; /** * Instances of this class plug in to the reporting infrastructure to provide a @@ -69,7 +69,7 @@ public class AddTaggedHashesToHashDb implements GeneralReportModule { progressPanel.start(); progressPanel.updateStatusLabel("Adding hashes..."); - HashDatabase hashSet = configPanel.getSelectedHashDatabase(); + HashDb hashSet = configPanel.getSelectedHashDatabase(); if (hashSet != null) { progressPanel.updateStatusLabel("Adding hashes to " + hashSet.getHashSetName() + " hash set..."); diff --git a/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.form b/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.form index 20cec74d82..dfe9ba921e 100755 --- a/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.form +++ b/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.form @@ -124,7 +124,7 @@ - + diff --git a/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.java b/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.java index 9c1875eeb2..0c20eee562 100644 --- a/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.java +++ b/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.java @@ -39,7 +39,7 @@ import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager; import org.sleuthkit.autopsy.modules.hashdatabase.HashLookupSettingsPanel; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; /** * Instances of this class are used to configure the report module plug in that @@ -52,7 +52,7 @@ class AddTaggedHashesToHashDbConfigPanel extends javax.swing.JPanel { private final Map tagNameSelections = new LinkedHashMap<>(); private final TagNamesListModel tagsNamesListModel = new TagNamesListModel(); private final TagsNamesListCellRenderer tagsNamesRenderer = new TagsNamesListCellRenderer(); - private HashDatabase selectedHashSet = null; + private HashDb selectedHashSet = null; AddTaggedHashesToHashDbConfigPanel() { initComponents(); @@ -107,9 +107,9 @@ class AddTaggedHashesToHashDbConfigPanel extends javax.swing.JPanel { // Get the updateable hash databases and add their hash set names to the // JComboBox component. - List updateableHashSets = HashDbManager.getInstance().getUpdateableHashDatabases(); + List updateableHashSets = HashDbManager.getInstance().getUpdateableHashSets(); if (!updateableHashSets.isEmpty()) { - for (HashDatabase hashDb : updateableHashSets) { + for (HashDb hashDb : updateableHashSets) { hashSetsComboBox.addItem(hashDb); } hashSetsComboBox.setEnabled(true); @@ -138,7 +138,7 @@ class AddTaggedHashesToHashDbConfigPanel extends javax.swing.JPanel { * * @return A HashDb object representing the database or null. */ - HashDatabase getSelectedHashDatabase() { + HashDb getSelectedHashDatabase() { return selectedHashSet; } @@ -286,7 +286,7 @@ class AddTaggedHashesToHashDbConfigPanel extends javax.swing.JPanel { }//GEN-LAST:event_selectAllButtonActionPerformed private void hashSetsComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hashSetsComboBoxActionPerformed - selectedHashSet = (HashDatabase)hashSetsComboBox.getSelectedItem(); + selectedHashSet = (HashDb)hashSetsComboBox.getSelectedItem(); }//GEN-LAST:event_hashSetsComboBoxActionPerformed private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deselectAllButtonActionPerformed @@ -311,7 +311,7 @@ class AddTaggedHashesToHashDbConfigPanel extends javax.swing.JPanel { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton configureHashDatabasesButton; private javax.swing.JButton deselectAllButton; - private javax.swing.JComboBox hashSetsComboBox; + private javax.swing.JComboBox hashSetsComboBox; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JScrollPane jScrollPane1; diff --git a/Experimental/src/org/sleuthkit/autopsy/experimental/configuration/SharedConfiguration.java b/Experimental/src/org/sleuthkit/autopsy/experimental/configuration/SharedConfiguration.java index ccb2e49e54..e3f6a23bf5 100755 --- a/Experimental/src/org/sleuthkit/autopsy/experimental/configuration/SharedConfiguration.java +++ b/Experimental/src/org/sleuthkit/autopsy/experimental/configuration/SharedConfiguration.java @@ -47,7 +47,7 @@ import org.sleuthkit.autopsy.keywordsearch.KeywordListsManager; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager; import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.autopsy.core.ServicesMonitor; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; import org.sleuthkit.autopsy.experimental.configuration.AutoIngestSettingsPanel.UpdateConfigSwingWorker; import org.sleuthkit.autopsy.coordinationservice.CoordinationService; import org.sleuthkit.autopsy.coordinationservice.CoordinationService.CategoryNode; @@ -1017,15 +1017,17 @@ public class SharedConfiguration { // If a copy of the database is loaded, close it before deleting and copying. if (localDb.exists()) { List hashDbs = HashDbManager.getInstance().getAllHashSets(); - HashDbManager.HashDb matchingDb = null; + HashDbManager.HashDatabase matchingDb = null; for (HashDbManager.HashDb db : hashDbs) { - try { - if (localDb.getAbsolutePath().equals(db.getDatabasePath()) || localDb.getAbsolutePath().equals(db.getIndexPath())) { - matchingDb = db; - break; + if(db instanceof HashDbManager.HashDatabase){ + try { + if (localDb.getAbsolutePath().equals(db.getDatabasePath()) || localDb.getAbsolutePath().equals(db.getIndexPath())) { + matchingDb = (HashDbManager.HashDatabase)db; + break; + } + } catch (TskCoreException ex) { + throw new SharedConfigurationException(String.format("Error getting hash database path info for %s", localDb.getParentFile().getAbsolutePath()), ex); } - } catch (TskCoreException ex) { - throw new SharedConfigurationException(String.format("Error getting hash database path info for %s", localDb.getParentFile().getAbsolutePath()), ex); } } @@ -1122,11 +1124,13 @@ public class SharedConfiguration { try { HashDbManager hashDbManager = HashDbManager.getInstance(); hashDbManager.loadLastSavedConfiguration(); - for (HashDb hashDb : hashDbManager.getAllHashSets()) { - if (hashDb.hasIndexOnly()) { - results.add(hashDb.getIndexPath()); - } else { - results.add(hashDb.getDatabasePath()); + for (HashDbManager.HashDb hashDb : hashDbManager.getAllHashSets()) { + if(hashDb instanceof HashDatabase){ + if (hashDb.hasIndexOnly()) { + results.add(hashDb.getIndexPath()); + } else { + results.add(hashDb.getDatabasePath()); + } } } } catch (TskCoreException ex) { From f00ceeea273df66fce95d66bd61e00a118d8577e Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Mon, 13 Nov 2017 14:03:29 -0500 Subject: [PATCH 32/41] Cleanup --- .../autopsy/modules/hashdatabase/AddContentToHashDbAction.java | 2 +- .../modules/hashdatabase/AddHashValuesToDatabaseDialog.java | 2 +- .../hashdatabase/AddHashValuesToDatabaseProgressDialog.java | 2 +- .../modules/hashdatabase/HashDbCreateDatabaseDialog.java | 2 +- .../autopsy/modules/hashdatabase/HashDbIngestModule.java | 2 +- .../autopsy/report/taggedhashes/AddTaggedHashesToHashDb.java | 2 +- .../report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.java | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddContentToHashDbAction.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddContentToHashDbAction.java index effa123af9..5ec70ce3b9 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddContentToHashDbAction.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddContentToHashDbAction.java @@ -32,10 +32,10 @@ import org.openide.util.Utilities; import org.openide.util.actions.Presenter; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.ingest.IngestManager; +import static org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.HashUtility; import org.sleuthkit.datamodel.TskCoreException; -import static org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; /** * Instances of this Action allow users to content to a hash database. diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseDialog.java index 1fe05701ce..40db15718f 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseDialog.java @@ -31,8 +31,8 @@ import javax.swing.JPopupMenu; import javax.swing.SwingUtilities; import org.openide.util.NbBundle; import org.openide.windows.WindowManager; -import org.sleuthkit.datamodel.HashEntry; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; +import org.sleuthkit.datamodel.HashEntry; /** * diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseProgressDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseProgressDialog.java index 3f3671c44f..f712a965fd 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseProgressDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/AddHashValuesToDatabaseProgressDialog.java @@ -31,9 +31,9 @@ import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.SwingWorker; import org.openide.util.NbBundle; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; import org.sleuthkit.datamodel.HashEntry; import org.sleuthkit.datamodel.TskCoreException; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; /** * diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java index a794ada72d..d07f5a034c 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbCreateDatabaseDialog.java @@ -33,9 +33,9 @@ import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.PlatformUtil; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb.KnownFilesType; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDbManagerException; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; /** * Instances of this class allow a user to create a new hash database and add it diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java index 75f477b585..40cd2230b3 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbIngestModule.java @@ -36,6 +36,7 @@ import org.sleuthkit.autopsy.ingest.IngestMessage; import org.sleuthkit.autopsy.ingest.IngestModuleReferenceCounter; import org.sleuthkit.autopsy.ingest.IngestServices; import org.sleuthkit.autopsy.ingest.ModuleDataEvent; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE; @@ -47,7 +48,6 @@ import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskData; import org.sleuthkit.datamodel.TskException; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; @NbBundle.Messages({ "HashDbIngestModule.noKnownBadHashDbSetMsg=No notable hash database set.", diff --git a/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDb.java b/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDb.java index e2c90b005c..1de1db7eaa 100755 --- a/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDb.java +++ b/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDb.java @@ -27,6 +27,7 @@ import javax.swing.JPanel; import org.openide.util.lookup.ServiceProvider; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.services.TagsManager; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; import org.sleuthkit.autopsy.report.GeneralReportModule; import org.sleuthkit.autopsy.report.ReportProgressPanel; import org.sleuthkit.datamodel.AbstractFile; @@ -34,7 +35,6 @@ import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; /** * Instances of this class plug in to the reporting infrastructure to provide a diff --git a/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.java b/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.java index 0c20eee562..4dd665b890 100644 --- a/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.java +++ b/Core/src/org/sleuthkit/autopsy/report/taggedhashes/AddTaggedHashesToHashDbConfigPanel.java @@ -35,11 +35,11 @@ import javax.swing.ListModel; import javax.swing.event.ListDataListener; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager; import org.sleuthkit.autopsy.modules.hashdatabase.HashLookupSettingsPanel; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; /** * Instances of this class are used to configure the report module plug in that From 0ea88c0f68213b8ff96544cf764b974e5fec9fc2 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Mon, 13 Nov 2017 14:24:50 -0500 Subject: [PATCH 33/41] Cleanup --- .../modules/hashdatabase/HashDbManager.java | 42 +++++++------------ .../hashdatabase/HashLookupSettingsPanel.java | 15 ++++--- 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index 59dcd998e0..a764065b6b 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -147,15 +147,15 @@ public class HashDbManager implements PropertyChangeListener { * * @throws HashDbManagerException */ - public synchronized HashDatabase addExistingHashDatabase(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDatabase.KnownFilesType knownFilesType) throws HashDbManagerException { - HashDatabase hashDb = null; + public synchronized HashDb addExistingHashDatabase(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDatabase.KnownFilesType knownFilesType) throws HashDbManagerException { + HashDb hashDb = null; hashDb = this.addExistingHashDatabaseNoSave(hashSetName, path, searchDuringIngest, sendIngestMessages, knownFilesType); this.save(); return hashDb; } - synchronized HashDatabase addExistingHashDatabaseNoSave(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDatabase.KnownFilesType knownFilesType) throws HashDbManagerException { - HashDatabase hashDb = null; + synchronized HashDb addExistingHashDatabaseNoSave(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDatabase.KnownFilesType knownFilesType) throws HashDbManagerException { + HashDb hashDb = null; try { if (!new File(path).exists()) { throw new HashDbManagerException(NbBundle.getMessage(HashDbManager.class, "HashDbManager.hashDbDoesNotExistExceptionMsg", path)); @@ -169,7 +169,7 @@ public class HashDbManager implements PropertyChangeListener { throw new HashDbManagerException(NbBundle.getMessage(HashDbManager.class, "HashDbManager.duplicateHashSetNameExceptionMsg", hashSetName)); } - hashDb = addFileHashDatabase(SleuthkitJNI.openHashDatabase(path), hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType); + hashDb = addHashDatabase(SleuthkitJNI.openHashDatabase(path), hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType); } catch (TskCoreException ex) { throw new HashDbManagerException(ex.getMessage()); } @@ -194,10 +194,10 @@ public class HashDbManager implements PropertyChangeListener { * * @throws HashDbManagerException */ - public synchronized HashDatabase addNewHashDatabase(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, - HashDatabase.KnownFilesType knownFilesType) throws HashDbManagerException { + public synchronized HashDb addNewHashDatabase(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, + HashDb.KnownFilesType knownFilesType) throws HashDbManagerException { - HashDatabase hashDb = null; + HashDb hashDb = null; hashDb = this.addNewHashDatabaseNoSave(hashSetName, path, searchDuringIngest, sendIngestMessages, knownFilesType); this.save(); @@ -205,9 +205,9 @@ public class HashDbManager implements PropertyChangeListener { return hashDb; } - public synchronized HashDatabase addNewHashDatabaseNoSave(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, - HashDatabase.KnownFilesType knownFilesType) throws HashDbManagerException { - HashDatabase hashDb = null; + public synchronized HashDb addNewHashDatabaseNoSave(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, + HashDb.KnownFilesType knownFilesType) throws HashDbManagerException { + HashDb hashDb = null; try { File file = new File(path); if (file.exists()) { @@ -226,14 +226,14 @@ public class HashDbManager implements PropertyChangeListener { throw new HashDbManagerException(NbBundle.getMessage(HashDbManager.class, "HashDbManager.duplicateHashSetNameExceptionMsg", hashSetName)); } - hashDb = addFileHashDatabase(SleuthkitJNI.createHashDatabase(path), hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType); + hashDb = addHashDatabase(SleuthkitJNI.createHashDatabase(path), hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType); } catch (TskCoreException ex) { throw new HashDbManagerException(ex.getMessage()); } return hashDb; } - private HashDatabase addFileHashDatabase(int handle, String hashSetName, boolean searchDuringIngest, boolean sendIngestMessages, HashDatabase.KnownFilesType knownFilesType) throws TskCoreException { + private HashDatabase addHashDatabase(int handle, String hashSetName, boolean searchDuringIngest, boolean sendIngestMessages, HashDatabase.KnownFilesType knownFilesType) throws TskCoreException { // Wrap an object around the handle. HashDatabase hashDb = new HashDatabase(handle, hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType); @@ -400,20 +400,6 @@ public class HashDbManager implements PropertyChangeListener { } } - /** - * Gets all of the file hash databases used to classify files as known or known - * bad. - * - * @return A list, possibly empty, of hash databases. - */ - synchronized List getAllFileHashSets() { - List hashDbs = new ArrayList<>(); - this.hashSets.stream().filter((thisSet) -> (thisSet instanceof HashDatabase)).forEach((thisSet) -> { - hashDbs.add((HashDatabase)thisSet); - }); - return hashDbs; - } - /** * Gets all of the hash databases used to classify files as known or known * bad. Will add any new central repository databases to the list before @@ -551,7 +537,7 @@ public class HashDbManager implements PropertyChangeListener { if(hashDbInfo.isFileDatabaseType()){ String dbPath = this.getValidFilePath(hashDbInfo.getHashSetName(), hashDbInfo.getPath()); if (dbPath != null) { - addFileHashDatabase(SleuthkitJNI.openHashDatabase(dbPath), hashDbInfo.getHashSetName(), hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), hashDbInfo.getKnownFilesType()); + addHashDatabase(SleuthkitJNI.openHashDatabase(dbPath), hashDbInfo.getHashSetName(), hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), hashDbInfo.getKnownFilesType()); } else { logger.log(Level.WARNING, Bundle.HashDbManager_noDbPath_message(hashDbInfo.getHashSetName())); allDatabasesLoadedCorrectly = false; diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java index ef8986af24..f765fcbd4b 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java @@ -305,13 +305,16 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan public void saveSettings() { //Checking for for any unindexed databases List unindexed = new ArrayList<>(); - for (HashDatabase db : hashSetManager.getAllFileHashSets()) { - try { - if (!db.hasIndex()) { - unindexed.add(db); + for (HashDb db : hashSetManager.getAllHashSets()) { + if(db instanceof HashDatabase){ + try { + HashDatabase hashDatabase = (HashDatabase)db; + if (!hashDatabase.hasIndex()) { + unindexed.add(hashDatabase); + } + } catch (TskCoreException ex) { + Logger.getLogger(HashLookupSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting index info for hash database", ex); //NON-NLS } - } catch (TskCoreException ex) { - Logger.getLogger(HashLookupSettingsPanel.class.getName()).log(Level.SEVERE, "Error getting index info for hash database", ex); //NON-NLS } } From fed52680a97ec4e4b9a43bf93e7e3f5808344b91 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Mon, 13 Nov 2017 14:28:04 -0500 Subject: [PATCH 34/41] Cleanup --- .../autopsy/modules/hashdatabase/HashDbManager.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index a764065b6b..412fb6410e 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -147,14 +147,14 @@ public class HashDbManager implements PropertyChangeListener { * * @throws HashDbManagerException */ - public synchronized HashDb addExistingHashDatabase(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDatabase.KnownFilesType knownFilesType) throws HashDbManagerException { + public synchronized HashDb addExistingHashDatabase(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws HashDbManagerException { HashDb hashDb = null; hashDb = this.addExistingHashDatabaseNoSave(hashSetName, path, searchDuringIngest, sendIngestMessages, knownFilesType); this.save(); return hashDb; } - synchronized HashDb addExistingHashDatabaseNoSave(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDatabase.KnownFilesType knownFilesType) throws HashDbManagerException { + synchronized HashDb addExistingHashDatabaseNoSave(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws HashDbManagerException { HashDb hashDb = null; try { if (!new File(path).exists()) { @@ -407,7 +407,7 @@ public class HashDbManager implements PropertyChangeListener { * * @return A list, possibly empty, of hash databases. */ - public synchronized List getAllHashSets(){ + public synchronized List getAllHashSets() { try{ updateHashSetsFromCentralRepository(); } catch (TskCoreException ex){ From 2bb24e3d4de52068525f1a544fe070dabd82044e Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Tue, 14 Nov 2017 11:32:19 -0500 Subject: [PATCH 35/41] Remove/change some public methods. --- .../datamodel/EamGlobalSet.java | 6 +-- .../modules/hashdatabase/HashDbManager.java | 48 +++++-------------- .../hashdatabase/HashLookupSettings.java | 32 +++++++------ 3 files changed, 31 insertions(+), 55 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalSet.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalSet.java index 80e7d9cb8b..e4292dc6ca 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalSet.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalSet.java @@ -150,11 +150,11 @@ public class EamGlobalSet { * Return the FileKnown status as a KnownFilesType * @return KNOWN or KNOWN_BAD */ - public HashDbManager.HashDatabase.KnownFilesType getKnownStatus(){ + public HashDbManager.HashDb.KnownFilesType getKnownStatus(){ if(fileKnownStatus.equals(TskData.FileKnown.BAD)){ - return HashDbManager.HashDatabase.KnownFilesType.KNOWN_BAD; + return HashDbManager.HashDb.KnownFilesType.KNOWN_BAD; } - return HashDbManager.HashDatabase.KnownFilesType.KNOWN; + return HashDbManager.HashDb.KnownFilesType.KNOWN; } /** diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index 412fb6410e..e656606c52 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -692,11 +692,6 @@ public class HashDbManager implements PropertyChangeListener { INDEXING_DONE } - enum DatabaseType{ - FILE, - CENTRAL_REPOSITORY - }; - public String getHashSetName(); public String getDisplayName(); @@ -709,11 +704,11 @@ public class HashDbManager implements PropertyChangeListener { public boolean getDefaultSearchDuringIngest(); - void setSearchDuringIngest(boolean useForIngest); + public void setSearchDuringIngest(boolean useForIngest); public boolean getSendIngestMessages(); - void setSendIngestMessages(boolean showInboxMessages); + public void setSendIngestMessages(boolean showInboxMessages); /** * Indicates whether the hash database accepts updates. @@ -750,8 +745,6 @@ public class HashDbManager implements PropertyChangeListener { */ public boolean isValid() throws TskCoreException; - public int getHandle(); - public String getIndexPath() throws TskCoreException; public boolean hasIndexOnly() throws TskCoreException; @@ -762,14 +755,11 @@ public class HashDbManager implements PropertyChangeListener { public void removePropertyChangeListener(PropertyChangeListener pcl); - void close() throws TskCoreException; + public void close() throws TskCoreException; @Override public String toString(); - DatabaseType getDatabaseType(); - - } /** @@ -817,8 +807,7 @@ public class HashDbManager implements PropertyChangeListener { propertyChangeSupport.removePropertyChangeListener(pcl); } - @Override - public int getHandle(){ + int getHandle(){ return handle; } @@ -840,12 +829,8 @@ public class HashDbManager implements PropertyChangeListener { public void setIndexing(boolean indexing){ this.indexing = indexing; } - - @Override - public DatabaseType getDatabaseType(){ - return DatabaseType.FILE; - } + @Override public String getIndexPath() throws TskCoreException { return SleuthkitJNI.getHashDatabaseIndexPath(handle); } @@ -996,7 +981,7 @@ public class HashDbManager implements PropertyChangeListener { return hasIndex(); } - public boolean hasIndex() throws TskCoreException { + boolean hasIndex() throws TskCoreException { return SleuthkitJNI.hashDatabaseHasLookupIndex(handle); } @@ -1005,11 +990,11 @@ public class HashDbManager implements PropertyChangeListener { return SleuthkitJNI.hashDatabaseIsIndexOnly(handle); } - public boolean canBeReIndexed() throws TskCoreException { + boolean canBeReIndexed() throws TskCoreException { return SleuthkitJNI.hashDatabaseCanBeReindexed(handle); } - public boolean isIndexing() { + boolean isIndexing() { return indexing; } @@ -1117,11 +1102,6 @@ public class HashDbManager implements PropertyChangeListener { propertyChangeSupport.removePropertyChangeListener(pcl); } - @Override - public int getHandle(){ - return 0; - } - @Override public boolean hasIndexOnly() throws TskCoreException{ return true; @@ -1137,15 +1117,15 @@ public class HashDbManager implements PropertyChangeListener { return getHashSetName() + " " + getVersion(); } - public String getVersion(){ + String getVersion(){ return version; } - public String getOrgName(){ + String getOrgName(){ return orgName; } - public int getReferenceSetID(){ + int getReferenceSetID(){ return referenceSetID; } @@ -1153,11 +1133,6 @@ public class HashDbManager implements PropertyChangeListener { public String getDatabasePath() throws TskCoreException { return ""; } - - @Override - public DatabaseType getDatabaseType(){ - return DatabaseType.CENTRAL_REPOSITORY; - } @Override public String getIndexPath() throws TskCoreException { @@ -1311,7 +1286,6 @@ public class HashDbManager implements PropertyChangeListener { * Returns whether this database can be enabled. * * @return true if is valid, false otherwise - * @throws TskCoreException */ @Override public boolean isValid() { diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java index 5dda017e54..fecc5ad192 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java @@ -36,8 +36,8 @@ import org.sleuthkit.autopsy.core.RuntimeProperties; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.PlatformUtil; import org.sleuthkit.autopsy.coreutils.XMLUtil; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb.DatabaseType; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.CentralRepoHashDb; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; import org.sleuthkit.datamodel.TskCoreException; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -297,6 +297,11 @@ final class HashLookupSettings implements Serializable { */ static final class HashDbInfo implements Serializable { + enum DatabaseType{ + FILE, + CENTRAL_REPOSITORY + }; + private static final long serialVersionUID = 1L; private final String hashSetName; private final HashDbManager.HashDatabase.KnownFilesType knownFilesType; @@ -466,7 +471,8 @@ final class HashLookupSettings implements Serializable { return false; } - if( ! this.dbType.equals(hashDb.getDatabaseType())){ + if((this.dbType == DatabaseType.CENTRAL_REPOSITORY) && (! (hashDb instanceof CentralRepoHashDb)) + || (this.dbType == DatabaseType.FILE) && (! (hashDb instanceof HashDatabase))){ return false; } @@ -474,19 +480,15 @@ final class HashLookupSettings implements Serializable { return false; } - if(this.dbType.equals(DatabaseType.FILE)){ - // FILE types will always have unique names, so no more testing required - return true; - } - - // Central repo tests - CentralRepoHashDb crDb = (CentralRepoHashDb) hashDb; - if(this.referenceSetID != crDb.getReferenceSetID()){ - return false; - } - - if(! version.equals(crDb.getVersion())){ - return false; + if(hashDb instanceof CentralRepoHashDb){ + CentralRepoHashDb crDb = (CentralRepoHashDb) hashDb; + if(this.referenceSetID != crDb.getReferenceSetID()){ + return false; + } + + if(! version.equals(crDb.getVersion())){ + return false; + } } return true; From 8a63c5aa154b947d400e84b6ccd8792b0b13141b Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Tue, 14 Nov 2017 15:04:30 -0500 Subject: [PATCH 36/41] Change HashDb interface to an abstract class. Rename SleuthkitHashSet and CentralRepoHashSet --- .../modules/hashdatabase/HashDbManager.java | 158 +++++++++--------- .../hashdatabase/HashLookupSettings.java | 30 ++-- .../hashdatabase/HashLookupSettingsPanel.java | 32 ++-- .../ImportCentralRepoDbProgressDialog.java | 10 +- .../modules/hashdatabase/ModalNoButtons.java | 16 +- .../configuration/SharedConfiguration.java | 28 ++-- 6 files changed, 132 insertions(+), 142 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index e656606c52..4f68120f6a 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -233,9 +233,9 @@ public class HashDbManager implements PropertyChangeListener { return hashDb; } - private HashDatabase addHashDatabase(int handle, String hashSetName, boolean searchDuringIngest, boolean sendIngestMessages, HashDatabase.KnownFilesType knownFilesType) throws TskCoreException { + private SleuthkitHashSet addHashDatabase(int handle, String hashSetName, boolean searchDuringIngest, boolean sendIngestMessages, SleuthkitHashSet.KnownFilesType knownFilesType) throws TskCoreException { // Wrap an object around the handle. - HashDatabase hashDb = new HashDatabase(handle, hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType); + SleuthkitHashSet hashDb = new SleuthkitHashSet(handle, hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType); // Get the indentity data before updating the collections since the // accessor methods may throw. @@ -268,7 +268,7 @@ public class HashDbManager implements PropertyChangeListener { return hashDb; } - CentralRepoHashDb addExistingCentralRepoHashSet(String hashSetName, String version, int referenceSetID, + CentralRepoHashSet addExistingCentralRepoHashSet(String hashSetName, String version, int referenceSetID, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType, boolean readOnly) throws TskCoreException{ @@ -276,7 +276,7 @@ public class HashDbManager implements PropertyChangeListener { throw new TskCoreException("Could not load central repository database " + hashSetName + " - central repository is not enabled"); } - CentralRepoHashDb db = new CentralRepoHashDb(hashSetName, version, referenceSetID, searchDuringIngest, + CentralRepoHashSet db = new CentralRepoHashSet(hashSetName, version, referenceSetID, searchDuringIngest, sendIngestMessages, knownFilesType, readOnly); if(! db.isValid()){ @@ -300,7 +300,7 @@ public class HashDbManager implements PropertyChangeListener { } - synchronized void indexHashDatabase(HashDatabase hashDb) { + synchronized void indexHashDatabase(SleuthkitHashSet hashDb) { hashDb.addPropertyChangeListener(this); HashDbIndexer creator = new HashDbIndexer(hashDb); creator.execute(); @@ -308,8 +308,8 @@ public class HashDbManager implements PropertyChangeListener { @Override public void propertyChange(PropertyChangeEvent event) { - if (event.getPropertyName().equals(HashDatabase.Event.INDEXING_DONE.name())) { - HashDatabase hashDb = (HashDatabase) event.getNewValue(); + if (event.getPropertyName().equals(SleuthkitHashSet.Event.INDEXING_DONE.name())) { + SleuthkitHashSet hashDb = (SleuthkitHashSet) event.getNewValue(); if (null != hashDb) { try { String indexPath = hashDb.getIndexPath(); @@ -352,9 +352,9 @@ public class HashDbManager implements PropertyChangeListener { // Now undertake the operations that could throw. - // Indexing is only relevanet for file type hashsets - if(hashDb instanceof HashDatabase){ - HashDatabase hashDatabase = (HashDatabase)hashDb; + // Indexing is only relevanet for sleuthkit hashsets + if(hashDb instanceof SleuthkitHashSet){ + SleuthkitHashSet hashDatabase = (SleuthkitHashSet)hashDb; try { if(hashDatabase.hasIndex()){ hashSetPaths.remove(hashDatabase.getIndexPath()); @@ -370,12 +370,12 @@ public class HashDbManager implements PropertyChangeListener { } catch (TskCoreException ex) { Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error getting database path of " + hashDatabase.getHashSetName() + " hash database when removing the database", ex); //NON-NLS } - } - try { - hashDb.close(); - } catch (TskCoreException ex) { - Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error closing " + hashDb.getHashSetName() + " hash database when removing the database", ex); //NON-NLS + try { + hashDatabase.close(); + } catch (TskCoreException ex) { + Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error closing " + hashDb.getHashSetName() + " hash database when removing the database", ex); //NON-NLS + } } // Let any external listeners know that a set has been deleted @@ -426,7 +426,7 @@ public class HashDbManager implements PropertyChangeListener { */ public synchronized List getKnownFileHashSets() { List hashDbs = new ArrayList<>(); - this.hashSets.stream().filter((db) -> (db.getKnownFilesType() == HashDatabase.KnownFilesType.KNOWN)).forEach((db) -> { + this.hashSets.stream().filter((db) -> (db.getKnownFilesType() == SleuthkitHashSet.KnownFilesType.KNOWN)).forEach((db) -> { hashDbs.add(db); }); return hashDbs; @@ -439,7 +439,7 @@ public class HashDbManager implements PropertyChangeListener { */ public synchronized List getKnownBadFileHashSets() { List hashDbs = new ArrayList<>(); - this.hashSets.stream().filter((db) -> (db.getKnownFilesType() == HashDatabase.KnownFilesType.KNOWN_BAD)).forEach((db) -> { + this.hashSets.stream().filter((db) -> (db.getKnownFilesType() == SleuthkitHashSet.KnownFilesType.KNOWN_BAD)).forEach((db) -> { hashDbs.add(db); }); return hashDbs; @@ -478,7 +478,7 @@ public class HashDbManager implements PropertyChangeListener { // Defaults for fields not stored in the central repository: // searchDuringIngest: false // sendIngestMessages: true if the hash set is notable - boolean sendIngestMessages = globalSet.getKnownStatus().equals(HashDatabase.KnownFilesType.KNOWN_BAD); + boolean sendIngestMessages = globalSet.getKnownStatus().equals(SleuthkitHashSet.KnownFilesType.KNOWN_BAD); crHashSets.add(new HashDbInfo(globalSet.getSetName(), globalSet.getVersion(), globalSet.getGlobalSetID(), globalSet.getKnownStatus(), globalSet.isReadOnly(), false, sendIngestMessages)); } @@ -503,10 +503,12 @@ public class HashDbManager implements PropertyChangeListener { private void closeHashDatabases(List hashDatabases) { for (HashDb database : hashDatabases) { - try { - database.close(); - } catch (TskCoreException ex) { - Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error closing " + database.getHashSetName() + " hash database", ex); //NON-NLS + if(database instanceof SleuthkitHashSet){ + try { + ((SleuthkitHashSet)database).close(); + } catch (TskCoreException ex) { + Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error closing " + database.getHashSetName() + " hash database", ex); //NON-NLS + } } } hashDatabases.clear(); @@ -663,7 +665,7 @@ public class HashDbManager implements PropertyChangeListener { return filePath; } - public static interface HashDb { + public static abstract class HashDb { /** * Indicates how files with hashes stored in a particular hash database @@ -692,23 +694,23 @@ public class HashDbManager implements PropertyChangeListener { INDEXING_DONE } - public String getHashSetName(); + public abstract String getHashSetName(); - public String getDisplayName(); + abstract String getDisplayName(); - public String getDatabasePath() throws TskCoreException; + public abstract String getDatabasePath() throws TskCoreException; - public HashDatabase.KnownFilesType getKnownFilesType(); + public abstract SleuthkitHashSet.KnownFilesType getKnownFilesType(); - public boolean getSearchDuringIngest(); + public abstract boolean getSearchDuringIngest(); - public boolean getDefaultSearchDuringIngest(); + abstract boolean getDefaultSearchDuringIngest(); - public void setSearchDuringIngest(boolean useForIngest); + abstract void setSearchDuringIngest(boolean useForIngest); - public boolean getSendIngestMessages(); + public abstract boolean getSendIngestMessages(); - public void setSendIngestMessages(boolean showInboxMessages); + abstract void setSendIngestMessages(boolean showInboxMessages); /** * Indicates whether the hash database accepts updates. @@ -717,7 +719,7 @@ public class HashDbManager implements PropertyChangeListener { * * @throws org.sleuthkit.datamodel.TskCoreException */ - public boolean isUpdateable() throws TskCoreException; + public abstract boolean isUpdateable() throws TskCoreException; /** * Adds hashes of content (if calculated) to the hash database. @@ -727,15 +729,15 @@ public class HashDbManager implements PropertyChangeListener { * * @throws TskCoreException */ - public void addHashes(Content content) throws TskCoreException; + public abstract void addHashes(Content content) throws TskCoreException; - public void addHashes(Content content, String comment) throws TskCoreException; + public abstract void addHashes(Content content, String comment) throws TskCoreException; - public void addHashes(List hashes) throws TskCoreException; + public abstract void addHashes(List hashes) throws TskCoreException; - public boolean lookupMD5Quick(Content content) throws TskCoreException; + public abstract boolean lookupMD5Quick(Content content) throws TskCoreException; - public HashHitInfo lookupMD5(Content content) throws TskCoreException; + public abstract HashHitInfo lookupMD5(Content content) throws TskCoreException; /** * Returns whether this database can be enabled. @@ -743,22 +745,20 @@ public class HashDbManager implements PropertyChangeListener { * @return true if is valid, false otherwise * @throws TskCoreException */ - public boolean isValid() throws TskCoreException; + abstract boolean isValid() throws TskCoreException; - public String getIndexPath() throws TskCoreException; + public abstract String getIndexPath() throws TskCoreException; - public boolean hasIndexOnly() throws TskCoreException; + public abstract boolean hasIndexOnly() throws TskCoreException; - public void firePropertyChange(String propertyName, Object oldValue, Object newValue); + public abstract void firePropertyChange(String propertyName, Object oldValue, Object newValue); - public void addPropertyChangeListener(PropertyChangeListener pcl); + public abstract void addPropertyChangeListener(PropertyChangeListener pcl); - public void removePropertyChangeListener(PropertyChangeListener pcl); - - public void close() throws TskCoreException; + public abstract void removePropertyChangeListener(PropertyChangeListener pcl); @Override - public String toString(); + public abstract String toString(); } @@ -766,18 +766,18 @@ public class HashDbManager implements PropertyChangeListener { * Instances of this class represent hash databases used to classify files * as known or know bad. */ - public static class HashDatabase implements HashDb{ + class SleuthkitHashSet extends HashDb{ private static final long serialVersionUID = 1L; private final int handle; private final String hashSetName; private boolean searchDuringIngest; private boolean sendIngestMessages; - private final HashDatabase.KnownFilesType knownFilesType; + private final SleuthkitHashSet.KnownFilesType knownFilesType; private boolean indexing; private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); - private HashDatabase(int handle, String hashSetName, boolean useForIngest, boolean sendHitMessages, KnownFilesType knownFilesType) { + private SleuthkitHashSet(int handle, String hashSetName, boolean useForIngest, boolean sendHitMessages, KnownFilesType knownFilesType) { this.handle = handle; this.hashSetName = hashSetName; this.searchDuringIngest = useForIngest; @@ -817,7 +817,7 @@ public class HashDbManager implements PropertyChangeListener { } @Override - public String getDisplayName(){ + String getDisplayName(){ return getHashSetName(); } @@ -846,13 +846,13 @@ public class HashDbManager implements PropertyChangeListener { } @Override - public boolean getDefaultSearchDuringIngest(){ + boolean getDefaultSearchDuringIngest(){ // File type hash sets are on by default return true; } @Override - public void setSearchDuringIngest(boolean useForIngest) { + void setSearchDuringIngest(boolean useForIngest) { this.searchDuringIngest = useForIngest; } @@ -862,7 +862,7 @@ public class HashDbManager implements PropertyChangeListener { } @Override - public void setSendIngestMessages(boolean showInboxMessages) { + void setSendIngestMessages(boolean showInboxMessages) { this.sendIngestMessages = showInboxMessages; } @@ -977,7 +977,7 @@ public class HashDbManager implements PropertyChangeListener { * @throws TskCoreException */ @Override - public boolean isValid() throws TskCoreException { + boolean isValid() throws TskCoreException { return hasIndex(); } @@ -1003,8 +1003,7 @@ public class HashDbManager implements PropertyChangeListener { this.propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue); } - @Override - public void close() throws TskCoreException { + private void close() throws TskCoreException { SleuthkitJNI.closeHashDatabase(handle); } @@ -1032,7 +1031,7 @@ public class HashDbManager implements PropertyChangeListener { if (getClass() != obj.getClass()) { return false; } - final HashDatabase other = (HashDatabase) obj; + final SleuthkitHashSet other = (SleuthkitHashSet) obj; if (!Objects.equals(this.hashSetName, other.hashSetName)) { return false; } @@ -1047,13 +1046,13 @@ public class HashDbManager implements PropertyChangeListener { * Instances of this class represent hash databases used to classify files * as known or know bad. */ - public static class CentralRepoHashDb implements HashDb{ + class CentralRepoHashSet extends HashDb{ private static final long serialVersionUID = 1L; private final String hashSetName; private boolean searchDuringIngest; private boolean sendIngestMessages; - private final HashDatabase.KnownFilesType knownFilesType; + private final SleuthkitHashSet.KnownFilesType knownFilesType; private final int referenceSetID; private final String version; private String orgName; @@ -1061,8 +1060,8 @@ public class HashDbManager implements PropertyChangeListener { private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); @Messages({"HashDbManager.CentralRepoHashDb.orgError=Error loading organization"}) - private CentralRepoHashDb(String hashSetName, String version, int referenceSetID, - boolean useForIngest, boolean sendHitMessages, HashDatabase.KnownFilesType knownFilesType, + private CentralRepoHashSet(String hashSetName, String version, int referenceSetID, + boolean useForIngest, boolean sendHitMessages, SleuthkitHashSet.KnownFilesType knownFilesType, boolean readOnly) throws TskCoreException{ this.hashSetName = hashSetName; @@ -1076,7 +1075,7 @@ public class HashDbManager implements PropertyChangeListener { try{ orgName = EamDb.getInstance().getReferenceSetOrganization(referenceSetID).getName(); } catch (EamDbException ex){ - Logger.getLogger(HashDatabase.class.getName()).log(Level.SEVERE, "Error looking up central repository organization", ex); //NON-NLS + Logger.getLogger(SleuthkitHashSet.class.getName()).log(Level.SEVERE, "Error looking up central repository organization", ex); //NON-NLS orgName = Bundle.HashDbManager_CentralRepoHashDb_orgError(); } } @@ -1113,7 +1112,7 @@ public class HashDbManager implements PropertyChangeListener { } @Override - public String getDisplayName(){ + String getDisplayName(){ return getHashSetName() + " " + getVersion(); } @@ -1140,7 +1139,7 @@ public class HashDbManager implements PropertyChangeListener { } @Override - public HashDatabase.KnownFilesType getKnownFilesType() { + public SleuthkitHashSet.KnownFilesType getKnownFilesType() { return knownFilesType; } @@ -1150,13 +1149,13 @@ public class HashDbManager implements PropertyChangeListener { } @Override - public boolean getDefaultSearchDuringIngest(){ + boolean getDefaultSearchDuringIngest(){ // Central repo hash sets are off by default return false; } @Override - public void setSearchDuringIngest(boolean useForIngest) { + void setSearchDuringIngest(boolean useForIngest) { this.searchDuringIngest = useForIngest; } @@ -1166,7 +1165,7 @@ public class HashDbManager implements PropertyChangeListener { } @Override - public void setSendIngestMessages(boolean showInboxMessages) { + void setSendIngestMessages(boolean showInboxMessages) { this.sendIngestMessages = showInboxMessages; } @@ -1243,7 +1242,7 @@ public class HashDbManager implements PropertyChangeListener { try{ return EamDb.getInstance().isHashInReferenceSet(file.getMd5Hash(), this.referenceSetID); } catch (EamDbException ex){ - Logger.getLogger(HashDatabase.class.getName()).log(Level.SEVERE, "Error performing central reposiotry hash lookup", ex); //NON-NLS + Logger.getLogger(SleuthkitHashSet.class.getName()).log(Level.SEVERE, "Error performing central reposiotry hash lookup", ex); //NON-NLS throw new TskCoreException("Error performing central reposiotry hash lookup", ex); } } @@ -1274,7 +1273,7 @@ public class HashDbManager implements PropertyChangeListener { result = new HashHitInfo(file.getMd5Hash(), "", ""); } } catch (EamDbException ex){ - Logger.getLogger(HashDatabase.class.getName()).log(Level.SEVERE, "Error performing central reposiotry hash lookup", ex); //NON-NLS + Logger.getLogger(SleuthkitHashSet.class.getName()).log(Level.SEVERE, "Error performing central reposiotry hash lookup", ex); //NON-NLS throw new TskCoreException("Error performing central reposiotry hash lookup", ex); } } @@ -1288,14 +1287,14 @@ public class HashDbManager implements PropertyChangeListener { * @return true if is valid, false otherwise */ @Override - public boolean isValid() { + boolean isValid() { if(! EamDb.isEnabled()) { return false; } try{ return EamDb.getInstance().referenceSetIsValid(this.referenceSetID, this.hashSetName, this.version); } catch (EamDbException ex){ - Logger.getLogger(CentralRepoHashDb.class.getName()).log(Level.SEVERE, "Error validating hash database " + hashSetName, ex); //NON-NLS + Logger.getLogger(CentralRepoHashSet.class.getName()).log(Level.SEVERE, "Error validating hash database " + hashSetName, ex); //NON-NLS return false; } } @@ -1304,11 +1303,6 @@ public class HashDbManager implements PropertyChangeListener { public void firePropertyChange(String propertyName, Object oldValue, Object newValue){ this.propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue); } - - @Override - public void close() throws TskCoreException { - - } @Override public String toString(){ @@ -1334,7 +1328,7 @@ public class HashDbManager implements PropertyChangeListener { if (getClass() != obj.getClass()) { return false; } - final CentralRepoHashDb other = (CentralRepoHashDb) obj; + final CentralRepoHashSet other = (CentralRepoHashSet) obj; if (!Objects.equals(this.hashSetName, other.hashSetName)) { return false; } @@ -1354,9 +1348,9 @@ public class HashDbManager implements PropertyChangeListener { private class HashDbIndexer extends SwingWorker { private ProgressHandle progress = null; - private HashDatabase hashDb = null; + private SleuthkitHashSet hashDb = null; - HashDbIndexer(HashDatabase hashDb) { + HashDbIndexer(SleuthkitHashSet hashDb) { this.hashDb = hashDb; } @@ -1370,7 +1364,7 @@ public class HashDbManager implements PropertyChangeListener { try { SleuthkitJNI.createLookupIndexForHashDatabase(hashDb.getHandle()); } catch (TskCoreException ex) { - Logger.getLogger(HashDatabase.class.getName()).log(Level.SEVERE, "Error indexing hash database", ex); //NON-NLS + Logger.getLogger(SleuthkitHashSet.class.getName()).log(Level.SEVERE, "Error indexing hash database", ex); //NON-NLS JOptionPane.showMessageDialog(null, NbBundle.getMessage(this.getClass(), "HashDbManager.dlgMsg.errorIndexingHashSet", @@ -1400,7 +1394,7 @@ public class HashDbManager implements PropertyChangeListener { } try { - hashDb.firePropertyChange(HashDatabase.Event.INDEXING_DONE.toString(), null, hashDb); + hashDb.firePropertyChange(SleuthkitHashSet.Event.INDEXING_DONE.toString(), null, hashDb); hashDb.firePropertyChange(HashDbManager.SetEvt.DB_INDEXED.toString(), null, hashDb.getHashSetName()); } catch (Exception e) { logger.log(Level.SEVERE, "HashDbManager listener threw exception", e); //NON-NLS diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java index fecc5ad192..8630b516c4 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java @@ -36,8 +36,8 @@ import org.sleuthkit.autopsy.core.RuntimeProperties; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.PlatformUtil; import org.sleuthkit.autopsy.coreutils.XMLUtil; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.CentralRepoHashDb; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.CentralRepoHashSet; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.SleuthkitHashSet; import org.sleuthkit.datamodel.TskCoreException; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -202,7 +202,7 @@ final class HashLookupSettings implements Serializable { // Handle legacy known files types. if (knownFilesType.equals("NSRL")) { //NON-NLS - knownFilesType = HashDbManager.HashDatabase.KnownFilesType.KNOWN.toString(); + knownFilesType = HashDbManager.SleuthkitHashSet.KnownFilesType.KNOWN.toString(); updatedSchema = true; } @@ -236,7 +236,7 @@ final class HashLookupSettings implements Serializable { } else { throw new HashLookupSettingsException(String.format(elementErrorMessage, PATH_ELEMENT)); } - hashDbInfoList.add(new HashDbInfo(hashSetName, HashDbManager.HashDatabase.KnownFilesType.valueOf(knownFilesType), + hashDbInfoList.add(new HashDbInfo(hashSetName, HashDbManager.SleuthkitHashSet.KnownFilesType.valueOf(knownFilesType), searchDuringIngestFlag, sendIngestMessagesFlag, dbPath)); hashSetNames.add(hashSetName); } @@ -304,7 +304,7 @@ final class HashLookupSettings implements Serializable { private static final long serialVersionUID = 1L; private final String hashSetName; - private final HashDbManager.HashDatabase.KnownFilesType knownFilesType; + private final HashDbManager.SleuthkitHashSet.KnownFilesType knownFilesType; private boolean searchDuringIngest; private final boolean sendIngestMessages; private final String path; @@ -323,7 +323,7 @@ final class HashLookupSettings implements Serializable { * @param sendIngestMessages Whether or not ingest messages are sent * @param path The path to the db */ - HashDbInfo(String hashSetName, HashDbManager.HashDatabase.KnownFilesType knownFilesType, boolean searchDuringIngest, boolean sendIngestMessages, String path) { + HashDbInfo(String hashSetName, HashDbManager.SleuthkitHashSet.KnownFilesType knownFilesType, boolean searchDuringIngest, boolean sendIngestMessages, String path) { this.hashSetName = hashSetName; this.knownFilesType = knownFilesType; this.searchDuringIngest = searchDuringIngest; @@ -335,7 +335,7 @@ final class HashLookupSettings implements Serializable { this.dbType = DatabaseType.FILE; } - HashDbInfo(String hashSetName, String version, int referenceSetID, HashDbManager.HashDatabase.KnownFilesType knownFilesType, boolean readOnly, boolean searchDuringIngest, boolean sendIngestMessages){ + HashDbInfo(String hashSetName, String version, int referenceSetID, HashDbManager.SleuthkitHashSet.KnownFilesType knownFilesType, boolean readOnly, boolean searchDuringIngest, boolean sendIngestMessages){ this.hashSetName = hashSetName; this.version = version; this.referenceSetID = referenceSetID; @@ -348,8 +348,8 @@ final class HashLookupSettings implements Serializable { } HashDbInfo(HashDbManager.HashDb db) throws TskCoreException{ - if(db instanceof HashDbManager.HashDatabase){ - HashDbManager.HashDatabase fileTypeDb = (HashDbManager.HashDatabase)db; + if(db instanceof HashDbManager.SleuthkitHashSet){ + HashDbManager.SleuthkitHashSet fileTypeDb = (HashDbManager.SleuthkitHashSet)db; this.hashSetName = fileTypeDb.getHashSetName(); this.knownFilesType = fileTypeDb.getKnownFilesType(); this.searchDuringIngest = fileTypeDb.getSearchDuringIngest(); @@ -364,7 +364,7 @@ final class HashLookupSettings implements Serializable { this.path = fileTypeDb.getDatabasePath(); } } else { - HashDbManager.CentralRepoHashDb centralRepoDb = (HashDbManager.CentralRepoHashDb)db; + HashDbManager.CentralRepoHashSet centralRepoDb = (HashDbManager.CentralRepoHashSet)db; this.hashSetName = centralRepoDb.getHashSetName(); this.version = centralRepoDb.getVersion(); this.knownFilesType = centralRepoDb.getKnownFilesType(); @@ -407,7 +407,7 @@ final class HashLookupSettings implements Serializable { * * @return The known files type setting. */ - HashDbManager.HashDatabase.KnownFilesType getKnownFilesType() { + HashDbManager.SleuthkitHashSet.KnownFilesType getKnownFilesType() { return knownFilesType; } @@ -471,8 +471,8 @@ final class HashLookupSettings implements Serializable { return false; } - if((this.dbType == DatabaseType.CENTRAL_REPOSITORY) && (! (hashDb instanceof CentralRepoHashDb)) - || (this.dbType == DatabaseType.FILE) && (! (hashDb instanceof HashDatabase))){ + if((this.dbType == DatabaseType.CENTRAL_REPOSITORY) && (! (hashDb instanceof CentralRepoHashSet)) + || (this.dbType == DatabaseType.FILE) && (! (hashDb instanceof SleuthkitHashSet))){ return false; } @@ -480,8 +480,8 @@ final class HashLookupSettings implements Serializable { return false; } - if(hashDb instanceof CentralRepoHashDb){ - CentralRepoHashDb crDb = (CentralRepoHashDb) hashDb; + if(hashDb instanceof CentralRepoHashSet){ + CentralRepoHashSet crDb = (CentralRepoHashSet) hashDb; if(this.referenceSetID != crDb.getReferenceSetID()){ return false; } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java index f765fcbd4b..d4a77883d6 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettingsPanel.java @@ -45,8 +45,8 @@ import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.events.AutopsyEvent; import org.sleuthkit.autopsy.ingest.IngestManager; import org.sleuthkit.autopsy.ingest.IngestModuleGlobalSettingsPanel; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.CentralRepoHashDb; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.SleuthkitHashSet; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.CentralRepoHashSet; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb.KnownFilesType; import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; @@ -180,8 +180,8 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan addHashesToDatabaseButton.setEnabled(false); } - if(db instanceof HashDatabase){ - HashDatabase hashDb = (HashDatabase)db; + if(db instanceof SleuthkitHashSet){ + SleuthkitHashSet hashDb = (SleuthkitHashSet)db; // Disable the central repo fields hashDbVersionLabel.setText(Bundle.HashLookupSettingsPanel_notApplicable()); @@ -253,7 +253,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan indexButton.setEnabled(false); deleteDatabaseButton.setEnabled(false); - CentralRepoHashDb crDb = (CentralRepoHashDb)db; + CentralRepoHashSet crDb = (CentralRepoHashSet)db; hashDbVersionLabel.setText(crDb.getVersion()); hashDbOrgLabel.setText(crDb.getOrgName()); @@ -304,11 +304,11 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan "HashLookupSettingsPanel.saveFail.title=Save Fail"}) public void saveSettings() { //Checking for for any unindexed databases - List unindexed = new ArrayList<>(); + List unindexed = new ArrayList<>(); for (HashDb db : hashSetManager.getAllHashSets()) { - if(db instanceof HashDatabase){ + if(db instanceof SleuthkitHashSet){ try { - HashDatabase hashDatabase = (HashDatabase)db; + SleuthkitHashSet hashDatabase = (SleuthkitHashSet)db; if (!hashDatabase.hasIndex()) { unindexed.add(hashDatabase); } @@ -373,8 +373,8 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan } @Messages({"# {0} - hash lookup name", "HashLookupSettingsPanel.removeDatabaseFailure.message=Failed to remove hash lookup: {0}"}) - void removeThese(List toRemove) { - for (HashDatabase hashDb : toRemove) { + void removeThese(List toRemove) { + for (SleuthkitHashSet hashDb : toRemove) { try { hashSetManager.removeHashDatabaseNoSave(hashDb); } catch (HashDbManager.HashDbManagerException ex) { @@ -392,7 +392,7 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan * @param plural Whether or not there are multiple unindexed databases * @param unindexed The list of unindexed databases. Can be of size 1. */ - private void showInvalidIndex(boolean plural, List unindexed) { + private void showInvalidIndex(boolean plural, List unindexed) { String total = ""; String message; for (HashDb hdb : unindexed) { @@ -937,15 +937,15 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan private void indexButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_indexButtonActionPerformed final HashDb hashDatabase = ((HashSetTable) hashSetTable).getSelection(); assert hashDatabase != null; - assert hashDatabase instanceof HashDatabase; + assert hashDatabase instanceof SleuthkitHashSet; // Add a listener for the INDEXING_DONE event. This listener will update // the UI. - HashDatabase hashDb = (HashDatabase)hashDatabase; + SleuthkitHashSet hashDb = (SleuthkitHashSet)hashDatabase; hashDb.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName().equals(HashDatabase.Event.INDEXING_DONE.toString())) { + if (evt.getPropertyName().equals(SleuthkitHashSet.Event.INDEXING_DONE.toString())) { HashDb selectedHashDb = ((HashSetTable) hashSetTable).getSelection(); if (selectedHashDb != null && hashDb != null && hashDb.equals(selectedHashDb)) { updateComponents(); @@ -969,8 +969,8 @@ public final class HashLookupSettingsPanel extends IngestModuleGlobalSettingsPan private void importDatabaseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importDatabaseButtonActionPerformed HashDb hashDb = new HashDbImportDatabaseDialog().getHashDatabase(); if (null != hashDb) { - if(hashDb instanceof CentralRepoHashDb){ - int newReferenceSetID = ((CentralRepoHashDb)hashDb).getReferenceSetID(); + if(hashDb instanceof CentralRepoHashSet){ + int newReferenceSetID = ((CentralRepoHashSet)hashDb).getReferenceSetID(); newReferenceSetIDs.add(newReferenceSetID); } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java index 6f14459eb6..1f44df404e 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java @@ -77,7 +77,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P } void importFile(String hashSetName, String version, int orgId, - boolean searchDuringIngest, boolean sendIngestMessages, HashDbManager.HashDatabase.KnownFilesType knownFilesType, + boolean searchDuringIngest, boolean sendIngestMessages, HashDbManager.SleuthkitHashSet.KnownFilesType knownFilesType, boolean readOnly, String importFileName){ setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); @@ -139,16 +139,16 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P private final int orgId; private final boolean searchDuringIngest; private final boolean sendIngestMessages; - private final HashDbManager.HashDatabase.KnownFilesType knownFilesType; + private final HashDbManager.SleuthkitHashSet.KnownFilesType knownFilesType; private final boolean readOnly; private final File importFile; private final long totalLines; private int referenceSetID = -1; - private HashDbManager.CentralRepoHashDb newHashDb = null; + private HashDbManager.CentralRepoHashSet newHashDb = null; private final AtomicLong numLines = new AtomicLong(); ImportIDXWorker(String hashSetName, String version, int orgId, - boolean searchDuringIngest, boolean sendIngestMessages, HashDbManager.HashDatabase.KnownFilesType knownFilesType, + boolean searchDuringIngest, boolean sendIngestMessages, HashDbManager.SleuthkitHashSet.KnownFilesType knownFilesType, boolean readOnly, File importFile){ this.hashSetName = hashSetName; @@ -194,7 +194,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P protected Void doInBackground() throws Exception { TskData.FileKnown knownStatus; - if (knownFilesType.equals(HashDbManager.HashDatabase.KnownFilesType.KNOWN)) { + if (knownFilesType.equals(HashDbManager.SleuthkitHashSet.KnownFilesType.KNOWN)) { knownStatus = TskData.FileKnown.KNOWN; } else { knownStatus = TskData.FileKnown.BAD; diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ModalNoButtons.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ModalNoButtons.java index 5795233479..41a9fe4fe8 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ModalNoButtons.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ModalNoButtons.java @@ -26,7 +26,7 @@ import java.util.List; import javax.swing.JOptionPane; import org.openide.util.NbBundle; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.SleuthkitHashSet; /** * This class exists as a stop-gap measure to force users to have an indexed @@ -43,8 +43,8 @@ import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; */ class ModalNoButtons extends javax.swing.JDialog implements PropertyChangeListener { - List unindexed; - HashDatabase toIndex; + List unindexed; + SleuthkitHashSet toIndex; HashLookupSettingsPanel hdbmp; int length = 0; int currentcount = 1; @@ -58,7 +58,7 @@ class ModalNoButtons extends javax.swing.JDialog implements PropertyChangeListen * @param parent Swing parent frame. * @param unindexed the list of unindexed databases to index. */ - ModalNoButtons(HashLookupSettingsPanel hdbmp, java.awt.Frame parent, List unindexed) { + ModalNoButtons(HashLookupSettingsPanel hdbmp, java.awt.Frame parent, List unindexed) { super(parent, NbBundle.getMessage(ModalNoButtons.class, "ModalNoButtons.indexingDbsTitle"), true); this.unindexed = unindexed; this.toIndex = null; @@ -75,7 +75,7 @@ class ModalNoButtons extends javax.swing.JDialog implements PropertyChangeListen * @param parent Swing parent frame. * @param unindexed The unindexed database to index. */ - ModalNoButtons(HashLookupSettingsPanel hdbmp, java.awt.Frame parent, HashDatabase unindexed) { + ModalNoButtons(HashLookupSettingsPanel hdbmp, java.awt.Frame parent, SleuthkitHashSet unindexed) { super(parent, NbBundle.getMessage(ModalNoButtons.class, "ModalNoButtons.indexingDbTitle"), true); this.unindexed = null; this.toIndex = unindexed; @@ -183,7 +183,7 @@ class ModalNoButtons extends javax.swing.JDialog implements PropertyChangeListen "ModalNoButtons.dlgTitle.unfinishedIndexing"), JOptionPane.YES_NO_OPTION); if (res == JOptionPane.YES_OPTION) { - List remove = new ArrayList<>(); + List remove = new ArrayList<>(); if (this.toIndex == null) { remove = this.unindexed; } else { @@ -230,7 +230,7 @@ class ModalNoButtons extends javax.swing.JDialog implements PropertyChangeListen private void indexThese() { length = this.unindexed.size(); this.INDEXING_PROGBAR.setIndeterminate(true); - for (HashDatabase db : this.unindexed) { + for (SleuthkitHashSet db : this.unindexed) { currentDb = db.getHashSetName(); this.CURRENTDB_LABEL.setText("(" + currentDb + ")"); this.CURRENTLYON_LABEL.setText( @@ -255,7 +255,7 @@ class ModalNoButtons extends javax.swing.JDialog implements PropertyChangeListen * this dialog if all indexing is complete. */ public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName().equals(HashDatabase.Event.INDEXING_DONE.name())) { + if (evt.getPropertyName().equals(SleuthkitHashSet.Event.INDEXING_DONE.name())) { if (currentcount >= length) { this.INDEXING_PROGBAR.setValue(100); this.setModal(false); diff --git a/Experimental/src/org/sleuthkit/autopsy/experimental/configuration/SharedConfiguration.java b/Experimental/src/org/sleuthkit/autopsy/experimental/configuration/SharedConfiguration.java index e3f6a23bf5..1720b4b647 100755 --- a/Experimental/src/org/sleuthkit/autopsy/experimental/configuration/SharedConfiguration.java +++ b/Experimental/src/org/sleuthkit/autopsy/experimental/configuration/SharedConfiguration.java @@ -47,7 +47,7 @@ import org.sleuthkit.autopsy.keywordsearch.KeywordListsManager; import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager; import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.autopsy.core.ServicesMonitor; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDatabase; +import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb; import org.sleuthkit.autopsy.experimental.configuration.AutoIngestSettingsPanel.UpdateConfigSwingWorker; import org.sleuthkit.autopsy.coordinationservice.CoordinationService; import org.sleuthkit.autopsy.coordinationservice.CoordinationService.CategoryNode; @@ -1017,17 +1017,15 @@ public class SharedConfiguration { // If a copy of the database is loaded, close it before deleting and copying. if (localDb.exists()) { List hashDbs = HashDbManager.getInstance().getAllHashSets(); - HashDbManager.HashDatabase matchingDb = null; + HashDbManager.HashDb matchingDb = null; for (HashDbManager.HashDb db : hashDbs) { - if(db instanceof HashDbManager.HashDatabase){ - try { - if (localDb.getAbsolutePath().equals(db.getDatabasePath()) || localDb.getAbsolutePath().equals(db.getIndexPath())) { - matchingDb = (HashDbManager.HashDatabase)db; - break; - } - } catch (TskCoreException ex) { - throw new SharedConfigurationException(String.format("Error getting hash database path info for %s", localDb.getParentFile().getAbsolutePath()), ex); + try { + if (localDb.getAbsolutePath().equals(db.getDatabasePath()) || localDb.getAbsolutePath().equals(db.getIndexPath())) { + matchingDb = db; + break; } + } catch (TskCoreException ex) { + throw new SharedConfigurationException(String.format("Error getting hash database path info for %s", localDb.getParentFile().getAbsolutePath()), ex); } } @@ -1125,12 +1123,10 @@ public class SharedConfiguration { HashDbManager hashDbManager = HashDbManager.getInstance(); hashDbManager.loadLastSavedConfiguration(); for (HashDbManager.HashDb hashDb : hashDbManager.getAllHashSets()) { - if(hashDb instanceof HashDatabase){ - if (hashDb.hasIndexOnly()) { - results.add(hashDb.getIndexPath()); - } else { - results.add(hashDb.getDatabasePath()); - } + if (hashDb.hasIndexOnly()) { + results.add(hashDb.getIndexPath()); + } else { + results.add(hashDb.getDatabasePath()); } } } catch (TskCoreException ex) { From 156970c9e51b64dcad976b64a52aceac67118f91 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Wed, 15 Nov 2017 09:08:29 -0500 Subject: [PATCH 37/41] Made reference set methods less hash-specific --- .../datamodel/AbstractSqlEamDb.java | 40 +++++++++++++------ .../centralrepository/datamodel/EamDb.java | 15 ++++++- .../datamodel/SqliteEamDb.java | 4 +- .../modules/hashdatabase/HashDbManager.java | 4 +- 4 files changed, 45 insertions(+), 18 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java index fad0196288..5fba1f1670 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java @@ -1251,13 +1251,13 @@ public abstract class AbstractSqlEamDb implements EamDb { } /** - * Remove a reference set and all hashes contained in it. + * Remove a reference set and all entries contained in it. * @param referenceSetID * @throws EamDbException */ @Override public void deleteReferenceSet(int referenceSetID) throws EamDbException{ - deleteReferenceSetFiles(referenceSetID); + deleteReferenceSetEntries(referenceSetID); deleteReferenceSetEntry(referenceSetID); } @@ -1285,16 +1285,18 @@ public abstract class AbstractSqlEamDb implements EamDb { } /** - * Remove all entries for this reference set from the reference_file table + * Remove all entries for this reference set from the reference tables + * (Currently only removes entries from the files table) * @param referenceSetID * @throws EamDbException */ - private void deleteReferenceSetFiles(int referenceSetID) throws EamDbException{ + private void deleteReferenceSetEntries(int referenceSetID) throws EamDbException{ Connection conn = connect(); PreparedStatement preparedStatement = null; String sql = "DELETE FROM %s WHERE reference_set_id=?"; + // When other reference types are added, this will need to loop over all the tables String fileTableName = EamDbUtil.correlationTypeToReferenceTableName(getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID)); try { @@ -1312,29 +1314,43 @@ public abstract class AbstractSqlEamDb implements EamDb { /** * Check whether the given reference set exists in the central repository. * @param referenceSetID - * @param hashSetName + * @param setName * @param version * @return true if a matching entry exists in the central repository * @throws EamDbException */ @Override - public boolean referenceSetIsValid(int referenceSetID, String hashSetName, String version) throws EamDbException{ + public boolean referenceSetIsValid(int referenceSetID, String setName, String version) throws EamDbException{ EamGlobalSet refSet = this.getReferenceSetByID(referenceSetID); if(refSet == null){ return false; } - return(refSet.getSetName().equals(hashSetName) && refSet.getVersion().equals(version)); + return(refSet.getSetName().equals(setName) && refSet.getVersion().equals(version)); } - + /** - * Check if the given hash is in a specific reference set + * Check if the given file hash is in this reference set. + * Only searches the reference_files table. * @param hash * @param referenceSetID * @return true if the hash is found in the reference set + * @throws EamDbException */ @Override - public boolean isHashInReferenceSet(String hash, int referenceSetID) throws EamDbException{ + public boolean isFileHashInReferenceSet(String hash, int referenceSetID) throws EamDbException{ + return isValueInReferenceSet(hash, referenceSetID, CorrelationAttribute.FILES_TYPE_ID); + } + + /** + * Check if the given value is in a specific reference set + * @param value + * @param referenceSetID + * @param correlationTypeID + * @return true if the hash is found in the reference set + */ + @Override + public boolean isValueInReferenceSet(String value, int referenceSetID, int correlationTypeID) throws EamDbException{ Connection conn = connect(); @@ -1343,11 +1359,11 @@ public abstract class AbstractSqlEamDb implements EamDb { ResultSet resultSet = null; String sql = "SELECT count(*) FROM %s WHERE value=? AND reference_set_id=?"; - String fileTableName = EamDbUtil.correlationTypeToReferenceTableName(getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID)); + String fileTableName = EamDbUtil.correlationTypeToReferenceTableName(getCorrelationTypeById(correlationTypeID)); try { preparedStatement = conn.prepareStatement(String.format(sql, fileTableName)); - preparedStatement.setString(1, hash); + preparedStatement.setString(1, value); preparedStatement.setInt(2, referenceSetID); resultSet = preparedStatement.executeQuery(); resultSet.next(); diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java index 4edeb5b734..1f1bd8a942 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java @@ -380,12 +380,23 @@ public interface EamDb { public boolean referenceSetExists(String hashSetName, String version) throws EamDbException; /** - * Check if the given hash is in a specific reference set + * Check if the given file hash is in this reference set. + * Only searches the reference_files table. * @param hash * @param referenceSetID * @return true if the hash is found in the reference set + * @throws EamDbException */ - public boolean isHashInReferenceSet(String hash, int referenceSetID) throws EamDbException; + public boolean isFileHashInReferenceSet(String hash, int referenceSetID) throws EamDbException; + + /** + * Check if the given value is in a specific reference set + * @param value + * @param referenceSetID + * @param correlationTypeID + * @return true if the hash is found in the reference set + */ + public boolean isValueInReferenceSet(String value, int referenceSetID, int correlationTypeID) throws EamDbException; /** * Is the artifact known as bad according to the reference entries? diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java index 45a0388561..4ee57db0b2 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java @@ -657,10 +657,10 @@ public class SqliteEamDb extends AbstractSqlEamDb { * @return true if the hash is found in the reference set */ @Override - public boolean isHashInReferenceSet(String hash, int referenceSetID) throws EamDbException{ + public boolean isValueInReferenceSet(String value, int referenceSetID, int correlationTypeID) throws EamDbException { try{ acquireSharedLock(); - return super.isHashInReferenceSet(hash, referenceSetID); + return super.isValueInReferenceSet(value, referenceSetID, correlationTypeID); } finally { releaseSharedLock(); } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index 4f68120f6a..27935cc3d9 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -1240,7 +1240,7 @@ public class HashDbManager implements PropertyChangeListener { AbstractFile file = (AbstractFile) content; if (null != file.getMd5Hash()) { try{ - return EamDb.getInstance().isHashInReferenceSet(file.getMd5Hash(), this.referenceSetID); + return EamDb.getInstance().isFileHashInReferenceSet(file.getMd5Hash(), this.referenceSetID); } catch (EamDbException ex){ Logger.getLogger(SleuthkitHashSet.class.getName()).log(Level.SEVERE, "Error performing central reposiotry hash lookup", ex); //NON-NLS throw new TskCoreException("Error performing central reposiotry hash lookup", ex); @@ -1268,7 +1268,7 @@ public class HashDbManager implements PropertyChangeListener { AbstractFile file = (AbstractFile) content; if (null != file.getMd5Hash()) { try{ - if(EamDb.getInstance().isHashInReferenceSet(file.getMd5Hash(), this.referenceSetID)){ + if(EamDb.getInstance().isFileHashInReferenceSet(file.getMd5Hash(), this.referenceSetID)){ // Make a bare-bones HashHitInfo for now result = new HashHitInfo(file.getMd5Hash(), "", ""); } From 143e530c327f32f51ecaab3779ecb8ac203ff050 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Wed, 15 Nov 2017 09:18:03 -0500 Subject: [PATCH 38/41] Missed a "hash" reference --- .../autopsy/centralrepository/datamodel/AbstractSqlEamDb.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java index 5fba1f1670..fa03d01321 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java @@ -1347,7 +1347,7 @@ public abstract class AbstractSqlEamDb implements EamDb { * @param value * @param referenceSetID * @param correlationTypeID - * @return true if the hash is found in the reference set + * @return true if the value is found in the reference set */ @Override public boolean isValueInReferenceSet(String value, int referenceSetID, int correlationTypeID) throws EamDbException{ From 61b7f89788ad9aa42fe412874dddb8f8cde24f85 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Thu, 16 Nov 2017 09:40:29 -0500 Subject: [PATCH 39/41] Cleanup --- .../datamodel/AbstractSqlEamDb.java | 13 +++++++------ .../autopsy/centralrepository/datamodel/EamDb.java | 14 ++++++++------ .../centralrepository/datamodel/SqliteEamDb.java | 9 +++++---- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java index fa03d01321..eb73f9ef66 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java @@ -34,7 +34,6 @@ import java.time.LocalDate; import java.util.HashMap; import java.util.Map; import java.util.Set; -import org.openide.util.NbBundle; import org.openide.util.NbBundle.Messages; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.coreutils.Logger; @@ -1312,7 +1311,8 @@ public abstract class AbstractSqlEamDb implements EamDb { } /** - * Check whether the given reference set exists in the central repository. + * Check whether a reference set with the given parameters exists in the central repository. + * Used to check whether reference sets saved in the settings are still present. * @param referenceSetID * @param setName * @param version @@ -1773,14 +1773,15 @@ public abstract class AbstractSqlEamDb implements EamDb { } /** - * Check whether a reference set with the given name/version is in the central repo - * @param hashSetName + * Check whether a reference set with the given name/version is in the central repo. + * Used to check for name collisions when creating reference sets. + * @param referenceSetName * @param version * @return true if a matching set is found * @throws EamDbException */ @Override - public boolean referenceSetExists(String hashSetName, String version) throws EamDbException{ + public boolean referenceSetExists(String referenceSetName, String version) throws EamDbException{ Connection conn = connect(); PreparedStatement preparedStatement1 = null; @@ -1789,7 +1790,7 @@ public abstract class AbstractSqlEamDb implements EamDb { try { preparedStatement1 = conn.prepareStatement(sql1); - preparedStatement1.setString(1, hashSetName); + preparedStatement1.setString(1, referenceSetName); preparedStatement1.setString(2, version); resultSet = preparedStatement1.executeQuery(); return (resultSet.next()); diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java index 1f1bd8a942..2ab708e5de 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java @@ -361,23 +361,25 @@ public interface EamDb { public void deleteReferenceSet(int referenceSetID) throws EamDbException; /** - * Check whether the given reference set exists in the central repository. + * Check whether a reference set with the given parameters exists in the central repository. + * Used to check whether reference sets saved in the settings are still present. * @param referenceSetID - * @param hashSetName + * @param referenceSetName * @param version * @return true if a matching entry exists in the central repository * @throws EamDbException */ - public boolean referenceSetIsValid(int referenceSetID, String hashSetName, String version) throws EamDbException; + public boolean referenceSetIsValid(int referenceSetID, String referenceSetName, String version) throws EamDbException; /** - * Check whether a reference set with the given name/version is in the central repo - * @param hashSetName + * Check whether a reference set with the given name/version is in the central repo. + * Used to check for name collisions when creating reference sets. + * @param referenceSetName * @param version * @return true if a matching set is found * @throws EamDbException */ - public boolean referenceSetExists(String hashSetName, String version) throws EamDbException; + public boolean referenceSetExists(String referenceSetName, String version) throws EamDbException; /** * Check if the given file hash is in this reference set. diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java index 4ee57db0b2..efbda95156 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java @@ -667,17 +667,18 @@ public class SqliteEamDb extends AbstractSqlEamDb { } /** - * Check whether a reference set with the given name/version is in the central repo - * @param hashSetName + * Check whether a reference set with the given name/version is in the central repo. + * Used to check for name collisions when creating reference sets. + * @param referenceSetName * @param version * @return true if a matching set is found * @throws EamDbException */ @Override - public boolean referenceSetExists(String hashSetName, String version) throws EamDbException { + public boolean referenceSetExists(String referenceSetName, String version) throws EamDbException { try{ acquireSharedLock(); - return super.referenceSetExists(hashSetName, version); + return super.referenceSetExists(referenceSetName, version); } finally { releaseSharedLock(); } From c062a20213a3fcddcd0d8d37b66b4fc9bfa80657 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Fri, 17 Nov 2017 08:47:43 -0500 Subject: [PATCH 40/41] Addresses most of the review comments --- .../datamodel/AbstractSqlEamDb.java | 39 ++++--------------- .../centralrepository/datamodel/EamDb.java | 19 ++------- .../datamodel/EamGlobalSet.java | 32 +++++++++------ .../datamodel/SqliteEamDb.java | 10 ++--- .../modules/hashdatabase/HashDbManager.java | 38 +++++++++++------- .../hashdatabase/HashLookupSettings.java | 12 +++--- .../ImportCentralRepoDbProgressDialog.java | 11 +++--- 7 files changed, 72 insertions(+), 89 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java index eb73f9ef66..7c7d22066e 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java @@ -1276,7 +1276,7 @@ public abstract class AbstractSqlEamDb implements EamDb { preparedStatement.setInt(1, referenceSetID); preparedStatement.executeUpdate(); } catch (SQLException ex) { - throw new EamDbException("Error deleting reference set", ex); // NON-NLS + throw new EamDbException("Error deleting reference set " + referenceSetID, ex); // NON-NLS } finally { EamDbUtil.closePreparedStatement(preparedStatement); EamDbUtil.closeConnection(conn); @@ -1285,7 +1285,7 @@ public abstract class AbstractSqlEamDb implements EamDb { /** * Remove all entries for this reference set from the reference tables - * (Currently only removes entries from the files table) + * (Currently only removes entries from the reference_file table) * @param referenceSetID * @throws EamDbException */ @@ -1303,7 +1303,7 @@ public abstract class AbstractSqlEamDb implements EamDb { preparedStatement.setInt(1, referenceSetID); preparedStatement.executeUpdate(); } catch (SQLException ex) { - throw new EamDbException("Error deleting files from reference set", ex); // NON-NLS + throw new EamDbException("Error deleting files from reference set " + referenceSetID, ex); // NON-NLS } finally { EamDbUtil.closePreparedStatement(preparedStatement); EamDbUtil.closeConnection(conn); @@ -1369,7 +1369,7 @@ public abstract class AbstractSqlEamDb implements EamDb { resultSet.next(); matchingInstances = resultSet.getLong(1); } catch (SQLException ex) { - throw new EamDbException("Error determining if file is in reference set.", ex); // NON-NLS + throw new EamDbException("Error determining if value (" + value + ") is in reference set " + referenceSetID, ex); // NON-NLS } finally { EamDbUtil.closePreparedStatement(preparedStatement); EamDbUtil.closeResultSet(resultSet); @@ -1388,7 +1388,7 @@ public abstract class AbstractSqlEamDb implements EamDb { * @return Global known status of the artifact */ @Override - public boolean isArtifactlKnownBadByReference(CorrelationAttribute.Type aType, String value) throws EamDbException { + public boolean isArtifactKnownBadByReference(CorrelationAttribute.Type aType, String value) throws EamDbException { // TEMP: Only support file correlation type if (aType.getId() != CorrelationAttribute.FILES_TYPE_ID) { @@ -1537,30 +1537,6 @@ public abstract class AbstractSqlEamDb implements EamDb { EamGlobalSet globalSet = getReferenceSetByID(referenceSetID); return (getOrganizationByID(globalSet.getOrgID())); } - - /** - * Add a new reference set - * - * @param orgID - * @param setName - * @param version - * @param importDate - * @return the reference set ID of the newly created set - * @throws EamDbException - */ - @Override - public int newReferenceSet(int orgID, String setName, String version, TskData.FileKnown knownStatus, - boolean isReadOnly) throws EamDbException { - EamDb dbManager = EamDb.getInstance(); - EamGlobalSet eamGlobalSet = new EamGlobalSet( - orgID, - setName, - version, - knownStatus, - isReadOnly, - LocalDate.now()); - return dbManager.newReferencelSet(eamGlobalSet); - } /** * Update an existing organization. @@ -1634,7 +1610,7 @@ public abstract class AbstractSqlEamDb implements EamDb { * @throws EamDbException */ @Override - public int newReferencelSet(EamGlobalSet eamGlobalSet) throws EamDbException { + public int newReferenceSet(EamGlobalSet eamGlobalSet) throws EamDbException { Connection conn = connect(); PreparedStatement preparedStatement1 = null; @@ -1796,7 +1772,8 @@ public abstract class AbstractSqlEamDb implements EamDb { return (resultSet.next()); } catch (SQLException ex) { - throw new EamDbException("Error getting reference instances by type and value.", ex); // NON-NLS + throw new EamDbException("Error testing whether reference set exists (name: " + referenceSetName + + " version: " + version, ex); // NON-NLS } finally { EamDbUtil.closePreparedStatement(preparedStatement1); EamDbUtil.closeResultSet(resultSet); diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java index 2ab708e5de..9f7e31fbc5 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java @@ -354,7 +354,7 @@ public interface EamDb { List getListCasesHavingArtifactInstancesKnownBad(CorrelationAttribute.Type aType, String value) throws EamDbException; /** - * Remove a reference set and all hashes contained in it. + * Remove a reference set and all values contained in it. * @param referenceSetID * @throws EamDbException */ @@ -408,7 +408,7 @@ public interface EamDb { * * @return Global known status of the artifact */ - boolean isArtifactlKnownBadByReference(CorrelationAttribute.Type aType, String value) throws EamDbException; + boolean isArtifactKnownBadByReference(CorrelationAttribute.Type aType, String value) throws EamDbException; /** * Add a new organization @@ -477,20 +477,7 @@ public interface EamDb { * * @throws EamDbException */ - int newReferencelSet(EamGlobalSet eamGlobalSet) throws EamDbException; - - /** - * Add a new reference set - * - * @param orgID - * @param setName - * @param version - * @param importDate - * @return the reference set ID of the newly created set - * @throws EamDbException - */ - int newReferenceSet(int orgID, String setName, String version, TskData.FileKnown knownStatus, - boolean isReadOnly) throws EamDbException; + int newReferenceSet(EamGlobalSet eamGlobalSet) throws EamDbException; /** * Get a global set by ID diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalSet.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalSet.java index e4292dc6ca..23a4c257ae 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalSet.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamGlobalSet.java @@ -19,7 +19,6 @@ package org.sleuthkit.autopsy.centralrepository.datamodel; import java.time.LocalDate; -import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager; import org.sleuthkit.datamodel.TskData; /** @@ -61,6 +60,26 @@ public class EamGlobalSet { LocalDate importDate) { this(-1, orgID, setName, version, knownStatus, isReadOnly, importDate); } + + /** + * Create a new EamGlobalSet object. + * This is intended to be used when creating a new global set as the + * globalSetID will be unknown to start. + * importDate will be automatically set to the current time. + * @param orgID + * @param setName + * @param version + * @param knownStatus + * @param isReadOnly + */ + public EamGlobalSet( + int orgID, + String setName, + String version, + TskData.FileKnown knownStatus, + boolean isReadOnly) { + this(-1, orgID, setName, version, knownStatus, isReadOnly, LocalDate.now()); + } /** * @return the globalSetID @@ -145,17 +164,6 @@ public class EamGlobalSet { public void setFileKnownStatus(TskData.FileKnown fileKnownStatus) { this.fileKnownStatus = fileKnownStatus; } - - /** - * Return the FileKnown status as a KnownFilesType - * @return KNOWN or KNOWN_BAD - */ - public HashDbManager.HashDb.KnownFilesType getKnownStatus(){ - if(fileKnownStatus.equals(TskData.FileKnown.BAD)){ - return HashDbManager.HashDb.KnownFilesType.KNOWN_BAD; - } - return HashDbManager.HashDb.KnownFilesType.KNOWN; - } /** * @return the importDate diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java index efbda95156..719a58385b 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java @@ -636,7 +636,7 @@ public class SqliteEamDb extends AbstractSqlEamDb { } /** - * Remove a reference set and all hashes contained in it. + * Remove a reference set and all values contained in it. * @param referenceSetID * @throws EamDbException */ @@ -693,10 +693,10 @@ public class SqliteEamDb extends AbstractSqlEamDb { * @return Global known status of the artifact */ @Override - public boolean isArtifactlKnownBadByReference(CorrelationAttribute.Type aType, String value) throws EamDbException { + public boolean isArtifactKnownBadByReference(CorrelationAttribute.Type aType, String value) throws EamDbException { try{ acquireSharedLock(); - return super.isArtifactlKnownBadByReference(aType, value); + return super.isArtifactKnownBadByReference(aType, value); } finally { releaseSharedLock(); } @@ -786,10 +786,10 @@ public class SqliteEamDb extends AbstractSqlEamDb { * @throws EamDbException */ @Override - public int newReferencelSet(EamGlobalSet eamGlobalSet) throws EamDbException { + public int newReferenceSet(EamGlobalSet eamGlobalSet) throws EamDbException { try{ acquireExclusiveLock(); - return super.newReferencelSet(eamGlobalSet); + return super.newReferenceSet(eamGlobalSet); } finally { releaseExclusiveLock(); } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index 27935cc3d9..35dd424c39 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -52,6 +52,7 @@ import org.sleuthkit.datamodel.HashEntry; import org.sleuthkit.datamodel.HashHitInfo; import org.sleuthkit.datamodel.SleuthkitJNI; import org.sleuthkit.datamodel.TskCoreException; +import org.sleuthkit.datamodel.TskData; /** * This class implements a singleton that manages the set of hash databases used @@ -233,7 +234,7 @@ public class HashDbManager implements PropertyChangeListener { return hashDb; } - private SleuthkitHashSet addHashDatabase(int handle, String hashSetName, boolean searchDuringIngest, boolean sendIngestMessages, SleuthkitHashSet.KnownFilesType knownFilesType) throws TskCoreException { + private SleuthkitHashSet addHashDatabase(int handle, String hashSetName, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType) throws TskCoreException { // Wrap an object around the handle. SleuthkitHashSet hashDb = new SleuthkitHashSet(handle, hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType); @@ -426,7 +427,7 @@ public class HashDbManager implements PropertyChangeListener { */ public synchronized List getKnownFileHashSets() { List hashDbs = new ArrayList<>(); - this.hashSets.stream().filter((db) -> (db.getKnownFilesType() == SleuthkitHashSet.KnownFilesType.KNOWN)).forEach((db) -> { + this.hashSets.stream().filter((db) -> (db.getKnownFilesType() == HashDb.KnownFilesType.KNOWN)).forEach((db) -> { hashDbs.add(db); }); return hashDbs; @@ -439,7 +440,7 @@ public class HashDbManager implements PropertyChangeListener { */ public synchronized List getKnownBadFileHashSets() { List hashDbs = new ArrayList<>(); - this.hashSets.stream().filter((db) -> (db.getKnownFilesType() == SleuthkitHashSet.KnownFilesType.KNOWN_BAD)).forEach((db) -> { + this.hashSets.stream().filter((db) -> (db.getKnownFilesType() == HashDb.KnownFilesType.KNOWN_BAD)).forEach((db) -> { hashDbs.add(db); }); return hashDbs; @@ -478,9 +479,9 @@ public class HashDbManager implements PropertyChangeListener { // Defaults for fields not stored in the central repository: // searchDuringIngest: false // sendIngestMessages: true if the hash set is notable - boolean sendIngestMessages = globalSet.getKnownStatus().equals(SleuthkitHashSet.KnownFilesType.KNOWN_BAD); + boolean sendIngestMessages = convertFileKnown(globalSet.getFileKnownStatus()).equals(HashDb.KnownFilesType.KNOWN_BAD); crHashSets.add(new HashDbInfo(globalSet.getSetName(), globalSet.getVersion(), - globalSet.getGlobalSetID(), globalSet.getKnownStatus(), globalSet.isReadOnly(), false, sendIngestMessages)); + globalSet.getGlobalSetID(), convertFileKnown(globalSet.getFileKnownStatus()), globalSet.isReadOnly(), false, sendIngestMessages)); } } catch (EamDbException ex){ Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error loading central repository hash sets", ex); //NON-NLS @@ -488,6 +489,13 @@ public class HashDbManager implements PropertyChangeListener { } return crHashSets; } + + private static HashDb.KnownFilesType convertFileKnown(TskData.FileKnown fileKnown){ + if(fileKnown.equals(TskData.FileKnown.BAD)){ + return HashDb.KnownFilesType.KNOWN_BAD; + } + return HashDb.KnownFilesType.KNOWN; + } /** * Restores the last saved hash sets configuration. This supports @@ -700,7 +708,7 @@ public class HashDbManager implements PropertyChangeListener { public abstract String getDatabasePath() throws TskCoreException; - public abstract SleuthkitHashSet.KnownFilesType getKnownFilesType(); + public abstract HashDb.KnownFilesType getKnownFilesType(); public abstract boolean getSearchDuringIngest(); @@ -773,7 +781,7 @@ public class HashDbManager implements PropertyChangeListener { private final String hashSetName; private boolean searchDuringIngest; private boolean sendIngestMessages; - private final SleuthkitHashSet.KnownFilesType knownFilesType; + private final HashDb.KnownFilesType knownFilesType; private boolean indexing; private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this); @@ -1052,7 +1060,7 @@ public class HashDbManager implements PropertyChangeListener { private final String hashSetName; private boolean searchDuringIngest; private boolean sendIngestMessages; - private final SleuthkitHashSet.KnownFilesType knownFilesType; + private final HashDb.KnownFilesType knownFilesType; private final int referenceSetID; private final String version; private String orgName; @@ -1061,7 +1069,7 @@ public class HashDbManager implements PropertyChangeListener { @Messages({"HashDbManager.CentralRepoHashDb.orgError=Error loading organization"}) private CentralRepoHashSet(String hashSetName, String version, int referenceSetID, - boolean useForIngest, boolean sendHitMessages, SleuthkitHashSet.KnownFilesType knownFilesType, + boolean useForIngest, boolean sendHitMessages, HashDb.KnownFilesType knownFilesType, boolean readOnly) throws TskCoreException{ this.hashSetName = hashSetName; @@ -1075,7 +1083,7 @@ public class HashDbManager implements PropertyChangeListener { try{ orgName = EamDb.getInstance().getReferenceSetOrganization(referenceSetID).getName(); } catch (EamDbException ex){ - Logger.getLogger(SleuthkitHashSet.class.getName()).log(Level.SEVERE, "Error looking up central repository organization", ex); //NON-NLS + Logger.getLogger(SleuthkitHashSet.class.getName()).log(Level.SEVERE, "Error looking up central repository organization for reference set " + referenceSetID, ex); //NON-NLS orgName = Bundle.HashDbManager_CentralRepoHashDb_orgError(); } } @@ -1139,7 +1147,7 @@ public class HashDbManager implements PropertyChangeListener { } @Override - public SleuthkitHashSet.KnownFilesType getKnownFilesType() { + public HashDb.KnownFilesType getKnownFilesType() { return knownFilesType; } @@ -1242,7 +1250,8 @@ public class HashDbManager implements PropertyChangeListener { try{ return EamDb.getInstance().isFileHashInReferenceSet(file.getMd5Hash(), this.referenceSetID); } catch (EamDbException ex){ - Logger.getLogger(SleuthkitHashSet.class.getName()).log(Level.SEVERE, "Error performing central reposiotry hash lookup", ex); //NON-NLS + Logger.getLogger(SleuthkitHashSet.class.getName()).log(Level.SEVERE, "Error performing central reposiotry hash lookup for hash " + + file.getMd5Hash() + " in reference set " + referenceSetID, ex); //NON-NLS throw new TskCoreException("Error performing central reposiotry hash lookup", ex); } } @@ -1273,7 +1282,8 @@ public class HashDbManager implements PropertyChangeListener { result = new HashHitInfo(file.getMd5Hash(), "", ""); } } catch (EamDbException ex){ - Logger.getLogger(SleuthkitHashSet.class.getName()).log(Level.SEVERE, "Error performing central reposiotry hash lookup", ex); //NON-NLS + Logger.getLogger(SleuthkitHashSet.class.getName()).log(Level.SEVERE, "Error performing central reposiotry hash lookup for hash " + + file.getMd5Hash() + " in reference set " + referenceSetID, ex); //NON-NLS throw new TskCoreException("Error performing central reposiotry hash lookup", ex); } } @@ -1364,7 +1374,7 @@ public class HashDbManager implements PropertyChangeListener { try { SleuthkitJNI.createLookupIndexForHashDatabase(hashDb.getHandle()); } catch (TskCoreException ex) { - Logger.getLogger(SleuthkitHashSet.class.getName()).log(Level.SEVERE, "Error indexing hash database", ex); //NON-NLS + Logger.getLogger(HashDbIndexer.class.getName()).log(Level.SEVERE, "Error indexing hash set " + hashDb.getHashSetName(), ex); //NON-NLS JOptionPane.showMessageDialog(null, NbBundle.getMessage(this.getClass(), "HashDbManager.dlgMsg.errorIndexingHashSet", diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java index 8630b516c4..948f18451d 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupSettings.java @@ -202,7 +202,7 @@ final class HashLookupSettings implements Serializable { // Handle legacy known files types. if (knownFilesType.equals("NSRL")) { //NON-NLS - knownFilesType = HashDbManager.SleuthkitHashSet.KnownFilesType.KNOWN.toString(); + knownFilesType = HashDbManager.HashDb.KnownFilesType.KNOWN.toString(); updatedSchema = true; } @@ -236,7 +236,7 @@ final class HashLookupSettings implements Serializable { } else { throw new HashLookupSettingsException(String.format(elementErrorMessage, PATH_ELEMENT)); } - hashDbInfoList.add(new HashDbInfo(hashSetName, HashDbManager.SleuthkitHashSet.KnownFilesType.valueOf(knownFilesType), + hashDbInfoList.add(new HashDbInfo(hashSetName, HashDbManager.HashDb.KnownFilesType.valueOf(knownFilesType), searchDuringIngestFlag, sendIngestMessagesFlag, dbPath)); hashSetNames.add(hashSetName); } @@ -304,7 +304,7 @@ final class HashLookupSettings implements Serializable { private static final long serialVersionUID = 1L; private final String hashSetName; - private final HashDbManager.SleuthkitHashSet.KnownFilesType knownFilesType; + private final HashDbManager.HashDb.KnownFilesType knownFilesType; private boolean searchDuringIngest; private final boolean sendIngestMessages; private final String path; @@ -323,7 +323,7 @@ final class HashLookupSettings implements Serializable { * @param sendIngestMessages Whether or not ingest messages are sent * @param path The path to the db */ - HashDbInfo(String hashSetName, HashDbManager.SleuthkitHashSet.KnownFilesType knownFilesType, boolean searchDuringIngest, boolean sendIngestMessages, String path) { + HashDbInfo(String hashSetName, HashDbManager.HashDb.KnownFilesType knownFilesType, boolean searchDuringIngest, boolean sendIngestMessages, String path) { this.hashSetName = hashSetName; this.knownFilesType = knownFilesType; this.searchDuringIngest = searchDuringIngest; @@ -335,7 +335,7 @@ final class HashLookupSettings implements Serializable { this.dbType = DatabaseType.FILE; } - HashDbInfo(String hashSetName, String version, int referenceSetID, HashDbManager.SleuthkitHashSet.KnownFilesType knownFilesType, boolean readOnly, boolean searchDuringIngest, boolean sendIngestMessages){ + HashDbInfo(String hashSetName, String version, int referenceSetID, HashDbManager.HashDb.KnownFilesType knownFilesType, boolean readOnly, boolean searchDuringIngest, boolean sendIngestMessages){ this.hashSetName = hashSetName; this.version = version; this.referenceSetID = referenceSetID; @@ -407,7 +407,7 @@ final class HashLookupSettings implements Serializable { * * @return The known files type setting. */ - HashDbManager.SleuthkitHashSet.KnownFilesType getKnownFilesType() { + HashDbManager.HashDb.KnownFilesType getKnownFilesType() { return knownFilesType; } diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java index 1f44df404e..880feabcb7 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/ImportCentralRepoDbProgressDialog.java @@ -39,6 +39,7 @@ import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttribute; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb; import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException; import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalFileInstance; +import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalSet; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskData; @@ -77,7 +78,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P } void importFile(String hashSetName, String version, int orgId, - boolean searchDuringIngest, boolean sendIngestMessages, HashDbManager.SleuthkitHashSet.KnownFilesType knownFilesType, + boolean searchDuringIngest, boolean sendIngestMessages, HashDbManager.HashDb.KnownFilesType knownFilesType, boolean readOnly, String importFileName){ setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); @@ -139,7 +140,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P private final int orgId; private final boolean searchDuringIngest; private final boolean sendIngestMessages; - private final HashDbManager.SleuthkitHashSet.KnownFilesType knownFilesType; + private final HashDbManager.HashDb.KnownFilesType knownFilesType; private final boolean readOnly; private final File importFile; private final long totalLines; @@ -148,7 +149,7 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P private final AtomicLong numLines = new AtomicLong(); ImportIDXWorker(String hashSetName, String version, int orgId, - boolean searchDuringIngest, boolean sendIngestMessages, HashDbManager.SleuthkitHashSet.KnownFilesType knownFilesType, + boolean searchDuringIngest, boolean sendIngestMessages, HashDbManager.HashDb.KnownFilesType knownFilesType, boolean readOnly, File importFile){ this.hashSetName = hashSetName; @@ -194,14 +195,14 @@ class ImportCentralRepoDbProgressDialog extends javax.swing.JDialog implements P protected Void doInBackground() throws Exception { TskData.FileKnown knownStatus; - if (knownFilesType.equals(HashDbManager.SleuthkitHashSet.KnownFilesType.KNOWN)) { + if (knownFilesType.equals(HashDbManager.HashDb.KnownFilesType.KNOWN)) { knownStatus = TskData.FileKnown.KNOWN; } else { knownStatus = TskData.FileKnown.BAD; } // Create an empty hashset in the central repository - referenceSetID = EamDb.getInstance().newReferenceSet(orgId, hashSetName, version, knownStatus, readOnly); + referenceSetID = EamDb.getInstance().newReferenceSet(new EamGlobalSet(orgId, hashSetName, version, knownStatus, readOnly)); EamDb dbManager = EamDb.getInstance(); CorrelationAttribute.Type contentType = dbManager.getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID); // get "FILES" type From 5bccb82c685882dab0523fc93de5642957aff3b7 Mon Sep 17 00:00:00 2001 From: Ann Priestman Date: Fri, 17 Nov 2017 09:41:37 -0500 Subject: [PATCH 41/41] Update central repo hashsets automatically when getting known, known bad, or updateable hash sets --- .../modules/hashdatabase/HashDbManager.java | 17 ++++++++++++++++- .../HashLookupModuleSettingsPanel.java | 5 ----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java index 35dd424c39..e8de1893ca 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashDbManager.java @@ -427,6 +427,11 @@ public class HashDbManager implements PropertyChangeListener { */ public synchronized List getKnownFileHashSets() { List hashDbs = new ArrayList<>(); + try{ + updateHashSetsFromCentralRepository(); + } catch (TskCoreException ex){ + Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error loading central repository hash sets", ex); //NON-NLS + } this.hashSets.stream().filter((db) -> (db.getKnownFilesType() == HashDb.KnownFilesType.KNOWN)).forEach((db) -> { hashDbs.add(db); }); @@ -440,6 +445,11 @@ public class HashDbManager implements PropertyChangeListener { */ public synchronized List getKnownBadFileHashSets() { List hashDbs = new ArrayList<>(); + try{ + updateHashSetsFromCentralRepository(); + } catch (TskCoreException ex){ + Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error loading central repository hash sets", ex); //NON-NLS + } this.hashSets.stream().filter((db) -> (db.getKnownFilesType() == HashDb.KnownFilesType.KNOWN_BAD)).forEach((db) -> { hashDbs.add(db); }); @@ -457,6 +467,11 @@ public class HashDbManager implements PropertyChangeListener { private List getUpdateableHashSets(List hashDbs) { ArrayList updateableDbs = new ArrayList<>(); + try{ + updateHashSetsFromCentralRepository(); + } catch (TskCoreException ex){ + Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error loading central repository hash sets", ex); //NON-NLS + } for (HashDb db : hashDbs) { try { if (db.isUpdateable()) { @@ -603,7 +618,7 @@ public class HashDbManager implements PropertyChangeListener { } } - void updateHashSetsFromCentralRepository() throws TskCoreException { + private void updateHashSetsFromCentralRepository() throws TskCoreException { if(EamDb.isEnabled()){ List crHashDbInfoList = getCentralRepoHashSetsFromDatabase(); for(HashDbInfo hashDbInfo : crHashDbInfoList) { diff --git a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java index c6d3e109fe..bbe2a4e7d9 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/hashdatabase/HashLookupModuleSettingsPanel.java @@ -53,11 +53,6 @@ public final class HashLookupModuleSettingsPanel extends IngestModuleIngestJobSe } private void initializeHashSetModels(HashLookupModuleSettings settings) { - try{ - hashDbManager.updateHashSetsFromCentralRepository(); - } catch (TskCoreException ex){ - Logger.getLogger(HashLookupModuleSettingsPanel.class.getName()).log(Level.SEVERE, "Error updating central repository hash sets", ex); //NON-NLS - } initializeHashSetModels(settings, hashDbManager.getKnownFileHashSets(), knownHashSetModels); initializeHashSetModels(settings, hashDbManager.getKnownBadFileHashSets(), knownBadHashSetModels); }