Search in sources :

Example 21 with CRL

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

the class X509CRLSelector2Test method testSetMinCRLNumberLjava_math_BigInteger.

/**
     * setMinCRLNumber(BigInteger minCRL) method testing. Tests if CRLs with any
     * crl number value match the selector in the case of null crlNumber
     * criteria, if specified minCRL value matches the selector, and if CRL with
     * inappropriate crlNumber value does not match the selector.
     */
@AndroidOnly("Uses specific class: " + "org.apache.harmony.security.asn1.ASN1OctetString.")
public void testSetMinCRLNumberLjava_math_BigInteger() {
    X509CRLSelector selector = new X509CRLSelector();
    BigInteger minCRL = new BigInteger("10000");
    CRL crl = new TestCRL(minCRL);
    selector.setMinCRLNumber(null);
    assertTrue("Any CRL should match in the case of null minCRLNumber.", selector.match(crl));
    selector.setMinCRLNumber(minCRL);
    assertTrue("The CRL should match the selection criteria.", selector.match(crl));
    selector.setMinCRLNumber(new BigInteger("10001"));
    assertFalse("The CRL should not match the selection criteria.", selector.match(crl));
}
Also used : BigInteger(java.math.BigInteger) X509CRL(java.security.cert.X509CRL) CRL(java.security.cert.CRL) X509CRLSelector(java.security.cert.X509CRLSelector) AndroidOnly(dalvik.annotation.AndroidOnly)

Example 22 with CRL

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

the class X509CRLSelector2Test method testAddIssuerLjavax_security_auth_x500_X500Principal02.

/**
     * addIssuer(X500Principal issuer) method testing. Tests if CRLs with
     * specified issuers match the selector, and if not specified issuer does
     * not match the selector.
     */
public void testAddIssuerLjavax_security_auth_x500_X500Principal02() {
    X509CRLSelector selector = new X509CRLSelector();
    X500Principal iss1 = new X500Principal("O=First Org.");
    X500Principal iss2 = new X500Principal("O=Second Org.");
    CRL crl1 = new TestCRL(iss1);
    CRL crl2 = new TestCRL(iss2);
    selector.addIssuer(iss1);
    assertTrue("The CRL should match the selection criteria.", selector.match(crl1));
    assertFalse("The CRL should not match the selection criteria.", selector.match(crl2));
    selector.addIssuer(iss2);
    assertTrue("The CRL should match the selection criteria.", selector.match(crl2));
}
Also used : X500Principal(javax.security.auth.x500.X500Principal) X509CRL(java.security.cert.X509CRL) CRL(java.security.cert.CRL) X509CRLSelector(java.security.cert.X509CRLSelector)

Example 23 with CRL

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

the class X509CRLTest method getType.

private void getType(CertificateFactory f) throws Exception {
    CRL crlRsa = getCRL(f, CRL_RSA);
    assertEquals("X.509", crlRsa.getType());
}
Also used : X509CRL(java.security.cert.X509CRL) CRL(java.security.cert.CRL)

Example 24 with CRL

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

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 25 with CRL

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

the class CertificateFactory4Test method test_generateCRLLjava_io_InputStream.

/**
     * java.security.cert.CertificateFactory#generateCRL(java.io.InputStream)
     */
public void test_generateCRLLjava_io_InputStream() throws Exception {
    CertificateFactory fact = CertificateFactory.getInstance("X.509");
    for (int i = 0; i < CRL_URLS.length; i++) {
        URL certUrl = new URL(BASE_URL + CRL_URLS[i]);
        try {
            InputStream is = certUrl.openStream();
            CRL crl = fact.generateCRL(is);
            assertNotNull("The CRL in \"" + certUrl.toExternalForm() + "\" were not parsed correctly", crl);
        } catch (IOException e) {
        // the certificate could not be found, skip it
        } catch (CRLException e) {
            fail("An exception was thrown while parsing \"" + certUrl.toExternalForm() + "\": " + e.getMessage());
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) CRL(java.security.cert.CRL) CertificateFactory(java.security.cert.CertificateFactory) CRLException(java.security.cert.CRLException) URL(java.net.URL)

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