Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
XRYContactsFileParser.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019-2021 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.datasourceprocessors.xry;
20 
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.List;
24 import java.util.logging.Level;
27 import org.sleuthkit.datamodel.Account;
28 import org.sleuthkit.datamodel.Blackboard;
29 import org.sleuthkit.datamodel.BlackboardArtifact;
30 import org.sleuthkit.datamodel.BlackboardAttribute;
31 import org.sleuthkit.datamodel.Content;
32 import org.sleuthkit.datamodel.SleuthkitCase;
33 import org.sleuthkit.datamodel.TskCoreException;
34 import org.sleuthkit.datamodel.blackboardutils.CommunicationArtifactsHelper;
35 
39 final class XRYContactsFileParser extends AbstractSingleEntityParser {
40 
41  private static final Logger logger = Logger.getLogger(XRYContactsFileParser.class.getName());
42 
43  @Override
44  boolean canProcess(XRYKeyValuePair pair) {
45  return XryKey.contains(pair.getKey());
46  }
47 
48  @Override
49  boolean isNamespace(String nameSpace) {
50  //No namespaces are currently known for this report type.
51  return false;
52  }
53 
54  @Override
55  void makeArtifact(List<XRYKeyValuePair> keyValuePairs, Content parent, SleuthkitCase currentCase) throws TskCoreException, Blackboard.BlackboardException {
56  // Transform all the data from XRY land into the appropriate CommHelper
57  // data types.
58  String contactName = null;
59  String phoneNumber = null;
60  String homePhoneNumber = null;
61  String mobilePhoneNumber = null;
62  String emailAddr = null;
63  boolean hasAnEmail = false;
64  final Collection<BlackboardAttribute> additionalAttributes = new ArrayList<>();
65 
66  for (XRYKeyValuePair pair : keyValuePairs) {
67  XryKey xryKey = XryKey.fromDisplayName(pair.getKey());
68  switch (xryKey) {
69  case NAME:
70  if (contactName != null) {
71  additionalAttributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME, PARSER_NAME, pair.getValue()));
72  } else {
73  contactName = pair.getValue();
74  }
75  break;
76  case TEL:
77  if (!XRYUtils.isPhoneValid(pair.getValue())) {
78  continue;
79  }
80 
81  if (phoneNumber != null) {
82  additionalAttributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER, PARSER_NAME, pair.getValue()));
83  } else {
84  phoneNumber = pair.getValue();
85  }
86  break;
87  case MOBILE:
88  if (!XRYUtils.isPhoneValid(pair.getValue())) {
89  continue;
90  }
91 
92  if (mobilePhoneNumber != null) {
93  additionalAttributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_MOBILE, PARSER_NAME, pair.getValue()));
94  } else {
95  mobilePhoneNumber = pair.getValue();
96  }
97  break;
98  case HOME:
99  if (!XRYUtils.isPhoneValid(pair.getValue())) {
100  continue;
101  }
102 
103  if (homePhoneNumber != null) {
104  additionalAttributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_HOME, PARSER_NAME, pair.getValue()));
105  } else {
106  homePhoneNumber = pair.getValue();
107  }
108  break;
109  case EMAIL_HOME:
110  if (!XRYUtils.isEmailValid(pair.getValue())) {
111  continue;
112  }
113 
114  hasAnEmail = true;
115  additionalAttributes.add(new BlackboardAttribute(
116  BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_HOME,
117  PARSER_NAME, pair.getValue()));
118  break;
119  default:
120  //Otherwise, the XryKey enum contains the correct BlackboardAttribute
121  //type.
122  if (xryKey.getType() != null) {
123  additionalAttributes.add(new BlackboardAttribute(xryKey.getType(),
124  PARSER_NAME, pair.getValue()));
125  }
126 
127  logger.log(Level.INFO, String.format("[XRY DSP] Key value pair "
128  + "(in brackets) [ %s ] was recognized but "
129  + "more data or time is needed to finish implementation. Discarding... ",
130  pair));
131  }
132  }
133 
134  // Make sure we have the required fields, otherwise the CommHelper will
135  // complain about illegal arguments.
136  if (phoneNumber != null || homePhoneNumber != null || mobilePhoneNumber != null || hasAnEmail) {
137  CommunicationArtifactsHelper helper = new CommunicationArtifactsHelper(
138  currentCase, PARSER_NAME, parent, Account.Type.DEVICE, null);
139 
140  helper.addContact(contactName, phoneNumber, homePhoneNumber,
141  mobilePhoneNumber, emailAddr, additionalAttributes);
142  } else {
143  // Just create an artifact with the attributes that we do have.
144  if (!additionalAttributes.isEmpty()) {
145  BlackboardArtifact artifact = parent.newDataArtifact(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_CONTACT), additionalAttributes);
146 
147  currentCase.getBlackboard().postArtifact(artifact, PARSER_NAME, null);
148  }
149  }
150  }
151 
158  private enum XryKey {
159  NAME("name", null),
160  TEL("tel", null),
161  MOBILE("mobile", null),
162  HOME("home", null),
163  RELATED_APPLICATION("related application", BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME),
164  ADDRESS_HOME("address home", BlackboardAttribute.ATTRIBUTE_TYPE.TSK_LOCATION),
165  EMAIL_HOME("email home", null),
166  DELETED("deleted", BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ISDELETED),
167  //Ignoring or need more information to decide.
168  STORAGE("storage", null),
169  OTHER("other", null),
170  PICTURE("picture", null),
171  INDEX("index", null),
172  ACCOUNT_NAME("account name", null);
173 
174  private final String name;
175  private final BlackboardAttribute.ATTRIBUTE_TYPE type;
176 
177  XryKey(String name, BlackboardAttribute.ATTRIBUTE_TYPE type) {
178  this.name = name;
179  this.type = type;
180  }
181 
182  BlackboardAttribute.ATTRIBUTE_TYPE getType() {
183  return type;
184  }
185 
189  static boolean contains(String key) {
190  try {
191  XryKey.fromDisplayName(key);
192  return true;
193  } catch (IllegalArgumentException ex) {
194  return false;
195  }
196  }
197 
205  static XryKey fromDisplayName(String key) {
206  String normalizedKey = key.trim().toLowerCase();
207  for (XryKey keyChoice : XryKey.values()) {
208  if (normalizedKey.equals(keyChoice.name)) {
209  return keyChoice;
210  }
211  }
212 
213  throw new IllegalArgumentException(String.format("Key [%s] was not found."
214  + " All keys should be tested with contains.", key));
215  }
216  }
217 }

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.