19 package org.sleuthkit.autopsy.modules.hashdatabase;
21 import java.util.ArrayList;
22 import java.util.HashSet;
23 import java.util.List;
24 import java.util.logging.Level;
25 import java.io.IOException;
35 final class HashLookupModuleSettings
implements IngestModuleIngestJobSettings {
37 private static final long serialVersionUID = 1L;
38 private HashSet<String> namesOfEnabledKnownHashSets;
39 private HashSet<String> namesOfDisabledKnownHashSets;
40 private HashSet<String> namesOfEnabledKnownBadHashSets;
41 private HashSet<String> namesOfDisabledKnownBadHashSets;
42 private boolean shouldCalculateHashes =
true;
43 private List<HashDbInfo> databaseInfoList;
45 HashLookupModuleSettings(
boolean shouldCalculateHashes, List<HashDb> hashDbList){
46 this.shouldCalculateHashes = shouldCalculateHashes;
48 databaseInfoList = HashLookupSettings.convertHashSetList(hashDbList);
49 }
catch (HashLookupSettings.HashLookupSettingsException ex){
50 Logger.getLogger(HashLookupModuleSettings.class.getName()).log(Level.SEVERE,
"Error creating hash set settings.", ex);
51 databaseInfoList =
new ArrayList<>();
63 private void readObject(java.io.ObjectInputStream stream)
64 throws IOException, ClassNotFoundException {
66 stream.defaultReadObject();
67 upgradeFromOlderVersions();
78 HashLookupModuleSettings(
boolean shouldCalculateHashes,
79 List<HashDb> enabledHashSets,
80 List<HashDb> disabledHashSets) {
81 this.shouldCalculateHashes = shouldCalculateHashes;
83 databaseInfoList =
new ArrayList<>();
84 for(HashDb db:enabledHashSets){
86 HashDbInfo dbInfo =
new HashDbInfo(db);
87 dbInfo.setSearchDuringIngest(
true);
88 databaseInfoList.add(dbInfo);
89 }
catch (TskCoreException ex){
90 Logger.getLogger(HashLookupModuleSettings.class.getName()).log(Level.SEVERE,
"Error creating hash set settings for " + db.getHashSetName(), ex);
93 for(HashDb db:disabledHashSets){
95 HashDbInfo dbInfo =
new HashDbInfo(db);
96 dbInfo.setSearchDuringIngest(
false);
97 databaseInfoList.add(dbInfo);
98 }
catch (TskCoreException ex){
99 Logger.getLogger(HashLookupModuleSettings.class.getName()).log(Level.SEVERE,
"Error creating hash set settings for " + db.getHashSetName(), ex);
109 public long getVersionNumber() {
110 return HashLookupModuleSettings.serialVersionUID;
119 boolean shouldCalculateHashes() {
120 return this.shouldCalculateHashes;
131 boolean isHashSetEnabled(HashDb db) {
132 for(HashDbInfo dbInfo:databaseInfoList){
133 if(dbInfo.matches(db)){
134 return dbInfo.getSearchDuringIngest();
139 return db.getSearchDuringIngest();
146 private void upgradeFromOlderVersions() {
148 if(databaseInfoList != null){
153 databaseInfoList = HashLookupSettings.convertHashSetList(HashDbManager.getInstance().getAllHashSets());
154 }
catch (HashLookupSettings.HashLookupSettingsException ex){
155 Logger.getLogger(HashLookupModuleSettings.class.getName()).log(Level.SEVERE,
"Error updating hash set settings.", ex);
159 List<String> disabledHashSetNames =
new ArrayList<>();
160 if(namesOfDisabledKnownHashSets != null){
161 disabledHashSetNames.addAll(namesOfDisabledKnownHashSets);
163 if(namesOfDisabledKnownBadHashSets != null){
164 disabledHashSetNames.addAll(namesOfDisabledKnownBadHashSets);
167 for(HashLookupSettings.HashDbInfo db:databaseInfoList){
168 if(db.isFileDatabaseType() && disabledHashSetNames.contains(db.getHashSetName())){
169 db.setSearchDuringIngest(
false);
171 db.setSearchDuringIngest(
true);
175 namesOfDisabledKnownHashSets = null;
176 namesOfDisabledKnownBadHashSets = null;
177 namesOfEnabledKnownHashSets = null;
178 namesOfEnabledKnownBadHashSets = null;