19package org.sleuthkit.autopsy.centralrepository.ingestmodule;
21import java.util.HashSet;
22import java.util.LinkedHashSet;
25import java.util.logging.Level;
26import org.apache.commons.lang3.StringUtils;
27import org.openide.util.NbBundle;
28import org.sleuthkit.autopsy.casemodule.Case;
29import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
30import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbManager;
31import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoException;
32import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoPlatforms;
33import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepository;
34import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttributeInstance;
35import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttributeUtil;
36import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationCase;
37import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationDataSource;
38import static org.sleuthkit.autopsy.centralrepository.ingestmodule.CentralRepoIngestModuleUtils.getOccurrencesInOtherCases;
39import static org.sleuthkit.autopsy.centralrepository.ingestmodule.CentralRepoIngestModuleUtils.makePrevNotableAnalysisResult;
40import static org.sleuthkit.autopsy.centralrepository.ingestmodule.CentralRepoIngestModuleUtils.makePrevSeenAnalysisResult;
41import static org.sleuthkit.autopsy.centralrepository.ingestmodule.CentralRepoIngestModuleUtils.makePrevUnseenAnalysisResult;
42import org.sleuthkit.autopsy.coreutils.Logger;
43import org.sleuthkit.autopsy.ingest.DataArtifactIngestModule;
44import org.sleuthkit.autopsy.ingest.IngestJobContext;
45import org.sleuthkit.datamodel.DataArtifact;
46import org.sleuthkit.datamodel.Image;
47import org.sleuthkit.datamodel.OsAccount;
48import org.sleuthkit.datamodel.OsAccountManager;
49import org.sleuthkit.datamodel.TskCoreException;
50import org.sleuthkit.datamodel.TskData;
79 CentralRepoDataArtifactIngestModule(IngestSettings settings) {
88 "CentralRepoIngestModule_crNotEnabledErrMsg=Central repository required, but not enabled",
89 "CentralRepoIngestModule_crInaccessibleErrMsg=Error accessing central repository",
90 "CentralRepoIngestModule_noCurrentCaseErrMsg=Error getting current case",
91 "CentralRepoIngestModule_crDatabaseTypeMismatch=Mulit-user cases require a PostgreSQL central repository"
141 LOGGER.log(Level.SEVERE, String.format(
"Error adding correlation attribute '%s' to central repository for '%s' (job ID=%d)", corrAttr, artifact,
context.getJobId()), ex);
158 List<CorrelationAttributeInstance> previousOccurrences =
null;
160 previousOccurrences = getOccurrencesInOtherCases(corrAttr,
context.getJobId());
161 if (!previousOccurrences.isEmpty()) {
162 Set<String> previousCases =
new HashSet<>();
164 if (occurrence.getKnownStatus() == TskData.FileKnown.BAD) {
165 previousCases.add(occurrence.getCorrelationCase().getDisplayName());
168 if (!previousCases.isEmpty()) {
182 if (previousOccurrences ==
null) {
183 previousOccurrences = getOccurrencesInOtherCases(corrAttr,
context.getJobId());
185 if (!previousOccurrences.isEmpty()) {
187 if (!previousCases.isEmpty()) {
196 if (previousOccurrences ==
null) {
197 previousOccurrences = getOccurrencesInOtherCases(corrAttr,
context.getJobId());
199 if (previousOccurrences.isEmpty()) {
213 private Set<String>
getPreviousCases(List<CorrelationAttributeInstance> previousOccurrences) {
214 Set<String> previousCases =
new HashSet<>();
216 previousCases.add(occurrence.getCorrelationCase().getDisplayName());
218 return previousCases;
228 LOGGER.log(Level.SEVERE, String.format(
"Error doing final bulk commit of correlation attributes (job ID=%d)",
context.getJobId()), ex);
242 "CentralRepoIngestModule_prevSeenOsAcctSetName=Users seen in previous cases",
243 "CentralRepoIngestModule_prevSeenOsAcctConfig=Previously Seen Users (Central Repository)"
249 List<OsAccount> osAccounts = osAccountMgr.getOsAccountsByDataSourceObjId(
context.getDataSource().getId());
250 for (OsAccount osAccount : osAccounts) {
259 LOGGER.log(Level.SEVERE, String.format(
"Error adding correlation attribute '%s' to central repository for '%s'(job ID=%d)", corrAttr, osAccount,
context.getJobId()), ex);
265 LOGGER.log(Level.SEVERE, String.format(
"Error getting OS accounts for data source '%s' (job ID=%d)",
context.getDataSource(),
context.getJobId()), ex);
279 List<CorrelationAttributeInstance> previousOccurrences = getOccurrencesInOtherCases(corrAttr,
context.getJobId());
280 if (!previousOccurrences.isEmpty()) {
282 if (!previousCases.isEmpty()) {
294 if (!(
context.getDataSource() instanceof Image)) {
301 if (correlationCase ==
null) {
302 correlationCase =
centralRepo.newCase(currentCase);
306 if (correlationDataSource ==
null) {
310 Image image = (Image)
context.getDataSource();
311 String imageMd5Hash = image.getMd5();
312 if (imageMd5Hash ==
null) {
315 String crMd5Hash = correlationDataSource.
getMd5();
316 if (StringUtils.equals(imageMd5Hash, crMd5Hash) ==
false) {
317 correlationDataSource.
setMd5(imageMd5Hash);
320 String imageSha1Hash = image.getSha1();
321 if (imageSha1Hash ==
null) {
324 String crSha1Hash = correlationDataSource.
getSha1();
325 if (StringUtils.equals(imageSha1Hash, crSha1Hash) ==
false) {
326 correlationDataSource.
setSha1(imageSha1Hash);
329 String imageSha256Hash = image.getSha256();
330 if (imageSha256Hash ==
null) {
331 imageSha256Hash =
"";
333 String crSha256Hash = correlationDataSource.
getSha256();
334 if (StringUtils.equals(imageSha256Hash, crSha256Hash) ==
false) {
335 correlationDataSource.
setSha256(imageSha256Hash);
339 LOGGER.log(Level.SEVERE, String.format(
"Error fetching data from the central repository for data source '%s' (job ID=%d)",
context.getDataSource().getName(),
context.getJobId()), ex);
341 LOGGER.log(Level.SEVERE, String.format(
"Error fetching data from the case database for data source '%s' (job ID=%d)",
context.getDataSource().getName(),
context.getJobId()), ex);
SleuthkitCase getSleuthkitCase()
static Case getCurrentCaseThrows()
static CentralRepoDbChoice getSavedDbChoice()
String getCorrelationValue()
Type getCorrelationType()
static final int PHONE_TYPE_ID
static final int MAC_TYPE_ID
static final int IMSI_TYPE_ID
static final int IMEI_TYPE_ID
static final int USBID_TYPE_ID
static final int EMAIL_TYPE_ID
static final int INSTALLED_PROGS_TYPE_ID
static final int ICCID_TYPE_ID
static final int DOMAIN_TYPE_ID
static List< CorrelationAttributeInstance > makeCorrAttrsToSave(DataArtifact artifact)
void setMd5(String md5Hash)
void setSha1(String sha1Hash)
static CorrelationDataSource fromTSKDataSource(CorrelationCase correlationCase, Content dataSource)
void setSha256(String sha256Hash)
void makeAnalysisResults(OsAccount osAccount, CorrelationAttributeInstance corrAttr)
void startUp(IngestJobContext context)
final Set< String > corrAttrValuesAlreadyProcessed
final boolean saveCorrAttrInstances
void syncDataSourceHashes()
final boolean flagNotableItems
final boolean flagPrevSeenDevices
void makeAnalysisResults(DataArtifact artifact, CorrelationAttributeInstance corrAttr)
Set< String > getPreviousCases(List< CorrelationAttributeInstance > previousOccurrences)
CentralRepository centralRepo
static final Logger LOGGER
final boolean flagUniqueArtifacts
ProcessResult process(DataArtifact artifact)
synchronized static Logger getLogger(String name)
CentralRepoPlatforms getDbPlatform()
static CentralRepository getInstance()
static boolean isEnabled()