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.util.ArrayList;
27 import java.util.HashSet;
28 import java.util.List;
29 import java.util.Objects;
31 import java.util.concurrent.ExecutionException;
32 import java.util.logging.Level;
33 import javax.swing.JFileChooser;
34 import javax.swing.JOptionPane;
35 import javax.swing.SwingWorker;
36 import javax.swing.filechooser.FileNameExtensionFilter;
37 import org.apache.commons.io.FilenameUtils;
38 import org.netbeans.api.progress.ProgressHandle;
39 import org.openide.util.NbBundle;
40 import org.openide.util.NbBundle.Messages;
41 import org.openide.windows.WindowManager;
69 private List<HashDb>
hashSets =
new ArrayList<>();
72 PropertyChangeSupport changeSupport =
new PropertyChangeSupport(
HashDbManager.class);
83 DB_ADDED, DB_DELETED, DB_INDEXED
92 if (instance == null) {
99 changeSupport.addPropertyChangeListener(listener);
103 changeSupport.removePropertyChangeListener(listener);
106 synchronized boolean verifyAllDatabasesLoadedCorrectly(){
119 static String getHashDatabaseFileExtension() {
132 super(message, exception);
157 hashDb = this.addExistingHashDatabaseNoSave(hashSetName, path, searchDuringIngest, sendIngestMessages, knownFilesType);
165 if (!
new File(path).exists()) {
166 throw new HashDbManagerException(NbBundle.getMessage(
HashDbManager.class,
"HashDbManager.hashDbDoesNotExistExceptionMsg", path));
169 if (hashSetPaths.contains(path)) {
170 throw new HashDbManagerException(NbBundle.getMessage(
HashDbManager.class,
"HashDbManager.hashDbAlreadyAddedExceptionMsg", path));
173 if (hashSetNames.contains(hashSetName)) {
174 throw new HashDbManagerException(NbBundle.getMessage(
HashDbManager.class,
"HashDbManager.duplicateHashSetNameExceptionMsg", hashSetName));
177 hashDb =
addHashDatabase(SleuthkitJNI.openHashDatabase(path), hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType);
178 }
catch (TskCoreException ex) {
179 throw new HashDbManagerException(ex.getMessage());
202 public synchronized HashDb addNewHashDatabase(String hashSetName, String path,
boolean searchDuringIngest,
boolean sendIngestMessages,
217 File file =
new File(path);
219 throw new HashDbManagerException(NbBundle.getMessage(
HashDbManager.class,
"HashDbManager.hashDbFileExistsExceptionMsg", path));
221 if (!FilenameUtils.getExtension(file.getName()).equalsIgnoreCase(HASH_DATABASE_FILE_EXTENSON)) {
222 throw new HashDbManagerException(NbBundle.getMessage(
HashDbManager.class,
"HashDbManager.illegalHashDbFileNameExtensionMsg",
223 getHashDatabaseFileExtension()));
226 if (hashSetPaths.contains(path)) {
227 throw new HashDbManagerException(NbBundle.getMessage(
HashDbManager.class,
"HashDbManager.hashDbAlreadyAddedExceptionMsg", path));
230 if (hashSetNames.contains(hashSetName)) {
231 throw new HashDbManagerException(NbBundle.getMessage(
HashDbManager.class,
"HashDbManager.duplicateHashSetNameExceptionMsg", hashSetName));
234 hashDb =
addHashDatabase(SleuthkitJNI.createHashDatabase(path), hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType);
235 }
catch (TskCoreException ex) {
236 throw new HashDbManagerException(ex.getMessage());
241 private SleuthkitHashSet
addHashDatabase(
int handle, String hashSetName,
boolean searchDuringIngest,
boolean sendIngestMessages,
HashDb.
KnownFilesType knownFilesType) throws TskCoreException {
243 SleuthkitHashSet hashDb =
new SleuthkitHashSet(handle, hashSetName, searchDuringIngest, sendIngestMessages, knownFilesType);
247 String databasePath = hashDb.getDatabasePath();
248 String indexPath = hashDb.getIndexPath();
252 hashSetNames.add(hashDb.getHashSetName());
253 if (!databasePath.equals(
"None")) {
254 hashSetPaths.add(databasePath);
256 if (!indexPath.equals(
"None")) {
257 hashSetPaths.add(indexPath);
261 hashSets.add(hashDb);
265 changeSupport.firePropertyChange(
SetEvt.
DB_ADDED.toString(), null, hashSetName);
266 }
catch (Exception e) {
267 logger.log(Level.SEVERE,
"HashDbManager listener threw exception", e);
269 NbBundle.getMessage(
this.getClass(),
"HashDbManager.moduleErr"),
270 NbBundle.getMessage(
this.getClass(),
"HashDbManager.moduleErrorListeningToUpdatesMsg"),
276 CentralRepoHashSet addExistingCentralRepoHashSet(String hashSetName, String version,
int referenceSetID,
278 boolean readOnly)
throws TskCoreException{
281 throw new TskCoreException(
"Could not load central repository hash set " + hashSetName +
" - central repository is not enabled");
284 CentralRepoHashSet db =
new CentralRepoHashSet(hashSetName, version, referenceSetID, searchDuringIngest,
285 sendIngestMessages, knownFilesType, readOnly);
288 throw new TskCoreException(
"Error finding hash set " + hashSetName +
" in central repository");
296 changeSupport.firePropertyChange(SetEvt.DB_ADDED.toString(), null, hashSetName);
297 }
catch (Exception e) {
298 logger.log(Level.SEVERE,
"HashDbManager listener threw exception", e);
299 MessageNotifyUtil.Notify.show(
300 NbBundle.getMessage(
this.getClass(),
"HashDbManager.moduleErr"),
301 NbBundle.getMessage(
this.getClass(),
"HashDbManager.moduleErrorListeningToUpdatesMsg"),
302 MessageNotifyUtil.MessageType.ERROR);
308 synchronized void indexHashDatabase(SleuthkitHashSet hashDb) {
309 hashDb.addPropertyChangeListener(
this);
310 HashDbIndexer creator =
new HashDbIndexer(hashDb);
316 if (event.getPropertyName().equals(SleuthkitHashSet.Event.INDEXING_DONE.name())) {
317 SleuthkitHashSet hashDb = (SleuthkitHashSet) event.getNewValue();
318 if (null != hashDb) {
320 String indexPath = hashDb.getIndexPath();
321 if (!indexPath.equals(
"None")) {
322 hashSetPaths.add(indexPath);
324 }
catch (TskCoreException ex) {
325 Logger.
getLogger(
HashDbManager.class.getName()).log(Level.SEVERE,
"Error getting index path of " + hashDb.getHashSetName() +
" hash set after indexing", ex);
347 if (ingestIsRunning) {
348 throw new HashDbManagerException(NbBundle.getMessage(
this.getClass(),
"HashDbManager.ingestRunningExceptionMsg"));
354 String hashSetName = hashDb.getHashSetName();
355 hashSetNames.remove(hashSetName);
356 hashSets.remove(hashDb);
361 if(hashDb instanceof SleuthkitHashSet){
362 SleuthkitHashSet hashDatabase = (SleuthkitHashSet)hashDb;
364 if(hashDatabase.hasIndex()){
365 hashSetPaths.remove(hashDatabase.getIndexPath());
367 }
catch (TskCoreException ex) {
368 Logger.
getLogger(
HashDbManager.class.getName()).log(Level.SEVERE,
"Error getting index path of " + hashDatabase.getHashSetName() +
" hash set when removing the hash set", ex);
372 if (!hashDatabase.hasIndexOnly()) {
373 hashSetPaths.remove(hashDatabase.getDatabasePath());
375 }
catch (TskCoreException ex) {
376 Logger.
getLogger(
HashDbManager.class.getName()).log(Level.SEVERE,
"Error getting hash set path of " + hashDatabase.getHashSetName() +
" hash set when removing the hash set", ex);
380 hashDatabase.close();
381 }
catch (TskCoreException ex) {
382 Logger.
getLogger(
HashDbManager.class.getName()).log(Level.SEVERE,
"Error closing " + hashDb.getHashSetName() +
" hash set when removing the hash set", ex);
388 changeSupport.firePropertyChange(
SetEvt.
DB_DELETED.toString(), null, hashSetName);
389 }
catch (Exception e) {
390 logger.log(Level.SEVERE,
"HashDbManager listener threw exception", e);
392 NbBundle.getMessage(
this.getClass(),
"HashDbManager.moduleErr"),
393 NbBundle.getMessage(
this.getClass(),
"HashDbManager.moduleErrorListeningToUpdatesMsg"),
398 void save() throws HashDbManagerException {
400 if (!HashLookupSettings.writeSettings(
new HashLookupSettings(HashLookupSettings.convertHashSetList(
this.hashSets)))) {
401 throw new HashDbManagerException(NbBundle.getMessage(
this.getClass(),
"HashDbManager.saveErrorExceptionMsg"));
403 }
catch (HashLookupSettings.HashLookupSettingsException ex) {
404 throw new HashDbManagerException(NbBundle.getMessage(
this.getClass(),
"HashDbManager.saveErrorExceptionMsg"));
418 }
catch (TskCoreException ex){
422 List<HashDb> hashDbs =
new ArrayList<>();
423 hashDbs.addAll(this.hashSets);
433 List<HashDb> hashDbs =
new ArrayList<>();
436 }
catch (TskCoreException ex){
451 List<HashDb> hashDbs =
new ArrayList<>();
454 }
catch (TskCoreException ex){
473 ArrayList<HashDb> updateableDbs =
new ArrayList<>();
476 }
catch (TskCoreException ex){
479 for (
HashDb db : hashDbs) {
481 if (db.isUpdateable()) {
482 updateableDbs.add(db);
484 }
catch (TskCoreException ex) {
485 Logger.
getLogger(
HashDbManager.class.getName()).log(Level.SEVERE,
"Error checking updateable status of " + db.getHashSetName() +
" hash set", ex);
488 return updateableDbs;
492 List<HashDbInfo> crHashSets =
new ArrayList<>();
502 crHashSets.add(
new HashDbInfo(globalSet.getSetName(), globalSet.getVersion(),
503 globalSet.getGlobalSetID(),
convertFileKnown(globalSet.getFileKnownStatus()), globalSet.isReadOnly(),
false, sendIngestMessages));
513 if(fileKnown.equals(TskData.FileKnown.BAD)){
525 hashSetNames.clear();
526 hashSetPaths.clear();
532 for (
HashDb database : hashDatabases) {
533 if(database instanceof SleuthkitHashSet){
535 ((SleuthkitHashSet)database).close();
536 }
catch (TskCoreException ex) {
541 hashDatabases.clear();
546 HashLookupSettings settings = HashLookupSettings.readSettings();
548 }
catch (HashLookupSettings.HashLookupSettingsException ex) {
559 @Messages({
"# {0} - hash set name",
"HashDbManager.noDbPath.message=Couldn't get valid hash set path for: {0}",
560 "HashDbManager.centralRepoLoadError.message=Error loading central repository hash sets"})
562 allDatabasesLoadedCorrectly =
true;
563 List<HashDbInfo> hashDbInfoList = settings.getHashDbInfo();
564 for (HashDbInfo hashDbInfo : hashDbInfoList) {
566 if(hashDbInfo.isFileDatabaseType()){
567 String dbPath = this.
getValidFilePath(hashDbInfo.getHashSetName(), hashDbInfo.getPath());
568 if (dbPath != null) {
569 addHashDatabase(SleuthkitJNI.openHashDatabase(dbPath), hashDbInfo.getHashSetName(), hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), hashDbInfo.getKnownFilesType());
571 logger.log(Level.WARNING, Bundle.HashDbManager_noDbPath_message(hashDbInfo.getHashSetName()));
572 allDatabasesLoadedCorrectly =
false;
576 addExistingCentralRepoHashSet(hashDbInfo.getHashSetName(), hashDbInfo.getVersion(),
577 hashDbInfo.getReferenceSetID(),
578 hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(),
579 hashDbInfo.getKnownFilesType(), hashDbInfo.isReadOnly());
582 }
catch (TskCoreException ex) {
584 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
585 NbBundle.getMessage(this.getClass(),
586 "HashDbManager.unableToOpenHashDbMsg", hashDbInfo.getHashSetName()),
587 NbBundle.getMessage(
this.getClass(),
"HashDbManager.openHashDbErr"),
588 JOptionPane.ERROR_MESSAGE);
589 allDatabasesLoadedCorrectly =
false;
596 }
catch (TskCoreException ex){
599 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
600 Bundle.HashDbManager_centralRepoLoadError_message(),
601 NbBundle.getMessage(this.getClass(),
"HashDbManager.openHashDbErr"),
602 JOptionPane.ERROR_MESSAGE);
603 allDatabasesLoadedCorrectly =
false;
616 HashLookupSettings.writeSettings(
new HashLookupSettings(HashLookupSettings.convertHashSetList(
this.hashSets)));
617 allDatabasesLoadedCorrectly =
true;
618 }
catch (HashLookupSettings.HashLookupSettingsException ex) {
619 allDatabasesLoadedCorrectly =
false;
620 logger.log(Level.SEVERE,
"Could not overwrite hash set settings.", ex);
628 for(HashDbInfo hashDbInfo : crHashDbInfoList) {
630 addExistingCentralRepoHashSet(hashDbInfo.getHashSetName(), hashDbInfo.getVersion(),
631 hashDbInfo.getReferenceSetID(),
632 hashDbInfo.getSearchDuringIngest(), hashDbInfo.getSendIngestMessages(), hashDbInfo.getKnownFilesType(),
633 hashDbInfo.isReadOnly());
640 for(
HashDb db:this.hashSets){
641 if(dbInfo.matches(db)){
650 File database =
new File(configuredPath);
651 if (database.exists()) {
652 return configuredPath;
656 String newPath = null;
658 JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(),
659 NbBundle.getMessage(this.getClass(),
"HashDbManager.dlgMsg.dbNotFoundAtLoc",
660 hashSetName, configuredPath),
661 NbBundle.getMessage(this.getClass(),
"HashDbManager.dlgTitle.MissingDb"),
662 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
664 if (null != newPath && !newPath.isEmpty()) {
665 database =
new File(newPath);
666 if (!database.exists()) {
675 String filePath = null;
676 JFileChooser fc =
new JFileChooser();
677 fc.setDragEnabled(
false);
678 fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
679 String[] EXTENSION =
new String[]{
"txt",
"idx",
"hash",
"Hash",
"kdb"};
680 FileNameExtensionFilter filter =
new FileNameExtensionFilter(
681 NbBundle.getMessage(
this.getClass(),
"HashDbManager.fileNameExtensionFilter.title"), EXTENSION);
682 fc.setFileFilter(filter);
683 fc.setMultiSelectionEnabled(
false);
684 if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
685 File f = fc.getSelectedFile();
687 filePath = f.getCanonicalPath();
688 }
catch (IOException ex) {
708 this.displayName = displayName;
712 return this.displayName;
726 abstract String getDisplayName();
734 abstract
void setSearchDuringIngest(
boolean useForIngest);
738 abstract
void setSendIngestMessages(
boolean showInboxMessages);
747 public abstract
boolean isUpdateable() throws TskCoreException;
757 public abstract
void addHashes(Content content) throws TskCoreException;
759 public abstract
void addHashes(Content content, String comment) throws TskCoreException;
761 public abstract
void addHashes(List<HashEntry> hashes) throws TskCoreException;
763 public abstract
boolean lookupMD5Quick(Content content) throws TskCoreException;
765 public abstract HashHitInfo
lookupMD5(Content content) throws TskCoreException;
773 abstract
boolean isValid() throws TskCoreException;
775 public abstract String
getIndexPath() throws TskCoreException;
777 public abstract
boolean hasIndexOnly() throws TskCoreException;
779 public abstract
void firePropertyChange(String propertyName, Object oldValue, Object newValue);
794 class SleuthkitHashSet extends
HashDb{
796 private static final long serialVersionUID = 1L;
797 private final int handle;
798 private final String hashSetName;
799 private boolean searchDuringIngest;
800 private boolean sendIngestMessages;
802 private boolean indexing;
803 private final PropertyChangeSupport propertyChangeSupport =
new PropertyChangeSupport(
this);
805 private SleuthkitHashSet(
int handle, String hashSetName,
boolean useForIngest,
boolean sendHitMessages,
KnownFilesType knownFilesType) {
806 this.handle = handle;
807 this.hashSetName = hashSetName;
808 this.searchDuringIngest = useForIngest;
809 this.sendIngestMessages = sendHitMessages;
810 this.knownFilesType = knownFilesType;
811 this.indexing =
false;
822 propertyChangeSupport.addPropertyChangeListener(pcl);
832 propertyChangeSupport.removePropertyChangeListener(pcl);
845 String getDisplayName(){
851 return SleuthkitJNI.getHashDatabasePath(handle);
854 public void setIndexing(
boolean indexing){
855 this.indexing = indexing;
860 return SleuthkitJNI.getHashDatabaseIndexPath(handle);
865 return knownFilesType;
870 return searchDuringIngest;
874 void setSearchDuringIngest(
boolean useForIngest) {
875 this.searchDuringIngest = useForIngest;
880 return sendIngestMessages;
884 void setSendIngestMessages(
boolean showInboxMessages) {
885 this.sendIngestMessages = showInboxMessages;
897 return SleuthkitJNI.isUpdateableHashDatabase(this.handle);
909 public void addHashes(Content content)
throws TskCoreException {
924 public void addHashes(Content content, String comment)
throws TskCoreException {
926 assert content instanceof AbstractFile;
927 if (content instanceof AbstractFile) {
928 AbstractFile file = (AbstractFile) content;
929 if (null != file.getMd5Hash()) {
930 SleuthkitJNI.addToHashDatabase(null, file.getMd5Hash(), null, null, comment, handle);
943 public void addHashes(List<HashEntry> hashes)
throws TskCoreException {
944 SleuthkitJNI.addToHashDatabase(hashes, handle);
957 public boolean lookupMD5Quick(Content content)
throws TskCoreException {
958 boolean result =
false;
959 assert content instanceof AbstractFile;
960 if (content instanceof AbstractFile) {
961 AbstractFile file = (AbstractFile) content;
962 if (null != file.getMd5Hash()) {
963 result = SleuthkitJNI.lookupInHashDatabase(file.getMd5Hash(), handle);
979 public HashHitInfo
lookupMD5(Content content)
throws TskCoreException {
980 HashHitInfo result = null;
982 assert content instanceof AbstractFile;
983 if (content instanceof AbstractFile) {
984 AbstractFile file = (AbstractFile) content;
985 if (null != file.getMd5Hash()) {
986 result = SleuthkitJNI.lookupInHashDatabaseVerbose(file.getMd5Hash(), handle);
999 boolean isValid() throws TskCoreException {
1003 boolean hasIndex() throws TskCoreException {
1004 return SleuthkitJNI.hashDatabaseHasLookupIndex(handle);
1008 public boolean hasIndexOnly() throws TskCoreException {
1009 return SleuthkitJNI.hashDatabaseIsIndexOnly(handle);
1012 boolean canBeReIndexed() throws TskCoreException {
1013 return SleuthkitJNI.hashDatabaseCanBeReindexed(handle);
1016 boolean isIndexing() {
1021 public void firePropertyChange(String propertyName, Object oldValue, Object newValue){
1022 this.propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
1025 private void close() throws TskCoreException {
1026 SleuthkitJNI.closeHashDatabase(handle);
1036 public int hashCode() {
1038 code = 47 * code + Integer.hashCode(handle);
1039 code = 47 * code + Objects.hashCode(this.hashSetName);
1040 code = 47 * code + Objects.hashCode(this.propertyChangeSupport);
1041 code = 47 * code + Objects.hashCode(this.knownFilesType);
1046 public boolean equals(Object obj) {
1050 if (getClass() != obj.getClass()) {
1053 final SleuthkitHashSet other = (SleuthkitHashSet) obj;
1054 if (!Objects.equals(
this.hashSetName, other.hashSetName)) {
1057 if (this.knownFilesType != other.knownFilesType) {
1068 class CentralRepoHashSet
extends HashDb{
1070 private static final long serialVersionUID = 1L;
1071 private final String hashSetName;
1072 private boolean searchDuringIngest;
1073 private boolean sendIngestMessages;
1074 private final HashDb.KnownFilesType knownFilesType;
1075 private final int referenceSetID;
1076 private final String version;
1077 private String orgName;
1078 private final boolean readOnly;
1079 private final PropertyChangeSupport propertyChangeSupport =
new PropertyChangeSupport(
this);
1081 @Messages({
"HashDbManager.CentralRepoHashDb.orgError=Error loading organization"})
1082 private CentralRepoHashSet(String hashSetName, String version,
int referenceSetID,
1083 boolean useForIngest,
boolean sendHitMessages, HashDb.KnownFilesType knownFilesType,
1085 throws TskCoreException{
1086 this.hashSetName = hashSetName;
1087 this.version = version;
1088 this.referenceSetID = referenceSetID;
1089 this.searchDuringIngest = useForIngest;
1090 this.sendIngestMessages = sendHitMessages;
1091 this.knownFilesType = knownFilesType;
1092 this.readOnly = readOnly;
1095 orgName = EamDb.getInstance().getReferenceSetOrganization(referenceSetID).getName();
1096 }
catch (EamDbException ex){
1097 Logger.getLogger(SleuthkitHashSet.class.getName()).log(Level.SEVERE,
"Error looking up central repository organization for reference set " + referenceSetID, ex);
1098 orgName = Bundle.HashDbManager_CentralRepoHashDb_orgError();
1110 propertyChangeSupport.addPropertyChangeListener(pcl);
1120 propertyChangeSupport.removePropertyChangeListener(pcl);
1134 public String getDisplayName(){
1135 if(! getVersion().isEmpty()){
1142 String getVersion(){
1146 String getOrgName(){
1150 int getReferenceSetID(){
1151 return referenceSetID;
1166 return knownFilesType;
1171 return searchDuringIngest;
1175 void setSearchDuringIngest(
boolean useForIngest) {
1176 this.searchDuringIngest = useForIngest;
1181 return sendIngestMessages;
1185 void setSendIngestMessages(
boolean showInboxMessages) {
1186 this.sendIngestMessages = showInboxMessages;
1197 public boolean isUpdateable() throws TskCoreException {
1198 return (! readOnly);
1210 public void addHashes(Content content)
throws TskCoreException {
1225 public void addHashes(Content content, String comment)
throws TskCoreException {
1227 assert content instanceof AbstractFile;
1228 if (content instanceof AbstractFile) {
1229 AbstractFile file = (AbstractFile) content;
1230 if (null != file.getMd5Hash()) {
1231 TskData.FileKnown type;
1232 if(knownFilesType.equals(HashDb.KnownFilesType.KNOWN_BAD)){
1233 type = TskData.FileKnown.BAD;
1235 type = TskData.FileKnown.KNOWN;
1239 EamGlobalFileInstance fileInstance =
new EamGlobalFileInstance(referenceSetID, file.getMd5Hash(),
1241 EamDb.getInstance().addReferenceInstance(fileInstance,EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.FILES_TYPE_ID));
1242 }
catch (EamDbException | CorrelationAttributeNormalizationException ex){
1243 throw new TskCoreException(
"Error adding hashes to " + getDisplayName(), ex);
1257 public void addHashes(List<HashEntry> hashes)
throws TskCoreException {
1258 Set<EamGlobalFileInstance> globalFileInstances =
new HashSet<>();
1259 for(HashEntry hashEntry:hashes){
1260 TskData.FileKnown type;
1261 if(knownFilesType.equals(HashDb.KnownFilesType.KNOWN_BAD)){
1262 type = TskData.FileKnown.BAD;
1264 type = TskData.FileKnown.KNOWN;
1267 globalFileInstances.add(
new EamGlobalFileInstance(referenceSetID, hashEntry.getMd5Hash(), type, hashEntry.getComment()));
1268 }
catch (EamDbException | CorrelationAttributeNormalizationException ex){
1269 throw new TskCoreException(
"Error adding hashes to " + getDisplayName(), ex);
1274 EamDb.getInstance().bulkInsertReferenceTypeEntries(globalFileInstances,
1275 EamDb.getInstance().getCorrelationTypeById(CorrelationAttributeInstance.FILES_TYPE_ID));
1276 }
catch (EamDbException ex){
1277 throw new TskCoreException(
"Error adding hashes to " + getDisplayName(), ex);
1291 public boolean lookupMD5Quick(Content content)
throws TskCoreException {
1293 assert content instanceof AbstractFile;
1294 if (content instanceof AbstractFile) {
1295 AbstractFile file = (AbstractFile) content;
1296 if (null != file.getMd5Hash()) {
1298 return EamDb.getInstance().isFileHashInReferenceSet(file.getMd5Hash(), this.referenceSetID);
1299 }
catch (EamDbException | CorrelationAttributeNormalizationException ex){
1300 Logger.getLogger(SleuthkitHashSet.class.getName()).log(Level.SEVERE,
"Error performing central reposiotry hash lookup for hash "
1301 + file.getMd5Hash() +
" in reference set " + referenceSetID, ex);
1302 throw new TskCoreException(
"Error performing central reposiotry hash lookup", ex);
1319 public HashHitInfo
lookupMD5(Content content)
throws TskCoreException {
1320 HashHitInfo result = null;
1322 assert content instanceof AbstractFile;
1323 if (content instanceof AbstractFile) {
1324 AbstractFile file = (AbstractFile) content;
1325 if (null != file.getMd5Hash()) {
1327 if(EamDb.getInstance().isFileHashInReferenceSet(file.getMd5Hash(), this.referenceSetID)){
1329 result =
new HashHitInfo(file.getMd5Hash(),
"",
"");
1331 }
catch (EamDbException | CorrelationAttributeNormalizationException ex){
1332 Logger.getLogger(SleuthkitHashSet.class.getName()).log(Level.SEVERE,
"Error performing central reposiotry hash lookup for hash "
1333 + file.getMd5Hash() +
" in reference set " + referenceSetID, ex);
1334 throw new TskCoreException(
"Error performing central reposiotry hash lookup", ex);
1348 if(! EamDb.isEnabled()) {
1352 return EamDb.getInstance().referenceSetIsValid(this.referenceSetID, this.hashSetName, this.version);
1353 }
catch (EamDbException ex){
1354 Logger.getLogger(CentralRepoHashSet.class.getName()).log(Level.SEVERE,
"Error validating hash set " + hashSetName, ex);
1360 public void firePropertyChange(String propertyName, Object oldValue, Object newValue){
1361 this.propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
1366 return getDisplayName();
1371 public int hashCode() {
1373 code = 47 * code + Objects.hashCode(this.hashSetName);
1374 code = 47 * code + Objects.hashCode(this.version);
1375 code = 47 * code + Integer.hashCode(this.referenceSetID);
1376 code = 47 * code + Objects.hashCode(this.knownFilesType);
1381 public boolean equals(Object obj) {
1385 if (getClass() != obj.getClass()) {
1388 final CentralRepoHashSet other = (CentralRepoHashSet) obj;
1389 if (!Objects.equals(
this.hashSetName, other.hashSetName)) {
1392 if (!Objects.equals(
this.version, other.version)) {
1395 if (this.knownFilesType != other.knownFilesType) {
1407 private ProgressHandle progress = null;
1408 private SleuthkitHashSet hashDb = null;
1411 this.hashDb = hashDb;
1416 hashDb.setIndexing(
true);
1417 progress = ProgressHandle.createHandle(
1418 NbBundle.getMessage(
this.getClass(),
"HashDbManager.progress.indexingHashSet", hashDb.getHashSetName()));
1420 progress.switchToIndeterminate();
1422 SleuthkitJNI.createLookupIndexForHashDatabase(hashDb.getHandle());
1423 }
catch (TskCoreException ex) {
1425 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
1426 NbBundle.getMessage(this.getClass(),
1427 "HashDbManager.dlgMsg.errorIndexingHashSet",
1428 hashDb.getHashSetName()),
1429 NbBundle.getMessage(
this.getClass(),
"HashDbManager.hashDbIndexingErr"),
1430 JOptionPane.ERROR_MESSAGE);
1437 hashDb.setIndexing(
false);
1443 }
catch (InterruptedException | ExecutionException ex) {
1444 logger.log(Level.SEVERE,
"Error creating index", ex);
1446 NbBundle.getMessage(
this.getClass(),
"HashDbManager.errCreatingIndex.title"),
1447 NbBundle.getMessage(
this.getClass(),
"HashDbManager.errCreatingIndex.msg", ex.getMessage()),
1450 catch (java.util.concurrent.CancellationException ex) {
1454 hashDb.firePropertyChange(SleuthkitHashSet.Event.INDEXING_DONE.toString(), null, hashDb);
1456 }
catch (Exception e) {
1457 logger.log(Level.SEVERE,
"HashDbManager listener threw exception", e);
1459 NbBundle.getMessage(
this.getClass(),
"HashDbManager.moduleErr"),
1460 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)