Search in sources :

Example 1 with JPasswordQualityField

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

the class DExportKeyPair method exportPressed.

private void exportPressed() {
    Password firstPassword;
    if (jpfPassword instanceof JPasswordQualityField) {
        char[] firstPasswordChars = ((JPasswordQualityField) jpfPassword).getPassword();
        if (firstPasswordChars == null) {
            JOptionPane.showMessageDialog(this, res.getString("DExportKeyPair.MinimumPasswordQualityNotMet.message"), res.getString("DExportKeyPair.Simple.Title"), JOptionPane.WARNING_MESSAGE);
            return;
        }
        firstPassword = new Password(firstPasswordChars);
    } else {
        firstPassword = new Password(((JPasswordField) jpfPassword).getPassword());
    }
    Password confirmPassword = new Password(jpfConfirmPassword.getPassword());
    if (firstPassword.equals(confirmPassword)) {
        exportPassword = firstPassword;
    } else {
        JOptionPane.showMessageDialog(this, res.getString("DExportKeyPair.PasswordsNoMatch.message"), res.getString("DExportKeyPair.Simple.Title"), JOptionPane.WARNING_MESSAGE);
        return;
    }
    String exportFileStr = jtfExportFile.getText().trim();
    if (exportFileStr.length() == 0) {
        JOptionPane.showMessageDialog(this, res.getString("DExportKeyPair.ExportFileRequired.message"), res.getString("DExportKeyPair.Simple.Title"), JOptionPane.WARNING_MESSAGE);
        return;
    }
    File exportFile = new File(exportFileStr);
    if (exportFile.isFile()) {
        String message = MessageFormat.format(res.getString("DExportKeyPair.OverWriteExportFile.message"), exportFile);
        int selected = JOptionPane.showConfirmDialog(this, message, res.getString("DExportKeyPair.Simple.Title"), JOptionPane.YES_NO_OPTION);
        if (selected != JOptionPane.YES_OPTION) {
            return;
        }
    }
    this.exportFile = exportFile;
    exportSelected = true;
    closeDialog();
}
Also used : JPasswordQualityField(org.kse.gui.password.JPasswordQualityField) JPasswordField(javax.swing.JPasswordField) File(java.io.File) Password(org.kse.crypto.Password)

Example 2 with JPasswordQualityField

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

the class DExportPrivateKeyOpenSsl method exportPressed.

private void exportPressed() {
    encrypt = jcbEncrypt.isSelected();
    if (encrypt) {
        pbeAlgorithm = (OpenSslPbeType) jcbPbeAlg.getSelectedItem();
        Password firstPassword;
        if (jpfPassword instanceof JPasswordQualityField) {
            char[] firstPasswordChars = ((JPasswordQualityField) jpfPassword).getPassword();
            if (firstPasswordChars == null) {
                JOptionPane.showMessageDialog(this, res.getString("DExportPrivateKeyOpenSsl.MinimumPasswordQualityNotMet.message"), res.getString("DExportPrivateKeyOpenSsl.Simple.Title"), JOptionPane.WARNING_MESSAGE);
                return;
            }
            firstPassword = new Password(firstPasswordChars);
        } else {
            firstPassword = new Password(((JPasswordField) jpfPassword).getPassword());
        }
        Password confirmPassword = new Password(jpfConfirmPassword.getPassword());
        if (firstPassword.equals(confirmPassword)) {
            exportPassword = firstPassword;
        } else {
            JOptionPane.showMessageDialog(this, res.getString("DExportPrivateKeyOpenSsl.PasswordsNoMatch.message"), res.getString("DExportPrivateKeyOpenSsl.Simple.Title"), JOptionPane.WARNING_MESSAGE);
            return;
        }
    }
    pemEncode = jcbExportPem.isSelected();
    String exportFileChars = jtfExportFile.getText().trim();
    if (exportFileChars.length() == 0) {
        JOptionPane.showMessageDialog(this, res.getString("DExportPrivateKeyOpenSsl.ExportFileRequired.message"), res.getString("DExportPrivateKeyOpenSsl.Simple.Title"), JOptionPane.WARNING_MESSAGE);
        return;
    }
    File exportFile = new File(exportFileChars);
    if (exportFile.isFile()) {
        String message = MessageFormat.format(res.getString("DExportPrivateKeyOpenSsl.OverWriteExportFile.message"), exportFile);
        int selected = JOptionPane.showConfirmDialog(this, message, res.getString("DExportPrivateKeyOpenSsl.Simple.Title"), JOptionPane.YES_NO_OPTION);
        if (selected != JOptionPane.YES_OPTION) {
            return;
        }
    }
    this.exportFile = exportFile;
    exportSelected = true;
    closeDialog();
}
Also used : JPasswordQualityField(org.kse.gui.password.JPasswordQualityField) JPasswordField(javax.swing.JPasswordField) File(java.io.File) Password(org.kse.crypto.Password)

Example 3 with JPasswordQualityField

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

the class DExportPrivateKeyOpenSsl method initComponents.

private void initComponents() {
    GridBagConstraints gbcLbl = new GridBagConstraints();
    gbcLbl.gridx = 0;
    gbcLbl.gridwidth = 3;
    gbcLbl.gridheight = 1;
    gbcLbl.insets = new Insets(5, 5, 5, 5);
    gbcLbl.anchor = GridBagConstraints.EAST;
    GridBagConstraints gbcEdCtrl = new GridBagConstraints();
    gbcEdCtrl.gridx = 3;
    gbcEdCtrl.gridwidth = 3;
    gbcEdCtrl.gridheight = 1;
    gbcEdCtrl.insets = new Insets(5, 5, 5, 5);
    gbcEdCtrl.anchor = GridBagConstraints.WEST;
    jlEncrypt = new JLabel(res.getString("DExportPrivateKeyOpenSsl.jlEncrypt.text"));
    GridBagConstraints gbc_jlEncrypt = (GridBagConstraints) gbcLbl.clone();
    gbc_jlEncrypt.gridy = 0;
    jcbEncrypt = new JCheckBox();
    jcbEncrypt.setSelected(true);
    jcbEncrypt.setToolTipText(res.getString("DExportPrivateKeyOpenSsl.jcbEncrypt.tooltip"));
    GridBagConstraints gbc_jcbEncrypt = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jcbEncrypt.gridy = 0;
    jcbEncrypt.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent evt) {
            if (jcbEncrypt.isSelected()) {
                jcbExportPem.setSelected(true);
                jcbExportPem.setEnabled(false);
            } else {
                jcbExportPem.setEnabled(true);
            }
        }
    });
    jlPbeAlg = new JLabel(res.getString("DExportPrivateKeyOpenSsl.jlPbeAlg.text"));
    GridBagConstraints gbc_jlPbeAlg = (GridBagConstraints) gbcLbl.clone();
    gbc_jlPbeAlg.gridy = 1;
    jcbPbeAlg = new JComboBox<OpenSslPbeType>();
    populatePbeAlgs();
    jcbPbeAlg.setToolTipText(res.getString("DExportPrivateKeyOpenSsl.jcbPbeAlg.tooltip"));
    jcbPbeAlg.setSelectedIndex(0);
    GridBagConstraints gbc_jcbPbeAlg = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jcbPbeAlg.gridy = 1;
    jlPassword = new JLabel(res.getString("DExportPrivateKeyOpenSsl.jlPassword.text"));
    GridBagConstraints gbc_jlPassword = (GridBagConstraints) gbcLbl.clone();
    gbc_jlPassword.gridy = 2;
    if (passwordQualityConfig.getEnabled()) {
        if (passwordQualityConfig.getEnforced()) {
            jpfPassword = new JPasswordQualityField(15, passwordQualityConfig.getMinimumQuality());
        } else {
            jpfPassword = new JPasswordQualityField(15);
        }
    } else {
        jpfPassword = new JPasswordField(15);
    }
    jpfPassword.setToolTipText(res.getString("DExportPrivateKeyOpenSsl.jpqfPassword.tooltip"));
    GridBagConstraints gbc_jpfPassword = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jpfPassword.gridy = 2;
    jlConfirmPassword = new JLabel(res.getString("DExportPrivateKeyOpenSsl.jlConfirmPassword.text"));
    GridBagConstraints gbc_jlConfirmPassword = (GridBagConstraints) gbcLbl.clone();
    gbc_jlConfirmPassword.gridy = 3;
    jpfConfirmPassword = new JPasswordField(15);
    jpfConfirmPassword.setToolTipText(res.getString("DExportPrivateKeyOpenSsl.jpfConfirmPassword.tooltip"));
    GridBagConstraints gbc_jpfConfirmPassword = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jpfConfirmPassword.gridy = 3;
    jlExportPem = new JLabel(res.getString("DExportPrivateKeyOpenSsl.jlExportPem.text"));
    GridBagConstraints gbc_jlExportPem = (GridBagConstraints) gbcLbl.clone();
    gbc_jlExportPem.gridy = 4;
    jcbExportPem = new JCheckBox();
    jcbExportPem.setSelected(true);
    // Itinitla export setting is with
    jcbExportPem.setEnabled(false);
    // encryption - must be pem
    // export
    jcbExportPem.setToolTipText(res.getString("DExportPrivateKeyOpenSsl.jcbExportPem.tooltip"));
    GridBagConstraints gbc_jcbExportPem = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jcbExportPem.gridy = 4;
    jlExportFile = new JLabel(res.getString("DExportPrivateKeyOpenSsl.jlExportFile.text"));
    GridBagConstraints gbc_jlExportFile = (GridBagConstraints) gbcLbl.clone();
    gbc_jlExportFile.gridy = 5;
    jtfExportFile = new JTextField(30);
    jtfExportFile.setToolTipText(res.getString("DExportPrivateKeyOpenSsl.jtfExportFile.tooltip"));
    GridBagConstraints gbc_jtfExportFile = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jtfExportFile.gridy = 5;
    gbc_jtfExportFile.gridwidth = 6;
    jbBrowse = new JButton(res.getString("DExportPrivateKeyOpenSsl.jbBrowse.text"));
    jbBrowse.setToolTipText(res.getString("DExportPrivateKeyOpenSsl.jbBrowse.tooltip"));
    PlatformUtil.setMnemonic(jbBrowse, res.getString("DExportPrivateKeyOpenSsl.jbBrowse.mnemonic").charAt(0));
    GridBagConstraints gbc_jbBrowse = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jbBrowse.gridy = 5;
    gbc_jbBrowse.gridx = 9;
    jbBrowse.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DExportPrivateKeyOpenSsl.this);
                browsePressed();
            } finally {
                CursorUtil.setCursorFree(DExportPrivateKeyOpenSsl.this);
            }
        }
    });
    jpOptions = new JPanel(new GridBagLayout());
    jpOptions.setBorder(new CompoundBorder(new CompoundBorder(new EmptyBorder(5, 5, 5, 5), new EtchedBorder()), new EmptyBorder(5, 5, 5, 5)));
    jpOptions.add(jlEncrypt, gbc_jlEncrypt);
    jpOptions.add(jcbEncrypt, gbc_jcbEncrypt);
    jpOptions.add(jlPbeAlg, gbc_jlPbeAlg);
    jpOptions.add(jcbPbeAlg, gbc_jcbPbeAlg);
    jpOptions.add(jlPassword, gbc_jlPassword);
    jpOptions.add(jpfPassword, gbc_jpfPassword);
    jpOptions.add(jlConfirmPassword, gbc_jlConfirmPassword);
    jpOptions.add(jpfConfirmPassword, gbc_jpfConfirmPassword);
    jpOptions.add(jlExportPem, gbc_jlExportPem);
    jpOptions.add(jcbExportPem, gbc_jcbExportPem);
    jpOptions.add(jlExportFile, gbc_jlExportFile);
    jpOptions.add(jtfExportFile, gbc_jtfExportFile);
    jpOptions.add(jbBrowse, gbc_jbBrowse);
    jcbEncrypt.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent evt) {
            if (jcbEncrypt.isSelected()) {
                jcbPbeAlg.setEnabled(true);
                jpfPassword.setEnabled(true);
                jpfConfirmPassword.setEnabled(true);
            } else {
                jcbPbeAlg.setEnabled(false);
                jpfPassword.setEnabled(false);
                if (jpfPassword instanceof JPasswordQualityField) {
                    ((JPasswordQualityField) jpfPassword).setText("");
                } else {
                    ((JPasswordField) jpfPassword).setText("");
                }
                jpfConfirmPassword.setEnabled(false);
                jpfConfirmPassword.setText("");
            }
        }
    });
    jbExport = new JButton(res.getString("DExportPrivateKeyOpenSsl.jbExport.text"));
    PlatformUtil.setMnemonic(jbExport, res.getString("DExportPrivateKeyOpenSsl.jbExport.mnemonic").charAt(0));
    jbExport.setToolTipText(res.getString("DExportPrivateKeyOpenSsl.jbExport.tooltip"));
    jbExport.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DExportPrivateKeyOpenSsl.this);
                exportPressed();
            } finally {
                CursorUtil.setCursorFree(DExportPrivateKeyOpenSsl.this);
            }
        }
    });
    jbCancel = new JButton(res.getString("DExportPrivateKeyOpenSsl.jbCancel.text"));
    jbCancel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            cancelPressed();
        }
    });
    jbCancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CANCEL_KEY);
    jbCancel.getActionMap().put(CANCEL_KEY, new AbstractAction() {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent evt) {
            cancelPressed();
        }
    });
    jpButtons = PlatformUtil.createDialogButtonPanel(jbExport, jbCancel, false);
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(jpOptions, BorderLayout.CENTER);
    getContentPane().add(jpButtons, BorderLayout.SOUTH);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent evt) {
            closeDialog();
        }
    });
    setTitle(MessageFormat.format(res.getString("DExportPrivateKeyOpenSsl.Title"), entryAlias));
    setResizable(false);
    getRootPane().setDefaultButton(jbExport);
    populateExportFileName();
    pack();
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) ItemEvent(java.awt.event.ItemEvent) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) JTextField(javax.swing.JTextField) BorderLayout(java.awt.BorderLayout) JPasswordQualityField(org.kse.gui.password.JPasswordQualityField) ChangeListener(javax.swing.event.ChangeListener) CompoundBorder(javax.swing.border.CompoundBorder) EmptyBorder(javax.swing.border.EmptyBorder) AbstractAction(javax.swing.AbstractAction) JLabel(javax.swing.JLabel) JCheckBox(javax.swing.JCheckBox) EtchedBorder(javax.swing.border.EtchedBorder) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) JPasswordField(javax.swing.JPasswordField) WindowEvent(java.awt.event.WindowEvent) ItemListener(java.awt.event.ItemListener) OpenSslPbeType(org.kse.crypto.privatekey.OpenSslPbeType)

Example 4 with JPasswordQualityField

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

the class DExportPrivateKeyPkcs8 method initComponents.

private void initComponents() {
    GridBagConstraints gbcLbl = new GridBagConstraints();
    gbcLbl.gridx = 0;
    gbcLbl.gridwidth = 3;
    gbcLbl.gridheight = 1;
    gbcLbl.insets = new Insets(5, 5, 5, 5);
    gbcLbl.anchor = GridBagConstraints.EAST;
    GridBagConstraints gbcEdCtrl = new GridBagConstraints();
    gbcEdCtrl.gridx = 3;
    gbcEdCtrl.gridwidth = 3;
    gbcEdCtrl.gridheight = 1;
    gbcEdCtrl.insets = new Insets(5, 5, 5, 5);
    gbcEdCtrl.anchor = GridBagConstraints.WEST;
    jlEncrypt = new JLabel(res.getString("DExportPrivateKeyPkcs8.jlEncrypt.text"));
    GridBagConstraints gbc_jlEncrypt = (GridBagConstraints) gbcLbl.clone();
    gbc_jlEncrypt.gridy = 0;
    jcbEncrypt = new JCheckBox();
    jcbEncrypt.setSelected(true);
    jcbEncrypt.setToolTipText(res.getString("DExportPrivateKeyPkcs8.jcbEncrypt.tooltip"));
    GridBagConstraints gbc_jcbEncrypt = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jcbEncrypt.gridy = 0;
    jlPbeAlg = new JLabel(res.getString("DExportPrivateKeyPkcs8.jlPbeAlg.text"));
    GridBagConstraints gbc_jlPbeAlg = (GridBagConstraints) gbcLbl.clone();
    gbc_jlPbeAlg.gridy = 1;
    jcbPbeAlg = new JComboBox<Pkcs8PbeType>();
    populatePbeAlgs();
    jcbPbeAlg.setToolTipText(res.getString("DExportPrivateKeyPkcs8.jcbPbeAlg.tooltip"));
    jcbPbeAlg.setSelectedIndex(0);
    GridBagConstraints gbc_jcbPbeAlg = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jcbPbeAlg.gridy = 1;
    jlPassword = new JLabel(res.getString("DExportPrivateKeyPkcs8.jlPassword.text"));
    GridBagConstraints gbc_jlPassword = (GridBagConstraints) gbcLbl.clone();
    gbc_jlPassword.gridy = 2;
    if (passwordQualityConfig.getEnabled()) {
        if (passwordQualityConfig.getEnforced()) {
            jpfPassword = new JPasswordQualityField(15, passwordQualityConfig.getMinimumQuality());
        } else {
            jpfPassword = new JPasswordQualityField(15);
        }
    } else {
        jpfPassword = new JPasswordField(15);
    }
    jpfPassword.setToolTipText(res.getString("DExportPrivateKeyPkcs8.jpqfPassword.tooltip"));
    GridBagConstraints gbc_jpfPassword = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jpfPassword.gridy = 2;
    jlConfirmPassword = new JLabel(res.getString("DExportPrivateKeyPkcs8.jlConfirmPassword.text"));
    GridBagConstraints gbc_jlConfirmPassword = (GridBagConstraints) gbcLbl.clone();
    gbc_jlConfirmPassword.gridy = 3;
    jpfConfirmPassword = new JPasswordField(15);
    jpfConfirmPassword.setToolTipText(res.getString("DExportPrivateKeyPkcs8.jpfConfirmPassword.tooltip"));
    GridBagConstraints gbc_jpfConfirmPassword = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jpfConfirmPassword.gridy = 3;
    jlExportPem = new JLabel(res.getString("DExportPrivateKeyPkcs8.jlExportPem.text"));
    GridBagConstraints gbc_jlExportPem = (GridBagConstraints) gbcLbl.clone();
    gbc_jlExportPem.gridy = 4;
    jcbExportPem = new JCheckBox();
    jcbExportPem.setSelected(true);
    jcbExportPem.setToolTipText(res.getString("DExportPrivateKeyPkcs8.jcbExportPem.tooltip"));
    GridBagConstraints gbc_jcbExportPem = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jcbExportPem.gridy = 4;
    jlExportFile = new JLabel(res.getString("DExportPrivateKeyPkcs8.jlExportFile.text"));
    GridBagConstraints gbc_jlExportFile = (GridBagConstraints) gbcLbl.clone();
    gbc_jlExportFile.gridy = 5;
    jtfExportFile = new JTextField(30);
    jtfExportFile.setToolTipText(res.getString("DExportPrivateKeyPkcs8.jtfExportFile.tooltip"));
    GridBagConstraints gbc_jtfExportFile = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jtfExportFile.gridy = 5;
    gbc_jtfExportFile.gridwidth = 6;
    jbBrowse = new JButton(res.getString("DExportPrivateKeyPkcs8.jbBrowse.text"));
    jbBrowse.setToolTipText(res.getString("DExportPrivateKeyPkcs8.jbBrowse.tooltip"));
    PlatformUtil.setMnemonic(jbBrowse, res.getString("DExportPrivateKeyPkcs8.jbBrowse.mnemonic").charAt(0));
    GridBagConstraints gbc_jbBrowse = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jbBrowse.gridy = 5;
    gbc_jbBrowse.gridx = 9;
    jbBrowse.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DExportPrivateKeyPkcs8.this);
                browsePressed();
            } finally {
                CursorUtil.setCursorFree(DExportPrivateKeyPkcs8.this);
            }
        }
    });
    jpOptions = new JPanel(new GridBagLayout());
    jpOptions.setBorder(new CompoundBorder(new CompoundBorder(new EmptyBorder(5, 5, 5, 5), new EtchedBorder()), new EmptyBorder(5, 5, 5, 5)));
    jpOptions.add(jlEncrypt, gbc_jlEncrypt);
    jpOptions.add(jcbEncrypt, gbc_jcbEncrypt);
    jpOptions.add(jlPbeAlg, gbc_jlPbeAlg);
    jpOptions.add(jcbPbeAlg, gbc_jcbPbeAlg);
    jpOptions.add(jlPassword, gbc_jlPassword);
    jpOptions.add(jpfPassword, gbc_jpfPassword);
    jpOptions.add(jlConfirmPassword, gbc_jlConfirmPassword);
    jpOptions.add(jpfConfirmPassword, gbc_jpfConfirmPassword);
    jpOptions.add(jlExportPem, gbc_jlExportPem);
    jpOptions.add(jcbExportPem, gbc_jcbExportPem);
    jpOptions.add(jlExportFile, gbc_jlExportFile);
    jpOptions.add(jtfExportFile, gbc_jtfExportFile);
    jpOptions.add(jbBrowse, gbc_jbBrowse);
    jcbEncrypt.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent evt) {
            if (jcbEncrypt.isSelected()) {
                jcbPbeAlg.setEnabled(true);
                jpfPassword.setEnabled(true);
                jpfConfirmPassword.setEnabled(true);
            } else {
                jcbPbeAlg.setEnabled(false);
                jpfPassword.setEnabled(false);
                if (jpfPassword instanceof JPasswordQualityField) {
                    ((JPasswordQualityField) jpfPassword).setText("");
                } else {
                    ((JPasswordField) jpfPassword).setText("");
                }
                jpfConfirmPassword.setEnabled(false);
                jpfConfirmPassword.setText("");
            }
        }
    });
    jbExport = new JButton(res.getString("DExportPrivateKeyPkcs8.jbExport.text"));
    PlatformUtil.setMnemonic(jbExport, res.getString("DExportPrivateKeyPkcs8.jbExport.mnemonic").charAt(0));
    jbExport.setToolTipText(res.getString("DExportPrivateKeyPkcs8.jbExport.tooltip"));
    jbExport.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DExportPrivateKeyPkcs8.this);
                exportPressed();
            } finally {
                CursorUtil.setCursorFree(DExportPrivateKeyPkcs8.this);
            }
        }
    });
    jbCancel = new JButton(res.getString("DExportPrivateKeyPkcs8.jbCancel.text"));
    jbCancel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            cancelPressed();
        }
    });
    jbCancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CANCEL_KEY);
    jbCancel.getActionMap().put(CANCEL_KEY, new AbstractAction() {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent evt) {
            cancelPressed();
        }
    });
    jpButtons = PlatformUtil.createDialogButtonPanel(jbExport, jbCancel, false);
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(jpOptions, BorderLayout.CENTER);
    getContentPane().add(jpButtons, BorderLayout.SOUTH);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent evt) {
            closeDialog();
        }
    });
    setTitle(MessageFormat.format(res.getString("DExportPrivateKeyPkcs8.Title"), entryAlias));
    setResizable(false);
    getRootPane().setDefaultButton(jbExport);
    populateExportFileName();
    pack();
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) ItemEvent(java.awt.event.ItemEvent) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) JTextField(javax.swing.JTextField) BorderLayout(java.awt.BorderLayout) JPasswordQualityField(org.kse.gui.password.JPasswordQualityField) CompoundBorder(javax.swing.border.CompoundBorder) EmptyBorder(javax.swing.border.EmptyBorder) AbstractAction(javax.swing.AbstractAction) Pkcs8PbeType(org.kse.crypto.privatekey.Pkcs8PbeType) JLabel(javax.swing.JLabel) JCheckBox(javax.swing.JCheckBox) EtchedBorder(javax.swing.border.EtchedBorder) ActionListener(java.awt.event.ActionListener) JPasswordField(javax.swing.JPasswordField) WindowEvent(java.awt.event.WindowEvent) ItemListener(java.awt.event.ItemListener)

Example 5 with JPasswordQualityField

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

the class DExportPrivateKeyPkcs8 method exportPressed.

private void exportPressed() {
    encrypt = jcbEncrypt.isSelected();
    if (encrypt) {
        pbeAlgorithm = (Pkcs8PbeType) jcbPbeAlg.getSelectedItem();
        Password firstPassword;
        if (jpfPassword instanceof JPasswordQualityField) {
            char[] firstPasswordChars = ((JPasswordQualityField) jpfPassword).getPassword();
            if (firstPasswordChars == null) {
                JOptionPane.showMessageDialog(this, res.getString("DExportPrivateKeyPkcs8.MinimumPasswordQualityNotMet.message"), res.getString("DExportPrivateKeyPkcs8.Simple.Title"), JOptionPane.WARNING_MESSAGE);
                return;
            }
            firstPassword = new Password(firstPasswordChars);
        } else {
            firstPassword = new Password(((JPasswordField) jpfPassword).getPassword());
        }
        Password confirmPassword = new Password(jpfConfirmPassword.getPassword());
        if (firstPassword.equals(confirmPassword)) {
            exportPassword = firstPassword;
        } else {
            JOptionPane.showMessageDialog(this, res.getString("DExportPrivateKeyPkcs8.PasswordsNoMatch.message"), res.getString("DExportPrivateKeyPkcs8.Simple.Title"), JOptionPane.WARNING_MESSAGE);
            return;
        }
    }
    pemEncode = jcbExportPem.isSelected();
    String exportFileStr = jtfExportFile.getText().trim();
    if (exportFileStr.length() == 0) {
        JOptionPane.showMessageDialog(this, res.getString("DExportPrivateKeyPkcs8.ExportFileRequired.message"), res.getString("DExportPrivateKeyPkcs8.Simple.Title"), JOptionPane.WARNING_MESSAGE);
        return;
    }
    File exportFile = new File(exportFileStr);
    if (exportFile.isFile()) {
        String message = MessageFormat.format(res.getString("DExportPrivateKeyPkcs8.OverWriteExportFile.message"), exportFile);
        int selected = JOptionPane.showConfirmDialog(this, message, res.getString("DExportPrivateKeyPkcs8.Simple.Title"), JOptionPane.YES_NO_OPTION);
        if (selected != JOptionPane.YES_OPTION) {
            return;
        }
    }
    this.exportFile = exportFile;
    exportSelected = true;
    closeDialog();
}
Also used : JPasswordQualityField(org.kse.gui.password.JPasswordQualityField) JPasswordField(javax.swing.JPasswordField) File(java.io.File) Password(org.kse.crypto.Password)

Aggregations

JPasswordField (javax.swing.JPasswordField)8 JPasswordQualityField (org.kse.gui.password.JPasswordQualityField)8 BorderLayout (java.awt.BorderLayout)4 GridBagConstraints (java.awt.GridBagConstraints)4 GridBagLayout (java.awt.GridBagLayout)4 Insets (java.awt.Insets)4 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 WindowAdapter (java.awt.event.WindowAdapter)4 WindowEvent (java.awt.event.WindowEvent)4 File (java.io.File)4 AbstractAction (javax.swing.AbstractAction)4 JButton (javax.swing.JButton)4 JLabel (javax.swing.JLabel)4 JPanel (javax.swing.JPanel)4 JTextField (javax.swing.JTextField)4 CompoundBorder (javax.swing.border.CompoundBorder)4 EmptyBorder (javax.swing.border.EmptyBorder)4 EtchedBorder (javax.swing.border.EtchedBorder)4 Password (org.kse.crypto.Password)4