Search in sources :

Example 6 with KeyPairType

use of org.kse.crypto.keypair.KeyPairType in project keystore-explorer by kaikramer.

the class SignJarAction method doAction.

/**
 * Do action.
 */
@Override
protected void doAction() {
    try {
        KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
        KeyStoreState currentState = history.getCurrentState();
        String alias = kseFrame.getSelectedEntryAlias();
        Password password = getEntryPassword(alias, currentState);
        if (password == null) {
            return;
        }
        KeyStore keyStore = currentState.getKeyStore();
        Provider provider = history.getExplicitProvider();
        PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, password.toCharArray());
        X509Certificate[] certs = X509CertUtil.orderX509CertChain(X509CertUtil.convertCertificates(keyStore.getCertificateChain(alias)));
        KeyPairType keyPairType = KeyPairUtil.getKeyPairType(privateKey);
        DSignJar dSignJar = new DSignJar(frame, privateKey, keyPairType, alias, provider);
        dSignJar.setLocationRelativeTo(frame);
        dSignJar.setVisible(true);
        SignatureType signatureType = dSignJar.getSignatureType();
        String signatureName = dSignJar.getSignatureName();
        File inputJarFile = dSignJar.getInputJar();
        File outputJarFile = dSignJar.getOutputJar();
        String tsaUrl = dSignJar.getTimestampingServerUrl();
        if (signatureType == null) {
            return;
        }
        String signer = KSE.getFullApplicationName();
        DigestType digestType = dSignJar.getDigestType();
        if (inputJarFile.equals(outputJarFile)) {
            JarSigner.sign(inputJarFile, privateKey, certs, signatureType, signatureName, signer, digestType, tsaUrl, provider);
        } else {
            JarSigner.sign(inputJarFile, outputJarFile, privateKey, certs, signatureType, signatureName, signer, digestType, tsaUrl, provider);
        }
        JOptionPane.showMessageDialog(frame, res.getString("SignJarAction.SignJarSuccessful.message"), res.getString("SignJarAction.SignJar.Title"), JOptionPane.INFORMATION_MESSAGE);
    } catch (Exception ex) {
        DError.displayError(frame, ex);
    }
}
Also used : KeyStoreState(org.kse.utilities.history.KeyStoreState) KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) PrivateKey(java.security.PrivateKey) SignatureType(org.kse.crypto.signing.SignatureType) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate) Provider(java.security.Provider) DigestType(org.kse.crypto.digest.DigestType) DSignJar(org.kse.gui.dialogs.sign.DSignJar) KeyPairType(org.kse.crypto.keypair.KeyPairType) File(java.io.File) Password(org.kse.crypto.Password)

Example 7 with KeyPairType

use of org.kse.crypto.keypair.KeyPairType in project keystore-explorer by kaikramer.

the class DGenerateKeyPair method loadKeySizes.

private void loadKeySizes(int keyPairSize) {
    KeyPairType keyPairType = KeyPairType.RSA;
    keyPairSize = validateKeyPairSize(keyPairType, keyPairSize);
    jspRSAKeySize.setModel(new SpinnerNumberModel(keyPairSize, keyPairType.minSize(), keyPairType.maxSize(), keyPairType.stepSize()));
    keyPairType = KeyPairType.DSA;
    keyPairSize = validateKeyPairSize(keyPairType, keyPairSize);
    jspDSAKeySize.setModel(new SpinnerNumberModel(keyPairSize, keyPairType.minSize(), keyPairType.maxSize(), keyPairType.stepSize()));
}
Also used : SpinnerNumberModel(javax.swing.SpinnerNumberModel) KeyPairType(org.kse.crypto.keypair.KeyPairType)

Example 8 with KeyPairType

use of org.kse.crypto.keypair.KeyPairType in project keystore-explorer by kaikramer.

the class DGenerateKeyPairCert method initComponents.

private void initComponents(String title) throws CryptoException {
    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;
    jlVersion = new JLabel(res.getString("DGenerateKeyPairCert.jlVersion.text"));
    GridBagConstraints gbc_jlVersion = (GridBagConstraints) gbcLbl.clone();
    gbc_jlVersion.gridy = 0;
    jrbVersion1 = new JRadioButton(res.getString("DGenerateKeyPairCert.jrbVersion1.text"));
    jrbVersion1.setToolTipText(res.getString("DGenerateKeyPairCert.jrbVersion1.tooltip"));
    GridBagConstraints gbc_jrbVersion1 = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jrbVersion1.gridy = 0;
    gbc_jrbVersion1.gridwidth = 1;
    jrbVersion3 = new JRadioButton(res.getString("DGenerateKeyPairCert.jrbVersion3.text"));
    jrbVersion3.setToolTipText(res.getString("DGenerateKeyPairCert.jrbVersion3.tooltip"));
    GridBagConstraints gbc_jrbVersion3 = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jrbVersion3.gridx = 4;
    gbc_jrbVersion3.gridy = 0;
    gbc_jrbVersion3.gridwidth = 1;
    ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(jrbVersion1);
    buttonGroup.add(jrbVersion3);
    jlSigAlg = new JLabel(res.getString("DGenerateKeyPairCert.jlSigAlg.text"));
    GridBagConstraints gbc_jlSigAlg = (GridBagConstraints) gbcLbl.clone();
    gbc_jlSigAlg.gridy = 1;
    jcbSignatureAlgorithm = new JComboBox<SignatureType>();
    jcbSignatureAlgorithm.setToolTipText(res.getString("DGenerateKeyPairCert.jcbSignatureAlgorithm.tooltip"));
    jcbSignatureAlgorithm.setMaximumRowCount(10);
    GridBagConstraints gbc_jcbSigAlg = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jcbSigAlg.gridy = 1;
    // populate signature algorithm selector
    if (issuerPrivateKey != null) {
        KeyPairType issuerKeyPairType = KeyPairType.resolveJce(issuerPrivateKey.getAlgorithm());
        DialogHelper.populateSigAlgs(issuerKeyPairType, issuerPrivateKey, provider, jcbSignatureAlgorithm);
    } else {
        // self-signed
        DialogHelper.populateSigAlgs(keyPairType, keyPair.getPrivate(), provider, jcbSignatureAlgorithm);
    }
    Date now = new Date();
    jlValidityStart = new JLabel(res.getString("DGenerateKeyPairCert.jlValidityStart.text"));
    GridBagConstraints gbc_jlValidityStart = (GridBagConstraints) gbcLbl.clone();
    gbc_jlValidityStart.gridy = 2;
    jdtValidityStart = new JDateTime(res.getString("DGenerateKeyPairCert.jdtValidityStart.text"), false);
    jdtValidityStart.setDateTime(now);
    jdtValidityStart.setToolTipText(res.getString("DGenerateKeyPairCert.jdtValidityStart.tooltip"));
    GridBagConstraints gbc_jdtValidityStart = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jdtValidityStart.gridy = 2;
    jlValidityPeriod = new JLabel(res.getString("DGenerateKeyPairCert.jlValidityPeriod.text"));
    GridBagConstraints gbc_jlValidityPeriod = (GridBagConstraints) gbcLbl.clone();
    gbc_jlValidityPeriod.gridy = 3;
    jvpValidityPeriod = new JValidityPeriod(JValidityPeriod.YEARS);
    jvpValidityPeriod.setToolTipText(res.getString("DGenerateKeyPairCert.jvpValidityPeriod.tooltip"));
    jvpValidityPeriod.addApplyActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Date startDate = jdtValidityStart.getDateTime();
            if (startDate == null) {
                startDate = new Date();
                jdtValidityStart.setDateTime(startDate);
            }
            Date validityEnd = jvpValidityPeriod.getValidityEnd(startDate);
            jdtValidityEnd.setDateTime(validityEnd);
        }
    });
    GridBagConstraints gbc_jvpValidityPeriod = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jvpValidityPeriod.gridy = 3;
    jlValidityEnd = new JLabel(res.getString("DGenerateKeyPairCert.jlValidityEnd.text"));
    GridBagConstraints gbc_jlValidityEnd = (GridBagConstraints) gbcLbl.clone();
    gbc_jlValidityEnd.gridy = 4;
    jdtValidityEnd = new JDateTime(res.getString("DGenerateKeyPairCert.jdtValidityEnd.text"), false);
    jdtValidityEnd.setDateTime(new Date(now.getTime() + TimeUnit.DAYS.toMillis(365)));
    jdtValidityEnd.setToolTipText(res.getString("DGenerateKeyPairCert.jdtValidityEnd.tooltip"));
    GridBagConstraints gbc_jdtValidityEnd = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jdtValidityEnd.gridy = 4;
    jlSerialNumber = new JLabel(res.getString("DGenerateKeyPairCert.jlSerialNumber.text"));
    GridBagConstraints gbc_jlSerialNumber = (GridBagConstraints) gbcLbl.clone();
    gbc_jlSerialNumber.gridy = 5;
    jtfSerialNumber = new JTextField("" + generateSerialNumber(), 20);
    jtfSerialNumber.setToolTipText(res.getString("DGenerateKeyPairCert.jtfSerialNumber.tooltip"));
    GridBagConstraints gbc_jtfSerialNumber = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jtfSerialNumber.gridy = 5;
    jlName = new JLabel(res.getString("DGenerateKeyPairCert.jlName.text"));
    GridBagConstraints gbc_jlName = (GridBagConstraints) gbcLbl.clone();
    gbc_jlName.gridy = 6;
    jdnName = new JDistinguishedName("Name", 30, true);
    jdnName.setToolTipText(res.getString("DGenerateKeyPairCert.jdnName.tooltip"));
    GridBagConstraints gbc_jdnName = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jdnName.gridy = 6;
    jbAddExtensions = new JButton(res.getString("DGenerateKeyPairCert.jbAddExtensions.text"));
    jbAddExtensions.setMnemonic(res.getString("DGenerateKeyPairCert.jbAddExtensions.mnemonic").charAt(0));
    jbAddExtensions.setToolTipText(res.getString("DGenerateKeyPairCert.jbAddExtensions.tooltip"));
    GridBagConstraints gbc_jbAddExtensions = (GridBagConstraints) gbcEdCtrl.clone();
    gbc_jbAddExtensions.gridy = 7;
    gbc_jbAddExtensions.gridwidth = 8;
    gbc_jbAddExtensions.anchor = GridBagConstraints.EAST;
    jbAddExtensions.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DGenerateKeyPairCert.this);
                addExtensionsPressed();
            } finally {
                CursorUtil.setCursorFree(DGenerateKeyPairCert.this);
            }
        }
    });
    jrbVersion3.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent evt) {
            jbAddExtensions.setEnabled(jrbVersion3.isSelected());
        }
    });
    jrbVersion3.setSelected(true);
    jpOptions = new JPanel(new GridBagLayout());
    jpOptions.setBorder(new CompoundBorder(new EmptyBorder(5, 5, 5, 5), new EtchedBorder()));
    jpOptions.add(jlVersion, gbc_jlVersion);
    jpOptions.add(jrbVersion1, gbc_jrbVersion1);
    jpOptions.add(jrbVersion3, gbc_jrbVersion3);
    jpOptions.add(jlSigAlg, gbc_jlSigAlg);
    jpOptions.add(jcbSignatureAlgorithm, gbc_jcbSigAlg);
    jpOptions.add(jlValidityStart, gbc_jlValidityStart);
    jpOptions.add(jdtValidityStart, gbc_jdtValidityStart);
    jpOptions.add(jlValidityPeriod, gbc_jlValidityPeriod);
    jpOptions.add(jvpValidityPeriod, gbc_jvpValidityPeriod);
    jpOptions.add(jlValidityEnd, gbc_jlValidityEnd);
    jpOptions.add(jdtValidityEnd, gbc_jdtValidityEnd);
    jpOptions.add(jlSerialNumber, gbc_jlSerialNumber);
    jpOptions.add(jtfSerialNumber, gbc_jtfSerialNumber);
    jpOptions.add(jlName, gbc_jlName);
    jpOptions.add(jdnName, gbc_jdnName);
    jpOptions.add(jbAddExtensions, gbc_jbAddExtensions);
    jbOK = new JButton(res.getString("DGenerateKeyPairCert.jbOK.text"));
    jbOK.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            okPressed();
        }
    });
    jbCancel = new JButton(res.getString("DGenerateKeyPairCert.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(jbOK, 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(title);
    setResizable(false);
    getRootPane().setDefaultButton(jbOK);
    pack();
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) 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) JValidityPeriod(org.kse.gui.crypto.JValidityPeriod) JTextField(javax.swing.JTextField) JDistinguishedName(org.kse.gui.crypto.JDistinguishedName) BorderLayout(java.awt.BorderLayout) ChangeListener(javax.swing.event.ChangeListener) CompoundBorder(javax.swing.border.CompoundBorder) KeyPairType(org.kse.crypto.keypair.KeyPairType) EmptyBorder(javax.swing.border.EmptyBorder) AbstractAction(javax.swing.AbstractAction) JLabel(javax.swing.JLabel) SignatureType(org.kse.crypto.signing.SignatureType) Date(java.util.Date) EtchedBorder(javax.swing.border.EtchedBorder) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) ButtonGroup(javax.swing.ButtonGroup) WindowEvent(java.awt.event.WindowEvent) JDateTime(org.kse.gui.datetime.JDateTime)

Aggregations

KeyPairType (org.kse.crypto.keypair.KeyPairType)8 KeyStore (java.security.KeyStore)4 Provider (java.security.Provider)4 X509Certificate (java.security.cert.X509Certificate)4 Password (org.kse.crypto.Password)4 SignatureType (org.kse.crypto.signing.SignatureType)4 KeyStoreHistory (org.kse.utilities.history.KeyStoreHistory)4 KeyStoreState (org.kse.utilities.history.KeyStoreState)4 File (java.io.File)3 PrivateKey (java.security.PrivateKey)3 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2 PublicKey (java.security.PublicKey)2 Date (java.util.Date)2 Spkac (org.kse.crypto.csr.spkac.Spkac)2 BorderLayout (java.awt.BorderLayout)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 ActionEvent (java.awt.event.ActionEvent)1