use of org.kse.crypto.Password in project keystore-explorer by kaikramer.
the class DExportPrivateKeyOpenSsl method exportPressed.
private void exportPressed() {
encrypt = jcbEncrypt.isSelected();
if (encrypt) {
pbeAlgorithm = (OpenSslPbeType) jcbPbeAlg.getSelectedItem();
Password firstPassword;
if (jpfPassword instanceof JPasswordQualityField) {
char[] firstPasswordChars = ((JPasswordQualityField) jpfPassword).getPassword();
if (firstPasswordChars == null) {
JOptionPane.showMessageDialog(this, res.getString("DExportPrivateKeyOpenSsl.MinimumPasswordQualityNotMet.message"), res.getString("DExportPrivateKeyOpenSsl.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("DExportPrivateKeyOpenSsl.PasswordsNoMatch.message"), res.getString("DExportPrivateKeyOpenSsl.Simple.Title"), JOptionPane.WARNING_MESSAGE);
return;
}
}
pemEncode = jcbExportPem.isSelected();
String exportFileChars = jtfExportFile.getText().trim();
if (exportFileChars.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DExportPrivateKeyOpenSsl.ExportFileRequired.message"), res.getString("DExportPrivateKeyOpenSsl.Simple.Title"), JOptionPane.WARNING_MESSAGE);
return;
}
File exportFile = new File(exportFileChars);
if (exportFile.isFile()) {
String message = MessageFormat.format(res.getString("DExportPrivateKeyOpenSsl.OverWriteExportFile.message"), exportFile);
int selected = JOptionPane.showConfirmDialog(this, message, res.getString("DExportPrivateKeyOpenSsl.Simple.Title"), JOptionPane.YES_NO_OPTION);
if (selected != JOptionPane.YES_OPTION) {
return;
}
}
this.exportFile = exportFile;
exportSelected = true;
closeDialog();
}
use of org.kse.crypto.Password in project keystore-explorer by kaikramer.
the class DExportPrivateKeyPkcs8 method exportPressed.
private void exportPressed() {
encrypt = jcbEncrypt.isSelected();
if (encrypt) {
pbeAlgorithm = (Pkcs8PbeType) jcbPbeAlg.getSelectedItem();
Password firstPassword;
if (jpfPassword instanceof JPasswordQualityField) {
char[] firstPasswordChars = ((JPasswordQualityField) jpfPassword).getPassword();
if (firstPasswordChars == null) {
JOptionPane.showMessageDialog(this, res.getString("DExportPrivateKeyPkcs8.MinimumPasswordQualityNotMet.message"), res.getString("DExportPrivateKeyPkcs8.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("DExportPrivateKeyPkcs8.PasswordsNoMatch.message"), res.getString("DExportPrivateKeyPkcs8.Simple.Title"), JOptionPane.WARNING_MESSAGE);
return;
}
}
pemEncode = jcbExportPem.isSelected();
String exportFileStr = jtfExportFile.getText().trim();
if (exportFileStr.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DExportPrivateKeyPkcs8.ExportFileRequired.message"), res.getString("DExportPrivateKeyPkcs8.Simple.Title"), JOptionPane.WARNING_MESSAGE);
return;
}
File exportFile = new File(exportFileStr);
if (exportFile.isFile()) {
String message = MessageFormat.format(res.getString("DExportPrivateKeyPkcs8.OverWriteExportFile.message"), exportFile);
int selected = JOptionPane.showConfirmDialog(this, message, res.getString("DExportPrivateKeyPkcs8.Simple.Title"), JOptionPane.YES_NO_OPTION);
if (selected != JOptionPane.YES_OPTION) {
return;
}
}
this.exportFile = exportFile;
exportSelected = true;
closeDialog();
}
use of org.kse.crypto.Password in project keystore-explorer by kaikramer.
the class DExamineSsl method okPressed.
private void okPressed() {
String sslHost = ((String) jcbSslHost.getSelectedItem()).trim();
if (sslHost.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DExamineSsl.SslHostReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
String sslPortStr = ((String) jcbSslPort.getSelectedItem()).trim();
if (sslPortStr.length() == 0) {
JOptionPane.showMessageDialog(this, res.getString("DExamineSsl.SslPortReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
int sslPort = 0;
try {
sslPort = Integer.parseInt(sslPortStr);
if (sslPort < 1) {
JOptionPane.showMessageDialog(this, res.getString("DExamineSsl.PositiveIntegerSslPortReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(this, res.getString("DExamineSsl.PositiveIntegerSslPortReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
this.sslHost = sslHost;
this.sslPort = sslPort;
// check selected key store
if (useClientAuth()) {
KeyStoreHistory ksh = (KeyStoreHistory) jcbKeyStore.getSelectedItem();
if (ksh == null) {
JOptionPane.showMessageDialog(this, res.getString("DExamineSsl.NoKeyStoreSelected.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
Password keyStorePassword = ksh.getCurrentState().getPassword();
if (keyStorePassword == null && ksh.getCurrentState().getType().hasEntryPasswords()) {
JOptionPane.showMessageDialog(this, res.getString("DExamineSsl.NoPasswordSetForKeyStore.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return;
}
}
// save host/port in preferences
applicationSettings.addSslHost(sslHost);
applicationSettings.addSslPort(sslPortStr);
cancelled = false;
closeDialog();
}
use of org.kse.crypto.Password in project keystore-explorer by kaikramer.
the class KseFrame method dragSelectedEntry.
/**
* Get a the selected entry as a drag entry for DnD.
*
* @return Drag entry or null if entry could not be dragged
*/
public DragEntry dragSelectedEntry() {
try {
KeyStoreHistory history = getActiveKeyStoreHistory();
if (history == null) {
// No KeyStore to drag from
return null;
}
KeyStoreState currentState = history.getCurrentState();
KeyStore keyStore = currentState.getKeyStore();
String alias = getSelectedEntryAlias();
KeyStoreType type = KeyStoreType.resolveJce(keyStore.getType());
if (alias == null) {
// No selected entry to drag
return null;
}
if (KeyStoreUtil.isKeyEntry(alias, keyStore)) {
JOptionPane.showMessageDialog(frame, res.getString("KseFrame.NoDragKeyEntry.message"), KSE.getApplicationName(), JOptionPane.WARNING_MESSAGE);
return null;
}
if (KeyStoreUtil.isKeyPairEntry(alias, keyStore) && type.hasExportablePrivateKeys()) {
// Otherwise entry must already be unlocked to get password
Password password = currentState.getEntryPassword(alias);
if (password == null && type.hasEntryPasswords()) {
JOptionPane.showMessageDialog(frame, res.getString("KseFrame.NoDragLockedKeyPairEntry.message"), KSE.getApplicationName(), JOptionPane.WARNING_MESSAGE);
return null;
}
PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, password.toCharArray());
Certificate[] certificateChain = keyStore.getCertificateChain(alias);
return new DragKeyPairEntry(alias, privateKey, password, certificateChain);
} else {
Certificate trustedCertificate = keyStore.getCertificate(alias);
return new DragTrustedCertificateEntry(alias, trustedCertificate);
}
} catch (Exception ex) {
DError.displayError(frame, ex);
return null;
}
}
use of org.kse.crypto.Password in project keystore-explorer by kaikramer.
the class CutAction method bufferSelectedEntry.
private BufferEntry bufferSelectedEntry() {
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStoreState currentState = history.getCurrentState();
String alias = kseFrame.getSelectedEntryAlias();
if (alias == null) {
return null;
}
BufferEntry bufferEntry = null;
KeyStore keyStore = currentState.getKeyStore();
if (KeyStoreUtil.isKeyEntry(alias, keyStore)) {
Password password = getEntryPassword(alias, currentState);
if (password == null) {
return null;
}
Key key = keyStore.getKey(alias, password.toCharArray());
if (key instanceof PrivateKey) {
JOptionPane.showMessageDialog(frame, res.getString("CutAction.NoCutKeyEntryWithPrivateKey.message"), res.getString("CutAction.Cut.Title"), JOptionPane.WARNING_MESSAGE);
return null;
}
bufferEntry = new KeyBufferEntry(alias, true, key, password);
} else if (KeyStoreUtil.isTrustedCertificateEntry(alias, keyStore)) {
Certificate certificate = keyStore.getCertificate(alias);
bufferEntry = new TrustedCertificateBufferEntry(alias, true, certificate);
} else if (KeyStoreUtil.isKeyPairEntry(alias, keyStore)) {
Password password = getEntryPassword(alias, currentState);
if (password == null) {
return null;
}
PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, password.toCharArray());
Certificate[] certificateChain = keyStore.getCertificateChain(alias);
bufferEntry = new KeyPairBufferEntry(alias, true, privateKey, password, certificateChain);
}
KeyStoreState newState = currentState.createBasisForNextState(this);
keyStore = newState.getKeyStore();
keyStore.deleteEntry(alias);
newState.removeEntryPassword(alias);
currentState.append(newState);
return bufferEntry;
} catch (Exception ex) {
DError.displayError(frame, ex);
return null;
}
}
Aggregations