Example usage for org.bouncycastle.asn1.x509 Attribute Attribute

List of usage examples for org.bouncycastle.asn1.x509 Attribute Attribute

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.x509 Attribute Attribute.

Prototype

private Attribute(ASN1Sequence seq) 

Source Link

Usage

From source file:org.glite.slcs.pki.bouncycastle.PKCS10.java

License:eu-egee.org license

/**
 * Gets the X509Extensions included in the PKCS10.
 * //from  w  w w . ja  v  a2s .  c o m
 * @return The X509Extensions or <code>null</code> if there is no
 *         X509Extensions.
 */
public X509Extensions getX509Extensions() {
    X509Extensions x509Extensions = null;
    ASN1Set attributes = this.bcPKCS10_.getCertificationRequestInfo().getAttributes();
    if (attributes.size() > 0) {
        ASN1Sequence attributeSequence = (ASN1Sequence) attributes.getObjectAt(0);
        Attribute attribute = new Attribute(attributeSequence);
        DERObjectIdentifier oid = attribute.getAttrType();
        if (oid.equals(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest)) {
            ASN1Set attributeValues = attribute.getAttrValues();
            if (attributeValues.size() > 0) {
                ASN1Sequence x509extensionsSequence = (ASN1Sequence) attributeValues.getObjectAt(0);
                x509Extensions = new X509Extensions(x509extensionsSequence);

            }
        }
    }
    return x509Extensions;
}

From source file:org.qipki.crypto.x509.X509ExtensionsReaderImpl.java

License:Open Source License

@Override
public List<X509ExtensionHolder> extractRequestedExtensions(PKCS10CertificationRequest pkcs10) {
    final List<X509ExtensionHolder> extractedExtensions = new ArrayList<X509ExtensionHolder>();
    final CertificationRequestInfo certificationRequestInfo = pkcs10.getCertificationRequestInfo();
    final ASN1Set attributesAsn1Set = certificationRequestInfo.getAttributes();
    if (attributesAsn1Set == null) {
        return extractedExtensions;
    }/*from   www.j a v  a 2s .c  om*/
    // The `Extension Request` attribute is contained within an ASN.1 Set,
    // usually as the first element.
    X509Extensions requestedExtensions = null;
    for (int i = 0; i < attributesAsn1Set.size(); ++i) {
        // There should be only only one attribute in the set. (that is, only
        // the `Extension Request`, but loop through to find it properly)
        final DEREncodable derEncodable = attributesAsn1Set.getObjectAt(i);
        if (derEncodable instanceof DERSequence) {
            final Attribute attribute = new Attribute((DERSequence) attributesAsn1Set.getObjectAt(i));

            if (attribute.getAttrType().equals(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest)) {
                // The `Extension Request` attribute is present.
                final ASN1Set attributeValues = attribute.getAttrValues();

                // The X509Extensions are contained as a value of the ASN.1 Set.
                // WARN Assuming that it is the first value of the set.
                if (attributeValues.size() >= 1) {
                    DEREncodable extensionsDEREncodable = attributeValues.getObjectAt(0);
                    ASN1Sequence extensionsASN1Sequence = (ASN1Sequence) extensionsDEREncodable;
                    requestedExtensions = new X509Extensions(extensionsASN1Sequence);
                    // No need to search any more.
                    break;
                }
            }
        }
    }
    if (requestedExtensions != null) {
        Enumeration<?> e = requestedExtensions.oids();
        while (e.hasMoreElements()) {
            DERObjectIdentifier oid = (DERObjectIdentifier) e.nextElement();
            X509Extension extension = requestedExtensions.getExtension(oid);
            extractedExtensions.add(new X509ExtensionHolder(oid, extension.isCritical(),
                    X509Extension.convertValueToObject(extension)));
        }
    }
    return extractedExtensions;
}