use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.
the class KeyPairCertificateChainDetailsAction method showCertificateSelectedEntry.
/**
* Show the certificate details of the selected KeyStore entry.
*/
public void showCertificateSelectedEntry() {
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStore keyStore = history.getCurrentState().getKeyStore();
String alias = kseFrame.getSelectedEntryAlias();
X509Certificate[] certs = X509CertUtil.convertCertificates(keyStore.getCertificateChain(alias));
DViewCertificate dViewCertificate = new DViewCertificate(frame, MessageFormat.format(res.getString("KeyPairCertificateChainDetailsAction.CertDetailsEntry.Title"), alias), certs, kseFrame, DViewCertificate.EXPORT);
dViewCertificate.setLocationRelativeTo(frame);
dViewCertificate.setVisible(true);
} catch (Exception ex) {
DError.displayError(frame, ex);
}
}
use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.
the class KeyPairPublicKeyDetailsAction method doAction.
/**
* Do action.
*/
@Override
protected void doAction() {
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStoreState currentState = history.getCurrentState();
KeyStore keyStore = currentState.getKeyStore();
String alias = kseFrame.getSelectedEntryAlias();
PublicKey pubKey = X509CertUtil.orderX509CertChain(X509CertUtil.convertCertificates(keyStore.getCertificateChain(alias)))[0].getPublicKey();
DViewPublicKey dViewPublicKey = new DViewPublicKey(frame, MessageFormat.format(res.getString("KeyPairPublicKeyDetailsAction.PubKeyDetailsEntry.Title"), alias), pubKey);
dViewPublicKey.setLocationRelativeTo(frame);
dViewPublicKey.setVisible(true);
} catch (Exception ex) {
DError.displayError(frame, ex);
}
}
use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.
the class DeleteKeyPairAction method deleteSelectedEntry.
/**
* Let the user delete the selected KeyStore entry.
*/
public void deleteSelectedEntry() {
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStoreState currentState = history.getCurrentState();
KeyStoreState newState = currentState.createBasisForNextState(this);
KeyStore keyStore = newState.getKeyStore();
String alias = kseFrame.getSelectedEntryAlias();
String message = MessageFormat.format(res.getString("DeleteKeyPairAction.ConfirmDelete.message"), alias);
int selected = JOptionPane.showConfirmDialog(frame, message, res.getString("DeleteKeyPairAction.DeleteEntry.Title"), JOptionPane.YES_NO_OPTION);
if (selected != JOptionPane.YES_OPTION) {
return;
}
keyStore.deleteEntry(alias);
newState.removeEntryPassword(alias);
currentState.append(newState);
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 ExportKeyPairAction method doAction.
/**
* Do action.
*/
@Override
protected void doAction() {
File exportFile = null;
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 privateKey = (PrivateKey) keyStore.getKey(alias, password.toCharArray());
Certificate[] certificates = keyStore.getCertificateChain(alias);
DExportKeyPair dExportKeyPair = new DExportKeyPair(frame, alias, applicationSettings.getPasswordQualityConfig());
dExportKeyPair.setLocationRelativeTo(frame);
dExportKeyPair.setVisible(true);
if (!dExportKeyPair.exportSelected()) {
return;
}
exportFile = dExportKeyPair.getExportFile();
Password exportPassword = dExportKeyPair.getExportPassword();
KeyStore pkcs12 = KeyStoreUtil.create(KeyStoreType.PKCS12);
certificates = X509CertUtil.orderX509CertChain(X509CertUtil.convertCertificates(certificates));
pkcs12.setKeyEntry(alias, privateKey, exportPassword.toCharArray(), certificates);
KeyStoreUtil.save(pkcs12, exportFile, exportPassword);
JOptionPane.showMessageDialog(frame, res.getString("ExportKeyPairAction.ExportKeyPairSuccessful.message"), res.getString("ExportKeyPairAction.ExportKeyPair.Title"), JOptionPane.INFORMATION_MESSAGE);
} catch (FileNotFoundException ex) {
String message = MessageFormat.format(res.getString("ExportKeyPairAction.NoWriteFile.message"), exportFile);
JOptionPane.showMessageDialog(frame, message, res.getString("ExportKeyPairAction.ExportKeyPair.Title"), JOptionPane.WARNING_MESSAGE);
} catch (Exception ex) {
DError.displayError(frame, ex);
}
}
use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.
the class ExportKeyPairCertificateChainAction method getCertificateChain.
private X509Certificate[] getCertificateChain(String alias) throws CryptoException {
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStore keyStore = history.getCurrentState().getKeyStore();
X509Certificate[] certChain = X509CertUtil.convertCertificates(keyStore.getCertificateChain(alias));
return certChain;
} catch (KeyStoreException ex) {
String message = MessageFormat.format(res.getString("ExportKeyPairCertificateChainAction.NoAccessEntry.message"), alias);
throw new CryptoException(message, ex);
}
}
Aggregations