Search in sources :

Example 1 with X509ExtensionType

use of org.kse.crypto.x509.X509ExtensionType in project keystore-explorer by kaikramer.

the class DAddExtensions method addPressed.

private void addPressed() {
    DAddExtensionType dAddExtensionType = new DAddExtensionType(this, extensions);
    dAddExtensionType.setLocationRelativeTo(this);
    dAddExtensionType.setVisible(true);
    X509ExtensionType extensionTypeToAdd = dAddExtensionType.getExtensionType();
    if (extensionTypeToAdd == null) {
        return;
    }
    boolean isCritical = dAddExtensionType.isExtensionCritical();
    byte[] extensionValue = null;
    DExtension dExtension = null;
    switch(extensionTypeToAdd) {
        case AUTHORITY_INFORMATION_ACCESS:
            {
                dExtension = new DAuthorityInformationAccess(this);
                break;
            }
        case AUTHORITY_KEY_IDENTIFIER:
            {
                dExtension = new DAuthorityKeyIdentifier(this, authorityPublicKey, authorityCertName, authorityCertSerialNumber);
                break;
            }
        case BASIC_CONSTRAINTS:
            {
                dExtension = new DBasicConstraints(this);
                break;
            }
        case CERTIFICATE_POLICIES:
            {
                dExtension = new DCertificatePolicies(this);
                break;
            }
        case EXTENDED_KEY_USAGE:
            {
                dExtension = new DExtendedKeyUsage(this);
                break;
            }
        case INHIBIT_ANY_POLICY:
            {
                dExtension = new DInhibitAnyPolicy(this);
                break;
            }
        case ISSUER_ALTERNATIVE_NAME:
            {
                dExtension = new DIssuerAlternativeName(this);
                break;
            }
        case KEY_USAGE:
            {
                dExtension = new DKeyUsage(this);
                break;
            }
        case NAME_CONSTRAINTS:
            {
                dExtension = new DNameConstraints(this);
                break;
            }
        case NETSCAPE_BASE_URL:
            {
                dExtension = new DNetscapeBaseUrl(this);
                break;
            }
        case NETSCAPE_CA_POLICY_URL:
            {
                dExtension = new DNetscapeCaPolicyUrl(this);
                break;
            }
        case NETSCAPE_CA_REVOCATION_URL:
            {
                dExtension = new DNetscapeCaRevocationUrl(this);
                break;
            }
        case NETSCAPE_CERTIFICATE_RENEWAL_URL:
            {
                dExtension = new DNetscapeCertificateRenewalUrl(this);
                break;
            }
        case NETSCAPE_CERTIFICATE_TYPE:
            {
                dExtension = new DNetscapeCertificateType(this);
                break;
            }
        case NETSCAPE_COMMENT:
            {
                dExtension = new DNetscapeComment(this);
                break;
            }
        case NETSCAPE_REVOCATION_URL:
            {
                dExtension = new DNetscapeRevocationUrl(this);
                break;
            }
        case NETSCAPE_SSL_SERVER_NAME:
            {
                dExtension = new DNetscapeSslServerName(this);
                break;
            }
        case POLICY_CONSTRAINTS:
            {
                dExtension = new DPolicyConstraints(this);
                break;
            }
        case POLICY_MAPPINGS:
            {
                dExtension = new DPolicyMappings(this);
                break;
            }
        case PRIVATE_KEY_USAGE_PERIOD:
            {
                dExtension = new DPrivateKeyUsagePeriod(this);
                break;
            }
        case SUBJECT_ALTERNATIVE_NAME:
            {
                dExtension = new DSubjectAlternativeName(this);
                break;
            }
        case SUBJECT_INFORMATION_ACCESS:
            {
                dExtension = new DSubjectInformationAccess(this);
                break;
            }
        case SUBJECT_KEY_IDENTIFIER:
            {
                dExtension = new DSubjectKeyIdentifier(this, subjectPublicKey);
                break;
            }
        default:
            {
                return;
            }
    }
    dExtension.setLocationRelativeTo(this);
    dExtension.setVisible(true);
    extensionValue = dExtension.getValue();
    if (extensionValue == null) {
        return;
    }
    extensions.addExtension(extensionTypeToAdd.oid(), isCritical, extensionValue);
    reloadExtensionsTable();
    selectExtensionInTable(extensionTypeToAdd.oid());
    updateButtonControls();
}
Also used : X509ExtensionType(org.kse.crypto.x509.X509ExtensionType)

Example 2 with X509ExtensionType

use of org.kse.crypto.x509.X509ExtensionType in project keystore-explorer by kaikramer.

the class DAddExtensionType method initComponents.

private void initComponents() {
    jpExtensionTypes = new JPanel(new BorderLayout(5, 5));
    jpExtensionTypes.setBorder(new CompoundBorder(new EmptyBorder(5, 5, 5, 5), new CompoundBorder(new EtchedBorder(), new EmptyBorder(5, 5, 5, 5))));
    jlExtensionTypes = new JLabel(res.getString("DAddExtensionType.jlExtensionTypes.text"));
    jltExtensionTypes = new JList<X509ExtensionType>();
    // Longest name to define constant width
    jltExtensionTypes.setPrototypeCellValue(NETSCAPE_CERTIFICATE_RENEWAL_URL);
    jltExtensionTypes.setToolTipText(res.getString("DAddExtensionType.jltExtensionTypes.tooltip"));
    jltExtensionTypes.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jltExtensionTypes.setBorder(new EtchedBorder());
    jltExtensionTypes.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent evt) {
            maybeAddExtension(evt);
        }
    });
    jspExtensionTypes = new JScrollPane(jltExtensionTypes);
    jcbCriticalExtension = new JCheckBox(res.getString("DAddExtensionType.jcbCriticalExtension.text"));
    jcbCriticalExtension.setMnemonic(res.getString("DAddExtensionType.jcbCriticalExtension.mnemonic").charAt(0));
    jcbCriticalExtension.setToolTipText(res.getString("DAddExtensionType.jcbCriticalExtension.tooltip"));
    jpExtensionTypes.add(jlExtensionTypes, BorderLayout.NORTH);
    jpExtensionTypes.add(jspExtensionTypes, BorderLayout.CENTER);
    jpExtensionTypes.add(jcbCriticalExtension, BorderLayout.SOUTH);
    jbOK = new JButton(res.getString("DAddExtensionType.jbOK.text"));
    jbOK.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            okPressed();
        }
    });
    jbCancel = new JButton(res.getString("DAddExtensionType.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);
    populateExtensionTypes();
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(jpExtensionTypes, BorderLayout.CENTER);
    getContentPane().add(jpButtons, BorderLayout.SOUTH);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent evt) {
            closeDialog();
        }
    });
    setResizable(false);
    getRootPane().setDefaultButton(jbOK);
    pack();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) MouseEvent(java.awt.event.MouseEvent) ActionEvent(java.awt.event.ActionEvent) MouseAdapter(java.awt.event.MouseAdapter) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) WindowAdapter(java.awt.event.WindowAdapter) JCheckBox(javax.swing.JCheckBox) EtchedBorder(javax.swing.border.EtchedBorder) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) WindowEvent(java.awt.event.WindowEvent) X509ExtensionType(org.kse.crypto.x509.X509ExtensionType) CompoundBorder(javax.swing.border.CompoundBorder) EmptyBorder(javax.swing.border.EmptyBorder) AbstractAction(javax.swing.AbstractAction)

Example 3 with X509ExtensionType

use of org.kse.crypto.x509.X509ExtensionType in project keystore-explorer by kaikramer.

the class DAddExtensionType method populateExtensionTypes.

private void populateExtensionTypes() {
    // Population is the supported set minus those already added
    ArrayList<X509ExtensionType> availableExtensions = new ArrayList<X509ExtensionType>();
    for (X509ExtensionType extentionType : SUPPORTED_EXTENSIONS) {
        if (extensions.getExtensionValue(extentionType.oid()) == null) {
            availableExtensions.add(extentionType);
        }
    }
    jltExtensionTypes.setListData(availableExtensions.toArray(new X509ExtensionType[availableExtensions.size()]));
    if (availableExtensions.size() > 0) {
        jltExtensionTypes.setSelectedIndex(0);
    }
}
Also used : X509ExtensionType(org.kse.crypto.x509.X509ExtensionType) ArrayList(java.util.ArrayList)

Example 4 with X509ExtensionType

use of org.kse.crypto.x509.X509ExtensionType in project keystore-explorer by kaikramer.

the class DAddExtensions method editSelectedExtension.

private void editSelectedExtension() {
    try {
        int selectedRow = jtExtensions.getSelectedRow();
        if (selectedRow != -1) {
            String oid = ((ASN1ObjectIdentifier) jtExtensions.getValueAt(selectedRow, 2)).getId();
            X509ExtensionType extensionType = X509ExtensionType.resolveOid(oid);
            byte[] extensionValue = extensions.getExtensionValue(oid);
            boolean isCritical = extensions.getCriticalExtensionOIDs().contains(oid);
            byte[] newExtensionValue = null;
            DExtension dExtension = null;
            switch(extensionType) {
                case AUTHORITY_INFORMATION_ACCESS:
                    {
                        dExtension = new DAuthorityInformationAccess(this, extensionValue);
                        break;
                    }
                case AUTHORITY_KEY_IDENTIFIER:
                    {
                        dExtension = new DAuthorityKeyIdentifier(this, extensionValue, authorityPublicKey);
                        break;
                    }
                case BASIC_CONSTRAINTS:
                    {
                        dExtension = new DBasicConstraints(this, extensionValue);
                        break;
                    }
                case CERTIFICATE_POLICIES:
                    {
                        dExtension = new DCertificatePolicies(this, extensionValue);
                        break;
                    }
                case EXTENDED_KEY_USAGE:
                    {
                        dExtension = new DExtendedKeyUsage(this, extensionValue);
                        break;
                    }
                case INHIBIT_ANY_POLICY:
                    {
                        dExtension = new DInhibitAnyPolicy(this, extensionValue);
                        break;
                    }
                case ISSUER_ALTERNATIVE_NAME:
                    {
                        dExtension = new DIssuerAlternativeName(this, extensionValue);
                        break;
                    }
                case KEY_USAGE:
                    {
                        dExtension = new DKeyUsage(this, extensionValue);
                        break;
                    }
                case NAME_CONSTRAINTS:
                    {
                        dExtension = new DNameConstraints(this, extensionValue);
                        break;
                    }
                case NETSCAPE_BASE_URL:
                    {
                        dExtension = new DNetscapeBaseUrl(this, extensionValue);
                        break;
                    }
                case NETSCAPE_CERTIFICATE_RENEWAL_URL:
                    {
                        dExtension = new DNetscapeCertificateRenewalUrl(this, extensionValue);
                        break;
                    }
                case NETSCAPE_CA_POLICY_URL:
                    {
                        dExtension = new DNetscapeCaPolicyUrl(this, extensionValue);
                        break;
                    }
                case NETSCAPE_CA_REVOCATION_URL:
                    {
                        dExtension = new DNetscapeCaRevocationUrl(this, extensionValue);
                        break;
                    }
                case NETSCAPE_CERTIFICATE_TYPE:
                    {
                        dExtension = new DNetscapeCertificateType(this, extensionValue);
                        break;
                    }
                case NETSCAPE_COMMENT:
                    {
                        dExtension = new DNetscapeComment(this, extensionValue);
                        break;
                    }
                case NETSCAPE_REVOCATION_URL:
                    {
                        dExtension = new DNetscapeRevocationUrl(this, extensionValue);
                        break;
                    }
                case NETSCAPE_SSL_SERVER_NAME:
                    {
                        dExtension = new DNetscapeSslServerName(this, extensionValue);
                        break;
                    }
                case POLICY_CONSTRAINTS:
                    {
                        dExtension = new DPolicyConstraints(this, extensionValue);
                        break;
                    }
                case POLICY_MAPPINGS:
                    {
                        dExtension = new DPolicyMappings(this, extensionValue);
                        break;
                    }
                case PRIVATE_KEY_USAGE_PERIOD:
                    {
                        dExtension = new DPrivateKeyUsagePeriod(this, extensionValue);
                        break;
                    }
                case SUBJECT_ALTERNATIVE_NAME:
                    {
                        dExtension = new DSubjectAlternativeName(this, extensionValue);
                        break;
                    }
                case SUBJECT_INFORMATION_ACCESS:
                    {
                        dExtension = new DSubjectInformationAccess(this, extensionValue);
                        break;
                    }
                case SUBJECT_KEY_IDENTIFIER:
                    {
                        dExtension = new DSubjectKeyIdentifier(this, extensionValue, subjectPublicKey);
                        break;
                    }
                default:
                    {
                        return;
                    }
            }
            dExtension.setLocationRelativeTo(this);
            dExtension.setVisible(true);
            newExtensionValue = dExtension.getValue();
            if (newExtensionValue == null) {
                return;
            }
            extensions.addExtension(oid, isCritical, newExtensionValue);
            reloadExtensionsTable();
            selectExtensionInTable(oid);
            updateButtonControls();
        }
    } catch (IOException ex) {
        DError dError = new DError(this, ex);
        dError.setLocationRelativeTo(this);
        dError.setVisible(true);
    }
}
Also used : IOException(java.io.IOException) Point(java.awt.Point) DError(org.kse.gui.error.DError) X509ExtensionType(org.kse.crypto.x509.X509ExtensionType) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Aggregations

X509ExtensionType (org.kse.crypto.x509.X509ExtensionType)4 BorderLayout (java.awt.BorderLayout)1 Point (java.awt.Point)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 AbstractAction (javax.swing.AbstractAction)1 JButton (javax.swing.JButton)1 JCheckBox (javax.swing.JCheckBox)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 CompoundBorder (javax.swing.border.CompoundBorder)1 EmptyBorder (javax.swing.border.EmptyBorder)1 EtchedBorder (javax.swing.border.EtchedBorder)1