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