Search in sources :

Example 21 with X509Extension

use of org.gudy.bouncycastle.asn1.x509.X509Extension in project XobotOS by xamarin.

the class X509V2AttributeCertificate method getExtensionOIDs.

private Set getExtensionOIDs(boolean critical) {
    X509Extensions extensions = cert.getAcinfo().getExtensions();
    if (extensions != null) {
        Set set = new HashSet();
        Enumeration e = extensions.oids();
        while (e.hasMoreElements()) {
            DERObjectIdentifier oid = (DERObjectIdentifier) e.nextElement();
            X509Extension ext = extensions.getExtension(oid);
            if (ext.isCritical() == critical) {
                set.add(oid.getId());
            }
        }
        return set;
    }
    return null;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Enumeration(java.util.Enumeration) X509Extension(org.bouncycastle.asn1.x509.X509Extension) X509Extensions(org.bouncycastle.asn1.x509.X509Extensions) DERObjectIdentifier(org.bouncycastle.asn1.DERObjectIdentifier) HashSet(java.util.HashSet)

Example 22 with X509Extension

use of org.gudy.bouncycastle.asn1.x509.X509Extension in project BiglyBT by BiglySoftware.

the class X509CRLEntryObject method getExtensionOIDs.

private Set getExtensionOIDs(boolean critical) {
    X509Extensions extensions = c.getExtensions();
    if (extensions != null) {
        HashSet set = new HashSet();
        Enumeration e = extensions.oids();
        while (e.hasMoreElements()) {
            DERObjectIdentifier oid = (DERObjectIdentifier) e.nextElement();
            X509Extension ext = extensions.getExtension(oid);
            if (critical == ext.isCritical()) {
                set.add(oid.getId());
            }
        }
        return set;
    }
    return null;
}
Also used : Enumeration(java.util.Enumeration) X509Extension(org.gudy.bouncycastle.asn1.x509.X509Extension) X509Extensions(org.gudy.bouncycastle.asn1.x509.X509Extensions) DERObjectIdentifier(org.gudy.bouncycastle.asn1.DERObjectIdentifier) HashSet(java.util.HashSet)

Example 23 with X509Extension

use of org.gudy.bouncycastle.asn1.x509.X509Extension in project BiglyBT by BiglySoftware.

the class X509CertificateObject method hasUnsupportedCriticalExtension.

@Override
public boolean hasUnsupportedCriticalExtension() {
    if (this.getVersion() == 3) {
        X509Extensions extensions = c.getTBSCertificate().getExtensions();
        if (extensions != null) {
            Enumeration e = extensions.oids();
            while (e.hasMoreElements()) {
                DERObjectIdentifier oid = (DERObjectIdentifier) e.nextElement();
                if (oid.getId().equals("2.5.29.15") || oid.getId().equals("2.5.29.19")) {
                    continue;
                }
                X509Extension ext = extensions.getExtension(oid);
                if (ext.isCritical()) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : X509Extension(org.gudy.bouncycastle.asn1.x509.X509Extension)

Example 24 with X509Extension

use of org.gudy.bouncycastle.asn1.x509.X509Extension in project BiglyBT by BiglySoftware.

the class X509CertificateObject method toString.

public String toString() {
    StringBuilder buf = new StringBuilder();
    String nl = System.getProperty("line.separator");
    buf.append("  [0]         Version: ").append(this.getVersion()).append(nl);
    buf.append("         SerialNumber: ").append(this.getSerialNumber()).append(nl);
    buf.append("             IssuerDN: ").append(this.getIssuerDN()).append(nl);
    buf.append("           Start Date: ").append(this.getNotBefore()).append(nl);
    buf.append("           Final Date: ").append(this.getNotAfter()).append(nl);
    buf.append("            SubjectDN: ").append(this.getSubjectDN()).append(nl);
    buf.append("           Public Key: ").append(this.getPublicKey()).append(nl);
    buf.append("  Signature Algorithm: ").append(this.getSigAlgName()).append(nl);
    byte[] sig = this.getSignature();
    buf.append("            Signature: ").append(new String(Hex.encode(sig, 0, 20))).append(nl);
    for (int i = 20; i < sig.length; i += 20) {
        if (i < sig.length - 20) {
            buf.append("                       ").append(new String(Hex.encode(sig, i, 20))).append(nl);
        } else {
            buf.append("                       ").append(new String(Hex.encode(sig, i, sig.length - i))).append(nl);
        }
    }
    X509Extensions extensions = c.getTBSCertificate().getExtensions();
    if (extensions != null) {
        Enumeration e = extensions.oids();
        if (e.hasMoreElements()) {
            buf.append("       Extensions: \n");
        }
        while (e.hasMoreElements()) {
            DERObjectIdentifier oid = (DERObjectIdentifier) e.nextElement();
            X509Extension ext = extensions.getExtension(oid);
            if (ext.getValue() != null) {
                byte[] octs = ext.getValue().getOctets();
                ByteArrayInputStream bIn = new ByteArrayInputStream(octs);
                DERInputStream dIn = new DERInputStream(bIn);
                buf.append("                       critical(").append(ext.isCritical()).append(") ");
                try {
                    if (oid.equals(X509Extensions.BasicConstraints)) {
                        buf.append(new BasicConstraints((ASN1Sequence) dIn.readObject())).append(nl);
                    } else if (oid.equals(X509Extensions.KeyUsage)) {
                        buf.append(new KeyUsage((DERBitString) dIn.readObject())).append(nl);
                    } else if (oid.equals(MiscObjectIdentifiers.netscapeCertType)) {
                        buf.append(new NetscapeCertType((DERBitString) dIn.readObject())).append(nl);
                    } else if (oid.equals(MiscObjectIdentifiers.netscapeRevocationURL)) {
                        buf.append(new NetscapeRevocationURL((DERIA5String) dIn.readObject())).append(nl);
                    } else if (oid.equals(MiscObjectIdentifiers.verisignCzagExtension)) {
                        buf.append(new VerisignCzagExtension((DERIA5String) dIn.readObject())).append(nl);
                    } else {
                        buf.append(oid.getId());
                        buf.append(" value = ").append(ASN1Dump.dumpAsString(dIn.readObject())).append(nl);
                    // buf.append(" value = " + "*****" + nl);
                    }
                } catch (Exception ex) {
                    buf.append(oid.getId());
                    // buf.append(" value = " + new String(Hex.encode(ext.getValue().getOctets())) + nl);
                    buf.append(" value = " + "*****").append(nl);
                }
            } else {
                buf.append(nl);
            }
        }
    }
    return buf.toString();
}
Also used : VerisignCzagExtension(org.gudy.bouncycastle.asn1.misc.VerisignCzagExtension) X509Extension(org.gudy.bouncycastle.asn1.x509.X509Extension) NetscapeRevocationURL(org.gudy.bouncycastle.asn1.misc.NetscapeRevocationURL) IOException(java.io.IOException) ByteArrayInputStream(java.io.ByteArrayInputStream) NetscapeCertType(org.gudy.bouncycastle.asn1.misc.NetscapeCertType)

Example 25 with X509Extension

use of org.gudy.bouncycastle.asn1.x509.X509Extension in project BiglyBT by BiglySoftware.

the class X509CertificateObject method getExtensionValue.

@Override
public byte[] getExtensionValue(String oid) {
    X509Extensions exts = c.getTBSCertificate().getExtensions();
    if (exts != null) {
        X509Extension ext = exts.getExtension(new DERObjectIdentifier(oid));
        if (ext != null) {
            ByteArrayOutputStream bOut = new ByteArrayOutputStream();
            DEROutputStream dOut = new DEROutputStream(bOut);
            try {
                dOut.writeObject(ext.getValue());
                return bOut.toByteArray();
            } catch (Exception e) {
                throw new RuntimeException("error encoding " + e.toString());
            }
        }
    }
    return null;
}
Also used : X509Extension(org.gudy.bouncycastle.asn1.x509.X509Extension) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

Enumeration (java.util.Enumeration)14 IOException (java.io.IOException)11 X509Extension (org.gudy.bouncycastle.asn1.x509.X509Extension)11 DERObjectIdentifier (org.bouncycastle.asn1.DERObjectIdentifier)10 X509Extension (org.bouncycastle.asn1.x509.X509Extension)10 X509Extensions (org.bouncycastle.asn1.x509.X509Extensions)10 HashSet (java.util.HashSet)8 Set (java.util.Set)6 X509Extensions (org.gudy.bouncycastle.asn1.x509.X509Extensions)6 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)5 CertificateExpiredException (java.security.cert.CertificateExpiredException)4 CertificateNotYetValidException (java.security.cert.CertificateNotYetValidException)4 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)4 DERSequence (org.bouncycastle.asn1.DERSequence)4 DERObjectIdentifier (org.gudy.bouncycastle.asn1.DERObjectIdentifier)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 GeneralSecurityException (java.security.GeneralSecurityException)3 CRLException (java.security.cert.CRLException)3 ArrayList (java.util.ArrayList)3 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)3