use of org.kse.gui.password.DGetPassword in project keystore-explorer by kaikramer.
the class AuthorityCertificatesAction method loadCaCertificatesKeyStore.
private KeyStore loadCaCertificatesKeyStore() {
File caCertificatesFile = applicationSettings.getCaCertificatesFile();
KeyStore caCertificatesKeyStore = null;
try {
// first try to open cacerts with default password
try {
Password password = new Password(AuthorityCertificates.CACERTS_DEFAULT_PWD.toCharArray());
caCertificatesKeyStore = KeyStoreUtil.load(caCertificatesFile, password);
if (caCertificatesFile != null) {
return caCertificatesKeyStore;
}
} catch (KeyStoreLoadException ex) {
// not default password, continue with password dialog
}
DGetPassword dGetPassword = new DGetPassword(frame, res.getString("AuthorityCertificatesAction.CaCertificatesKeyStorePassword.Title"));
dGetPassword.setLocationRelativeTo(frame);
dGetPassword.setVisible(true);
Password password = dGetPassword.getPassword();
if (password == null) {
return null;
}
try {
caCertificatesKeyStore = KeyStoreUtil.load(caCertificatesFile, password);
} catch (KeyStoreLoadException ex) {
String problemStr = MessageFormat.format(res.getString("AuthorityCertificatesAction.NoOpenCaCertificatesKeyStore.Problem"), ex.getKeyStoreType(), caCertificatesFile.getName());
String[] causes = new String[] { res.getString("AuthorityCertificatesAction.PasswordIncorrectKeyStore.Cause"), res.getString("AuthorityCertificatesAction.CorruptedKeyStore.Cause") };
Problem problem = new Problem(problemStr, causes, ex);
DProblem dProblem = new DProblem(frame, res.getString("AuthorityCertificatesAction.ProblemOpeningCaCertificatesKeyStore.Title"), problem);
dProblem.setLocationRelativeTo(frame);
dProblem.setVisible(true);
return null;
}
if (caCertificatesKeyStore == null) {
JOptionPane.showMessageDialog(frame, MessageFormat.format(res.getString("AuthorityCertificatesAction.FileNotRecognisedType.message"), caCertificatesFile.getName()), res.getString("AuthorityCertificatesAction.OpenCaCertificatesKeyStore.Title"), JOptionPane.WARNING_MESSAGE);
return null;
}
return caCertificatesKeyStore;
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(frame, MessageFormat.format(res.getString("AuthorityCertificatesAction.NoReadFile.message"), caCertificatesFile), res.getString("AuthorityCertificatesAction.OpenCaCertificatesKeyStore.Title"), JOptionPane.WARNING_MESSAGE);
return null;
} catch (Exception ex) {
DError.displayError(frame, ex);
return null;
}
}
use of org.kse.gui.password.DGetPassword in project keystore-explorer by kaikramer.
the class OpenAction method showPasswordDialog.
private Password showPasswordDialog(File keyStoreFile) {
DGetPassword dGetPassword = new DGetPassword(frame, MessageFormat.format(res.getString("OpenAction.UnlockKeyStore.Title"), keyStoreFile.getName()));
dGetPassword.setLocationRelativeTo(frame);
dGetPassword.setVisible(true);
return dGetPassword.getPassword();
}
use of org.kse.gui.password.DGetPassword in project keystore-explorer by kaikramer.
the class KeyStoreExplorerAction method unlockEntry.
/**
* Unlock a key or key pair entry. Updates the KeyStore history with the
* password.
*
* @param alias
* Entry's alias
* @param state
* KeyStore state
* @return Key pair password if successful, null otherwise
*/
protected Password unlockEntry(String alias, KeyStoreState state) {
try {
KeyStore keyStore = state.getKeyStore();
DGetPassword dGetPassword = new DGetPassword(frame, MessageFormat.format(res.getString("KeyStoreExplorerAction.UnlockEntry.Title"), alias));
dGetPassword.setLocationRelativeTo(frame);
dGetPassword.setVisible(true);
Password password = dGetPassword.getPassword();
if (password == null) {
return null;
}
// Test password is correct
keyStore.getKey(alias, password.toCharArray());
state.setEntryPassword(alias, password);
kseFrame.updateControls(true);
return password;
} catch (GeneralSecurityException ex) {
String problemStr = MessageFormat.format(res.getString("KeyStoreExplorerAction.NoUnlockEntry.Problem"), alias);
String[] causes = new String[] { res.getString("KeyStoreExplorerAction.PasswordIncorrectEntry.Cause") };
Problem problem = new Problem(problemStr, causes, ex);
DProblem dProblem = new DProblem(frame, res.getString("KeyStoreExplorerAction.ProblemUnlockingEntry.Title"), problem);
dProblem.setLocationRelativeTo(frame);
dProblem.setVisible(true);
return null;
}
}
use of org.kse.gui.password.DGetPassword in project keystore-explorer by kaikramer.
the class ExamineFileAction method getPassword.
private Password getPassword(File file) {
DGetPassword dGetPassword = new DGetPassword(frame, MessageFormat.format(res.getString("ExamineFileAction.EnterPassword.Title"), file.getName()));
dGetPassword.setLocationRelativeTo(frame);
dGetPassword.setVisible(true);
return dGetPassword.getPassword();
}
use of org.kse.gui.password.DGetPassword in project keystore-explorer by kaikramer.
the class PasswordCallbackHandler method handlePasswordCallback.
private void handlePasswordCallback(PasswordCallback passCb) throws UnsupportedCallbackException {
DGetPassword dGetPassword = new DGetPassword(frame, res.getString("PasswordCallbackHandler.Title"));
dGetPassword.setLocationRelativeTo(frame);
dGetPassword.setVisible(true);
Password password = dGetPassword.getPassword();
if (password == null) {
throw new CancellationException("Password Callback canceled by user");
}
passCb.setPassword(password.toCharArray());
}
Aggregations