use of org.kse.utilities.history.KeyStoreState in project keystore-explorer by kaikramer.
the class RenameTrustedCertificateAction method doAction.
/**
* Do action.
*/
@Override
protected void doAction() {
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStoreState currentState = history.getCurrentState();
KeyStoreState newState = currentState.createBasisForNextState(this);
KeyStore keyStore = newState.getKeyStore();
String alias = kseFrame.getSelectedEntryAlias();
DGetAlias dGetAlias = new DGetAlias(frame, res.getString("RenameTrustedCertificateAction.NewEntryAlias.Title"), alias);
dGetAlias.setLocationRelativeTo(frame);
dGetAlias.setVisible(true);
String newAlias = dGetAlias.getAlias();
if (newAlias == null) {
return;
}
if (newAlias.equalsIgnoreCase(alias)) {
JOptionPane.showMessageDialog(frame, MessageFormat.format(res.getString("RenameTrustedCertificateAction.RenameAliasIdentical.message"), alias), res.getString("RenameTrustedCertificateAction.RenameEntry.Title"), JOptionPane.WARNING_MESSAGE);
return;
}
if (keyStore.containsAlias(newAlias)) {
String message = MessageFormat.format(res.getString("RenameTrustedCertificateAction.OverWriteEntry.message"), newAlias);
int selected = JOptionPane.showConfirmDialog(frame, message, res.getString("RenameTrustedCertificateAction.RenameEntry.Title"), JOptionPane.YES_NO_OPTION);
if (selected != JOptionPane.YES_OPTION) {
return;
}
keyStore.deleteEntry(newAlias);
newState.removeEntryPassword(newAlias);
}
Certificate cert = keyStore.getCertificate(alias);
keyStore.setCertificateEntry(newAlias, cert);
keyStore.deleteEntry(alias);
currentState.append(newState);
kseFrame.updateControls(true);
} catch (Exception ex) {
DError.displayError(frame, ex);
}
}
use of org.kse.utilities.history.KeyStoreState in project keystore-explorer by kaikramer.
the class SignJarAction 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();
Provider provider = history.getExplicitProvider();
PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, password.toCharArray());
X509Certificate[] certs = X509CertUtil.orderX509CertChain(X509CertUtil.convertCertificates(keyStore.getCertificateChain(alias)));
KeyPairType keyPairType = KeyPairUtil.getKeyPairType(privateKey);
DSignJar dSignJar = new DSignJar(frame, privateKey, keyPairType, alias, provider);
dSignJar.setLocationRelativeTo(frame);
dSignJar.setVisible(true);
SignatureType signatureType = dSignJar.getSignatureType();
String signatureName = dSignJar.getSignatureName();
File inputJarFile = dSignJar.getInputJar();
File outputJarFile = dSignJar.getOutputJar();
String tsaUrl = dSignJar.getTimestampingServerUrl();
if (signatureType == null) {
return;
}
String signer = KSE.getFullApplicationName();
DigestType digestType = dSignJar.getDigestType();
if (inputJarFile.equals(outputJarFile)) {
JarSigner.sign(inputJarFile, privateKey, certs, signatureType, signatureName, signer, digestType, tsaUrl, provider);
} else {
JarSigner.sign(inputJarFile, outputJarFile, privateKey, certs, signatureType, signatureName, signer, digestType, tsaUrl, provider);
}
JOptionPane.showMessageDialog(frame, res.getString("SignJarAction.SignJarSuccessful.message"), res.getString("SignJarAction.SignJar.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 SignMidletAction 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());
X509Certificate[] certs = X509CertUtil.orderX509CertChain(X509CertUtil.convertCertificates(keyStore.getCertificateChain(alias)));
if (!privateKey.getAlgorithm().equals(KeyPairType.RSA.jce())) {
JOptionPane.showMessageDialog(frame, res.getString("SignMidletAction.ReqRsaKeyPairMidletSigning.message"), res.getString("SignMidletAction.SignMidlet.Title"), JOptionPane.WARNING_MESSAGE);
return;
}
DSignMidlet dSignMidlet = new DSignMidlet(frame);
dSignMidlet.setLocationRelativeTo(frame);
dSignMidlet.setVisible(true);
File inputJadFile = dSignMidlet.getInputJad();
File outputJadFile = dSignMidlet.getOutputJad();
File jarFile = dSignMidlet.getJar();
if (inputJadFile == null) {
return;
}
if (inputJadFile.equals(outputJadFile)) {
MidletSigner.sign(inputJadFile, jarFile, (RSAPrivateKey) privateKey, certs, 1);
} else {
MidletSigner.sign(inputJadFile, outputJadFile, jarFile, (RSAPrivateKey) privateKey, certs, 1);
}
JOptionPane.showMessageDialog(frame, res.getString("SignMidletAction.SignMidletSuccessful.message"), res.getString("SignMidletAction.SignMidlet.Title"), JOptionPane.INFORMATION_MESSAGE);
} catch (Exception ex) {
DError.displayError(frame, ex);
}
}
Aggregations