Search in sources :

Example 21 with Extension

use of org.bouncycastle.asn1.x509.Extension in project robovm by robovm.

the class X509CertificateObject method hasUnsupportedCriticalExtension.

public boolean hasUnsupportedCriticalExtension() {
    if (this.getVersion() == 3) {
        Extensions extensions = c.getTBSCertificate().getExtensions();
        if (extensions != null) {
            Enumeration e = extensions.oids();
            while (e.hasMoreElements()) {
                ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) e.nextElement();
                String oidId = oid.getId();
                if (oidId.equals(RFC3280CertPathUtilities.KEY_USAGE) || oidId.equals(RFC3280CertPathUtilities.CERTIFICATE_POLICIES) || oidId.equals(RFC3280CertPathUtilities.POLICY_MAPPINGS) || oidId.equals(RFC3280CertPathUtilities.INHIBIT_ANY_POLICY) || oidId.equals(RFC3280CertPathUtilities.CRL_DISTRIBUTION_POINTS) || oidId.equals(RFC3280CertPathUtilities.ISSUING_DISTRIBUTION_POINT) || oidId.equals(RFC3280CertPathUtilities.DELTA_CRL_INDICATOR) || oidId.equals(RFC3280CertPathUtilities.POLICY_CONSTRAINTS) || oidId.equals(RFC3280CertPathUtilities.BASIC_CONSTRAINTS) || oidId.equals(RFC3280CertPathUtilities.SUBJECT_ALTERNATIVE_NAME) || oidId.equals(RFC3280CertPathUtilities.NAME_CONSTRAINTS)) {
                    continue;
                }
                Extension ext = extensions.getExtension(oid);
                if (ext.isCritical()) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Extension(org.bouncycastle.asn1.x509.Extension) VerisignCzagExtension(org.bouncycastle.asn1.misc.VerisignCzagExtension) Enumeration(java.util.Enumeration) DERBitString(org.bouncycastle.asn1.DERBitString) DEROctetString(org.bouncycastle.asn1.DEROctetString) DERIA5String(org.bouncycastle.asn1.DERIA5String) ASN1String(org.bouncycastle.asn1.ASN1String) Extensions(org.bouncycastle.asn1.x509.Extensions) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 22 with Extension

use of org.bouncycastle.asn1.x509.Extension in project robovm by robovm.

the class X509CRLEntryObject method toString.

public String toString() {
    StringBuffer buf = new StringBuffer();
    String nl = System.getProperty("line.separator");
    buf.append("      userCertificate: ").append(this.getSerialNumber()).append(nl);
    buf.append("       revocationDate: ").append(this.getRevocationDate()).append(nl);
    buf.append("       certificateIssuer: ").append(this.getCertificateIssuer()).append(nl);
    Extensions extensions = c.getExtensions();
    if (extensions != null) {
        Enumeration e = extensions.oids();
        if (e.hasMoreElements()) {
            buf.append("   crlEntryExtensions:").append(nl);
            while (e.hasMoreElements()) {
                ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) e.nextElement();
                Extension ext = extensions.getExtension(oid);
                if (ext.getExtnValue() != null) {
                    byte[] octs = ext.getExtnValue().getOctets();
                    ASN1InputStream dIn = new ASN1InputStream(octs);
                    buf.append("                       critical(").append(ext.isCritical()).append(") ");
                    try {
                        if (oid.equals(X509Extension.reasonCode)) {
                            buf.append(CRLReason.getInstance(ASN1Enumerated.getInstance(dIn.readObject()))).append(nl);
                        } else if (oid.equals(X509Extension.certificateIssuer)) {
                            buf.append("Certificate issuer: ").append(GeneralNames.getInstance(dIn.readObject())).append(nl);
                        } else {
                            buf.append(oid.getId());
                            buf.append(" value = ").append(ASN1Dump.dumpAsString(dIn.readObject())).append(nl);
                        }
                    } catch (Exception ex) {
                        buf.append(oid.getId());
                        buf.append(" value = ").append("*****").append(nl);
                    }
                } else {
                    buf.append(nl);
                }
            }
        }
    }
    return buf.toString();
}
Also used : Extension(org.bouncycastle.asn1.x509.Extension) X509Extension(org.bouncycastle.asn1.x509.X509Extension) ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) Enumeration(java.util.Enumeration) Extensions(org.bouncycastle.asn1.x509.Extensions) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) IOException(java.io.IOException) CRLException(java.security.cert.CRLException)

Example 23 with Extension

use of org.bouncycastle.asn1.x509.Extension in project robovm by robovm.

the class X509CRLObject method loadCRLEntries.

private Set loadCRLEntries() {
    Set entrySet = new HashSet();
    Enumeration certs = c.getRevokedCertificateEnumeration();
    // the issuer
    X500Name previousCertificateIssuer = null;
    while (certs.hasMoreElements()) {
        TBSCertList.CRLEntry entry = (TBSCertList.CRLEntry) certs.nextElement();
        X509CRLEntryObject crlEntry = new X509CRLEntryObject(entry, isIndirect, previousCertificateIssuer);
        entrySet.add(crlEntry);
        if (isIndirect && entry.hasExtensions()) {
            Extension currentCaName = entry.getExtensions().getExtension(Extension.certificateIssuer);
            if (currentCaName != null) {
                previousCertificateIssuer = X500Name.getInstance(GeneralNames.getInstance(currentCaName.getParsedValue()).getNames()[0].getName());
            }
        }
    }
    return entrySet;
}
Also used : Extension(org.bouncycastle.asn1.x509.Extension) HashSet(java.util.HashSet) Set(java.util.Set) Enumeration(java.util.Enumeration) TBSCertList(org.bouncycastle.asn1.x509.TBSCertList) X500Name(org.bouncycastle.asn1.x500.X500Name) X509CRLEntry(java.security.cert.X509CRLEntry) HashSet(java.util.HashSet)

Example 24 with Extension

use of org.bouncycastle.asn1.x509.Extension in project cas by apereo.

the class CRLDistributionPointRevocationChecker method getDistributionPoints.

/**
     * Gets the distribution points.
     *
     * @param cert the cert
     * @return the url distribution points
     */
private URI[] getDistributionPoints(final X509Certificate cert) {
    final List<DistributionPoint> points;
    try {
        points = new ExtensionReader(cert).readCRLDistributionPoints();
    } catch (final RuntimeException e) {
        LOGGER.error("Error reading CRLDistributionPoints extension field on [{}]", CertUtils.toString(cert), e);
        return new URI[0];
    }
    final List<URI> urls = new ArrayList<>();
    if (points != null) {
        points.stream().map(DistributionPoint::getDistributionPoint).filter(Objects::nonNull).forEach(pointName -> {
            final ASN1Sequence nameSequence = ASN1Sequence.getInstance(pointName.getName());
            IntStream.range(0, nameSequence.size()).mapToObj(i -> GeneralName.getInstance(nameSequence.getObjectAt(i))).forEach(name -> {
                LOGGER.debug("Found CRL distribution point [{}].", name);
                try {
                    addURL(urls, DERIA5String.getInstance(name.getName()).getString());
                } catch (final RuntimeException e) {
                    LOGGER.warn("[{}] not supported. String or GeneralNameList expected.", pointName);
                }
            });
        });
    }
    return urls.toArray(new URI[urls.size()]);
}
Also used : X509Certificate(java.security.cert.X509Certificate) IntStream(java.util.stream.IntStream) RevocationPolicy(org.apereo.cas.adaptors.x509.authentication.revocation.policy.RevocationPolicy) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) Arrays(java.util.Arrays) URLDecoder(java.net.URLDecoder) URL(java.net.URL) DistributionPoint(org.bouncycastle.asn1.x509.DistributionPoint) LoggerFactory(org.slf4j.LoggerFactory) X509CRL(java.security.cert.X509CRL) ByteArrayResource(org.springframework.core.io.ByteArrayResource) ArrayList(java.util.ArrayList) CertUtils(org.apereo.cas.adaptors.x509.util.CertUtils) URI(java.net.URI) DERIA5String(org.bouncycastle.asn1.DERIA5String) Logger(org.slf4j.Logger) CRLFetcher(org.apereo.cas.adaptors.x509.authentication.CRLFetcher) MalformedURLException(java.net.MalformedURLException) Throwables(com.google.common.base.Throwables) Element(net.sf.ehcache.Element) StandardCharsets(java.nio.charset.StandardCharsets) ExtensionReader(org.cryptacular.x509.ExtensionReader) Objects(java.util.Objects) GeneralName(org.bouncycastle.asn1.x509.GeneralName) List(java.util.List) ResourceCRLFetcher(org.apereo.cas.adaptors.x509.authentication.ResourceCRLFetcher) Cache(net.sf.ehcache.Cache) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) ArrayList(java.util.ArrayList) DistributionPoint(org.bouncycastle.asn1.x509.DistributionPoint) URI(java.net.URI) ExtensionReader(org.cryptacular.x509.ExtensionReader)

Example 25 with Extension

use of org.bouncycastle.asn1.x509.Extension in project j2objc by google.

the class IosX509Certificate method getExtensionValue.

@Override
public byte[] getExtensionValue(String oid) {
    lazyDecoding();
    Extension ext = extensions.getExtensionByOID(oid);
    return (ext == null) ? null : ext.getRawExtnValue();
}
Also used : Extension(org.apache.harmony.security.x509.Extension)

Aggregations

IOException (java.io.IOException)52 Enumeration (java.util.Enumeration)37 ArrayList (java.util.ArrayList)36 ExtCertPathValidatorException (org.bouncycastle.jce.exception.ExtCertPathValidatorException)36 List (java.util.List)35 CertPathValidatorException (java.security.cert.CertPathValidatorException)34 X509Certificate (java.security.cert.X509Certificate)34 GeneralSecurityException (java.security.GeneralSecurityException)33 CertificateExpiredException (java.security.cert.CertificateExpiredException)31 CertificateNotYetValidException (java.security.cert.CertificateNotYetValidException)31 CRLDistPoint (org.bouncycastle.asn1.x509.CRLDistPoint)31 IssuingDistributionPoint (org.bouncycastle.asn1.x509.IssuingDistributionPoint)31 DistributionPoint (org.bouncycastle.asn1.x509.DistributionPoint)28 CertPathBuilderException (java.security.cert.CertPathBuilderException)26 Extension (org.bouncycastle.asn1.x509.Extension)25 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)22 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)22 HashSet (java.util.HashSet)21 Set (java.util.Set)21 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)20