use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.
the class KseFrame method updateApplicationTitle.
private void updateApplicationTitle() {
// Title: "[KeyStore Name [*] - ] Application Name and Version"
String appName = MessageFormat.format("{0} {1}", KSE.getApplicationName(), KSE.getApplicationVersion());
KeyStoreHistory history = getActiveKeyStoreHistory();
if (history == null) {
frame.setTitle(appName);
} else {
String keyStoreName = history.getName();
if (!history.getCurrentState().isSavedState()) {
frame.setTitle(MessageFormat.format("{0} * - {1}", keyStoreName, appName));
} else {
frame.setTitle(MessageFormat.format("{0} - {1}", keyStoreName, appName));
}
}
}
use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.
the class KseFrame method getActiveKeyStore.
/**
* Get the active KeyStore.
*
* @return The KeyStore or null if no KeyStore is active
*/
public KeyStore getActiveKeyStore() {
KeyStoreHistory history = getActiveKeyStoreHistory();
if (history == null) {
return null;
}
KeyStoreState currentState = history.getCurrentState();
KeyStore keyStore = currentState.getKeyStore();
return keyStore;
}
use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.
the class KseFrame method handleDeleteSelectedEntry.
private void handleDeleteSelectedEntry() {
KeyStoreHistory history = getActiveKeyStoreHistory();
KeyStore keyStore = history.getCurrentState().getKeyStore();
String alias = getSelectedEntryAlias();
try {
if (KeyStoreUtil.isKeyPairEntry(alias, keyStore)) {
deleteKeyPairAction.deleteSelectedEntry();
} else if (KeyStoreUtil.isTrustedCertificateEntry(alias, keyStore)) {
deleteTrustedCertificateAction.deleteSelectedEntry();
} else {
deleteKeyAction.deleteSelectedEntry();
}
} catch (Exception ex) {
DError.displayError(frame, ex);
}
}
use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.
the class AppendToCertificateChainAction 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;
}
KeyStoreState newState = currentState.createBasisForNextState(this);
KeyStore keyStore = newState.getKeyStore();
Key privKey = keyStore.getKey(alias, password.toCharArray());
X509Certificate[] certChain = X509CertUtil.orderX509CertChain(X509CertUtil.convertCertificates(keyStore.getCertificateChain(alias)));
// Certificate to append to is the end one in the chain
X509Certificate certToAppendTo = certChain[certChain.length - 1];
if (X509CertUtil.isCertificateSelfSigned(certToAppendTo)) {
JOptionPane.showMessageDialog(frame, res.getString("AppendToCertificateChainAction.CannotAppendCertSelfSigned.message"), res.getString("AppendToCertificateChainAction.AppendToCertificateChain.Title"), JOptionPane.WARNING_MESSAGE);
return;
}
File certFile = chooseAppendCertificateFile();
if (certFile == null) {
return;
}
X509Certificate[] certs = openCertificate(certFile);
if ((certs == null) || (certs.length == 0)) {
return;
}
if (certs.length > 1) {
JOptionPane.showMessageDialog(frame, res.getString("AppendToCertificateChainAction.NoMultipleAppendCert.message"), res.getString("AppendToCertificateChainAction.AppendToCertificateChain.Title"), JOptionPane.WARNING_MESSAGE);
return;
}
X509Certificate certToAppend = certs[0];
if (!X509CertUtil.verifyCertificate(certToAppendTo, certToAppend)) {
JOptionPane.showMessageDialog(frame, res.getString("AppendToCertificateChainAction.AppendCertNotSigner.message"), res.getString("AppendToCertificateChainAction.AppendToCertificateChain.Title"), JOptionPane.WARNING_MESSAGE);
return;
}
X509Certificate[] newCertChain = new X509Certificate[certChain.length + 1];
System.arraycopy(certChain, 0, newCertChain, 0, certChain.length);
newCertChain[newCertChain.length - 1] = certToAppend;
keyStore.deleteEntry(alias);
keyStore.setKeyEntry(alias, privKey, password.toCharArray(), newCertChain);
currentState.append(newState);
kseFrame.updateControls(true);
JOptionPane.showMessageDialog(frame, res.getString("AppendToCertificateChainAction.AppendToCertificateChainSuccessful.message"), res.getString("AppendToCertificateChainAction.AppendToCertificateChain.Title"), JOptionPane.INFORMATION_MESSAGE);
} catch (Exception ex) {
DError.displayError(frame, ex);
}
}
use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.
the class ChangeTypeAction method changeKeyStoreType.
private boolean changeKeyStoreType(KeyStoreType newKeyStoreType) {
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStoreState currentState = history.getCurrentState();
KeyStore currentKeyStore = currentState.getKeyStore();
String currentType = currentState.getKeyStore().getType();
KeyStore newKeyStore = KeyStoreUtil.create(newKeyStoreType);
// Only warn the user once
resetWarnings();
// Copy all entries to the new KeyStore: Trusted certs, key pairs and secret keys
for (Enumeration<String> aliases = currentKeyStore.aliases(); aliases.hasMoreElements(); ) {
String alias = aliases.nextElement();
if (KeyStoreUtil.isTrustedCertificateEntry(alias, currentKeyStore)) {
Certificate trustedCertificate = currentKeyStore.getCertificate(alias);
newKeyStore.setCertificateEntry(alias, trustedCertificate);
} else if (KeyStoreUtil.isKeyPairEntry(alias, currentKeyStore)) {
if (!copyKeyPairEntry(newKeyStoreType, currentState, currentKeyStore, currentType, newKeyStore, alias)) {
return false;
}
} else if (KeyStoreUtil.isKeyEntry(alias, currentKeyStore)) {
if (!copySecretKeyEntry(newKeyStoreType, currentState, currentKeyStore, newKeyStore, alias)) {
return false;
}
}
}
KeyStoreState newState = currentState.createBasisForNextState(this);
newState.setKeyStore(newKeyStore);
currentState.append(newState);
kseFrame.updateControls(true);
JOptionPane.showMessageDialog(frame, res.getString("ChangeTypeAction.ChangeKeyStoreTypeSuccessful.message"), res.getString("ChangeTypeAction.ChangeKeyStoreType.Title"), JOptionPane.INFORMATION_MESSAGE);
return true;
} catch (Exception ex) {
DError.displayError(frame, ex);
return false;
}
}
Aggregations