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!"); }