Search in sources :

Example 6 with DProblem

use of org.kse.gui.error.DProblem 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 DProblem

use of org.kse.gui.error.DProblem 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 DProblem

use of org.kse.gui.error.DProblem 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)

Example 9 with DProblem

use of org.kse.gui.error.DProblem in project keystore-explorer by kaikramer.

the class DSignMidlet method okPressed.

private void okPressed() {
    String inputJad = jtfInputJad.getText().trim();
    if (inputJad.length() == 0) {
        JOptionPane.showMessageDialog(this, res.getString("DSignMidlet.InputJadRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
        return;
    }
    File inputJadFile = new File(inputJad);
    if (!inputJadFile.isFile()) {
        JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DSignMidlet.InputJadNotFile.message"), inputJadFile), getTitle(), JOptionPane.WARNING_MESSAGE);
        return;
    }
    try {
        MidletSigner.readJadFile(inputJadFile);
    } catch (IOException ex) {
        String problemStr = MessageFormat.format(res.getString("DSignMidlet.NoOpenJad.Problem"), inputJadFile.getName());
        String[] causes = new String[] { res.getString("DSignMidlet.NotJad.Cause"), res.getString("DSignMidlet.CorruptedJad.Cause") };
        Problem problem = new Problem(problemStr, causes, ex);
        DProblem dProblem = new DProblem(this, res.getString("DSignMidlet.ProblemOpeningJad.Title"), problem);
        dProblem.setLocationRelativeTo(this);
        dProblem.setVisible(true);
        return;
    }
    boolean signDirectly = jcbSignDirectly.isSelected();
    File outputJadFile;
    if (signDirectly) {
        outputJadFile = inputJadFile;
    } else {
        String outputJad = jtfOutputJad.getText().trim();
        if (outputJad.length() == 0) {
            JOptionPane.showMessageDialog(this, res.getString("DSignMidlet.OutputJadRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
            return;
        }
        outputJadFile = new File(outputJad);
    }
    String jar = jtfJar.getText().trim();
    if (jar.length() == 0) {
        JOptionPane.showMessageDialog(this, res.getString("DSignMidlet.JarRequired.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
        return;
    }
    File jarFile = new File(jar);
    if (!jarFile.isFile()) {
        JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DSignMidlet.JarNotFile.message"), jarFile), getTitle(), JOptionPane.WARNING_MESSAGE);
        return;
    }
    JarFile jarFileTest = null;
    try {
        jarFileTest = new JarFile(jarFile);
    } catch (IOException ex) {
        String problemStr = MessageFormat.format(res.getString("DSignMidlet.NoOpenJar.Problem"), jarFile.getName());
        String[] causes = new String[] { res.getString("DSignMidlet.NotJar.Cause"), res.getString("DSignMidlet.CorruptedJar.Cause") };
        Problem problem = new Problem(problemStr, causes, ex);
        DProblem dProblem = new DProblem(this, res.getString("DSignMidlet.ProblemOpeningJar.Title"), problem);
        dProblem.setLocationRelativeTo(this);
        dProblem.setVisible(true);
        return;
    } finally {
        IOUtils.closeQuietly(jarFileTest);
    }
    if (!signDirectly) {
        if (outputJadFile.isFile()) {
            String message = MessageFormat.format(res.getString("DSignMidlet.OverWriteOutputJadFile.message"), outputJadFile);
            int selected = JOptionPane.showConfirmDialog(this, message, getTitle(), JOptionPane.YES_NO_OPTION);
            if (selected != JOptionPane.YES_OPTION) {
                return;
            }
        }
    }
    this.inputJadFile = inputJadFile;
    this.outputJadFile = outputJadFile;
    this.jarFile = jarFile;
    closeDialog();
}
Also used : Problem(org.kse.gui.error.Problem) DProblem(org.kse.gui.error.DProblem) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File) DProblem(org.kse.gui.error.DProblem)

Example 10 with DProblem

use of org.kse.gui.error.DProblem in project keystore-explorer by kaikramer.

the class OpenAction method showErrorMessage.

private int showErrorMessage(File keyStoreFile, KeyStoreLoadException klex) {
    String problemStr = MessageFormat.format(res.getString("OpenAction.NoOpenKeyStore.Problem"), klex.getKeyStoreType().friendly(), keyStoreFile.getName());
    String[] causes = new String[] { res.getString("OpenAction.PasswordIncorrectKeyStore.Cause"), res.getString("OpenAction.CorruptedKeyStore.Cause") };
    Problem problem = new Problem(problemStr, causes, klex);
    DProblem dProblem = new DProblem(frame, res.getString("OpenAction.ProblemOpeningKeyStore.Title"), problem);
    dProblem.setLocationRelativeTo(frame);
    dProblem.setVisible(true);
    int choice = JOptionPane.showConfirmDialog(frame, res.getString("OpenAction.TryAgain.message"), res.getString("OpenAction.TryAgain.Title"), JOptionPane.YES_NO_OPTION);
    return choice;
}
Also used : DProblem(org.kse.gui.error.DProblem) Problem(org.kse.gui.error.Problem) DProblem(org.kse.gui.error.DProblem)

Aggregations

DProblem (org.kse.gui.error.DProblem)22 Problem (org.kse.gui.error.Problem)22 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 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 KeyStoreHistory (org.kse.utilities.history.KeyStoreHistory)3