Autopsy  4.20.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.ArrayList;
22 import java.util.List;
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 import org.sleuthkit.datamodel.AbstractFile;
40 import org.sleuthkit.datamodel.Content;
41 
46 final class ContactNode extends BlackboardArtifactNode {
47 
48  private static final Logger logger = Logger.getLogger(ContactNode.class.getName());
49 
50  @Messages({
51  "ContactNode_Name=Name",
52  "ContactNode_Phone=Phone Number",
53  "ContactNode_Email=Email Address",
54  "ContactNode_Mobile_Number=Mobile Number",
55  "ContactNode_Office_Number=Office Number",
56  "ContactNode_URL=URL",
57  "ContactNode_Home_Number=Home Number",})
58 
59  ContactNode(BlackboardArtifact artifact) {
60  super(artifact);
61 
62  String name = getAttributeDisplayString(artifact, TSK_NAME);
63  if (name == null || name.trim().isEmpty()) {
64  // VCards use TSK_NAME_PERSON instead of TSK_NAME
65  name = getAttributeDisplayString(artifact, TSK_NAME_PERSON);
66  }
67  setDisplayName(name);
68  }
69 
70  @Override
71  protected Sheet createSheet() {
72  Sheet sheet = new Sheet();
73 
74  final BlackboardArtifact artifact = getArtifact();
75  BlackboardArtifact.ARTIFACT_TYPE fromID = BlackboardArtifact.ARTIFACT_TYPE.fromID(artifact.getArtifactTypeID());
76  if (fromID != TSK_CONTACT) {
77  return sheet;
78  }
79 
80  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
81  if (sheetSet == null) {
82  sheetSet = Sheet.createPropertiesSet();
83  sheet.put(sheetSet);
84  }
85 
86  // Sorting the attributes by type so that the duplicates can be removed
87  // and they can be grouped by type for display. The attribute prefixes
88  // are used so that all attributed of that type are found, including
89  // ones that are not predefined as part of BlackboardAttributes
90  try {
91  List<BlackboardAttribute> phoneNumList = new ArrayList<>();
92  List<BlackboardAttribute> emailList = new ArrayList<>();
93  List<BlackboardAttribute> nameList = new ArrayList<>();
94  List<BlackboardAttribute> otherList = new ArrayList<>();
95  for (BlackboardAttribute bba : artifact.getAttributes()) {
96  if (bba.getAttributeType().getTypeName().startsWith("TSK_PHONE")) {
97  phoneNumList.add(bba);
98  } else if (bba.getAttributeType().getTypeName().startsWith("TSK_EMAIL")) {
99  emailList.add(bba);
100  } else if (bba.getAttributeType().getTypeName().startsWith("TSK_NAME")) {
101  nameList.add(bba);
102  } else {
103  otherList.add(bba);
104  }
105  }
106 
107  addPropertiesToSheet(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME.getLabel(),
108  sheetSet, nameList);
109  addPropertiesToSheet(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER.getLabel(),
110  sheetSet, phoneNumList);
111  addPropertiesToSheet(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL.getLabel(),
112  sheetSet, emailList);
113 
114  for (BlackboardAttribute bba : otherList) {
115  sheetSet.put(new NodeProperty<>(bba.getAttributeType().getTypeName(), bba.getAttributeType().getDisplayName(), "", bba.getDisplayString()));
116  }
117 
118  List<Content> children = artifact.getChildren();
119  if (children != null) {
120  int count = 0;
121  String imageLabelPrefix = "Image";
122  for (Content child : children) {
123  if (child instanceof AbstractFile) {
124  String imageLabel = imageLabelPrefix;
125  if (count > 0) {
126  imageLabel = imageLabelPrefix + "-" + count;
127  }
128  sheetSet.put(new NodeProperty<>(imageLabel, imageLabel, imageLabel, child.getName()));
129  }
130  }
131  }
132 
133  } catch (TskCoreException ex) {
134  logger.log(Level.WARNING, "Error getting attribute values.", ex); //NON-NLS
135  }
136 
137  return sheet;
138  }
139 
140  private void addPropertiesToSheet(String propertyID, Sheet.Set sheetSet, List<BlackboardAttribute> attributeList) {
141  int count = 0;
142  for (BlackboardAttribute bba : attributeList) {
143  if (count++ > 0) {
144  if (bba.getAttributeType().getTypeName().startsWith("TSK_PHONE")) {
145  String phoneNumCountry = PhoneNumUtil.getCountryCode(bba.getValueString());
146  if (phoneNumCountry.equals("")) {
147  sheetSet.put(new NodeProperty<>(propertyID + "_" + count, bba.getAttributeType().getDisplayName(), "", bba.getDisplayString()));
148  } else {
149  sheetSet.put(new NodeProperty<>(propertyID + "_" + count, bba.getAttributeType().getDisplayName(), "", bba.getDisplayString() + " [" + phoneNumCountry + "]"));
150  }
151  } else {
152  sheetSet.put(new NodeProperty<>(propertyID + "_" + count, bba.getAttributeType().getDisplayName(), "", bba.getDisplayString()));
153  }
154  } else {
155  if (bba.getAttributeType().getTypeName().startsWith("TSK_PHONE")) {
156  String phoneNumCountry = PhoneNumUtil.getCountryCode(bba.getValueString());
157  if (phoneNumCountry.equals("")) {
158  sheetSet.put(new NodeProperty<>(propertyID, bba.getAttributeType().getDisplayName(), "", bba.getDisplayString()));
159  } else {
160  sheetSet.put(new NodeProperty<>(propertyID, bba.getAttributeType().getDisplayName(), "", bba.getDisplayString() + " [" + phoneNumCountry + "]"));
161  }
162  } else {
163  sheetSet.put(new NodeProperty<>(propertyID, bba.getAttributeType().getDisplayName(), "", bba.getDisplayString()));
164  }
165  }
166  }
167  }
168 
169  private static String getAttributeDisplayString(final BlackboardArtifact artifact, final BlackboardAttribute.ATTRIBUTE_TYPE attributeType) {
170  try {
171  BlackboardAttribute attribute = artifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.fromID(attributeType.getTypeID())));
172  if (attribute == null) {
173  return "";
174  } else if (attributeType.getValueType() == DATETIME) {
175  return TimeUtilities.epochToTime(attribute.getValueLong(),
176  TimeZone.getTimeZone(Utils.getUserPreferredZoneId()));
177  } else {
178  return attribute.getDisplayString();
179  }
180  } catch (TskCoreException tskCoreException) {
181  logger.log(Level.WARNING, "Error getting attribute value.", tskCoreException); //NON-NLS
182  return "";
183  }
184  }
185 
192  @Override
193  public String getSourceName() {
194  return getDisplayName();
195  }
196 
197 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.