Example usage for org.bouncycastle.cert X509AttributeCertificateHolder getSignature

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

Introduction

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

Prototype

public byte[] getSignature() 

Source Link

Document

Return the bytes making up the signature associated with this attribute certificate.

Usage

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

License:Apache License

/**
 * Deserializes the information in a VOMS attribute certificate.
 * //from w  w w  . j a  v a 2  s. co  m
 * @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;
}