Added new exception class for text converter + code review comments

This commit is contained in:
Eugene Livis 2015-10-15 10:57:34 -04:00
parent 968d3f7391
commit 34e093c2e1
7 changed files with 63 additions and 31 deletions

View File

@ -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);

View File

@ -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;

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2014 Basis Technology Corp.
* Copyright 2015 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> 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"));
}
}

View File

@ -0,0 +1,35 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2015 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> 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);
}
}

View File

@ -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));

View File

@ -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
}

View File

@ -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);