Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CTHostIDGenerationUtil.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2023 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 com.basistech.df.cybertriage.autopsy.ctapi.util;
20 
21 import com.license4j.HardwareID;
22 import java.net.InetAddress;
23 import java.net.UnknownHostException;
24 import java.util.logging.Level;
25 import org.apache.commons.lang3.StringUtils;
27 
33 public class CTHostIDGenerationUtil {
34 
35  private static final Logger LOGGER = Logger.getLogger(CTHostIDGenerationUtil.class.getName());
36  private static final String USER_NAME = System.getProperty("user.name");
37  private static String cachedId = "";
38 
48  public static String generateLicenseHostID() {
49  if (StringUtils.isBlank(cachedId)) {
50  try {
51  String hostName = StringUtils.defaultString(InetAddress.getLocalHost().getCanonicalHostName());
52  String macAddressMd5 = StringUtils.isNotBlank(HardwareID.getHardwareIDFromEthernetAddress())
53  ? Md5HashUtil.getMD5MessageDigest(HardwareID.getHardwareIDFromEthernetAddress()).substring(0, 16)
54  : Md5HashUtil.getMD5MessageDigest(hostName).substring(0, 16);
55 
56  String usernameMd5 = StringUtils.isNotBlank(USER_NAME)
57  ? Md5HashUtil.getMD5MessageDigest(USER_NAME).substring(0, 16)
58  : Md5HashUtil.getMD5MessageDigest(hostName).substring(0, 16);
59 
60  cachedId = macAddressMd5 + "_" + usernameMd5;
61 
62  } catch (UnknownHostException ex) {
63  LOGGER.log(Level.WARNING, "Unable to determine host name.", ex);
64  }
65  }
66 
67  return cachedId;
68  }
69 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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