use of org.kse.utilities.history.KeyStoreState in project keystore-explorer by kaikramer.
the class UndoAction method setEnabled.
/**
* Enable or disable the action.
*
* @param enabled
* True to enable, false to disable it
*/
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
if (enabled) {
KeyStoreState currentState = kseFrame.getActiveKeyStoreHistory().getCurrentState();
putValue(NAME, MessageFormat.format(res.getString("UndoAction.dynamic.text"), currentState.getActionDescription()));
} else {
putValue(NAME, defaultName);
}
}
use of org.kse.utilities.history.KeyStoreState in project keystore-explorer by kaikramer.
the class UnlockKeyAction method doAction.
/**
* Do action.
*/
@Override
protected void doAction() {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStoreState currentState = history.getCurrentState();
String alias = kseFrame.getSelectedEntryAlias();
Password password = currentState.getEntryPassword(alias);
if (password != null) {
JOptionPane.showMessageDialog(frame, MessageFormat.format(res.getString("UnlockKeyAction.KeyAlreadyUnlocked.message"), alias), KSE.getApplicationName(), JOptionPane.WARNING_MESSAGE);
return;
}
unlockEntry(alias, currentState);
}
use of org.kse.utilities.history.KeyStoreState in project keystore-explorer by kaikramer.
the class UnlockKeyPairAction method doAction.
/**
* Do action.
*/
@Override
protected void doAction() {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStoreState currentState = history.getCurrentState();
String alias = kseFrame.getSelectedEntryAlias();
Password password = currentState.getEntryPassword(alias);
if (password != null) {
JOptionPane.showMessageDialog(frame, MessageFormat.format(res.getString("UnlockKeyPairAction.KeyPairAlreadyUnlocked.message"), alias), KSE.getApplicationName(), JOptionPane.WARNING_MESSAGE);
return;
}
unlockEntry(alias, currentState);
}
use of org.kse.utilities.history.KeyStoreState in project keystore-explorer by kaikramer.
the class ImportKeyPairAction method importKeyPairOpenSsl.
private void importKeyPairOpenSsl() {
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStoreState currentState = history.getCurrentState();
KeyStoreState newState = currentState.createBasisForNextState(this);
KeyStore keyStore = newState.getKeyStore();
DImportKeyPairOpenSsl dImportKeyPairOpenSsl = new DImportKeyPairOpenSsl(frame);
dImportKeyPairOpenSsl.setLocationRelativeTo(frame);
dImportKeyPairOpenSsl.setVisible(true);
PrivateKey privateKey = dImportKeyPairOpenSsl.getPrivateKey();
Certificate[] certs = dImportKeyPairOpenSsl.getCertificateChain();
if ((privateKey == null) || (certs == null)) {
return;
}
X509Certificate[] x509Certs = X509CertUtil.orderX509CertChain(X509CertUtil.convertCertificates(certs));
DGetAlias dGetAlias = new DGetAlias(frame, res.getString("ImportKeyPairAction.NewKeyPairEntryAlias.Title"), X509CertUtil.getCertificateAlias(x509Certs[0]));
dGetAlias.setLocationRelativeTo(frame);
dGetAlias.setVisible(true);
String alias = dGetAlias.getAlias();
if (alias == null) {
return;
}
if (keyStore.containsAlias(alias)) {
String message = MessageFormat.format(res.getString("ImportKeyPairAction.OverWriteEntry.message"), alias);
int selected = JOptionPane.showConfirmDialog(frame, message, res.getString("ImportKeyPairAction.NewKeyPairEntryAlias.Title"), JOptionPane.YES_NO_OPTION);
if (selected != JOptionPane.YES_OPTION) {
return;
}
}
Password password = new Password((char[]) null);
KeyStoreType type = KeyStoreType.resolveJce(keyStore.getType());
if (type.hasEntryPasswords()) {
DGetNewPassword dGetNewPassword = new DGetNewPassword(frame, res.getString("ImportKeyPairAction.NewKeyPairEntryPassword.Title"), applicationSettings.getPasswordQualityConfig());
dGetNewPassword.setLocationRelativeTo(frame);
dGetNewPassword.setVisible(true);
password = dGetNewPassword.getPassword();
if (password == null) {
return;
}
}
if (keyStore.containsAlias(alias)) {
keyStore.deleteEntry(alias);
newState.removeEntryPassword(alias);
}
keyStore.setKeyEntry(alias, privateKey, password.toCharArray(), x509Certs);
newState.setEntryPassword(alias, password);
currentState.append(newState);
kseFrame.updateControls(true);
JOptionPane.showMessageDialog(frame, res.getString("ImportKeyPairAction.KeyPairImportSuccessful.message"), res.getString("ImportKeyPairAction.ImportKeyPair.Title"), JOptionPane.INFORMATION_MESSAGE);
} catch (Exception ex) {
DError.displayError(frame, ex);
}
}
use of org.kse.utilities.history.KeyStoreState in project keystore-explorer by kaikramer.
the class ImportKeyPairAction method importKeyPairPvk.
private void importKeyPairPvk() {
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStoreState currentState = history.getCurrentState();
KeyStoreState newState = currentState.createBasisForNextState(this);
KeyStore keyStore = newState.getKeyStore();
DImportKeyPairPvk dImportKeyPairPvk = new DImportKeyPairPvk(frame);
dImportKeyPairPvk.setLocationRelativeTo(frame);
dImportKeyPairPvk.setVisible(true);
PrivateKey privateKey = dImportKeyPairPvk.getPrivateKey();
Certificate[] certs = dImportKeyPairPvk.getCertificateChain();
if ((privateKey == null) || (certs == null)) {
return;
}
X509Certificate[] x509Certs = X509CertUtil.orderX509CertChain(X509CertUtil.convertCertificates(certs));
DGetAlias dGetAlias = new DGetAlias(frame, res.getString("ImportKeyPairAction.NewKeyPairEntryAlias.Title"), X509CertUtil.getCertificateAlias(x509Certs[0]));
dGetAlias.setLocationRelativeTo(frame);
dGetAlias.setVisible(true);
String alias = dGetAlias.getAlias();
if (alias == null) {
return;
}
if (keyStore.containsAlias(alias)) {
String message = MessageFormat.format(res.getString("ImportKeyPairAction.OverWriteEntry.message"), alias);
int selected = JOptionPane.showConfirmDialog(frame, message, res.getString("ImportKeyPairAction.NewKeyPairEntryAlias.Title"), JOptionPane.YES_NO_OPTION);
if (selected != JOptionPane.YES_OPTION) {
return;
}
}
Password password = new Password((char[]) null);
KeyStoreType type = KeyStoreType.resolveJce(keyStore.getType());
if (type.hasEntryPasswords()) {
DGetNewPassword dGetNewPassword = new DGetNewPassword(frame, res.getString("ImportKeyPairAction.NewKeyPairEntryPassword.Title"), applicationSettings.getPasswordQualityConfig());
dGetNewPassword.setLocationRelativeTo(frame);
dGetNewPassword.setVisible(true);
password = dGetNewPassword.getPassword();
if (password == null) {
return;
}
}
if (keyStore.containsAlias(alias)) {
keyStore.deleteEntry(alias);
newState.removeEntryPassword(alias);
}
keyStore.setKeyEntry(alias, privateKey, password.toCharArray(), x509Certs);
newState.setEntryPassword(alias, password);
currentState.append(newState);
kseFrame.updateControls(true);
JOptionPane.showMessageDialog(frame, res.getString("ImportKeyPairAction.KeyPairImportSuccessful.message"), res.getString("ImportKeyPairAction.ImportKeyPair.Title"), JOptionPane.INFORMATION_MESSAGE);
} catch (Exception ex) {
DError.displayError(frame, ex);
}
}
Aggregations