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;
95 preferences.addPreferenceChangeListener(listener);
99 preferences.removePreferenceChangeListener(listener);
103 return preferences.getBoolean(KEEP_PREFERRED_VIEWER,
false);
107 preferences.putBoolean(KEEP_PREFERRED_VIEWER, value);
111 return preferences.getBoolean(HIDE_KNOWN_FILES_IN_DATA_SOURCES_TREE,
false);
115 preferences.putBoolean(HIDE_KNOWN_FILES_IN_DATA_SOURCES_TREE, value);
119 return preferences.getBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE,
true);
123 preferences.putBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, value);
127 return preferences.getBoolean(DISPLAY_TIMES_IN_LOCAL_TIME,
true);
131 preferences.putBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, value);
135 return preferences.getInt(NUMBER_OF_FILE_INGEST_THREADS, 2);
139 preferences.putInt(NUMBER_OF_FILE_INGEST_THREADS, value);
150 dbType = DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE,
"POSTGRESQL"));
151 }
catch (Exception ex) {
152 dbType = DbType.SQLITE;
154 return new CaseDbConnectionInfo(
155 preferences.get(EXTERNAL_DATABASE_HOSTNAME_OR_IP,
""),
156 preferences.get(EXTERNAL_DATABASE_PORTNUMBER,
"5432"),
157 preferences.get(EXTERNAL_DATABASE_USER,
""),
158 TextConverter.convertHexTextToText(preferences.get(EXTERNAL_DATABASE_PASSWORD,
"")),
170 preferences.put(EXTERNAL_DATABASE_HOSTNAME_OR_IP, connectionInfo.getHost());
171 preferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort());
172 preferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName());
173 preferences.put(EXTERNAL_DATABASE_PASSWORD, TextConverter.convertTextToHexText(connectionInfo.getPassword()));
174 preferences.put(EXTERNAL_DATABASE_TYPE, connectionInfo.getDbType().toString());
178 preferences.putBoolean(IS_MULTI_USER_MODE_ENABLED, enabled);
185 return preferences.getBoolean(IS_MULTI_USER_MODE_ENABLED,
false);
189 return preferences.get(INDEXING_SERVER_HOST,
"");
193 preferences.put(INDEXING_SERVER_HOST, hostName);
197 return preferences.get(INDEXING_SERVER_PORT,
"8983");
201 preferences.putInt(INDEXING_SERVER_PORT, port);
211 preferences.put(MESSAGE_SERVICE_HOST, info.getHost());
212 preferences.put(MESSAGE_SERVICE_PORT, Integer.toString(info.getPort()));
213 preferences.put(MESSAGE_SERVICE_USER, info.getUserName());
214 preferences.put(MESSAGE_SERVICE_PASSWORD, TextConverter.convertTextToHexText(info.getPassword()));
226 port = Integer.parseInt(preferences.get(MESSAGE_SERVICE_PORT, DEFAULT_PORT_STRING));
227 }
catch (NumberFormatException ex) {
233 preferences.get(MESSAGE_SERVICE_HOST,
""),
235 preferences.get(MESSAGE_SERVICE_USER,
""),
236 TextConverter.convertHexTextToText(preferences.get(MESSAGE_SERVICE_PASSWORD,
"")));
245 int timeOut = preferences.getInt(PROCESS_TIME_OUT_HOURS, DEFAULT_PROCESS_TIMEOUT_HR);
261 preferences.putInt(PROCESS_TIME_OUT_HOURS, value);
272 boolean enabled = preferences.getBoolean(PROCESS_TIME_OUT_ENABLED,
false);
284 preferences.putBoolean(PROCESS_TIME_OUT_ENABLED, enabled);
291 static final class TextConverter {
293 private static final char[] TMP =
"hgleri21auty84fwe".toCharArray();
294 private static final byte[] SALT = {
295 (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12,
296 (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12,};
307 static String convertTextToHexText(String property)
throws UserPreferencesException {
309 SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(
"PBEWithMD5AndDES");
310 SecretKey key = keyFactory.generateSecret(
new PBEKeySpec(TMP));
311 Cipher pbeCipher = Cipher.getInstance(
"PBEWithMD5AndDES");
312 pbeCipher.init(Cipher.ENCRYPT_MODE, key,
new PBEParameterSpec(SALT, 20));
313 return base64Encode(pbeCipher.doFinal(property.getBytes(
"UTF-8")));
314 }
catch (Exception ex) {
315 throw new UserPreferencesException(
316 NbBundle.getMessage(TextConverter.class,
"TextConverter.convert.exception.txt"));
320 private static String base64Encode(byte[] bytes) {
321 return Base64.getEncoder().encodeToString(bytes);
333 static String convertHexTextToText(String property)
throws UserPreferencesException {
335 SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(
"PBEWithMD5AndDES");
336 SecretKey key = keyFactory.generateSecret(
new PBEKeySpec(TMP));
337 Cipher pbeCipher = Cipher.getInstance(
"PBEWithMD5AndDES");
338 pbeCipher.init(Cipher.DECRYPT_MODE, key,
new PBEParameterSpec(SALT, 20));
339 return new String(pbeCipher.doFinal(base64Decode(property)),
"UTF-8");
340 }
catch (Exception ex) {
341 throw new UserPreferencesException(
342 NbBundle.getMessage(TextConverter.class,
"TextConverter.convertFromHex.exception.txt"));
346 private static byte[] base64Decode(String property) {
347 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 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 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 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()