Search in sources :

Example 11 with DProblem

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

Example 12 with DProblem

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

the class ExamineClipboardAction method showCrl.

private void showCrl(InputStream is) {
    if (is == null) {
        return;
    }
    X509CRL crl = null;
    try {
        crl = X509CertUtil.loadCRL(is);
    } catch (Exception ex) {
        String problemStr = res.getString("ExamineClipboardAction.NoOpenCrl.Problem");
        String[] causes = new String[] { res.getString("ExamineClipboardAction.NotCrl.Cause"), res.getString("ExamineClipboardAction.CorruptedCrl.Cause") };
        Problem problem = new Problem(problemStr, causes, ex);
        DProblem dProblem = new DProblem(frame, res.getString("ExamineClipboardAction.ProblemOpeningCrl.Title"), problem);
        dProblem.setLocationRelativeTo(frame);
        dProblem.setVisible(true);
    }
    if (crl != null) {
        DViewCrl dViewCrl = new DViewCrl(frame, res.getString("ExamineClipboardAction.CrlDetails.Title"), crl);
        dViewCrl.setLocationRelativeTo(frame);
        dViewCrl.setVisible(true);
    }
}
Also used : X509CRL(java.security.cert.X509CRL) Problem(org.kse.gui.error.Problem) DProblem(org.kse.gui.error.DProblem) CryptoException(org.kse.crypto.CryptoException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) DProblem(org.kse.gui.error.DProblem) DViewCrl(org.kse.gui.dialogs.DViewCrl)

Example 13 with DProblem

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

the class ExamineClipboardAction method showCsr.

private void showCsr(InputStream is, CryptoFileType fileType) {
    if (is == null) {
        return;
    }
    try {
        PKCS10CertificationRequest pkcs10Csr = null;
        Spkac spkacCsr = null;
        try {
            if (fileType == CryptoFileType.PKCS10_CSR) {
                pkcs10Csr = Pkcs10Util.loadCsr(is);
            } else if (fileType == CryptoFileType.SPKAC_CSR) {
                spkacCsr = new Spkac(is);
            }
        } catch (Exception ex) {
            String problemStr = res.getString("ExamineClipboardAction.NoOpenCsr.Problem");
            String[] causes = new String[] { res.getString("ExamineClipboardAction.NotCsr.Cause"), res.getString("ExamineClipboardAction.CorruptedCsr.Cause") };
            Problem problem = new Problem(problemStr, causes, ex);
            DProblem dProblem = new DProblem(frame, res.getString("ExamineClipboardAction.ProblemOpeningCsr.Title"), problem);
            dProblem.setLocationRelativeTo(frame);
            dProblem.setVisible(true);
            return;
        }
        if (pkcs10Csr != null) {
            DViewCsr dViewCsr = new DViewCsr(frame, res.getString("ExamineClipboardAction.CsrDetails.Title"), pkcs10Csr);
            dViewCsr.setLocationRelativeTo(frame);
            dViewCsr.setVisible(true);
        } else {
            DViewCsr dViewCsr = new DViewCsr(frame, res.getString("ExamineClipboardAction.CsrDetails.Title"), spkacCsr);
            dViewCsr.setLocationRelativeTo(frame);
            dViewCsr.setVisible(true);
        }
    } catch (Exception ex) {
        DError.displayError(frame, ex);
    }
}
Also used : PKCS10CertificationRequest(org.bouncycastle.pkcs.PKCS10CertificationRequest) DViewCsr(org.kse.gui.dialogs.DViewCsr) Spkac(org.kse.crypto.csr.spkac.Spkac) Problem(org.kse.gui.error.Problem) DProblem(org.kse.gui.error.DProblem) CryptoException(org.kse.crypto.CryptoException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) DProblem(org.kse.gui.error.DProblem)

Example 14 with DProblem

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

the class ExamineFileAction method openCsr.

private void openCsr(File file, CryptoFileType fileType) throws CryptoException {
    if (file == null) {
        return;
    }
    PKCS10CertificationRequest pkcs10Csr = null;
    Spkac spkacCsr = null;
    try {
        if (fileType == CryptoFileType.PKCS10_CSR) {
            pkcs10Csr = Pkcs10Util.loadCsr(new FileInputStream(file));
        } else if (fileType == CryptoFileType.SPKAC_CSR) {
            spkacCsr = new Spkac(new FileInputStream(file));
        }
    } catch (Exception ex) {
        String problemStr = MessageFormat.format(res.getString("ExamineFileAction.NoOpenCsr.Problem"), file.getName());
        String[] causes = new String[] { res.getString("ExamineFileAction.NotCsr.Cause"), res.getString("ExamineFileAction.CorruptedCsr.Cause") };
        Problem problem = new Problem(problemStr, causes, ex);
        DProblem dProblem = new DProblem(frame, res.getString("ExamineFileAction.ProblemOpeningCsr.Title"), problem);
        dProblem.setLocationRelativeTo(frame);
        dProblem.setVisible(true);
        return;
    }
    if (pkcs10Csr != null) {
        DViewCsr dViewCsr = new DViewCsr(frame, MessageFormat.format(res.getString("ExamineFileAction.CsrDetailsFile.Title"), file.getName()), pkcs10Csr);
        dViewCsr.setLocationRelativeTo(frame);
        dViewCsr.setVisible(true);
    } else {
        DViewCsr dViewCsr = new DViewCsr(frame, MessageFormat.format(res.getString("ExamineFileAction.CsrDetailsFile.Title"), file.getName()), spkacCsr);
        dViewCsr.setLocationRelativeTo(frame);
        dViewCsr.setVisible(true);
    }
}
Also used : PKCS10CertificationRequest(org.bouncycastle.pkcs.PKCS10CertificationRequest) DViewCsr(org.kse.gui.dialogs.DViewCsr) Spkac(org.kse.crypto.csr.spkac.Spkac) Problem(org.kse.gui.error.Problem) DProblem(org.kse.gui.error.DProblem) FileInputStream(java.io.FileInputStream) CryptoException(org.kse.crypto.CryptoException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) DProblem(org.kse.gui.error.DProblem)

Example 15 with DProblem

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

the class ExamineFileAction method openCrl.

private void openCrl(File crlFile) {
    if (crlFile == null) {
        return;
    }
    X509CRL crl = null;
    try {
        crl = X509CertUtil.loadCRL(new FileInputStream(crlFile));
    } catch (Exception ex) {
        String problemStr = MessageFormat.format(res.getString("ExamineFileAction.NoOpenCrl.Problem"), crlFile.getName());
        String[] causes = new String[] { res.getString("ExamineFileAction.NotCrl.Cause"), res.getString("ExamineFileAction.CorruptedCrl.Cause") };
        Problem problem = new Problem(problemStr, causes, ex);
        DProblem dProblem = new DProblem(frame, res.getString("ExamineFileAction.ProblemOpeningCrl.Title"), problem);
        dProblem.setLocationRelativeTo(frame);
        dProblem.setVisible(true);
    }
    if (crl != null) {
        DViewCrl dViewCrl = new DViewCrl(frame, MessageFormat.format(res.getString("ExamineFileAction.CrlDetailsFile.Title"), crlFile.getName()), crl);
        dViewCrl.setLocationRelativeTo(frame);
        dViewCrl.setVisible(true);
    }
}
Also used : X509CRL(java.security.cert.X509CRL) Problem(org.kse.gui.error.Problem) DProblem(org.kse.gui.error.DProblem) FileInputStream(java.io.FileInputStream) CryptoException(org.kse.crypto.CryptoException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) DProblem(org.kse.gui.error.DProblem) DViewCrl(org.kse.gui.dialogs.DViewCrl)

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