Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
HashLookupModuleSettings.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org *
6 
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.modules.hashdatabase;
20 
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;
27 import org.sleuthkit.datamodel.TskCoreException;
31 
35 final class HashLookupModuleSettings implements IngestModuleIngestJobSettings {
36 
37  private static final long serialVersionUID = 1L;
38  private HashSet<String> namesOfEnabledKnownHashSets; // The four lists of hash set names are only used for upgrading
39  private HashSet<String> namesOfDisabledKnownHashSets; // from older settings files. All data should be stored in
40  private HashSet<String> namesOfEnabledKnownBadHashSets; // the databaseInfoList list.
41  private HashSet<String> namesOfDisabledKnownBadHashSets;
42  private boolean shouldCalculateHashes = true;
43  private List<HashDbInfo> databaseInfoList;
44 
45  HashLookupModuleSettings(boolean shouldCalculateHashes, List<HashDb> hashDbList){
46  this.shouldCalculateHashes = shouldCalculateHashes;
47  try{
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); //NON-NLS
51  databaseInfoList = new ArrayList<>();
52  }
53  }
54 
63  private void readObject(java.io.ObjectInputStream stream)
64  throws IOException, ClassNotFoundException {
65 
66  stream.defaultReadObject();
67  upgradeFromOlderVersions();
68  }
69 
78  HashLookupModuleSettings(boolean shouldCalculateHashes,
79  List<HashDb> enabledHashSets,
80  List<HashDb> disabledHashSets) {
81  this.shouldCalculateHashes = shouldCalculateHashes;
82 
83  databaseInfoList = new ArrayList<>();
84  for(HashDb db:enabledHashSets){
85  try{
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); //NON-NLS
91  }
92  }
93  for(HashDb db:disabledHashSets){
94  try{
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); //NON-NLS
100  }
101  }
102 
103  }
104 
108  @Override
109  public long getVersionNumber() {
110  return HashLookupModuleSettings.serialVersionUID;
111  }
112 
119  boolean shouldCalculateHashes() {
120  return this.shouldCalculateHashes;
121  }
122 
131  boolean isHashSetEnabled(HashDb db) {
132  for(HashDbInfo dbInfo:databaseInfoList){
133  if(dbInfo.matches(db)){
134  return dbInfo.getSearchDuringIngest();
135  }
136  }
137 
138  // We didn't find it, so use the value in the HashDb object
139  return db.getSearchDuringIngest();
140  }
141 
146  private void upgradeFromOlderVersions() {
147 
148  if(databaseInfoList != null){
149  return;
150  }
151 
152  try{
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); //NON-NLS
156  return;
157  }
158 
159  List<String> disabledHashSetNames = new ArrayList<>();
160  if(namesOfDisabledKnownHashSets != null){
161  disabledHashSetNames.addAll(namesOfDisabledKnownHashSets);
162  }
163  if(namesOfDisabledKnownBadHashSets != null){
164  disabledHashSetNames.addAll(namesOfDisabledKnownBadHashSets);
165  }
166 
167  for(HashLookupSettings.HashDbInfo db:databaseInfoList){
168  if(db.isFileDatabaseType() && disabledHashSetNames.contains(db.getHashSetName())){
169  db.setSearchDuringIngest(false);
170  } else {
171  db.setSearchDuringIngest(true);
172  }
173  }
174 
175  namesOfDisabledKnownHashSets = null;
176  namesOfDisabledKnownBadHashSets = null;
177  namesOfEnabledKnownHashSets = null;
178  namesOfEnabledKnownBadHashSets = null;
179  }
180 
181 }

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.