Search in sources :

Example 96 with ASN1EncodableVector

use of org.openecard.bouncycastle.asn1.ASN1EncodableVector in project xipki by xipki.

the class ExtensionsChecker method createGeneralName.

private static GeneralName createGeneralName(GeneralName reqName, Set<GeneralNameMode> modes) throws BadCertTemplateException {
    int tag = reqName.getTagNo();
    GeneralNameMode mode = null;
    if (modes != null) {
        for (GeneralNameMode m : modes) {
            if (m.getTag().getTag() == tag) {
                mode = m;
                break;
            }
        }
        if (mode == null) {
            throw new BadCertTemplateException("generalName tag " + tag + " is not allowed");
        }
    }
    switch(tag) {
        case GeneralName.rfc822Name:
        case GeneralName.dNSName:
        case GeneralName.uniformResourceIdentifier:
        case GeneralName.iPAddress:
        case GeneralName.registeredID:
        case GeneralName.directoryName:
            return new GeneralName(tag, reqName.getName());
        case GeneralName.otherName:
            ASN1Sequence reqSeq = ASN1Sequence.getInstance(reqName.getName());
            ASN1ObjectIdentifier type = ASN1ObjectIdentifier.getInstance(reqSeq.getObjectAt(0));
            if (mode != null && !mode.getAllowedTypes().contains(type)) {
                throw new BadCertTemplateException("otherName.type " + type.getId() + " is not allowed");
            }
            ASN1Encodable value = ASN1TaggedObject.getInstance(reqSeq.getObjectAt(1)).getObject();
            String text;
            if (!(value instanceof ASN1String)) {
                throw new BadCertTemplateException("otherName.value is not a String");
            } else {
                text = ((ASN1String) value).getString();
            }
            ASN1EncodableVector vector = new ASN1EncodableVector();
            vector.add(type);
            vector.add(new DERTaggedObject(true, 0, new DERUTF8String(text)));
            DERSequence seq = new DERSequence(vector);
            return new GeneralName(GeneralName.otherName, seq);
        case GeneralName.ediPartyName:
            reqSeq = ASN1Sequence.getInstance(reqName.getName());
            int size = reqSeq.size();
            String nameAssigner = null;
            int idx = 0;
            if (size > 1) {
                DirectoryString ds = DirectoryString.getInstance(ASN1TaggedObject.getInstance(reqSeq.getObjectAt(idx++)).getObject());
                nameAssigner = ds.getString();
            }
            DirectoryString ds = DirectoryString.getInstance(ASN1TaggedObject.getInstance(reqSeq.getObjectAt(idx++)).getObject());
            String partyName = ds.getString();
            vector = new ASN1EncodableVector();
            if (nameAssigner != null) {
                vector.add(new DERTaggedObject(false, 0, new DirectoryString(nameAssigner)));
            }
            vector.add(new DERTaggedObject(false, 1, new DirectoryString(partyName)));
            seq = new DERSequence(vector);
            return new GeneralName(GeneralName.ediPartyName, seq);
        default:
            throw new RuntimeException("should not reach here, unknown GeneralName tag " + tag);
    }
// end switch
}
Also used : GeneralNameMode(org.xipki.ca.api.profile.GeneralNameMode) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) DERBMPString(org.bouncycastle.asn1.DERBMPString) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) ASN1String(org.bouncycastle.asn1.ASN1String) DirectoryString(org.bouncycastle.asn1.x500.DirectoryString) QaDirectoryString(org.xipki.ca.qa.internal.QaDirectoryString) DEROctetString(org.bouncycastle.asn1.DEROctetString) DERIA5String(org.bouncycastle.asn1.DERIA5String) DERT61String(org.bouncycastle.asn1.DERT61String) CRLDistPoint(org.bouncycastle.asn1.x509.CRLDistPoint) DistributionPoint(org.bouncycastle.asn1.x509.DistributionPoint) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) DERSequence(org.bouncycastle.asn1.DERSequence) BadCertTemplateException(org.xipki.ca.api.BadCertTemplateException) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) GeneralName(org.bouncycastle.asn1.x509.GeneralName) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1String(org.bouncycastle.asn1.ASN1String) DirectoryString(org.bouncycastle.asn1.x500.DirectoryString) QaDirectoryString(org.xipki.ca.qa.internal.QaDirectoryString) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 97 with ASN1EncodableVector

use of org.openecard.bouncycastle.asn1.ASN1EncodableVector in project xipki by xipki.

the class IssuerAndSubject method toASN1Primitive.

@Override
public // CHECKSTYLE:SKIP
ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector vec = new ASN1EncodableVector();
    vec.add(issuer);
    vec.add(subject);
    return new DERSequence(vec);
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector)

Example 98 with ASN1EncodableVector

use of org.openecard.bouncycastle.asn1.ASN1EncodableVector in project xipki by xipki.

the class ExtensionExistence method toASN1Primitive.

// constructor
@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector vector = new ASN1EncodableVector();
    if (CollectionUtil.isNonEmpty(needExtensions)) {
        ASN1EncodableVector vec = new ASN1EncodableVector();
        for (ASN1ObjectIdentifier m : needExtensions) {
            vec.add(m);
        }
        vector.add(new DERTaggedObject(true, 0, new DERSequence(vec)));
    }
    if (CollectionUtil.isNonEmpty(wantExtensions)) {
        ASN1EncodableVector vec = new ASN1EncodableVector();
        for (ASN1ObjectIdentifier m : wantExtensions) {
            vec.add(m);
        }
        vector.add(new DERTaggedObject(true, 1, new DERSequence(vec)));
    }
    return new DERSequence(vector);
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 99 with ASN1EncodableVector

use of org.openecard.bouncycastle.asn1.ASN1EncodableVector in project xipki by xipki.

the class P12ComplexCsrGenCmd method getSubject.

@Override
protected X500Name getSubject(String subject) {
    X500Name name = new X500Name(subject);
    List<RDN> list = new LinkedList<>();
    RDN[] rs = name.getRDNs();
    for (RDN m : rs) {
        list.add(m);
    }
    ASN1ObjectIdentifier id;
    // dateOfBirth
    if (complexSubject.booleanValue()) {
        id = ObjectIdentifiers.DN_DATE_OF_BIRTH;
        RDN[] rdns = name.getRDNs(id);
        if (rdns == null || rdns.length == 0) {
            ASN1Encodable atvValue = new DERGeneralizedTime("19950102120000Z");
            RDN rdn = new RDN(id, atvValue);
            list.add(rdn);
        }
    }
    // postalAddress
    if (complexSubject.booleanValue()) {
        id = ObjectIdentifiers.DN_POSTAL_ADDRESS;
        RDN[] rdns = name.getRDNs(id);
        if (rdns == null || rdns.length == 0) {
            ASN1EncodableVector vec = new ASN1EncodableVector();
            vec.add(new DERUTF8String("my street 1"));
            vec.add(new DERUTF8String("12345 Germany"));
            ASN1Sequence atvValue = new DERSequence(vec);
            RDN rdn = new RDN(id, atvValue);
            list.add(rdn);
        }
    }
    // DN_UNIQUE_IDENTIFIER
    id = ObjectIdentifiers.DN_UNIQUE_IDENTIFIER;
    RDN[] rdns = name.getRDNs(id);
    if (rdns == null || rdns.length == 0) {
        DERUTF8String atvValue = new DERUTF8String("abc-def-ghi");
        RDN rdn = new RDN(id, atvValue);
        list.add(rdn);
    }
    return new X500Name(list.toArray(new RDN[0]));
}
Also used : DERUTF8String(org.bouncycastle.asn1.DERUTF8String) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) DERSequence(org.bouncycastle.asn1.DERSequence) DERGeneralizedTime(org.bouncycastle.asn1.DERGeneralizedTime) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) X500Name(org.bouncycastle.asn1.x500.X500Name) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) RDN(org.bouncycastle.asn1.x500.RDN) LinkedList(java.util.LinkedList) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 100 with ASN1EncodableVector

use of org.openecard.bouncycastle.asn1.ASN1EncodableVector in project keepass2android by PhilippC.

the class RC2CBCParameter method toASN1Object.

public DERObject toASN1Object() {
    ASN1EncodableVector v = new ASN1EncodableVector();
    if (version != null) {
        v.add(version);
    }
    v.add(iv);
    return new DERSequence(v);
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector)

Aggregations

ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)246 DERSequence (org.bouncycastle.asn1.DERSequence)196 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)54 IOException (java.io.IOException)45 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)43 DERTaggedObject (org.bouncycastle.asn1.DERTaggedObject)42 DEROctetString (org.bouncycastle.asn1.DEROctetString)32 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)24 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)21 DLSequence (org.bouncycastle.asn1.DLSequence)21 BigInteger (java.math.BigInteger)20 X509Certificate (java.security.cert.X509Certificate)20 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)18 DERSet (org.bouncycastle.asn1.DERSet)18 ArrayList (java.util.ArrayList)17 DERBitString (org.bouncycastle.asn1.DERBitString)17 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)16 BERSequence (org.bouncycastle.asn1.BERSequence)14 DERIA5String (org.bouncycastle.asn1.DERIA5String)14 DERInteger (org.bouncycastle.asn1.DERInteger)14