Example usage for org.bouncycastle.cert X509AttributeCertificateHolder getAttributes

List of usage examples for org.bouncycastle.cert X509AttributeCertificateHolder getAttributes

Introduction

In this page you can find the example usage for org.bouncycastle.cert X509AttributeCertificateHolder getAttributes.

Prototype

public Attribute[] getAttributes(ASN1ObjectIdentifier type) 

Source Link

Document

Return an array of attributes matching the passed in type OID.

Usage

From source file:AAModulePackage.ACHelper.java

/**
 * This method takes in an AC and wraps it up in the wrapper class.
 * @param ac - X509AttributeCertificateHold that we want to wrap.
 * @return wrapped up AC./*from w w w . ja v  a  2s .  co m*/
 */
public static AttributeCertificateWrapper extractAttributes(X509AttributeCertificateHolder ac) {
    AttributeCertificateWrapper wrapper = new AttributeCertificateWrapper(ac);

    for (Attribute a : ac.getAttributes(NewAttributeIdentifiers.role)) {
        ASN1Set set = a.getAttrValues();
        String s = DERGeneralString.getInstance(set.getObjectAt(0)).getString();
        wrapper.setRole(s);
    }

    for (Attribute a : ac.getAttributes(NewAttributeIdentifiers.record_id)) {
        ASN1Set set = a.getAttrValues();
        String s = DERGeneralString.getInstance(set.getObjectAt(0)).getString();
        wrapper.setRecordId(s);
    }

    for (Attribute a : ac.getAttributes(NewAttributeIdentifiers.time_stamp)) {
        ASN1Set set = a.getAttrValues();
        Time t = new Time(set.getObjectAt(0).toASN1Primitive());
        wrapper.setTimeStamp(t);
    }

    for (Attribute a : ac.getAttributes(NewAttributeIdentifiers.record_type)) {
        ASN1Set set = a.getAttrValues();
        String[] arr = new String[set.size()];
        for (int i = 0; i < set.size(); ++i) {
            arr[i] = DERGeneralString.getInstance(set.getObjectAt(i)).getString();
        }
        wrapper.setRecordTypes(arr);
    }

    for (Attribute a : ac.getAttributes(NewAttributeIdentifiers.record_subject)) {
        ASN1Set set = a.getAttrValues();
        String s = DERGeneralString.getInstance(set.getObjectAt(0)).getString();
        wrapper.setRecord_subject(s);
    }

    for (Attribute a : ac.getAttributes(NewAttributeIdentifiers.actions_taken)) {
        ASN1Set set = a.getAttrValues();
        String[] arr = new String[set.size()];
        for (int i = 0; i < set.size(); ++i) {
            arr[i] = DERGeneralString.getInstance(set.getObjectAt(i)).getString();
        }
        wrapper.setActions_taken(arr);
    }
    return wrapper;
}

From source file:org.italiangrid.voms.asn1.VOMSACUtils.java

License:Apache License

/**
 * Deserializes the information in a VOMS attribute certificate.
 * /*ww  w.  j a  v  a  2s  . c  om*/
 * @param ac
 *          a VOMS {@link AttributeCertificate}
 * @return a {@link VOMSAttribute} object which provides more convenient
 *         access to the VOMS authorization information
 */
public static VOMSAttribute deserializeVOMSAttributes(AttributeCertificate ac) {

    VOMSAttributesImpl attrs = new VOMSAttributesImpl();

    X509AttributeCertificateHolder acHolder = new X509AttributeCertificateHolder(ac);
    Attribute[] asn1Attrs = acHolder.getAttributes(VOMS_FQANS_OID);

    for (Attribute a : asn1Attrs) {
        DERObject theVOMSDerObject = a.getAttributeValues()[0].getDERObject();
        IetfAttrSyntax attrSyntax = new IetfAttrSyntax(ASN1Sequence.getInstance(theVOMSDerObject));

        String policyAuthority = policyAuthoritySanityChecks(attrSyntax);

        // The policy authority string has the following format:
        // <vo name>://<hostname>:<port>

        attrs.setVO(policyAuthority.substring(0, policyAuthority.indexOf(POLICY_AUTHORITY_SEP)));
        attrs.setHost(policyAuthority.substring(policyAuthority.indexOf(POLICY_AUTHORITY_SEP) + 3,
                policyAuthority.lastIndexOf(":")));
        attrs.setPort(Integer.parseInt(policyAuthority.substring(policyAuthority.lastIndexOf(":") + 1)));

        attrs.setFQANs(deserializeFQANs(attrSyntax));

        attrs.setNotBefore(acHolder.getNotBefore());
        attrs.setNotAfter(acHolder.getNotAfter());
        attrs.setSignature(acHolder.getSignature());
        attrs.setGenericAttributes(deserializeGAs(acHolder));
        attrs.setAACertificates(deserializeACCerts(acHolder));
        attrs.setTargets(deserializeACTargets(acHolder));

        attrs.setVOMSAC(acHolder);

        try {

            attrs.setIssuer(new X500Principal(acHolder.getIssuer().getNames()[0].getEncoded()));
            attrs.setHolder(new X500Principal(acHolder.getHolder().getIssuer()[0].getEncoded()));
            attrs.setHolderSerialNumber(acHolder.getHolder().getSerialNumber());

        } catch (IOException e) {
            throw new VOMSError("Error parsing attribute certificate issuer  or holder name: " + e.getMessage(),
                    e);
        }
    }

    return attrs;
}