Example usage for org.bouncycastle.asn1.x509 Target getInstance

List of usage examples for org.bouncycastle.asn1.x509 Target getInstance

Introduction

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

Prototype

public static Target getInstance(Object obj) 

Source Link

Document

Creates an instance of a Target from the given object.

Usage

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

License:Apache License

@SuppressWarnings("rawtypes")
private static List<String> deserializeACTargets(X509AttributeCertificateHolder ac) {

    List<String> targets = new ArrayList<String>();

    X509Extension targetExtension = ac.getExtension(X509Extension.targetInformation);

    if (targetExtension == null)
        return targets;

    TargetInformation ti = TargetInformation.getInstance((ASN1Sequence) targetExtension.getParsedValue());

    // Only one Targets according to RFC 3281
    Targets asn1TargetContainer = ti.getTargetsObjects()[0];

    // The deserialization has to be done by hand since it seems VOMS
    // does not correctly encode the ACTargets extension...
    ASN1Sequence targetSequence = (ASN1Sequence) asn1TargetContainer.getDERObject();
    Target[] asn1Targets = new Target[targetSequence.size()];

    int count = 0;

    for (Enumeration e = targetSequence.getObjects(); e.hasMoreElements();) {

        // There's one sequence more than expected here that makes
        // the bc constructor fail...
        ASN1Sequence seq = (ASN1Sequence) e.nextElement();
        ASN1TaggedObject val = (ASN1TaggedObject) seq.getObjectAt(0);
        asn1Targets[count++] = Target.getInstance(val);
    }//  w w  w  .j a v  a 2 s. c  o  m

    // Extract the actual string
    for (Target t : asn1Targets) {

        GeneralName targetURI = t.getTargetName();

        if (targetURI.getTagNo() != GeneralName.uniformResourceIdentifier)
            raiseACNonConformantError("wrong AC target extension encoding. Only URI targets are supported.");

        String targetString = ((DERIA5String) targetURI.getName()).getString();
        targets.add(targetString);
    }
    return targets;
}