Search in sources :

Example 21 with DERTaggedObject

use of com.github.zhenwei.core.asn1.DERTaggedObject in project xabber-android by redsolution.

the class CustomDomainVerifier method parseOtherName.

private static Pair<String, String> parseOtherName(byte[] otherName) {
    try {
        ASN1Primitive asn1Primitive = ASN1Primitive.fromByteArray(otherName);
        if (asn1Primitive instanceof DERTaggedObject) {
            ASN1Primitive inner = ((DERTaggedObject) asn1Primitive).getObject();
            if (inner instanceof DLSequence) {
                DLSequence sequence = (DLSequence) inner;
                if (sequence.size() >= 2 && sequence.getObjectAt(1) instanceof DERTaggedObject) {
                    String oid = sequence.getObjectAt(0).toString();
                    ASN1Primitive value = ((DERTaggedObject) sequence.getObjectAt(1)).getObject();
                    if (value instanceof DERUTF8String) {
                        return new Pair<>(oid, ((DERUTF8String) value).getString());
                    } else if (value instanceof DERIA5String) {
                        return new Pair<>(oid, ((DERIA5String) value).getString());
                    }
                }
            }
        }
        return null;
    } catch (IOException e) {
        return null;
    }
}
Also used : DERUTF8String(org.bouncycastle.asn1.DERUTF8String) DERIA5String(org.bouncycastle.asn1.DERIA5String) DLSequence(org.bouncycastle.asn1.DLSequence) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) DERIA5String(org.bouncycastle.asn1.DERIA5String) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) IOException(java.io.IOException) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive) Pair(android.util.Pair)

Example 22 with DERTaggedObject

use of com.github.zhenwei.core.asn1.DERTaggedObject in project xipki by xipki.

the class XmlX509CertprofileUtil method buildPolicyConstrains.

// method buildGeneralSubtree
public static ASN1Sequence buildPolicyConstrains(PolicyConstraints type) throws CertprofileException {
    ParamUtil.requireNonNull("type", type);
    Integer requireExplicitPolicy = type.getRequireExplicitPolicy();
    if (requireExplicitPolicy != null && requireExplicitPolicy < 0) {
        throw new CertprofileException("negative requireExplicitPolicy is not allowed: " + requireExplicitPolicy);
    }
    Integer inhibitPolicyMapping = type.getInhibitPolicyMapping();
    if (inhibitPolicyMapping != null && inhibitPolicyMapping < 0) {
        throw new CertprofileException("negative inhibitPolicyMapping is not allowed: " + inhibitPolicyMapping);
    }
    if (requireExplicitPolicy == null && inhibitPolicyMapping == null) {
        return null;
    }
    final boolean explicit = false;
    ASN1EncodableVector vec = new ASN1EncodableVector();
    if (requireExplicitPolicy != null) {
        vec.add(new DERTaggedObject(explicit, 0, new ASN1Integer(BigInteger.valueOf(requireExplicitPolicy))));
    }
    if (inhibitPolicyMapping != null) {
        vec.add(new DERTaggedObject(explicit, 1, new ASN1Integer(BigInteger.valueOf(inhibitPolicyMapping))));
    }
    return new DERSequence(vec);
}
Also used : ASN1Integer(org.bouncycastle.asn1.ASN1Integer) BigInteger(java.math.BigInteger) DERSequence(org.bouncycastle.asn1.DERSequence) CertprofileException(org.xipki.ca.api.profile.CertprofileException) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) ASN1Integer(org.bouncycastle.asn1.ASN1Integer)

Example 23 with DERTaggedObject

use of com.github.zhenwei.core.asn1.DERTaggedObject in project xipki by xipki.

the class Asn1NewKeyControl method toASN1Primitive.

@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector vector = new ASN1EncodableVector();
    vector.add(new DERTaggedObject(0, ASN1Boolean.getInstance(control.isExtractable())));
    return new DERSequence(vector);
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector)

Example 24 with DERTaggedObject

use of com.github.zhenwei.core.asn1.DERTaggedObject 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 25 with DERTaggedObject

use of com.github.zhenwei.core.asn1.DERTaggedObject 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)

Aggregations

DERTaggedObject (org.bouncycastle.asn1.DERTaggedObject)98 DERTaggedObject (com.github.zhenwei.core.asn1.DERTaggedObject)73 ASN1EncodableVector (com.github.zhenwei.core.asn1.ASN1EncodableVector)66 DERSequence (com.github.zhenwei.core.asn1.DERSequence)60 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)57 DERSequence (org.bouncycastle.asn1.DERSequence)56 IOException (java.io.IOException)31 DEROctetString (org.bouncycastle.asn1.DEROctetString)26 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)22 DLSequence (org.bouncycastle.asn1.DLSequence)21 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)20 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)19 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)17 Iterator (java.util.Iterator)14 ASN1Integer (com.github.zhenwei.core.asn1.ASN1Integer)13 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)11 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)11 DERIA5String (org.bouncycastle.asn1.DERIA5String)11 DERSet (org.bouncycastle.asn1.DERSet)11 DEROctetString (com.github.zhenwei.core.asn1.DEROctetString)10