Search in sources :

Example 26 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 27 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 28 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 29 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)

Aggregations

X509CRLSelector (java.security.cert.X509CRLSelector)29 X500Principal (javax.security.auth.x500.X500Principal)9 IOException (java.io.IOException)7 BigInteger (java.math.BigInteger)6 Date (java.util.Date)4 AndroidOnly (dalvik.annotation.AndroidOnly)3 X509CRL (java.security.cert.X509CRL)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 CRL (java.security.cert.CRL)2 CertStoreException (java.security.cert.CertStoreException)2 CertificateFactory (java.security.cert.CertificateFactory)2 X509Certificate (java.security.cert.X509Certificate)2 ArrayList (java.util.ArrayList)2 ASN1OctetString (org.apache.harmony.security.asn1.ASN1OctetString)2 InputStream (java.io.InputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 URI (java.net.URI)1 URLConnection (java.net.URLConnection)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1