changed password field into a proper JPassword box. now using TextConverter to store encrypted password in properties file.

This commit is contained in:
Nick Davis 2017-06-20 17:37:42 -04:00
parent beba50c231
commit fc20b7ea19
6 changed files with 58 additions and 56 deletions

View File

@ -136,13 +136,12 @@ public class PostgresEamDb extends AbstractSqlEamDb {
@Override
protected Connection connect() throws EamDbException {
synchronized (this) {
if (!dbSettings.isEnabled()) {
if (!EamDb.isEnabled()) {
throw new EamDbException("Enterprise artifacts manager is not enabled"); // NON-NLS
}
if (connectionPool == null) {
setupConnectionPool();
// confirmDatabaseSchema();
}
}

View File

@ -31,6 +31,8 @@ import java.util.logging.Level;
import org.openide.util.Exceptions;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.ModuleSettings;
import org.sleuthkit.autopsy.coreutils.TextConverter;
import org.sleuthkit.autopsy.coreutils.TextConverterException;
/**
* Settings for the Postgres implementation of the enterprise artifacts manager
@ -50,7 +52,6 @@ public final class PostgresEamDbSettings {
private final String JDBC_BASE_URI = "jdbc:postgresql://"; // NON-NLS
private final String JDBC_DRIVER = "org.postgresql.Driver"; // NON-NLS
private boolean enabled;
private String host;
private int port;
private String dbName;
@ -64,8 +65,6 @@ public final class PostgresEamDbSettings {
}
public void loadSettings() {
enabled = Boolean.valueOf(ModuleSettings.getConfigSetting("EnterpriseArtifactsManager", "db.enabled")); // NON-NLS
host = ModuleSettings.getConfigSetting("EnterpriseArtifactsManager", "db.postgresql.host"); // NON-NLS
if (host == null || host.isEmpty()) {
host = DEFAULT_HOST;
@ -112,6 +111,13 @@ public final class PostgresEamDbSettings {
password = ModuleSettings.getConfigSetting("EnterpriseArtifactsManager", "db.postgresql.password"); // NON-NLS
if (password == null || password.isEmpty()) {
password = DEFAULT_PASSWORD;
} else {
try {
password = TextConverter.convertHexTextToText(password);
} catch (TextConverterException ex) {
LOGGER.log(Level.WARNING, "Failed to convert password from hex text to text.", ex);
password = DEFAULT_PASSWORD;
}
}
String badTagsStr = ModuleSettings.getConfigSetting("EnterpriseArtifactsManager", "db.badTags"); // NON-NLS
@ -127,7 +133,12 @@ public final class PostgresEamDbSettings {
ModuleSettings.setConfigSetting("EnterpriseArtifactsManager", "db.postgresql.dbName", getDbName()); // NON-NLS
ModuleSettings.setConfigSetting("EnterpriseArtifactsManager", "db.postgresql.bulkThreshold", Integer.toString(getBulkThreshold())); // NON-NLS
ModuleSettings.setConfigSetting("EnterpriseArtifactsManager", "db.postgresql.user", getUserName()); // NON-NLS
ModuleSettings.setConfigSetting("EnterpriseArtifactsManager", "db.postgresql.password", getPassword()); // NON-NLS
try {
ModuleSettings.setConfigSetting("EnterpriseArtifactsManager", "db.postgresql.password", TextConverter.convertTextToHexText(getPassword())); // NON-NLS
} catch (TextConverterException ex) {
LOGGER.log(Level.SEVERE, "Failed to convert password from text to hex text.", ex);
}
ModuleSettings.setConfigSetting("EnterpriseArtifactsManager", "db.badTags", String.join(",", badTags)); // NON-NLS
}
@ -464,20 +475,6 @@ public final class PostgresEamDbSettings {
|| !userName.equals(userNameString) || !password.equals(userPasswordString);
}
/**
* @return the enabled
*/
public boolean isEnabled() {
return enabled;
}
/**
* @param enabled the enabled to set
*/
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
/**
* @return the host
*/

View File

@ -19,8 +19,6 @@
package org.sleuthkit.autopsy.experimental.enterpriseartifactsmanager.datamodel;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
@ -138,9 +136,7 @@ public class SqliteEamDb extends AbstractSqlEamDb {
}
if (connectionPool == null) {
// verifyDBDirectory();
setupConnectionPool();
// confirmDatabaseSchema();
}
try {

View File

@ -23,15 +23,12 @@ import java.io.IOException;
import java.nio.file.Files;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import org.openide.util.Exceptions;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.ModuleSettings;
import org.sleuthkit.autopsy.coreutils.PlatformUtil;
@ -57,7 +54,6 @@ public final class SqliteEamDbSettings {
private static final String PRAGMA_PAGE_SIZE_4096 = "PRAGMA page_size = 4096";
private static final String PRAGMA_FOREIGN_KEYS_ON = "PRAGMA foreign_keys = ON";
private boolean enabled;
private String dbName;
private String dbDirectory;
private int bulkThreshold;
@ -68,8 +64,6 @@ public final class SqliteEamDbSettings {
}
public void loadSettings() {
enabled = Boolean.valueOf(ModuleSettings.getConfigSetting("EnterpriseArtifactsManager", "db.enabled")); // NON-NLS
dbName = ModuleSettings.getConfigSetting("EnterpriseArtifactsManager", "db.sqlite.dbName"); // NON-NLS
if (dbName == null || dbName.isEmpty()) {
dbName = DEFAULT_DBNAME;

View File

@ -332,6 +332,8 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="bnTest" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="lbTestIcon" min="-2" pref="20" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="bnCreateDb" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="bnOk" min="-2" max="-2" attributes="0"/>
@ -345,13 +347,22 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="bnOk" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="bnCancel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="bnTest" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="bnCreateDb" alignment="3" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace min="4" pref="4" max="-2" attributes="0"/>
<Component id="lbTestIcon" max="32767" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="3" attributes="0">
<Component id="bnOk" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="bnCancel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="bnTest" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="bnCreateDb" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -397,6 +408,8 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="bnCreateDbActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="lbTestIcon">
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="pnSetupGuidance">

View File

@ -108,6 +108,7 @@ public class EamDbSettingsDialog extends JDialog {
bnOk = new javax.swing.JButton();
bnTest = new javax.swing.JButton();
bnCreateDb = new javax.swing.JButton();
lbTestIcon = new javax.swing.JLabel();
pnSetupGuidance = new javax.swing.JPanel();
taSetupGuidance = new javax.swing.JTextArea();
@ -304,6 +305,8 @@ public class EamDbSettingsDialog extends JDialog {
.addContainerGap()
.addComponent(bnTest)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lbTestIcon, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(bnCreateDb)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(bnOk)
@ -315,12 +318,18 @@ public class EamDbSettingsDialog extends JDialog {
pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnButtonsLayout.createSequentialGroup()
.addGap(0, 0, 0)
.addGroup(pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(bnOk)
.addComponent(bnCancel)
.addComponent(bnTest)
.addComponent(bnCreateDb))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnButtonsLayout.createSequentialGroup()
.addGap(4, 4, 4)
.addComponent(lbTestIcon, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(pnButtonsLayout.createSequentialGroup()
.addGroup(pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(bnOk)
.addComponent(bnCancel)
.addComponent(bnTest)
.addComponent(bnCreateDb))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
pnSetupGuidance.setBorder(javax.swing.BorderFactory.createTitledBorder(null, org.openide.util.NbBundle.getMessage(EamDbSettingsDialog.class, "EamDbSettingsDialog.pnSetupGuidance.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N
@ -412,7 +421,7 @@ public class EamDbSettingsDialog extends JDialog {
setTextPrompts();
setTextBoxListeners();
lbTestIcon.setIcon(null);
}
private void display() {
@ -471,6 +480,11 @@ public class EamDbSettingsDialog extends JDialog {
}
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
if (testingStatus == DatabaseTestResult.TESTEDOK) {
lbTestIcon.setIcon(goodIcon);
} else {
lbTestIcon.setIcon(badIcon);
}
valid();
}//GEN-LAST:event_bnTestActionPerformed
@ -753,7 +767,7 @@ public class EamDbSettingsDialog extends JDialog {
}
try {
dbSettingsPostgres.setPassword(jpDbPassword.getPassword().toString());
dbSettingsPostgres.setPassword(new String(jpDbPassword.getPassword()));
} catch (EamDbException ex) {
if (!guidanceText.toString().isEmpty()) {
guidanceText.append(", ");
@ -856,30 +870,18 @@ public class EamDbSettingsDialog extends JDialog {
@Override
public void changedUpdate(DocumentEvent e) {
Object statusIcon = e.getDocument().getProperty("statusIcon"); // NON-NLS
if (statusIcon != null) {
((javax.swing.JLabel) statusIcon).setIcon(null);
}
firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
valid();
}
@Override
public void insertUpdate(DocumentEvent e) {
Object statusIcon = e.getDocument().getProperty("statusIcon"); // NON-NLS
if (statusIcon != null) {
((javax.swing.JLabel) statusIcon).setIcon(null);
}
firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
valid();
}
@Override
public void removeUpdate(DocumentEvent e) {
Object statusIcon = e.getDocument().getProperty("statusIcon"); // NON-NLS
if (statusIcon != null) {
((javax.swing.JLabel) statusIcon).setIcon(null);
}
firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
valid();
}
@ -905,6 +907,7 @@ public class EamDbSettingsDialog extends JDialog {
private javax.swing.JLabel lbDatabasePath;
private javax.swing.JLabel lbHostName;
private javax.swing.JLabel lbPort;
private javax.swing.JLabel lbTestIcon;
private javax.swing.JLabel lbUserName;
private javax.swing.JLabel lbUserPassword;
private javax.swing.JPanel pnButtons;