Search in sources :

Example 16 with ASN1ObjectIdentifier

use of org.bouncycastle.asn1.ASN1ObjectIdentifier in project robovm by robovm.

the class AttributeTable method getAll.

/**
     * Return all the attributes matching the OBJECT IDENTIFIER oid. The vector will be 
     * empty if there are no attributes of the required type present.
     * 
     * @param oid type of attribute required.
     * @return a vector of all the attributes found of type oid.
     */
public ASN1EncodableVector getAll(ASN1ObjectIdentifier oid) {
    ASN1EncodableVector v = new ASN1EncodableVector();
    Object value = attributes.get(oid);
    if (value instanceof Vector) {
        Enumeration e = ((Vector) value).elements();
        while (e.hasMoreElements()) {
            v.add((Attribute) e.nextElement());
        }
    } else if (value != null) {
        v.add((Attribute) value);
    }
    return v;
}
Also used : Enumeration(java.util.Enumeration) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) Vector(java.util.Vector) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector)

Example 17 with ASN1ObjectIdentifier

use of org.bouncycastle.asn1.ASN1ObjectIdentifier in project robovm by robovm.

the class SignedData method calculateVersion.

// RFC3852, section 5.1:
// IF ((certificates is present) AND
//    (any certificates with a type of other are present)) OR
//    ((crls is present) AND
//    (any crls with a type of other are present))
// THEN version MUST be 5
// ELSE
//    IF (certificates is present) AND
//       (any version 2 attribute certificates are present)
//    THEN version MUST be 4
//    ELSE
//       IF ((certificates is present) AND
//          (any version 1 attribute certificates are present)) OR
//          (any SignerInfo structures are version 3) OR
//          (encapContentInfo eContentType is other than id-data)
//       THEN version MUST be 3
//       ELSE version MUST be 1
//
private ASN1Integer calculateVersion(ASN1ObjectIdentifier contentOid, ASN1Set certs, ASN1Set crls, ASN1Set signerInfs) {
    boolean otherCert = false;
    boolean otherCrl = false;
    boolean attrCertV1Found = false;
    boolean attrCertV2Found = false;
    if (certs != null) {
        for (Enumeration en = certs.getObjects(); en.hasMoreElements(); ) {
            Object obj = en.nextElement();
            if (obj instanceof ASN1TaggedObject) {
                ASN1TaggedObject tagged = ASN1TaggedObject.getInstance(obj);
                if (tagged.getTagNo() == 1) {
                    attrCertV1Found = true;
                } else if (tagged.getTagNo() == 2) {
                    attrCertV2Found = true;
                } else if (tagged.getTagNo() == 3) {
                    otherCert = true;
                }
            }
        }
    }
    if (otherCert) {
        return new ASN1Integer(5);
    }
    if (// no need to check if otherCert is true
    crls != null) {
        for (Enumeration en = crls.getObjects(); en.hasMoreElements(); ) {
            Object obj = en.nextElement();
            if (obj instanceof ASN1TaggedObject) {
                otherCrl = true;
            }
        }
    }
    if (otherCrl) {
        return VERSION_5;
    }
    if (attrCertV2Found) {
        return VERSION_4;
    }
    if (attrCertV1Found) {
        return VERSION_3;
    }
    if (checkForVersion3(signerInfs)) {
        return VERSION_3;
    }
    if (!CMSObjectIdentifiers.data.equals(contentOid)) {
        return VERSION_3;
    }
    return VERSION_1;
}
Also used : Enumeration(java.util.Enumeration) ASN1TaggedObject(org.bouncycastle.asn1.ASN1TaggedObject) ASN1TaggedObject(org.bouncycastle.asn1.ASN1TaggedObject) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) BERTaggedObject(org.bouncycastle.asn1.BERTaggedObject) ASN1Object(org.bouncycastle.asn1.ASN1Object) ASN1Integer(org.bouncycastle.asn1.ASN1Integer)

Example 18 with ASN1ObjectIdentifier

use of org.bouncycastle.asn1.ASN1ObjectIdentifier in project robovm by robovm.

the class X509Name method decodeOID.

private ASN1ObjectIdentifier decodeOID(String name, Hashtable lookUp) {
    name = name.trim();
    if (Strings.toUpperCase(name).startsWith("OID.")) {
        return new ASN1ObjectIdentifier(name.substring(4));
    } else if (name.charAt(0) >= '0' && name.charAt(0) <= '9') {
        return new ASN1ObjectIdentifier(name);
    }
    ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) lookUp.get(Strings.toLowerCase(name));
    if (oid == null) {
        throw new IllegalArgumentException("Unknown object id - " + name + " - passed to distinguished name");
    }
    return oid;
}
Also used : ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 19 with ASN1ObjectIdentifier

use of org.bouncycastle.asn1.ASN1ObjectIdentifier in project robovm by robovm.

the class X509Name method toString.

/**
     * convert the structure to a string - if reverse is true the
     * oids and values are listed out starting with the last element
     * in the sequence (ala RFC 2253), otherwise the string will begin
     * with the first element of the structure. If no string definition
     * for the oid is found in oidSymbols the string value of the oid is
     * added. Two standard symbol tables are provided DefaultSymbols, and
     * RFC2253Symbols as part of this class.
     *
     * @param reverse if true start at the end of the sequence and work back.
     * @param oidSymbols look up table strings for oids.
     */
public String toString(boolean reverse, Hashtable oidSymbols) {
    StringBuffer buf = new StringBuffer();
    Vector components = new Vector();
    boolean first = true;
    StringBuffer ava = null;
    for (int i = 0; i < ordering.size(); i++) {
        if (((Boolean) added.elementAt(i)).booleanValue()) {
            ava.append('+');
            appendValue(ava, oidSymbols, (ASN1ObjectIdentifier) ordering.elementAt(i), (String) values.elementAt(i));
        } else {
            ava = new StringBuffer();
            appendValue(ava, oidSymbols, (ASN1ObjectIdentifier) ordering.elementAt(i), (String) values.elementAt(i));
            components.addElement(ava);
        }
    }
    if (reverse) {
        for (int i = components.size() - 1; i >= 0; i--) {
            if (first) {
                first = false;
            } else {
                buf.append(',');
            }
            buf.append(components.elementAt(i).toString());
        }
    } else {
        for (int i = 0; i < components.size(); i++) {
            if (first) {
                first = false;
            } else {
                buf.append(',');
            }
            buf.append(components.elementAt(i).toString());
        }
    }
    return buf.toString();
}
Also used : ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) Vector(java.util.Vector)

Example 20 with ASN1ObjectIdentifier

use of org.bouncycastle.asn1.ASN1ObjectIdentifier in project robovm by robovm.

the class X509Name method toASN1Primitive.

public ASN1Primitive toASN1Primitive() {
    if (seq == null) {
        ASN1EncodableVector vec = new ASN1EncodableVector();
        ASN1EncodableVector sVec = new ASN1EncodableVector();
        ASN1ObjectIdentifier lstOid = null;
        for (int i = 0; i != ordering.size(); i++) {
            ASN1EncodableVector v = new ASN1EncodableVector();
            ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) ordering.elementAt(i);
            v.add(oid);
            String str = (String) values.elementAt(i);
            v.add(converter.getConvertedValue(oid, str));
            if (lstOid == null || ((Boolean) this.added.elementAt(i)).booleanValue()) {
                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));
        seq = new DERSequence(vec);
    }
    return seq;
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) ASN1String(org.bouncycastle.asn1.ASN1String) DERUniversalString(org.bouncycastle.asn1.DERUniversalString) DERSet(org.bouncycastle.asn1.DERSet) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Aggregations

ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)331 IOException (java.io.IOException)85 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)80 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)61 DEROctetString (org.bouncycastle.asn1.DEROctetString)60 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)57 DERIA5String (org.bouncycastle.asn1.DERIA5String)57 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)52 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)50 DERSequence (org.bouncycastle.asn1.DERSequence)47 DERPrintableString (org.bouncycastle.asn1.DERPrintableString)44 ASN1String (org.bouncycastle.asn1.ASN1String)41 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)38 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)37 Extension (org.bouncycastle.asn1.x509.Extension)36 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)35 ArrayList (java.util.ArrayList)34 BigInteger (java.math.BigInteger)33 X500Name (org.bouncycastle.asn1.x500.X500Name)33 HashSet (java.util.HashSet)31