Search in sources :

Example 11 with Problem

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

the class DImportKeyPairPvk method createLoadPvkProblem.

private Problem createLoadPvkProblem(Exception exception, File pvkFile) {
    String problemStr = null;
    ArrayList<String> causeList = new ArrayList<String>();
    if (jcbEncrypted.isSelected()) {
        problemStr = MessageFormat.format(res.getString("DImportKeyPairPvk.NoLoadEncryptedPvk.Problem"), pvkFile.getName());
        causeList.add(res.getString("DImportKeyPairPvk.PasswordIncorrectPvk.Cause"));
    } else {
        problemStr = MessageFormat.format(res.getString("DImportKeyPairPvk.NoLoadUnencryptedPvk.Problem"), pvkFile.getName());
    }
    causeList.add(res.getString("DImportKeyPairPvk.NotPvk.Cause"));
    causeList.add(res.getString("DImportKeyPairPvk.CorruptedPvk.Cause"));
    String[] causes = causeList.toArray(new String[causeList.size()]);
    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 12 with Problem

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

the class DImportKeyPairPvk method createLoadCertsProblem.

private Problem createLoadCertsProblem(Exception exception, File certsFile) {
    String problemStr = MessageFormat.format(res.getString("DImportKeyPairPvk.NoLoadCerts.Problem"), certsFile.getName());
    String[] causes = new String[] { res.getString("DImportKeyPairPvk.NotCerts.Cause"), res.getString("DImportKeyPairPvk.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 13 with Problem

use of org.kse.gui.error.Problem 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 14 with Problem

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

Example 15 with Problem

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

the class KeyStoreExplorerAction method unlockEntry.

/**
 * Unlock a key or key pair entry. Updates the KeyStore history with the
 * password.
 *
 * @param alias
 *            Entry's alias
 * @param state
 *            KeyStore state
 * @return Key pair password if successful, null otherwise
 */
protected Password unlockEntry(String alias, KeyStoreState state) {
    try {
        KeyStore keyStore = state.getKeyStore();
        DGetPassword dGetPassword = new DGetPassword(frame, MessageFormat.format(res.getString("KeyStoreExplorerAction.UnlockEntry.Title"), alias));
        dGetPassword.setLocationRelativeTo(frame);
        dGetPassword.setVisible(true);
        Password password = dGetPassword.getPassword();
        if (password == null) {
            return null;
        }
        // Test password is correct
        keyStore.getKey(alias, password.toCharArray());
        state.setEntryPassword(alias, password);
        kseFrame.updateControls(true);
        return password;
    } catch (GeneralSecurityException ex) {
        String problemStr = MessageFormat.format(res.getString("KeyStoreExplorerAction.NoUnlockEntry.Problem"), alias);
        String[] causes = new String[] { res.getString("KeyStoreExplorerAction.PasswordIncorrectEntry.Cause") };
        Problem problem = new Problem(problemStr, causes, ex);
        DProblem dProblem = new DProblem(frame, res.getString("KeyStoreExplorerAction.ProblemUnlockingEntry.Title"), problem);
        dProblem.setLocationRelativeTo(frame);
        dProblem.setVisible(true);
        return null;
    }
}
Also used : DGetPassword(org.kse.gui.password.DGetPassword) GeneralSecurityException(java.security.GeneralSecurityException) Problem(org.kse.gui.error.Problem) DProblem(org.kse.gui.error.DProblem) KeyStore(java.security.KeyStore) DProblem(org.kse.gui.error.DProblem) DGetNewPassword(org.kse.gui.password.DGetNewPassword) DGetPassword(org.kse.gui.password.DGetPassword) 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