Autopsy  4.12.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
StixArtifactData.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-2019 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.modules.stix;
20 
21 import java.util.Arrays;
22 import java.util.Collection;
23 import java.util.logging.Level;
24 import org.apache.commons.lang3.StringUtils;
25 import org.openide.util.NbBundle.Messages;
30 import org.sleuthkit.datamodel.AbstractFile;
31 import org.sleuthkit.datamodel.Blackboard;
32 import org.sleuthkit.datamodel.BlackboardArtifact;
33 import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT;
34 import org.sleuthkit.datamodel.BlackboardAttribute;
35 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY;
36 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME;
37 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_TITLE;
38 import org.sleuthkit.datamodel.SleuthkitCase;
39 import org.sleuthkit.datamodel.TskCoreException;
40 
44 class StixArtifactData {
45 
46  private static final String MODULE_NAME = "Stix";
47 
48  private AbstractFile file;
49  private final String observableId;
50  private final String objType;
51  private static final Logger logger = Logger.getLogger(StixArtifactData.class.getName());
52 
53  StixArtifactData(AbstractFile a_file, String a_observableId, String a_objType) {
54  file = a_file;
55  observableId = a_observableId;
56  objType = a_objType;
57  }
58 
59  StixArtifactData(long a_objId, String a_observableId, String a_objType) {
60  try {
61  Case case1 = Case.getCurrentCaseThrows();
62  SleuthkitCase sleuthkitCase = case1.getSleuthkitCase();
63  file = sleuthkitCase.getAbstractFileById(a_objId);
64  } catch (TskCoreException | NoCurrentCaseException ex) {
65  file = null;
66  }
67  observableId = a_observableId;
68  objType = a_objType;
69  }
70 
71  @Messages({"StixArtifactData.indexError.message=Failed to index STIX interesting file hit artifact for keyword search.",
72  "StixArtifactData.noOpenCase.errMsg=No open case available."})
73  void createArtifact(String a_title) throws TskCoreException {
74  Blackboard blackboard;
75  try {
76  blackboard = Case.getCurrentCaseThrows().getSleuthkitCase().getBlackboard();
77  } catch (NoCurrentCaseException ex) {
78  logger.log(Level.SEVERE, "Exception while getting open case.", ex); //NON-NLS
79  MessageNotifyUtil.Notify.error(Bundle.StixArtifactData_noOpenCase_errMsg(), ex.getLocalizedMessage());
80  return;
81  }
82 
83  String setName = "STIX Indicator - " + StringUtils.defaultIfBlank(a_title, "(no title)"); //NON-NLS
84 
85  Collection<BlackboardAttribute> attributes = Arrays.asList(
86  new BlackboardAttribute(TSK_SET_NAME, MODULE_NAME, setName),
87  new BlackboardAttribute(TSK_TITLE, MODULE_NAME, observableId),
88  new BlackboardAttribute(TSK_CATEGORY, MODULE_NAME, objType));
89 
90  // Create artifact if it doesn't already exist.
91  if (!blackboard.artifactExists(file, TSK_INTERESTING_FILE_HIT, attributes)) {
92  BlackboardArtifact bba = file.newArtifact(TSK_INTERESTING_FILE_HIT);
93  bba.addAttributes(attributes);
94 
95  try {
96  /*
97  * post the artifact which will index the artifact for keyword
98  * search, and fire an event to notify UI of this new artifact
99  */
100  blackboard.postArtifact(bba, MODULE_NAME);
101  } catch (Blackboard.BlackboardException ex) {
102  logger.log(Level.SEVERE, "Unable to index blackboard artifact " + bba.getArtifactID(), ex); //NON-NLS
103  MessageNotifyUtil.Notify.error(Bundle.StixArtifactData_indexError_message(), bba.getDisplayName());
104  }
105  }
106  }
107 }

Copyright © 2012-2018 Basis Technology. Generated on: Wed Sep 18 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.