Autopsy  4.10.0
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.NbBundle.Messages;
28 import org.openide.util.lookup.ServiceProvider;
29 import org.openide.windows.WindowManager;
37 import org.sleuthkit.datamodel.AbstractFile;
38 import org.sleuthkit.datamodel.Content;
39 import org.sleuthkit.datamodel.ContentTag;
40 import org.sleuthkit.datamodel.TagName;
41 import org.sleuthkit.datamodel.TskCoreException;
42 
47 @ServiceProvider(service = GeneralReportModule.class)
49 
50  private static final Logger logger = Logger.getLogger(AddTaggedHashesToHashDb.class.getName());
51  private AddTaggedHashesToHashDbConfigPanel configPanel;
52 
54  }
55 
56  @Override
57  public String getName() {
58  return "Add Tagged Hashes";
59  }
60 
61  @Override
62  public String getDescription() {
63  return "Adds hashes of tagged files to a hash set.";
64  }
65 
66  @Override
67  public String getRelativeFilePath() {
68  return "";
69  }
70 
71  @Messages({
72  "AddTaggedHashesToHashDb.error.noHashSetsSelected=No hash set selected for export.",
73  "AddTaggedHashesToHashDb.error.noTagsSelected=No tags selected for export."
74  })
75  @Override
76  public void generateReport(String reportPath, ReportProgressPanel progressPanel) {
77  Case openCase;
78  try {
79  openCase = Case.getCurrentCaseThrows();
80  } catch (NoCurrentCaseException ex) {
81  Logger.getLogger(AddTaggedHashesToHashDb.class.getName()).log(Level.SEVERE, "Exception while getting open case.", ex);
82  JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), "No open Case", "Exception while getting open case.", JOptionPane.ERROR_MESSAGE);
83  return;
84  }
85  progressPanel.setIndeterminate(true);
86  progressPanel.start();
87  progressPanel.updateStatusLabel("Adding hashes...");
88 
89  HashDb hashSet = configPanel.getSelectedHashDatabase();
90  if (hashSet == null) {
91  logger.log(Level.WARNING, "No hash set selected for export."); //NON-NLS
92  MessageNotifyUtil.Message.error(Bundle.AddTaggedHashesToHashDb_error_noHashSetsSelected());
93  progressPanel.setIndeterminate(false);
95  return;
96  }
97 
98  progressPanel.updateStatusLabel("Adding hashes to " + hashSet.getHashSetName() + " hash set...");
99 
100  TagsManager tagsManager = openCase.getServices().getTagsManager();
101  List<TagName> tagNames = configPanel.getSelectedTagNames();
102  if (tagNames.isEmpty()) {
103  logger.log(Level.WARNING, "No tags selected for export."); //NON-NLS
104  MessageNotifyUtil.Message.error(Bundle.AddTaggedHashesToHashDb_error_noTagsSelected());
105  progressPanel.setIndeterminate(false);
107  return;
108  }
109 
110  ArrayList<String> failedExports = new ArrayList<>();
111  for (TagName tagName : tagNames) {
112  if (progressPanel.getStatus() == ReportProgressPanel.ReportStatus.CANCELED) {
113  break;
114  }
115 
116  progressPanel.updateStatusLabel("Adding " + tagName.getDisplayName() + " hashes to " + hashSet.getHashSetName() + " hash set...");
117  try {
118  List<ContentTag> tags = tagsManager.getContentTagsByTagName(tagName);
119  for (ContentTag tag : tags) {
120  // TODO: Currently only AbstractFiles have md5 hashes. Here only files matter.
121  Content content = tag.getContent();
122  if (content instanceof AbstractFile) {
123  if (null != ((AbstractFile) content).getMd5Hash()) {
124  try {
125  hashSet.addHashes(tag.getContent(), openCase.getDisplayName());
126  } catch (TskCoreException ex) {
127  Logger.getLogger(AddTaggedHashesToHashDb.class.getName()).log(Level.SEVERE, "Error adding hash for obj_id = " + tag.getContent().getId() + " to hash set " + hashSet.getHashSetName(), ex);
128  failedExports.add(tag.getContent().getName());
129  }
130  } else {
131  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);
132  break;
133  }
134  }
135  }
136  } catch (TskCoreException ex) {
137  Logger.getLogger(AddTaggedHashesToHashDb.class.getName()).log(Level.SEVERE, "Error adding to hash set", ex);
138  JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), "Error getting selected tags for case.", "Hash Export Error", JOptionPane.ERROR_MESSAGE);
139  }
140  }
141  if (!failedExports.isEmpty()) {
142  StringBuilder errorMessage = new StringBuilder("Failed to export hashes for the following files: ");
143  for (int i = 0; i < failedExports.size(); ++i) {
144  errorMessage.append(failedExports.get(i));
145  if (failedExports.size() > 1 && i < failedExports.size() - 1) {
146  errorMessage.append(",");
147  }
148  if (i == failedExports.size() - 1) {
149  errorMessage.append(".");
150  }
151  }
152  JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), errorMessage.toString(), "Hash Export Error", JOptionPane.ERROR_MESSAGE);
153  }
154 
155  progressPanel.setIndeterminate(false);
157  }
158 
159  @Override
160  public JPanel getConfigurationPanel() {
161  configPanel = new AddTaggedHashesToHashDbConfigPanel();
162  return configPanel;
163  }
164 }
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: Fri Mar 22 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.