use of org.kse.gui.error.DProblem in project keystore-explorer by kaikramer.
the class SetKeyPasswordAction method doAction.
/**
* Do action.
*/
@Override
protected void doAction() {
String alias = null;
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStoreState currentState = history.getCurrentState();
KeyStoreState newState = currentState.createBasisForNextState(this);
KeyStore keyStore = newState.getKeyStore();
alias = kseFrame.getSelectedEntryAlias();
Password oldPassword = newState.getEntryPassword(alias);
DChangePassword dChangePassword = new DChangePassword(frame, DOCUMENT_MODAL, res.getString("SetKeyPasswordAction.SetKeyPassword.Title"), oldPassword, applicationSettings.getPasswordQualityConfig());
dChangePassword.setLocationRelativeTo(frame);
dChangePassword.setVisible(true);
if (oldPassword == null) {
oldPassword = dChangePassword.getOldPassword();
}
Password newPassword = dChangePassword.getNewPassword();
if ((oldPassword == null) || (newPassword == null)) {
return;
}
// Change the password by recreating the entry
Key key = keyStore.getKey(alias, oldPassword.toCharArray());
keyStore.deleteEntry(alias);
newState.removeEntryPassword(alias);
keyStore.setKeyEntry(alias, key, newPassword.toCharArray(), null);
if (currentState.getEntryPassword(alias) == null) {
currentState.setEntryPassword(alias, oldPassword);
}
newState.setEntryPassword(alias, newPassword);
currentState.append(newState);
kseFrame.updateControls(true);
JOptionPane.showMessageDialog(frame, res.getString("SetKeyPasswordAction.SetKeyPasswordSuccessful.message"), res.getString("SetKeyPasswordAction.SetKeyPassword.Title"), JOptionPane.INFORMATION_MESSAGE);
} catch (GeneralSecurityException ex) {
String problemStr = MessageFormat.format(res.getString("SetKeyPasswordAction.NoSetPasswordKeyEntry.Problem"), alias);
String[] causes = new String[] { res.getString("SetKeyPasswordAction.PasswordIncorrectKeyEntry.Cause") };
Problem problem = new Problem(problemStr, causes, ex);
DProblem dProblem = new DProblem(frame, res.getString("SetKeyPasswordAction.ProblemSettingPasswordKeyEntry.Title"), problem);
dProblem.setLocationRelativeTo(frame);
dProblem.setVisible(true);
} catch (Exception ex) {
DError.displayError(frame, ex);
}
}
use of org.kse.gui.error.DProblem in project keystore-explorer by kaikramer.
the class DImportKeyPairOpenSsl method loadCertificates.
private X509Certificate[] loadCertificates() {
String certificatePath = jtfCertificatePath.getText().trim();
if (certificatePath.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DImportKeyPairOpenSsl.CertificateRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
}
File certificateFile = new File(certificatePath);
try {
X509Certificate[] certs = X509CertUtil.loadCertificates(new FileInputStream(certificateFile));
if (certs.length == 0) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairOpenSsl.NoCertsFound.message"), certificateFile), getTitle(), JOptionPane.WARNING_MESSAGE);
}
return certs;
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairOpenSsl.NoReadFile.message"), certificateFile), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
} catch (Exception ex) {
Problem problem = createLoadCertsProblem(ex, certificateFile);
DProblem dProblem = new DProblem(this, res.getString("DImportKeyPairOpenSsl.ProblemLoadingCerts.Title"), problem);
dProblem.setLocationRelativeTo(this);
dProblem.setVisible(true);
return null;
}
}
use of org.kse.gui.error.DProblem in project keystore-explorer by kaikramer.
the class DImportKeyPairPkcs8 method loadPrivateKey.
private PrivateKey loadPrivateKey() {
String privateKeyPath = jtfPrivateKeyPath.getText().trim();
if (privateKeyPath.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DImportKeyPairPkcs8.PrivateKeyRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
}
File privateKeyFile = new File(privateKeyPath);
try {
PrivateKey privateKey = null;
if (!jcbEncrypted.isSelected()) {
privateKey = Pkcs8Util.load(new FileInputStream(privateKeyFile));
} else {
Password password = new Password(jpfPassword.getPassword());
privateKey = Pkcs8Util.loadEncrypted(new FileInputStream(privateKeyFile), password);
}
return privateKey;
} catch (PrivateKeyEncryptedException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPkcs8.PrivateKeyEncrypted.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
jcbEncrypted.setSelected(true);
return null;
} catch (PrivateKeyUnencryptedException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPkcs8.PrivateKeyNotEncrypted.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
jcbEncrypted.setSelected(false);
return null;
} catch (PrivateKeyPbeNotSupportedException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPkcs8.PrivateKeyPbeNotSupported.message"), ex.getUnsupportedPbe()), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DImportKeyPairPkcs8.NoReadFile.message"), privateKeyFile), getTitle(), JOptionPane.WARNING_MESSAGE);
return null;
} catch (Exception ex) {
Problem problem = createLoadPkcs8Problem(ex, privateKeyFile);
DProblem dProblem = new DProblem(this, res.getString("DImportKeyPairPkcs8.ProblemLoadingPkcs8.Title"), problem);
dProblem.setLocationRelativeTo(this);
dProblem.setVisible(true);
return null;
}
}
use of org.kse.gui.error.DProblem in project keystore-explorer by kaikramer.
the class DSignMidlet method okPressed.
private void okPressed() {
String inputJad = jtfInputJad.getText().trim();
if (inputJad.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DSignMidlet.InputJadRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
File inputJadFile = new File(inputJad);
if (!inputJadFile.isFile()) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DSignMidlet.InputJadNotFile.message"), inputJadFile), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
try {
MidletSigner.readJadFile(inputJadFile);
} catch (IOException ex) {
String problemStr = MessageFormat.format(res.getString("DSignMidlet.NoOpenJad.Problem"), inputJadFile.getName());
String[] causes = new String[] { res.getString("DSignMidlet.NotJad.Cause"), res.getString("DSignMidlet.CorruptedJad.Cause") };
Problem problem = new Problem(problemStr, causes, ex);
DProblem dProblem = new DProblem(this, res.getString("DSignMidlet.ProblemOpeningJad.Title"), problem);
dProblem.setLocationRelativeTo(this);
dProblem.setVisible(true);
return;
}
boolean signDirectly = jcbSignDirectly.isSelected();
File outputJadFile;
if (signDirectly) {
outputJadFile = inputJadFile;
} else {
String outputJad = jtfOutputJad.getText().trim();
if (outputJad.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DSignMidlet.OutputJadRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
outputJadFile = new File(outputJad);
}
String jar = jtfJar.getText().trim();
if (jar.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DSignMidlet.JarRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
File jarFile = new File(jar);
if (!jarFile.isFile()) {
JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DSignMidlet.JarNotFile.message"), jarFile), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
JarFile jarFileTest = null;
try {
jarFileTest = new JarFile(jarFile);
} catch (IOException ex) {
String problemStr = MessageFormat.format(res.getString("DSignMidlet.NoOpenJar.Problem"), jarFile.getName());
String[] causes = new String[] { res.getString("DSignMidlet.NotJar.Cause"), res.getString("DSignMidlet.CorruptedJar.Cause") };
Problem problem = new Problem(problemStr, causes, ex);
DProblem dProblem = new DProblem(this, res.getString("DSignMidlet.ProblemOpeningJar.Title"), problem);
dProblem.setLocationRelativeTo(this);
dProblem.setVisible(true);
return;
} finally {
IOUtils.closeQuietly(jarFileTest);
}
if (!signDirectly) {
if (outputJadFile.isFile()) {
String message = MessageFormat.format(res.getString("DSignMidlet.OverWriteOutputJadFile.message"), outputJadFile);
int selected = JOptionPane.showConfirmDialog(this, message, getTitle(), JOptionPane.YES_NO_OPTION);
if (selected != JOptionPane.YES_OPTION) {
return;
}
}
}
this.inputJadFile = inputJadFile;
this.outputJadFile = outputJadFile;
this.jarFile = jarFile;
closeDialog();
}
use of org.kse.gui.error.DProblem in project keystore-explorer by kaikramer.
the class OpenAction method showErrorMessage.
private int showErrorMessage(File keyStoreFile, KeyStoreLoadException klex) {
String problemStr = MessageFormat.format(res.getString("OpenAction.NoOpenKeyStore.Problem"), klex.getKeyStoreType().friendly(), keyStoreFile.getName());
String[] causes = new String[] { res.getString("OpenAction.PasswordIncorrectKeyStore.Cause"), res.getString("OpenAction.CorruptedKeyStore.Cause") };
Problem problem = new Problem(problemStr, causes, klex);
DProblem dProblem = new DProblem(frame, res.getString("OpenAction.ProblemOpeningKeyStore.Title"), problem);
dProblem.setLocationRelativeTo(frame);
dProblem.setVisible(true);
int choice = JOptionPane.showConfirmDialog(frame, res.getString("OpenAction.TryAgain.message"), res.getString("OpenAction.TryAgain.Title"), JOptionPane.YES_NO_OPTION);
return choice;
}
Aggregations