Search in sources :

Example 61 with DERObjectIdentifier

use of org.gudy.bouncycastle.asn1.DERObjectIdentifier 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 62 with DERObjectIdentifier

use of org.gudy.bouncycastle.asn1.DERObjectIdentifier 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 63 with DERObjectIdentifier

use of org.gudy.bouncycastle.asn1.DERObjectIdentifier 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)

Example 64 with DERObjectIdentifier

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

the class X509CertificateObject method getCriticalExtensionOIDs.

@Override
public Set getCriticalExtensionOIDs() {
    if (this.getVersion() == 3) {
        HashSet set = new HashSet();
        X509Extensions extensions = c.getTBSCertificate().getExtensions();
        if (extensions != null) {
            Enumeration e = extensions.oids();
            while (e.hasMoreElements()) {
                DERObjectIdentifier oid = (DERObjectIdentifier) e.nextElement();
                X509Extension ext = extensions.getExtension(oid);
                if (ext.isCritical()) {
                    set.add(oid.getId());
                }
            }
            return set;
        }
    }
    return null;
}
Also used : X509Extension(org.gudy.bouncycastle.asn1.x509.X509Extension)

Example 65 with DERObjectIdentifier

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

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 : X509Extension(org.gudy.bouncycastle.asn1.x509.X509Extension) X509Extensions(org.gudy.bouncycastle.asn1.x509.X509Extensions)

Aggregations

DERObjectIdentifier (org.bouncycastle.asn1.DERObjectIdentifier)48 IOException (java.io.IOException)28 Enumeration (java.util.Enumeration)23 HashSet (java.util.HashSet)19 ArrayList (java.util.ArrayList)17 Set (java.util.Set)17 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)17 List (java.util.List)16 X509Certificate (java.security.cert.X509Certificate)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)11 DEREncodable (org.bouncycastle.asn1.DEREncodable)11 DERObject (org.bouncycastle.asn1.DERObject)11 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)11 X509Extension (org.gudy.bouncycastle.asn1.x509.X509Extension)11 DEROctetString (org.bouncycastle.asn1.DEROctetString)9 Iterator (java.util.Iterator)8 X962Parameters (org.bouncycastle.asn1.x9.X962Parameters)8 X9ECParameters (org.bouncycastle.asn1.x9.X9ECParameters)8 HashMap (java.util.HashMap)7