Autopsy  4.20.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.Files;
30 import java.nio.file.Paths;
31 import java.util.Optional;
32 import java.util.logging.Level;
35 
39 public class CTLicensePersistence {
40 
41  private static final String CT_SETTINGS_DIR = "CyberTriage";
42  private static final String CT_LICENSE_FILENAME = "CyberTriageLicense.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 saveLicenseResponse(LicenseResponse licenseResponse) {
55  if (licenseResponse != null) {
56  File licenseFile = getCTLicenseFile();
57  try {
58  licenseFile.getParentFile().mkdirs();
59  objectMapper.writeValue(licenseFile, licenseResponse);
60  return true;
61  } catch (IOException ex) {
62  logger.log(Level.WARNING, "There was an error writing CyberTriage license to file: " + licenseFile.getAbsolutePath(), ex);
63  }
64  }
65 
66  return false;
67  }
68 
69  public synchronized Optional<LicenseResponse> loadLicenseResponse() {
70  Optional<LicenseResponse> toRet = Optional.empty();
71  File licenseFile = getCTLicenseFile();
72  if (licenseFile.exists() && licenseFile.isFile()) {
73  try {
74  toRet = Optional.ofNullable(objectMapper.readValue(licenseFile, LicenseResponse.class));
75  } catch (IOException ex) {
76  logger.log(Level.WARNING, "There was an error reading CyberTriage license to file: " + licenseFile.getAbsolutePath(), ex);
77  }
78  }
79 
80  return toRet;
81  }
82 
83  public synchronized Optional<LicenseInfo> loadLicenseInfo() {
84  return loadLicenseResponse().flatMap((license) -> {
85  try {
86  return Optional.ofNullable(LicenseDecryptorUtil.getInstance().createLicenseInfo(license));
87  } catch (JsonProcessingException | LicenseDecryptorUtil.InvalidLicenseException ex) {
88  logger.log(Level.WARNING, "There was an error decrypting license data from license file", ex);
89  return Optional.empty();
90  }
91  });
92  }
93 
94  private File getCTLicenseFile() {
96  }
97 }
synchronized boolean saveLicenseResponse(LicenseResponse licenseResponse)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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.