From 9e49241ac0f94de412024ca64aa1f5cea8356c6f Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Sat, 8 Mar 2014 00:23:05 -0500 Subject: [PATCH] Work on ingest framework API --- .../autopsy/ingest/IngestConfigurator.java | 2 +- .../autopsy/ingest/IngestModuleFactory.java | 2 +- .../ingest/IngestModuleFactoryAdapter.java | 2 +- .../FileExtMismatchDetectorModuleFactory.java | 2 +- .../hashdatabase/HashDbConfigPanel.java | 4 +- .../hashdatabase/HashDbSimpleConfigPanel.java | 29 +++--- .../hashdatabase/HashLookupModuleFactory.java | 92 +++++++------------ .../hashdatabase/HashLookupOptions.java | 76 +++++++++++++++ .../KeywordSearchModuleFactory.java | 2 +- 9 files changed, 129 insertions(+), 82 deletions(-) create mode 100755 HashDatabase/src/org/sleuthkit/autopsy/hashdatabase/HashLookupOptions.java diff --git a/Core/src/org/sleuthkit/autopsy/ingest/IngestConfigurator.java b/Core/src/org/sleuthkit/autopsy/ingest/IngestConfigurator.java index e4231da7f2..88e79f2efb 100644 --- a/Core/src/org/sleuthkit/autopsy/ingest/IngestConfigurator.java +++ b/Core/src/org/sleuthkit/autopsy/ingest/IngestConfigurator.java @@ -70,7 +70,7 @@ public class IngestConfigurator { // NOTE: In the future, this code will be modified to get the ingest // options for each module for the current context; for now just // get the default ingest options. - IngestModuleTemplate moduleTemplate = new IngestModuleTemplate(moduleFactory, moduleFactory.getDefaultPerIngestJobOptions()); + IngestModuleTemplate moduleTemplate = new IngestModuleTemplate(moduleFactory, moduleFactory.getDefaultIngestOptions()); String moduleName = moduleTemplate.getIngestModuleFactory().getModuleDisplayName(); if (enabledModuleNames.contains(moduleName)) { moduleTemplate.setEnabled(true); diff --git a/Core/src/org/sleuthkit/autopsy/ingest/IngestModuleFactory.java b/Core/src/org/sleuthkit/autopsy/ingest/IngestModuleFactory.java index 60c1d31500..281265c0e5 100755 --- a/Core/src/org/sleuthkit/autopsy/ingest/IngestModuleFactory.java +++ b/Core/src/org/sleuthkit/autopsy/ingest/IngestModuleFactory.java @@ -82,7 +82,7 @@ public interface IngestModuleFactory { * * @return The ingest options. */ - IngestModuleOptions getDefaultPerIngestJobOptions(); + IngestModuleOptions getDefaultIngestOptions(); /** * Queries the factory to determine if it provides user interface panels to diff --git a/Core/src/org/sleuthkit/autopsy/ingest/IngestModuleFactoryAdapter.java b/Core/src/org/sleuthkit/autopsy/ingest/IngestModuleFactoryAdapter.java index 58fb6b0b0b..555c036ca8 100755 --- a/Core/src/org/sleuthkit/autopsy/ingest/IngestModuleFactoryAdapter.java +++ b/Core/src/org/sleuthkit/autopsy/ingest/IngestModuleFactoryAdapter.java @@ -34,7 +34,7 @@ public abstract class IngestModuleFactoryAdapter implements IngestModuleFactory public abstract String getModuleVersionNumber(); @Override - public IngestModuleOptions getDefaultPerIngestJobOptions() { + public IngestModuleOptions getDefaultIngestOptions() { return new NoIngestOptions(); } diff --git a/FileExtMismatch/src/org/sleuthkit/autopsy/fileextmismatch/FileExtMismatchDetectorModuleFactory.java b/FileExtMismatch/src/org/sleuthkit/autopsy/fileextmismatch/FileExtMismatchDetectorModuleFactory.java index 6211a54549..25c625f0f1 100755 --- a/FileExtMismatch/src/org/sleuthkit/autopsy/fileextmismatch/FileExtMismatchDetectorModuleFactory.java +++ b/FileExtMismatch/src/org/sleuthkit/autopsy/fileextmismatch/FileExtMismatchDetectorModuleFactory.java @@ -44,7 +44,7 @@ public class FileExtMismatchDetectorModuleFactory extends IngestModuleFactoryAda } @Override - public IngestModuleOptions getDefaultPerIngestJobOptions() { + public IngestModuleOptions getDefaultIngestOptions() { return new FileExtMismatchDetectorOptions(); } diff --git a/HashDatabase/src/org/sleuthkit/autopsy/hashdatabase/HashDbConfigPanel.java b/HashDatabase/src/org/sleuthkit/autopsy/hashdatabase/HashDbConfigPanel.java index ac224925e4..c09ee53059 100644 --- a/HashDatabase/src/org/sleuthkit/autopsy/hashdatabase/HashDbConfigPanel.java +++ b/HashDatabase/src/org/sleuthkit/autopsy/hashdatabase/HashDbConfigPanel.java @@ -38,17 +38,17 @@ import javax.swing.table.AbstractTableModel; import javax.swing.table.TableCellRenderer; import org.openide.util.NbBundle; -import org.sleuthkit.autopsy.corecomponents.OptionsPanel; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.ingest.IngestManager; import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.autopsy.hashdatabase.HashDbManager.HashDb; import org.sleuthkit.autopsy.hashdatabase.HashDbManager.HashDb.KnownFilesType; +import org.sleuthkit.autopsy.ingest.IngestModuleResourcesConfigPanel; /** * Instances of this class provide a comprehensive UI for managing the hash sets configuration. */ -public final class HashDbConfigPanel extends javax.swing.JPanel implements OptionsPanel { +public final class HashDbConfigPanel extends IngestModuleResourcesConfigPanel { private static final String NO_SELECTION_TEXT = NbBundle .getMessage(HashDbConfigPanel.class, "HashDbConfigPanel.noSelectionText"); private static final String ERROR_GETTING_PATH_TEXT = NbBundle diff --git a/HashDatabase/src/org/sleuthkit/autopsy/hashdatabase/HashDbSimpleConfigPanel.java b/HashDatabase/src/org/sleuthkit/autopsy/hashdatabase/HashDbSimpleConfigPanel.java index 6ebe04ff03..6fe5cc76f3 100644 --- a/HashDatabase/src/org/sleuthkit/autopsy/hashdatabase/HashDbSimpleConfigPanel.java +++ b/HashDatabase/src/org/sleuthkit/autopsy/hashdatabase/HashDbSimpleConfigPanel.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2011 - 2013 Basis Technology Corp. + * Copyright 2011 - 2014 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,8 +19,6 @@ package org.sleuthkit.autopsy.hashdatabase; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.util.List; import java.util.logging.Level; import javax.swing.JOptionPane; @@ -34,11 +32,13 @@ import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.ingest.IngestManager; import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.autopsy.hashdatabase.HashDbManager.HashDb; +import org.sleuthkit.autopsy.ingest.IngestModuleOptions; +import org.sleuthkit.autopsy.ingest.IngestModuleOptionsPanel; /** * Instances of this class provide a simplified UI for managing the hash sets configuration. */ -public class HashDbSimpleConfigPanel extends javax.swing.JPanel { +public class HashDbSimpleConfigPanel extends IngestModuleOptionsPanel { private HashDatabasesTableModel knownTableModel; private HashDatabasesTableModel knownBadTableModel; @@ -54,16 +54,6 @@ public class HashDbSimpleConfigPanel extends javax.swing.JPanel { customizeHashDbsTable(jScrollPane1, knownHashTable, knownTableModel); customizeHashDbsTable(jScrollPane2, knownBadHashTable, knownBadTableModel); alwaysCalcHashesCheckbox.setSelected(HashDbManager.getInstance().getAlwaysCalculateHashes()); - - // Add a listener to the always calculate hashes checkbox component. - // The listener passes the user's selection on to the hash database manager. - alwaysCalcHashesCheckbox.addActionListener( new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - HashDbManager.getInstance().setAlwaysCalculateHashes(alwaysCalcHashesCheckbox.isSelected()); - } - }); - load(); } @@ -85,6 +75,15 @@ public class HashDbSimpleConfigPanel extends javax.swing.JPanel { } } + @Override + public IngestModuleOptions getIngestOptions() { + // RJCTODO: Work out how this works, load() and store(), etc. + HashDbManager hashDbManager = HashDbManager.getInstance(); + List knownFileHashSets = hashDbManager.getKnownFileHashSets(); + List knownBadFileHashSets = hashDbManager.getKnownBadFileHashSets(); + return new HashLookupOptions(alwaysCalcHashesCheckbox.isSelected(), knownFileHashSets, knownBadFileHashSets); + } + public void load() { knownTableModel.load(); knownBadTableModel.load(); @@ -256,7 +255,7 @@ public class HashDbSimpleConfigPanel extends javax.swing.JPanel { }// //GEN-END:initComponents private void alwaysCalcHashesCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_alwaysCalcHashesCheckboxActionPerformed - // TODO add your handling code here: + HashDbManager.getInstance().setAlwaysCalculateHashes(alwaysCalcHashesCheckbox.isSelected()); }//GEN-LAST:event_alwaysCalcHashesCheckboxActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables diff --git a/HashDatabase/src/org/sleuthkit/autopsy/hashdatabase/HashLookupModuleFactory.java b/HashDatabase/src/org/sleuthkit/autopsy/hashdatabase/HashLookupModuleFactory.java index 59d86a194f..7b174ac4fe 100755 --- a/HashDatabase/src/org/sleuthkit/autopsy/hashdatabase/HashLookupModuleFactory.java +++ b/HashDatabase/src/org/sleuthkit/autopsy/hashdatabase/HashLookupModuleFactory.java @@ -16,107 +16,79 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.sleuthkit.autopsy.hashdatabase; -import java.io.Serializable; -import java.util.ArrayList; -import javax.swing.JPanel; import org.openide.util.NbBundle; import org.openide.util.lookup.ServiceProvider; import org.sleuthkit.autopsy.coreutils.Version; import org.sleuthkit.autopsy.ingest.IngestModuleFactoryAdapter; import org.sleuthkit.autopsy.ingest.FileIngestModule; import org.sleuthkit.autopsy.ingest.IngestModuleFactory; +import org.sleuthkit.autopsy.ingest.IngestModuleOptions; +import org.sleuthkit.autopsy.ingest.IngestModuleOptionsPanel; +import org.sleuthkit.autopsy.ingest.IngestModuleResourcesConfigPanel; /** * A factory that creates file ingest modules that do hash database lookups. */ -@ServiceProvider(service=IngestModuleFactory.class) -public class HashLookupModuleFactory extends IngestModuleFactoryAdapter { +@ServiceProvider(service = IngestModuleFactory.class) +public class HashLookupModuleFactory extends IngestModuleFactoryAdapter { + @Override public String getModuleDisplayName() { return getModuleName(); } - + static String getModuleName() { - return NbBundle.getMessage(HashDbIngestModule.class, "HashDbIngestModule.moduleName"); + return NbBundle.getMessage(HashDbIngestModule.class, "HashDbIngestModule.moduleName"); } - + @Override public String getModuleDescription() { - return NbBundle.getMessage(HashDbIngestModule.class, "HashDbIngestModule.moduleDescription"); + return NbBundle.getMessage(HashDbIngestModule.class, "HashDbIngestModule.moduleDescription"); } - + @Override public String getModuleVersionNumber() { - return Version.getVersion(); + return Version.getVersion(); } - + @Override - public Serializable getDefaultPerIngestJobOptions() { - return new IngestOptions(); + public IngestModuleOptions getDefaultIngestOptions() { + return new HashLookupOptions(); } - + @Override public boolean providesIngestOptionsPanels() { return true; } - - @Override - public JPanel getIngestOptionsPanel(Serializable ingestOptions) { - HashDbSimpleConfigPanel ingestOptionsPanel = new HashDbSimpleConfigPanel(); - ingestOptionsPanel.load(); - return ingestOptionsPanel; - } - - @Override - public Serializable getIngestOptionsFromPanel(JPanel ingestOptionsPanel) throws InvalidOptionsException { - if (!(ingestOptionsPanel instanceof HashDbSimpleConfigPanel)) { - throw new IllegalArgumentException("JPanel not a HashDbSimpleConfigPanel"); - } - HashDbSimpleConfigPanel panel = (HashDbSimpleConfigPanel)ingestOptionsPanel; - panel.store(); - - return new IngestOptions(); // RJCTODO + @Override + public IngestModuleOptionsPanel getIngestOptionsPanel(IngestModuleOptions ingestOptions) { + HashDbSimpleConfigPanel ingestOptionsPanel = new HashDbSimpleConfigPanel(); + ingestOptionsPanel.load(); + return ingestOptionsPanel; } - + @Override public boolean providesResourcesConfigPanels() { - return true; + return true; } - + @Override - public JPanel getGlobalOptionsPanel() { - HashDbConfigPanel globalOptionsPanel = new HashDbConfigPanel(); - globalOptionsPanel.load(); - return globalOptionsPanel; - } - - @Override - public void saveGlobalOptionsFromPanel(JPanel globalOptionsPanel) throws InvalidOptionsException { - if (!(globalOptionsPanel instanceof HashDbConfigPanel)) { - throw new IllegalArgumentException("JPanel not a HashDbConfigPanel"); - } - - HashDbConfigPanel panel = (HashDbConfigPanel)globalOptionsPanel; - panel.store(); + public IngestModuleResourcesConfigPanel getResourcesConfigPanel() { + HashDbConfigPanel resourcesConfigPanel = new HashDbConfigPanel(); + resourcesConfigPanel.load(); + return resourcesConfigPanel; } - + @Override public boolean isFileIngestModuleFactory() { - return true; + return true; } - + @Override - public FileIngestModule createFileIngestModule(Serializable ingestOptions) throws InvalidOptionsException { + public FileIngestModule createFileIngestModule(IngestModuleOptions ingestOptions) throws InvalidOptionsException { return new HashDbIngestModule(); } - - private static class IngestOptions implements Serializable { - // RJCTODO: fill out - boolean alwaysCalcHashes = true; - ArrayList hashSetNames = new ArrayList<>(); - } } diff --git a/HashDatabase/src/org/sleuthkit/autopsy/hashdatabase/HashLookupOptions.java b/HashDatabase/src/org/sleuthkit/autopsy/hashdatabase/HashLookupOptions.java new file mode 100755 index 0000000000..a16a8b8fcc --- /dev/null +++ b/HashDatabase/src/org/sleuthkit/autopsy/hashdatabase/HashLookupOptions.java @@ -0,0 +1,76 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2014 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.hashdatabase; + +import java.util.ArrayList; +import java.util.List; +import org.sleuthkit.autopsy.ingest.IngestModuleOptions; + +/** + * Ingest options for the hash lookup file ingest module. + */ +// Note that this class is not yet used as intended. +public class HashLookupOptions implements IngestModuleOptions { + + private boolean shouldCalculateHashes = true; + private ArrayList knownFileHashSets; + private ArrayList knownBadFileHashSets; + + HashLookupOptions() { + shouldCalculateHashes = true; + knownFileHashSets = new ArrayList<>(); + knownBadFileHashSets = new ArrayList<>(); + } + + HashLookupOptions(boolean shouldCalculateHashes, List knownFileHashSets, List knownBadFileHashSets) { + this.shouldCalculateHashes = shouldCalculateHashes; + this.knownFileHashSets = new ArrayList<>(knownFileHashSets); + this.knownBadFileHashSets = new ArrayList<>(knownBadFileHashSets); + } + + @Override + public boolean areValid() { + // RJCTODO: Verify that hash sets are present in hash db manager + return true; + } + + boolean shouldCalculateHashes() { + return shouldCalculateHashes; + } + + void setShouldCalculateHashes(boolean shouldCalculateHashes) { + this.shouldCalculateHashes = shouldCalculateHashes; + } + + List getKnownFileHashSets() { + return new ArrayList<>(knownFileHashSets); + } + + void setKnownFileHashSets(List hashSets) { + knownFileHashSets = new ArrayList<>(hashSets); + } + + List getKnownBadFileHashSets() { + return new ArrayList<>(knownBadFileHashSets); + } + + void setKnownBadFileHashSets(List hashSets) { + knownBadFileHashSets = new ArrayList<>(hashSets); + } +} diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchModuleFactory.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchModuleFactory.java index 480beb57d8..d935540a34 100755 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchModuleFactory.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchModuleFactory.java @@ -54,7 +54,7 @@ public class KeywordSearchModuleFactory extends IngestModuleFactoryAdapter { } @Override - public Serializable getDefaultPerIngestJobOptions() { + public Serializable getDefaultIngestOptions() { return new IngestOptions(); }