use of org.kse.crypto.Password in project keystore-explorer by kaikramer.
the class KeyPairPrivateKeyDetailsAction method doAction.
/**
* Do action.
*/
@Override
protected void doAction() {
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStoreState currentState = history.getCurrentState();
String alias = kseFrame.getSelectedEntryAlias();
Password password = getEntryPassword(alias, currentState);
if (password == null) {
return;
}
KeyStore keyStore = currentState.getKeyStore();
PrivateKey privKey = (PrivateKey) keyStore.getKey(alias, password.toCharArray());
DViewPrivateKey dViewPrivateKey = new DViewPrivateKey(frame, MessageFormat.format(res.getString("KeyPairPrivateKeyDetailsAction.PrivKeyDetailsEntry.Title"), alias), privKey, history.getExplicitProvider());
dViewPrivateKey.setLocationRelativeTo(frame);
dViewPrivateKey.setVisible(true);
} catch (Exception ex) {
DError.displayError(frame, ex);
}
}
use of org.kse.crypto.Password in project keystore-explorer by kaikramer.
the class SaveAction method saveKeyStore.
/**
* Save the supplied KeyStore back to the file it was originally opened
* from.
*
* @param history
* KeyStore history
* @return True if the KeyStore is saved to disk, false otherwise
*/
protected boolean saveKeyStore(KeyStoreHistory history) {
File saveFile = null;
try {
KeyStoreState currentState = history.getCurrentState();
kseFrame.focusOnKeyStore(currentState.getKeyStore());
saveFile = history.getFile();
if (saveFile == null) {
return saveKeyStoreAs(history);
}
Password password = currentState.getPassword();
if (password == null) {
SetPasswordAction setPasswordAction = new SetPasswordAction(kseFrame);
if (setPasswordAction.setKeyStorePassword()) {
currentState = history.getCurrentState();
password = currentState.getPassword();
} else {
return false;
}
}
KeyStoreUtil.save(currentState.getKeyStore(), saveFile, password);
currentState.setPassword(password);
currentState.setAsSavedState();
kseFrame.updateControls(false);
return true;
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(frame, MessageFormat.format(res.getString("SaveAction.NoWriteFile.message"), saveFile), res.getString("SaveAction.SaveKeyStore.Title"), JOptionPane.WARNING_MESSAGE);
return false;
} catch (Exception ex) {
DError.displayError(frame, ex);
return false;
}
}
use of org.kse.crypto.Password in project keystore-explorer by kaikramer.
the class SaveAsAction method saveKeyStoreAs.
/**
* Save the supplied opened KeyStore to disk to what may be a different file
* from the one it was opened from (if any).
*
* @param history
* KeyStore history
* @return True if the KeyStore is saved to disk, false otherwise
*/
protected boolean saveKeyStoreAs(KeyStoreHistory history) {
File saveFile = null;
try {
KeyStoreState currentState = history.getCurrentState();
Password password = currentState.getPassword();
if (password == null) {
SetPasswordAction setPasswordAction = new SetPasswordAction(kseFrame);
if (setPasswordAction.setKeyStorePassword()) {
currentState = history.getCurrentState();
password = currentState.getPassword();
} else {
return false;
}
}
JFileChooser chooser = FileChooserFactory.getKeyStoreFileChooser();
chooser.setCurrentDirectory(CurrentDirectory.get());
chooser.setDialogTitle(res.getString("SaveAsAction.SaveKeyStoreAs.Title"));
chooser.setMultiSelectionEnabled(false);
int rtnValue = chooser.showSaveDialog(frame);
if (rtnValue != JFileChooser.APPROVE_OPTION) {
return false;
}
saveFile = chooser.getSelectedFile();
CurrentDirectory.updateForFile(saveFile);
if (saveFile.isFile()) {
String message = MessageFormat.format(res.getString("SaveAsAction.OverWriteFile.message"), saveFile);
int selected = JOptionPane.showConfirmDialog(frame, message, res.getString("SaveAsAction.SaveKeyStoreAs.Title"), JOptionPane.YES_NO_OPTION);
if (selected != JOptionPane.YES_OPTION) {
return false;
}
}
if (isKeyStoreFileOpen(saveFile)) {
JOptionPane.showMessageDialog(frame, res.getString("SaveAsAction.NoSaveKeyStoreAlreadyOpen.message"), res.getString("SaveAsAction.SaveKeyStoreAs.Title"), JOptionPane.WARNING_MESSAGE);
return false;
}
KeyStoreUtil.save(currentState.getKeyStore(), saveFile, password);
currentState.setPassword(password);
history.setFile(saveFile);
currentState.setAsSavedState();
kseFrame.updateControls(false);
kseFrame.addRecentFile(saveFile);
return true;
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(frame, MessageFormat.format(res.getString("SaveAsAction.NoWriteFile.message"), saveFile), res.getString("SaveAsAction.SaveKeyStoreAs.Title"), JOptionPane.WARNING_MESSAGE);
return false;
} catch (Exception ex) {
DError.displayError(frame, ex);
return false;
}
}
use of org.kse.crypto.Password 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.crypto.Password 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);
}
}
Aggregations