Search in sources :

Example 16 with DLSequence

use of org.bouncycastle.asn1.DLSequence in project Conversations by siacs.

the class XmppDomainVerifier 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 17 with DLSequence

use of org.bouncycastle.asn1.DLSequence 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 18 with DLSequence

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

the class ContentInfo method toASN1Primitive.

/**
     * Produce an object suitable for an ASN1OutputStream.
     * <pre>
     * ContentInfo ::= SEQUENCE {
     *          contentType ContentType,
     *          content
     *          [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL }
     * </pre>
     */
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(contentType);
    if (content != null) {
        v.add(new BERTaggedObject(true, 0, content));
    }
    if (isBer) {
        return new BERSequence(v);
    } else {
        return new DLSequence(v);
    }
}
Also used : DLSequence(org.bouncycastle.asn1.DLSequence) BERSequence(org.bouncycastle.asn1.BERSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) BERTaggedObject(org.bouncycastle.asn1.BERTaggedObject)

Example 19 with DLSequence

use of org.bouncycastle.asn1.DLSequence in project signer by demoiselle.

the class OIDGeneric method getInstance.

/**
 * Instance for OIDGeneric.
 *
 * @param data
 *            Set of bytes with the contents of the certificate.
 * @return Object GenericOID
 * @throws IOException exception of input/output
 * @throws Exception general exception
 */
public static OIDGeneric getInstance(byte[] data) throws IOException, Exception {
    is = new ASN1InputStream(data);
    DLSequence sequence = (DLSequence) is.readObject();
    ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) sequence.getObjectAt(0);
    DERTaggedObject taggedObject = (DERTaggedObject) sequence.getObjectAt(1);
    DERTaggedObject taggedObject2 = (DERTaggedObject) taggedObject.getObject();
    DEROctetString octet = null;
    DERPrintableString print = null;
    DERUTF8String utf8 = null;
    DERIA5String ia5 = null;
    try {
        octet = (DEROctetString) taggedObject2.getObject();
    } catch (Exception e) {
        try {
            print = (DERPrintableString) taggedObject2.getObject();
        } catch (Exception e1) {
            try {
                utf8 = (DERUTF8String) taggedObject2.getObject();
            } catch (Exception e2) {
                ia5 = (DERIA5String) taggedObject2.getObject();
            }
        }
    }
    String className = getPackageName() + oid.getId().replaceAll("[.]", "_");
    OIDGeneric oidGenerico;
    try {
        oidGenerico = (OIDGeneric) Class.forName(className).newInstance();
    } catch (InstantiationException e) {
        throw new Exception(coreMessagesBundle.getString("error.class.instance", className), e);
    } catch (IllegalAccessException e) {
        throw new Exception(coreMessagesBundle.getString("error.class.illegal.access", className), e);
    } catch (ClassNotFoundException e) {
        oidGenerico = new OIDGeneric();
    }
    oidGenerico.oid = oid.getId();
    if (octet != null) {
        oidGenerico.data = new String(octet.getOctets());
    } else {
        if (print != null) {
            oidGenerico.data = print.getString();
        } else {
            if (utf8 != null) {
                oidGenerico.data = utf8.getString();
            } else {
                oidGenerico.data = ia5.getString();
            }
        }
    }
    oidGenerico.initialize();
    return oidGenerico;
}
Also used : ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) DERIA5String(org.bouncycastle.asn1.DERIA5String) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) DEROctetString(org.bouncycastle.asn1.DEROctetString) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) DEROctetString(org.bouncycastle.asn1.DEROctetString) IOException(java.io.IOException) DERIA5String(org.bouncycastle.asn1.DERIA5String) DLSequence(org.bouncycastle.asn1.DLSequence) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 20 with DLSequence

use of org.bouncycastle.asn1.DLSequence in project signer by demoiselle.

the class PolicyIssuerName method parse.

@Override
public void parse(ASN1Primitive primitive) {
    if (primitive instanceof DLSequence) {
        DLSequence sequence = (DLSequence) primitive;
        ASN1Encodable asn1Encodable = sequence.getObjectAt(0);
        if (asn1Encodable instanceof DERTaggedObject) {
            DERTaggedObject derTaggedObject = (DERTaggedObject) asn1Encodable;
            ASN1Primitive object = derTaggedObject.getObject();
            if (object instanceof DEROctetString) {
                OctetString octetString = new OctetString();
                octetString.parse(object);
                this.issuerName = octetString.getValueUTF8();
            } else if (object instanceof DERSequence) {
                DERSequence sequence2 = (DERSequence) object;
                for (int i = 0; i < sequence2.size(); i++) {
                    ASN1Encodable obj = sequence2.getObjectAt(i);
                    if (obj instanceof DERSet) {
                        DERSet set = (DERSet) obj;
                        ASN1Encodable object2 = set.getObjectAt(0);
                        if (object2 instanceof DERSequence) {
                            DERSequence sequence3 = (DERSequence) object2;
                            ObjectIdentifier objectIdendifier = new ObjectIdentifier();
                            objectIdendifier.parse(sequence3.getObjectAt(0).toASN1Primitive());
                            String name = null;
                            ASN1Encodable object3 = sequence3.getObjectAt(1);
                            if (object3 instanceof DERPrintableString) {
                                name = ((DERPrintableString) object3).getString();
                            } else if (object3 instanceof DERUTF8String) {
                                name = ((DERUTF8String) object3).getString();
                            } else {
                                System.out.println(policyMessagesBundle.getString("error.not.recognized.object", object3.getClass(), object3.toString()));
                            }
                            if (this.issuerNames == null) {
                                this.issuerNames = new HashMap<ObjectIdentifier, String>();
                            }
                            this.issuerNames.put(objectIdendifier, name);
                        }
                    }
                }
            }
        }
    }
}
Also used : DEROctetString(org.bouncycastle.asn1.DEROctetString) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) HashMap(java.util.HashMap) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) DEROctetString(org.bouncycastle.asn1.DEROctetString) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) DERSet(org.bouncycastle.asn1.DERSet) DEROctetString(org.bouncycastle.asn1.DEROctetString) DERSequence(org.bouncycastle.asn1.DERSequence) DLSequence(org.bouncycastle.asn1.DLSequence) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive)

Aggregations

DLSequence (org.bouncycastle.asn1.DLSequence)37 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)21 DERTaggedObject (org.bouncycastle.asn1.DERTaggedObject)14 IOException (java.io.IOException)13 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)12 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)9 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)9 DEROctetString (org.bouncycastle.asn1.DEROctetString)9 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)8 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)6 DERIA5String (org.bouncycastle.asn1.DERIA5String)6 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)6 BigInteger (java.math.BigInteger)5 Pair (android.util.Pair)3 BufferedWriter (java.io.BufferedWriter)3 ASN1OutputStream (org.bouncycastle.asn1.ASN1OutputStream)3 JRubyMethod (org.jruby.anno.JRubyMethod)3 ByteArrayOutputStream (org.jruby.ext.openssl.util.ByteArrayOutputStream)3 CertificateEncodingException (java.security.cert.CertificateEncodingException)2 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)2