Search in sources :

Example 26 with KeyStoreHistory

use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.

the class SetKeyPairPasswordAction 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("SetKeyPairPasswordAction.SetKeyPairPassword.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
        Certificate[] certs = keyStore.getCertificateChain(alias);
        certs = X509CertUtil.orderX509CertChain(X509CertUtil.convertCertificates(certs));
        Key privateKey = keyStore.getKey(alias, oldPassword.toCharArray());
        keyStore.deleteEntry(alias);
        newState.removeEntryPassword(alias);
        keyStore.setKeyEntry(alias, privateKey, newPassword.toCharArray(), certs);
        if (currentState.getEntryPassword(alias) == null) {
            currentState.setEntryPassword(alias, oldPassword);
        }
        newState.setEntryPassword(alias, newPassword);
        currentState.append(newState);
        kseFrame.updateControls(true);
        JOptionPane.showMessageDialog(frame, res.getString("SetKeyPairPasswordAction.SetKeyPairPasswordSuccessful.message"), res.getString("SetKeyPairPasswordAction.SetKeyPairPassword.Title"), JOptionPane.INFORMATION_MESSAGE);
    } catch (GeneralSecurityException ex) {
        String problemStr = MessageFormat.format(res.getString("SetKeyPairPasswordAction.NoSetPasswordKeyPairEntry.Problem"), alias);
        String[] causes = new String[] { res.getString("SetKeyPairPasswordAction.PasswordIncorrectKeyPairEntry.Cause"), res.getString("SetKeyPairPasswordAction.NotSupportedAlgorithmKeyPairEntry.Cause") };
        Problem problem = new Problem(problemStr, causes, ex);
        DProblem dProblem = new DProblem(frame, res.getString("SetKeyPairPasswordAction.ProblemSettingPasswordKeyPairEntry.Title"), problem);
        dProblem.setLocationRelativeTo(frame);
        dProblem.setVisible(true);
    } catch (Exception ex) {
        DError.displayError(frame, ex);
    }
}
Also used : KeyStoreState(org.kse.utilities.history.KeyStoreState) KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) GeneralSecurityException(java.security.GeneralSecurityException) KeyStore(java.security.KeyStore) DProblem(org.kse.gui.error.DProblem) GeneralSecurityException(java.security.GeneralSecurityException) DProblem(org.kse.gui.error.DProblem) Problem(org.kse.gui.error.Problem) DChangePassword(org.kse.gui.password.DChangePassword) Key(java.security.Key) DChangePassword(org.kse.gui.password.DChangePassword) Password(org.kse.crypto.Password) Certificate(java.security.cert.Certificate)

Example 27 with KeyStoreHistory

use of org.kse.utilities.history.KeyStoreHistory 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);
    }
}
Also used : KeyStoreState(org.kse.utilities.history.KeyStoreState) KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) GeneralSecurityException(java.security.GeneralSecurityException) DProblem(org.kse.gui.error.DProblem) Problem(org.kse.gui.error.Problem) DChangePassword(org.kse.gui.password.DChangePassword) KeyStore(java.security.KeyStore) Key(java.security.Key) DProblem(org.kse.gui.error.DProblem) GeneralSecurityException(java.security.GeneralSecurityException) DChangePassword(org.kse.gui.password.DChangePassword) Password(org.kse.crypto.Password)

Example 28 with KeyStoreHistory

use of org.kse.utilities.history.KeyStoreHistory 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;
}
Also used : KeyStoreState(org.kse.utilities.history.KeyStoreState) KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) Password(org.kse.crypto.Password)

Example 29 with KeyStoreHistory

use of org.kse.utilities.history.KeyStoreHistory in project keystore-explorer by kaikramer.

the class RedoAction method doAction.

/**
 * Do action.
 */
@Override
protected void doAction() {
    try {
        KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
        history.getCurrentState().setNextStateAsCurrentState();
        kseFrame.updateControls(true);
    } catch (Exception ex) {
        DError.displayError(frame, ex);
    }
}
Also used : KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory)

Example 30 with KeyStoreHistory

use of org.kse.utilities.history.KeyStoreHistory 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();
}
Also used : KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) Password(org.kse.crypto.Password)

Aggregations

KeyStoreHistory (org.kse.utilities.history.KeyStoreHistory)60 KeyStore (java.security.KeyStore)45 KeyStoreState (org.kse.utilities.history.KeyStoreState)41 Password (org.kse.crypto.Password)31 X509Certificate (java.security.cert.X509Certificate)21 PrivateKey (java.security.PrivateKey)17 Certificate (java.security.cert.Certificate)13 Key (java.security.Key)12 CryptoException (org.kse.crypto.CryptoException)11 KeyStoreType (org.kse.crypto.keystore.KeyStoreType)11 DGetAlias (org.kse.gui.dialogs.DGetAlias)10 KeyStoreException (java.security.KeyStoreException)9 File (java.io.File)7 GeneralSecurityException (java.security.GeneralSecurityException)6 DViewCertificate (org.kse.gui.dialogs.DViewCertificate)6 DGetNewPassword (org.kse.gui.password.DGetNewPassword)6 FileNotFoundException (java.io.FileNotFoundException)5 PublicKey (java.security.PublicKey)5 Provider (java.security.Provider)4 ArrayList (java.util.ArrayList)3