19 package org.sleuthkit.autopsy.core;
21 import java.util.Base64;
22 import java.util.prefs.BackingStoreException;
24 import java.util.prefs.PreferenceChangeListener;
25 import java.util.prefs.Preferences;
26 import javax.crypto.Cipher;
27 import javax.crypto.SecretKey;
28 import javax.crypto.SecretKeyFactory;
29 import javax.crypto.spec.PBEKeySpec;
30 import javax.crypto.spec.PBEParameterSpec;
31 import org.openide.util.NbBundle;
32 import org.openide.util.NbPreferences;
70 private static final String
APP_NAME =
"AppName";
98 preferences.addPreferenceChangeListener(listener);
102 preferences.removePreferenceChangeListener(listener);
106 return preferences.getBoolean(KEEP_PREFERRED_VIEWER,
false);
110 preferences.putBoolean(KEEP_PREFERRED_VIEWER, value);
114 return preferences.getBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE,
false);
118 preferences.putBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, value);
122 return preferences.getBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE,
true);
126 preferences.putBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, value);
130 return preferences.getBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE,
true);
134 preferences.putBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, value);
138 return preferences.getBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE,
true);
142 preferences.putBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, value);
146 return preferences.getBoolean(DISPLAY_TIMES_IN_LOCAL_TIME,
true);
150 preferences.putBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, value);
154 return preferences.getInt(NUMBER_OF_FILE_INGEST_THREADS, 2);
158 preferences.putInt(NUMBER_OF_FILE_INGEST_THREADS, value);
169 dbType =
DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE,
"POSTGRESQL"));
170 }
catch (Exception ex) {
174 preferences.get(EXTERNAL_DATABASE_HOSTNAME_OR_IP,
""),
175 preferences.get(EXTERNAL_DATABASE_PORTNUMBER,
"5432"),
176 preferences.get(EXTERNAL_DATABASE_USER,
""),
177 TextConverter.convertHexTextToText(preferences.get(EXTERNAL_DATABASE_PASSWORD,
"")),
189 preferences.put(EXTERNAL_DATABASE_HOSTNAME_OR_IP, connectionInfo.getHost());
190 preferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort());
191 preferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName());
192 preferences.put(EXTERNAL_DATABASE_PASSWORD, TextConverter.convertTextToHexText(connectionInfo.getPassword()));
193 preferences.put(EXTERNAL_DATABASE_TYPE, connectionInfo.getDbType().toString());
197 preferences.putBoolean(IS_MULTI_USER_MODE_ENABLED, enabled);
201 if (!IS_WINDOWS_OS) {
204 return preferences.getBoolean(IS_MULTI_USER_MODE_ENABLED,
false);
208 return preferences.get(INDEXING_SERVER_HOST,
"");
212 preferences.put(INDEXING_SERVER_HOST, hostName);
216 return preferences.get(INDEXING_SERVER_PORT,
"8983");
220 preferences.putInt(INDEXING_SERVER_PORT, port);
230 preferences.put(MESSAGE_SERVICE_HOST, info.getHost());
231 preferences.put(MESSAGE_SERVICE_PORT, Integer.toString(info.getPort()));
232 preferences.put(MESSAGE_SERVICE_USER, info.getUserName());
233 preferences.put(MESSAGE_SERVICE_PASSWORD, TextConverter.convertTextToHexText(info.getPassword()));
245 port = Integer.parseInt(preferences.get(MESSAGE_SERVICE_PORT, DEFAULT_PORT_STRING));
246 }
catch (NumberFormatException ex) {
252 preferences.get(MESSAGE_SERVICE_HOST,
""),
254 preferences.get(MESSAGE_SERVICE_USER,
""),
255 TextConverter.convertHexTextToText(preferences.get(MESSAGE_SERVICE_PASSWORD,
"")));
264 int timeOut = preferences.getInt(PROCESS_TIME_OUT_HOURS, DEFAULT_PROCESS_TIMEOUT_HR);
280 preferences.putInt(PROCESS_TIME_OUT_HOURS, value);
291 boolean enabled = preferences.getBoolean(PROCESS_TIME_OUT_ENABLED,
false);
303 preferences.putBoolean(PROCESS_TIME_OUT_ENABLED, enabled);
311 return preferences.get(APP_NAME,
"Autopsy");
320 preferences.put(APP_NAME, name);
327 static final class TextConverter {
329 private static final char[] TMP =
"hgleri21auty84fwe".toCharArray();
330 private static final byte[] SALT = {
331 (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12,
332 (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12,};
343 static String convertTextToHexText(String property)
throws UserPreferencesException {
345 SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(
"PBEWithMD5AndDES");
346 SecretKey key = keyFactory.generateSecret(
new PBEKeySpec(TMP));
347 Cipher pbeCipher = Cipher.getInstance(
"PBEWithMD5AndDES");
348 pbeCipher.init(Cipher.ENCRYPT_MODE, key,
new PBEParameterSpec(SALT, 20));
349 return base64Encode(pbeCipher.doFinal(property.getBytes(
"UTF-8")));
350 }
catch (Exception ex) {
351 throw new UserPreferencesException(
352 NbBundle.getMessage(TextConverter.class,
"TextConverter.convert.exception.txt"));
356 private static String base64Encode(byte[] bytes) {
357 return Base64.getEncoder().encodeToString(bytes);
369 static String convertHexTextToText(String property)
throws UserPreferencesException {
371 SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(
"PBEWithMD5AndDES");
372 SecretKey key = keyFactory.generateSecret(
new PBEKeySpec(TMP));
373 Cipher pbeCipher = Cipher.getInstance(
"PBEWithMD5AndDES");
374 pbeCipher.init(Cipher.DECRYPT_MODE, key,
new PBEParameterSpec(SALT, 20));
375 return new String(pbeCipher.doFinal(base64Decode(property)),
"UTF-8");
376 }
catch (Exception ex) {
377 throw new UserPreferencesException(
378 NbBundle.getMessage(TextConverter.class,
"TextConverter.convertFromHex.exception.txt"));
382 private static byte[] base64Decode(String property) {
383 return Base64.getDecoder().decode(property);
static final String HIDE_SLACK_FILES_IN_VIEWS_TREE
static final String HIDE_KNOWN_FILES_IN_VIEWS_TREE
static void setProcessTimeOutHrs(int value)
static void setKeepPreferredContentViewer(boolean value)
static int getProcessTimeOutHrs()
static boolean hideSlackFilesInDataSourcesTree()
static final int DEFAULT_PROCESS_TIMEOUT_HR
static String getIndexingServerPort()
static void setNumberOfFileIngestThreads(int value)
static String getAppName()
static void reloadFromStorage()
static void setDisplayTimesInLocalTime(boolean value)
static final String EXTERNAL_DATABASE_NAME
static final String EXTERNAL_DATABASE_USER
static final String DEFAULT_PORT_STRING
static boolean getIsMultiUserModeEnabled()
static void setHideSlackFilesInViewsTree(boolean value)
static CaseDbConnectionInfo getDatabaseConnectionInfo()
static boolean keepPreferredContentViewer()
static boolean hideKnownFilesInViewsTree()
static void setIsTimeOutEnabled(boolean enabled)
static final String HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE
static void setIsMultiUserModeEnabled(boolean enabled)
static final boolean IS_WINDOWS_OS
static void removeChangeListener(PreferenceChangeListener listener)
static void setMessageServiceConnectionInfo(MessageServiceConnectionInfo info)
static final String IS_MULTI_USER_MODE_ENABLED
static final String NUMBER_OF_FILE_INGEST_THREADS
static void setHideKnownFilesInViewsTree(boolean value)
static boolean getIsTimeOutEnabled()
static int numberOfFileIngestThreads()
static final Preferences preferences
static final String DISPLAY_TIMES_IN_LOCAL_TIME
static void setAppName(String name)
static final int DEFAULT_PORT_INT
static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo)
static final String EXTERNAL_DATABASE_PORTNUMBER
static final String PROCESS_TIME_OUT_ENABLED
static final String KEEP_PREFERRED_VIEWER
static final String MESSAGE_SERVICE_PORT
static void saveToStorage()
static void setIndexingServerHost(String hostName)
static final String MESSAGE_SERVICE_PASSWORD
static final String INDEXING_SERVER_HOST
static boolean hideSlackFilesInViewsTree()
static final String HIDE_SLACK_FILES_IN_DATA_SRCS_TREE
static void setHideSlackFilesInDataSourcesTree(boolean value)
static void setHideKnownFilesInDataSourcesTree(boolean value)
static void setIndexingServerPort(int port)
static final String PROCESS_TIME_OUT_HOURS
static final String MESSAGE_SERVICE_HOST
static final String APP_NAME
static boolean hideKnownFilesInDataSourcesTree()
static final String MESSAGE_SERVICE_USER
static void addChangeListener(PreferenceChangeListener listener)
static final String EXTERNAL_DATABASE_TYPE
static final String INDEXING_SERVER_PORT
static String getIndexingServerHost()
static boolean displayTimesInLocalTime()
static final String EXTERNAL_DATABASE_PASSWORD
static final String EXTERNAL_DATABASE_HOSTNAME_OR_IP
static MessageServiceConnectionInfo getMessageServiceConnectionInfo()