Search in sources :

Example 1 with DGetPassword

use of org.kse.gui.password.DGetPassword in project keystore-explorer by kaikramer.

the class AuthorityCertificatesAction method loadCaCertificatesKeyStore.

private KeyStore loadCaCertificatesKeyStore() {
    File caCertificatesFile = applicationSettings.getCaCertificatesFile();
    KeyStore caCertificatesKeyStore = null;
    try {
        // first try to open cacerts with default password
        try {
            Password password = new Password(AuthorityCertificates.CACERTS_DEFAULT_PWD.toCharArray());
            caCertificatesKeyStore = KeyStoreUtil.load(caCertificatesFile, password);
            if (caCertificatesFile != null) {
                return caCertificatesKeyStore;
            }
        } catch (KeyStoreLoadException ex) {
        // not default password, continue with password dialog
        }
        DGetPassword dGetPassword = new DGetPassword(frame, res.getString("AuthorityCertificatesAction.CaCertificatesKeyStorePassword.Title"));
        dGetPassword.setLocationRelativeTo(frame);
        dGetPassword.setVisible(true);
        Password password = dGetPassword.getPassword();
        if (password == null) {
            return null;
        }
        try {
            caCertificatesKeyStore = KeyStoreUtil.load(caCertificatesFile, password);
        } catch (KeyStoreLoadException ex) {
            String problemStr = MessageFormat.format(res.getString("AuthorityCertificatesAction.NoOpenCaCertificatesKeyStore.Problem"), ex.getKeyStoreType(), caCertificatesFile.getName());
            String[] causes = new String[] { res.getString("AuthorityCertificatesAction.PasswordIncorrectKeyStore.Cause"), res.getString("AuthorityCertificatesAction.CorruptedKeyStore.Cause") };
            Problem problem = new Problem(problemStr, causes, ex);
            DProblem dProblem = new DProblem(frame, res.getString("AuthorityCertificatesAction.ProblemOpeningCaCertificatesKeyStore.Title"), problem);
            dProblem.setLocationRelativeTo(frame);
            dProblem.setVisible(true);
            return null;
        }
        if (caCertificatesKeyStore == null) {
            JOptionPane.showMessageDialog(frame, MessageFormat.format(res.getString("AuthorityCertificatesAction.FileNotRecognisedType.message"), caCertificatesFile.getName()), res.getString("AuthorityCertificatesAction.OpenCaCertificatesKeyStore.Title"), JOptionPane.WARNING_MESSAGE);
            return null;
        }
        return caCertificatesKeyStore;
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(frame, MessageFormat.format(res.getString("AuthorityCertificatesAction.NoReadFile.message"), caCertificatesFile), res.getString("AuthorityCertificatesAction.OpenCaCertificatesKeyStore.Title"), JOptionPane.WARNING_MESSAGE);
        return null;
    } catch (Exception ex) {
        DError.displayError(frame, ex);
        return null;
    }
}
Also used : DGetPassword(org.kse.gui.password.DGetPassword) KeyStoreLoadException(org.kse.crypto.keystore.KeyStoreLoadException) FileNotFoundException(java.io.FileNotFoundException) DProblem(org.kse.gui.error.DProblem) Problem(org.kse.gui.error.Problem) File(java.io.File) KeyStore(java.security.KeyStore) DProblem(org.kse.gui.error.DProblem) FileNotFoundException(java.io.FileNotFoundException) CryptoException(org.kse.crypto.CryptoException) KeyStoreLoadException(org.kse.crypto.keystore.KeyStoreLoadException) DGetPassword(org.kse.gui.password.DGetPassword) Password(org.kse.crypto.Password)

Example 2 with DGetPassword

use of org.kse.gui.password.DGetPassword in project keystore-explorer by kaikramer.

the class OpenAction method showPasswordDialog.

private Password showPasswordDialog(File keyStoreFile) {
    DGetPassword dGetPassword = new DGetPassword(frame, MessageFormat.format(res.getString("OpenAction.UnlockKeyStore.Title"), keyStoreFile.getName()));
    dGetPassword.setLocationRelativeTo(frame);
    dGetPassword.setVisible(true);
    return dGetPassword.getPassword();
}
Also used : DGetPassword(org.kse.gui.password.DGetPassword)

Example 3 with DGetPassword

use of org.kse.gui.password.DGetPassword 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 4 with DGetPassword

use of org.kse.gui.password.DGetPassword in project keystore-explorer by kaikramer.

the class ExamineFileAction method getPassword.

private Password getPassword(File file) {
    DGetPassword dGetPassword = new DGetPassword(frame, MessageFormat.format(res.getString("ExamineFileAction.EnterPassword.Title"), file.getName()));
    dGetPassword.setLocationRelativeTo(frame);
    dGetPassword.setVisible(true);
    return dGetPassword.getPassword();
}
Also used : DGetPassword(org.kse.gui.password.DGetPassword)

Example 5 with DGetPassword

use of org.kse.gui.password.DGetPassword in project keystore-explorer by kaikramer.

the class PasswordCallbackHandler method handlePasswordCallback.

private void handlePasswordCallback(PasswordCallback passCb) throws UnsupportedCallbackException {
    DGetPassword dGetPassword = new DGetPassword(frame, res.getString("PasswordCallbackHandler.Title"));
    dGetPassword.setLocationRelativeTo(frame);
    dGetPassword.setVisible(true);
    Password password = dGetPassword.getPassword();
    if (password == null) {
        throw new CancellationException("Password Callback canceled by user");
    }
    passCb.setPassword(password.toCharArray());
}
Also used : DGetPassword(org.kse.gui.password.DGetPassword) CancellationException(java.util.concurrent.CancellationException) DGetPassword(org.kse.gui.password.DGetPassword) Password(org.kse.crypto.Password)

Aggregations

DGetPassword (org.kse.gui.password.DGetPassword)5 Password (org.kse.crypto.Password)3 KeyStore (java.security.KeyStore)2 DProblem (org.kse.gui.error.DProblem)2 Problem (org.kse.gui.error.Problem)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 CancellationException (java.util.concurrent.CancellationException)1 CryptoException (org.kse.crypto.CryptoException)1 KeyStoreLoadException (org.kse.crypto.keystore.KeyStoreLoadException)1 DGetNewPassword (org.kse.gui.password.DGetNewPassword)1