fixes for ingest module

This commit is contained in:
Greg DiCristofaro 2022-05-13 15:31:31 -04:00
parent a630a0f088
commit 27ba196a21
2 changed files with 47 additions and 21 deletions

View File

@ -63,7 +63,7 @@ public final class IngestJobSettings {
private String executionContext; private String executionContext;
private FilesSet fileFilter; private FilesSet fileFilter;
private String moduleSettingsFolderPath; private String moduleSettingsFolderPath;
/** /**
* @return The base path to module settings. * @return The base path to module settings.
@ -73,6 +73,19 @@ public final class IngestJobSettings {
return MODULE_SETTINGS_FOLDER_PATH; return MODULE_SETTINGS_FOLDER_PATH;
} }
/**
* Returns the string to use with ModuleSettings for resource identification.
* @param executionContext The execution context.
* @return
*/
private static String getModuleSettingsResource(String executionContext) {
return Paths.get(MODULE_SETTINGS_FOLDER, executionContext).toString();
}
/** /**
* Gets the path to the module settings folder for a given execution * Gets the path to the module settings folder for a given execution
* context. * context.
@ -81,12 +94,12 @@ public final class IngestJobSettings {
* the Run Ingest Modules dialog, and auto ingest. Different execution * the Run Ingest Modules dialog, and auto ingest. Different execution
* contexts may have different ingest job settings. * contexts may have different ingest job settings.
* *
* @param The execution context identifier. * @param executionContext The execution context identifier.
* *
* @return The path to the module settings folder * @return The path to the module settings folder
*/ */
static Path getSavedModuleSettingsFolder(String executionContext) { static Path getSavedModuleSettingsFolder(String executionContext) {
return Paths.get(IngestJobSettings.MODULE_SETTINGS_FOLDER_PATH, executionContext); return Paths.get(getBaseModuleSettingsPath(), executionContext);
} }
/** /**
@ -178,7 +191,7 @@ public final class IngestJobSettings {
* @return The path to the ingest module settings folder. * @return The path to the ingest module settings folder.
*/ */
public Path getSavedModuleSettingsFolder() { public Path getSavedModuleSettingsFolder() {
return Paths.get(IngestJobSettings.MODULE_SETTINGS_FOLDER_PATH, executionContext); return Paths.get(getBaseModuleSettingsPath(), executionContext);
} }
/** /**
@ -358,8 +371,8 @@ public final class IngestJobSettings {
* Get the enabled/disabled ingest modules settings for this context. By * Get the enabled/disabled ingest modules settings for this context. By
* default, all loaded modules except Plaso are enabled. * default, all loaded modules except Plaso are enabled.
*/ */
HashSet<String> enabledModuleNames = getModulesNames(executionContext, IngestJobSettings.ENABLED_MODULES_PROPERTY, makeCsvList(loadedModuleNames)); HashSet<String> enabledModuleNames = getModulesNames(this.executionContext, IngestJobSettings.ENABLED_MODULES_PROPERTY, makeCsvList(loadedModuleNames));
HashSet<String> disabledModuleNames = getModulesNames(executionContext, IngestJobSettings.DISABLED_MODULES_PROPERTY, plasoModuleName); //NON-NLS HashSet<String> disabledModuleNames = getModulesNames(this.executionContext, IngestJobSettings.DISABLED_MODULES_PROPERTY, plasoModuleName); //NON-NLS
// If plaso was loaded, but appears in neither the enabled nor the // If plaso was loaded, but appears in neither the enabled nor the
// disabled list, add it to the disabled list. // disabled list, add it to the disabled list.
@ -419,14 +432,15 @@ public final class IngestJobSettings {
* Update the enabled/disabled ingest module settings for this context * Update the enabled/disabled ingest module settings for this context
* to reflect any missing modules or newly discovered modules. * to reflect any missing modules or newly discovered modules.
*/ */
ModuleSettings.setConfigSetting(this.executionContext, IngestJobSettings.ENABLED_MODULES_PROPERTY, makeCsvList(enabledModuleNames)); String ingestModuleResource = getModuleSettingsResource(this.executionContext);
ModuleSettings.setConfigSetting(this.executionContext, IngestJobSettings.DISABLED_MODULES_PROPERTY, makeCsvList(disabledModuleNames)); ModuleSettings.setConfigSetting(ingestModuleResource, IngestJobSettings.ENABLED_MODULES_PROPERTY, makeCsvList(enabledModuleNames));
ModuleSettings.setConfigSetting(ingestModuleResource, IngestJobSettings.DISABLED_MODULES_PROPERTY, makeCsvList(disabledModuleNames));
/** /**
* Restore the last used File Ingest Filter * Restore the last used File Ingest Filter
*/ */
if (ModuleSettings.settingExists(this.executionContext, IngestJobSettings.LAST_FILE_INGEST_FILTER_PROPERTY) == false) { if (ModuleSettings.settingExists(ingestModuleResource, IngestJobSettings.LAST_FILE_INGEST_FILTER_PROPERTY) == false) {
ModuleSettings.setConfigSetting(this.executionContext, IngestJobSettings.LAST_FILE_INGEST_FILTER_PROPERTY, FilesSetsManager.getDefaultFilter().getName()); ModuleSettings.setConfigSetting(ingestModuleResource, IngestJobSettings.LAST_FILE_INGEST_FILTER_PROPERTY, FilesSetsManager.getDefaultFilter().getName());
} }
try { try {
Map<String, FilesSet> fileIngestFilters = FilesSetsManager.getInstance() Map<String, FilesSet> fileIngestFilters = FilesSetsManager.getInstance()
@ -434,7 +448,7 @@ public final class IngestJobSettings {
for (FilesSet fSet : FilesSetsManager.getStandardFileIngestFilters()) { for (FilesSet fSet : FilesSetsManager.getStandardFileIngestFilters()) {
fileIngestFilters.put(fSet.getName(), fSet); fileIngestFilters.put(fSet.getName(), fSet);
} }
this.fileFilter = fileIngestFilters.get(ModuleSettings.getConfigSetting(this.executionContext, IngestJobSettings.LAST_FILE_INGEST_FILTER_PROPERTY)); this.fileFilter = fileIngestFilters.get(ModuleSettings.getConfigSetting(ingestModuleResource, IngestJobSettings.LAST_FILE_INGEST_FILTER_PROPERTY));
} catch (FilesSetsManager.FilesSetsManagerException ex) { } catch (FilesSetsManager.FilesSetsManagerException ex) {
this.fileFilter = FilesSetsManager.getDefaultFilter(); this.fileFilter = FilesSetsManager.getDefaultFilter();
logger.log(Level.SEVERE, "Failed to get file filter from .properties file, default filter being used", ex); //NON-NLS logger.log(Level.SEVERE, "Failed to get file filter from .properties file, default filter being used", ex); //NON-NLS
@ -453,11 +467,12 @@ public final class IngestJobSettings {
* @return * @return
*/ */
private static HashSet<String> getModulesNames(String executionContext, String propertyName, String defaultSetting) { private static HashSet<String> getModulesNames(String executionContext, String propertyName, String defaultSetting) {
if (ModuleSettings.settingExists(executionContext, propertyName) == false) { String ingestModuleResource = getModuleSettingsResource(executionContext);
ModuleSettings.setConfigSetting(executionContext, propertyName, defaultSetting); if (ModuleSettings.settingExists(ingestModuleResource, propertyName) == false) {
ModuleSettings.setConfigSetting(ingestModuleResource, propertyName, defaultSetting);
} }
HashSet<String> moduleNames = new HashSet<>(); HashSet<String> moduleNames = new HashSet<>();
String modulesSetting = ModuleSettings.getConfigSetting(executionContext, propertyName); String modulesSetting = ModuleSettings.getConfigSetting(ingestModuleResource, propertyName);
if (!modulesSetting.isEmpty()) { if (!modulesSetting.isEmpty()) {
String[] settingNames = modulesSetting.split(", "); String[] settingNames = modulesSetting.split(", ");
for (String name : settingNames) { for (String name : settingNames) {
@ -502,8 +517,8 @@ public final class IngestJobSettings {
* Gets a set which contains all the names of enabled modules for the * Gets a set which contains all the names of enabled modules for the
* specified context. * specified context.
* *
* @param context -the execution context (profile name) to check * @param context -the execution context (profile name) to check.
* *
* @return the names of the enabled modules * @return the names of the enabled modules
*/ */
static List<String> getEnabledModules(String context) { static List<String> getEnabledModules(String context) {
@ -582,13 +597,15 @@ public final class IngestJobSettings {
disabledModuleNames.add(moduleName); disabledModuleNames.add(moduleName);
} }
} }
ModuleSettings.setConfigSetting(this.executionContext, IngestJobSettings.ENABLED_MODULES_PROPERTY, makeCsvList(enabledModuleNames));
ModuleSettings.setConfigSetting(this.executionContext, IngestJobSettings.DISABLED_MODULES_PROPERTY, makeCsvList(disabledModuleNames)); String ingestModuleResource = getModuleSettingsResource(this.executionContext);
ModuleSettings.setConfigSetting(ingestModuleResource, IngestJobSettings.ENABLED_MODULES_PROPERTY, makeCsvList(enabledModuleNames));
ModuleSettings.setConfigSetting(ingestModuleResource, IngestJobSettings.DISABLED_MODULES_PROPERTY, makeCsvList(disabledModuleNames));
/** /**
* Save the last used File Ingest Filter setting for this context. * Save the last used File Ingest Filter setting for this context.
*/ */
ModuleSettings.setConfigSetting(this.executionContext, LAST_FILE_INGEST_FILTER_PROPERTY, fileFilter.getName()); ModuleSettings.setConfigSetting(ingestModuleResource, LAST_FILE_INGEST_FILTER_PROPERTY, fileFilter.getName());
} }
/** /**

View File

@ -39,13 +39,14 @@ import org.openide.util.io.NbObjectOutputStream;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.PlatformUtil; import org.sleuthkit.autopsy.coreutils.PlatformUtil;
import org.sleuthkit.autopsy.report.GeneralReportSettings; import org.sleuthkit.autopsy.report.GeneralReportSettings;
import com.google.common.annotations.Beta;
/** /**
* Utility class responsible for managing serialization and deserialization of * Utility class responsible for managing serialization and deserialization of
* all of the settings that make up a reporting configuration in an atomic, * all of the settings that make up a reporting configuration in an atomic,
* thread safe way. * thread safe way.
*/ */
final class ReportingConfigLoader { public final class ReportingConfigLoader {
private static final Logger logger = Logger.getLogger(ReportingConfigLoader.class.getName()); private static final Logger logger = Logger.getLogger(ReportingConfigLoader.class.getName());
private static final String REPORT_CONFIG_FOLDER = "ReportingConfigs"; //NON-NLS private static final String REPORT_CONFIG_FOLDER = "ReportingConfigs"; //NON-NLS
@ -61,6 +62,14 @@ final class ReportingConfigLoader {
// existing in the configuration file. // existing in the configuration file.
private static final List<String> DELETED_REPORT_MODULES = Arrays.asList("org.sleuthkit.autopsy.report.modules.stix.STIXReportModule"); private static final List<String> DELETED_REPORT_MODULES = Arrays.asList("org.sleuthkit.autopsy.report.modules.stix.STIXReportModule");
/**
* @return The base path for reports.
*/
@Beta
public static String getBaseReportPath() {
return REPORT_CONFIG_FOLDER_PATH;
}
/** /**
* Deserialize all of the settings that make up a reporting configuration in * Deserialize all of the settings that make up a reporting configuration in
* an atomic, thread safe way. * an atomic, thread safe way.