Search in sources :

Example 41 with X509CRLSelector

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

the class X509CRLSelector2Test method testMatchLjava_security_cert_X509CRL.

/**
     * match(CRL crl) method testing. Tests if the null object matches to the
     * selector or not.
     */
public void testMatchLjava_security_cert_X509CRL() {
    X509CRLSelector selector = new X509CRLSelector();
    assertFalse("The null object should not match", selector.match((X509CRL) null));
}
Also used : X509CRL(java.security.cert.X509CRL) X509CRLSelector(java.security.cert.X509CRLSelector)

Example 42 with X509CRLSelector

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

the class X509CRLSelector2Test method testToString.

public void testToString() {
    X509CRLSelector selector = new X509CRLSelector();
    X500Principal iss1 = new X500Principal("O=First Org.");
    X500Principal iss2 = new X500Principal("O=Second Org.");
    BigInteger minCRL = new BigInteger("10000");
    BigInteger maxCRL = new BigInteger("10000");
    Date date = new Date(200);
    selector.addIssuer(iss1);
    selector.addIssuer(iss2);
    selector.setMinCRLNumber(minCRL);
    selector.setMaxCRLNumber(maxCRL);
    selector.setDateAndTime(date);
    assertNotNull("The result should not be null.", selector.toString());
}
Also used : X500Principal(javax.security.auth.x500.X500Principal) BigInteger(java.math.BigInteger) X509CRLSelector(java.security.cert.X509CRLSelector) Date(java.util.Date)

Example 43 with X509CRLSelector

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

the class X509CRLSelector2Test method testSetIssuersLjava_util_Collection.

/**
     * setIssuers(Collection <X500Principal> issuers) method testing. Tests if
     * CRLs with any issuers match the selector in the case of null issuerNames
     * criteria, if specified issuers match the selector, and if not specified
     * issuer does not match the selector.
     */
public void testSetIssuersLjava_util_Collection() {
    X509CRLSelector selector = new X509CRLSelector();
    X500Principal iss1 = new X500Principal("O=First Org.");
    X500Principal iss2 = new X500Principal("O=Second Org.");
    X500Principal iss3 = new X500Principal("O=Third Org.");
    TestCRL crl1 = new TestCRL(iss1);
    TestCRL crl2 = new TestCRL(iss2);
    TestCRL crl3 = new TestCRL(iss3);
    selector.setIssuers(null);
    assertTrue("Any CRL issuers should match in the case of null issuers.", selector.match(crl1) && selector.match(crl2));
    ArrayList<X500Principal> issuers = new ArrayList<X500Principal>(2);
    issuers.add(iss1);
    issuers.add(iss2);
    selector.setIssuers(issuers);
    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) X509CRLSelector(java.security.cert.X509CRLSelector)

Example 44 with X509CRLSelector

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

the class Pair method loadCRLs.

/**
     * Loads CRLs from a source. This method is also called in JarSigner.
     * @param src the source, which means System.in if null, or a URI,
     *        or a bare file path name
     */
public static Collection<? extends CRL> loadCRLs(String src) throws Exception {
    InputStream in = null;
    URI uri = null;
    if (src == null) {
        in = System.in;
    } else {
        try {
            uri = new URI(src);
            if (uri.getScheme().equals("ldap")) {
            // No input stream for LDAP
            } else {
                in = uri.toURL().openStream();
            }
        } catch (Exception e) {
            try {
                in = new FileInputStream(src);
            } catch (Exception e2) {
                if (uri == null || uri.getScheme() == null) {
                    // More likely a bare file path
                    throw e2;
                } else {
                    // More likely a protocol or network problem
                    throw e;
                }
            }
        }
    }
    if (in != null) {
        try {
            // Read the full stream before feeding to X509Factory,
            // otherwise, keytool -gencrl | keytool -printcrl
            // might not work properly, since -gencrl is slow
            // and there's no data in the pipe at the beginning.
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            byte[] b = new byte[4096];
            while (true) {
                int len = in.read(b);
                if (len < 0)
                    break;
                bout.write(b, 0, len);
            }
            return CertificateFactory.getInstance("X509").generateCRLs(new ByteArrayInputStream(bout.toByteArray()));
        } finally {
            if (in != System.in) {
                in.close();
            }
        }
    } else {
        // must be LDAP, and uri is not null
        // Lazily load LDAPCertStoreHelper if present
        CertStoreHelper helper = CertStoreHelper.getInstance("LDAP");
        String path = uri.getPath();
        if (path.charAt(0) == '/')
            path = path.substring(1);
        CertStore s = helper.getCertStore(uri);
        X509CRLSelector sel = helper.wrap(new X509CRLSelector(), null, path);
        return s.getCRLs(sel);
    }
}
Also used : CertStoreHelper(sun.security.provider.certpath.CertStoreHelper) URI(java.net.URI) CertStore(java.security.cert.CertStore) KeyStoreException(java.security.KeyStoreException) UnrecoverableEntryException(java.security.UnrecoverableEntryException) CertStoreException(java.security.cert.CertStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) CertificateException(java.security.cert.CertificateException) X509CRLSelector(java.security.cert.X509CRLSelector)

Example 45 with X509CRLSelector

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

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)

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