From 78cad5ccbb52ea247e6a3f0e70699e4568db4ae8 Mon Sep 17 00:00:00 2001 From: mhmdfy Date: Thu, 1 Oct 2015 15:13:48 -0400 Subject: [PATCH 01/14] write jython documents with more details --- docs/doxygen/modDevPython.dox | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/doxygen/modDevPython.dox b/docs/doxygen/modDevPython.dox index 9b1b74501f..983a100830 100755 --- a/docs/doxygen/modDevPython.dox +++ b/docs/doxygen/modDevPython.dox @@ -23,7 +23,20 @@ There are also a set of tutorials that Basis Technology published on their blog: \section mod_dev_py_setup Basic Setup -You don't really need anything to develop a python Autopsy module except for the standard Autopsy and your favorite text editor. We recommend pyCharm or the Python plug-in to NetBeans. +-You don't really need anything to develop a python Autopsy module except for the standard Autopsy and your favorite text editor. We recommend IntelliJ IDEA or the Jython plug-in to NetBeans. + +To install NetBeans' plug-in: +-# Download and install the Jython 2.7 installer (http://www.jython.org/downloads.html). +-# Download NetBeans Python plug-in zip file (http://plugins.netbeans.org/plugin/56795/python4netbeans802). +-# Unpack the content (.nbm files) of the zip file to the desired location. +-# In NetBeans go to Tools->Plugins->Download->Add Plugins, then choose extracted .nbm files. +-# Setup Jython path from Tools->Python Platform, click on new, then choose Jython.exe (usually in C:/Program files/Jython2.7/bin/) + +To install IntelliJ IDEA + Python plug-in: +-# Download and install IDEA https://www.jetbrains.com/idea/download/ +-# In File->Settings->Plugins-> install Python Community Edition +-# In File->Project Structure->Project-> Project SDK-> choose IntelliJ IDEA Community Edition +-# In Libraries->add new libraries->choose desired autopsy modules (usually in C:\Program Files\Autopsy-3.1.3\autopsy\modules) \section mod_dev_py_create Creating a Basic Python Module From 61242364c48cc93a28d2b4dc2b2d4445a4311840 Mon Sep 17 00:00:00 2001 From: mhmdfy Date: Thu, 1 Oct 2015 15:15:24 -0400 Subject: [PATCH 02/14] download tab --- docs/doxygen/modDevPython.dox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/doxygen/modDevPython.dox b/docs/doxygen/modDevPython.dox index 983a100830..272df945de 100755 --- a/docs/doxygen/modDevPython.dox +++ b/docs/doxygen/modDevPython.dox @@ -29,7 +29,7 @@ To install NetBeans' plug-in: -# Download and install the Jython 2.7 installer (http://www.jython.org/downloads.html). -# Download NetBeans Python plug-in zip file (http://plugins.netbeans.org/plugin/56795/python4netbeans802). -# Unpack the content (.nbm files) of the zip file to the desired location. --# In NetBeans go to Tools->Plugins->Download->Add Plugins, then choose extracted .nbm files. +-# In NetBeans go to Tools->Plugins. In Download tab, click on Add Plugins, then choose extracted .nbm files. -# Setup Jython path from Tools->Python Platform, click on new, then choose Jython.exe (usually in C:/Program files/Jython2.7/bin/) To install IntelliJ IDEA + Python plug-in: From 21817637d7087dca35f213c97a910d5447d37405 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Tue, 13 Oct 2015 16:55:40 -0400 Subject: [PATCH 03/14] Added class to encrypt and decrypt input string --- .../sleuthkit/autopsy/core/TextConverter.java | 86 +++++++++++++++++++ .../autopsy/core/UserPreferences.java | 37 +++++--- 2 files changed, 112 insertions(+), 11 deletions(-) create mode 100644 Core/src/org/sleuthkit/autopsy/core/TextConverter.java diff --git a/Core/src/org/sleuthkit/autopsy/core/TextConverter.java b/Core/src/org/sleuthkit/autopsy/core/TextConverter.java new file mode 100644 index 0000000000..864362034f --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/core/TextConverter.java @@ -0,0 +1,86 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2014 Basis Technology Corp. + * Contact: carrier sleuthkit 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 org.sleuthkit.autopsy.core; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.security.GeneralSecurityException; +import java.util.Base64; + +import javax.crypto.Cipher; +import javax.crypto.SecretKey; +import javax.crypto.SecretKeyFactory; +import javax.crypto.spec.PBEKeySpec; +import javax.crypto.spec.PBEParameterSpec; +import javax.xml.bind.DatatypeConverter; + +/** + * Provides ability to convert text to hex text. + */ +class TextConverter { + + private static final char[] LOOK_AWAY = "dontlookhere".toCharArray(); + private static final byte[] SALT = { + (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12, + (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12, + }; + + /*static void main(String[] args) throws Exception { + String originalPassword = "secret"; + System.out.println("Original password: " + originalPassword); + String encryptedPassword = convert(originalPassword); + System.out.println("Encrypted password: " + encryptedPassword); + String decryptedPassword = deconvert(encryptedPassword); + System.out.println("Decrypted password: " + decryptedPassword); + }*/ + + static String convert(String property) throws GeneralSecurityException, UnsupportedEncodingException { + SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); + SecretKey key = keyFactory.generateSecret(new PBEKeySpec(LOOK_AWAY)); + Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); + pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(SALT, 20)); + //return toHexString(pbeCipher.doFinal(property.getBytes("UTF-8"))); + return base64Encode(pbeCipher.doFinal(property.getBytes("UTF-8"))); + } + + private static String base64Encode(byte[] bytes) { + return Base64.getEncoder().encodeToString(bytes); + } + + private static String toHexString(byte[] array) { + return DatatypeConverter.printHexBinary(array); + } + + private static byte[] toByteArray(String s) { + return DatatypeConverter.parseHexBinary(s); + } + + static String deconvert(String property) throws GeneralSecurityException, IOException { + SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); + SecretKey key = keyFactory.generateSecret(new PBEKeySpec(LOOK_AWAY)); + Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); + pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(SALT, 20)); + //return new String(pbeCipher.doFinal(toByteArray(property)), "UTF-8"); + return new String(pbeCipher.doFinal(base64Decode(property)), "UTF-8"); + } + + private static byte[] base64Decode(String property) { + return Base64.getDecoder().decode(property); + } +} diff --git a/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java b/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java index 2f1c6a5ae5..407ca27ce0 100755 --- a/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java +++ b/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java @@ -18,10 +18,14 @@ */ package org.sleuthkit.autopsy.core; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.security.GeneralSecurityException; import java.util.prefs.BackingStoreException; import org.sleuthkit.autopsy.events.MessageServiceConnectionInfo; import java.util.prefs.PreferenceChangeListener; import java.util.prefs.Preferences; +import org.openide.util.Exceptions; import org.openide.util.NbPreferences; import org.sleuthkit.datamodel.CaseDbConnectionInfo; import org.sleuthkit.datamodel.TskData.DbType; @@ -129,25 +133,36 @@ public final class UserPreferences { } public static CaseDbConnectionInfo getDatabaseConnectionInfo() { - DbType dbType; try { - dbType = DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE, "SQLITE")); - } catch (Exception ex) { - dbType = DbType.SQLITE; + DbType dbType; + try { + dbType = DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE, "SQLITE")); + } catch (Exception ex) { + dbType = DbType.SQLITE; + } + String text = TextConverter.deconvert(preferences.get(EXTERNAL_DATABASE_PASSWORD, "")); + return new CaseDbConnectionInfo( + preferences.get(EXTERNAL_DATABASE_HOSTNAME_OR_IP, ""), + preferences.get(EXTERNAL_DATABASE_PORTNUMBER, "5432"), + preferences.get(EXTERNAL_DATABASE_USER, ""), + TextConverter.deconvert(preferences.get(EXTERNAL_DATABASE_PASSWORD, "")), + dbType); + } catch (GeneralSecurityException | IOException ex) { + Exceptions.printStackTrace(ex); } - return new CaseDbConnectionInfo( - preferences.get(EXTERNAL_DATABASE_HOSTNAME_OR_IP, ""), - preferences.get(EXTERNAL_DATABASE_PORTNUMBER, "5432"), - preferences.get(EXTERNAL_DATABASE_USER, ""), - preferences.get(EXTERNAL_DATABASE_PASSWORD, ""), - dbType); + return null; } public static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo) { preferences.put(EXTERNAL_DATABASE_HOSTNAME_OR_IP, connectionInfo.getHost()); preferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort()); preferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName()); - preferences.put(EXTERNAL_DATABASE_PASSWORD, connectionInfo.getPassword()); + try { + String password = TextConverter.convert(connectionInfo.getPassword()); + preferences.put(EXTERNAL_DATABASE_PASSWORD, TextConverter.convert(connectionInfo.getPassword())); + } catch (GeneralSecurityException | UnsupportedEncodingException ex) { + Exceptions.printStackTrace(ex); + } preferences.put(EXTERNAL_DATABASE_TYPE, connectionInfo.getDbType().toString()); } From 235814f7417c1de2da2cdbed421d4b24c442a453 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 14 Oct 2015 14:43:20 -0400 Subject: [PATCH 04/14] First cut at text to hex text conversion --- .../sleuthkit/autopsy/core/TextConverter.java | 38 ++++++++----------- .../autopsy/core/UserPreferences.java | 8 ++-- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/core/TextConverter.java b/Core/src/org/sleuthkit/autopsy/core/TextConverter.java index 864362034f..93b4288b06 100644 --- a/Core/src/org/sleuthkit/autopsy/core/TextConverter.java +++ b/Core/src/org/sleuthkit/autopsy/core/TextConverter.java @@ -28,7 +28,6 @@ import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.PBEParameterSpec; -import javax.xml.bind.DatatypeConverter; /** * Provides ability to convert text to hex text. @@ -41,21 +40,18 @@ class TextConverter { (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12, }; - /*static void main(String[] args) throws Exception { - String originalPassword = "secret"; - System.out.println("Original password: " + originalPassword); - String encryptedPassword = convert(originalPassword); - System.out.println("Encrypted password: " + encryptedPassword); - String decryptedPassword = deconvert(encryptedPassword); - System.out.println("Decrypted password: " + decryptedPassword); - }*/ - - static String convert(String property) throws GeneralSecurityException, UnsupportedEncodingException { + /** + * Convert text to hex text. + * @param property Input text string. + * @return Converted hex string. + * @throws GeneralSecurityException + * @throws UnsupportedEncodingException + */ + static String convertTextToHexText(String property) throws GeneralSecurityException, UnsupportedEncodingException { SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); SecretKey key = keyFactory.generateSecret(new PBEKeySpec(LOOK_AWAY)); Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(SALT, 20)); - //return toHexString(pbeCipher.doFinal(property.getBytes("UTF-8"))); return base64Encode(pbeCipher.doFinal(property.getBytes("UTF-8"))); } @@ -63,20 +59,18 @@ class TextConverter { return Base64.getEncoder().encodeToString(bytes); } - private static String toHexString(byte[] array) { - return DatatypeConverter.printHexBinary(array); - } - - private static byte[] toByteArray(String s) { - return DatatypeConverter.parseHexBinary(s); - } - - static String deconvert(String property) throws GeneralSecurityException, IOException { + /** + * Convert hex text back to text. + * @param property Input hex text string. + * @return Converted text string. + * @throws GeneralSecurityException + * @throws IOException + */ + static String convertHexTextToText(String property) throws GeneralSecurityException, IOException { SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); SecretKey key = keyFactory.generateSecret(new PBEKeySpec(LOOK_AWAY)); Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(SALT, 20)); - //return new String(pbeCipher.doFinal(toByteArray(property)), "UTF-8"); return new String(pbeCipher.doFinal(base64Decode(property)), "UTF-8"); } diff --git a/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java b/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java index 407ca27ce0..ba0e9fe2f0 100755 --- a/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java +++ b/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java @@ -140,12 +140,12 @@ public final class UserPreferences { } catch (Exception ex) { dbType = DbType.SQLITE; } - String text = TextConverter.deconvert(preferences.get(EXTERNAL_DATABASE_PASSWORD, "")); + String text = TextConverter.convertHexTextToText(preferences.get(EXTERNAL_DATABASE_PASSWORD, "")); return new CaseDbConnectionInfo( preferences.get(EXTERNAL_DATABASE_HOSTNAME_OR_IP, ""), preferences.get(EXTERNAL_DATABASE_PORTNUMBER, "5432"), preferences.get(EXTERNAL_DATABASE_USER, ""), - TextConverter.deconvert(preferences.get(EXTERNAL_DATABASE_PASSWORD, "")), + TextConverter.convertHexTextToText(preferences.get(EXTERNAL_DATABASE_PASSWORD, "")), dbType); } catch (GeneralSecurityException | IOException ex) { Exceptions.printStackTrace(ex); @@ -158,8 +158,8 @@ public final class UserPreferences { preferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort()); preferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName()); try { - String password = TextConverter.convert(connectionInfo.getPassword()); - preferences.put(EXTERNAL_DATABASE_PASSWORD, TextConverter.convert(connectionInfo.getPassword())); + String password = TextConverter.convertTextToHexText(connectionInfo.getPassword()); + preferences.put(EXTERNAL_DATABASE_PASSWORD, TextConverter.convertTextToHexText(connectionInfo.getPassword())); } catch (GeneralSecurityException | UnsupportedEncodingException ex) { Exceptions.printStackTrace(ex); } From 95ef28b8a44d597d6c52bd2cd8b8553ed46b72c2 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 14 Oct 2015 14:52:13 -0400 Subject: [PATCH 05/14] Clean up user preferences, propagate exceptions --- .../autopsy/core/UserPreferences.java | 64 ++++++++++--------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java b/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java index ba0e9fe2f0..7acbfd03f3 100755 --- a/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java +++ b/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java @@ -25,7 +25,6 @@ import java.util.prefs.BackingStoreException; import org.sleuthkit.autopsy.events.MessageServiceConnectionInfo; import java.util.prefs.PreferenceChangeListener; import java.util.prefs.Preferences; -import org.openide.util.Exceptions; import org.openide.util.NbPreferences; import org.sleuthkit.datamodel.CaseDbConnectionInfo; import org.sleuthkit.datamodel.TskData.DbType; @@ -132,37 +131,40 @@ public final class UserPreferences { preferences.putInt(NUMBER_OF_FILE_INGEST_THREADS, value); } - public static CaseDbConnectionInfo getDatabaseConnectionInfo() { + /** + * Reads persisted case database connection info. + * @return An object encapsulating the database connection info. + * @throws GeneralSecurityException + * @throws IOException + */ + public static CaseDbConnectionInfo getDatabaseConnectionInfo() throws GeneralSecurityException, IOException { + DbType dbType; try { - DbType dbType; - try { - dbType = DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE, "SQLITE")); - } catch (Exception ex) { - dbType = DbType.SQLITE; - } - String text = TextConverter.convertHexTextToText(preferences.get(EXTERNAL_DATABASE_PASSWORD, "")); - return new CaseDbConnectionInfo( - preferences.get(EXTERNAL_DATABASE_HOSTNAME_OR_IP, ""), - preferences.get(EXTERNAL_DATABASE_PORTNUMBER, "5432"), - preferences.get(EXTERNAL_DATABASE_USER, ""), - TextConverter.convertHexTextToText(preferences.get(EXTERNAL_DATABASE_PASSWORD, "")), - dbType); - } catch (GeneralSecurityException | IOException ex) { - Exceptions.printStackTrace(ex); + dbType = DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE, "SQLITE")); + } catch (Exception ex) { + dbType = DbType.SQLITE; } - return null; + String text = TextConverter.convertHexTextToText(preferences.get(EXTERNAL_DATABASE_PASSWORD, "")); + return new CaseDbConnectionInfo( + preferences.get(EXTERNAL_DATABASE_HOSTNAME_OR_IP, ""), + preferences.get(EXTERNAL_DATABASE_PORTNUMBER, "5432"), + preferences.get(EXTERNAL_DATABASE_USER, ""), + TextConverter.convertHexTextToText(preferences.get(EXTERNAL_DATABASE_PASSWORD, "")), + dbType); } - public static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo) { + /** + * Persists case database connection info. + * @param connectionInfo An object encapsulating the database connection info. + * @throws GeneralSecurityException + * @throws UnsupportedEncodingException + */ + public static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo) throws GeneralSecurityException, UnsupportedEncodingException { preferences.put(EXTERNAL_DATABASE_HOSTNAME_OR_IP, connectionInfo.getHost()); preferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort()); preferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName()); - try { - String password = TextConverter.convertTextToHexText(connectionInfo.getPassword()); - preferences.put(EXTERNAL_DATABASE_PASSWORD, TextConverter.convertTextToHexText(connectionInfo.getPassword())); - } catch (GeneralSecurityException | UnsupportedEncodingException ex) { - Exceptions.printStackTrace(ex); - } + String password = TextConverter.convertTextToHexText(connectionInfo.getPassword()); + preferences.put(EXTERNAL_DATABASE_PASSWORD, TextConverter.convertTextToHexText(connectionInfo.getPassword())); preferences.put(EXTERNAL_DATABASE_TYPE, connectionInfo.getDbType().toString()); } @@ -194,10 +196,12 @@ public final class UserPreferences { * Persists message service connection info. * * @param info An object encapsulating the message service info. + * @throws java.security.GeneralSecurityException + * @throws java.io.UnsupportedEncodingException */ - public static void setMessageServiceConnectionInfo(MessageServiceConnectionInfo info) { + public static void setMessageServiceConnectionInfo(MessageServiceConnectionInfo info) throws GeneralSecurityException, UnsupportedEncodingException { preferences.put(MESSAGE_SERVICE_USER, info.getUserName()); - preferences.put(MESSAGE_SERVICE_PASSWORD, info.getPassword()); + preferences.put(MESSAGE_SERVICE_PASSWORD, TextConverter.convertTextToHexText(info.getPassword())); preferences.put(MESSAGE_SERVICE_HOST, info.getHost()); preferences.put(MESSAGE_SERVICE_PORT, info.getPort()); } @@ -206,10 +210,12 @@ public final class UserPreferences { * Reads persisted message service connection info. * * @return An object encapsulating the message service info. + * @throws java.security.GeneralSecurityException + * @throws java.io.IOException */ - public static MessageServiceConnectionInfo getMessageServiceConnectionInfo() { + public static MessageServiceConnectionInfo getMessageServiceConnectionInfo() throws GeneralSecurityException, IOException { return new MessageServiceConnectionInfo(preferences.get(MESSAGE_SERVICE_USER, ""), - preferences.get(MESSAGE_SERVICE_PASSWORD, ""), + TextConverter.convertHexTextToText(preferences.get(MESSAGE_SERVICE_PASSWORD, "")), preferences.get(MESSAGE_SERVICE_HOST, ""), preferences.get(MESSAGE_SERVICE_PORT, "61616")); } From 09c0f5dfc236be3ae1e88e67833073943fae1991 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 14 Oct 2015 15:47:27 -0400 Subject: [PATCH 06/14] Exception handling --- .../autopsy/casemodule/Bundle.properties | 1 + .../sleuthkit/autopsy/casemodule/Case.java | 13 +++++- .../sleuthkit/autopsy/core/Bundle.properties | 4 +- .../autopsy/core/ServicesMonitor.java | 4 ++ .../sleuthkit/autopsy/core/TextConverter.java | 43 +++++++++++------- .../autopsy/core/UserPreferences.java | 25 +++++------ .../MultiUserSettingsPanel.java | 44 ++++++++++++++----- .../autopsy/events/AutopsyEventPublisher.java | 6 +++ 8 files changed, 96 insertions(+), 44 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties index cfcb914c4d..c9a86ea72f 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Bundle.properties @@ -108,6 +108,7 @@ AddImageWizardIterator.stepXofN=Step {0} of {1} AddLocalFilesTask.localFileAdd.progress.text=Adding\: {0}/{1} Case.getCurCase.exception.noneOpen=Cannot get the current case; there is no case open\! Case.create.exception.msg=Error creating a case\: {0} in dir {1} +Case.databaseConnectionInfo.error.msg=Error accessing case database connection info Case.open.exception.blankCase.msg=Case name is blank. Case.open.msgDlg.updated.msg=Updated case database schema.\nA backup copy of the database with the following path has been made\:\n {0} Case.open.msgDlg.updated.title=Case Database Schema Update diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index a4e477fada..c136022021 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -28,6 +28,7 @@ import java.io.IOException; import java.nio.file.InvalidPathException; import java.nio.file.Path; import java.nio.file.Paths; +import java.security.GeneralSecurityException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; @@ -455,6 +456,10 @@ public class Case implements SleuthkitCase.ErrorObserver { logger.log(Level.SEVERE, "Error creating a case: " + caseName + " in dir " + caseDir, ex); //NON-NLS throw new CaseActionException( NbBundle.getMessage(Case.class, "Case.create.exception.msg", caseName, caseDir), ex); + } catch (IllegalArgumentException ex) { + logger.log(Level.SEVERE, "Error accessing case database connection info", ex); //NON-NLS + throw new CaseActionException( + NbBundle.getMessage(Case.class, "Case.databaseConnectionInfo.error.msg"), ex); } /** @@ -566,7 +571,13 @@ public class Case implements SleuthkitCase.ErrorObserver { if (!UserPreferences.getIsMultiUserModeEnabled()) { throw new CaseActionException(NbBundle.getMessage(Case.class, "Case.open.exception.multiUserCaseNotEnabled")); } - db = SleuthkitCase.openCase(metadata.getCaseDatabaseName(), UserPreferences.getDatabaseConnectionInfo(), caseDir); + try { + db = SleuthkitCase.openCase(metadata.getCaseDatabaseName(), UserPreferences.getDatabaseConnectionInfo(), caseDir); + } catch (IllegalArgumentException ex) { + logger.log(Level.SEVERE, "Error accessing case database connection info", ex); //NON-NLS + throw new CaseActionException( + NbBundle.getMessage(Case.class, "Case.databaseConnectionInfo.error.msg"), ex); + } } /** diff --git a/Core/src/org/sleuthkit/autopsy/core/Bundle.properties b/Core/src/org/sleuthkit/autopsy/core/Bundle.properties index 4fa84d55dc..65793ee266 100644 --- a/Core/src/org/sleuthkit/autopsy/core/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/core/Bundle.properties @@ -20,4 +20,6 @@ ServicesMonitor.statusChange.notify.title=Service Status Update ServicesMonitor.statusChange.notify.msg=Status for {0} is {1} ServicesMonitor.nullServiceName.excepton.txt=Requested service name is null ServicesMonitor.nullStatusOrDetails.excepton.txt=Status or details string is null -ServicesMonitor.unknownServiceName.excepton.txt=Requested service name {0} is unknown \ No newline at end of file +ServicesMonitor.unknownServiceName.excepton.txt=Requested service name {0} is unknown +TextConverter.convert.exception.txt=Unable to convert text {0} to hex text +TextConverter.convertFromHex.exception.txt=Unable to convert hex text to text \ No newline at end of file diff --git a/Core/src/org/sleuthkit/autopsy/core/ServicesMonitor.java b/Core/src/org/sleuthkit/autopsy/core/ServicesMonitor.java index b7144c98fc..ddad30e08b 100644 --- a/Core/src/org/sleuthkit/autopsy/core/ServicesMonitor.java +++ b/Core/src/org/sleuthkit/autopsy/core/ServicesMonitor.java @@ -266,6 +266,8 @@ public class ServicesMonitor { } else { setServiceStatus(Service.REMOTE_CASE_DATABASE.toString(), ServiceStatus.DOWN.toString(), ""); } + } catch (IllegalArgumentException ex) { + logger.log(Level.SEVERE, "Error accessing case database connection info", ex); //NON-NLS } catch (Exception ex) { logger.log(Level.SEVERE, "Exception while checking database connection status", ex); //NON-NLS } @@ -297,6 +299,8 @@ public class ServicesMonitor { } else { setServiceStatus(Service.MESSAGING.toString(), ServiceStatus.DOWN.toString(), ""); } + } catch (IllegalArgumentException ex) { + logger.log(Level.SEVERE, "Error accessing messaging service connection info", ex); //NON-NLS } catch (Exception ex) { logger.log(Level.SEVERE, "Exception while checking messaging server connection status", ex); //NON-NLS } diff --git a/Core/src/org/sleuthkit/autopsy/core/TextConverter.java b/Core/src/org/sleuthkit/autopsy/core/TextConverter.java index 93b4288b06..bb9030851e 100644 --- a/Core/src/org/sleuthkit/autopsy/core/TextConverter.java +++ b/Core/src/org/sleuthkit/autopsy/core/TextConverter.java @@ -28,13 +28,14 @@ import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.PBEParameterSpec; +import org.openide.util.NbBundle; /** * Provides ability to convert text to hex text. */ class TextConverter { - private static final char[] LOOK_AWAY = "dontlookhere".toCharArray(); + private static final char[] TMP = "dontlookhere".toCharArray(); private static final byte[] SALT = { (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12, (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12, @@ -44,15 +45,19 @@ class TextConverter { * Convert text to hex text. * @param property Input text string. * @return Converted hex string. - * @throws GeneralSecurityException - * @throws UnsupportedEncodingException + * @throws IllegalArgumentException */ - static String convertTextToHexText(String property) throws GeneralSecurityException, UnsupportedEncodingException { - SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); - SecretKey key = keyFactory.generateSecret(new PBEKeySpec(LOOK_AWAY)); - Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); - pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(SALT, 20)); - return base64Encode(pbeCipher.doFinal(property.getBytes("UTF-8"))); + static String convertTextToHexText(String property) throws IllegalArgumentException { + try { + SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); + SecretKey key = keyFactory.generateSecret(new PBEKeySpec(TMP)); + Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); + pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(SALT, 20)); + return base64Encode(pbeCipher.doFinal(property.getBytes("UTF-8"))); + } catch (Exception ex) { + throw new IllegalArgumentException( + NbBundle.getMessage(TextConverter.class, "TextConverter.convert.exception.txt")); + } } private static String base64Encode(byte[] bytes) { @@ -63,15 +68,19 @@ class TextConverter { * Convert hex text back to text. * @param property Input hex text string. * @return Converted text string. - * @throws GeneralSecurityException - * @throws IOException + * @throws IllegalArgumentException */ - static String convertHexTextToText(String property) throws GeneralSecurityException, IOException { - SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); - SecretKey key = keyFactory.generateSecret(new PBEKeySpec(LOOK_AWAY)); - Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); - pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(SALT, 20)); - return new String(pbeCipher.doFinal(base64Decode(property)), "UTF-8"); + static String convertHexTextToText(String property) throws IllegalArgumentException { + try { + SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); + SecretKey key = keyFactory.generateSecret(new PBEKeySpec(TMP)); + Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); + pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(SALT, 20)); + return new String(pbeCipher.doFinal(base64Decode(property)), "UTF-8"); + } catch (Exception ex) { + throw new IllegalArgumentException( + NbBundle.getMessage(TextConverter.class, "TextConverter.convertFromHex.exception.txt")); + } } private static byte[] base64Decode(String property) { diff --git a/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java b/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java index 7acbfd03f3..8f8eb9a9d2 100755 --- a/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java +++ b/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java @@ -134,10 +134,9 @@ public final class UserPreferences { /** * Reads persisted case database connection info. * @return An object encapsulating the database connection info. - * @throws GeneralSecurityException - * @throws IOException + * @throws IllegalArgumentException */ - public static CaseDbConnectionInfo getDatabaseConnectionInfo() throws GeneralSecurityException, IOException { + public static CaseDbConnectionInfo getDatabaseConnectionInfo() throws IllegalArgumentException { DbType dbType; try { dbType = DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE, "SQLITE")); @@ -155,11 +154,13 @@ public final class UserPreferences { /** * Persists case database connection info. - * @param connectionInfo An object encapsulating the database connection info. - * @throws GeneralSecurityException - * @throws UnsupportedEncodingException + * + * @param connectionInfo An object encapsulating the database connection + * info. + * + * @throws IllegalArgumentException */ - public static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo) throws GeneralSecurityException, UnsupportedEncodingException { + public static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo) throws IllegalArgumentException { preferences.put(EXTERNAL_DATABASE_HOSTNAME_OR_IP, connectionInfo.getHost()); preferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort()); preferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName()); @@ -196,10 +197,9 @@ public final class UserPreferences { * Persists message service connection info. * * @param info An object encapsulating the message service info. - * @throws java.security.GeneralSecurityException - * @throws java.io.UnsupportedEncodingException + * @throws IllegalArgumentException */ - public static void setMessageServiceConnectionInfo(MessageServiceConnectionInfo info) throws GeneralSecurityException, UnsupportedEncodingException { + public static void setMessageServiceConnectionInfo(MessageServiceConnectionInfo info) throws IllegalArgumentException { preferences.put(MESSAGE_SERVICE_USER, info.getUserName()); preferences.put(MESSAGE_SERVICE_PASSWORD, TextConverter.convertTextToHexText(info.getPassword())); preferences.put(MESSAGE_SERVICE_HOST, info.getHost()); @@ -210,10 +210,9 @@ public final class UserPreferences { * Reads persisted message service connection info. * * @return An object encapsulating the message service info. - * @throws java.security.GeneralSecurityException - * @throws java.io.IOException + * @throws IllegalArgumentException */ - public static MessageServiceConnectionInfo getMessageServiceConnectionInfo() throws GeneralSecurityException, IOException { + public static MessageServiceConnectionInfo getMessageServiceConnectionInfo() throws IllegalArgumentException { return new MessageServiceConnectionInfo(preferences.get(MESSAGE_SERVICE_USER, ""), TextConverter.convertHexTextToText(preferences.get(MESSAGE_SERVICE_PASSWORD, "")), preferences.get(MESSAGE_SERVICE_HOST, ""), diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java index 807390cd25..0c115b83e6 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java @@ -18,8 +18,12 @@ import org.sleuthkit.autopsy.core.UserPreferences; import org.sleuthkit.autopsy.events.MessageServiceConnectionInfo; import org.sleuthkit.autopsy.coreutils.Logger; import java.awt.Cursor; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.security.GeneralSecurityException; import java.util.logging.Level; import javax.swing.ImageIcon; +import org.openide.util.Exceptions; import org.openide.util.ImageUtilities; import org.openide.util.Lookup; import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService; @@ -484,17 +488,25 @@ public final class MultiUserSettingsPanel extends javax.swing.JPanel { }//GEN-LAST:event_bnTestSolrActionPerformed void load() { - CaseDbConnectionInfo dbInfo = UserPreferences.getDatabaseConnectionInfo(); - tbDbHostname.setText(dbInfo.getHost().trim()); - tbDbPort.setText(dbInfo.getPort().trim()); - tbDbUsername.setText(dbInfo.getUserName().trim()); - tbDbPassword.setText(dbInfo.getPassword()); + try { + CaseDbConnectionInfo dbInfo = UserPreferences.getDatabaseConnectionInfo(); + tbDbHostname.setText(dbInfo.getHost().trim()); + tbDbPort.setText(dbInfo.getPort().trim()); + tbDbUsername.setText(dbInfo.getUserName().trim()); + tbDbPassword.setText(dbInfo.getPassword()); + } catch (IllegalArgumentException ex) { + logger.log(Level.SEVERE, "Error accessing case database connection info", ex); //NON-NLS + } - MessageServiceConnectionInfo msgServiceInfo = UserPreferences.getMessageServiceConnectionInfo(); - tbMsgHostname.setText(msgServiceInfo.getHost().trim()); - tbMsgPort.setText(msgServiceInfo.getPort().trim()); - tbMsgUsername.setText(msgServiceInfo.getUserName().trim()); - tbMsgPassword.setText(msgServiceInfo.getPassword()); + try { + MessageServiceConnectionInfo msgServiceInfo = UserPreferences.getMessageServiceConnectionInfo(); + tbMsgHostname.setText(msgServiceInfo.getHost().trim()); + tbMsgPort.setText(msgServiceInfo.getPort().trim()); + tbMsgUsername.setText(msgServiceInfo.getUserName().trim()); + tbMsgPassword.setText(msgServiceInfo.getPassword()); + } catch (IllegalArgumentException ex) { + logger.log(Level.SEVERE, "Error accessing case database connection info", ex); //NON-NLS + } String indexingServerHost = UserPreferences.getIndexingServerHost().trim(); if (!indexingServerHost.isEmpty()) { @@ -570,14 +582,22 @@ public final class MultiUserSettingsPanel extends javax.swing.JPanel { new String(tbDbPassword.getPassword()), dbType); - UserPreferences.setDatabaseConnectionInfo(info); + try { + UserPreferences.setDatabaseConnectionInfo(info); + } catch (IllegalArgumentException ex) { + logger.log(Level.SEVERE, "Error accessing case database connection info", ex); //NON-NLS + } MessageServiceConnectionInfo msgServiceInfo = new MessageServiceConnectionInfo( tbMsgUsername.getText().trim(), new String(tbMsgPassword.getPassword()), tbMsgHostname.getText().trim(), tbMsgPort.getText().trim()); - UserPreferences.setMessageServiceConnectionInfo(msgServiceInfo); + try { + UserPreferences.setMessageServiceConnectionInfo(msgServiceInfo); + } catch (IllegalArgumentException ex) { + logger.log(Level.SEVERE, "Error accessing messaging service connection info", ex); //NON-NLS + } UserPreferences.setIndexingServerHost(tbSolrHostname.getText().trim()); UserPreferences.setIndexingServerPort(Integer.parseInt(tbSolrPort.getText().trim())); diff --git a/Core/src/org/sleuthkit/autopsy/events/AutopsyEventPublisher.java b/Core/src/org/sleuthkit/autopsy/events/AutopsyEventPublisher.java index a23a203ee6..ad22cc8b2f 100644 --- a/Core/src/org/sleuthkit/autopsy/events/AutopsyEventPublisher.java +++ b/Core/src/org/sleuthkit/autopsy/events/AutopsyEventPublisher.java @@ -19,7 +19,9 @@ package org.sleuthkit.autopsy.events; import java.beans.PropertyChangeListener; +import java.io.IOException; import java.net.URISyntaxException; +import java.security.GeneralSecurityException; import java.util.Set; import java.util.logging.Level; import javax.jms.JMSException; @@ -70,6 +72,10 @@ public final class AutopsyEventPublisher { String message = "Failed to open remote event channel"; //NON-NLS logger.log(Level.SEVERE, message, ex); throw new AutopsyEventException(message, ex); + } catch (IllegalArgumentException ex) { + String message = "Error accessing messaging service connection info"; //NON-NLS + logger.log(Level.SEVERE, message, ex); + throw new AutopsyEventException(message, ex); } } From 0838207a9ce4a906974e0bbfe394a8d89d1d30ed Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 14 Oct 2015 15:53:12 -0400 Subject: [PATCH 07/14] Added logs and cleaned up imports --- Core/src/org/sleuthkit/autopsy/casemodule/Case.java | 1 - Core/src/org/sleuthkit/autopsy/core/TextConverter.java | 9 +++++---- Core/src/org/sleuthkit/autopsy/core/UserPreferences.java | 3 --- .../autopsy/corecomponents/MultiUserSettingsPanel.java | 4 ---- .../sleuthkit/autopsy/events/AutopsyEventPublisher.java | 2 -- 5 files changed, 5 insertions(+), 14 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index c136022021..f25c6c64e1 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -28,7 +28,6 @@ import java.io.IOException; import java.nio.file.InvalidPathException; import java.nio.file.Path; import java.nio.file.Paths; -import java.security.GeneralSecurityException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; diff --git a/Core/src/org/sleuthkit/autopsy/core/TextConverter.java b/Core/src/org/sleuthkit/autopsy/core/TextConverter.java index bb9030851e..06bd418f70 100644 --- a/Core/src/org/sleuthkit/autopsy/core/TextConverter.java +++ b/Core/src/org/sleuthkit/autopsy/core/TextConverter.java @@ -18,23 +18,22 @@ */ package org.sleuthkit.autopsy.core; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.security.GeneralSecurityException; import java.util.Base64; - +import java.util.logging.Level; import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.PBEParameterSpec; import org.openide.util.NbBundle; +import org.sleuthkit.autopsy.coreutils.Logger; /** * Provides ability to convert text to hex text. */ class TextConverter { + private static final Logger logger = Logger.getLogger(TextConverter.class.getName()); private static final char[] TMP = "dontlookhere".toCharArray(); private static final byte[] SALT = { (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12, @@ -55,6 +54,7 @@ class TextConverter { pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(SALT, 20)); return base64Encode(pbeCipher.doFinal(property.getBytes("UTF-8"))); } catch (Exception ex) { + logger.log(Level.SEVERE, "Error converting text to hex text", ex); //NON-NLS throw new IllegalArgumentException( NbBundle.getMessage(TextConverter.class, "TextConverter.convert.exception.txt")); } @@ -78,6 +78,7 @@ class TextConverter { pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(SALT, 20)); return new String(pbeCipher.doFinal(base64Decode(property)), "UTF-8"); } catch (Exception ex) { + logger.log(Level.SEVERE, "Error converting hex text to text", ex); //NON-NLS throw new IllegalArgumentException( NbBundle.getMessage(TextConverter.class, "TextConverter.convertFromHex.exception.txt")); } diff --git a/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java b/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java index 8f8eb9a9d2..9acae39438 100755 --- a/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java +++ b/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java @@ -18,9 +18,6 @@ */ package org.sleuthkit.autopsy.core; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.security.GeneralSecurityException; import java.util.prefs.BackingStoreException; import org.sleuthkit.autopsy.events.MessageServiceConnectionInfo; import java.util.prefs.PreferenceChangeListener; diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java index 0c115b83e6..b692d53fa8 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java @@ -18,12 +18,8 @@ import org.sleuthkit.autopsy.core.UserPreferences; import org.sleuthkit.autopsy.events.MessageServiceConnectionInfo; import org.sleuthkit.autopsy.coreutils.Logger; import java.awt.Cursor; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.security.GeneralSecurityException; import java.util.logging.Level; import javax.swing.ImageIcon; -import org.openide.util.Exceptions; import org.openide.util.ImageUtilities; import org.openide.util.Lookup; import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService; diff --git a/Core/src/org/sleuthkit/autopsy/events/AutopsyEventPublisher.java b/Core/src/org/sleuthkit/autopsy/events/AutopsyEventPublisher.java index ad22cc8b2f..80c352e611 100644 --- a/Core/src/org/sleuthkit/autopsy/events/AutopsyEventPublisher.java +++ b/Core/src/org/sleuthkit/autopsy/events/AutopsyEventPublisher.java @@ -19,9 +19,7 @@ package org.sleuthkit.autopsy.events; import java.beans.PropertyChangeListener; -import java.io.IOException; import java.net.URISyntaxException; -import java.security.GeneralSecurityException; import java.util.Set; import java.util.logging.Level; import javax.jms.JMSException; From d05ccfc3345336e64b4b9a6501c9901f96de23b2 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Wed, 14 Oct 2015 16:05:03 -0400 Subject: [PATCH 08/14] Cleanup --- Core/src/org/sleuthkit/autopsy/core/UserPreferences.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java b/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java index 9acae39438..bfdb915f79 100755 --- a/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java +++ b/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java @@ -140,7 +140,6 @@ public final class UserPreferences { } catch (Exception ex) { dbType = DbType.SQLITE; } - String text = TextConverter.convertHexTextToText(preferences.get(EXTERNAL_DATABASE_PASSWORD, "")); return new CaseDbConnectionInfo( preferences.get(EXTERNAL_DATABASE_HOSTNAME_OR_IP, ""), preferences.get(EXTERNAL_DATABASE_PORTNUMBER, "5432"), @@ -161,7 +160,6 @@ public final class UserPreferences { preferences.put(EXTERNAL_DATABASE_HOSTNAME_OR_IP, connectionInfo.getHost()); preferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort()); preferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName()); - String password = TextConverter.convertTextToHexText(connectionInfo.getPassword()); preferences.put(EXTERNAL_DATABASE_PASSWORD, TextConverter.convertTextToHexText(connectionInfo.getPassword())); preferences.put(EXTERNAL_DATABASE_TYPE, connectionInfo.getDbType().toString()); } From 34e093c2e12ff4009ddd49faf4d2d2581bd0932a Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Thu, 15 Oct 2015 10:57:34 -0400 Subject: [PATCH 09/14] Added new exception class for text converter + code review comments --- .../sleuthkit/autopsy/casemodule/Case.java | 5 +-- .../autopsy/core/ServicesMonitor.java | 4 +-- .../sleuthkit/autopsy/core/TextConverter.java | 21 +++++------ .../autopsy/core/TextConverterException.java | 35 +++++++++++++++++++ .../autopsy/core/UserPreferences.java | 17 +++++---- .../MultiUserSettingsPanel.java | 9 ++--- .../autopsy/events/AutopsyEventPublisher.java | 3 +- 7 files changed, 63 insertions(+), 31 deletions(-) create mode 100644 Core/src/org/sleuthkit/autopsy/core/TextConverterException.java diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index f25c6c64e1..b2c61cee50 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -71,6 +71,7 @@ import org.sleuthkit.autopsy.casemodule.events.BlackBoardArtifactTagDeletedEvent import org.sleuthkit.autopsy.casemodule.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.casemodule.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.core.RuntimeProperties; +import org.sleuthkit.autopsy.core.TextConverterException; import org.sleuthkit.datamodel.BlackboardArtifactTag; import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.ContentTag; @@ -455,7 +456,7 @@ public class Case implements SleuthkitCase.ErrorObserver { logger.log(Level.SEVERE, "Error creating a case: " + caseName + " in dir " + caseDir, ex); //NON-NLS throw new CaseActionException( NbBundle.getMessage(Case.class, "Case.create.exception.msg", caseName, caseDir), ex); - } catch (IllegalArgumentException ex) { + } catch (TextConverterException ex) { logger.log(Level.SEVERE, "Error accessing case database connection info", ex); //NON-NLS throw new CaseActionException( NbBundle.getMessage(Case.class, "Case.databaseConnectionInfo.error.msg"), ex); @@ -572,7 +573,7 @@ public class Case implements SleuthkitCase.ErrorObserver { } try { db = SleuthkitCase.openCase(metadata.getCaseDatabaseName(), UserPreferences.getDatabaseConnectionInfo(), caseDir); - } catch (IllegalArgumentException ex) { + } catch (TextConverterException ex) { logger.log(Level.SEVERE, "Error accessing case database connection info", ex); //NON-NLS throw new CaseActionException( NbBundle.getMessage(Case.class, "Case.databaseConnectionInfo.error.msg"), ex); diff --git a/Core/src/org/sleuthkit/autopsy/core/ServicesMonitor.java b/Core/src/org/sleuthkit/autopsy/core/ServicesMonitor.java index ee71ff5e3e..4b239ab395 100644 --- a/Core/src/org/sleuthkit/autopsy/core/ServicesMonitor.java +++ b/Core/src/org/sleuthkit/autopsy/core/ServicesMonitor.java @@ -242,7 +242,7 @@ public class ServicesMonitor { CaseDbConnectionInfo info; try { info = UserPreferences.getDatabaseConnectionInfo(); - } catch (IllegalArgumentException ex) { + } catch (TextConverterException ex) { logger.log(Level.SEVERE, "Error accessing case database connection info", ex); //NON-NLS setServiceStatus(Service.REMOTE_CASE_DATABASE.toString(), ServiceStatus.DOWN.toString(), "Error accessing case database connection info"); return; @@ -287,7 +287,7 @@ public class ServicesMonitor { MessageServiceConnectionInfo info; try { info = UserPreferences.getMessageServiceConnectionInfo(); - } catch (IllegalArgumentException ex) { + } catch (TextConverterException ex) { logger.log(Level.SEVERE, "Error accessing messaging service connection info", ex); //NON-NLS setServiceStatus(Service.MESSAGING.toString(), ServiceStatus.DOWN.toString(), "Error accessing messaging service connection info"); return; diff --git a/Core/src/org/sleuthkit/autopsy/core/TextConverter.java b/Core/src/org/sleuthkit/autopsy/core/TextConverter.java index 06bd418f70..e84a34a81a 100644 --- a/Core/src/org/sleuthkit/autopsy/core/TextConverter.java +++ b/Core/src/org/sleuthkit/autopsy/core/TextConverter.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2014 Basis Technology Corp. + * Copyright 2015 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,22 +19,19 @@ package org.sleuthkit.autopsy.core; import java.util.Base64; -import java.util.logging.Level; import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.PBEParameterSpec; import org.openide.util.NbBundle; -import org.sleuthkit.autopsy.coreutils.Logger; /** * Provides ability to convert text to hex text. */ class TextConverter { - private static final Logger logger = Logger.getLogger(TextConverter.class.getName()); - private static final char[] TMP = "dontlookhere".toCharArray(); + private static final char[] TMP = "hgleri21auty84fwe".toCharArray(); private static final byte[] SALT = { (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12, (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12, @@ -44,9 +41,9 @@ class TextConverter { * Convert text to hex text. * @param property Input text string. * @return Converted hex string. - * @throws IllegalArgumentException + * @throws org.sleuthkit.autopsy.core.TextConverterException */ - static String convertTextToHexText(String property) throws IllegalArgumentException { + static String convertTextToHexText(String property) throws TextConverterException { try { SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); SecretKey key = keyFactory.generateSecret(new PBEKeySpec(TMP)); @@ -54,8 +51,7 @@ class TextConverter { pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(SALT, 20)); return base64Encode(pbeCipher.doFinal(property.getBytes("UTF-8"))); } catch (Exception ex) { - logger.log(Level.SEVERE, "Error converting text to hex text", ex); //NON-NLS - throw new IllegalArgumentException( + throw new TextConverterException( NbBundle.getMessage(TextConverter.class, "TextConverter.convert.exception.txt")); } } @@ -68,9 +64,9 @@ class TextConverter { * Convert hex text back to text. * @param property Input hex text string. * @return Converted text string. - * @throws IllegalArgumentException + * @throws org.sleuthkit.autopsy.core.TextConverterException */ - static String convertHexTextToText(String property) throws IllegalArgumentException { + static String convertHexTextToText(String property) throws TextConverterException { try { SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); SecretKey key = keyFactory.generateSecret(new PBEKeySpec(TMP)); @@ -78,8 +74,7 @@ class TextConverter { pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(SALT, 20)); return new String(pbeCipher.doFinal(base64Decode(property)), "UTF-8"); } catch (Exception ex) { - logger.log(Level.SEVERE, "Error converting hex text to text", ex); //NON-NLS - throw new IllegalArgumentException( + throw new TextConverterException( NbBundle.getMessage(TextConverter.class, "TextConverter.convertFromHex.exception.txt")); } } diff --git a/Core/src/org/sleuthkit/autopsy/core/TextConverterException.java b/Core/src/org/sleuthkit/autopsy/core/TextConverterException.java new file mode 100644 index 0000000000..8a99a8258e --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/core/TextConverterException.java @@ -0,0 +1,35 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2015 Basis Technology Corp. + * Contact: carrier sleuthkit 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 org.sleuthkit.autopsy.core; + +/** + * Exception thrown when text conversion (such as from text to hex text or vice versa) resulted in + * an error + */ +public class TextConverterException extends Exception { + private static final long serialVersionUID = 1L; + + public TextConverterException(String message) { + super(message); + } + + public TextConverterException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java b/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java index 844573987c..d1f81b044b 100755 --- a/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java +++ b/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java @@ -133,9 +133,9 @@ public final class UserPreferences { /** * Reads persisted case database connection info. * @return An object encapsulating the database connection info. - * @throws IllegalArgumentException + * @throws org.sleuthkit.autopsy.core.TextConverterException */ - public static CaseDbConnectionInfo getDatabaseConnectionInfo() throws IllegalArgumentException { + public static CaseDbConnectionInfo getDatabaseConnectionInfo() throws TextConverterException { DbType dbType; try { dbType = DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE, "POSTGRESQL")); @@ -155,10 +155,9 @@ public final class UserPreferences { * * @param connectionInfo An object encapsulating the database connection * info. - * - * @throws IllegalArgumentException + * @throws org.sleuthkit.autopsy.core.TextConverterException */ - public static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo) throws IllegalArgumentException { + public static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo) throws TextConverterException { preferences.put(EXTERNAL_DATABASE_HOSTNAME_OR_IP, connectionInfo.getHost()); preferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort()); preferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName()); @@ -194,9 +193,9 @@ public final class UserPreferences { * Persists message service connection info. * * @param info An object encapsulating the message service info. - * @throws IllegalArgumentException + * @throws org.sleuthkit.autopsy.core.TextConverterException */ - public static void setMessageServiceConnectionInfo(MessageServiceConnectionInfo info) throws IllegalArgumentException { + public static void setMessageServiceConnectionInfo(MessageServiceConnectionInfo info) throws TextConverterException { preferences.put(MESSAGE_SERVICE_HOST, info.getHost()); preferences.put(MESSAGE_SERVICE_PORT, Integer.toString(info.getPort())); preferences.put(MESSAGE_SERVICE_USER, info.getUserName()); @@ -207,9 +206,9 @@ public final class UserPreferences { * Reads persisted message service connection info. * * @return An object encapsulating the message service info. - * @throws IllegalArgumentException + * @throws org.sleuthkit.autopsy.core.TextConverterException */ - public static MessageServiceConnectionInfo getMessageServiceConnectionInfo() throws IllegalArgumentException { + public static MessageServiceConnectionInfo getMessageServiceConnectionInfo() throws TextConverterException { int port; try { port = Integer.parseInt(preferences.get(MESSAGE_SERVICE_PORT, DEFAULT_PORT_STRING)); diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java index 906496770b..02e55d2d50 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java @@ -22,6 +22,7 @@ import java.util.logging.Level; import javax.swing.ImageIcon; import org.openide.util.ImageUtilities; import org.openide.util.Lookup; +import org.sleuthkit.autopsy.core.TextConverterException; import org.sleuthkit.autopsy.events.MessageServiceException; import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService; import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchServiceException; @@ -566,7 +567,7 @@ public final class MultiUserSettingsPanel extends javax.swing.JPanel { tbDbPort.setText(dbInfo.getPort().trim()); tbDbUsername.setText(dbInfo.getUserName().trim()); tbDbPassword.setText(dbInfo.getPassword()); - } catch (IllegalArgumentException ex) { + } catch (TextConverterException ex) { logger.log(Level.SEVERE, "Error accessing case database connection info", ex); //NON-NLS } @@ -576,7 +577,7 @@ public final class MultiUserSettingsPanel extends javax.swing.JPanel { tbMsgPort.setText(Integer.toString(msgServiceInfo.getPort())); tbMsgUsername.setText(msgServiceInfo.getUserName().trim()); tbMsgPassword.setText(msgServiceInfo.getPassword()); - } catch (IllegalArgumentException ex) { + } catch (TextConverterException ex) { logger.log(Level.SEVERE, "Error accessing case database connection info", ex); //NON-NLS } @@ -656,7 +657,7 @@ public final class MultiUserSettingsPanel extends javax.swing.JPanel { try { UserPreferences.setDatabaseConnectionInfo(info); - } catch (IllegalArgumentException ex) { + } catch (TextConverterException ex) { logger.log(Level.SEVERE, "Error accessing case database connection info", ex); //NON-NLS } @@ -675,7 +676,7 @@ public final class MultiUserSettingsPanel extends javax.swing.JPanel { try { UserPreferences.setMessageServiceConnectionInfo(msgServiceInfo); - } catch (IllegalArgumentException ex) { + } catch (TextConverterException ex) { logger.log(Level.SEVERE, "Error accessing messaging service connection info", ex); //NON-NLS } diff --git a/Core/src/org/sleuthkit/autopsy/events/AutopsyEventPublisher.java b/Core/src/org/sleuthkit/autopsy/events/AutopsyEventPublisher.java index 80c352e611..e71780437a 100644 --- a/Core/src/org/sleuthkit/autopsy/events/AutopsyEventPublisher.java +++ b/Core/src/org/sleuthkit/autopsy/events/AutopsyEventPublisher.java @@ -23,6 +23,7 @@ import java.net.URISyntaxException; import java.util.Set; import java.util.logging.Level; import javax.jms.JMSException; +import org.sleuthkit.autopsy.core.TextConverterException; import org.sleuthkit.autopsy.core.UserPreferences; import org.sleuthkit.autopsy.coreutils.Logger; @@ -70,7 +71,7 @@ public final class AutopsyEventPublisher { String message = "Failed to open remote event channel"; //NON-NLS logger.log(Level.SEVERE, message, ex); throw new AutopsyEventException(message, ex); - } catch (IllegalArgumentException ex) { + } catch (TextConverterException ex) { String message = "Error accessing messaging service connection info"; //NON-NLS logger.log(Level.SEVERE, message, ex); throw new AutopsyEventException(message, ex); From 286d7215ab62cb4cb6e997ee441d778993dd9660 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Thu, 15 Oct 2015 13:36:56 -0400 Subject: [PATCH 10/14] Moved text converter to user preferences, created new exception class --- .../sleuthkit/autopsy/casemodule/Case.java | 6 +- .../autopsy/core/ServicesMonitor.java | 4 +- .../sleuthkit/autopsy/core/TextConverter.java | 85 ------------------ .../autopsy/core/UserPreferences.java | 87 +++++++++++++++++-- ...ion.java => UserPreferencesException.java} | 6 +- .../MultiUserSettingsPanel.java | 10 +-- .../autopsy/events/AutopsyEventPublisher.java | 4 +- 7 files changed, 94 insertions(+), 108 deletions(-) delete mode 100644 Core/src/org/sleuthkit/autopsy/core/TextConverter.java rename Core/src/org/sleuthkit/autopsy/core/{TextConverterException.java => UserPreferencesException.java} (84%) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index b2c61cee50..de01134bcd 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -71,7 +71,7 @@ import org.sleuthkit.autopsy.casemodule.events.BlackBoardArtifactTagDeletedEvent import org.sleuthkit.autopsy.casemodule.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.casemodule.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.core.RuntimeProperties; -import org.sleuthkit.autopsy.core.TextConverterException; +import org.sleuthkit.autopsy.core.UserPreferencesException; import org.sleuthkit.datamodel.BlackboardArtifactTag; import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.ContentTag; @@ -456,7 +456,7 @@ public class Case implements SleuthkitCase.ErrorObserver { logger.log(Level.SEVERE, "Error creating a case: " + caseName + " in dir " + caseDir, ex); //NON-NLS throw new CaseActionException( NbBundle.getMessage(Case.class, "Case.create.exception.msg", caseName, caseDir), ex); - } catch (TextConverterException ex) { + } catch (UserPreferencesException ex) { logger.log(Level.SEVERE, "Error accessing case database connection info", ex); //NON-NLS throw new CaseActionException( NbBundle.getMessage(Case.class, "Case.databaseConnectionInfo.error.msg"), ex); @@ -573,7 +573,7 @@ public class Case implements SleuthkitCase.ErrorObserver { } try { db = SleuthkitCase.openCase(metadata.getCaseDatabaseName(), UserPreferences.getDatabaseConnectionInfo(), caseDir); - } catch (TextConverterException ex) { + } catch (UserPreferencesException ex) { logger.log(Level.SEVERE, "Error accessing case database connection info", ex); //NON-NLS throw new CaseActionException( NbBundle.getMessage(Case.class, "Case.databaseConnectionInfo.error.msg"), ex); diff --git a/Core/src/org/sleuthkit/autopsy/core/ServicesMonitor.java b/Core/src/org/sleuthkit/autopsy/core/ServicesMonitor.java index 4b239ab395..4c1fb92989 100644 --- a/Core/src/org/sleuthkit/autopsy/core/ServicesMonitor.java +++ b/Core/src/org/sleuthkit/autopsy/core/ServicesMonitor.java @@ -242,7 +242,7 @@ public class ServicesMonitor { CaseDbConnectionInfo info; try { info = UserPreferences.getDatabaseConnectionInfo(); - } catch (TextConverterException ex) { + } catch (UserPreferencesException ex) { logger.log(Level.SEVERE, "Error accessing case database connection info", ex); //NON-NLS setServiceStatus(Service.REMOTE_CASE_DATABASE.toString(), ServiceStatus.DOWN.toString(), "Error accessing case database connection info"); return; @@ -287,7 +287,7 @@ public class ServicesMonitor { MessageServiceConnectionInfo info; try { info = UserPreferences.getMessageServiceConnectionInfo(); - } catch (TextConverterException ex) { + } catch (UserPreferencesException ex) { logger.log(Level.SEVERE, "Error accessing messaging service connection info", ex); //NON-NLS setServiceStatus(Service.MESSAGING.toString(), ServiceStatus.DOWN.toString(), "Error accessing messaging service connection info"); return; diff --git a/Core/src/org/sleuthkit/autopsy/core/TextConverter.java b/Core/src/org/sleuthkit/autopsy/core/TextConverter.java deleted file mode 100644 index e84a34a81a..0000000000 --- a/Core/src/org/sleuthkit/autopsy/core/TextConverter.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2015 Basis Technology Corp. - * Contact: carrier sleuthkit 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 org.sleuthkit.autopsy.core; - -import java.util.Base64; -import javax.crypto.Cipher; -import javax.crypto.SecretKey; -import javax.crypto.SecretKeyFactory; -import javax.crypto.spec.PBEKeySpec; -import javax.crypto.spec.PBEParameterSpec; -import org.openide.util.NbBundle; - -/** - * Provides ability to convert text to hex text. - */ -class TextConverter { - - private static final char[] TMP = "hgleri21auty84fwe".toCharArray(); - private static final byte[] SALT = { - (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12, - (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12, - }; - - /** - * Convert text to hex text. - * @param property Input text string. - * @return Converted hex string. - * @throws org.sleuthkit.autopsy.core.TextConverterException - */ - static String convertTextToHexText(String property) throws TextConverterException { - try { - SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); - SecretKey key = keyFactory.generateSecret(new PBEKeySpec(TMP)); - Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); - pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(SALT, 20)); - return base64Encode(pbeCipher.doFinal(property.getBytes("UTF-8"))); - } catch (Exception ex) { - throw new TextConverterException( - NbBundle.getMessage(TextConverter.class, "TextConverter.convert.exception.txt")); - } - } - - private static String base64Encode(byte[] bytes) { - return Base64.getEncoder().encodeToString(bytes); - } - - /** - * Convert hex text back to text. - * @param property Input hex text string. - * @return Converted text string. - * @throws org.sleuthkit.autopsy.core.TextConverterException - */ - static String convertHexTextToText(String property) throws TextConverterException { - try { - SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); - SecretKey key = keyFactory.generateSecret(new PBEKeySpec(TMP)); - Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); - pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(SALT, 20)); - return new String(pbeCipher.doFinal(base64Decode(property)), "UTF-8"); - } catch (Exception ex) { - throw new TextConverterException( - NbBundle.getMessage(TextConverter.class, "TextConverter.convertFromHex.exception.txt")); - } - } - - private static byte[] base64Decode(String property) { - return Base64.getDecoder().decode(property); - } -} diff --git a/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java b/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java index d1f81b044b..a9909593b0 100755 --- a/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java +++ b/Core/src/org/sleuthkit/autopsy/core/UserPreferences.java @@ -18,10 +18,17 @@ */ package org.sleuthkit.autopsy.core; +import java.util.Base64; import java.util.prefs.BackingStoreException; import org.sleuthkit.autopsy.events.MessageServiceConnectionInfo; import java.util.prefs.PreferenceChangeListener; import java.util.prefs.Preferences; +import javax.crypto.Cipher; +import javax.crypto.SecretKey; +import javax.crypto.SecretKeyFactory; +import javax.crypto.spec.PBEKeySpec; +import javax.crypto.spec.PBEParameterSpec; +import org.openide.util.NbBundle; import org.openide.util.NbPreferences; import org.sleuthkit.datamodel.CaseDbConnectionInfo; import org.sleuthkit.datamodel.TskData.DbType; @@ -133,9 +140,9 @@ public final class UserPreferences { /** * Reads persisted case database connection info. * @return An object encapsulating the database connection info. - * @throws org.sleuthkit.autopsy.core.TextConverterException + * @throws org.sleuthkit.autopsy.core.UserPreferencesException */ - public static CaseDbConnectionInfo getDatabaseConnectionInfo() throws TextConverterException { + public static CaseDbConnectionInfo getDatabaseConnectionInfo() throws UserPreferencesException { DbType dbType; try { dbType = DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE, "POSTGRESQL")); @@ -155,9 +162,9 @@ public final class UserPreferences { * * @param connectionInfo An object encapsulating the database connection * info. - * @throws org.sleuthkit.autopsy.core.TextConverterException + * @throws org.sleuthkit.autopsy.core.UserPreferencesException */ - public static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo) throws TextConverterException { + public static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo) throws UserPreferencesException { preferences.put(EXTERNAL_DATABASE_HOSTNAME_OR_IP, connectionInfo.getHost()); preferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort()); preferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName()); @@ -193,9 +200,9 @@ public final class UserPreferences { * Persists message service connection info. * * @param info An object encapsulating the message service info. - * @throws org.sleuthkit.autopsy.core.TextConverterException + * @throws org.sleuthkit.autopsy.core.UserPreferencesException */ - public static void setMessageServiceConnectionInfo(MessageServiceConnectionInfo info) throws TextConverterException { + public static void setMessageServiceConnectionInfo(MessageServiceConnectionInfo info) throws UserPreferencesException { preferences.put(MESSAGE_SERVICE_HOST, info.getHost()); preferences.put(MESSAGE_SERVICE_PORT, Integer.toString(info.getPort())); preferences.put(MESSAGE_SERVICE_USER, info.getUserName()); @@ -206,9 +213,9 @@ public final class UserPreferences { * Reads persisted message service connection info. * * @return An object encapsulating the message service info. - * @throws org.sleuthkit.autopsy.core.TextConverterException + * @throws org.sleuthkit.autopsy.core.UserPreferencesException */ - public static MessageServiceConnectionInfo getMessageServiceConnectionInfo() throws TextConverterException { + public static MessageServiceConnectionInfo getMessageServiceConnectionInfo() throws UserPreferencesException { int port; try { port = Integer.parseInt(preferences.get(MESSAGE_SERVICE_PORT, DEFAULT_PORT_STRING)); @@ -271,4 +278,68 @@ public final class UserPreferences { public static void setIsTimeOutEnabled(boolean enabled) { preferences.putBoolean(PROCESS_TIME_OUT_ENABLED, enabled); } + + + /** + * Provides ability to convert text to hex text. + */ + static final class TextConverter { + + private static final char[] TMP = "hgleri21auty84fwe".toCharArray(); + private static final byte[] SALT = { + (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12, + (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12,}; + + /** + * Convert text to hex text. + * + * @param property Input text string. + * + * @return Converted hex string. + * + * @throws org.sleuthkit.autopsy.core.UserPreferencesException + */ + static String convertTextToHexText(String property) throws UserPreferencesException { + try { + SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); + SecretKey key = keyFactory.generateSecret(new PBEKeySpec(TMP)); + Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); + pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(SALT, 20)); + return base64Encode(pbeCipher.doFinal(property.getBytes("UTF-8"))); + } catch (Exception ex) { + throw new UserPreferencesException( + NbBundle.getMessage(TextConverter.class, "TextConverter.convert.exception.txt")); + } + } + + private static String base64Encode(byte[] bytes) { + return Base64.getEncoder().encodeToString(bytes); + } + + /** + * Convert hex text back to text. + * + * @param property Input hex text string. + * + * @return Converted text string. + * + * @throws org.sleuthkit.autopsy.core.UserPreferencesException + */ + static String convertHexTextToText(String property) throws UserPreferencesException { + try { + SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); + SecretKey key = keyFactory.generateSecret(new PBEKeySpec(TMP)); + Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); + pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(SALT, 20)); + return new String(pbeCipher.doFinal(base64Decode(property)), "UTF-8"); + } catch (Exception ex) { + throw new UserPreferencesException( + NbBundle.getMessage(TextConverter.class, "TextConverter.convertFromHex.exception.txt")); + } + } + + private static byte[] base64Decode(String property) { + return Base64.getDecoder().decode(property); + } + } } diff --git a/Core/src/org/sleuthkit/autopsy/core/TextConverterException.java b/Core/src/org/sleuthkit/autopsy/core/UserPreferencesException.java similarity index 84% rename from Core/src/org/sleuthkit/autopsy/core/TextConverterException.java rename to Core/src/org/sleuthkit/autopsy/core/UserPreferencesException.java index 8a99a8258e..7d9c22fe0b 100644 --- a/Core/src/org/sleuthkit/autopsy/core/TextConverterException.java +++ b/Core/src/org/sleuthkit/autopsy/core/UserPreferencesException.java @@ -22,14 +22,14 @@ package org.sleuthkit.autopsy.core; * Exception thrown when text conversion (such as from text to hex text or vice versa) resulted in * an error */ -public class TextConverterException extends Exception { +public class UserPreferencesException extends Exception { private static final long serialVersionUID = 1L; - public TextConverterException(String message) { + public UserPreferencesException(String message) { super(message); } - public TextConverterException(String message, Throwable cause) { + public UserPreferencesException(String message, Throwable cause) { super(message, cause); } } diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java index 02e55d2d50..b254693300 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java @@ -22,7 +22,7 @@ import java.util.logging.Level; import javax.swing.ImageIcon; import org.openide.util.ImageUtilities; import org.openide.util.Lookup; -import org.sleuthkit.autopsy.core.TextConverterException; +import org.sleuthkit.autopsy.core.UserPreferencesException; import org.sleuthkit.autopsy.events.MessageServiceException; import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService; import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchServiceException; @@ -567,7 +567,7 @@ public final class MultiUserSettingsPanel extends javax.swing.JPanel { tbDbPort.setText(dbInfo.getPort().trim()); tbDbUsername.setText(dbInfo.getUserName().trim()); tbDbPassword.setText(dbInfo.getPassword()); - } catch (TextConverterException ex) { + } catch (UserPreferencesException ex) { logger.log(Level.SEVERE, "Error accessing case database connection info", ex); //NON-NLS } @@ -577,7 +577,7 @@ public final class MultiUserSettingsPanel extends javax.swing.JPanel { tbMsgPort.setText(Integer.toString(msgServiceInfo.getPort())); tbMsgUsername.setText(msgServiceInfo.getUserName().trim()); tbMsgPassword.setText(msgServiceInfo.getPassword()); - } catch (TextConverterException ex) { + } catch (UserPreferencesException ex) { logger.log(Level.SEVERE, "Error accessing case database connection info", ex); //NON-NLS } @@ -657,7 +657,7 @@ public final class MultiUserSettingsPanel extends javax.swing.JPanel { try { UserPreferences.setDatabaseConnectionInfo(info); - } catch (TextConverterException ex) { + } catch (UserPreferencesException ex) { logger.log(Level.SEVERE, "Error accessing case database connection info", ex); //NON-NLS } @@ -676,7 +676,7 @@ public final class MultiUserSettingsPanel extends javax.swing.JPanel { try { UserPreferences.setMessageServiceConnectionInfo(msgServiceInfo); - } catch (TextConverterException ex) { + } catch (UserPreferencesException ex) { logger.log(Level.SEVERE, "Error accessing messaging service connection info", ex); //NON-NLS } diff --git a/Core/src/org/sleuthkit/autopsy/events/AutopsyEventPublisher.java b/Core/src/org/sleuthkit/autopsy/events/AutopsyEventPublisher.java index e71780437a..80c23d924f 100644 --- a/Core/src/org/sleuthkit/autopsy/events/AutopsyEventPublisher.java +++ b/Core/src/org/sleuthkit/autopsy/events/AutopsyEventPublisher.java @@ -23,7 +23,7 @@ import java.net.URISyntaxException; import java.util.Set; import java.util.logging.Level; import javax.jms.JMSException; -import org.sleuthkit.autopsy.core.TextConverterException; +import org.sleuthkit.autopsy.core.UserPreferencesException; import org.sleuthkit.autopsy.core.UserPreferences; import org.sleuthkit.autopsy.coreutils.Logger; @@ -71,7 +71,7 @@ public final class AutopsyEventPublisher { String message = "Failed to open remote event channel"; //NON-NLS logger.log(Level.SEVERE, message, ex); throw new AutopsyEventException(message, ex); - } catch (TextConverterException ex) { + } catch (UserPreferencesException ex) { String message = "Error accessing messaging service connection info"; //NON-NLS logger.log(Level.SEVERE, message, ex); throw new AutopsyEventException(message, ex); From cae1733ae1e530c81d421200ce5a5368a1764586 Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Thu, 15 Oct 2015 13:49:15 -0400 Subject: [PATCH 11/14] code formating --- .../autopsy/corecomponents/MultiUserSettingsPanel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java index b254693300..0a26244edc 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/MultiUserSettingsPanel.java @@ -574,7 +574,7 @@ public final class MultiUserSettingsPanel extends javax.swing.JPanel { try { MessageServiceConnectionInfo msgServiceInfo = UserPreferences.getMessageServiceConnectionInfo(); tbMsgHostname.setText(msgServiceInfo.getHost().trim()); - tbMsgPort.setText(Integer.toString(msgServiceInfo.getPort())); + tbMsgPort.setText(Integer.toString(msgServiceInfo.getPort())); tbMsgUsername.setText(msgServiceInfo.getUserName().trim()); tbMsgPassword.setText(msgServiceInfo.getPassword()); } catch (UserPreferencesException ex) { From 711c958a04cda32c5b2546d7cb625dfc34ecb8aa Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Thu, 15 Oct 2015 15:40:59 -0400 Subject: [PATCH 12/14] Added baloon notification if KWS core creation fails --- .../org/sleuthkit/autopsy/keywordsearch/Bundle.properties | 1 + .../src/org/sleuthkit/autopsy/keywordsearch/Server.java | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Bundle.properties b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Bundle.properties index cbeb1a8438..b657f600a3 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Bundle.properties +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Bundle.properties @@ -223,6 +223,7 @@ Server.connect.exception.msg=Failed to connect to Solr server\: Server.openCore.exception.msg=Core open requested, but server not yet running Server.openCore.exception.cantOpen.msg=Could not open Core Server.openCore.exception.cantOpen.msg2=Could not open Core +Server.openCore.exception.cantOpenForCase.msg=Could not open Keyword Search Core for case {0} Server.request.exception.exception.msg=Could not issue Solr request Server.commit.exception.msg=Could not commit index Server.addDoc.exception.msg=Could not add document to index via update handler\: {0} diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java index 20e3f178ee..50d5e962bd 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java @@ -626,7 +626,12 @@ public class Server { Case currentCase = Case.getCurrentCase(); - currentCore = openCore(currentCase); + try { + currentCore = openCore(currentCase); + } catch (KeywordSearchModuleException ex) { + MessageNotifyUtil.Notify.error(NbBundle.getMessage(Server.class, "Server.openCore.exception.cantOpenForCase.msg", currentCase.getName()), ex.getCause().getMessage()); + throw ex; + } serverAction.putValue(CORE_EVT, CORE_EVT_STATES.STARTED); } From f5a32922bfcdf66bf15e39ecec2df055feeae1dd Mon Sep 17 00:00:00 2001 From: Eugene Livis Date: Fri, 16 Oct 2015 10:57:05 -0400 Subject: [PATCH 13/14] Changed UI message text --- .../src/org/sleuthkit/autopsy/keywordsearch/Bundle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Bundle.properties b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Bundle.properties index b657f600a3..62a15c1517 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Bundle.properties +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Bundle.properties @@ -223,7 +223,7 @@ Server.connect.exception.msg=Failed to connect to Solr server\: Server.openCore.exception.msg=Core open requested, but server not yet running Server.openCore.exception.cantOpen.msg=Could not open Core Server.openCore.exception.cantOpen.msg2=Could not open Core -Server.openCore.exception.cantOpenForCase.msg=Could not open Keyword Search Core for case {0} +Server.openCore.exception.cantOpenForCase.msg=Could not create keyword search index for case {0} Server.request.exception.exception.msg=Could not issue Solr request Server.commit.exception.msg=Could not commit index Server.addDoc.exception.msg=Could not add document to index via update handler\: {0} From 3c235d9bac0505914ec229b8c3154fdf87afa6f4 Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Fri, 16 Oct 2015 12:00:28 -0400 Subject: [PATCH 14/14] Do linting of SingleUserCaseImporter --- .../sleuthkit/autopsy/casemodule/SingleUserCaseImporter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/SingleUserCaseImporter.java b/Core/src/org/sleuthkit/autopsy/casemodule/SingleUserCaseImporter.java index 936eccab5b..b5498cc284 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/SingleUserCaseImporter.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/SingleUserCaseImporter.java @@ -47,7 +47,6 @@ import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.SwingUtilities; import org.apache.commons.io.FileUtils; -import org.openide.util.Exceptions; import org.openide.util.NbBundle; import org.openide.windows.WindowManager; import org.sleuthkit.autopsy.casemodule.Case.CaseType; @@ -1391,6 +1390,8 @@ public class SingleUserCaseImporter implements Runnable { JTextArea jta = new JTextArea(casesThatWillBeProcessed.toString() + SEP + casesThatWillNotBeProcessed.toString()); jta.setEditable(false); JScrollPane jsp = new JScrollPane(jta) { + private static final long serialVersionUID = 1L; + @Override public Dimension getPreferredSize() { return new Dimension(700, 480);