Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CTLicensePersistence.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.ctoptions.ctcloud;
20 
25 import com.fasterxml.jackson.core.JsonProcessingException;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import java.io.File;
28 import java.io.IOException;
29 import java.nio.file.Paths;
30 import java.util.Optional;
31 import java.util.logging.Level;
34 
38 public class CTLicensePersistence {
39 
40  private static final String CT_SETTINGS_DIR = "CyberTriage";
41  private static final String CT_LICENSE_FILENAME = "CyberTriageLicense.json";
42  private static final String MALWARE_INGEST_SETTINGS_FILENAME = "MalwareIngestSettings.json";
43 
44  private static final Logger logger = Logger.getLogger(CTLicensePersistence.class.getName());
45 
46  private static final CTLicensePersistence instance = new CTLicensePersistence();
47 
49 
51  return instance;
52  }
53 
54  public synchronized boolean deleteLicenseResponse() {
55  File licenseFile = getCTLicenseFile();
56  if (licenseFile.exists()) {
57  return licenseFile.delete();
58  } else {
59  return false;
60  }
61  }
62 
63  public synchronized boolean saveLicenseResponse(LicenseResponse licenseResponse) {
64  if (licenseResponse != null) {
65  File licenseFile = getCTLicenseFile();
66  try {
67  licenseFile.getParentFile().mkdirs();
68  objectMapper.writeValue(licenseFile, licenseResponse);
69  return true;
70  } catch (IOException ex) {
71  logger.log(Level.WARNING, "There was an error writing CyberTriage license to file: " + licenseFile.getAbsolutePath(), ex);
72  }
73  }
74 
75  return false;
76  }
77 
78  public synchronized Optional<LicenseResponse> loadLicenseResponse() {
79  Optional<LicenseResponse> toRet = Optional.empty();
80  File licenseFile = getCTLicenseFile();
81  if (licenseFile.exists() && licenseFile.isFile()) {
82  try {
83  toRet = Optional.ofNullable(objectMapper.readValue(licenseFile, LicenseResponse.class));
84  } catch (IOException ex) {
85  logger.log(Level.WARNING, "There was an error reading CyberTriage license to file: " + licenseFile.getAbsolutePath(), ex);
86  }
87  }
88 
89  return toRet;
90  }
91 
92  public synchronized Optional<LicenseInfo> loadLicenseInfo() {
93  return loadLicenseResponse().flatMap((license) -> {
94  try {
95  return Optional.ofNullable(LicenseDecryptorUtil.getInstance().createLicenseInfo(license));
96  } catch (JsonProcessingException | LicenseDecryptorUtil.InvalidLicenseException ex) {
97  logger.log(Level.WARNING, "There was an error decrypting license data from license file", ex);
98  return Optional.empty();
99  }
100  });
101  }
102 
103  private File getCTLicenseFile() {
105  }
106 
107  private File getMalwareIngestFile() {
109  }
110 }
synchronized boolean saveLicenseResponse(LicenseResponse licenseResponse)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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