Search in sources :

Example 91 with Attribute

use of org.bouncycastle.asn1.x509.Attribute in project xipki by xipki.

the class SubjectChecker method checkSubjectAttributeMultiValued.

// method checkSubjectAttributeNotMultiValued
private ValidationIssue checkSubjectAttributeMultiValued(ASN1ObjectIdentifier type, X500Name subject, X500Name requestedSubject) throws BadCertTemplateException {
    ValidationIssue issue = createSubjectIssue(type);
    RDN[] rdns = subject.getRDNs(type);
    int rdnsSize = (rdns == null) ? 0 : rdns.length;
    RDN[] requestedRdns = requestedSubject.getRDNs(type);
    if (rdnsSize != 1) {
        if (rdnsSize == 0) {
            // check optional attribute but is present in requestedSubject
            if (requestedRdns != null && requestedRdns.length > 0) {
                issue.setFailureMessage("is absent but expected present");
            }
        } else {
            issue.setFailureMessage("number of RDNs '" + rdnsSize + "' is not 1");
        }
        return issue;
    }
    // control
    final RdnControl rdnControl = subjectControl.getControl(type);
    // check the encoding
    StringType stringType = null;
    if (rdnControl != null) {
        stringType = rdnControl.getStringType();
    }
    List<String> requestedCoreAtvTextValues = new LinkedList<>();
    if (requestedRdns != null) {
        for (RDN requestedRdn : requestedRdns) {
            String textValue = getRdnTextValueOfRequest(requestedRdn);
            requestedCoreAtvTextValues.add(textValue);
        }
        if (rdnControl != null && rdnControl.getPatterns() != null) {
            // sort the requestedRDNs
            requestedCoreAtvTextValues = sort(requestedCoreAtvTextValues, rdnControl.getPatterns());
        }
    }
    if (rdns == null) {
        // return always false, only to make the null checker happy
        return issue;
    }
    StringBuilder failureMsg = new StringBuilder();
    AttributeTypeAndValue[] li = rdns[0].getTypesAndValues();
    List<AttributeTypeAndValue> atvs = new LinkedList<>();
    for (AttributeTypeAndValue m : li) {
        if (type.equals(m.getType())) {
            atvs.add(m);
        }
    }
    final int atvsSize = atvs.size();
    int minOccurs = (rdnControl == null) ? 0 : rdnControl.getMinOccurs();
    int maxOccurs = (rdnControl == null) ? 0 : rdnControl.getMaxOccurs();
    if (atvsSize < minOccurs || atvsSize > maxOccurs) {
        issue.setFailureMessage("number of AttributeTypeAndValuess '" + atvsSize + "' is not within [" + minOccurs + ", " + maxOccurs + "]");
        return issue;
    }
    for (int i = 0; i < atvsSize; i++) {
        AttributeTypeAndValue atv = atvs.get(i);
        String atvTextValue = getAtvValueString("AttributeTypeAndValue[" + i + "]", atv, stringType, failureMsg);
        if (atvTextValue == null) {
            continue;
        }
        checkAttributeTypeAndValue("AttributeTypeAndValue[" + i + "]", type, atvTextValue, rdnControl, requestedCoreAtvTextValues, i, failureMsg);
    }
    int len = failureMsg.length();
    if (len > 2) {
        failureMsg.delete(len - 2, len);
        issue.setFailureMessage(failureMsg.toString());
    }
    return issue;
}
Also used : StringType(org.xipki.ca.api.profile.StringType) DERBMPString(org.bouncycastle.asn1.DERBMPString) DERIA5String(org.bouncycastle.asn1.DERIA5String) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) DERT61String(org.bouncycastle.asn1.DERT61String) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) ValidationIssue(org.xipki.common.qa.ValidationIssue) LinkedList(java.util.LinkedList) AttributeTypeAndValue(org.bouncycastle.asn1.x500.AttributeTypeAndValue) RdnControl(org.xipki.ca.api.profile.RdnControl) RDN(org.bouncycastle.asn1.x500.RDN)

Example 92 with Attribute

use of org.bouncycastle.asn1.x509.Attribute in project xipki by xipki.

the class SubjectChecker method createSubjectIssue.

private static ValidationIssue createSubjectIssue(ASN1ObjectIdentifier subjectAttrType) {
    ValidationIssue issue;
    String attrName = ObjectIdentifiers.getName(subjectAttrType);
    if (attrName == null) {
        attrName = subjectAttrType.getId().replace('.', '_');
        issue = new ValidationIssue("X509.SUBJECT." + attrName, "attribute " + subjectAttrType.getId());
    } else {
        issue = new ValidationIssue("X509.SUBJECT." + attrName, "attribute " + attrName + " (" + subjectAttrType.getId() + ")");
    }
    return issue;
}
Also used : DERBMPString(org.bouncycastle.asn1.DERBMPString) DERIA5String(org.bouncycastle.asn1.DERIA5String) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) DERT61String(org.bouncycastle.asn1.DERT61String) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) ValidationIssue(org.xipki.common.qa.ValidationIssue)

Example 93 with Attribute

use of org.bouncycastle.asn1.x509.Attribute in project xipki by xipki.

the class CaUtil method getExtensions.

public static Extensions getExtensions(CertificationRequestInfo csr) {
    ParamUtil.requireNonNull("csr", csr);
    ASN1Set attrs = csr.getAttributes();
    for (int i = 0; i < attrs.size(); i++) {
        Attribute attr = Attribute.getInstance(attrs.getObjectAt(i));
        if (PKCSObjectIdentifiers.pkcs_9_at_extensionRequest.equals(attr.getAttrType())) {
            return Extensions.getInstance(attr.getAttributeValues()[0]);
        }
    }
    return null;
}
Also used : ASN1Set(org.bouncycastle.asn1.ASN1Set) Attribute(org.bouncycastle.asn1.pkcs.Attribute) DistributionPoint(org.bouncycastle.asn1.x509.DistributionPoint) CRLDistPoint(org.bouncycastle.asn1.x509.CRLDistPoint)

Example 94 with Attribute

use of org.bouncycastle.asn1.x509.Attribute in project jspwiki by apache.

the class XHtmlElementToWikiTranslator method printChildren.

private void printChildren(Element base) throws IOException, JDOMException {
    for (Iterator i = base.getContent().iterator(); i.hasNext(); ) {
        Object c = i.next();
        if (c instanceof Element) {
            Element e = (Element) c;
            String n = e.getName().toLowerCase();
            if (n.equals("h1")) {
                m_out.print("\n!!! ");
                print(e);
                m_out.println();
            } else if (n.equals("h2")) {
                m_out.print("\n!!! ");
                print(e);
                m_out.println();
            } else if (n.equals("h3")) {
                m_out.print("\n!! ");
                print(e);
                m_out.println();
            } else if (n.equals("h4")) {
                m_out.print("\n! ");
                print(e);
                m_out.println();
            } else if (n.equals("p")) {
                if (// we don't want to print empty elements: <p></p>
                e.getContentSize() != 0) {
                    m_out.println();
                    print(e);
                    m_out.println();
                }
            } else if (n.equals("br")) {
                if (m_preStack.isPreMode()) {
                    m_out.println();
                } else {
                    String parentElementName = base.getName().toLowerCase();
                    // 
                    if (parentElementName.matches("p|div") && !base.getText().matches("(?s).*\\[\\{.*\\}\\].*")) {
                        m_out.print(" \\\\\n");
                    } else {
                        m_out.print(" \\\\");
                    }
                }
                print(e);
            } else if (n.equals("hr")) {
                m_out.println();
                print("----");
                print(e);
                m_out.println();
            } else if (n.equals("table")) {
                if (!m_outTimmer.isCurrentlyOnLineBegin()) {
                    m_out.println();
                }
                print(e);
            } else if (n.equals("tr")) {
                print(e);
                m_out.println();
            } else if (n.equals("td")) {
                m_out.print("| ");
                print(e);
                if (!m_preStack.isPreMode()) {
                    print(" ");
                }
            } else if (n.equals("th")) {
                m_out.print("|| ");
                print(e);
                if (!m_preStack.isPreMode()) {
                    print(" ");
                }
            } else if (n.equals("a")) {
                if (!isIgnorableWikiMarkupLink(e)) {
                    if (e.getChild("IMG") != null) {
                        printImage(e);
                    } else {
                        String ref = e.getAttributeValue("href");
                        if (ref == null) {
                            if (isUndefinedPageLink(e)) {
                                m_out.print("[");
                                print(e);
                                m_out.print("]");
                            } else {
                                print(e);
                            }
                        } else {
                            ref = trimLink(ref);
                            if (ref != null) {
                                if (// This is a link to a footnote.
                                ref.startsWith("#")) {
                                    // convert "#ref-PageName-1" to just "1"
                                    String href = ref.replaceFirst("#ref-.+-(\\d+)", "$1");
                                    // remove the brackets around "[1]"
                                    String textValue = e.getValue().substring(1, (e.getValue().length() - 1));
                                    if (href.equals(textValue)) {
                                        // handles the simplest case. Example: [1]
                                        print(e);
                                    } else {
                                        // handles the case where the link text is different from the href. Example: [something|1]
                                        m_out.print("[" + textValue + "|" + href + "]");
                                    }
                                } else {
                                    Map augmentedWikiLinkAttributes = getAugmentedWikiLinkAttributes(e);
                                    m_out.print("[");
                                    print(e);
                                    if (!e.getTextTrim().equalsIgnoreCase(ref)) {
                                        m_out.print("|");
                                        print(ref);
                                        if (!augmentedWikiLinkAttributes.isEmpty()) {
                                            m_out.print("|");
                                            String augmentedWikiLink = augmentedWikiLinkMapToString(augmentedWikiLinkAttributes);
                                            m_out.print(augmentedWikiLink);
                                        }
                                    } else if (!augmentedWikiLinkAttributes.isEmpty()) {
                                        // If the ref has the same value as the text and also if there
                                        // are attributes, then just print: [ref|ref|attributes] .
                                        m_out.print("|" + ref + "|");
                                        String augmentedWikiLink = augmentedWikiLinkMapToString(augmentedWikiLinkAttributes);
                                        m_out.print(augmentedWikiLink);
                                    }
                                    m_out.print("]");
                                }
                            }
                        }
                    }
                }
            } else if (n.equals("b") || n.equals("strong")) {
                m_out.print("__");
                print(e);
                m_out.print("__");
            } else if (n.equals("i") || n.equals("em") || n.equals("address")) {
                m_out.print("''");
                print(e);
                m_out.print("''");
            } else if (n.equals("u")) {
                m_out.print("%%( text-decoration:underline; )");
                print(e);
                m_out.print("/%");
            } else if (n.equals("strike")) {
                m_out.print("%%strike ");
                print(e);
                m_out.print("/%");
            // NOTE: don't print a space before or after the double percents because that can break words into two.
            // For example: %%(color:red)ABC%%%%(color:green)DEF%% is different from %%(color:red)ABC%% %%(color:green)DEF%%
            } else if (n.equals("sup")) {
                m_out.print("%%sup ");
                print(e);
                m_out.print("/%");
            } else if (n.equals("sub")) {
                m_out.print("%%sub ");
                print(e);
                m_out.print("/%");
            } else if (n.equals("dl")) {
                m_out.print("\n");
                print(e);
                // print a newline after the definition list. If we don't,
                // it may cause problems for the subsequent element.
                m_out.print("\n");
            } else if (n.equals("dt")) {
                m_out.print(";");
                print(e);
            } else if (n.equals("dd")) {
                m_out.print(":");
                print(e);
            } else if (n.equals("ul")) {
                m_out.println();
                m_liStack.push("*");
                print(e);
                m_liStack.pop();
            } else if (n.equals("ol")) {
                m_out.println();
                m_liStack.push("#");
                print(e);
                m_liStack.pop();
            } else if (n.equals("li")) {
                m_out.print(m_liStack + " ");
                print(e);
                // The following line assumes that the XHTML has been "pretty-printed"
                // (newlines separate child elements from their parents).
                boolean lastListItem = base.indexOf(e) == (base.getContentSize() - 2);
                boolean sublistItem = m_liStack.toString().length() > 1;
                // only print a newline if this <li> element is not the last item within a sublist.
                if (!sublistItem || !lastListItem) {
                    m_out.println();
                }
            } else if (n.equals("pre")) {
                // start JSPWiki "code blocks" on its own line
                m_out.print("\n{{{");
                m_preStack.push();
                print(e);
                m_preStack.pop();
                // print a newline after the closing braces
                // to avoid breaking any subsequent wiki markup that follows.
                m_out.print("}}}\n");
            } else if (n.equals("code") || n.equals("tt")) {
                m_out.print("{{");
                m_preStack.push();
                print(e);
                m_preStack.pop();
                m_out.print("}}");
            // NOTE: don't print a newline after the closing brackets because if the Text is inside
            // a table or list, it would break it if there was a subsequent row or list item.
            } else if (n.equals("img")) {
                if (!isIgnorableWikiMarkupLink(e)) {
                    m_out.print("[");
                    print(trimLink(e.getAttributeValue("src")));
                    m_out.print("]");
                }
            } else if (n.equals("form")) {
                // remove the hidden input where name="formname" since a new one will be generated again when the xhtml is rendered.
                Element formName = (Element) XPath.selectSingleNode(e, "INPUT[@name='formname']");
                if (formName != null) {
                    formName.detach();
                }
                String name = e.getAttributeValue("name");
                m_out.print("\n[{FormOpen");
                if (name != null) {
                    m_out.print(" form='" + name + "'");
                }
                m_out.print("}]\n");
                print(e);
                m_out.print("\n[{FormClose}]\n");
            } else if (n.equals("input")) {
                String type = e.getAttributeValue("type");
                String name = e.getAttributeValue("name");
                String value = e.getAttributeValue("value");
                String checked = e.getAttributeValue("checked");
                m_out.print("[{FormInput");
                if (type != null) {
                    m_out.print(" type='" + type + "'");
                }
                if (name != null) {
                    // remove the "nbf_" that was prepended since new one will be generated again when the xhtml is rendered.
                    if (name.startsWith("nbf_")) {
                        name = name.substring(4, name.length());
                    }
                    m_out.print(" name='" + name + "'");
                }
                if (value != null && !value.equals("")) {
                    m_out.print(" value='" + value + "'");
                }
                if (checked != null) {
                    m_out.print(" checked='" + checked + "'");
                }
                m_out.print("}]");
                print(e);
            } else if (n.equals("textarea")) {
                String name = e.getAttributeValue("name");
                String rows = e.getAttributeValue("rows");
                String cols = e.getAttributeValue("cols");
                m_out.print("[{FormTextarea");
                if (name != null) {
                    if (name.startsWith("nbf_")) {
                        name = name.substring(4, name.length());
                    }
                    m_out.print(" name='" + name + "'");
                }
                if (rows != null) {
                    m_out.print(" rows='" + rows + "'");
                }
                if (cols != null) {
                    m_out.print(" cols='" + cols + "'");
                }
                m_out.print("}]");
                print(e);
            } else if (n.equals("select")) {
                String name = e.getAttributeValue("name");
                m_out.print("[{FormSelect");
                if (name != null) {
                    if (name.startsWith("nbf_")) {
                        name = name.substring(4, name.length());
                    }
                    m_out.print(" name='" + name + "'");
                }
                m_out.print(" value='");
                print(e);
                m_out.print("'}]");
            } else if (n.equals("option")) {
                // is expected to be a newline character which is at index of 0).
                if (base.indexOf(e) != 1) {
                    m_out.print(";");
                }
                Attribute selected = e.getAttribute("selected");
                if (selected != null) {
                    m_out.print("*");
                }
                String value = e.getAttributeValue("value");
                if (value != null) {
                    m_out.print(value);
                } else {
                    print(e);
                }
            } else {
                print(e);
            }
        } else {
            print(c);
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Iterator(java.util.Iterator) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 95 with Attribute

use of org.bouncycastle.asn1.x509.Attribute in project keystore-explorer by kaikramer.

the class DViewCsr method extensionsPressed.

private void extensionsPressed() {
    // extract sequence with extensions from csr
    Attribute[] attributes = pkcs10Csr.getAttributes(pkcs_9_at_extensionRequest);
    X509ExtensionSet x509ExtensionSet = new X509ExtensionSet();
    if ((attributes != null) && (attributes.length > 0)) {
        ASN1Encodable[] attributeValues = attributes[0].getAttributeValues();
        if (attributeValues.length > 0) {
            ASN1Sequence asn1Sequence = ASN1Sequence.getInstance(attributeValues[0]);
            x509ExtensionSet = new X509ExtensionSet(asn1Sequence);
        }
    }
    DViewExtensions dViewExtensions = new DViewExtensions(this, res.getString("DViewCertificate.Extensions.Title"), x509ExtensionSet);
    dViewExtensions.setLocationRelativeTo(this);
    dViewExtensions.setVisible(true);
}
Also used : X509ExtensionSet(org.kse.crypto.x509.X509ExtensionSet) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) Attribute(org.bouncycastle.asn1.pkcs.Attribute) DViewExtensions(org.kse.gui.dialogs.extensions.DViewExtensions) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable)

Aggregations

Attribute (org.jdom2.Attribute)149 Element (org.jdom2.Element)104 IOException (java.io.IOException)42 ArrayList (java.util.ArrayList)38 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)33 Attribute (org.bouncycastle.asn1.cms.Attribute)29 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)26 X509Certificate (java.security.cert.X509Certificate)25 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)23 Test (org.junit.Test)22 DERSequence (org.bouncycastle.asn1.DERSequence)20 DERSet (org.bouncycastle.asn1.DERSet)20 List (java.util.List)19 Attribute (org.bouncycastle.asn1.pkcs.Attribute)18 Document (org.jdom2.Document)18 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)17 DataConversionException (org.jdom2.DataConversionException)16 Editor (jmri.jmrit.display.Editor)15 CertificateEncodingException (java.security.cert.CertificateEncodingException)14 ASN1Set (org.bouncycastle.asn1.ASN1Set)14