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

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.