Search in sources :

Example 6 with Problem

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);
    }
}
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 7 with Problem

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;
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) Problem(org.kse.gui.error.Problem) DProblem(org.kse.gui.error.DProblem) File(java.io.File) X509Certificate(java.security.cert.X509Certificate) FileInputStream(java.io.FileInputStream) CryptoException(org.kse.crypto.CryptoException) PrivateKeyUnencryptedException(org.kse.crypto.privatekey.PrivateKeyUnencryptedException) PrivateKeyPbeNotSupportedException(org.kse.crypto.privatekey.PrivateKeyPbeNotSupportedException) FileNotFoundException(java.io.FileNotFoundException) PrivateKeyEncryptedException(org.kse.crypto.privatekey.PrivateKeyEncryptedException) DProblem(org.kse.gui.error.DProblem)

Example 8 with Problem

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;
}
Also used : ArrayList(java.util.ArrayList) Problem(org.kse.gui.error.Problem) DProblem(org.kse.gui.error.DProblem)

Example 9 with 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;
}
Also used : Problem(org.kse.gui.error.Problem) DProblem(org.kse.gui.error.DProblem)

Example 10 with 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;
    }
}
Also used : PrivateKeyEncryptedException(org.kse.crypto.privatekey.PrivateKeyEncryptedException) PrivateKeyUnencryptedException(org.kse.crypto.privatekey.PrivateKeyUnencryptedException) PrivateKey(java.security.PrivateKey) DViewPrivateKey(org.kse.gui.dialogs.DViewPrivateKey) FileNotFoundException(java.io.FileNotFoundException) PrivateKeyPbeNotSupportedException(org.kse.crypto.privatekey.PrivateKeyPbeNotSupportedException) Problem(org.kse.gui.error.Problem) DProblem(org.kse.gui.error.DProblem) File(java.io.File) FileInputStream(java.io.FileInputStream) CryptoException(org.kse.crypto.CryptoException) PrivateKeyUnencryptedException(org.kse.crypto.privatekey.PrivateKeyUnencryptedException) PrivateKeyPbeNotSupportedException(org.kse.crypto.privatekey.PrivateKeyPbeNotSupportedException) FileNotFoundException(java.io.FileNotFoundException) PrivateKeyEncryptedException(org.kse.crypto.privatekey.PrivateKeyEncryptedException) DProblem(org.kse.gui.error.DProblem) Password(org.kse.crypto.Password)

Aggregations

DProblem (org.kse.gui.error.DProblem)29 Problem (org.kse.gui.error.Problem)29 CryptoException (org.kse.crypto.CryptoException)12 File (java.io.File)11 FileNotFoundException (java.io.FileNotFoundException)11 FileInputStream (java.io.FileInputStream)9 Password (org.kse.crypto.Password)9 IOException (java.io.IOException)7 X509Certificate (java.security.cert.X509Certificate)7 KeyStore (java.security.KeyStore)6 PrivateKeyEncryptedException (org.kse.crypto.privatekey.PrivateKeyEncryptedException)6 PrivateKeyUnencryptedException (org.kse.crypto.privatekey.PrivateKeyUnencryptedException)6 PrivateKey (java.security.PrivateKey)5 ArrayList (java.util.ArrayList)4 PrivateKeyPbeNotSupportedException (org.kse.crypto.privatekey.PrivateKeyPbeNotSupportedException)4 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)3 GeneralSecurityException (java.security.GeneralSecurityException)3 Certificate (java.security.cert.Certificate)3 PKCS10CertificationRequest (org.bouncycastle.pkcs.PKCS10CertificationRequest)3 Spkac (org.kse.crypto.csr.spkac.Spkac)3