Autopsy  4.12.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ContactNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 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.communications.relationships;
20 
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.TimeZone;
25 import java.util.logging.Level;
26 import org.openide.nodes.Sheet;
27 import org.openide.util.NbBundle.Messages;
31 import org.sleuthkit.datamodel.BlackboardArtifact;
32 import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_CONTACT;
33 import org.sleuthkit.datamodel.BlackboardAttribute;
34 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME;
35 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME_PERSON;
36 import static org.sleuthkit.datamodel.BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DATETIME;
37 import org.sleuthkit.datamodel.TimeUtilities;
38 import org.sleuthkit.datamodel.TskCoreException;
40 import org.sleuthkit.datamodel.AbstractFile;
41 import org.sleuthkit.datamodel.Content;
42 
47 final class ContactNode extends BlackboardArtifactNode {
48 
49  private static final Logger logger = Logger.getLogger(ContactNode.class.getName());
50 
51  @Messages({
52  "ContactNode_Name=Name",
53  "ContactNode_Phone=Phone Number",
54  "ContactNode_Email=Email Address",
55  "ContactNode_Mobile_Number=Mobile Number",
56  "ContactNode_Office_Number=Office Number",
57  "ContactNode_URL=URL",
58  "ContactNode_Home_Number=Home Number",})
59 
60  ContactNode(BlackboardArtifact artifact) {
61  super(artifact);
62 
63  String name = getAttributeDisplayString(artifact, TSK_NAME);
64  if (name == null || name.trim().isEmpty()) {
65  // VCards use TSK_NAME_PERSON instead of TSK_NAME
66  name = getAttributeDisplayString(artifact, TSK_NAME_PERSON);
67  }
68  setDisplayName(name);
69  }
70 
71  @Override
72  protected Sheet createSheet() {
73  Sheet sheet = super.createSheet();
74 
75  final BlackboardArtifact artifact = getArtifact();
76  BlackboardArtifact.ARTIFACT_TYPE fromID = BlackboardArtifact.ARTIFACT_TYPE.fromID(artifact.getArtifactTypeID());
77  if (fromID != TSK_CONTACT) {
78  return sheet;
79  }
80 
81  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
82  if (sheetSet == null) {
83  sheetSet = Sheet.createPropertiesSet();
84  sheet.put(sheetSet);
85  }
86 
87  // Sorting the attributes by type so that the duplicates can be removed
88  // and they can be grouped by type for display. The attribute prefixes
89  // are used so that all attributed of that type are found, including
90  // ones that are not predefined as part of BlackboardAttributes
91  try {
92  HashMap<String, BlackboardAttribute> phoneNumMap = new HashMap<>();
93  HashMap<String, BlackboardAttribute> emailMap = new HashMap<>();
94  HashMap<String, BlackboardAttribute> nameMap = new HashMap<>();
95  HashMap<String, BlackboardAttribute> otherMap = new HashMap<>();
96  for (BlackboardAttribute bba : artifact.getAttributes()) {
97  if (bba.getAttributeType().getTypeName().startsWith("TSK_PHONE")) {
98  phoneNumMap.put(bba.getDisplayString(), bba);
99  } else if (bba.getAttributeType().getTypeName().startsWith("TSK_EMAIL")) {
100  emailMap.put(bba.getDisplayString(), bba);
101  } else if (bba.getAttributeType().getTypeName().startsWith("TSK_NAME")) {
102  nameMap.put(bba.getDisplayString(), bba);
103  } else {
104  otherMap.put(bba.getDisplayString(), bba);
105  }
106  }
107 
108  addPropertiesToSheet(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME.getLabel(),
109  sheetSet, nameMap);
110  addPropertiesToSheet(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER.getLabel(),
111  sheetSet, phoneNumMap);
112  addPropertiesToSheet(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL.getLabel(),
113  sheetSet, emailMap);
114 
115  for (BlackboardAttribute bba : otherMap.values()) {
116  sheetSet.put(new NodeProperty<>(bba.getAttributeType().getTypeName(), bba.getAttributeType().getDisplayName(), "", bba.getDisplayString()));
117  }
118 
119  // Don't need these values to appear in the Contact property sheet.
120  sheetSet.remove("S");
121  sheetSet.remove("C");
122 
123  List<Content> children = artifact.getChildren();
124  if(children != null) {
125  int count = 0;
126  String imageLabelPrefix = "Image";
127  for(Content child: children) {
128  if(child instanceof AbstractFile) {
129  String imageLabel = imageLabelPrefix;
130  if(count > 0) {
131  imageLabel = imageLabelPrefix + "-" + count;
132  }
133  sheetSet.put(new NodeProperty<>(imageLabel, imageLabel, imageLabel, child.getName()));
134  }
135  }
136  }
137 
138  } catch (TskCoreException ex) {
139  logger.log(Level.WARNING, "Error getting attribute values.", ex); //NON-NLS
140  }
141 
142  return sheet;
143  }
144 
145  private void addPropertiesToSheet(String propertyID, Sheet.Set sheetSet, Map<String, BlackboardAttribute> attributeMap) {
146  int count = 0;
147  for (BlackboardAttribute bba : attributeMap.values()) {
148  if (count++ > 0) {
149  sheetSet.put(new NodeProperty<>(propertyID + "_" + count, bba.getAttributeType().getDisplayName(), "", bba.getDisplayString()));
150  } else {
151  sheetSet.put(new NodeProperty<>(propertyID, bba.getAttributeType().getDisplayName(), "", bba.getDisplayString()));
152  }
153  }
154  }
155 
156  private static String getAttributeDisplayString(final BlackboardArtifact artifact, final BlackboardAttribute.ATTRIBUTE_TYPE attributeType) {
157  try {
158  BlackboardAttribute attribute = artifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.fromID(attributeType.getTypeID())));
159  if (attribute == null) {
160  return "";
161  } else if (attributeType.getValueType() == DATETIME) {
162  return TimeUtilities.epochToTime(attribute.getValueLong(),
163  TimeZone.getTimeZone(Utils.getUserPreferredZoneId()));
164  } else {
165  return attribute.getDisplayString();
166  }
167  } catch (TskCoreException tskCoreException) {
168  logger.log(Level.WARNING, "Error getting attribute value.", tskCoreException); //NON-NLS
169  return "";
170  }
171  }
172 
179  @Override
180  public String getSourceName() {
181  return getDisplayName();
182  }
183 }

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.