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;
72 private static final String
APP_NAME =
"AppName";
74 private static final String
MODE =
"AutopsyMode";
131 preferences.addPreferenceChangeListener(listener);
135 preferences.removePreferenceChangeListener(listener);
139 return preferences.getBoolean(KEEP_PREFERRED_VIEWER,
false);
143 preferences.putBoolean(KEEP_PREFERRED_VIEWER, value);
147 return preferences.getBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE,
false);
151 preferences.putBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, value);
155 return preferences.getBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE,
true);
159 preferences.putBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, value);
163 return preferences.getBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE,
true);
167 preferences.putBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, value);
171 return preferences.getBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE,
true);
175 preferences.putBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, value);
179 return preferences.getBoolean(DISPLAY_TIMES_IN_LOCAL_TIME,
true);
183 preferences.putBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, value);
187 return preferences.getInt(NUMBER_OF_FILE_INGEST_THREADS, 2);
191 preferences.putInt(NUMBER_OF_FILE_INGEST_THREADS, value);
204 dbType = DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE,
"POSTGRESQL"));
205 }
catch (Exception ex) {
206 dbType = DbType.SQLITE;
208 return new CaseDbConnectionInfo(
209 preferences.get(EXTERNAL_DATABASE_HOSTNAME_OR_IP,
""),
210 preferences.get(EXTERNAL_DATABASE_PORTNUMBER,
"5432"),
211 preferences.get(EXTERNAL_DATABASE_USER,
""),
212 TextConverter.convertHexTextToText(preferences.get(EXTERNAL_DATABASE_PASSWORD,
"")),
225 preferences.put(EXTERNAL_DATABASE_HOSTNAME_OR_IP, connectionInfo.getHost());
226 preferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort());
227 preferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName());
228 preferences.put(EXTERNAL_DATABASE_PASSWORD, TextConverter.convertTextToHexText(connectionInfo.getPassword()));
229 preferences.put(EXTERNAL_DATABASE_TYPE, connectionInfo.getDbType().toString());
233 preferences.putBoolean(IS_MULTI_USER_MODE_ENABLED, enabled);
237 if (!IS_WINDOWS_OS) {
240 return preferences.getBoolean(IS_MULTI_USER_MODE_ENABLED,
false);
244 return preferences.get(INDEXING_SERVER_HOST,
"");
248 preferences.put(INDEXING_SERVER_HOST, hostName);
252 return preferences.get(INDEXING_SERVER_PORT,
"8983");
256 preferences.putInt(INDEXING_SERVER_PORT, port);
267 preferences.put(MESSAGE_SERVICE_HOST, info.getHost());
268 preferences.put(MESSAGE_SERVICE_PORT, Integer.toString(info.getPort()));
269 preferences.put(MESSAGE_SERVICE_USER, info.getUserName());
270 preferences.put(MESSAGE_SERVICE_PASSWORD, TextConverter.convertTextToHexText(info.getPassword()));
283 port = Integer.parseInt(preferences.get(MESSAGE_SERVICE_PORT, DEFAULT_PORT_STRING));
284 }
catch (NumberFormatException ex) {
290 preferences.get(MESSAGE_SERVICE_HOST,
""),
292 preferences.get(MESSAGE_SERVICE_USER,
""),
293 TextConverter.convertHexTextToText(preferences.get(MESSAGE_SERVICE_PASSWORD,
"")));
302 int timeOut = preferences.getInt(PROCESS_TIME_OUT_HOURS, DEFAULT_PROCESS_TIMEOUT_HR);
318 preferences.putInt(PROCESS_TIME_OUT_HOURS, value);
329 boolean enabled = preferences.getBoolean(PROCESS_TIME_OUT_ENABLED,
false);
341 preferences.putBoolean(PROCESS_TIME_OUT_ENABLED, enabled);
359 preferences.put(APP_NAME, name);
365 static final class TextConverter {
367 private static final char[] TMP =
"hgleri21auty84fwe".toCharArray();
368 private static final byte[] SALT = {
369 (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12,
370 (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12,};
381 static String convertTextToHexText(String property)
throws UserPreferencesException {
383 SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(
"PBEWithMD5AndDES");
384 SecretKey key = keyFactory.generateSecret(
new PBEKeySpec(TMP));
385 Cipher pbeCipher = Cipher.getInstance(
"PBEWithMD5AndDES");
386 pbeCipher.init(Cipher.ENCRYPT_MODE, key,
new PBEParameterSpec(SALT, 20));
387 return base64Encode(pbeCipher.doFinal(property.getBytes(
"UTF-8")));
388 }
catch (Exception ex) {
389 throw new UserPreferencesException(
390 NbBundle.getMessage(TextConverter.class,
"TextConverter.convert.exception.txt"));
394 private static String base64Encode(byte[] bytes) {
395 return Base64.getEncoder().encodeToString(bytes);
407 static String convertHexTextToText(String property)
throws UserPreferencesException {
409 SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(
"PBEWithMD5AndDES");
410 SecretKey key = keyFactory.generateSecret(
new PBEKeySpec(TMP));
411 Cipher pbeCipher = Cipher.getInstance(
"PBEWithMD5AndDES");
412 pbeCipher.init(Cipher.DECRYPT_MODE, key,
new PBEParameterSpec(SALT, 20));
413 return new String(pbeCipher.doFinal(base64Decode(property)),
"UTF-8");
414 }
catch (Exception ex) {
415 throw new UserPreferencesException(
416 NbBundle.getMessage(TextConverter.class,
"TextConverter.convertFromHex.exception.txt"));
420 private static byte[] base64Decode(String property) {
421 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 void setMode(SelectedMode mode)
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 String SETTINGS_PROPERTIES
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 synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
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 String getConfigSetting(String moduleName, String settingName)
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 String getVersion()
static final String INDEXING_SERVER_PORT
static SelectedMode getMode()
static String getIndexingServerHost()
static boolean settingExists(String moduleName, String settingName)
static boolean displayTimesInLocalTime()
static final String EXTERNAL_DATABASE_PASSWORD
static final String EXTERNAL_DATABASE_HOSTNAME_OR_IP
static MessageServiceConnectionInfo getMessageServiceConnectionInfo()