19package org.sleuthkit.autopsy.centralrepository.ingestmodule;
21import java.util.HashSet;
24import java.util.logging.Level;
25import org.openide.util.NbBundle.Messages;
26import org.sleuthkit.autopsy.casemodule.Case;
27import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
28import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttributeInstance;
29import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttributeNormalizationException;
30import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationCase;
31import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationDataSource;
32import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttributeUtil;
33import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoException;
34import org.sleuthkit.autopsy.coreutils.Logger;
35import org.sleuthkit.autopsy.healthmonitor.HealthMonitor;
36import org.sleuthkit.autopsy.healthmonitor.TimingMetric;
37import org.sleuthkit.autopsy.ingest.FileIngestModule;
38import org.sleuthkit.autopsy.ingest.IngestJobContext;
39import org.sleuthkit.autopsy.ingest.IngestModuleReferenceCounter;
40import org.sleuthkit.datamodel.AbstractFile;
41import org.sleuthkit.datamodel.HashUtility;
42import org.sleuthkit.datamodel.TskData;
43import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepository;
44import static org.sleuthkit.autopsy.centralrepository.ingestmodule.CentralRepoIngestModuleUtils.makePrevNotableAnalysisResult;
53 private static final Logger logger = Logger.getLogger(CentralRepoIngestModule.class.getName());
54 private static final IngestModuleReferenceCounter refCounter =
new IngestModuleReferenceCounter();
55 private final boolean flagNotableItems;
56 private final boolean saveCorrAttrInstances;
57 private CorrelationAttributeInstance.Type filesType;
58 private IngestJobContext context;
59 private CentralRepository centralRepo;
68 CentralRepoIngestModule(IngestSettings settings) {
69 flagNotableItems = settings.isFlagTaggedNotableItems();
70 saveCorrAttrInstances = settings.shouldCreateCorrelationProperties();
75 if (!flagNotableItems && !saveCorrAttrInstances) {
79 if (!filesType.isEnabled()) {
83 if (abstractFile.getKnown() == TskData.FileKnown.KNOWN) {
87 if (!CorrelationAttributeUtil.isSupportedAbstractFileType(abstractFile)) {
98 String md5 = abstractFile.getMd5Hash();
99 if ((md5 ==
null) || (HashUtility.isNoDataMd5(md5))) {
103 if (flagNotableItems) {
105 TimingMetric timingMetric = HealthMonitor.getTimingMetric(
"Central Repository: Notable artifact query");
106 Set<String> otherCases =
new HashSet<>();
107 otherCases.addAll(centralRepo.getListCasesHavingArtifactInstancesKnownBad(filesType, md5));
108 HealthMonitor.submitTimingMetric(timingMetric);
109 if (!otherCases.isEmpty()) {
110 makePrevNotableAnalysisResult(abstractFile, otherCases, filesType, md5, context.getDataSource().getId(), context.getJobId());
112 }
catch (CentralRepoException ex) {
113 logger.log(Level.SEVERE,
"Error searching database for artifact.", ex);
114 }
catch (CorrelationAttributeNormalizationException ex) {
115 logger.log(Level.INFO,
"Error searching database for artifact: " + ex.getMessage());
119 if (saveCorrAttrInstances) {
120 List<CorrelationAttributeInstance> corrAttrs = CorrelationAttributeUtil.makeCorrAttrsToSave(abstractFile);
121 for (CorrelationAttributeInstance corrAttr : corrAttrs) {
123 centralRepo.addAttributeInstanceBulk(corrAttr);
124 }
catch (CentralRepoException ex) {
125 logger.log(Level.SEVERE,
"Error adding artifact to bulk artifacts.", ex);
135 if (refCounter.decrementAndGet(context.getJobId()) == 0) {
137 centralRepo.commitAttributeInstancesBulk();
138 }
catch (CentralRepoException ex) {
139 logger.log(Level.SEVERE, String.format(
"Error committing bulk insert of correlation attributes (job ID=%d)", context.getJobId()), ex);
145 "CentralRepoIngestModule_missingFileCorrAttrTypeErrMsg=Correlation attribute type for files not found in the central repository",
146 "CentralRepoIngestModule_cannotGetCrCaseErrMsg=Case not present in the central repository",
147 "CentralRepoIngestModule_cannotGetCrDataSourceErrMsg=Data source not present in the central repository"
151 this.context = context;
153 if (!CentralRepository.isEnabled()) {
158 centralRepo = CentralRepository.getInstance();
159 }
catch (CentralRepoException ex) {
169 filesType = centralRepo.getCorrelationTypeById(CorrelationAttributeInstance.FILES_TYPE_ID);
170 }
catch (CentralRepoException ex) {
179 if (refCounter.incrementAndGet(context.getJobId()) == 1) {
182 currentCase = Case.getCurrentCaseThrows();
183 }
catch (NoCurrentCaseException ex) {
187 CorrelationCase centralRepoCase;
189 centralRepoCase = centralRepo.getCase(currentCase);
190 }
catch (CentralRepoException ex) {
195 CorrelationDataSource.fromTSKDataSource(centralRepoCase, context.getDataSource());
196 }
catch (CentralRepoException ex) {