Search in sources :

Example 56 with CRL

use of java.security.cert.CRL in project j2objc by google.

the class CRLTest method testGetType02.

/**
 * Test #2 for <code>getType()</code> method<br>
 * Assertion: returns <code>CRL</code> type
 */
public final void testGetType02() {
    CRL crl = new MyCRL(null);
    assertNull(crl.getType());
}
Also used : CRL(java.security.cert.CRL)

Example 57 with CRL

use of java.security.cert.CRL in project j2objc by google.

the class myCertificateFactory method testCertificateFactory11.

/*
     * Test for <code> generateCertificate(InputStream inStream) </code><code>
     * generateCertificates(InputStream inStream) </code><code>
     * generateCRL(InputStream inStream) </code><code>
     * generateCRLs(InputStream inStream) </code>
     * methods
     * Assertion: throw CertificateException and CRLException when inStream
     * contains incompatible datas
     */
public void testCertificateFactory11() throws IOException {
    if (!X509Support) {
        fail(NotSupportMsg);
        return;
    }
    CertificateFactory[] certFs = initCertFs();
    assertNotNull("CertificateFactory objects were not created", certFs);
    MyCertificate mc = createMC();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(os);
    oos.writeObject(mc);
    oos.flush();
    oos.close();
    Certificate cer;
    Collection<?> colCer;
    CRL crl;
    Collection<?> colCrl;
    byte[] arr = os.toByteArray();
    ByteArrayInputStream is;
    for (int i = 0; i < certFs.length; i++) {
        is = new ByteArrayInputStream(arr);
        try {
            cer = certFs[i].generateCertificate(is);
            assertNull("Not null certificate was created", cer);
        } catch (CertificateException e) {
        }
        is = new ByteArrayInputStream(arr);
        try {
            colCer = certFs[i].generateCertificates(is);
            if (colCer != null) {
                assertTrue("Not empty certificate Collection was created", colCer.isEmpty());
            }
        } catch (CertificateException e) {
        }
        is = new ByteArrayInputStream(arr);
        try {
            crl = certFs[i].generateCRL(is);
            assertNull("Not null CRL was created", crl);
        } catch (CRLException e) {
        }
        is = new ByteArrayInputStream(arr);
        try {
            colCrl = certFs[i].generateCRLs(is);
            if (colCrl != null) {
                assertTrue("Not empty CRL Collection was created", colCrl.isEmpty());
            }
        } catch (CRLException e) {
        }
    }
}
Also used : MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate) CertificateException(java.security.cert.CertificateException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) CertificateFactory(java.security.cert.CertificateFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) CRL(java.security.cert.CRL) CRLException(java.security.cert.CRLException) Certificate(java.security.cert.Certificate) MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate)

Example 58 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 59 with CRL

use of java.security.cert.CRL in project jruby-openssl by jruby.

the class Lookup method loadCRLFile.

/**
 * c: X509_LOOKUP_load_crl_file
 */
public int loadCRLFile(final String file, final int type) throws Exception {
    if (file == null)
        return 1;
    BufferedReader reader = null;
    try {
        InputStream in = wrapJRubyNormalizedInputStream(file);
        CRL crl;
        if (type == X509_FILETYPE_PEM) {
            reader = new BufferedReader(new InputStreamReader(in));
            int count = 0;
            for (; ; ) {
                crl = PEMInputOutput.readX509CRL(reader, null);
                if (crl == null)
                    break;
                if (store.addCRL(crl) == 0)
                    return 0;
                count++;
            }
            return count;
        } else if (type == X509_FILETYPE_ASN1) {
            crl = SecurityHelper.getCertificateFactory("X.509").generateCRL(in);
            // }
            return store.addCRL(crl);
        } else {
            X509Error.addError(X509_R_BAD_X509_FILETYPE);
            // NOTE: really?
            return 0;
        }
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (Exception ignored) {
            }
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) X509_LU_CRL(org.jruby.ext.openssl.x509store.X509Utils.X509_LU_CRL) CRL(java.security.cert.CRL) FileExistsException(org.jruby.util.io.FileExistsException) GeneralSecurityException(java.security.GeneralSecurityException) InvalidValueException(org.jruby.util.io.InvalidValueException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException)

Aggregations

CRL (java.security.cert.CRL)59 CertificateException (java.security.cert.CertificateException)21 X509CRL (java.security.cert.X509CRL)21 CRLException (java.security.cert.CRLException)19 ByteArrayInputStream (java.io.ByteArrayInputStream)14 Certificate (java.security.cert.Certificate)13 File (java.io.File)9 IOException (java.io.IOException)9 X509Certificate (java.security.cert.X509Certificate)9 CertificateFactory (java.security.cert.CertificateFactory)8 ArrayList (java.util.ArrayList)8 DataInputStream (java.io.DataInputStream)6 InputStream (java.io.InputStream)6 CertificateFactorySpi (java.security.cert.CertificateFactorySpi)6 MyCertificateFactorySpi (org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi)6 FileInputStream (java.io.FileInputStream)5 X509CRLSelector (java.security.cert.X509CRLSelector)4 Collection (java.util.Collection)4 GeneralSecurityException (java.security.GeneralSecurityException)3 List (java.util.List)3