Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CaseUcoReportModule.java
Go to the documentation of this file.
1 /*
2  *
3  * Autopsy Forensic Browser
4  *
5  * Copyright 2018-2020 Basis Technology Corp.
6  * Project Contact/Architect: carrier <at> sleuthkit <dot> org
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 package org.sleuthkit.autopsy.report.modules.caseuco;
21 
22 import java.io.IOException;
23 import java.nio.file.Files;
24 import java.nio.file.Path;
25 import java.nio.file.Paths;
26 import java.util.ArrayDeque;
27 import java.util.Deque;
28 import java.util.HashSet;
29 import java.util.List;
30 import java.util.Set;
31 import java.util.logging.Level;
32 import javax.swing.JPanel;
33 import org.openide.util.NbBundle;
40 import org.sleuthkit.datamodel.AbstractFile;
41 import org.sleuthkit.datamodel.Content;
42 import org.sleuthkit.datamodel.TskCoreException;
43 import org.sleuthkit.datamodel.TskData;
44 
49 public final class CaseUcoReportModule implements GeneralReportModule {
50 
51  private static final Logger logger = Logger.getLogger(CaseUcoReportModule.class.getName());
53 
54  //Supported types of TSK_FS_FILES
55  private static final Set<Short> SUPPORTED_TYPES = new HashSet<Short>() {{
56  add(TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_UNDEF.getValue());
57  add(TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_REG.getValue());
58  add(TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_VIRT.getValue());
59  }};
60 
61  private static final String REPORT_FILE_NAME = "CASE_UCO_output";
62  private static final String EXTENSION = "json-ld";
63 
64  // Hidden constructor for the report
65  private CaseUcoReportModule() {
66  }
67 
68  // Get the default implementation of this report
69  public static synchronized CaseUcoReportModule getDefault() {
70  return SINGLE_INSTANCE;
71  }
72 
73  @Override
74  public String getName() {
75  return NbBundle.getMessage(this.getClass(), "CaseUcoReportModule.getName.text");
76  }
77 
78  @Override
79  public JPanel getConfigurationPanel() {
80  return null; // No configuration panel
81  }
82 
83  @Override
84  public String getRelativeFilePath() {
85  return REPORT_FILE_NAME + "." + EXTENSION;
86  }
87 
88  @Override
89  public String getDescription() {
90  return NbBundle.getMessage(this.getClass(), "CaseUcoReportModule.getDesc.text");
91  }
92 
98  public static String getReportFileName() {
99  return REPORT_FILE_NAME;
100  }
101 
108  @NbBundle.Messages({
109  "CaseUcoReportModule.notInitialized=CASE-UCO settings panel has not been initialized",
110  "CaseUcoReportModule.noDataSourceSelected=No data source selected for CASE-UCO report",
111  "CaseUcoReportModule.ioError=I/O error encountered while generating report",
112  "CaseUcoReportModule.noCaseOpen=No case is currently open",
113  "CaseUcoReportModule.tskCoreException=TskCoreException [%s] encountered while generating the report. Please reference the log for more details.",
114  "CaseUcoReportModule.processingDataSource=Processing datasource: %s",
115  "CaseUcoReportModule.ingestWarning=Warning, this report will be created before ingest services completed",
116  "CaseUcoReportModule.unableToCreateDirectories=Unable to create directory for CASE-UCO report",
117  "CaseUcoReportModule.srcModuleName=CASE-UCO Report"
118  })
119  @Override
120  @SuppressWarnings("deprecation")
121  public void generateReport(String baseReportDir, ReportProgressPanel progressPanel) {
122  try {
123  // Check if ingest has finished
124  warnIngest(progressPanel);
125 
126  //Create report paths if they don't already exist.
127  Path reportDirectory = Paths.get(baseReportDir);
128  try {
129  Files.createDirectories(reportDirectory);
130  } catch (IOException ex) {
131  logger.log(Level.WARNING, "Unable to create directory for CASE-UCO report.", ex);
133  Bundle.CaseUcoReportModule_unableToCreateDirectories());
134  return;
135  }
136 
137  CaseUcoReportGenerator generator =
138  new CaseUcoReportGenerator(reportDirectory, REPORT_FILE_NAME);
139 
140  //First write the Case to the report file.
141  Case caseObj = Case.getCurrentCaseThrows();
142  generator.addCase(caseObj);
143 
144  List<Content> dataSources = caseObj.getDataSources();
145  progressPanel.setIndeterminate(false);
146  progressPanel.setMaximumProgress(dataSources.size());
147  progressPanel.start();
148 
149  //Then search each data source for file content.
150  for(int i = 0; i < dataSources.size(); i++) {
151  Content dataSource = dataSources.get(i);
152  progressPanel.updateStatusLabel(String.format(
153  Bundle.CaseUcoReportModule_processingDataSource(),
154  dataSource.getName()));
155  //Add the data source and then all children.
156  generator.addDataSource(dataSource, caseObj);
157  performDepthFirstSearch(dataSource, generator);
158  progressPanel.setProgress(i+1);
159  }
160 
161  //Complete the report.
162  Path reportPath = generator.generateReport();
163  caseObj.addReport(reportPath.toString(),
164  Bundle.CaseUcoReportModule_srcModuleName(),
167  } catch (IOException ex) {
168  logger.log(Level.WARNING, "I/O error encountered while generating the report.", ex);
170  Bundle.CaseUcoReportModule_ioError());
171  } catch (NoCurrentCaseException ex) {
172  logger.log(Level.WARNING, "No case open.", ex);
174  Bundle.CaseUcoReportModule_noCaseOpen());
175  } catch (TskCoreException ex) {
176  logger.log(Level.WARNING, "TskCoreException encounted while generating the report.", ex);
178  String.format(Bundle.CaseUcoReportModule_tskCoreException(), ex.toString()));
179  }
180 
182  }
183 
187  private void warnIngest(ReportProgressPanel progressPanel) {
189  progressPanel.updateStatusLabel(Bundle.CaseUcoReportModule_ingestWarning());
190  }
191  }
192 
197  private void performDepthFirstSearch(Content dataSource,
198  CaseUcoReportGenerator generator) throws IOException, TskCoreException {
199 
200  Deque<Content> stack = new ArrayDeque<>();
201  stack.addAll(dataSource.getChildren());
202 
203  //Depth First Search the data source tree.
204  while(!stack.isEmpty()) {
205  Content current = stack.pop();
206  if(current instanceof AbstractFile) {
207  AbstractFile f = (AbstractFile) (current);
208  if(SUPPORTED_TYPES.contains(f.getMetaType().getValue())) {
209  generator.addFile(f, dataSource);
210  }
211  }
212 
213  for(Content child : current.getChildren()) {
214  stack.push(child);
215  }
216  }
217  }
218 }
List< Content > getDataSources()
Definition: Case.java:1438
static synchronized IngestManager getInstance()
void addReport(String localPath, String srcModuleName, String reportName)
Definition: Case.java:1630
void performDepthFirstSearch(Content dataSource, CaseUcoReportGenerator generator)
void generateReport(String baseReportDir, ReportProgressPanel progressPanel)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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.