Autopsy  4.11.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.Map;
23 import java.util.TimeZone;
24 import java.util.logging.Level;
25 import org.openide.nodes.Sheet;
26 import org.openide.util.NbBundle.Messages;
30 import org.sleuthkit.datamodel.BlackboardArtifact;
31 import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_CONTACT;
32 import org.sleuthkit.datamodel.BlackboardAttribute;
33 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME;
34 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME_PERSON;
35 import static org.sleuthkit.datamodel.BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DATETIME;
36 import org.sleuthkit.datamodel.TimeUtilities;
37 import org.sleuthkit.datamodel.TskCoreException;
39 
44 final class ContactNode extends BlackboardArtifactNode {
45 
46  private static final Logger logger = Logger.getLogger(ContactNode.class.getName());
47 
48  @Messages({
49  "ContactNode_Name=Name",
50  "ContactNode_Phone=Phone Number",
51  "ContactNode_Email=Email Address",
52  "ContactNode_Mobile_Number=Mobile Number",
53  "ContactNode_Office_Number=Office Number",
54  "ContactNode_URL=URL",
55  "ContactNode_Home_Number=Home Number",})
56 
57  ContactNode(BlackboardArtifact artifact) {
58  super(artifact);
59 
60  String name = getAttributeDisplayString(artifact, TSK_NAME);
61  if (name == null || name.trim().isEmpty()) {
62  // VCards use TSK_NAME_PERSON instead of TSK_NAME
63  name = getAttributeDisplayString(artifact, TSK_NAME_PERSON);
64  }
65  setDisplayName(name);
66  }
67 
68  @Override
69  protected Sheet createSheet() {
70  Sheet sheet = super.createSheet();
71 
72  final BlackboardArtifact artifact = getArtifact();
73  BlackboardArtifact.ARTIFACT_TYPE fromID = BlackboardArtifact.ARTIFACT_TYPE.fromID(artifact.getArtifactTypeID());
74  if (fromID != TSK_CONTACT) {
75  return sheet;
76  }
77 
78  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
79  if (sheetSet == null) {
80  sheetSet = Sheet.createPropertiesSet();
81  sheet.put(sheetSet);
82  }
83 
84  // Sorting the attributes by type so that the duplicates can be removed
85  // and they can be grouped by type for display. The attribute prefixes
86  // are used so that all attributed of that type are found, including
87  // ones that are not predefined as part of BlackboardAttributes
88  try {
89  HashMap<String, BlackboardAttribute> phoneNumMap = new HashMap<>();
90  HashMap<String, BlackboardAttribute> emailMap = new HashMap<>();
91  HashMap<String, BlackboardAttribute> nameMap = new HashMap<>();
92  HashMap<String, BlackboardAttribute> otherMap = new HashMap<>();
93  for (BlackboardAttribute bba : artifact.getAttributes()) {
94  if (bba.getAttributeType().getTypeName().startsWith("TSK_PHONE")) {
95  phoneNumMap.put(bba.getDisplayString(), bba);
96  } else if (bba.getAttributeType().getTypeName().startsWith("TSK_EMAIL")) {
97  emailMap.put(bba.getDisplayString(), bba);
98  } else if (bba.getAttributeType().getTypeName().startsWith("TSK_NAME")) {
99  nameMap.put(bba.getDisplayString(), bba);
100  } else {
101  otherMap.put(bba.getDisplayString(), bba);
102  }
103  }
104 
105  addPropertiesToSheet(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME.getLabel(),
106  sheetSet, nameMap);
107  addPropertiesToSheet(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER.getLabel(),
108  sheetSet, phoneNumMap);
109  addPropertiesToSheet(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL.getLabel(),
110  sheetSet, emailMap);
111 
112  for (BlackboardAttribute bba : otherMap.values()) {
113  sheetSet.put(new NodeProperty<>(bba.getAttributeType().getTypeName(), bba.getAttributeType().getDisplayName(), "", bba.getDisplayString()));
114  }
115 
116  } catch (TskCoreException ex) {
117  logger.log(Level.WARNING, "Error getting attribute values.", ex); //NON-NLS
118  }
119 
120  return sheet;
121  }
122 
123  private void addPropertiesToSheet(String propertyID, Sheet.Set sheetSet, Map<String, BlackboardAttribute> attributeMap) {
124  int count = 0;
125  for (BlackboardAttribute bba : attributeMap.values()) {
126  if (count++ > 0) {
127  sheetSet.put(new NodeProperty<>(propertyID + "_" + count, bba.getAttributeType().getDisplayName(), "", bba.getDisplayString()));
128  } else {
129  sheetSet.put(new NodeProperty<>(propertyID, bba.getAttributeType().getDisplayName(), "", bba.getDisplayString()));
130  }
131  }
132  }
133 
134  private static String getAttributeDisplayString(final BlackboardArtifact artifact, final BlackboardAttribute.ATTRIBUTE_TYPE attributeType) {
135  try {
136  BlackboardAttribute attribute = artifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.fromID(attributeType.getTypeID())));
137  if (attribute == null) {
138  return "";
139  } else if (attributeType.getValueType() == DATETIME) {
140  return TimeUtilities.epochToTime(attribute.getValueLong(),
141  TimeZone.getTimeZone(Utils.getUserPreferredZoneId()));
142  } else {
143  return attribute.getDisplayString();
144  }
145  } catch (TskCoreException tskCoreException) {
146  logger.log(Level.WARNING, "Error getting attribute value.", tskCoreException); //NON-NLS
147  return "";
148  }
149  }
150 
157  @Override
158  public String getSourceName() {
159  return getDisplayName();
160  }
161 }

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