19 package org.sleuthkit.autopsy.modules.hashdatabase;
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.beans.PropertyChangeSupport;
25 import java.io.IOException;
26 import java.io.Serializable;
27 import java.util.ArrayList;
28 import java.util.HashSet;
29 import java.util.List;
30 import java.util.Objects;
32 import java.util.concurrent.ExecutionException;
33 import java.util.logging.Level;
34 import javax.swing.JFileChooser;
35 import javax.swing.JOptionPane;
36 import javax.swing.SwingWorker;
37 import javax.swing.filechooser.FileNameExtensionFilter;
38 import org.apache.commons.io.FilenameUtils;
39 import org.netbeans.api.progress.ProgressHandle;
40 import org.openide.util.NbBundle;
41 import org.openide.util.NbBundle.Messages;
42 import org.openide.windows.WindowManager;
70 private List<HashDb>
hashSets =
new ArrayList<>();
73 PropertyChangeSupport changeSupport =
new PropertyChangeSupport(
HashDbManager.class);
84 DB_ADDED, DB_DELETED, DB_INDEXED
93 if (instance == null) {
100 changeSupport.addPropertyChangeListener(listener);
104 changeSupport.removePropertyChangeListener(listener);
107 synchronized boolean verifyAllDatabasesLoadedCorrectly(){
120 static String getHashDatabaseFileExtension() {
133 super(message, exception);
158 hashDb = this.addExistingHashDatabaseNoSave(hashSetName, path, searchDuringIngest, sendIngestMessages, knownFilesType);
166 if (!
new File(path).exists()) {
167 throw new HashDbManagerException(NbBundle.getMessage(
HashDbManager.class,
"HashDbManager.hashDbDoesNotExistExceptionMsg", path));
170 if (hashSetPaths.contains(path)) {
171 throw new HashDbManagerException(NbBundle.getMessage(
HashDbManager.class,
"HashDbManager.hashDbAlreadyAddedExceptionMsg", path));
174 if (hashSetNames.contains(hashSetName)) {
175 throw new HashDbManagerException(NbBundle.getMessage(
HashDbManager.class,
"HashDbManager.duplicateHashSetNameExceptionMsg", hashSetName));
178 hashDb =
addHashDatabase(SleuthkitJNI.openHashDatabase(path), hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType);
179 }
catch (TskCoreException ex) {
180 throw new HashDbManagerException(ex.getMessage());
203 public synchronized HashDb addNewHashDatabase(String hashSetName, String path,
boolean searchDuringIngest,
boolean sendIngestMessages,
218 File file =
new File(path);
220 throw new HashDbManagerException(NbBundle.getMessage(
HashDbManager.class,
"HashDbManager.hashDbFileExistsExceptionMsg", path));
222 if (!FilenameUtils.getExtension(file.getName()).equalsIgnoreCase(HASH_DATABASE_FILE_EXTENSON)) {
223 throw new HashDbManagerException(NbBundle.getMessage(
HashDbManager.class,
"HashDbManager.illegalHashDbFileNameExtensionMsg",
224 getHashDatabaseFileExtension()));
227 if (hashSetPaths.contains(path)) {
228 throw new HashDbManagerException(NbBundle.getMessage(
HashDbManager.class,
"HashDbManager.hashDbAlreadyAddedExceptionMsg", path));
231 if (hashSetNames.contains(hashSetName)) {
232 throw new HashDbManagerException(NbBundle.getMessage(
HashDbManager.class,
"HashDbManager.duplicateHashSetNameExceptionMsg", hashSetName));
235 hashDb =
addHashDatabase(SleuthkitJNI.createHashDatabase(path), hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType);
236 }
catch (TskCoreException ex) {
237 throw new HashDbManagerException(ex.getMessage());
242 private SleuthkitHashSet
addHashDatabase(
int handle, String hashSetName,
boolean searchDuringIngest,
boolean sendIngestMessages,
HashDb.
KnownFilesType knownFilesType) throws TskCoreException {
244 SleuthkitHashSet hashDb =
new SleuthkitHashSet(handle, hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType);
248 String databasePath = hashDb.getDatabasePath();
249 String indexPath = hashDb.getIndexPath();
253 hashSetNames.add(hashDb.getHashSetName());
254 if (!databasePath.equals(
"None")) {
255 hashSetPaths.add(databasePath);
257 if (!indexPath.equals(
"None")) {
258 hashSetPaths.add(indexPath);
262 hashSets.add(hashDb);
266 changeSupport.firePropertyChange(
SetEvt.
DB_ADDED.toString(), null, hashSetName);
267 }
catch (Exception e) {
268 logger.log(Level.SEVERE,
"HashDbManager listener threw exception", e);
270 NbBundle.getMessage(
this.getClass(),
"HashDbManager.moduleErr"),
271 NbBundle.getMessage(
this.getClass(),
"HashDbManager.moduleErrorListeningToUpdatesMsg"),
277 CentralRepoHashSet addExistingCentralRepoHashSet(String hashSetName, String version,
int referenceSetID,
279 boolean readOnly)
throws TskCoreException{
282 throw new TskCoreException(
"Could not load central repository hash set " + hashSetName +
" - central repository is not enabled");
285 CentralRepoHashSet db =
new CentralRepoHashSet(hashSetName, version, referenceSetID, searchDuringIngest,
286 sendIngestMessages, knownFilesType, readOnly);
289 throw new TskCoreException(
"Error finding hash set " + hashSetName +
" in central repository");
297 changeSupport.firePropertyChange(SetEvt.DB_ADDED.toString(), null, hashSetName);
298 }
catch (Exception e) {
299 logger.log(Level.SEVERE,
"HashDbManager listener threw exception", e);
300 MessageNotifyUtil.Notify.show(
301 NbBundle.getMessage(
this.getClass(),
"HashDbManager.moduleErr"),
302 NbBundle.getMessage(
this.getClass(),
"HashDbManager.moduleErrorListeningToUpdatesMsg"),
303 MessageNotifyUtil.MessageType.ERROR);
309 synchronized void indexHashDatabase(SleuthkitHashSet hashDb) {
310 hashDb.addPropertyChangeListener(
this);
311 HashDbIndexer creator =
new HashDbIndexer(hashDb);
317 if (event.getPropertyName().equals(SleuthkitHashSet.Event.INDEXING_DONE.name())) {
318 SleuthkitHashSet hashDb = (SleuthkitHashSet) event.getNewValue();
319 if (null != hashDb) {
321 String indexPath = hashDb.getIndexPath();
322 if (!indexPath.equals(
"None")) {
323 hashSetPaths.add(indexPath);
325 }
catch (TskCoreException ex) {
326 Logger.
getLogger(
HashDbManager.class.getName()).log(Level.SEVERE,
"Error getting index path of " + hashDb.getHashSetName() +
" hash set after indexing", ex);
348 if (ingestIsRunning) {
349 throw new HashDbManagerException(NbBundle.getMessage(
this.getClass(),
"HashDbManager.ingestRunningExceptionMsg"));
355 String hashSetName = hashDb.getHashSetName();
356 hashSetNames.remove(hashSetName);
357 hashSets.remove(hashDb);
362 if(hashDb instanceof SleuthkitHashSet){
363 SleuthkitHashSet hashDatabase = (SleuthkitHashSet)hashDb;
365 if(hashDatabase.hasIndex()){
366 hashSetPaths.remove(hashDatabase.getIndexPath());
368 }
catch (TskCoreException ex) {
369 Logger.
getLogger(
HashDbManager.class.getName()).log(Level.SEVERE,
"Error getting index path of " + hashDatabase.getHashSetName() +
" hash set when removing the hash set", ex);
373 if (!hashDatabase.hasIndexOnly()) {
374 hashSetPaths.remove(hashDatabase.getDatabasePath());
376 }
catch (TskCoreException ex) {
377 Logger.
getLogger(
HashDbManager.class.getName()).log(Level.SEVERE,
"Error getting hash set path of " + hashDatabase.getHashSetName() +
" hash set when removing the hash set", ex);
381 hashDatabase.close();
382 }
catch (TskCoreException ex) {
383 Logger.
getLogger(
HashDbManager.class.getName()).log(Level.SEVERE,
"Error closing " + hashDb.getHashSetName() +
" hash set when removing the hash set", ex);
389 changeSupport.firePropertyChange(
SetEvt.
DB_DELETED.toString(), null, hashSetName);
390 }
catch (Exception e) {
391 logger.log(Level.SEVERE,
"HashDbManager listener threw exception", e);
393 NbBundle.getMessage(
this.getClass(),
"HashDbManager.moduleErr"),
394 NbBundle.getMessage(
this.getClass(),
"HashDbManager.moduleErrorListeningToUpdatesMsg"),
399 void save() throws HashDbManagerException {
401 if (!HashLookupSettings.writeSettings(
new HashLookupSettings(HashLookupSettings.convertHashSetList(
this.hashSets)))) {
402 throw new HashDbManagerException(NbBundle.getMessage(
this.getClass(),
"HashDbManager.saveErrorExceptionMsg"));
404 }
catch (HashLookupSettings.HashLookupSettingsException ex) {
405 throw new HashDbManagerException(NbBundle.getMessage(
this.getClass(),
"HashDbManager.saveErrorExceptionMsg"));
419 }
catch (TskCoreException ex){
423 List<HashDb> hashDbs =
new ArrayList<>();
424 hashDbs.addAll(this.hashSets);
434 List<HashDb> hashDbs =
new ArrayList<>();
437 }
catch (TskCoreException ex){
452 List<HashDb> hashDbs =
new ArrayList<>();
455 }
catch (TskCoreException ex){
474 ArrayList<HashDb> updateableDbs =
new ArrayList<>();
477 }
catch (TskCoreException ex){
480 for (
HashDb db : hashDbs) {
482 if (db.isUpdateable()) {
483 updateableDbs.add(db);
485 }
catch (TskCoreException ex) {
486 Logger.
getLogger(
HashDbManager.class.getName()).log(Level.SEVERE,
"Error checking updateable status of " + db.getHashSetName() +
" hash set", ex);
489 return updateableDbs;
493 List<HashDbInfo> crHashSets =
new ArrayList<>();
503 crHashSets.add(
new HashDbInfo(globalSet.getSetName(), globalSet.getVersion(),
504 globalSet.getGlobalSetID(),
convertFileKnown(globalSet.getFileKnownStatus()), globalSet.isReadOnly(),
false, sendIngestMessages));
514 if(fileKnown.equals(TskData.FileKnown.BAD)){
526 hashSetNames.clear();
527 hashSetPaths.clear();
533 for (
HashDb database : hashDatabases) {
534 if(database instanceof SleuthkitHashSet){
536 ((SleuthkitHashSet)database).close();
537 }
catch (TskCoreException ex) {
542 hashDatabases.clear();
547 HashLookupSettings settings = HashLookupSettings.readSettings();
549 }
catch (HashLookupSettings.HashLookupSettingsException ex) {
560 @Messages({
"# {0} - hash set name",
"HashDbManager.noDbPath.message=Couldn't get valid hash set path for: {0}",
561 "HashDbManager.centralRepoLoadError.message=Error loading central repository hash sets"})
563 allDatabasesLoadedCorrectly =
true;
564 List<HashDbInfo> hashDbInfoList = settings.getHashDbInfo();
565 for (HashDbInfo hashDbInfo : hashDbInfoList) {
567 if(hashDbInfo.isFileDatabaseType()){
568 String dbPath = this.
getValidFilePath(hashDbInfo.getHashSetName(), hashDbInfo.getPath());
569 if (dbPath != null) {
570 addHashDatabase(SleuthkitJNI.openHashDatabase(dbPath), hashDbInfo.getHashSetName(), hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), hashDbInfo.getKnownFilesType());
572 logger.log(Level.WARNING, Bundle.HashDbManager_noDbPath_message(hashDbInfo.getHashSetName()));
573 allDatabasesLoadedCorrectly =
false;
577 addExistingCentralRepoHashSet(hashDbInfo.getHashSetName(), hashDbInfo.getVersion(),
578 hashDbInfo.getReferenceSetID(),
579 hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(),
580 hashDbInfo.getKnownFilesType(), hashDbInfo.isReadOnly());
583 }
catch (TskCoreException ex) {
585 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
586 NbBundle.getMessage(this.getClass(),
587 "HashDbManager.unableToOpenHashDbMsg", hashDbInfo.getHashSetName()),
588 NbBundle.getMessage(
this.getClass(),
"HashDbManager.openHashDbErr"),
589 JOptionPane.ERROR_MESSAGE);
590 allDatabasesLoadedCorrectly =
false;
597 }
catch (TskCoreException ex){
600 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
601 Bundle.HashDbManager_centralRepoLoadError_message(),
602 NbBundle.getMessage(this.getClass(),
"HashDbManager.openHashDbErr"),
603 JOptionPane.ERROR_MESSAGE);
604 allDatabasesLoadedCorrectly =
false;
617 HashLookupSettings.writeSettings(
new HashLookupSettings(HashLookupSettings.convertHashSetList(
this.hashSets)));
618 allDatabasesLoadedCorrectly =
true;
619 }
catch (HashLookupSettings.HashLookupSettingsException ex) {
620 allDatabasesLoadedCorrectly =
false;
621 logger.log(Level.SEVERE,
"Could not overwrite hash set settings.", ex);
629 for(HashDbInfo hashDbInfo : crHashDbInfoList) {
631 addExistingCentralRepoHashSet(hashDbInfo.getHashSetName(), hashDbInfo.getVersion(),
632 hashDbInfo.getReferenceSetID(),
633 hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), hashDbInfo.getKnownFilesType(),
634 hashDbInfo.isReadOnly());
641 for(
HashDb db:this.hashSets){
642 if(dbInfo.matches(db)){
651 File database =
new File(configuredPath);
652 if (database.exists()) {
653 return configuredPath;
657 String newPath = null;
659 JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(),
660 NbBundle.getMessage(this.getClass(),
"HashDbManager.dlgMsg.dbNotFoundAtLoc",
661 hashSetName, configuredPath),
662 NbBundle.getMessage(this.getClass(),
"HashDbManager.dlgTitle.MissingDb"),
663 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
665 if (null != newPath && !newPath.isEmpty()) {
666 database =
new File(newPath);
667 if (!database.exists()) {
676 String filePath = null;
677 JFileChooser fc =
new JFileChooser();
678 fc.setDragEnabled(
false);
679 fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
680 String[] EXTENSION =
new String[]{
"txt",
"idx",
"hash",
"Hash",
"kdb"};
681 FileNameExtensionFilter filter =
new FileNameExtensionFilter(
682 NbBundle.getMessage(
this.getClass(),
"HashDbManager.fileNameExtensionFilter.title"), EXTENSION);
683 fc.setFileFilter(filter);
684 fc.setMultiSelectionEnabled(
false);
685 if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
686 File f = fc.getSelectedFile();
688 filePath = f.getCanonicalPath();
689 }
catch (IOException ex) {
709 this.displayName = displayName;
713 return this.displayName;
727 abstract String getDisplayName();
735 abstract
void setSearchDuringIngest(
boolean useForIngest);
739 abstract
void setSendIngestMessages(
boolean showInboxMessages);
748 public abstract
boolean isUpdateable() throws TskCoreException;
758 public abstract
void addHashes(Content content) throws TskCoreException;
760 public abstract
void addHashes(Content content, String comment) throws TskCoreException;
762 public abstract
void addHashes(List<HashEntry> hashes) throws TskCoreException;
764 public abstract
boolean lookupMD5Quick(Content content) throws TskCoreException;
766 public abstract HashHitInfo
lookupMD5(Content content) throws TskCoreException;
774 abstract
boolean isValid() throws TskCoreException;
776 public abstract String
getIndexPath() throws TskCoreException;
778 public abstract
boolean hasIndexOnly() throws TskCoreException;
780 public abstract
void firePropertyChange(String propertyName, Object oldValue, Object newValue);
795 class SleuthkitHashSet extends
HashDb {
797 private static final long serialVersionUID = 1L;
798 private final int handle;
799 private final String hashSetName;
800 private boolean searchDuringIngest;
801 private boolean sendIngestMessages;
803 private boolean indexing;
804 private final PropertyChangeSupport propertyChangeSupport =
new PropertyChangeSupport(
this);
806 private SleuthkitHashSet(
int handle, String hashSetName,
boolean useForIngest,
boolean sendHitMessages,
KnownFilesType knownFilesType) {
807 this.handle = handle;
808 this.hashSetName = hashSetName;
809 this.searchDuringIngest = useForIngest;
810 this.sendIngestMessages = sendHitMessages;
811 this.knownFilesType = knownFilesType;
812 this.indexing =
false;
823 propertyChangeSupport.addPropertyChangeListener(pcl);
833 propertyChangeSupport.removePropertyChangeListener(pcl);
846 String getDisplayName(){
852 return SleuthkitJNI.getHashDatabasePath(handle);
855 public void setIndexing(
boolean indexing){
856 this.indexing = indexing;
861 return SleuthkitJNI.getHashDatabaseIndexPath(handle);
866 return knownFilesType;
871 return searchDuringIngest;
875 void setSearchDuringIngest(
boolean useForIngest) {
876 this.searchDuringIngest = useForIngest;
881 return sendIngestMessages;
885 void setSendIngestMessages(
boolean showInboxMessages) {
886 this.sendIngestMessages = showInboxMessages;
898 return SleuthkitJNI.isUpdateableHashDatabase(this.handle);
910 public void addHashes(Content content)
throws TskCoreException {
925 public void addHashes(Content content, String comment)
throws TskCoreException {
927 assert content instanceof AbstractFile;
928 if (content instanceof AbstractFile) {
929 AbstractFile file = (AbstractFile) content;
930 if (null != file.getMd5Hash()) {
931 SleuthkitJNI.addToHashDatabase(null, file.getMd5Hash(), null, null, comment, handle);
944 public void addHashes(List<HashEntry> hashes)
throws TskCoreException {
945 SleuthkitJNI.addToHashDatabase(hashes, handle);
958 public boolean lookupMD5Quick(Content content)
throws TskCoreException {
959 boolean result =
false;
960 assert content instanceof AbstractFile;
961 if (content instanceof AbstractFile) {
962 AbstractFile file = (AbstractFile) content;
963 if (null != file.getMd5Hash()) {
964 result = SleuthkitJNI.lookupInHashDatabase(file.getMd5Hash(), handle);
980 public HashHitInfo
lookupMD5(Content content)
throws TskCoreException {
981 HashHitInfo result = null;
983 assert content instanceof AbstractFile;
984 if (content instanceof AbstractFile) {
985 AbstractFile file = (AbstractFile) content;
986 if (null != file.getMd5Hash()) {
987 result = SleuthkitJNI.lookupInHashDatabaseVerbose(file.getMd5Hash(), handle);
1000 boolean isValid() throws TskCoreException {
1004 boolean hasIndex() throws TskCoreException {
1005 return SleuthkitJNI.hashDatabaseHasLookupIndex(handle);
1009 public boolean hasIndexOnly() throws TskCoreException {
1010 return SleuthkitJNI.hashDatabaseIsIndexOnly(handle);
1013 boolean canBeReIndexed() throws TskCoreException {
1014 return SleuthkitJNI.hashDatabaseCanBeReindexed(handle);
1017 boolean isIndexing() {
1022 public void firePropertyChange(String propertyName, Object oldValue, Object newValue){
1023 this.propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
1026 private void close() throws TskCoreException {
1027 SleuthkitJNI.closeHashDatabase(handle);
1037 public int hashCode() {
1039 code = 47 * code + Integer.hashCode(handle);
1040 code = 47 * code + Objects.hashCode(this.hashSetName);
1041 code = 47 * code + Objects.hashCode(this.propertyChangeSupport);
1042 code = 47 * code + Objects.hashCode(this.knownFilesType);
1047 public boolean equals(Object obj) {
1051 if (getClass() != obj.getClass()) {
1054 final SleuthkitHashSet other = (SleuthkitHashSet) obj;
1055 if (!Objects.equals(
this.hashSetName, other.hashSetName)) {
1058 if (this.knownFilesType != other.knownFilesType) {
1069 class CentralRepoHashSet
extends HashDb{
1071 private static final long serialVersionUID = 1L;
1072 private final String hashSetName;
1073 private boolean searchDuringIngest;
1074 private boolean sendIngestMessages;
1075 private final HashDb.KnownFilesType knownFilesType;
1076 private final int referenceSetID;
1077 private final String version;
1078 private String orgName;
1079 private final boolean readOnly;
1080 private final PropertyChangeSupport propertyChangeSupport =
new PropertyChangeSupport(
this);
1082 @Messages({
"HashDbManager.CentralRepoHashDb.orgError=Error loading organization"})
1083 private CentralRepoHashSet(String hashSetName, String version,
int referenceSetID,
1084 boolean useForIngest,
boolean sendHitMessages, HashDb.KnownFilesType knownFilesType,
1086 throws TskCoreException{
1087 this.hashSetName = hashSetName;
1088 this.version = version;
1089 this.referenceSetID = referenceSetID;
1090 this.searchDuringIngest = useForIngest;
1091 this.sendIngestMessages = sendHitMessages;
1092 this.knownFilesType = knownFilesType;
1093 this.readOnly = readOnly;
1096 orgName = EamDb.getInstance().getReferenceSetOrganization(referenceSetID).getName();
1097 }
catch (EamDbException ex){
1098 Logger.getLogger(SleuthkitHashSet.class.getName()).log(Level.SEVERE,
"Error looking up central repository organization for reference set " + referenceSetID, ex);
1099 orgName = Bundle.HashDbManager_CentralRepoHashDb_orgError();
1111 propertyChangeSupport.addPropertyChangeListener(pcl);
1121 propertyChangeSupport.removePropertyChangeListener(pcl);
1135 public String getDisplayName(){
1136 if(! getVersion().isEmpty()){
1143 String getVersion(){
1147 String getOrgName(){
1151 int getReferenceSetID(){
1152 return referenceSetID;
1167 return knownFilesType;
1172 return searchDuringIngest;
1176 void setSearchDuringIngest(
boolean useForIngest) {
1177 this.searchDuringIngest = useForIngest;
1182 return sendIngestMessages;
1186 void setSendIngestMessages(
boolean showInboxMessages) {
1187 this.sendIngestMessages = showInboxMessages;
1198 public boolean isUpdateable() throws TskCoreException {
1199 return (! readOnly);
1211 public void addHashes(Content content)
throws TskCoreException {
1226 public void addHashes(Content content, String comment)
throws TskCoreException {
1228 assert content instanceof AbstractFile;
1229 if (content instanceof AbstractFile) {
1230 AbstractFile file = (AbstractFile) content;
1231 if (null != file.getMd5Hash()) {
1232 TskData.FileKnown type;
1233 if(knownFilesType.equals(HashDb.KnownFilesType.KNOWN_BAD)){
1234 type = TskData.FileKnown.BAD;
1236 type = TskData.FileKnown.KNOWN;
1240 EamGlobalFileInstance fileInstance =
new EamGlobalFileInstance(referenceSetID, file.getMd5Hash(),
1242 EamDb.getInstance().addReferenceInstance(fileInstance,EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.FILES_TYPE_ID));
1243 }
catch (EamDbException | CorrelationAttributeNormalizationException ex){
1244 throw new TskCoreException(
"Error adding hashes to " + getDisplayName(), ex);
1258 public void addHashes(List<HashEntry> hashes)
throws TskCoreException {
1259 Set<EamGlobalFileInstance> globalFileInstances =
new HashSet<>();
1260 for(HashEntry hashEntry:hashes){
1261 TskData.FileKnown type;
1262 if(knownFilesType.equals(HashDb.KnownFilesType.KNOWN_BAD)){
1263 type = TskData.FileKnown.BAD;
1265 type = TskData.FileKnown.KNOWN;
1268 globalFileInstances.add(
new EamGlobalFileInstance(referenceSetID, hashEntry.getMd5Hash(), type, hashEntry.getComment()));
1269 }
catch (EamDbException | CorrelationAttributeNormalizationException ex){
1270 throw new TskCoreException(
"Error adding hashes to " + getDisplayName(), ex);
1275 EamDb.getInstance().bulkInsertReferenceTypeEntries(globalFileInstances,
1276 EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.FILES_TYPE_ID));
1277 }
catch (EamDbException ex){
1278 throw new TskCoreException(
"Error adding hashes to " + getDisplayName(), ex);
1292 public boolean lookupMD5Quick(Content content)
throws TskCoreException {
1294 assert content instanceof AbstractFile;
1295 if (content instanceof AbstractFile) {
1296 AbstractFile file = (AbstractFile) content;
1297 if (null != file.getMd5Hash()) {
1299 return EamDb.getInstance().isFileHashInReferenceSet(file.getMd5Hash(), this.referenceSetID);
1300 }
catch (EamDbException | CorrelationAttributeNormalizationException ex){
1301 Logger.getLogger(SleuthkitHashSet.class.getName()).log(Level.SEVERE,
"Error performing central reposiotry hash lookup for hash "
1302 + file.getMd5Hash() +
" in reference set " + referenceSetID, ex);
1303 throw new TskCoreException(
"Error performing central reposiotry hash lookup", ex);
1320 public HashHitInfo
lookupMD5(Content content)
throws TskCoreException {
1321 HashHitInfo result = null;
1323 assert content instanceof AbstractFile;
1324 if (content instanceof AbstractFile) {
1325 AbstractFile file = (AbstractFile) content;
1326 if (null != file.getMd5Hash()) {
1328 if(EamDb.getInstance().isFileHashInReferenceSet(file.getMd5Hash(), this.referenceSetID)){
1330 result =
new HashHitInfo(file.getMd5Hash(),
"",
"");
1332 }
catch (EamDbException | CorrelationAttributeNormalizationException ex){
1333 Logger.getLogger(SleuthkitHashSet.class.getName()).log(Level.SEVERE,
"Error performing central reposiotry hash lookup for hash "
1334 + file.getMd5Hash() +
" in reference set " + referenceSetID, ex);
1335 throw new TskCoreException(
"Error performing central reposiotry hash lookup", ex);
1349 if(! EamDb.isEnabled()) {
1353 return EamDb.getInstance().referenceSetIsValid(this.referenceSetID, this.hashSetName, this.version);
1354 }
catch (EamDbException ex){
1355 Logger.getLogger(CentralRepoHashSet.class.getName()).log(Level.SEVERE,
"Error validating hash set " + hashSetName, ex);
1361 public void firePropertyChange(String propertyName, Object oldValue, Object newValue){
1362 this.propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
1367 return getDisplayName();
1372 public int hashCode() {
1374 code = 47 * code + Objects.hashCode(this.hashSetName);
1375 code = 47 * code + Objects.hashCode(this.version);
1376 code = 47 * code + Integer.hashCode(this.referenceSetID);
1377 code = 47 * code + Objects.hashCode(this.knownFilesType);
1382 public boolean equals(Object obj) {
1386 if (getClass() != obj.getClass()) {
1389 final CentralRepoHashSet other = (CentralRepoHashSet) obj;
1390 if (!Objects.equals(
this.hashSetName, other.hashSetName)) {
1393 if (!Objects.equals(
this.version, other.version)) {
1396 if (this.knownFilesType != other.knownFilesType) {
1408 private ProgressHandle progress = null;
1409 private SleuthkitHashSet hashDb = null;
1412 this.hashDb = hashDb;
1417 hashDb.setIndexing(
true);
1418 progress = ProgressHandle.createHandle(
1419 NbBundle.getMessage(
this.getClass(),
"HashDbManager.progress.indexingHashSet", hashDb.getHashSetName()));
1421 progress.switchToIndeterminate();
1423 SleuthkitJNI.createLookupIndexForHashDatabase(hashDb.getHandle());
1424 }
catch (TskCoreException ex) {
1426 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
1427 NbBundle.getMessage(this.getClass(),
1428 "HashDbManager.dlgMsg.errorIndexingHashSet",
1429 hashDb.getHashSetName()),
1430 NbBundle.getMessage(
this.getClass(),
"HashDbManager.hashDbIndexingErr"),
1431 JOptionPane.ERROR_MESSAGE);
1438 hashDb.setIndexing(
false);
1444 }
catch (InterruptedException | ExecutionException ex) {
1445 logger.log(Level.SEVERE,
"Error creating index", ex);
1447 NbBundle.getMessage(
this.getClass(),
"HashDbManager.errCreatingIndex.title"),
1448 NbBundle.getMessage(
this.getClass(),
"HashDbManager.errCreatingIndex.msg", ex.getMessage()),
1451 catch (java.util.concurrent.CancellationException ex) {
1455 hashDb.firePropertyChange(SleuthkitHashSet.Event.INDEXING_DONE.toString(), null, hashDb);
1457 }
catch (Exception e) {
1458 logger.log(Level.SEVERE,
"HashDbManager listener threw exception", e);
1460 NbBundle.getMessage(
this.getClass(),
"HashDbManager.moduleErr"),
1461 NbBundle.getMessage(
this.getClass(),
"HashDbManager.moduleErrorListeningToUpdatesMsg"),
abstract boolean getSendIngestMessages()
Set< String > hashSetPaths
abstract String getIndexPath()
void configureSettings(HashLookupSettings settings)
static final Logger logger
static final String HASH_DATABASE_FILE_EXTENSON
void loadHashsetsConfiguration()
static synchronized IngestManager getInstance()
static boolean runningWithGUI
synchronized void addPropertyChangeListener(PropertyChangeListener listener)
HashDbManagerException(String message)
abstract String getHashSetName()
List< HashDbInfo > getCentralRepoHashSetsFromDatabase()
boolean isIngestRunning()
static final long serialVersionUID
List< HashDb > getUpdateableHashSets(List< HashDb > hashDbs)
abstract String toString()
synchronized HashDb addNewHashDatabaseNoSave(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType)
HashDbManagerException(String message, Throwable exception)
synchronized void removeHashDatabase(HashDb hashDb)
KnownFilesType(String displayName)
boolean allDatabasesLoadedCorrectly
abstract void firePropertyChange(String propertyName, Object oldValue, Object newValue)
synchronized List< HashDb > getKnownBadFileHashSets()
static EamDb getInstance()
boolean hashDbInfoIsNew(HashDbInfo dbInfo)
synchronized void removeHashDatabaseNoSave(HashDb hashDb)
static HashDbManager instance
Set< String > hashSetNames
static synchronized HashDbManager getInstance()
CorrelationAttributeInstance.Type getCorrelationTypeById(int typeId)
String getValidFilePath(String hashSetName, String configuredPath)
List< EamGlobalSet > getAllReferenceSets(CorrelationAttributeInstance.Type correlationType)
static HashDb.KnownFilesType convertFileKnown(TskData.FileKnown fileKnown)
abstract HashDb.KnownFilesType getKnownFilesType()
synchronized HashDb addNewHashDatabase(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType)
synchronized void removePropertyChangeListener(PropertyChangeListener listener)
static boolean isEnabled()
abstract HashHitInfo lookupMD5(Content content)
synchronized List< HashDb > getUpdateableHashSets()
synchronized List< HashDb > getAllHashSets()
abstract boolean isUpdateable()
abstract boolean lookupMD5Quick(Content content)
abstract String getDatabasePath()
void propertyChange(PropertyChangeEvent event)
void closeHashDatabases(List< HashDb > hashDatabases)
synchronized void loadLastSavedConfiguration()
abstract void addPropertyChangeListener(PropertyChangeListener pcl)
synchronized static Logger getLogger(String name)
static void show(String title, String message, MessageType type, ActionListener actionListener)
abstract boolean hasIndexOnly()
SleuthkitHashSet addHashDatabase(int handle, String hashSetName, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType)
abstract boolean getSearchDuringIngest()
void updateHashSetsFromCentralRepository()
synchronized List< HashDb > getKnownFileHashSets()
synchronized HashDb addExistingHashDatabase(String hashSetName, String path, boolean searchDuringIngest, boolean sendIngestMessages, HashDb.KnownFilesType knownFilesType)
static final int FILES_TYPE_ID
abstract void addHashes(Content content)
abstract void removePropertyChangeListener(PropertyChangeListener pcl)