Search in sources :

Example 11 with CRL

use of java.security.cert.CRL in project nhin-d by DirectProject.

the class CRLRevocationManager_getCrlFromUriTest method testGetCrlFromUri_nullURI_assertNull.

public void testGetCrlFromUri_nullURI_assertNull() {
    CRL crl = CRLRevocationManager.getInstance().getCrlFromUri(null);
    assertNull(crl);
}
Also used : X509CRL(java.security.cert.X509CRL) CRL(java.security.cert.CRL)

Example 12 with CRL

use of java.security.cert.CRL in project nhin-d by DirectProject.

the class CRLRevocationManager_writeCRLCacheFileTest method testWriteCRLCacheFile_writeToFile_deleteExisting.

public void testWriteCRLCacheFile_writeToFile_deleteExisting() throws Exception {
    CRLRevocationManager.initCRLCacheLocation();
    CRL crlToWrite = TestUtils.loadCRL("certs.crl");
    String distURI = "http://localhost:8080/config";
    // make sure it doesn't exist
    File crlFile = new File(CRLRevocationManager.getCacheFileName(distURI));
    assertFalse(crlFile.exists());
    CRLRevocationManager.getInstance().writeCRLCacheFile(distURI, (X509CRL) crlToWrite);
    // make sure the file exists
    assertTrue(crlFile.exists());
    // mark the date
    long originalFileDate = crlFile.lastModified();
    // sleep 2000 ms to make sure we get a new date
    Thread.sleep(2000);
    // write it again
    CRLRevocationManager.getInstance().writeCRLCacheFile(distURI, (X509CRL) crlToWrite);
    // make sure the file exists
    crlFile = new File(CRLRevocationManager.getCacheFileName(distURI));
    assertTrue(crlFile.exists());
    // mark the date
    long newFileDate = crlFile.lastModified();
    // make sure the dates aren't the same
    assertTrue(originalFileDate != newFileDate);
}
Also used : X509CRL(java.security.cert.X509CRL) CRL(java.security.cert.CRL) File(java.io.File)

Example 13 with CRL

use of java.security.cert.CRL in project nhin-d by DirectProject.

the class TestUtils method loadCRL.

public static CRL loadCRL(String certFileName) throws Exception {
    File fl = new File(crlBasePath + certFileName);
    InputStream str = FileUtils.openInputStream(fl);
    CRL retVal = CertificateFactory.getInstance("X.509").generateCRL(str);
    str.close();
    return retVal;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) CRL(java.security.cert.CRL) File(java.io.File)

Example 14 with CRL

use of java.security.cert.CRL in project java-chassis by ServiceComb.

the class KeyStoreUtil method createCRL.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static CRL[] createCRL(String crlfile) {
    InputStream is = null;
    try {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        is = new FileInputStream(crlfile);
        Collection c = cf.generateCRLs(is);
        CRL[] crls = (CRL[]) c.toArray(new CRL[c.size()]);
        return crls;
    } catch (CertificateException e) {
        throw new IllegalArgumentException("bad cert file.");
    } catch (FileNotFoundException e) {
        throw new IllegalArgumentException("crl file not found.");
    } catch (CRLException e) {
        throw new IllegalArgumentException("bad crl file.");
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                ignore();
            }
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) Collection(java.util.Collection) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) CRL(java.security.cert.CRL) CertificateFactory(java.security.cert.CertificateFactory) CRLException(java.security.cert.CRLException) FileInputStream(java.io.FileInputStream)

Example 15 with CRL

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

the class Pair method readCRLsFromCert.

/**
     * Returns CRLs described in a X509Certificate's CRLDistributionPoints
     * Extension. Only those containing a general name of type URI are read.
     */
public static List<CRL> readCRLsFromCert(X509Certificate cert) throws Exception {
    List<CRL> crls = new ArrayList<>();
    CRLDistributionPointsExtension ext = X509CertImpl.toImpl(cert).getCRLDistributionPointsExtension();
    if (ext == null)
        return crls;
    List<DistributionPoint> distPoints = ext.get(CRLDistributionPointsExtension.POINTS);
    for (DistributionPoint o : distPoints) {
        GeneralNames names = o.getFullName();
        if (names != null) {
            for (GeneralName name : names.names()) {
                if (name.getType() == GeneralNameInterface.NAME_URI) {
                    URIName uriName = (URIName) name.getName();
                    for (CRL crl : loadCRLs(uriName.getName())) {
                        if (crl instanceof X509CRL) {
                            crls.add((X509CRL) crl);
                        }
                    }
                    // Different name should point to same CRL
                    break;
                }
            }
        }
    }
    return crls;
}
Also used : X509CRL(java.security.cert.X509CRL) X509CRL(java.security.cert.X509CRL) CRL(java.security.cert.CRL)

Aggregations

CRL (java.security.cert.CRL)37 X509CRL (java.security.cert.X509CRL)16 CRLException (java.security.cert.CRLException)11 CertificateException (java.security.cert.CertificateException)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 ArrayList (java.util.ArrayList)7 File (java.io.File)6 Certificate (java.security.cert.Certificate)5 IOException (java.io.IOException)4 CertificateFactory (java.security.cert.CertificateFactory)4 DataInputStream (java.io.DataInputStream)3 InputStream (java.io.InputStream)3 CertificateFactorySpi (java.security.cert.CertificateFactorySpi)3 X509Certificate (java.security.cert.X509Certificate)3 List (java.util.List)3 FileInputStream (java.io.FileInputStream)2 X509CRLSelector (java.security.cert.X509CRLSelector)2 Iterator (java.util.Iterator)2 MyCertificateFactorySpi (org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi)2 AndroidOnly (dalvik.annotation.AndroidOnly)1