Autopsy  4.9.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddTaggedHashesToHashDb.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.taggedhashes;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.logging.Level;
25 import javax.swing.JOptionPane;
26 import javax.swing.JPanel;
27 import org.openide.util.lookup.ServiceProvider;
28 import org.openide.windows.WindowManager;
35 import org.sleuthkit.datamodel.AbstractFile;
36 import org.sleuthkit.datamodel.Content;
37 import org.sleuthkit.datamodel.ContentTag;
38 import org.sleuthkit.datamodel.TagName;
39 import org.sleuthkit.datamodel.TskCoreException;
40 
45 @ServiceProvider(service = GeneralReportModule.class)
47 
48  private AddTaggedHashesToHashDbConfigPanel configPanel;
49 
51  }
52 
53  @Override
54  public String getName() {
55  return "Add Tagged Hashes";
56  }
57 
58  @Override
59  public String getDescription() {
60  return "Adds hashes of tagged files to a hash set.";
61  }
62 
63  @Override
64  public String getRelativeFilePath() {
65  return "";
66  }
67 
68  @Override
69  public void generateReport(String reportPath, ReportProgressPanel progressPanel) {
70  Case openCase;
71  try {
72  openCase = Case.getCurrentCaseThrows();
73  } catch (NoCurrentCaseException ex) {
74  Logger.getLogger(AddTaggedHashesToHashDb.class.getName()).log(Level.SEVERE, "Exception while getting open case.", ex);
75  JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), "No open Case", "Exception while getting open case.", JOptionPane.ERROR_MESSAGE);
76  return;
77  }
78  progressPanel.setIndeterminate(true);
79  progressPanel.start();
80  progressPanel.updateStatusLabel("Adding hashes...");
81 
82  HashDb hashSet = configPanel.getSelectedHashDatabase();
83  if (hashSet != null) {
84  progressPanel.updateStatusLabel("Adding hashes to " + hashSet.getHashSetName() + " hash set...");
85 
86  TagsManager tagsManager = openCase.getServices().getTagsManager();
87  List<TagName> tagNames = configPanel.getSelectedTagNames();
88  ArrayList<String> failedExports = new ArrayList<>();
89  for (TagName tagName : tagNames) {
90  if (progressPanel.getStatus() == ReportProgressPanel.ReportStatus.CANCELED) {
91  break;
92  }
93 
94  progressPanel.updateStatusLabel("Adding " + tagName.getDisplayName() + " hashes to " + hashSet.getHashSetName() + " hash set...");
95  try {
96  List<ContentTag> tags = tagsManager.getContentTagsByTagName(tagName);
97  for (ContentTag tag : tags) {
98  // TODO: Currently only AbstractFiles have md5 hashes. Here only files matter.
99  Content content = tag.getContent();
100  if (content instanceof AbstractFile) {
101  if (null != ((AbstractFile) content).getMd5Hash()) {
102  try {
103  hashSet.addHashes(tag.getContent(), openCase.getDisplayName());
104  } catch (TskCoreException ex) {
105  Logger.getLogger(AddTaggedHashesToHashDb.class.getName()).log(Level.SEVERE, "Error adding hash for obj_id = " + tag.getContent().getId() + " to hash set " + hashSet.getHashSetName(), ex);
106  failedExports.add(tag.getContent().getName());
107  }
108  } else {
109  JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), "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.", "Add to Hash Set Error", JOptionPane.ERROR_MESSAGE);
110  break;
111  }
112  }
113  }
114  } catch (TskCoreException ex) {
115  Logger.getLogger(AddTaggedHashesToHashDb.class.getName()).log(Level.SEVERE, "Error adding to hash set", ex);
116  JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), "Error getting selected tags for case.", "Hash Export Error", JOptionPane.ERROR_MESSAGE);
117  }
118  }
119  if (!failedExports.isEmpty()) {
120  StringBuilder errorMessage = new StringBuilder("Failed to export hashes for the following files: ");
121  for (int i = 0; i < failedExports.size(); ++i) {
122  errorMessage.append(failedExports.get(i));
123  if (failedExports.size() > 1 && i < failedExports.size() - 1) {
124  errorMessage.append(",");
125  }
126  if (i == failedExports.size() - 1) {
127  errorMessage.append(".");
128  }
129  }
130  JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), errorMessage.toString(), "Hash Export Error", JOptionPane.ERROR_MESSAGE);
131  }
132  }
133  progressPanel.setIndeterminate(false);
135  }
136 
137  @Override
138  public JPanel getConfigurationPanel() {
139  configPanel = new AddTaggedHashesToHashDbConfigPanel();
140  return configPanel;
141  }
142 }
void generateReport(String reportPath, ReportProgressPanel progressPanel)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
List< ContentTag > getContentTagsByTagName(TagName tagName)

Copyright © 2012-2018 Basis Technology. Generated on: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.