Autopsy  4.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-2016 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;
38 
43 @ServiceProvider(service = GeneralReportModule.class)
45 
46  private AddTaggedHashesToHashDbConfigPanel configPanel;
47 
49  }
50 
51  @Override
52  public String getName() {
53  return "Add Tagged Hashes";
54  }
55 
56  @Override
57  public String getDescription() {
58  return "Adds hashes of tagged files to a hash database.";
59  }
60 
61  @Override
62  public String getRelativeFilePath() {
63  return "";
64  }
65 
66  @Override
67  public void generateReport(String reportPath, ReportProgressPanel progressPanel) {
68  progressPanel.setIndeterminate(true);
69  progressPanel.start();
70  progressPanel.updateStatusLabel("Adding hashes...");
71 
72  HashDb hashSet = configPanel.getSelectedHashDatabase();
73  if (hashSet != null) {
74  progressPanel.updateStatusLabel("Adding hashes to " + hashSet.getHashSetName() + " hash set...");
75 
77  List<TagName> tagNames = configPanel.getSelectedTagNames();
78  ArrayList<String> failedExports = new ArrayList<>();
79  for (TagName tagName : tagNames) {
80  if (progressPanel.getStatus() == ReportProgressPanel.ReportStatus.CANCELED) {
81  break;
82  }
83 
84  progressPanel.updateStatusLabel("Adding " + tagName.getDisplayName() + " hashes to " + hashSet.getHashSetName() + " hash set...");
85  try {
86  List<ContentTag> tags = tagsManager.getContentTagsByTagName(tagName);
87  for (ContentTag tag : tags) {
88  // TODO: Currently only AbstractFiles have md5 hashes. Here only files matter.
89  Content content = tag.getContent();
90  if (content instanceof AbstractFile) {
91  if (null != ((AbstractFile) content).getMd5Hash()) {
92  try {
93  hashSet.addHashes(tag.getContent(), Case.getCurrentCase().getDisplayName());
94  } catch (TskCoreException ex) {
95  Logger.getLogger(AddTaggedHashesToHashDb.class.getName()).log(Level.SEVERE, "Error adding hash for obj_id = " + tag.getContent().getId() + " to hash database " + hashSet.getHashSetName(), ex);
96  failedExports.add(tag.getContent().getName());
97  }
98  } else {
99  JOptionPane.showMessageDialog(null, "Unable to add the " + (tags.size() > 1 ? "files" : "file") + " to the hash database. Hashes have not been calculated. Please configure and run an appropriate ingest module.", "Add to Hash Database Error", JOptionPane.ERROR_MESSAGE);
100  break;
101  }
102  }
103  }
104  } catch (TskCoreException ex) {
105  Logger.getLogger(AddTaggedHashesToHashDb.class.getName()).log(Level.SEVERE, "Error adding to hash database", ex);
106  JOptionPane.showMessageDialog(null, "Error getting selected tags for case.", "Hash Export Error", JOptionPane.ERROR_MESSAGE);
107  }
108  }
109  if (!failedExports.isEmpty()) {
110  StringBuilder errorMessage = new StringBuilder("Failed to export hashes for the following files: ");
111  for (int i = 0; i < failedExports.size(); ++i) {
112  errorMessage.append(failedExports.get(i));
113  if (failedExports.size() > 1 && i < failedExports.size() - 1) {
114  errorMessage.append(",");
115  }
116  if (i == failedExports.size() - 1) {
117  errorMessage.append(".");
118  }
119  }
120  JOptionPane.showMessageDialog(null, errorMessage.toString(), "Hash Export Error", JOptionPane.ERROR_MESSAGE);
121  }
122  }
123  progressPanel.setIndeterminate(false);
125  }
126 
127  @Override
128  public JPanel getConfigurationPanel() {
129  configPanel = new AddTaggedHashesToHashDbConfigPanel();
130  return configPanel;
131  }
132 }
synchronized List< ContentTag > getContentTagsByTagName(TagName tagName)
void generateReport(String reportPath, ReportProgressPanel progressPanel)
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

Copyright © 2012-2016 Basis Technology. Generated on: Mon Apr 24 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.