use of org.kse.crypto.Password in project keystore-explorer by kaikramer.
the class SetPasswordAction method setKeyStorePassword.
/**
* Set the active KeyStore's password.
*
* @return True if successful
* @throws CryptoException
* If problem occurred
*/
protected boolean setKeyStorePassword() throws CryptoException {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStoreState currentState = history.getCurrentState();
KeyStoreState newState = currentState.createBasisForNextState(this);
Password password = getNewKeyStorePassword();
if (password == null) {
return false;
}
newState.setPassword(password);
currentState.append(newState);
kseFrame.updateControls(true);
return true;
}
use of org.kse.crypto.Password in project keystore-explorer by kaikramer.
the class OpenCaCertificatesAction method doAction.
/**
* Do action.
*/
@Override
protected void doAction() {
File caCertificatesFile = applicationSettings.getCaCertificatesFile();
if (caCertificatesFile.isFile()) {
openKeyStore(caCertificatesFile, AuthorityCertificates.CACERTS_DEFAULT_PWD);
return;
}
int selected = JOptionPane.showConfirmDialog(frame, res.getString("OpenCaCertificatesAction.NoCaCertificatesKeyStoreCreate.message"), res.getString("OpenCaCertificatesAction.OpenCaCertificatesKeyStore.Title"), JOptionPane.YES_NO_OPTION);
if (selected != JOptionPane.YES_OPTION) {
return;
}
try {
DNewKeyStoreType dNewKeyStoreType = new DNewKeyStoreType(frame);
dNewKeyStoreType.setLocationRelativeTo(frame);
dNewKeyStoreType.setVisible(true);
KeyStoreType keyStoreType = dNewKeyStoreType.getKeyStoreType();
if (keyStoreType == null) {
return;
}
Password password = getNewKeyStorePassword();
if (password == null) {
return;
}
KeyStore caCertificatesKeyStore = KeyStoreUtil.create(keyStoreType);
KeyStoreUtil.save(caCertificatesKeyStore, caCertificatesFile, password);
kseFrame.addKeyStore(caCertificatesKeyStore, caCertificatesFile, password);
} catch (Exception ex) {
DError.displayError(frame, ex);
}
}
use of org.kse.crypto.Password in project keystore-explorer by kaikramer.
the class KeyStoreState method createBasisForNextState.
/**
* Create the basis for the next state based on this one. Makes a copy of
* the current state excluding its position in the history.
*
* @param action
* The action responsible for the creation of the next state
* @return Next state
* @throws CryptoException
* If underlying KeyStore could not be copied
*/
public KeyStoreState createBasisForNextState(HistoryAction action) throws CryptoException {
KeyStoreState copy = new KeyStoreState();
copy.history = this.history;
copy.keyStore = KeyStoreUtil.copy(this.keyStore);
if (this.password != null) {
// Copy as may be cleared
copy.password = new Password(this.password);
}
HashMap<String, Password> keyPairPasswordsCopy = new HashMap<String, Password>();
for (String alias : entryPasswords.keySet()) {
keyPairPasswordsCopy.put(alias, new Password(entryPasswords.get(alias)));
}
copy.entryPasswords = keyPairPasswordsCopy;
copy.action = action;
return copy;
}
use of org.kse.crypto.Password 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.crypto.Password in project keystore-explorer by kaikramer.
the class DExportKeyPair method exportPressed.
private void exportPressed() {
Password firstPassword;
if (jpfPassword instanceof JPasswordQualityField) {
char[] firstPasswordChars = ((JPasswordQualityField) jpfPassword).getPassword();
if (firstPasswordChars == null) {
JOptionPane.showMessageDialog(this, res.getString("DExportKeyPair.MinimumPasswordQualityNotMet.message"), res.getString("DExportKeyPair.Simple.Title"), JOptionPane.WARNING_MESSAGE);
return;
}
firstPassword = new Password(firstPasswordChars);
} else {
firstPassword = new Password(((JPasswordField) jpfPassword).getPassword());
}
Password confirmPassword = new Password(jpfConfirmPassword.getPassword());
if (firstPassword.equals(confirmPassword)) {
exportPassword = firstPassword;
} else {
JOptionPane.showMessageDialog(this, res.getString("DExportKeyPair.PasswordsNoMatch.message"), res.getString("DExportKeyPair.Simple.Title"), JOptionPane.WARNING_MESSAGE);
return;
}
String exportFileStr = jtfExportFile.getText().trim();
if (exportFileStr.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DExportKeyPair.ExportFileRequired.message"), res.getString("DExportKeyPair.Simple.Title"), JOptionPane.WARNING_MESSAGE);
return;
}
File exportFile = new File(exportFileStr);
if (exportFile.isFile()) {
String message = MessageFormat.format(res.getString("DExportKeyPair.OverWriteExportFile.message"), exportFile);
int selected = JOptionPane.showConfirmDialog(this, message, res.getString("DExportKeyPair.Simple.Title"), JOptionPane.YES_NO_OPTION);
if (selected != JOptionPane.YES_OPTION) {
return;
}
}
this.exportFile = exportFile;
exportSelected = true;
closeDialog();
}
Aggregations