use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.
the class ExportKeyPairPrivateKeyAction 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 privateKey = (PrivateKey) keyStore.getKey(alias, password.toCharArray());
DExportPrivateKeyType dExportPrivateKeyType = new DExportPrivateKeyType(frame);
dExportPrivateKeyType.setLocationRelativeTo(frame);
dExportPrivateKeyType.setVisible(true);
if (!dExportPrivateKeyType.exportTypeSelected()) {
return;
}
if (dExportPrivateKeyType.exportPkcs8()) {
exportAsPkcs8(privateKey, alias);
} else if (dExportPrivateKeyType.exportPvk()) {
exportAsPvk(privateKey, alias);
} else {
exportAsOpenSsl(privateKey, alias);
}
} catch (Exception ex) {
DError.displayError(frame, ex);
}
}
use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.
the class ExportKeyPairPublicKeyAction 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("ExportKeyPairPublicKeyAction.NoAccessEntry.message"), alias);
throw new CryptoException(message, ex);
}
}
use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.
the class ExportTrustedCertificateAction method getCertificate.
private X509Certificate getCertificate(String alias) throws CryptoException {
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStore keyStore = history.getCurrentState().getKeyStore();
X509Certificate cert = X509CertUtil.convertCertificate(keyStore.getCertificate(alias));
return cert;
} catch (KeyStoreException ex) {
String message = MessageFormat.format(res.getString("ExportTrustedCertificateAction.NoAccessEntry.message"), alias);
throw new CryptoException(message, ex);
}
}
use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.
the class ExportTrustedCertificatePublicKeyAction method getPublicKey.
private PublicKey getPublicKey(String alias) throws CryptoException {
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStore keyStore = history.getCurrentState().getKeyStore();
X509Certificate cert = X509CertUtil.convertCertificate(keyStore.getCertificate(alias));
return cert.getPublicKey();
} catch (KeyStoreException ex) {
String message = MessageFormat.format(res.getString("ExportTrustedCertificatePublicKeyAction.NoAccessEntry.message"), alias);
throw new CryptoException(message, ex);
}
}
use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.
the class GenerateSecretKeyAction method generateSecret.
/**
* Generate a secret key in the currently opened KeyStore.
*/
public void generateSecret() {
try {
int secretKeySize = applicationSettings.getGenerateSecretKeySize();
SecretKeyType secretKeyType = applicationSettings.getGenerateSecretKeyType();
DGenerateSecretKey dGenerateSecretKey = new DGenerateSecretKey(frame, secretKeyType, secretKeySize);
dGenerateSecretKey.setLocationRelativeTo(frame);
dGenerateSecretKey.setVisible(true);
if (!dGenerateSecretKey.isSuccessful()) {
return;
}
secretKeySize = dGenerateSecretKey.getSecretKeySize();
secretKeyType = dGenerateSecretKey.getSecretKeyType();
applicationSettings.setGenerateSecretKeySize(secretKeySize);
applicationSettings.setGenerateSecretKeyType(secretKeyType);
SecretKey secretKey = SecretKeyUtil.generateSecretKey(secretKeyType, secretKeySize);
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStoreState currentState = history.getCurrentState();
KeyStoreState newState = currentState.createBasisForNextState(this);
KeyStore keyStore = newState.getKeyStore();
DGetAlias dGetAlias = new DGetAlias(frame, res.getString("GenerateSecretKeyAction.NewSecretKeyEntryAlias.Title"), null);
dGetAlias.setLocationRelativeTo(frame);
dGetAlias.setVisible(true);
String alias = dGetAlias.getAlias();
if (alias == null) {
return;
}
if (keyStore.containsAlias(alias)) {
String message = MessageFormat.format(res.getString("GenerateSecretKeyAction.OverWriteEntry.message"), alias);
int selected = JOptionPane.showConfirmDialog(frame, message, res.getString("GenerateSecretKeyAction.NewSecretKeyEntryAlias.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("GenerateSecretKeyAction.NewSecretKeyEntryPassword.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, secretKey, password.toCharArray(), null);
newState.setEntryPassword(alias, password);
currentState.append(newState);
kseFrame.updateControls(true);
JOptionPane.showMessageDialog(frame, res.getString("GenerateSecretKeyAction.SecretKeyGenerationSuccessful.message"), res.getString("GenerateSecretKeyAction.GenerateSecretKey.Title"), JOptionPane.INFORMATION_MESSAGE);
} catch (Exception ex) {
DError.displayError(frame, ex);
}
}
Aggregations