Search in sources :

Example 96 with X509CRL

use of java.security.cert.X509CRL in project robovm by robovm.

the class PKIXCRLUtil method findCRLs.

public Set findCRLs(X509CRLStoreSelector crlselect, ExtendedPKIXParameters paramsPKIX, Date currentDate) throws AnnotatedException {
    Set initialSet = new HashSet();
    // get complete CRL(s)
    try {
        initialSet.addAll(findCRLs(crlselect, paramsPKIX.getAdditionalStores()));
        initialSet.addAll(findCRLs(crlselect, paramsPKIX.getStores()));
        initialSet.addAll(findCRLs(crlselect, paramsPKIX.getCertStores()));
    } catch (AnnotatedException e) {
        throw new AnnotatedException("Exception obtaining complete CRLs.", e);
    }
    Set finalSet = new HashSet();
    Date validityDate = currentDate;
    if (paramsPKIX.getDate() != null) {
        validityDate = paramsPKIX.getDate();
    }
    // based on RFC 5280 6.3.3
    for (Iterator it = initialSet.iterator(); it.hasNext(); ) {
        X509CRL crl = (X509CRL) it.next();
        if (crl.getNextUpdate().after(validityDate)) {
            X509Certificate cert = crlselect.getCertificateChecking();
            if (cert != null) {
                if (crl.getThisUpdate().before(cert.getNotAfter())) {
                    finalSet.add(crl);
                }
            } else {
                finalSet.add(crl);
            }
        }
    }
    return finalSet;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) X509CRL(java.security.cert.X509CRL) Iterator(java.util.Iterator) Date(java.util.Date) X509Certificate(java.security.cert.X509Certificate) HashSet(java.util.HashSet)

Example 97 with X509CRL

use of java.security.cert.X509CRL in project jdk8u_jdk by JetBrains.

the class Pair method printCRL.

private void printCRL(CRL crl, PrintStream out) throws Exception {
    if (rfc) {
        X509CRL xcrl = (X509CRL) crl;
        out.println("-----BEGIN X509 CRL-----");
        out.println(Base64.getMimeEncoder(64, CRLF).encodeToString(xcrl.getEncoded()));
        out.println("-----END X509 CRL-----");
    } else {
        out.println(crl.toString());
    }
}
Also used : X509CRL(java.security.cert.X509CRL)

Example 98 with X509CRL

use of java.security.cert.X509CRL in project jdk8u_jdk by JetBrains.

the class CertUtils method getCRLFromFile.

/**
     * Get a DER-encoded X.509 CRL from a file.
     *
     * @param crlFilePath path to file containing DER-encoded CRL
     * @return X509CRL
     * @throws IOException on error
     */
public static X509CRL getCRLFromFile(String crlFilePath) throws IOException {
    X509CRL crl = null;
    try {
        File crlFile = new File(System.getProperty("test.src", "."), crlFilePath);
        if (!crlFile.canRead())
            throw new IOException("File " + crlFile.toString() + " is not a readable file.");
        FileInputStream crlFileInputStream = new FileInputStream(crlFile);
        CertificateFactory cf = CertificateFactory.getInstance("X509");
        crl = (X509CRL) cf.generateCRL(crlFileInputStream);
    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException("Can't construct X509CRL: " + e.getMessage());
    }
    return crl;
}
Also used : X509CRL(java.security.cert.X509CRL) IOException(java.io.IOException) File(java.io.File) CertificateFactory(java.security.cert.CertificateFactory) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Example 99 with X509CRL

use of java.security.cert.X509CRL in project oxAuth by GluuFederation.

the class CRLCertificateVerifier method requestCRL.

public X509CRL requestCRL(String url) throws IOException, MalformedURLException, CertificateException, CRLException {
    HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
    try {
        con.setUseCaches(false);
        InputStream in = new BoundedInputStream(con.getInputStream(), maxCrlSize);
        try {
            CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
            X509CRL crl = (X509CRL) certificateFactory.generateCRL(in);
            log.debug("CRL size: " + crl.getEncoded().length + " bytes");
            return crl;
        } finally {
            IOUtils.closeQuietly(in);
        }
    } catch (IOException ex) {
        log.error("Failed to download CRL from '" + url + "'", ex);
    } finally {
        if (con != null) {
            con.disconnect();
        }
    }
    return null;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) X509CRL(java.security.cert.X509CRL) BoundedInputStream(org.apache.commons.io.input.BoundedInputStream) ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BoundedInputStream(org.apache.commons.io.input.BoundedInputStream) IOException(java.io.IOException) CertificateFactory(java.security.cert.CertificateFactory) URL(java.net.URL)

Example 100 with X509CRL

use of java.security.cert.X509CRL in project jdk8u_jdk by JetBrains.

the class GenerationTests method test_create_signature_x509_crt_crl.

static void test_create_signature_x509_crt_crl() throws Exception {
    System.out.println("* Generating signature-x509-crt-crl.xml");
    List<Object> xds = new ArrayList<Object>();
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    xds.add(signingCert);
    FileInputStream fis = new FileInputStream(CRL);
    X509CRL crl = (X509CRL) cf.generateCRL(fis);
    fis.close();
    xds.add(crl);
    KeyInfo crt_crl = kifac.newKeyInfo(Collections.singletonList(kifac.newX509Data(xds)));
    test_create_signature_external(dsaSha1, crt_crl, signingKey, new X509KeySelector(ks), false);
    System.out.println();
}
Also used : X509CRL(java.security.cert.X509CRL) CertificateFactory(java.security.cert.CertificateFactory)

Aggregations

X509CRL (java.security.cert.X509CRL)167 IOException (java.io.IOException)47 File (java.io.File)39 CRLException (java.security.cert.CRLException)39 X509Certificate (java.security.cert.X509Certificate)36 BigInteger (java.math.BigInteger)27 CertificateException (java.security.cert.CertificateException)27 CertificateFactory (java.security.cert.CertificateFactory)26 HashSet (java.util.HashSet)23 Date (java.util.Date)20 GeneralSecurityException (java.security.GeneralSecurityException)18 X509CRLEntry (java.security.cert.X509CRLEntry)18 InputStream (java.io.InputStream)17 Test (org.junit.Test)16 FileOutputStream (java.io.FileOutputStream)14 BufferedOutputStream (java.io.BufferedOutputStream)13 OutputStream (java.io.OutputStream)13 ArrayList (java.util.ArrayList)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 FileInputStream (java.io.FileInputStream)12