use of org.kse.gui.error.Problem 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.Problem 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.Problem in project keystore-explorer by kaikramer.
the class DImportKeyPairOpenSsl method createLoadOpenSslProblem.
private Problem createLoadOpenSslProblem(Exception exception, File openSslFile) {
String problemStr = null;
ArrayList<String> causeList = new ArrayList<String>();
if (jcbEncrypted.isSelected()) {
problemStr = MessageFormat.format(res.getString("DImportKeyPairOpenSsl.NoLoadEncryptedOpenSsl.Problem"), openSslFile.getName());
causeList.add(res.getString("DImportKeyPairOpenSsl.PasswordIncorrectOpenSsl.Cause"));
} else {
problemStr = MessageFormat.format(res.getString("DImportKeyPairOpenSsl.NoLoadUnencryptedOpenSsl.Problem"), openSslFile.getName());
}
causeList.add(res.getString("DImportKeyPairOpenSsl.NotOpenSsl.Cause"));
causeList.add(res.getString("DImportKeyPairOpenSsl.CorruptedOpenSsl.Cause"));
String[] causes = causeList.toArray(new String[causeList.size()]);
// Construct problem
Problem problem = new Problem(problemStr, causes, exception);
return problem;
}
use of org.kse.gui.error.Problem in project keystore-explorer by kaikramer.
the class DImportKeyPairPkcs8 method createLoadCertsProblem.
private Problem createLoadCertsProblem(Exception exception, File certsFile) {
String problemStr = MessageFormat.format(res.getString("DImportKeyPairPkcs8.NoLoadCerts.Problem"), certsFile.getName());
String[] causes = new String[] { res.getString("DImportKeyPairPkcs8.NotCerts.Cause"), res.getString("DImportKeyPairPkcs8.CorruptedCerts.Cause") };
Problem problem = new Problem(problemStr, causes, exception);
return problem;
}
use of org.kse.gui.error.Problem 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;
}
}
Aggregations