Example usage for org.bouncycastle.asn1 DERSequence DERSequence

List of usage examples for org.bouncycastle.asn1 DERSequence DERSequence

Introduction

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

Prototype

public DERSequence(ASN1Encodable[] elements) 

Source Link

Document

Create a sequence containing an array of objects.

Usage

From source file:org.glite.security.util.proxy.ProxyPolicy.java

License:Apache License

/**
 * output the ASN1 object of the proxy policy.
 * /*from  ww w  .jav  a 2  s.  com*/
 * @see org.bouncycastle.asn1.ASN1Encodable#toASN1Object()
 */
public DERObject toASN1Object() {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(new DERObjectIdentifier(m_oid));
    if (m_policy != null) {
        v.add(new DEROctetString(m_policy));
    }

    return new DERSequence(v);
}

From source file:org.glite.security.util.proxy.ProxyRestrictionData.java

License:Apache License

/**
 * Returns the NameConstraints structure of the restrictions.
 * //from w ww  . j  a v a2 s .  com
 * @return The DERSequence containing the NameConstraints structure.
 */
public DERSequence getNameConstraints() {
    // The NameConstraints sequence
    ASN1EncodableVector nameConstraintsSequenceVector = new ASN1EncodableVector();

    addTaggedSequenceOfSubtrees(0, m_permittedGeneralSubtrees, nameConstraintsSequenceVector);
    addTaggedSequenceOfSubtrees(1, m_excludedGeneralSubtrees, nameConstraintsSequenceVector);

    return new DERSequence(nameConstraintsSequenceVector);
}

From source file:org.glite.security.util.proxy.ProxyRestrictionData.java

License:Apache License

/**
 * Adds, with the given tag, a DER sequence object that contains the GeneralSubtree objects into the ASN1Vector.
 * //  w  w  w.ja  v  a2  s. co m
 * @param tagNo The tag to tag the object.
 * @param subtrees The Vector of GeneralSubtree objects. Null will throw NullPointerException. An empty Vector will
 *            not be added.
 * @param asn1Vector The vector to add the subtrees sequence with the given tag.
 */
private static void addTaggedSequenceOfSubtrees(int tagNo, Vector<GeneralSubtree> subtrees,
        ASN1EncodableVector asn1Vector) {
    if (!subtrees.isEmpty()) {
        ASN1EncodableVector subtreesSequenceVector = new ASN1EncodableVector();

        Enumeration<GeneralSubtree> generalSubtreesEnum = subtrees.elements();
        while (generalSubtreesEnum.hasMoreElements()) {
            subtreesSequenceVector.add(generalSubtreesEnum.nextElement());
        }
        asn1Vector.add(new DERTaggedObject(tagNo, new DERSequence(subtreesSequenceVector)));
    }
}

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

License:eu-egee.org license

/**
 * Builds a {@link X509Principal}, based on the given vectors.
 * /*from  w  ww. j  av a  2s .  co  m*/
 * @param ordering
 * @param values
 * @param added
 * @return the {@link X509Principal} or <code>null</code> if an error
 *         occurs.
 * @throws IOException
 *             if a DER encoding error occurs.
 */
private X509Principal buildX509Principal(Vector<DERObjectIdentifier> ordering, Vector<Object> values,
        Vector<Boolean> added) throws IOException {
    X509NameEntryConverter converter = new X509DefaultEntryConverter();
    ASN1EncodableVector vec = new ASN1EncodableVector();
    ASN1EncodableVector sVec = new ASN1EncodableVector();
    DERObjectIdentifier lstOid = null;
    // Bouncycastle's code
    for (int i = 0; i != ordering.size(); i++) {
        ASN1EncodableVector v = new ASN1EncodableVector();
        DERObjectIdentifier oid = ordering.elementAt(i);
        v.add(oid);
        String str = (String) values.elementAt(i);
        v.add(converter.getConvertedValue(oid, str));
        if (lstOid == null || added.elementAt(i)) {
            sVec.add(new DERSequence(v));
        } else {
            vec.add(new DERSet(sVec));
            sVec = new ASN1EncodableVector();
            sVec.add(new DERSequence(v));
        }

        lstOid = oid;
    }
    vec.add(new DERSet(sVec));
    DERSequence seq = new DERSequence(vec);
    byte[] bytes = seq.getDEREncoded();
    return new X509Principal(bytes);
}

From source file:org.glite.slcs.pki.CertificateExtensionFactory.java

License:eu-egee.org license

/**
 * //  ww w  . jav a  2 s . co m
 * @param keyPurposeId
 * @param keyPurposeName
 * @return
 */
static protected CertificateExtension createExtendedKeyUsageExtension(KeyPurposeId keyPurposeId,
        String keyPurposeName) {
    DERSequence keyPurposeIds = new DERSequence(keyPurposeId);
    ExtendedKeyUsage extendedKeyUsage = new ExtendedKeyUsage(keyPurposeIds);
    X509Extension extendedKeyUsageExtension = new X509Extension(false, new DEROctetString(extendedKeyUsage));
    return new CertificateExtension(X509Extensions.ExtendedKeyUsage, "ExtendedKeyUsage",
            extendedKeyUsageExtension, keyPurposeName);
}

From source file:org.glite.slcs.pki.CertificateExtensionFactory.java

License:eu-egee.org license

/**
 * /*from   ww w .j  a v a  2s .c o  m*/
 * @param prefixedAltNames
 * @param values
 * @return
 */
static protected CertificateExtension createSubjectAltNameExtension(Vector prefixedAltNames, String values) {
    ASN1EncodableVector altNames = new ASN1EncodableVector();
    Enumeration typeAndNames = prefixedAltNames.elements();
    while (typeAndNames.hasMoreElements()) {
        String typeAndName = (String) typeAndNames.nextElement();
        typeAndName = typeAndName.trim();
        if (typeAndName.startsWith("email:")) {
            String emailAddress = typeAndName.substring("email:".length());
            GeneralName altName = new GeneralName(GeneralName.rfc822Name, emailAddress);
            altNames.add(altName);

        } else if (typeAndName.startsWith("dns:")) {
            String hostname = typeAndName.substring("dns:".length());
            GeneralName altName = new GeneralName(GeneralName.dNSName, hostname);
            altNames.add(altName);
        } else {
            LOG.error("Unsupported subjectAltName: " + typeAndName);
        }
    }
    DERSequence subjectAltNames = new DERSequence(altNames);
    GeneralNames generalNames = new GeneralNames(subjectAltNames);
    X509Extension subjectAltNameExtension = new X509Extension(false, new DEROctetString(generalNames));
    return new CertificateExtension(X509Extensions.SubjectAlternativeName, "SubjectAltName",
            subjectAltNameExtension, values);

}

From source file:org.glite.slcs.pki.CertificateExtensionFactory.java

License:eu-egee.org license

/**
 * Creates a Cerificate Policies: policyOID extension with the given policy
 * OID.// w ww. java2 s .  co m
 * 
 * @param policyOID
 *            The policy OID (2.16.756.1.2.*)
 * @return The certificate policies CertificateExtension.
 */
static protected CertificateExtension createCertificatePoliciesExtension(String policyOID) {
    DERObjectIdentifier policyIdentifier = new DERObjectIdentifier(policyOID);
    PolicyInformation policyInformation = new PolicyInformation(policyIdentifier);
    DERSequence certificatePolicies = new DERSequence(policyInformation);
    X509Extension certificatePoliciesExtension = new X509Extension(false,
            new DEROctetString(certificatePolicies));
    return new CertificateExtension(X509Extensions.CertificatePolicies, "CertificatePolicies",
            certificatePoliciesExtension, policyOID);
}

From source file:org.glite.slcs.pki.CertificateExtensionFactory.java

License:eu-egee.org license

/**
 * //from  w w w.  j  ava  2  s.  c o  m
 * @param policyOIDs
 * @param values
 * @return
 */
static protected CertificateExtension createCertificatePoliciesExtension(Vector policyOIDs, String values) {
    ASN1EncodableVector policyInformations = new ASN1EncodableVector();
    Enumeration pOids = policyOIDs.elements();
    while (pOids.hasMoreElements()) {
        String policyOid = (String) pOids.nextElement();
        DERObjectIdentifier policyIdentifier = new DERObjectIdentifier(policyOid);
        PolicyInformation policyInformation = new PolicyInformation(policyIdentifier);
        policyInformations.add(policyInformation);

    }
    DERSequence certificatePolicies = new DERSequence(policyInformations);
    X509Extension certificatePoliciesExtension = new X509Extension(false,
            new DEROctetString(certificatePolicies));
    return new CertificateExtension(X509Extensions.CertificatePolicies, "CertificatePolicies",
            certificatePoliciesExtension, values);
}

From source file:org.glite.voms.ac.ACCerts.java

License:Open Source License

/**
 * Makes a DERObject representation.//from   w w w  . j  a v  a2s.c  o m
 *
 * @return the DERObject
 */
public ASN1Primitive toASN1Primitive() {
    DEREncodableVector v = new DEREncodableVector();

    ListIterator li = l.listIterator();
    while (li.hasNext()) {
        X509CertificateStructure x509 = (X509CertificateStructure) li.next();
        v.add(x509);
    }
    return new DERSequence(v);
}

From source file:org.glite.voms.ac.ACTargets.java

License:Open Source License

/**
 * Makes a DERObject representation./*  w w  w . j  a v a2 s .c  o  m*/
 *
 * @return the DERObject
 */
public ASN1Primitive toASN1Primitive() {
    DEREncodableVector v = new DEREncodableVector();

    ListIterator li = l.listIterator();
    while (li.hasNext()) {
        ACTarget c = (ACTarget) li.next();
        v.add(c);
    }
    return new DERSequence(v);
}