From 0bec001773e64a70c15c99790fd346be180c1656 Mon Sep 17 00:00:00 2001
From: Greg DiCristofaro <gregd@basistech.com>
Date: Thu, 24 Aug 2023 14:10:59 -0400
Subject: [PATCH] fixes

---
 .../autopsy/ctoptions/CTOptionsPanel.java     |  2 +-
 .../ctcloud/CTMalwareScannerOptionsPanel.java |  2 +-
 .../CTIncidentImportOptionsPanel.java         | 33 ++++----
 .../autopsy/incidentoptions/CTSettings.java   | 79 ++++++++++++-------
 .../CTSettingsPersistence.java                | 31 +++++---
 5 files changed, 91 insertions(+), 56 deletions(-)

diff --git a/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/CTOptionsPanel.java b/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/CTOptionsPanel.java
index 83a4a9a51a..2b6cffe789 100644
--- a/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/CTOptionsPanel.java
+++ b/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/CTOptionsPanel.java
@@ -26,12 +26,12 @@
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.List;
-import java.util.logging.Logger;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import javax.swing.JPanel;
 import org.netbeans.spi.options.OptionsPanelController;
 import org.openide.util.Lookup;
+import org.sleuthkit.autopsy.coreutils.Logger;
 import org.sleuthkit.autopsy.ingest.IngestModuleGlobalSettingsPanel;
 
 /**
diff --git a/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/ctcloud/CTMalwareScannerOptionsPanel.java b/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/ctcloud/CTMalwareScannerOptionsPanel.java
index 375943188c..3c71bd3cba 100644
--- a/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/ctcloud/CTMalwareScannerOptionsPanel.java
+++ b/Core/src/com/basistech/df/cybertriage/autopsy/ctoptions/ctcloud/CTMalwareScannerOptionsPanel.java
@@ -40,7 +40,6 @@
 import java.util.concurrent.CancellationException;
 import java.util.concurrent.ExecutionException;
 import java.util.logging.Level;
-import java.util.logging.Logger;
 import javax.swing.JOptionPane;
 import javax.swing.SwingUtilities;
 import javax.swing.SwingWorker;
@@ -51,6 +50,7 @@
 import org.openide.util.lookup.ServiceProvider;
 import org.openide.windows.WindowManager;
 import org.sleuthkit.autopsy.core.UserPreferences;
+import org.sleuthkit.autopsy.coreutils.Logger;
 
 /**
  * Options panel to be displayed in the CTOptionsPanel for settings regarding
diff --git a/Core/src/com/basistech/df/cybertriage/autopsy/incidentoptions/CTIncidentImportOptionsPanel.java b/Core/src/com/basistech/df/cybertriage/autopsy/incidentoptions/CTIncidentImportOptionsPanel.java
index bf018701ca..ef7aa5a67e 100644
--- a/Core/src/com/basistech/df/cybertriage/autopsy/incidentoptions/CTIncidentImportOptionsPanel.java
+++ b/Core/src/com/basistech/df/cybertriage/autopsy/incidentoptions/CTIncidentImportOptionsPanel.java
@@ -1,16 +1,21 @@
-/** *************************************************************************
- ** This data and information is proprietary to, and a valuable trade secret
- ** of, Sleuth Kit Labs. It is given in confidence by Sleuth Kit Labs
- ** and may only be used as permitted under the license agreement under which
- ** it has been distributed, and in no other way.
- **
- ** Copyright (c) 2023 Sleuth Kit Labs, LLC. All rights reserved
- **
- ** The technical data and information provided herein are provided with
- ** `limited rights', and the computer software provided herein is provided
- ** with `restricted rights' as those terms are defined in DAR and ASPR
- ** 7-104.9(a).
- ************************************************************************** */
+/*
+ * Autopsy Forensic Browser
+ *
+ * Copyright 2023 Basis Technology Corp.
+ * Contact: carrier <at> sleuthkit <dot> org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package com.basistech.df.cybertriage.autopsy.incidentoptions;
 
 import com.basistech.df.cybertriage.autopsy.ctoptions.subpanel.CTOptionsSubPanel;
@@ -21,7 +26,7 @@
 import java.net.URISyntaxException;
 import java.util.Collections;
 import java.util.logging.Level;
-import java.util.logging.Logger;
+import org.sleuthkit.autopsy.coreutils.Logger;
 import javax.swing.JFileChooser;
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
diff --git a/Core/src/com/basistech/df/cybertriage/autopsy/incidentoptions/CTSettings.java b/Core/src/com/basistech/df/cybertriage/autopsy/incidentoptions/CTSettings.java
index 67abb34f7b..d6427a641c 100644
--- a/Core/src/com/basistech/df/cybertriage/autopsy/incidentoptions/CTSettings.java
+++ b/Core/src/com/basistech/df/cybertriage/autopsy/incidentoptions/CTSettings.java
@@ -1,16 +1,21 @@
-/** *************************************************************************
- ** This data and information is proprietary to, and a valuable trade secret
- ** of, Sleuth Kit Labs. It is given in confidence by Sleuth Kit Labs
- ** and may only be used as permitted under the license agreement under which
- ** it has been distributed, and in no other way.
- **
- ** Copyright (c) 2023 Sleuth Kit Labs, LLC. All rights reserved
- **
- ** The technical data and information provided herein are provided with
- ** `limited rights', and the computer software provided herein is provided
- ** with `restricted rights' as those terms are defined in DAR and ASPR
- ** 7-104.9(a).
- ************************************************************************** */
+/*
+ * Autopsy Forensic Browser
+ *
+ * Copyright 2023 Basis Technology Corp.
+ * Contact: carrier <at> sleuthkit <dot> org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package com.basistech.df.cybertriage.autopsy.incidentoptions;
 
 import java.io.IOException;
@@ -19,40 +24,60 @@
 import java.nio.file.Paths;
 import java.util.Objects;
 import java.util.logging.Level;
-import java.util.logging.Logger;
+import org.sleuthkit.autopsy.coreutils.Logger;
 import org.apache.commons.lang3.StringUtils;
 import org.openide.modules.Places;
+import org.sleuthkit.autopsy.coreutils.PlatformUtil;
 
 /**
- * CT settings that don't include license information. This code must be kept in-sync with code in
- * CT Autopsy Importer NBM.
+ * CT settings that don't include license information. This code must be kept
+ * in-sync with code in CT Autopsy Importer NBM.
  */
 public class CTSettings {
 
+    private static final Logger LOGGER = Logger.getLogger(CTSettings.class.getCanonicalName());
     private static final String DEFAULT_FILE_REPO_PATH = getAppDataLocalDirectory();
 
-    // taken from com.basistech.df.cybertriage.utils.SystemProperties
-    private static String getAppDataLocalDirectory() {
+    private static final String CYBERTRIAGE_FOLDER = "cybertriage";
+    private static final String CYBERTRIAGE_DOT_FOLDER = "." + CYBERTRIAGE_FOLDER;
 
-        Logger LOGGER = java.util.logging.Logger.getLogger(CTSettings.class.getCanonicalName());
+    // based on com.basistech.df.cybertriage.utils.SystemProperties
+    private static String getAppDataLocalDirectory() {
         if (Objects.nonNull(Places.getUserDirectory()) && Places.getUserDirectory().getAbsolutePath().endsWith("testuserdir")) { // APP is in testing .. this should return the test path
             LOGGER.log(Level.INFO, "Application Data (test mode) Path: " + Places.getUserDirectory().getAbsolutePath());
             return Places.getUserDirectory().getAbsolutePath();
-        } else {
-            
-            Path localAppPath = StringUtils.isBlank(System.getenv("LOCALAPPDATA"))
-                    ? Places.getUserDirectory().toPath().toAbsolutePath()
-                    : Paths.get(System.getenv("LOCALAPPDATA"), "cybertriage");
-            
+        }
+
+        // try to use LOCALAPPDATA on windows
+        String localDataStr = System.getenv("LOCALAPPDATA");
+        if (StringUtils.isNotBlank(localDataStr)) {
+            Path localAppPath = Paths.get(localDataStr, CYBERTRIAGE_FOLDER);
             try {
                 Files.createDirectories(localAppPath);
                 LOGGER.log(Level.INFO, "Application Data Path: " + localAppPath.toString());
                 return localAppPath.toString();
             } catch (IOException ex) {
-                LOGGER.log(Level.SEVERE, "IO Error, defaulting to user dir", ex);
-                return Places.getUserDirectory().getAbsolutePath(); // In case of an IO Error
+                LOGGER.log(Level.SEVERE, "IO Error using " + localAppPath.toString(), ex);
             }
         }
+
+        // try to use ~/.cybertriage anywhere else
+        if (!PlatformUtil.isWindowsOS()) {
+            String homePathStr = System.getenv("HOME");
+            if (StringUtils.isNotBlank(homePathStr)) {
+                Path localAppPath = Paths.get(homePathStr, CYBERTRIAGE_DOT_FOLDER);
+                try {
+                    Files.createDirectories(localAppPath);
+                    LOGGER.log(Level.INFO, "Non-windows Application Data Path: " + localAppPath.toString());
+                    return localAppPath.toString();
+                } catch (IOException ex) {
+                    LOGGER.log(Level.SEVERE, "IO Error using " + localAppPath.toString(), ex);
+                }
+            }
+        }
+
+        // defer to user directory otherwise
+        return Places.getUserDirectory().getAbsolutePath(); // In case of an IO Error
     }
 
     public static String getDefaultFileRepoPath() {
diff --git a/Core/src/com/basistech/df/cybertriage/autopsy/incidentoptions/CTSettingsPersistence.java b/Core/src/com/basistech/df/cybertriage/autopsy/incidentoptions/CTSettingsPersistence.java
index be60813edd..e5e5b6838f 100644
--- a/Core/src/com/basistech/df/cybertriage/autopsy/incidentoptions/CTSettingsPersistence.java
+++ b/Core/src/com/basistech/df/cybertriage/autopsy/incidentoptions/CTSettingsPersistence.java
@@ -1,16 +1,21 @@
-/** *************************************************************************
- ** This data and information is proprietary to, and a valuable trade secret
- ** of, Sleuth Kit Labs. It is given in confidence by Sleuth Kit Labs
- ** and may only be used as permitted under the license agreement under which
- ** it has been distributed, and in no other way.
- **
- ** Copyright (c) 2023 Sleuth Kit Labs, LLC. All rights reserved
- **
- ** The technical data and information provided herein are provided with
- ** `limited rights', and the computer software provided herein is provided
- ** with `restricted rights' as those terms are defined in DAR and ASPR
- ** 7-104.9(a).
- ************************************************************************** */
+/*
+ * Autopsy Forensic Browser
+ *
+ * Copyright 2023 Basis Technology Corp.
+ * Contact: carrier <at> sleuthkit <dot> org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package com.basistech.df.cybertriage.autopsy.incidentoptions;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
-- 
GitLab