Exception handling

This commit is contained in:
Eugene Livis 2015-10-14 15:47:27 -04:00
parent 95ef28b8a4
commit 09c0f5dfc2
8 changed files with 96 additions and 44 deletions

View File

@ -108,6 +108,7 @@ AddImageWizardIterator.stepXofN=Step {0} of {1}
AddLocalFilesTask.localFileAdd.progress.text=Adding\: {0}/{1} AddLocalFilesTask.localFileAdd.progress.text=Adding\: {0}/{1}
Case.getCurCase.exception.noneOpen=Cannot get the current case; there is no case open\! 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.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.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.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 Case.open.msgDlg.updated.title=Case Database Schema Update

View File

@ -28,6 +28,7 @@ import java.io.IOException;
import java.nio.file.InvalidPathException; import java.nio.file.InvalidPathException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.security.GeneralSecurityException;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; 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 logger.log(Level.SEVERE, "Error creating a case: " + caseName + " in dir " + caseDir, ex); //NON-NLS
throw new CaseActionException( throw new CaseActionException(
NbBundle.getMessage(Case.class, "Case.create.exception.msg", caseName, caseDir), ex); 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()) { if (!UserPreferences.getIsMultiUserModeEnabled()) {
throw new CaseActionException(NbBundle.getMessage(Case.class, "Case.open.exception.multiUserCaseNotEnabled")); 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);
}
} }
/** /**

View File

@ -20,4 +20,6 @@ ServicesMonitor.statusChange.notify.title=Service Status Update
ServicesMonitor.statusChange.notify.msg=Status for {0} is {1} ServicesMonitor.statusChange.notify.msg=Status for {0} is {1}
ServicesMonitor.nullServiceName.excepton.txt=Requested service name is null ServicesMonitor.nullServiceName.excepton.txt=Requested service name is null
ServicesMonitor.nullStatusOrDetails.excepton.txt=Status or details string is null ServicesMonitor.nullStatusOrDetails.excepton.txt=Status or details string is null
ServicesMonitor.unknownServiceName.excepton.txt=Requested service name {0} is unknown 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

View File

@ -266,6 +266,8 @@ public class ServicesMonitor {
} else { } else {
setServiceStatus(Service.REMOTE_CASE_DATABASE.toString(), ServiceStatus.DOWN.toString(), ""); 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) { } catch (Exception ex) {
logger.log(Level.SEVERE, "Exception while checking database connection status", ex); //NON-NLS logger.log(Level.SEVERE, "Exception while checking database connection status", ex); //NON-NLS
} }
@ -297,6 +299,8 @@ public class ServicesMonitor {
} else { } else {
setServiceStatus(Service.MESSAGING.toString(), ServiceStatus.DOWN.toString(), ""); 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) { } catch (Exception ex) {
logger.log(Level.SEVERE, "Exception while checking messaging server connection status", ex); //NON-NLS logger.log(Level.SEVERE, "Exception while checking messaging server connection status", ex); //NON-NLS
} }

View File

@ -28,13 +28,14 @@ import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory; import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec; import javax.crypto.spec.PBEParameterSpec;
import org.openide.util.NbBundle;
/** /**
* Provides ability to convert text to hex text. * Provides ability to convert text to hex text.
*/ */
class TextConverter { class TextConverter {
private static final char[] LOOK_AWAY = "dontlookhere".toCharArray(); private static final char[] TMP = "dontlookhere".toCharArray();
private static final byte[] SALT = { private static final byte[] SALT = {
(byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12, (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12,
(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. * Convert text to hex text.
* @param property Input text string. * @param property Input text string.
* @return Converted hex string. * @return Converted hex string.
* @throws GeneralSecurityException * @throws IllegalArgumentException
* @throws UnsupportedEncodingException
*/ */
static String convertTextToHexText(String property) throws GeneralSecurityException, UnsupportedEncodingException { static String convertTextToHexText(String property) throws IllegalArgumentException {
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); try {
SecretKey key = keyFactory.generateSecret(new PBEKeySpec(LOOK_AWAY)); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); SecretKey key = keyFactory.generateSecret(new PBEKeySpec(TMP));
pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(SALT, 20)); Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
return base64Encode(pbeCipher.doFinal(property.getBytes("UTF-8"))); 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) { private static String base64Encode(byte[] bytes) {
@ -63,15 +68,19 @@ class TextConverter {
* Convert hex text back to text. * Convert hex text back to text.
* @param property Input hex text string. * @param property Input hex text string.
* @return Converted text string. * @return Converted text string.
* @throws GeneralSecurityException * @throws IllegalArgumentException
* @throws IOException
*/ */
static String convertHexTextToText(String property) throws GeneralSecurityException, IOException { static String convertHexTextToText(String property) throws IllegalArgumentException {
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); try {
SecretKey key = keyFactory.generateSecret(new PBEKeySpec(LOOK_AWAY)); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); SecretKey key = keyFactory.generateSecret(new PBEKeySpec(TMP));
pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(SALT, 20)); Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
return new String(pbeCipher.doFinal(base64Decode(property)), "UTF-8"); 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) { private static byte[] base64Decode(String property) {

View File

@ -134,10 +134,9 @@ public final class UserPreferences {
/** /**
* Reads persisted case database connection info. * Reads persisted case database connection info.
* @return An object encapsulating the database connection info. * @return An object encapsulating the database connection info.
* @throws GeneralSecurityException * @throws IllegalArgumentException
* @throws IOException
*/ */
public static CaseDbConnectionInfo getDatabaseConnectionInfo() throws GeneralSecurityException, IOException { public static CaseDbConnectionInfo getDatabaseConnectionInfo() throws IllegalArgumentException {
DbType dbType; DbType dbType;
try { try {
dbType = DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE, "SQLITE")); dbType = DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE, "SQLITE"));
@ -155,11 +154,13 @@ public final class UserPreferences {
/** /**
* Persists case database connection info. * Persists case database connection info.
* @param connectionInfo An object encapsulating the database connection info. *
* @throws GeneralSecurityException * @param connectionInfo An object encapsulating the database connection
* @throws UnsupportedEncodingException * 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_HOSTNAME_OR_IP, connectionInfo.getHost());
preferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort()); preferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort());
preferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName()); preferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName());
@ -196,10 +197,9 @@ public final class UserPreferences {
* Persists message service connection info. * Persists message service connection info.
* *
* @param info An object encapsulating the message service info. * @param info An object encapsulating the message service info.
* @throws java.security.GeneralSecurityException * @throws IllegalArgumentException
* @throws java.io.UnsupportedEncodingException
*/ */
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_USER, info.getUserName());
preferences.put(MESSAGE_SERVICE_PASSWORD, TextConverter.convertTextToHexText(info.getPassword())); preferences.put(MESSAGE_SERVICE_PASSWORD, TextConverter.convertTextToHexText(info.getPassword()));
preferences.put(MESSAGE_SERVICE_HOST, info.getHost()); preferences.put(MESSAGE_SERVICE_HOST, info.getHost());
@ -210,10 +210,9 @@ public final class UserPreferences {
* Reads persisted message service connection info. * Reads persisted message service connection info.
* *
* @return An object encapsulating the message service info. * @return An object encapsulating the message service info.
* @throws java.security.GeneralSecurityException * @throws IllegalArgumentException
* @throws java.io.IOException
*/ */
public static MessageServiceConnectionInfo getMessageServiceConnectionInfo() throws GeneralSecurityException, IOException { public static MessageServiceConnectionInfo getMessageServiceConnectionInfo() throws IllegalArgumentException {
return new MessageServiceConnectionInfo(preferences.get(MESSAGE_SERVICE_USER, ""), return new MessageServiceConnectionInfo(preferences.get(MESSAGE_SERVICE_USER, ""),
TextConverter.convertHexTextToText(preferences.get(MESSAGE_SERVICE_PASSWORD, "")), TextConverter.convertHexTextToText(preferences.get(MESSAGE_SERVICE_PASSWORD, "")),
preferences.get(MESSAGE_SERVICE_HOST, ""), preferences.get(MESSAGE_SERVICE_HOST, ""),

View File

@ -18,8 +18,12 @@ import org.sleuthkit.autopsy.core.UserPreferences;
import org.sleuthkit.autopsy.events.MessageServiceConnectionInfo; import org.sleuthkit.autopsy.events.MessageServiceConnectionInfo;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
import java.awt.Cursor; import java.awt.Cursor;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.GeneralSecurityException;
import java.util.logging.Level; import java.util.logging.Level;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import org.openide.util.Exceptions;
import org.openide.util.ImageUtilities; import org.openide.util.ImageUtilities;
import org.openide.util.Lookup; import org.openide.util.Lookup;
import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService; import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService;
@ -484,17 +488,25 @@ public final class MultiUserSettingsPanel extends javax.swing.JPanel {
}//GEN-LAST:event_bnTestSolrActionPerformed }//GEN-LAST:event_bnTestSolrActionPerformed
void load() { void load() {
CaseDbConnectionInfo dbInfo = UserPreferences.getDatabaseConnectionInfo(); try {
tbDbHostname.setText(dbInfo.getHost().trim()); CaseDbConnectionInfo dbInfo = UserPreferences.getDatabaseConnectionInfo();
tbDbPort.setText(dbInfo.getPort().trim()); tbDbHostname.setText(dbInfo.getHost().trim());
tbDbUsername.setText(dbInfo.getUserName().trim()); tbDbPort.setText(dbInfo.getPort().trim());
tbDbPassword.setText(dbInfo.getPassword()); 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(); try {
tbMsgHostname.setText(msgServiceInfo.getHost().trim()); MessageServiceConnectionInfo msgServiceInfo = UserPreferences.getMessageServiceConnectionInfo();
tbMsgPort.setText(msgServiceInfo.getPort().trim()); tbMsgHostname.setText(msgServiceInfo.getHost().trim());
tbMsgUsername.setText(msgServiceInfo.getUserName().trim()); tbMsgPort.setText(msgServiceInfo.getPort().trim());
tbMsgPassword.setText(msgServiceInfo.getPassword()); 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(); String indexingServerHost = UserPreferences.getIndexingServerHost().trim();
if (!indexingServerHost.isEmpty()) { if (!indexingServerHost.isEmpty()) {
@ -570,14 +582,22 @@ public final class MultiUserSettingsPanel extends javax.swing.JPanel {
new String(tbDbPassword.getPassword()), new String(tbDbPassword.getPassword()),
dbType); 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( MessageServiceConnectionInfo msgServiceInfo = new MessageServiceConnectionInfo(
tbMsgUsername.getText().trim(), tbMsgUsername.getText().trim(),
new String(tbMsgPassword.getPassword()), new String(tbMsgPassword.getPassword()),
tbMsgHostname.getText().trim(), tbMsgHostname.getText().trim(),
tbMsgPort.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.setIndexingServerHost(tbSolrHostname.getText().trim());
UserPreferences.setIndexingServerPort(Integer.parseInt(tbSolrPort.getText().trim())); UserPreferences.setIndexingServerPort(Integer.parseInt(tbSolrPort.getText().trim()));

View File

@ -19,7 +19,9 @@
package org.sleuthkit.autopsy.events; package org.sleuthkit.autopsy.events;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.security.GeneralSecurityException;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import javax.jms.JMSException; import javax.jms.JMSException;
@ -70,6 +72,10 @@ public final class AutopsyEventPublisher {
String message = "Failed to open remote event channel"; //NON-NLS String message = "Failed to open remote event channel"; //NON-NLS
logger.log(Level.SEVERE, message, ex); logger.log(Level.SEVERE, message, ex);
throw new AutopsyEventException(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);
} }
} }