use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.
the class SetKeyPairPasswordAction method doAction.
/**
* Do action.
*/
@Override
protected void doAction() {
String alias = null;
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStoreState currentState = history.getCurrentState();
KeyStoreState newState = currentState.createBasisForNextState(this);
KeyStore keyStore = newState.getKeyStore();
alias = kseFrame.getSelectedEntryAlias();
Password oldPassword = newState.getEntryPassword(alias);
DChangePassword dChangePassword = new DChangePassword(frame, DOCUMENT_MODAL, res.getString("SetKeyPairPasswordAction.SetKeyPairPassword.Title"), oldPassword, applicationSettings.getPasswordQualityConfig());
dChangePassword.setLocationRelativeTo(frame);
dChangePassword.setVisible(true);
if (oldPassword == null) {
oldPassword = dChangePassword.getOldPassword();
}
Password newPassword = dChangePassword.getNewPassword();
if ((oldPassword == null) || (newPassword == null)) {
return;
}
// Change the password by recreating the entry
Certificate[] certs = keyStore.getCertificateChain(alias);
certs = X509CertUtil.orderX509CertChain(X509CertUtil.convertCertificates(certs));
Key privateKey = keyStore.getKey(alias, oldPassword.toCharArray());
keyStore.deleteEntry(alias);
newState.removeEntryPassword(alias);
keyStore.setKeyEntry(alias, privateKey, newPassword.toCharArray(), certs);
if (currentState.getEntryPassword(alias) == null) {
currentState.setEntryPassword(alias, oldPassword);
}
newState.setEntryPassword(alias, newPassword);
currentState.append(newState);
kseFrame.updateControls(true);
JOptionPane.showMessageDialog(frame, res.getString("SetKeyPairPasswordAction.SetKeyPairPasswordSuccessful.message"), res.getString("SetKeyPairPasswordAction.SetKeyPairPassword.Title"), JOptionPane.INFORMATION_MESSAGE);
} catch (GeneralSecurityException ex) {
String problemStr = MessageFormat.format(res.getString("SetKeyPairPasswordAction.NoSetPasswordKeyPairEntry.Problem"), alias);
String[] causes = new String[] { res.getString("SetKeyPairPasswordAction.PasswordIncorrectKeyPairEntry.Cause"), res.getString("SetKeyPairPasswordAction.NotSupportedAlgorithmKeyPairEntry.Cause") };
Problem problem = new Problem(problemStr, causes, ex);
DProblem dProblem = new DProblem(frame, res.getString("SetKeyPairPasswordAction.ProblemSettingPasswordKeyPairEntry.Title"), problem);
dProblem.setLocationRelativeTo(frame);
dProblem.setVisible(true);
} catch (Exception ex) {
DError.displayError(frame, ex);
}
}
use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.
the class SetKeyPasswordAction method doAction.
/**
* Do action.
*/
@Override
protected void doAction() {
String alias = null;
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStoreState currentState = history.getCurrentState();
KeyStoreState newState = currentState.createBasisForNextState(this);
KeyStore keyStore = newState.getKeyStore();
alias = kseFrame.getSelectedEntryAlias();
Password oldPassword = newState.getEntryPassword(alias);
DChangePassword dChangePassword = new DChangePassword(frame, DOCUMENT_MODAL, res.getString("SetKeyPasswordAction.SetKeyPassword.Title"), oldPassword, applicationSettings.getPasswordQualityConfig());
dChangePassword.setLocationRelativeTo(frame);
dChangePassword.setVisible(true);
if (oldPassword == null) {
oldPassword = dChangePassword.getOldPassword();
}
Password newPassword = dChangePassword.getNewPassword();
if ((oldPassword == null) || (newPassword == null)) {
return;
}
// Change the password by recreating the entry
Key key = keyStore.getKey(alias, oldPassword.toCharArray());
keyStore.deleteEntry(alias);
newState.removeEntryPassword(alias);
keyStore.setKeyEntry(alias, key, newPassword.toCharArray(), null);
if (currentState.getEntryPassword(alias) == null) {
currentState.setEntryPassword(alias, oldPassword);
}
newState.setEntryPassword(alias, newPassword);
currentState.append(newState);
kseFrame.updateControls(true);
JOptionPane.showMessageDialog(frame, res.getString("SetKeyPasswordAction.SetKeyPasswordSuccessful.message"), res.getString("SetKeyPasswordAction.SetKeyPassword.Title"), JOptionPane.INFORMATION_MESSAGE);
} catch (GeneralSecurityException ex) {
String problemStr = MessageFormat.format(res.getString("SetKeyPasswordAction.NoSetPasswordKeyEntry.Problem"), alias);
String[] causes = new String[] { res.getString("SetKeyPasswordAction.PasswordIncorrectKeyEntry.Cause") };
Problem problem = new Problem(problemStr, causes, ex);
DProblem dProblem = new DProblem(frame, res.getString("SetKeyPasswordAction.ProblemSettingPasswordKeyEntry.Title"), problem);
dProblem.setLocationRelativeTo(frame);
dProblem.setVisible(true);
} catch (Exception ex) {
DError.displayError(frame, ex);
}
}
use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.
the class SetPasswordAction method setKeyStorePassword.
/**
* Set the active KeyStore's password.
*
* @return True if successful
* @throws CryptoException
* If problem occurred
*/
protected boolean setKeyStorePassword() throws CryptoException {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStoreState currentState = history.getCurrentState();
KeyStoreState newState = currentState.createBasisForNextState(this);
Password password = getNewKeyStorePassword();
if (password == null) {
return false;
}
newState.setPassword(password);
currentState.append(newState);
kseFrame.updateControls(true);
return true;
}
use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.
the class RedoAction method doAction.
/**
* Do action.
*/
@Override
protected void doAction() {
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
history.getCurrentState().setNextStateAsCurrentState();
kseFrame.updateControls(true);
} catch (Exception ex) {
DError.displayError(frame, ex);
}
}
use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.
the class DExamineSsl method okPressed.
private void okPressed() {
String sslHost = ((String) jcbSslHost.getSelectedItem()).trim();
if (sslHost.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DExamineSsl.SslHostReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
String sslPortStr = ((String) jcbSslPort.getSelectedItem()).trim();
if (sslPortStr.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DExamineSsl.SslPortReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
int sslPort = 0;
try {
sslPort = Integer.parseInt(sslPortStr);
if (sslPort < 1) {
JOptionPane.showMessageDialog(this, res.getString("DExamineSsl.PositiveIntegerSslPortReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(this, res.getString("DExamineSsl.PositiveIntegerSslPortReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
this.sslHost = sslHost;
this.sslPort = sslPort;
// check selected key store
if (useClientAuth()) {
KeyStoreHistory ksh = (KeyStoreHistory) jcbKeyStore.getSelectedItem();
if (ksh == null) {
JOptionPane.showMessageDialog(this, res.getString("DExamineSsl.NoKeyStoreSelected.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
Password keyStorePassword = ksh.getCurrentState().getPassword();
if (keyStorePassword == null && ksh.getCurrentState().getType().hasEntryPasswords()) {
JOptionPane.showMessageDialog(this, res.getString("DExamineSsl.NoPasswordSetForKeyStore.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
}
// save host/port in preferences
applicationSettings.addSslHost(sslHost);
applicationSettings.addSslPort(sslPortStr);
cancelled = false;
closeDialog();
}
Aggregations