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;
68 private static final String
APP_NAME =
"AppName";
96 preferences.addPreferenceChangeListener(listener);
100 preferences.removePreferenceChangeListener(listener);
104 return preferences.getBoolean(KEEP_PREFERRED_VIEWER,
false);
108 preferences.putBoolean(KEEP_PREFERRED_VIEWER, value);
112 return preferences.getBoolean(HIDE_KNOWN_FILES_IN_DATA_SOURCES_TREE,
false);
116 preferences.putBoolean(HIDE_KNOWN_FILES_IN_DATA_SOURCES_TREE, value);
120 return preferences.getBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE,
true);
124 preferences.putBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, value);
128 return preferences.getBoolean(DISPLAY_TIMES_IN_LOCAL_TIME,
true);
132 preferences.putBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, value);
136 return preferences.getInt(NUMBER_OF_FILE_INGEST_THREADS, 2);
140 preferences.putInt(NUMBER_OF_FILE_INGEST_THREADS, value);
151 dbType = DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE,
"POSTGRESQL"));
152 }
catch (Exception ex) {
153 dbType = DbType.SQLITE;
155 return new CaseDbConnectionInfo(
156 preferences.get(EXTERNAL_DATABASE_HOSTNAME_OR_IP,
""),
157 preferences.get(EXTERNAL_DATABASE_PORTNUMBER,
"5432"),
158 preferences.get(EXTERNAL_DATABASE_USER,
""),
159 TextConverter.convertHexTextToText(preferences.get(EXTERNAL_DATABASE_PASSWORD,
"")),
171 preferences.put(EXTERNAL_DATABASE_HOSTNAME_OR_IP, connectionInfo.getHost());
172 preferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort());
173 preferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName());
174 preferences.put(EXTERNAL_DATABASE_PASSWORD, TextConverter.convertTextToHexText(connectionInfo.getPassword()));
175 preferences.put(EXTERNAL_DATABASE_TYPE, connectionInfo.getDbType().toString());
179 preferences.putBoolean(IS_MULTI_USER_MODE_ENABLED, enabled);
186 return preferences.getBoolean(IS_MULTI_USER_MODE_ENABLED,
false);
190 return preferences.get(INDEXING_SERVER_HOST,
"");
194 preferences.put(INDEXING_SERVER_HOST, hostName);
198 return preferences.get(INDEXING_SERVER_PORT,
"8983");
202 preferences.putInt(INDEXING_SERVER_PORT, port);
212 preferences.put(MESSAGE_SERVICE_HOST, info.getHost());
213 preferences.put(MESSAGE_SERVICE_PORT, Integer.toString(info.getPort()));
214 preferences.put(MESSAGE_SERVICE_USER, info.getUserName());
215 preferences.put(MESSAGE_SERVICE_PASSWORD, TextConverter.convertTextToHexText(info.getPassword()));
227 port = Integer.parseInt(preferences.get(MESSAGE_SERVICE_PORT, DEFAULT_PORT_STRING));
228 }
catch (NumberFormatException ex) {
234 preferences.get(MESSAGE_SERVICE_HOST,
""),
236 preferences.get(MESSAGE_SERVICE_USER,
""),
237 TextConverter.convertHexTextToText(preferences.get(MESSAGE_SERVICE_PASSWORD,
"")));
246 int timeOut = preferences.getInt(PROCESS_TIME_OUT_HOURS, DEFAULT_PROCESS_TIMEOUT_HR);
262 preferences.putInt(PROCESS_TIME_OUT_HOURS, value);
273 boolean enabled = preferences.getBoolean(PROCESS_TIME_OUT_ENABLED,
false);
285 preferences.putBoolean(PROCESS_TIME_OUT_ENABLED, enabled);
293 return preferences.get(APP_NAME,
"Autopsy");
302 preferences.put(APP_NAME, name);
309 static final class TextConverter {
311 private static final char[] TMP =
"hgleri21auty84fwe".toCharArray();
312 private static final byte[] SALT = {
313 (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12,
314 (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12,};
325 static String convertTextToHexText(String property)
throws UserPreferencesException {
327 SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(
"PBEWithMD5AndDES");
328 SecretKey key = keyFactory.generateSecret(
new PBEKeySpec(TMP));
329 Cipher pbeCipher = Cipher.getInstance(
"PBEWithMD5AndDES");
330 pbeCipher.init(Cipher.ENCRYPT_MODE, key,
new PBEParameterSpec(SALT, 20));
331 return base64Encode(pbeCipher.doFinal(property.getBytes(
"UTF-8")));
332 }
catch (Exception ex) {
333 throw new UserPreferencesException(
334 NbBundle.getMessage(TextConverter.class,
"TextConverter.convert.exception.txt"));
338 private static String base64Encode(byte[] bytes) {
339 return Base64.getEncoder().encodeToString(bytes);
351 static String convertHexTextToText(String property)
throws UserPreferencesException {
353 SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(
"PBEWithMD5AndDES");
354 SecretKey key = keyFactory.generateSecret(
new PBEKeySpec(TMP));
355 Cipher pbeCipher = Cipher.getInstance(
"PBEWithMD5AndDES");
356 pbeCipher.init(Cipher.DECRYPT_MODE, key,
new PBEParameterSpec(SALT, 20));
357 return new String(pbeCipher.doFinal(base64Decode(property)),
"UTF-8");
358 }
catch (Exception ex) {
359 throw new UserPreferencesException(
360 NbBundle.getMessage(TextConverter.class,
"TextConverter.convertFromHex.exception.txt"));
364 private static byte[] base64Decode(String property) {
365 return Base64.getDecoder().decode(property);
static final String HIDE_KNOWN_FILES_IN_DATA_SOURCES_TREE
static final String HIDE_KNOWN_FILES_IN_VIEWS_TREE
static void setProcessTimeOutHrs(int value)
static void setKeepPreferredContentViewer(boolean value)
static int getProcessTimeOutHrs()
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 final boolean isWindowsOS
static boolean getIsMultiUserModeEnabled()
static CaseDbConnectionInfo getDatabaseConnectionInfo()
static boolean keepPreferredContentViewer()
static boolean hideKnownFilesInViewsTree()
static void setIsTimeOutEnabled(boolean enabled)
static void setIsMultiUserModeEnabled(boolean enabled)
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 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()