Search in sources :

Example 16 with Attribute

use of org.bouncycastle.asn1.x509.Attribute in project robovm by robovm.

the class X509AttributeCertificateHolder method getAttributes.

/**
     * Return an  array of attributes matching the passed in type OID.
     *
     * @param type the type of the attribute being looked for.
     * @return an array of Attribute of the requested type, zero length if none present.
     */
public Attribute[] getAttributes(ASN1ObjectIdentifier type) {
    ASN1Sequence seq = attrCert.getAcinfo().getAttributes();
    List list = new ArrayList();
    for (int i = 0; i != seq.size(); i++) {
        Attribute attr = Attribute.getInstance(seq.getObjectAt(i));
        if (attr.getAttrType().equals(type)) {
            list.add(attr);
        }
    }
    if (list.size() == 0) {
        return EMPTY_ARRAY;
    }
    return (Attribute[]) list.toArray(new Attribute[list.size()]);
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) Attribute(org.bouncycastle.asn1.x509.Attribute) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 17 with Attribute

use of org.bouncycastle.asn1.x509.Attribute in project robovm by robovm.

the class CMSSignedData method replaceCertificatesAndCRLs.

/**
     * Replace the certificate and CRL information associated with this
     * CMSSignedData object with the new one passed in.
     *
     * @param signedData the signed data object to be used as a base.
     * @param certificates the new certificates to be used.
     * @param attrCerts the new attribute certificates to be used.
     * @param crls the new CRLs to be used.
     * @return a new signed data object.
     * @exception CMSException if there is an error processing the CertStore
     */
public static CMSSignedData replaceCertificatesAndCRLs(CMSSignedData signedData, Store certificates, Store attrCerts, Store crls) throws CMSException {
    //
    // copy
    //
    CMSSignedData cms = new CMSSignedData(signedData);
    //
    // replace the certs and crls in the SignedData object
    //
    ASN1Set certSet = null;
    ASN1Set crlSet = null;
    if (certificates != null || attrCerts != null) {
        List certs = new ArrayList();
        if (certificates != null) {
            certs.addAll(CMSUtils.getCertificatesFromStore(certificates));
        }
        if (attrCerts != null) {
            certs.addAll(CMSUtils.getAttributeCertificatesFromStore(attrCerts));
        }
        ASN1Set set = CMSUtils.createBerSetFromList(certs);
        if (set.size() != 0) {
            certSet = set;
        }
    }
    if (crls != null) {
        ASN1Set set = CMSUtils.createBerSetFromList(CMSUtils.getCRLsFromStore(crls));
        if (set.size() != 0) {
            crlSet = set;
        }
    }
    //
    // replace the CMS structure.
    //
    cms.signedData = new SignedData(signedData.signedData.getDigestAlgorithms(), signedData.signedData.getEncapContentInfo(), certSet, crlSet, signedData.signedData.getSignerInfos());
    //
    // replace the contentInfo with the new one
    //
    cms.contentInfo = new ContentInfo(cms.contentInfo.getContentType(), cms.signedData);
    return cms;
}
Also used : ASN1Set(org.bouncycastle.asn1.ASN1Set) SignedData(org.bouncycastle.asn1.cms.SignedData) ContentInfo(org.bouncycastle.asn1.cms.ContentInfo) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 18 with Attribute

use of org.bouncycastle.asn1.x509.Attribute in project robovm by robovm.

the class Attribute method toASN1Primitive.

/** 
     * Produce an object suitable for an ASN1OutputStream.
     * <pre>
     * Attribute ::= SEQUENCE {
     *     attrType OBJECT IDENTIFIER,
     *     attrValues SET OF AttributeValue
     * }
     * </pre>
     */
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(attrType);
    v.add(attrValues);
    return new DERSequence(v);
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector)

Example 19 with Attribute

use of org.bouncycastle.asn1.x509.Attribute 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 20 with Attribute

use of org.bouncycastle.asn1.x509.Attribute 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)

Aggregations

Attribute (org.jdom2.Attribute)149 Element (org.jdom2.Element)104 IOException (java.io.IOException)42 ArrayList (java.util.ArrayList)38 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)33 Attribute (org.bouncycastle.asn1.cms.Attribute)29 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)26 X509Certificate (java.security.cert.X509Certificate)25 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)23 Test (org.junit.Test)22 DERSequence (org.bouncycastle.asn1.DERSequence)20 DERSet (org.bouncycastle.asn1.DERSet)20 List (java.util.List)19 Attribute (org.bouncycastle.asn1.pkcs.Attribute)18 Document (org.jdom2.Document)18 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)17 DataConversionException (org.jdom2.DataConversionException)16 Editor (jmri.jmrit.display.Editor)15 CertificateEncodingException (java.security.cert.CertificateEncodingException)14 ASN1Set (org.bouncycastle.asn1.ASN1Set)14