19 package org.sleuthkit.autopsy.centralrepository.ingestmodule;
21 import java.util.HashSet;
22 import java.util.List;
24 import java.util.logging.Level;
25 import org.openide.util.NbBundle.Messages;
51 final class CentralRepoIngestModule
implements FileIngestModule {
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();
74 public ProcessResult process(AbstractFile abstractFile) {
75 if (!flagNotableItems && !saveCorrAttrInstances) {
76 return ProcessResult.OK;
79 if (!filesType.isEnabled()) {
80 return ProcessResult.OK;
83 if (abstractFile.getKnown() == TskData.FileKnown.KNOWN) {
84 return ProcessResult.OK;
87 if (!CorrelationAttributeUtil.isSupportedAbstractFileType(abstractFile)) {
88 return ProcessResult.OK;
98 String md5 = abstractFile.getMd5Hash();
99 if ((md5 == null) || (HashUtility.isNoDataMd5(md5))) {
100 return ProcessResult.OK;
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);
130 return ProcessResult.OK;
134 public void shutDown() {
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"
150 public void startUp(IngestJobContext context)
throws IngestModuleException {
151 this.context = context;
153 if (!CentralRepository.isEnabled()) {
154 throw new IngestModuleException(Bundle.CentralRepoIngestModule_crNotEnabledErrMsg());
158 centralRepo = CentralRepository.getInstance();
159 }
catch (CentralRepoException ex) {
160 throw new IngestModuleException(Bundle.CentralRepoIngestModule_crInaccessibleErrMsg(), ex);
169 filesType = centralRepo.getCorrelationTypeById(CorrelationAttributeInstance.FILES_TYPE_ID);
170 }
catch (CentralRepoException ex) {
171 throw new IngestModuleException(Bundle.CentralRepoIngestModule_missingFileCorrAttrTypeErrMsg(), ex);
179 if (refCounter.incrementAndGet(context.getJobId()) == 1) {
182 currentCase = Case.getCurrentCaseThrows();
183 }
catch (NoCurrentCaseException ex) {
184 throw new IngestModuleException(Bundle.CentralRepoIngestModule_noCurrentCaseErrMsg(), ex);
187 CorrelationCase centralRepoCase;
189 centralRepoCase = centralRepo.getCase(currentCase);
190 }
catch (CentralRepoException ex) {
191 throw new IngestModuleException(Bundle.CentralRepoIngestModule_cannotGetCrCaseErrMsg(), ex);
195 CorrelationDataSource.fromTSKDataSource(centralRepoCase, context.getDataSource());
196 }
catch (CentralRepoException ex) {
197 throw new IngestModuleException(Bundle.CentralRepoIngestModule_cannotGetCrDataSourceErrMsg(), ex);