Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
SaveTaggedHashesToHashDb.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2018 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.report.modules.taggedhashes;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.logging.Level;
25 import javax.swing.JPanel;
26 import org.openide.util.NbBundle.Messages;
27 import org.openide.util.lookup.ServiceProvider;
36 import org.sleuthkit.datamodel.AbstractFile;
37 import org.sleuthkit.datamodel.Content;
38 import org.sleuthkit.datamodel.ContentTag;
39 import org.sleuthkit.datamodel.TagName;
40 import org.sleuthkit.datamodel.TskCoreException;
41 
46 @ServiceProvider(service = GeneralReportModule.class)
48 
49  private static final Logger logger = Logger.getLogger(SaveTaggedHashesToHashDb.class.getName());
50  private SaveTaggedHashesToHashDbConfigPanel configPanel;
51 
53  }
54 
55  @Override
56  public String getName() {
57  return "Save Tagged Hashes";
58  }
59 
60  @Override
61  public String getDescription() {
62  return "Adds hashes of tagged files to a hash set.";
63  }
64 
65  @Override
66  public String getRelativeFilePath() {
67  return null;
68  }
69 
75  @Override
77  return new HashesReportModuleSettings();
78  }
79 
85  @Override
87  initializePanel();
88  return configPanel.getConfiguration();
89  }
90 
96  @Override
97  public void setConfiguration(ReportModuleSettings settings) {
98  initializePanel();
99  if (settings == null || settings instanceof NoReportModuleSettings) {
100  configPanel.setConfiguration((HashesReportModuleSettings) getDefaultConfiguration());
101  return;
102  }
103 
104  if (settings instanceof HashesReportModuleSettings) {
105  configPanel.setConfiguration((HashesReportModuleSettings) settings);
106  return;
107  }
108 
109  throw new IllegalArgumentException("Expected settings argument to be an instance of HashesReportModuleSettings");
110  }
111 
112  @Messages({
113  "AddTaggedHashesToHashDb.error.noHashSetsSelected=No hash set selected for export.",
114  "AddTaggedHashesToHashDb.error.unableToOpenCase=Exception while getting open case.",
115  "AddTaggedHashesToHashDb.error.noTagsSelected=No tags selected for export."
116  })
117  @Override
118  public void generateReport(String reportPath, ReportProgressPanel progressPanel) {
119  Case openCase;
120  try {
121  openCase = Case.getCurrentCaseThrows();
122  } catch (NoCurrentCaseException ex) {
123  Logger.getLogger(SaveTaggedHashesToHashDb.class.getName()).log(Level.SEVERE, "Exception while getting open case.", ex);
124  progressPanel.complete(ReportProgressPanel.ReportStatus.ERROR, Bundle.AddTaggedHashesToHashDb_error_unableToOpenCase());
125  return;
126  }
127  progressPanel.setIndeterminate(true);
128  progressPanel.start();
129  progressPanel.updateStatusLabel("Adding hashes...");
130 
131  HashDb hashSet = configPanel.getSelectedHashDatabase();
132  if (hashSet == null) {
133  logger.log(Level.WARNING, "No hash set selected for export."); //NON-NLS
134  progressPanel.setIndeterminate(false);
135  progressPanel.complete(ReportProgressPanel.ReportStatus.ERROR, Bundle.AddTaggedHashesToHashDb_error_noHashSetsSelected());
136  return;
137  }
138 
139  progressPanel.updateStatusLabel("Adding hashes to " + hashSet.getHashSetName() + " hash set...");
140 
141  TagsManager tagsManager = openCase.getServices().getTagsManager();
142  List<TagName> tagNames = configPanel.getSelectedTagNames();
143  if (tagNames.isEmpty()) {
144  logger.log(Level.WARNING, "No tags selected for export."); //NON-NLS
145  progressPanel.setIndeterminate(false);
146  progressPanel.complete(ReportProgressPanel.ReportStatus.ERROR, Bundle.AddTaggedHashesToHashDb_error_noTagsSelected());
147  return;
148  }
149 
150  ArrayList<String> failedExports = new ArrayList<>();
151  for (TagName tagName : tagNames) {
152  if (progressPanel.getStatus() == ReportProgressPanel.ReportStatus.CANCELED) {
153  break;
154  }
155 
156  progressPanel.updateStatusLabel("Adding " + tagName.getDisplayName() + " hashes to " + hashSet.getHashSetName() + " hash set...");
157  try {
158  List<ContentTag> tags = tagsManager.getContentTagsByTagName(tagName);
159  for (ContentTag tag : tags) {
160  // TODO: Currently only AbstractFiles have md5 hashes. Here only files matter.
161  Content content = tag.getContent();
162  if (content instanceof AbstractFile) {
163  if (null != ((AbstractFile) content).getMd5Hash()) {
164  try {
165  hashSet.addHashes(tag.getContent(), openCase.getDisplayName());
166  } catch (TskCoreException ex) {
167  Logger.getLogger(SaveTaggedHashesToHashDb.class.getName()).log(Level.SEVERE, "Error adding hash for obj_id = " + tag.getContent().getId() + " to hash set " + hashSet.getHashSetName(), ex);
168  failedExports.add(tag.getContent().getName());
169  }
170  } else {
171  progressPanel.updateStatusLabel("Unable to add the " + (tags.size() > 1 ? "files" : "file") + " to the hash set. Hashes have not been calculated. Please configure and run an appropriate ingest module.");
172  break;
173  }
174  }
175  }
176  } catch (TskCoreException ex) {
177  Logger.getLogger(SaveTaggedHashesToHashDb.class.getName()).log(Level.SEVERE, "Error adding to hash set", ex);
178  progressPanel.updateStatusLabel("Error getting selected tags for case.");
179  }
180  }
181  if (!failedExports.isEmpty()) {
182  StringBuilder errorMessage = new StringBuilder("Failed to export hashes for the following files: ");
183  for (int i = 0; i < failedExports.size(); ++i) {
184  errorMessage.append(failedExports.get(i));
185  if (failedExports.size() > 1 && i < failedExports.size() - 1) {
186  errorMessage.append(",");
187  }
188  if (i == failedExports.size() - 1) {
189  errorMessage.append(".");
190  }
191  }
192  progressPanel.updateStatusLabel(errorMessage.toString());
193  }
194 
195  progressPanel.setIndeterminate(false);
197  }
198 
199  @Override
200  public JPanel getConfigurationPanel() {
201  initializePanel();
202  return configPanel;
203  }
204 
205  private void initializePanel() {
206  if (configPanel == null) {
207  configPanel = new SaveTaggedHashesToHashDbConfigPanel();
208  }
209  }
210 }
void generateReport(String reportPath, ReportProgressPanel progressPanel)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
List< ContentTag > getContentTagsByTagName(TagName tagName)

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.