From e0a75cf9fb992ae0beeab853584152aea44fd7a2 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Fri, 19 Aug 2016 11:37:58 -0400 Subject: [PATCH] AutomatedIngestDataSourceProcessor interface methods throw exception --- .../autopsy/casemodule/Bundle.properties | 1 + .../autopsy/casemodule/ImageDSProcessor.java | 10 ++--- .../casemodule/LocalFilesDSProcessor.java | 4 +- .../AutomatedIngestDataSourceProcessor.java | 28 +++++++++++-- .../autoingest/AutoIngestManager.java | 15 +++++-- .../datasourceprocessors/Bundle.properties | 1 + .../CellebriteLogicalReportProcessor.java | 4 +- .../CellebritePhysicalReportProcessor.java | 41 ++++++++++--------- 8 files changed, 69 insertions(+), 35 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties index 3f59ed542f..972e3323fe 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties @@ -160,6 +160,7 @@ GeneralFilter.encaseImageDesc.text=Encase Images (*.e01) GeneralFilter.virtualMachineImageDesc.text=Virtual Machines (*.vmdk, *.vhd) ImageDSProcessor.dsType.text=Image or VM File ImageDSProcessor.allDesc.text=All Supported Types +ImageDSProcessor.canProcess.exception.text=Exception inside canProcess() method ImageFilePanel.moduleErr=Module Error ImageFilePanel.moduleErr.msg=A module caused an error listening to ImageFilePanel updates. See log to determine which module. Some data could be incomplete. LocalDiskDSProcessor.dsType.text=Local Disk diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/ImageDSProcessor.java b/Core/src/org/sleuthkit/autopsy/casemodule/ImageDSProcessor.java index 5ac967fbbd..1cf6d71fba 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/ImageDSProcessor.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/ImageDSProcessor.java @@ -248,7 +248,7 @@ public class ImageDSProcessor implements AutomatedIngestDataSourceProcessor { } @Override - public int canProcess(Path dataSourcePath) { + public int canProcess(Path dataSourcePath) throws AutomatedIngestDataSourceProcessorException { // check file extension for supported types if (!isAcceptedByFiler(dataSourcePath.toFile(), filtersList)) { @@ -262,9 +262,8 @@ public class ImageDSProcessor implements AutomatedIngestDataSourceProcessor { // image does not have a file system that TSK can process return 0; } - } catch (Exception ignore) { - // ELTODO do we want to have error message here? - return 0; + } catch (Exception ex) { + throw new AutomatedIngestDataSourceProcessorException(NbBundle.getMessage(ImageDSProcessor.class, "ImageDSProcessor.canProcess.exception.text"), ex); } // able to process the data source @@ -272,8 +271,7 @@ public class ImageDSProcessor implements AutomatedIngestDataSourceProcessor { } @Override - public void process(String deviceId, Path dataSourcePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack) { - + public void process(String deviceId, Path dataSourcePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack) throws AutomatedIngestDataSourceProcessorException { this.deviceId = deviceId; this.imagePath = dataSourcePath.toString(); this.timeZone = Calendar.getInstance().getTimeZone().getID(); diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesDSProcessor.java b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesDSProcessor.java index 2bc7ecedac..a47dc74840 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesDSProcessor.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/LocalFilesDSProcessor.java @@ -205,7 +205,7 @@ public class LocalFilesDSProcessor implements AutomatedIngestDataSourceProcessor } @Override - public int canProcess(Path dataSourcePath) { + public int canProcess(Path dataSourcePath) throws AutomatedIngestDataSourceProcessorException { // Local files DSP can process any file by simply adding it as a logical file. // It should return lowest possible non-zero confidence level and be treated // as the "option of last resort" for auto ingest purposes @@ -213,7 +213,7 @@ public class LocalFilesDSProcessor implements AutomatedIngestDataSourceProcessor } @Override - public void process(String deviceId, Path dataSourcePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack) { + public void process(String deviceId, Path dataSourcePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack) throws AutomatedIngestDataSourceProcessorException { this.localFilePaths = Arrays.asList(new String[]{dataSourcePath.toString()}); run(deviceId, AUTO_INGEST_VIRTUAL_DIR_NAME, this.localFilePaths, progressMonitor, callBack); } diff --git a/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/AutomatedIngestDataSourceProcessor.java b/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/AutomatedIngestDataSourceProcessor.java index e1a6e5bbe1..219fd7d860 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/AutomatedIngestDataSourceProcessor.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/AutomatedIngestDataSourceProcessor.java @@ -26,7 +26,7 @@ import java.nio.file.Path; * * @author elivis */ -public interface AutomatedIngestDataSourceProcessor extends DataSourceProcessor{ +public interface AutomatedIngestDataSourceProcessor extends DataSourceProcessor { /** * Indicates whether the DataSourceProcessor is capable of processing the @@ -38,8 +38,11 @@ public interface AutomatedIngestDataSourceProcessor extends DataSourceProcessor{ * or less means the data source is not supported by the * DataSourceProcessor. Value of 100 indicates high certainty in * being able to process the data source. + * + * @throws + * org.sleuthkit.autopsy.corecomponentinterfaces.AutomatedIngestDataSourceProcessor.AutomatedIngestDataSourceProcessorException */ - int canProcess(Path dataSourcePath); + int canProcess(Path dataSourcePath) throws AutomatedIngestDataSourceProcessorException; /** * @@ -51,6 +54,25 @@ public interface AutomatedIngestDataSourceProcessor extends DataSourceProcessor{ * background task to report progress. * @param callBack Callback that will be used by the background task * to return results. + * + * @throws + * org.sleuthkit.autopsy.corecomponentinterfaces.AutomatedIngestDataSourceProcessor.AutomatedIngestDataSourceProcessorException */ - void process(String deviceId, Path dataSourcePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack); + void process(String deviceId, Path dataSourcePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack) throws AutomatedIngestDataSourceProcessorException; + + /** + * A custom exception for the use of AutomatedIngestDataSourceProcessor. + */ + public class AutomatedIngestDataSourceProcessorException extends Exception { + + private static final long serialVersionUID = 1L; + + public AutomatedIngestDataSourceProcessorException(String message) { + super(message); + } + + public AutomatedIngestDataSourceProcessorException(String message, Throwable cause) { + super(message, cause); + } + } } diff --git a/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestManager.java b/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestManager.java index e12a725c78..23392bbdd1 100644 --- a/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestManager.java +++ b/Experimental/src/org/sleuthkit/autopsy/experimental/autoingest/AutoIngestManager.java @@ -2103,7 +2103,12 @@ public final class AutoIngestManager extends Observable implements PropertyChang AutomatedIngestDataSourceProcessor selectedProcessor = null; int selectedProcessorConfidence = 0; for (AutomatedIngestDataSourceProcessor processor : processorCandidates) { - int confidence = processor.canProcess(dataSource.getPath()); + int confidence = 0; + try { + confidence = processor.canProcess(dataSource.getPath()); + } catch (AutomatedIngestDataSourceProcessor.AutomatedIngestDataSourceProcessorException ex) { + // ELTODO : log and auto-pause + } if (confidence > selectedProcessorConfidence) { selectedProcessor = processor; selectedProcessorConfidence = confidence; @@ -2119,8 +2124,12 @@ public final class AutoIngestManager extends Observable implements PropertyChang synchronized (ingestLock) { LOGGER.log(Level.INFO, "Identified data source type for {0} as {1}", new Object[]{manifestPath, selectedProcessor.getDataSourceType()}); - // ELTODO add sys log and possibly case log entries here - selectedProcessor.process(dataSource.getDeviceId(), dataSource.getPath(), progressMonitor, callBack); + try { + // ELTODO add sys log and possibly case log entries here + selectedProcessor.process(dataSource.getDeviceId(), dataSource.getPath(), progressMonitor, callBack); + } catch (AutomatedIngestDataSourceProcessor.AutomatedIngestDataSourceProcessorException ex) { + // ELTODO : log and auto-pause + } ingestLock.wait(); } } finally { diff --git a/Experimental/src/org/sleuthkit/autopsy/experimental/cellex/datasourceprocessors/Bundle.properties b/Experimental/src/org/sleuthkit/autopsy/experimental/cellex/datasourceprocessors/Bundle.properties index 6407c8566a..cc4b5407c5 100644 --- a/Experimental/src/org/sleuthkit/autopsy/experimental/cellex/datasourceprocessors/Bundle.properties +++ b/Experimental/src/org/sleuthkit/autopsy/experimental/cellex/datasourceprocessors/Bundle.properties @@ -25,3 +25,4 @@ CellebriteLogicalReportPanel.jLabel1.text=Input type: CellebriteLogicalReportPanel.jHandsetRadioButton.text=Handset CellebriteLogicalReportPanel.browseButton.text=Browse CellebriteLogicalReportPanel.pathTextField.text= +CellebritePhysicalReportProcessor.canProcess.exception.text=Exception inside canProcess() method diff --git a/Experimental/src/org/sleuthkit/autopsy/experimental/cellex/datasourceprocessors/CellebriteLogicalReportProcessor.java b/Experimental/src/org/sleuthkit/autopsy/experimental/cellex/datasourceprocessors/CellebriteLogicalReportProcessor.java index 17c4f28e93..a1fe31f961 100644 --- a/Experimental/src/org/sleuthkit/autopsy/experimental/cellex/datasourceprocessors/CellebriteLogicalReportProcessor.java +++ b/Experimental/src/org/sleuthkit/autopsy/experimental/cellex/datasourceprocessors/CellebriteLogicalReportProcessor.java @@ -250,7 +250,7 @@ public class CellebriteLogicalReportProcessor implements AutomatedIngestDataSour } @Override - public int canProcess(Path dataSourcePath) { + public int canProcess(Path dataSourcePath) throws AutomatedIngestDataSourceProcessorException { ReportType type = parseCellebriteLogicalReportType(dataSourcePath); switch (type) { case CELLEBRITE_LOGICAL_HANDSET: @@ -263,7 +263,7 @@ public class CellebriteLogicalReportProcessor implements AutomatedIngestDataSour } @Override - public void process(String deviceId, Path dataSourcePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack) { + public void process(String deviceId, Path dataSourcePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack) throws AutomatedIngestDataSourceProcessorException { ReportType type = parseCellebriteLogicalReportType(dataSourcePath); boolean isHandsetFile = false; switch (type) { diff --git a/Experimental/src/org/sleuthkit/autopsy/experimental/cellex/datasourceprocessors/CellebritePhysicalReportProcessor.java b/Experimental/src/org/sleuthkit/autopsy/experimental/cellex/datasourceprocessors/CellebritePhysicalReportProcessor.java index 41c03c7ead..34635380aa 100644 --- a/Experimental/src/org/sleuthkit/autopsy/experimental/cellex/datasourceprocessors/CellebritePhysicalReportProcessor.java +++ b/Experimental/src/org/sleuthkit/autopsy/experimental/cellex/datasourceprocessors/CellebritePhysicalReportProcessor.java @@ -37,7 +37,7 @@ import java.util.zip.ZipFile; import javax.swing.JPanel; import javax.swing.filechooser.FileFilter; import org.apache.commons.io.FilenameUtils; -import org.openide.util.Exceptions; +import org.openide.util.NbBundle; import org.openide.util.lookup.ServiceProvider; import org.openide.util.lookup.ServiceProviders; import org.sleuthkit.autopsy.casemodule.Case; @@ -256,19 +256,7 @@ public class CellebritePhysicalReportProcessor implements AutomatedIngestDataSou private static boolean isValidDataSource(Path dataSourcePath) { - String fileName = dataSourcePath.getFileName().toString(); - - // check whether it's a zip archive file - if (isAcceptedByFiler(new File(fileName), archiveFilters)) { - try { - Case currentCase = Case.getCurrentCase(); - Path extractedDataSource = extractDataSource(Paths.get(currentCase.getModuleDirectory()), dataSourcePath); - } catch (Exception ex) { - // ELTODO add log here? - return false; - } - } - + String fileName = dataSourcePath.getFileName().toString(); // is it a ".bin" image if (!isAcceptedByFiler(new File(fileName), cellebriteImageFiltersList)) { return false; @@ -298,12 +286,27 @@ public class CellebritePhysicalReportProcessor implements AutomatedIngestDataSou } } return false; - } + } + + private static boolean isArchive(Path dataSourcePath) throws AutomatedIngestDataSourceProcessorException { + + String fileName = dataSourcePath.getFileName().toString(); + // check whether it's a zip archive file + if (isAcceptedByFiler(new File(fileName), archiveFilters)) { + try { + Case currentCase = Case.getCurrentCase(); + Path extractedDataSource = extractDataSource(Paths.get(currentCase.getModuleDirectory()), dataSourcePath); + } catch (Exception ex) { + throw new AutomatedIngestDataSourceProcessorException(NbBundle.getMessage(CellebritePhysicalReportProcessor.class, "CellebritePhysicalReportProcessor.canProcess.exception.text"), ex); + } + } + return true; + } @Override - public int canProcess(Path dataSourcePath) { - // check whether this is a ".bin" file - if (isValidDataSource(dataSourcePath)) { + public int canProcess(Path dataSourcePath) throws AutomatedIngestDataSourceProcessorException { + // check whether this is an archive or a ".bin" file + if (isArchive(dataSourcePath) || isValidDataSource(dataSourcePath)) { // return "high confidence" value return 90; } @@ -311,7 +314,7 @@ public class CellebritePhysicalReportProcessor implements AutomatedIngestDataSou } @Override - public void process(String deviceId, Path dataSourcePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack) { + public void process(String deviceId, Path dataSourcePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack) throws AutomatedIngestDataSourceProcessorException { List dataSourcePathList = Arrays.asList(new String[]{dataSourcePath.toString()}); // in this particular case we don't want to call run() method as it will try to identify and process all ".bin" files in data source folder addImagesTask = new AddCellebritePhysicalReportTask(deviceId, dataSourcePathList, "", progressMonitor, callBack);