Search in sources :

Example 36 with X509CRLSelector

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

the class X509CRLSelector2Test method testSetMaxCRLNumberLjava_math_BigInteger.

/**
     * setMaxCRLNumber(BigInteger maxCRL) method testing. Tests if CRLs with any
     * crl number value match the selector in the case of null crlNumber
     * criteria, if specified maxCRL 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 testSetMaxCRLNumberLjava_math_BigInteger() {
    X509CRLSelector selector = new X509CRLSelector();
    BigInteger maxCRL = new BigInteger("10000");
    TestCRL crl = new TestCRL(maxCRL);
    selector.setMaxCRLNumber(null);
    assertTrue("Any CRL should match in the case of null minCRLNumber.", selector.match(crl));
    selector.setMaxCRLNumber(maxCRL);
    assertTrue("The CRL should match the selection criteria.", selector.match(crl));
    selector.setMaxCRLNumber(new BigInteger("9999"));
    assertFalse("The CRL should not match the selection criteria.", selector.match(crl));
}
Also used : BigInteger(java.math.BigInteger) X509CRLSelector(java.security.cert.X509CRLSelector) AndroidOnly(dalvik.annotation.AndroidOnly)

Example 37 with X509CRLSelector

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

the class X509CRLSelector2Test method testSetDateAndTimeLjava_util_Date.

/**
     * setDateAndTime(Date dateAndTime) method testing. Tests if CRLs with any
     * update dates match the selector in the case of null dateAndTime criteria,
     * if correct dates match and incorrect do not match the selector.
     */
public void testSetDateAndTimeLjava_util_Date() {
    X509CRLSelector selector = new X509CRLSelector();
    TestCRL crl = new TestCRL(new Date(200), new Date(300));
    selector.setDateAndTime(null);
    assertTrue("Any CRL should match in the case of null dateAndTime.", selector.match(crl));
    selector.setDateAndTime(new Date(200));
    assertTrue("The CRL should match the selection criteria.", selector.match(crl));
    selector.setDateAndTime(new Date(250));
    assertTrue("The CRL should match the selection criteria.", selector.match(crl));
    selector.setDateAndTime(new Date(300));
    assertTrue("The CRL should match the selection criteria.", selector.match(crl));
    selector.setDateAndTime(new Date(150));
    assertFalse("The CRL should not match the selection criteria.", selector.match(crl));
    selector.setDateAndTime(new Date(350));
    assertFalse("The CRL should not match the selection criteria.", selector.match(crl));
}
Also used : X509CRLSelector(java.security.cert.X509CRLSelector) Date(java.util.Date)

Example 38 with X509CRLSelector

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

the class X509CRLSelector2Test method testSetIssuerNamesLjava_util_Collection02.

/**
     * setIssuerNames(Collection <?> names) method testing. Tests if CRLs with
     * any issuers match the selector in the case of null issuerNames criteria,
     * if specified issuers match the selector, if not specified issuer does not
     * match the selector, and if the internal collection of issuer names is
     * copied during initialization.
     */
@SuppressWarnings("unchecked")
public void testSetIssuerNamesLjava_util_Collection02() {
    X509CRLSelector selector = new X509CRLSelector();
    String iss1 = "O=First Org.";
    byte[] iss2 = new byte[] // manually obtained DER encoding of "O=Second Org." issuer name;
    { 48, 22, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 83, 101, 99, 111, 110, 100, 32, 79, 114, 103, 46 };
    String iss3 = "O=Third Org.";
    TestCRL crl1 = new TestCRL(new X500Principal(iss1));
    TestCRL crl2 = new TestCRL(new X500Principal(iss2));
    TestCRL crl3 = new TestCRL(new X500Principal(iss3));
    try {
        selector.setIssuerNames(null);
    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected IOException was thrown.");
    }
    assertTrue("Any CRL issuers should match in the case of null issuers.", selector.match(crl1) && selector.match(crl2));
    ArrayList issuers = new ArrayList(2);
    issuers.add(iss1);
    issuers.add(iss2);
    try {
        selector.setIssuerNames(issuers);
    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected IOException was thrown.");
    }
    assertTrue("The CRL should match the selection criteria.", selector.match(crl1) && selector.match(crl2));
    assertFalse("The CRL should not match the selection criteria.", selector.match(crl3));
    issuers.add(iss3);
    assertFalse("The internal issuer collection is not protected " + "against the modifications.", selector.match(crl3));
}
Also used : ArrayList(java.util.ArrayList) X500Principal(javax.security.auth.x500.X500Principal) ASN1OctetString(org.apache.harmony.security.asn1.ASN1OctetString) IOException(java.io.IOException) X509CRLSelector(java.security.cert.X509CRLSelector)

Example 39 with X509CRLSelector

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

the class X509CRLSelector2Test method testSetCertificateCheckingLjava_X509Certificate.

/**
     * setCertificateChecking(X509Certificate) method testing.
     */
public void testSetCertificateCheckingLjava_X509Certificate() throws CertificateException {
    X509CRLSelector selector = new X509CRLSelector();
    CertificateFactory certFact = CertificateFactory.getInstance("X509");
    X509Certificate cert = (X509Certificate) certFact.generateCertificate(new ByteArrayInputStream(TestUtils.getX509Certificate_v3()));
    TestCRL crl = new TestCRL();
    selector.setCertificateChecking(cert);
    assertTrue("The CRL should match the selection criteria.", selector.match(crl));
    assertEquals(cert, selector.getCertificateChecking());
    selector.setCertificateChecking(null);
    assertTrue("The CRL should match the selection criteria.", selector.match(crl));
    assertNull(selector.getCertificateChecking());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CertificateFactory(java.security.cert.CertificateFactory) X509CRLSelector(java.security.cert.X509CRLSelector) X509Certificate(java.security.cert.X509Certificate)

Example 40 with X509CRLSelector

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

the class X509CRLSelector2Test method testGetDateAndTime.

/**
     * getDateAndTime() method testing. Tests if the method return null in the
     * case of not specified dateAndTime criteria, and if the returned value
     * corresponds to the specified one.
     */
public void testGetDateAndTime() {
    X509CRLSelector selector = new X509CRLSelector();
    assertNull("Initially the dateAndTime criteria should be null.", selector.getDateAndTime());
    Date date = new Date(200);
    selector.setDateAndTime(date);
    assertTrue("The result should be equal to specified.", date.equals(selector.getDateAndTime()));
}
Also used : X509CRLSelector(java.security.cert.X509CRLSelector) Date(java.util.Date)

Aggregations

X509CRLSelector (java.security.cert.X509CRLSelector)58 X500Principal (javax.security.auth.x500.X500Principal)19 IOException (java.io.IOException)13 BigInteger (java.math.BigInteger)12 Date (java.util.Date)8 X509CRL (java.security.cert.X509CRL)7 X509Certificate (java.security.cert.X509Certificate)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 CRL (java.security.cert.CRL)4 CertStoreException (java.security.cert.CertStoreException)4 CertificateFactory (java.security.cert.CertificateFactory)4 ArrayList (java.util.ArrayList)4 AndroidOnly (dalvik.annotation.AndroidOnly)3 KeyStoreException (java.security.KeyStoreException)3 URI (java.net.URI)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 UnrecoverableEntryException (java.security.UnrecoverableEntryException)2 UnrecoverableKeyException (java.security.UnrecoverableKeyException)2 CertStore (java.security.cert.CertStore)2 CertificateException (java.security.cert.CertificateException)2