Search in sources :

Example 86 with ASN1Encodable

use of com.android.org.bouncycastle.asn1.ASN1Encodable in project robovm by robovm.

the class X509Name method equals.

/**
     * @param inOrder if true the order of both X509 names must be the same,
     * as well as the values associated with each element.
     */
public boolean equals(Object obj, boolean inOrder) {
    if (!inOrder) {
        return this.equals(obj);
    }
    if (obj == this) {
        return true;
    }
    if (!(obj instanceof X509Name || obj instanceof ASN1Sequence)) {
        return false;
    }
    ASN1Primitive derO = ((ASN1Encodable) obj).toASN1Primitive();
    if (this.toASN1Primitive().equals(derO)) {
        return true;
    }
    X509Name other;
    try {
        other = X509Name.getInstance(obj);
    } catch (IllegalArgumentException e) {
        return false;
    }
    int orderingSize = ordering.size();
    if (orderingSize != other.ordering.size()) {
        return false;
    }
    for (int i = 0; i < orderingSize; i++) {
        ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) ordering.elementAt(i);
        ASN1ObjectIdentifier oOid = (ASN1ObjectIdentifier) other.ordering.elementAt(i);
        if (oid.equals(oOid)) {
            String value = (String) values.elementAt(i);
            String oValue = (String) other.values.elementAt(i);
            if (!equivalentStrings(value, oValue)) {
                return false;
            }
        } else {
            return false;
        }
    }
    return true;
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1String(org.bouncycastle.asn1.ASN1String) DERUniversalString(org.bouncycastle.asn1.DERUniversalString) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 87 with ASN1Encodable

use of com.android.org.bouncycastle.asn1.ASN1Encodable in project robovm by robovm.

the class X509V3CertificateGenerator method copyAndAddExtension.

/**
     * add a given extension field for the standard extensions tag (tag 3)
     * copying the extension value from another certificate.
     * @throws CertificateParsingException if the extension cannot be extracted.
     */
public void copyAndAddExtension(String oid, boolean critical, X509Certificate cert) throws CertificateParsingException {
    byte[] extValue = cert.getExtensionValue(oid);
    if (extValue == null) {
        throw new CertificateParsingException("extension " + oid + " not present");
    }
    try {
        ASN1Encodable value = X509ExtensionUtil.fromExtensionValue(extValue);
        this.addExtension(oid, critical, value);
    } catch (IOException e) {
        throw new CertificateParsingException(e.toString());
    }
}
Also used : CertificateParsingException(java.security.cert.CertificateParsingException) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) IOException(java.io.IOException)

Example 88 with ASN1Encodable

use of com.android.org.bouncycastle.asn1.ASN1Encodable in project XobotOS by xamarin.

the class AttributeCertificateIssuer method getNames.

private Object[] getNames() {
    GeneralNames name;
    if (form instanceof V2Form) {
        name = ((V2Form) form).getIssuerName();
    } else {
        name = (GeneralNames) form;
    }
    GeneralName[] names = name.getNames();
    List l = new ArrayList(names.length);
    for (int i = 0; i != names.length; i++) {
        if (names[i].getTagNo() == GeneralName.directoryName) {
            try {
                l.add(new X500Principal(((ASN1Encodable) names[i].getName()).getEncoded()));
            } catch (IOException e) {
                throw new RuntimeException("badly formed Name object");
            }
        }
    }
    return l.toArray(new Object[l.size()]);
}
Also used : V2Form(org.bouncycastle.asn1.x509.V2Form) GeneralNames(org.bouncycastle.asn1.x509.GeneralNames) ArrayList(java.util.ArrayList) X500Principal(javax.security.auth.x500.X500Principal) ArrayList(java.util.ArrayList) List(java.util.List) GeneralName(org.bouncycastle.asn1.x509.GeneralName) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) IOException(java.io.IOException)

Example 89 with ASN1Encodable

use of com.android.org.bouncycastle.asn1.ASN1Encodable in project XobotOS by xamarin.

the class X509V2AttributeCertificate method getAttributes.

public X509Attribute[] getAttributes() {
    ASN1Sequence seq = cert.getAcinfo().getAttributes();
    X509Attribute[] attrs = new X509Attribute[seq.size()];
    for (int i = 0; i != seq.size(); i++) {
        attrs[i] = new X509Attribute((ASN1Encodable) seq.getObjectAt(i));
    }
    return attrs;
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable)

Example 90 with ASN1Encodable

use of com.android.org.bouncycastle.asn1.ASN1Encodable in project XobotOS by xamarin.

the class X509V3CertificateGenerator method copyAndAddExtension.

/**
     * add a given extension field for the standard extensions tag (tag 3)
     * copying the extension value from another certificate.
     * @throws CertificateParsingException if the extension cannot be extracted.
     */
public void copyAndAddExtension(String oid, boolean critical, X509Certificate cert) throws CertificateParsingException {
    byte[] extValue = cert.getExtensionValue(oid);
    if (extValue == null) {
        throw new CertificateParsingException("extension " + oid + " not present");
    }
    try {
        ASN1Encodable value = X509ExtensionUtil.fromExtensionValue(extValue);
        this.addExtension(oid, critical, value);
    } catch (IOException e) {
        throw new CertificateParsingException(e.toString());
    }
}
Also used : CertificateParsingException(java.security.cert.CertificateParsingException) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) IOException(java.io.IOException)

Aggregations

ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)139 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)73 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)59 IOException (java.io.IOException)37 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)34 DEROctetString (org.bouncycastle.asn1.DEROctetString)32 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)29 DERIA5String (org.bouncycastle.asn1.DERIA5String)28 DERSequence (org.bouncycastle.asn1.DERSequence)25 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)21 DERPrintableString (org.bouncycastle.asn1.DERPrintableString)21 ArrayList (java.util.ArrayList)20 GeneralName (org.bouncycastle.asn1.x509.GeneralName)19 X509Certificate (java.security.cert.X509Certificate)17 HashSet (java.util.HashSet)17 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)17 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)17 BigInteger (java.math.BigInteger)16 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)16 DERBMPString (org.bouncycastle.asn1.DERBMPString)15