Made reference set methods less hash-specific

This commit is contained in:
Ann Priestman 2017-11-15 09:08:29 -05:00
parent 8a63c5aa15
commit 156970c9e5
4 changed files with 45 additions and 18 deletions

View File

@ -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 * @param referenceSetID
* @throws EamDbException * @throws EamDbException
*/ */
@Override @Override
public void deleteReferenceSet(int referenceSetID) throws EamDbException{ public void deleteReferenceSet(int referenceSetID) throws EamDbException{
deleteReferenceSetFiles(referenceSetID); deleteReferenceSetEntries(referenceSetID);
deleteReferenceSetEntry(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 * @param referenceSetID
* @throws EamDbException * @throws EamDbException
*/ */
private void deleteReferenceSetFiles(int referenceSetID) throws EamDbException{ private void deleteReferenceSetEntries(int referenceSetID) throws EamDbException{
Connection conn = connect(); Connection conn = connect();
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
String sql = "DELETE FROM %s WHERE reference_set_id=?"; 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)); String fileTableName = EamDbUtil.correlationTypeToReferenceTableName(getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID));
try { try {
@ -1312,29 +1314,43 @@ public abstract class AbstractSqlEamDb implements EamDb {
/** /**
* Check whether the given reference set exists in the central repository. * Check whether the given reference set exists in the central repository.
* @param referenceSetID * @param referenceSetID
* @param hashSetName * @param setName
* @param version * @param version
* @return true if a matching entry exists in the central repository * @return true if a matching entry exists in the central repository
* @throws EamDbException * @throws EamDbException
*/ */
@Override @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); EamGlobalSet refSet = this.getReferenceSetByID(referenceSetID);
if(refSet == null){ if(refSet == null){
return false; 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 hash
* @param referenceSetID * @param referenceSetID
* @return true if the hash is found in the reference set * @return true if the hash is found in the reference set
* @throws EamDbException
*/ */
@Override @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(); Connection conn = connect();
@ -1343,11 +1359,11 @@ public abstract class AbstractSqlEamDb implements EamDb {
ResultSet resultSet = null; ResultSet resultSet = null;
String sql = "SELECT count(*) FROM %s WHERE value=? AND reference_set_id=?"; 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 { try {
preparedStatement = conn.prepareStatement(String.format(sql, fileTableName)); preparedStatement = conn.prepareStatement(String.format(sql, fileTableName));
preparedStatement.setString(1, hash); preparedStatement.setString(1, value);
preparedStatement.setInt(2, referenceSetID); preparedStatement.setInt(2, referenceSetID);
resultSet = preparedStatement.executeQuery(); resultSet = preparedStatement.executeQuery();
resultSet.next(); resultSet.next();

View File

@ -380,12 +380,23 @@ public interface EamDb {
public boolean referenceSetExists(String hashSetName, String version) throws EamDbException; 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 hash
* @param referenceSetID * @param referenceSetID
* @return true if the hash is found in the reference set * @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? * Is the artifact known as bad according to the reference entries?

View File

@ -657,10 +657,10 @@ public class SqliteEamDb extends AbstractSqlEamDb {
* @return true if the hash is found in the reference set * @return true if the hash is found in the reference set
*/ */
@Override @Override
public boolean isHashInReferenceSet(String hash, int referenceSetID) throws EamDbException{ public boolean isValueInReferenceSet(String value, int referenceSetID, int correlationTypeID) throws EamDbException {
try{ try{
acquireSharedLock(); acquireSharedLock();
return super.isHashInReferenceSet(hash, referenceSetID); return super.isValueInReferenceSet(value, referenceSetID, correlationTypeID);
} finally { } finally {
releaseSharedLock(); releaseSharedLock();
} }

View File

@ -1240,7 +1240,7 @@ public class HashDbManager implements PropertyChangeListener {
AbstractFile file = (AbstractFile) content; AbstractFile file = (AbstractFile) content;
if (null != file.getMd5Hash()) { if (null != file.getMd5Hash()) {
try{ try{
return EamDb.getInstance().isHashInReferenceSet(file.getMd5Hash(), this.referenceSetID); return EamDb.getInstance().isFileHashInReferenceSet(file.getMd5Hash(), this.referenceSetID);
} catch (EamDbException ex){ } catch (EamDbException ex){
Logger.getLogger(SleuthkitHashSet.class.getName()).log(Level.SEVERE, "Error performing central reposiotry hash lookup", ex); //NON-NLS 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); throw new TskCoreException("Error performing central reposiotry hash lookup", ex);
@ -1268,7 +1268,7 @@ public class HashDbManager implements PropertyChangeListener {
AbstractFile file = (AbstractFile) content; AbstractFile file = (AbstractFile) content;
if (null != file.getMd5Hash()) { if (null != file.getMd5Hash()) {
try{ try{
if(EamDb.getInstance().isHashInReferenceSet(file.getMd5Hash(), this.referenceSetID)){ if(EamDb.getInstance().isFileHashInReferenceSet(file.getMd5Hash(), this.referenceSetID)){
// Make a bare-bones HashHitInfo for now // Make a bare-bones HashHitInfo for now
result = new HashHitInfo(file.getMd5Hash(), "", ""); result = new HashHitInfo(file.getMd5Hash(), "", "");
} }