Autopsy  4.18.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
XRYUtils.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2020 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.time.Instant;
22 import java.time.LocalDateTime;
23 import java.time.OffsetDateTime;
24 import java.time.ZoneId;
25 import java.time.ZonedDateTime;
26 import java.time.format.DateTimeFormatter;
27 import java.time.temporal.TemporalAccessor;
28 import java.time.temporal.TemporalQueries;
29 import org.sleuthkit.datamodel.CommunicationsUtils;
30 import org.sleuthkit.datamodel.InvalidAccountIDException;
31 
35 final class XRYUtils {
36 
37  // Pattern is in reverse due to a Java 8 bug, see calculateSecondsSinceEpoch()
38  // function for more details.
39  private static final DateTimeFormatter DATE_TIME_PARSER
40  = DateTimeFormatter.ofPattern("[(XXX) ][O ][(O) ]a h:m:s M/d/y");
41 
42  private static final String DEVICE_LOCALE = "(device)";
43  private static final String NETWORK_LOCALE = "(network)";
44 
45  public static boolean isPhoneValid(String phoneNumber) {
46  try {
47  CommunicationsUtils.normalizePhoneNum(phoneNumber);
48  return true;
49  } catch (InvalidAccountIDException ex) {
50  return false;
51  }
52  }
53 
54  public static boolean isEmailValid(String email) {
55  try {
56  CommunicationsUtils.normalizeEmailAddress(email);
57  return true;
58  } catch (InvalidAccountIDException ex) {
59  return false;
60  }
61  }
62 
69  public static long calculateSecondsSinceEpoch(String dateTime) {
70  String dateTimeWithoutLocale = removeDateTimeLocale(dateTime).trim();
87  String reversedDateTime = reverseOrderOfDateTimeComponents(dateTimeWithoutLocale);
95  String reversedDateTimeWithGMT = reversedDateTime.replace("UTC", "GMT");
96  TemporalAccessor result = DATE_TIME_PARSER.parseBest(reversedDateTimeWithGMT,
97  ZonedDateTime::from,
98  LocalDateTime::from,
99  OffsetDateTime::from);
100  //Query for the ZoneID
101  if (result.query(TemporalQueries.zoneId()) == null) {
102  //If none, assumed GMT+0.
103  return ZonedDateTime.of(LocalDateTime.from(result),
104  ZoneId.of("GMT")).toEpochSecond();
105  } else {
106  return Instant.from(result).getEpochSecond();
107  }
108  }
109 
118  private static String reverseOrderOfDateTimeComponents(String dateTime) {
119  StringBuilder reversedDateTime = new StringBuilder(dateTime.length());
120  String[] dateTimeComponents = dateTime.split(" ");
121  for (String component : dateTimeComponents) {
122  reversedDateTime.insert(0, " ").insert(0, component);
123  }
124  return reversedDateTime.toString().trim();
125  }
126 
135  private static String removeDateTimeLocale(String dateTime) {
136  String result = dateTime;
137  int deviceIndex = result.toLowerCase().indexOf(DEVICE_LOCALE);
138  if (deviceIndex != -1) {
139  result = result.substring(0, deviceIndex);
140  }
141  int networkIndex = result.toLowerCase().indexOf(NETWORK_LOCALE);
142  if (networkIndex != -1) {
143  result = result.substring(0, networkIndex);
144  }
145  return result;
146  }
147 
148  private XRYUtils() {
149 
150  }
151 }

Copyright © 2012-2021 Basis Technology. Generated on: Thu Jul 8 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.