mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-17 10:17:41 +00:00
Store read only flag and database type in central repo.
This commit is contained in:
parent
c43c8548a1
commit
b458d00507
@ -36,6 +36,7 @@ import java.util.Set;
|
||||
import org.sleuthkit.autopsy.casemodule.Case;
|
||||
|
||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||
import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager;
|
||||
import org.sleuthkit.datamodel.TskData;
|
||||
|
||||
/**
|
||||
@ -1501,12 +1502,15 @@ public abstract class AbstractSqlEamDb implements EamDb {
|
||||
* @throws EamDbException
|
||||
*/
|
||||
@Override
|
||||
public int newReferenceSet(int orgID, String setName, String version) throws EamDbException {
|
||||
public int newReferenceSet(int orgID, String setName, String version, TskData.FileKnown knownStatus,
|
||||
boolean isReadOnly) throws EamDbException {
|
||||
EamDb dbManager = EamDb.getInstance();
|
||||
EamGlobalSet eamGlobalSet = new EamGlobalSet(
|
||||
orgID,
|
||||
setName,
|
||||
version,
|
||||
knownStatus,
|
||||
isReadOnly,
|
||||
LocalDate.now());
|
||||
return dbManager.newReferencelSet(eamGlobalSet);
|
||||
}
|
||||
@ -1527,15 +1531,17 @@ 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, import_date) VALUES (?, ?, ?, ?)";
|
||||
String sql2 = "SELECT id FROM reference_sets WHERE org_id=? AND set_name=? AND version=? 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 read_only=? AND known_status=? 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.setString(4, eamGlobalSet.getImportDate().toString());
|
||||
preparedStatement1.setInt(4, eamGlobalSet.getKnownStatus().getFileKnownValue());
|
||||
preparedStatement1.setBoolean(5, eamGlobalSet.isReadOnly());
|
||||
preparedStatement1.setString(6, eamGlobalSet.getImportDate().toString());
|
||||
|
||||
preparedStatement1.executeUpdate();
|
||||
|
||||
@ -1591,6 +1597,39 @@ public abstract class AbstractSqlEamDb implements EamDb {
|
||||
EamDbUtil.closeConnection(conn);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all reference sets
|
||||
*
|
||||
* @return The global set associated with the ID
|
||||
*
|
||||
* @throws EamDbException
|
||||
*/
|
||||
@Override
|
||||
public List<EamGlobalSet> getAllReferenceSets() throws EamDbException{
|
||||
List<EamGlobalSet> results = new ArrayList<>();
|
||||
Connection conn = connect();
|
||||
|
||||
PreparedStatement preparedStatement1 = null;
|
||||
ResultSet resultSet = null;
|
||||
String sql1 = "SELECT * FROM reference_sets";
|
||||
|
||||
try {
|
||||
preparedStatement1 = conn.prepareStatement(sql1);
|
||||
resultSet = preparedStatement1.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
results.add(getEamGlobalSetFromResultSet(resultSet));
|
||||
}
|
||||
|
||||
} catch (SQLException ex) {
|
||||
throw new EamDbException("Error getting reference sets.", ex); // NON-NLS
|
||||
} finally {
|
||||
EamDbUtil.closePreparedStatement(preparedStatement1);
|
||||
EamDbUtil.closeResultSet(resultSet);
|
||||
EamDbUtil.closeConnection(conn);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new reference instance
|
||||
@ -2084,6 +2123,8 @@ public abstract class AbstractSqlEamDb implements EamDb {
|
||||
resultSet.getInt("org_id"),
|
||||
resultSet.getString("set_name"),
|
||||
resultSet.getString("version"),
|
||||
TskData.FileKnown.valueOf(resultSet.getByte("known_status")),
|
||||
resultSet.getBoolean("read_only"),
|
||||
LocalDate.parse(resultSet.getString("import_date"))
|
||||
);
|
||||
|
||||
|
@ -23,6 +23,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.sleuthkit.datamodel.TskData;
|
||||
import org.sleuthkit.autopsy.casemodule.Case;
|
||||
import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager;
|
||||
|
||||
/**
|
||||
* Main interface for interacting with the database
|
||||
@ -447,7 +448,8 @@ public interface EamDb {
|
||||
* @return The ID of the new global set
|
||||
* @throws EamDbException
|
||||
*/
|
||||
int newReferenceSet(int orgID, String setName, String version) throws EamDbException;
|
||||
int newReferenceSet(int orgID, String setName, String version, TskData.FileKnown knownStatus,
|
||||
boolean isReadOnly) throws EamDbException;
|
||||
|
||||
/**
|
||||
* Get a global set by ID
|
||||
@ -459,6 +461,15 @@ public interface EamDb {
|
||||
* @throws EamDbException
|
||||
*/
|
||||
EamGlobalSet getReferenceSetByID(int globalSetID) throws EamDbException;
|
||||
|
||||
/**
|
||||
* Get all reference sets
|
||||
*
|
||||
* @return The global set associated with the ID
|
||||
*
|
||||
* @throws EamDbException
|
||||
*/
|
||||
List<EamGlobalSet> getAllReferenceSets() throws EamDbException;
|
||||
|
||||
/**
|
||||
* Add a new reference instance
|
||||
|
@ -19,6 +19,8 @@
|
||||
package org.sleuthkit.autopsy.centralrepository.datamodel;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager;
|
||||
import org.sleuthkit.datamodel.TskData;
|
||||
|
||||
/**
|
||||
* A global set in the Central Repository database
|
||||
@ -29,6 +31,8 @@ public class EamGlobalSet {
|
||||
private int orgID;
|
||||
private String setName;
|
||||
private String version;
|
||||
private TskData.FileKnown knownStatus;
|
||||
private boolean isReadOnly;
|
||||
private LocalDate importDate;
|
||||
|
||||
public EamGlobalSet(
|
||||
@ -36,11 +40,15 @@ public class EamGlobalSet {
|
||||
int orgID,
|
||||
String setName,
|
||||
String version,
|
||||
TskData.FileKnown knownStatus,
|
||||
boolean isReadOnly,
|
||||
LocalDate importDate) {
|
||||
this.globalSetID = globalSetID;
|
||||
this.orgID = orgID;
|
||||
this.setName = setName;
|
||||
this.version = version;
|
||||
this.knownStatus = knownStatus;
|
||||
this.isReadOnly = isReadOnly;
|
||||
this.importDate = importDate;
|
||||
}
|
||||
|
||||
@ -48,8 +56,10 @@ public class EamGlobalSet {
|
||||
int orgID,
|
||||
String setName,
|
||||
String version,
|
||||
TskData.FileKnown knownStatus,
|
||||
boolean isReadOnly,
|
||||
LocalDate importDate) {
|
||||
this(-1, orgID, setName, version, importDate);
|
||||
this(-1, orgID, setName, version, knownStatus, isReadOnly, importDate);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,6 +117,34 @@ public class EamGlobalSet {
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether it is read only
|
||||
*/
|
||||
public boolean isReadOnly() {
|
||||
return isReadOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isReadOnly
|
||||
*/
|
||||
public void setReadOnly(boolean isReadOnly) {
|
||||
this.isReadOnly = isReadOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the known status
|
||||
*/
|
||||
public TskData.FileKnown getKnownStatus() {
|
||||
return knownStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param knownStatus the known status to set
|
||||
*/
|
||||
public void setKnownStatus(TskData.FileKnown knownStatus) {
|
||||
this.knownStatus = knownStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the importDate
|
||||
|
@ -792,6 +792,23 @@ public class SqliteEamDb extends AbstractSqlEamDb {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all reference sets
|
||||
*
|
||||
* @return The global set associated with the ID
|
||||
*
|
||||
* @throws EamDbException
|
||||
*/
|
||||
@Override
|
||||
public List<EamGlobalSet> getAllReferenceSets() throws EamDbException{
|
||||
try{
|
||||
acquireSharedLock();
|
||||
return super.getAllReferenceSets();
|
||||
} finally {
|
||||
releaseSharedLock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new reference instance
|
||||
*
|
||||
|
@ -311,6 +311,8 @@ public final class SqliteEamDbSettings {
|
||||
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)");
|
||||
|
@ -472,12 +472,14 @@ final public class ImportCentralRepoDatabaseDialog extends javax.swing.JDialog {
|
||||
*/
|
||||
private int createGlobalSet() throws EamDbException {
|
||||
EamDb dbManager = EamDb.getInstance();
|
||||
/*
|
||||
EamGlobalSet eamGlobalSet = new EamGlobalSet(
|
||||
selectedOrg.getOrgID(),
|
||||
tfDatabaseName.getText().trim(),
|
||||
tfDatabaseVersion.getText().trim(),
|
||||
LocalDate.now());
|
||||
return dbManager.newReferencelSet(eamGlobalSet);
|
||||
return dbManager.newReferencelSet(eamGlobalSet);*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Messages({"ImportHashDatabaseDialog.createGlobalSet.failedMsg.text=Failed to store attribution details.",
|
||||
|
@ -47,6 +47,8 @@ import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttribute;
|
||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb;
|
||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException;
|
||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalFileInstance;
|
||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalSet;
|
||||
import org.sleuthkit.autopsy.centralrepository.datamodel.EamOrganization;
|
||||
import org.sleuthkit.autopsy.centralrepository.optionspanel.ImportCentralRepoDatabaseDialog;
|
||||
import org.sleuthkit.autopsy.core.RuntimeProperties;
|
||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||
@ -649,6 +651,24 @@ public class HashDbManager implements PropertyChangeListener {
|
||||
}
|
||||
return updateableDbs;
|
||||
}
|
||||
|
||||
private List<HashDbInfo> getCentralRepoHashSetsFromDatabase(){
|
||||
List<HashDbInfo> crHashSets = new ArrayList<>();
|
||||
if(EamDb.isEnabled()){
|
||||
try{
|
||||
List<EamGlobalSet> 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));
|
||||
}
|
||||
} catch (EamDbException ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return crHashSets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores the last saved hash sets configuration. This supports
|
||||
@ -702,11 +722,28 @@ public class HashDbManager implements PropertyChangeListener {
|
||||
logger.log(Level.WARNING, Bundle.HashDbManager_noDbPath_message(hashDbInfo.getHashSetName()));
|
||||
allDatabasesLoadedCorrectly = false;
|
||||
}
|
||||
} else {
|
||||
addExistingCentralRepoHashSet(hashDbInfo.getHashSetName(), hashDbInfo.getVersion(),
|
||||
}// else {
|
||||
// addExistingCentralRepoHashSet(hashDbInfo.getHashSetName(), hashDbInfo.getVersion(),
|
||||
// hashDbInfo.getCentralRepoIndex(),
|
||||
// hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), hashDbInfo.getKnownFilesType());
|
||||
//}
|
||||
} 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()),
|
||||
NbBundle.getMessage(this.getClass(), "HashDbManager.openHashDbErr"),
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
allDatabasesLoadedCorrectly = false;
|
||||
}
|
||||
}
|
||||
|
||||
List<HashDbInfo> crHashDbInfoList = this.getCentralRepoHashSetsFromDatabase();
|
||||
for(HashDbInfo hashDbInfo : crHashDbInfoList) {
|
||||
try{
|
||||
addExistingCentralRepoHashSet(hashDbInfo.getHashSetName(), hashDbInfo.getVersion(),
|
||||
hashDbInfo.getCentralRepoIndex(),
|
||||
hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), hashDbInfo.getKnownFilesType());
|
||||
}
|
||||
hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), hashDbInfo.getKnownFilesType());
|
||||
} catch (TskCoreException ex) {
|
||||
Logger.getLogger(HashDbManager.class.getName()).log(Level.SEVERE, "Error opening hash database", ex); //NON-NLS
|
||||
JOptionPane.showMessageDialog(null,
|
||||
|
@ -475,13 +475,14 @@ final public class ImportCentralRepoDatabaseDialog extends javax.swing.JDialog {
|
||||
* @throws EamDbException
|
||||
*/
|
||||
private int createGlobalSet() throws EamDbException {
|
||||
EamDb dbManager = EamDb.getInstance();
|
||||
/*EamDb dbManager = EamDb.getInstance();
|
||||
EamGlobalSet eamGlobalSet = new EamGlobalSet(
|
||||
selectedOrg.getOrgID(),
|
||||
tfDatabaseName.getText().trim(),
|
||||
tfDatabaseVersion.getText().trim(),
|
||||
LocalDate.now());
|
||||
return dbManager.newReferencelSet(eamGlobalSet);
|
||||
return dbManager.newReferencelSet(eamGlobalSet);*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Messages({"ImportHashDatabaseDialog.createGlobalSet.failedMsg.text=Failed to store attribution details.",
|
||||
|
Loading…
x
Reference in New Issue
Block a user