Search in sources :

Example 6 with JPasswordQualityField

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

the class DExportPrivateKeyPvk 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;
    jlKeyType = new JLabel(res.getString("DExportPrivateKeyPvk.jlKeyType.text"));
    GridBagConstraints gbc_jlKeyType = (GridBagConstraints) gbcLbl.clone();
    gbc_jlKeyType.gridy = 0;
    jrbExchange = new JRadioButton(res.getString("DExportPrivateKeyPvk.jrbExchange.text"));
    jrbExchange.setToolTipText(res.getString("DExportPrivateKeyPvk.jrbExchange.tooltip"));
    PlatformUtil.setMnemonic(jrbExchange, res.getString("DExportPrivateKeyPvk.jrbExchange.mnemonic").charAt(0));
    jrbExchange.setSelected(true);
    GridBagConstraints gbc_jrbExchange = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jrbExchange.gridy = 0;
    jrbSignature = new JRadioButton(res.getString("DExportPrivateKeyPvk.jrbSignature.text"));
    jrbSignature.setToolTipText(res.getString("DExportPrivateKeyPvk.jrbSignature.tooltip"));
    PlatformUtil.setMnemonic(jrbSignature, res.getString("DExportPrivateKeyPvk.jrbSignature.mnemonic").charAt(0));
    GridBagConstraints gbc_jrbSignature = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jrbSignature.gridy = 0;
    gbc_jrbSignature.gridx = 6;
    ButtonGroup keyTypes = new ButtonGroup();
    keyTypes.add(jrbExchange);
    keyTypes.add(jrbSignature);
    if (privateKey instanceof DSAPrivateKey) {
        jrbSignature.setSelected(true);
        jrbExchange.setEnabled(false);
        jrbSignature.setEnabled(false);
    }
    jlEncrypt = new JLabel(res.getString("DExportPrivateKeyPvk.jlEncrypt.text"));
    GridBagConstraints gbc_jlEncrypt = (GridBagConstraints) gbcLbl.clone();
    gbc_jlEncrypt.gridy = 1;
    jcbEncrypt = new JCheckBox();
    jcbEncrypt.setSelected(true);
    jcbEncrypt.setToolTipText(res.getString("DExportPrivateKeyPvk.jcbEncrypt.tooltip"));
    GridBagConstraints gbc_jcbEncrypt = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jcbEncrypt.gridy = 1;
    jlEncryptionStrength = new JLabel(res.getString("DExportPrivateKeyPvk.jlEncryptionStrength.text"));
    GridBagConstraints gbc_jlEncryptionStrength = (GridBagConstraints) gbcLbl.clone();
    gbc_jlEncryptionStrength.gridy = 2;
    jrbStrong = new JRadioButton(res.getString("DExportPrivateKeyPvk.jrbStrong.text"));
    jrbStrong.setToolTipText(res.getString("DExportPrivateKeyPvk.jrbStrong.tooltip"));
    PlatformUtil.setMnemonic(jrbStrong, res.getString("DExportPrivateKeyPvk.jrbStrong.mnemonic").charAt(0));
    jrbStrong.setSelected(true);
    GridBagConstraints gbc_jrbStrong = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jrbStrong.gridy = 2;
    jrbWeak = new JRadioButton(res.getString("DExportPrivateKeyPvk.jrbWeak.text"));
    jrbWeak.setToolTipText(res.getString("DExportPrivateKeyPvk.jrbWeak.tooltip"));
    PlatformUtil.setMnemonic(jrbWeak, res.getString("DExportPrivateKeyPvk.jrbWeak.mnemonic").charAt(0));
    GridBagConstraints gbc_jrbWeak = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jrbWeak.gridy = 2;
    gbc_jrbWeak.gridx = 6;
    ButtonGroup encryptionStrengths = new ButtonGroup();
    encryptionStrengths.add(jrbStrong);
    encryptionStrengths.add(jrbWeak);
    jlPassword = new JLabel(res.getString("DExportPrivateKeyPvk.jlPassword.text"));
    GridBagConstraints gbc_jlPassword = (GridBagConstraints) gbcLbl.clone();
    gbc_jlPassword.gridy = 3;
    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("DExportPrivateKeyPvk.jpqfPassword.tooltip"));
    GridBagConstraints gbc_jpfPassword = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jpfPassword.gridy = 3;
    gbc_jpfPassword.gridwidth = 6;
    jlConfirmPassword = new JLabel(res.getString("DExportPrivateKeyPvk.jlConfirmPassword.text"));
    GridBagConstraints gbc_jlConfirmPassword = (GridBagConstraints) gbcLbl.clone();
    gbc_jlConfirmPassword.gridy = 4;
    jpfConfirmPassword = new JPasswordField(15);
    jpfConfirmPassword.setToolTipText(res.getString("DExportPrivateKeyPvk.jpfConfirmPassword.tooltip"));
    GridBagConstraints gbc_jpfConfirmPassword = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jpfConfirmPassword.gridy = 4;
    gbc_jpfConfirmPassword.gridwidth = 6;
    jlExportFile = new JLabel(res.getString("DExportPrivateKeyPvk.jlExportFile.text"));
    GridBagConstraints gbc_jlExportFile = (GridBagConstraints) gbcLbl.clone();
    gbc_jlExportFile.gridy = 5;
    jtfExportFile = new JTextField(30);
    jtfExportFile.setToolTipText(res.getString("DExportPrivateKeyPvk.jtfExportFile.tooltip"));
    GridBagConstraints gbc_jtfExportFile = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jtfExportFile.gridy = 5;
    gbc_jtfExportFile.gridwidth = 6;
    jbBrowse = new JButton(res.getString("DExportPrivateKeyPvk.jbBrowse.text"));
    jbBrowse.setToolTipText(res.getString("DExportPrivateKeyPvk.jbBrowse.tooltip"));
    PlatformUtil.setMnemonic(jbBrowse, res.getString("DExportPrivateKeyPvk.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(DExportPrivateKeyPvk.this);
                browsePressed();
            } finally {
                CursorUtil.setCursorFree(DExportPrivateKeyPvk.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(jlKeyType, gbc_jlKeyType);
    jpOptions.add(jrbExchange, gbc_jrbExchange);
    jpOptions.add(jrbSignature, gbc_jrbSignature);
    jpOptions.add(jlEncrypt, gbc_jlEncrypt);
    jpOptions.add(jcbEncrypt, gbc_jcbEncrypt);
    jpOptions.add(jrbStrong, gbc_jrbStrong);
    jpOptions.add(jrbWeak, gbc_jrbWeak);
    jpOptions.add(jlEncryptionStrength, gbc_jlEncryptionStrength);
    jpOptions.add(jlEncryptionStrength, gbc_jlEncryptionStrength);
    jpOptions.add(jlPassword, gbc_jlPassword);
    jpOptions.add(jpfPassword, gbc_jpfPassword);
    jpOptions.add(jlConfirmPassword, gbc_jlConfirmPassword);
    jpOptions.add(jpfConfirmPassword, gbc_jpfConfirmPassword);
    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()) {
                jrbStrong.setEnabled(true);
                jrbWeak.setEnabled(true);
                jpfPassword.setEnabled(true);
                jpfConfirmPassword.setEnabled(true);
            } else {
                jrbStrong.setEnabled(false);
                jrbWeak.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("DExportPrivateKeyPvk.jbExport.text"));
    PlatformUtil.setMnemonic(jbExport, res.getString("DExportPrivateKeyPvk.jbExport.mnemonic").charAt(0));
    jbExport.setToolTipText(res.getString("DExportPrivateKeyPvk.jbExport.tooltip"));
    jbExport.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DExportPrivateKeyPvk.this);
                exportPressed();
            } finally {
                CursorUtil.setCursorFree(DExportPrivateKeyPvk.this);
            }
        }
    });
    jbCancel = new JButton(res.getString("DExportPrivateKeyPvk.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("DExportPrivateKeyPvk.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) JRadioButton(javax.swing.JRadioButton) 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) JLabel(javax.swing.JLabel) JCheckBox(javax.swing.JCheckBox) EtchedBorder(javax.swing.border.EtchedBorder) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) JPasswordField(javax.swing.JPasswordField) WindowEvent(java.awt.event.WindowEvent) DSAPrivateKey(java.security.interfaces.DSAPrivateKey) ItemListener(java.awt.event.ItemListener)

Example 7 with JPasswordQualityField

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

the class DExportKeyPair 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;
    jlPassword = new JLabel(res.getString("DExportKeyPair.jlPassword.text"));
    GridBagConstraints gbc_jlPassword = (GridBagConstraints) gbcLbl.clone();
    gbc_jlPassword.gridy = 0;
    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("DExportKeyPair.jpqfPassword.tooltip"));
    GridBagConstraints gbc_jpfPassword = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jpfPassword.gridy = 0;
    jlConfirmPassword = new JLabel(res.getString("DExportKeyPair.jlConfirmPassword.text"));
    GridBagConstraints gbc_jlConfirmPassword = (GridBagConstraints) gbcLbl.clone();
    gbc_jlConfirmPassword.gridy = 1;
    jpfConfirmPassword = new JPasswordField(15);
    jpfConfirmPassword.setToolTipText(res.getString("DExportKeyPair.jpfConfirmPassword.tooltip"));
    GridBagConstraints gbc_jpfConfirmPassword = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jpfConfirmPassword.gridy = 1;
    jlExportFile = new JLabel(res.getString("DExportKeyPair.jlExportFile.text"));
    GridBagConstraints gbc_jlExportFile = (GridBagConstraints) gbcLbl.clone();
    gbc_jlExportFile.gridy = 2;
    jtfExportFile = new JTextField(30);
    jtfExportFile.setToolTipText(res.getString("DExportKeyPair.jtfExportFile.tooltip"));
    GridBagConstraints gbc_jtfExportFile = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jtfExportFile.gridy = 2;
    gbc_jtfExportFile.gridwidth = 6;
    jbBrowse = new JButton(res.getString("DExportKeyPair.jbBrowse.text"));
    jbBrowse.setToolTipText(res.getString("DExportKeyPair.jbBrowse.tooltip"));
    PlatformUtil.setMnemonic(jbBrowse, res.getString("DExportKeyPair.jbBrowse.mnemonic").charAt(0));
    GridBagConstraints gbc_jbBrowse = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jbBrowse.gridy = 2;
    gbc_jbBrowse.gridx = 9;
    jbBrowse.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DExportKeyPair.this);
                browsePressed();
            } finally {
                CursorUtil.setCursorFree(DExportKeyPair.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(jlPassword, gbc_jlPassword);
    jpOptions.add(jpfPassword, gbc_jpfPassword);
    jpOptions.add(jlConfirmPassword, gbc_jlConfirmPassword);
    jpOptions.add(jpfConfirmPassword, gbc_jpfConfirmPassword);
    jpOptions.add(jlExportFile, gbc_jlExportFile);
    jpOptions.add(jtfExportFile, gbc_jtfExportFile);
    jpOptions.add(jbBrowse, gbc_jbBrowse);
    jbExport = new JButton(res.getString("DExportKeyPair.jbExport.text"));
    PlatformUtil.setMnemonic(jbExport, res.getString("DExportKeyPair.jbExport.mnemonic").charAt(0));
    jbExport.setToolTipText(res.getString("DExportKeyPair.jbExport.tooltip"));
    jbExport.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DExportKeyPair.this);
                exportPressed();
            } finally {
                CursorUtil.setCursorFree(DExportKeyPair.this);
            }
        }
    });
    jbCancel = new JButton(res.getString("DExportKeyPair.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("DExportKeyPair.Title"), entryAlias));
    setResizable(false);
    getRootPane().setDefaultButton(jbExport);
    populateExportFileName();
    pack();
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) WindowAdapter(java.awt.event.WindowAdapter) JTextField(javax.swing.JTextField) EtchedBorder(javax.swing.border.EtchedBorder) ActionListener(java.awt.event.ActionListener) BorderLayout(java.awt.BorderLayout) JPasswordQualityField(org.kse.gui.password.JPasswordQualityField) JPasswordField(javax.swing.JPasswordField) WindowEvent(java.awt.event.WindowEvent) CompoundBorder(javax.swing.border.CompoundBorder) EmptyBorder(javax.swing.border.EmptyBorder) AbstractAction(javax.swing.AbstractAction)

Example 8 with JPasswordQualityField

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

the class DExportPrivateKeyPvk method exportPressed.

private void exportPressed() {
    if (jrbExchange.isSelected()) {
        keyType = MsPvkUtil.PVK_KEY_EXCHANGE;
    } else {
        keyType = MsPvkUtil.PVK_KEY_SIGNATURE;
    }
    encrypt = jcbEncrypt.isSelected();
    if (encrypt) {
        strongEncryption = jrbStrong.isSelected();
        Password firstPassword;
        if (jpfPassword instanceof JPasswordQualityField) {
            char[] firstPasswordChars = ((JPasswordQualityField) jpfPassword).getPassword();
            if (firstPasswordChars == null) {
                JOptionPane.showMessageDialog(this, res.getString("DExportPrivateKeyPvk.MinimumPasswordQualityNotMet.message"), res.getString("DExportPrivateKeyPvk.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("DExportPrivateKeyPvk.PasswordsNoMatch.message"), res.getString("DExportPrivateKeyPvk.Simple.Title"), JOptionPane.WARNING_MESSAGE);
            return;
        }
    }
    String exportFileChars = jtfExportFile.getText().trim();
    if (exportFileChars.length() == 0) {
        JOptionPane.showMessageDialog(this, res.getString("DExportPrivateKeyPvk.ExportFileRequired.message"), res.getString("DExportPrivateKeyPvk.Simple.Title"), JOptionPane.WARNING_MESSAGE);
        return;
    }
    File exportFile = new File(exportFileChars);
    if (exportFile.isFile()) {
        String message = MessageFormat.format(res.getString("DExportPrivateKeyPvk.OverWriteExportFile.message"), exportFile);
        int selected = JOptionPane.showConfirmDialog(this, message, res.getString("DExportPrivateKeyPvk.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