Search in sources :

Example 21 with CertStore

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

the class PKIXCRLUtil method findCRLs.

/**
     * Return a Collection of all CRLs found in the X509Store's that are
     * matching the crlSelect criteriums.
     *
     * @param crlSelect a {@link X509CRLStoreSelector} object that will be used
     *            to select the CRLs
     * @param crlStores a List containing only
     *            {@link org.bouncycastle.x509.X509Store  X509Store} objects.
     *            These are used to search for CRLs
     *
     * @return a Collection of all found {@link java.security.cert.X509CRL X509CRL} objects. May be
     *         empty but never <code>null</code>.
     */
private final Collection findCRLs(X509CRLStoreSelector crlSelect, List crlStores) throws AnnotatedException {
    Set crls = new HashSet();
    Iterator iter = crlStores.iterator();
    AnnotatedException lastException = null;
    boolean foundValidStore = false;
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof X509Store) {
            X509Store store = (X509Store) obj;
            try {
                crls.addAll(store.getMatches(crlSelect));
                foundValidStore = true;
            } catch (StoreException e) {
                lastException = new AnnotatedException("Exception searching in X.509 CRL store.", e);
            }
        } else {
            CertStore store = (CertStore) obj;
            try {
                crls.addAll(store.getCRLs(crlSelect));
                foundValidStore = true;
            } catch (CertStoreException e) {
                lastException = new AnnotatedException("Exception searching in X.509 CRL store.", e);
            }
        }
    }
    if (!foundValidStore && lastException != null) {
        throw lastException;
    }
    return crls;
}
Also used : X509Store(org.bouncycastle.x509.X509Store) Set(java.util.Set) HashSet(java.util.HashSet) CertStoreException(java.security.cert.CertStoreException) Iterator(java.util.Iterator) CertStore(java.security.cert.CertStore) HashSet(java.util.HashSet) StoreException(org.bouncycastle.util.StoreException) CertStoreException(java.security.cert.CertStoreException)

Example 22 with CertStore

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

the class CertPathValidatorUtilities method findCertificates.

/**
     * Return a Collection of all certificates or attribute certificates found
     * in the X509Store's that are matching the certSelect criteriums.
     *
     * @param certSelect a {@link Selector} object that will be used to select
     *                   the certificates
     * @param certStores a List containing only {@link X509Store} objects. These
     *                   are used to search for certificates.
     * @return a Collection of all found {@link X509Certificate} or
     *         {@link org.bouncycastle.x509.X509AttributeCertificate} objects.
     *         May be empty but never <code>null</code>.
     */
protected static Collection findCertificates(X509CertStoreSelector certSelect, List certStores) throws AnnotatedException {
    Set certs = new HashSet();
    Iterator iter = certStores.iterator();
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof X509Store) {
            X509Store certStore = (X509Store) obj;
            try {
                certs.addAll(certStore.getMatches(certSelect));
            } catch (StoreException e) {
                throw new AnnotatedException("Problem while picking certificates from X.509 store.", e);
            }
        } else {
            CertStore certStore = (CertStore) obj;
            try {
                certs.addAll(certStore.getCertificates(certSelect));
            } catch (CertStoreException e) {
                throw new AnnotatedException("Problem while picking certificates from certificate store.", e);
            }
        }
    }
    return certs;
}
Also used : X509Store(org.bouncycastle.x509.X509Store) Set(java.util.Set) HashSet(java.util.HashSet) CertStoreException(java.security.cert.CertStoreException) Iterator(java.util.Iterator) CertStore(java.security.cert.CertStore) HashSet(java.util.HashSet) CertStoreException(java.security.cert.CertStoreException) StoreException(org.bouncycastle.util.StoreException)

Example 23 with CertStore

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

the class CertStore2Test method testGetCertificates.

public void testGetCertificates() {
    CertStore certStore = null;
    try {
        certStore = CertStore.getInstance(CERT_STORE_NAME, null);
    } catch (InvalidAlgorithmParameterException e) {
        fail("unexpected exception: " + e);
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected exception: " + e);
    }
    assertNotNull(certStore);
    try {
        Collection<? extends Certificate> certificates = certStore.getCertificates(null);
        assertNull(certificates);
    } catch (CertStoreException e) {
        fail("unexpected exception: " + e);
    }
    try {
        Collection<? extends Certificate> certificates = certStore.getCertificates(new MyCertSelector());
        assertNotNull(certificates);
        assertTrue(certificates.isEmpty());
    } catch (CertStoreException e) {
        fail("unexpected exception: " + e);
    }
    try {
        certStore.getCertificates(new MyOtherCertSelector());
        fail("expected CertStoreException");
    } catch (CertStoreException e) {
    // ok
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) CertStoreException(java.security.cert.CertStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CertStore(java.security.cert.CertStore)

Example 24 with CertStore

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

the class CertStore2Test method testGetInstanceStringCertStoreParametersString.

public void testGetInstanceStringCertStoreParametersString() {
    try {
        CertStoreParameters parameters = new MyCertStoreParameters();
        CertStore certStore = CertStore.getInstance(CERT_STORE_NAME, parameters, CERT_STORE_PROVIDER_NAME);
        assertNotNull(certStore);
        assertNotNull(certStore.getCertStoreParameters());
        assertNotSame(parameters, certStore.getCertStoreParameters());
        assertEquals(CERT_STORE_PROVIDER_NAME, certStore.getProvider().getName());
    } catch (InvalidAlgorithmParameterException e) {
        fail("unexpected exception: " + e);
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected exception: " + e);
    } catch (NoSuchProviderException e) {
        fail("unexpected exception: " + e);
    }
    try {
        CertStore certStore = CertStore.getInstance(CERT_STORE_NAME, null, CERT_STORE_PROVIDER_NAME);
        assertNotNull(certStore);
        assertNull(certStore.getCertStoreParameters());
        assertEquals(CERT_STORE_PROVIDER_NAME, certStore.getProvider().getName());
    } catch (InvalidAlgorithmParameterException e) {
        fail("unexpected exception: " + e);
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected exception: " + e);
    } catch (NoSuchProviderException e) {
        fail("unexpected exception: " + e);
    }
    try {
        CertStore.getInstance("UnknownCertStore", new MyCertStoreParameters(), CERT_STORE_PROVIDER_NAME);
        fail("expected NoSuchAlgorithmException");
    } catch (InvalidAlgorithmParameterException e) {
        fail("unexpected exception: " + e);
    } catch (NoSuchAlgorithmException e) {
    // ok
    } catch (NoSuchProviderException e) {
        fail("unexpected exception: " + e);
    }
    try {
        CertStore.getInstance(CERT_STORE_NAME, null, "UnknownCertStoreProvider");
        fail("expected NoSuchProviderException");
    } catch (InvalidAlgorithmParameterException e) {
        fail("unexpected exception: " + e);
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected exception: " + e);
    } catch (NoSuchProviderException e) {
    // ok
    }
    try {
        CertStore.getInstance(CERT_STORE_NAME, new MyOtherCertStoreParameters(), CERT_STORE_PROVIDER_NAME);
    } catch (InvalidAlgorithmParameterException e) {
    // ok
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected exception: " + e);
    } catch (NoSuchProviderException e) {
        fail("unexpected exception: " + e);
    }
}
Also used : CertStoreParameters(java.security.cert.CertStoreParameters) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException) CertStore(java.security.cert.CertStore)

Example 25 with CertStore

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

the class myCertStore method testCertStore10.

/**
     * Test for method
     * <code>getInstance(String type, CertStoreParameters params, String provider)</code>
     * Assertion: return CertStore object
     */
public void testCertStore10() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException {
    if (!initParams()) {
        return;
    }
    CertStore certS;
    for (int i = 0; i < dValid.length; i++) {
        certS = CertStore.getInstance(dValid[i], dParams, dName);
        assertEquals("Incorrect type", certS.getType(), dValid[i]);
        certS.getCertStoreParameters();
    }
}
Also used : CertStore(java.security.cert.CertStore)

Aggregations

CertStore (java.security.cert.CertStore)38 X509Certificate (java.security.cert.X509Certificate)18 CollectionCertStoreParameters (java.security.cert.CollectionCertStoreParameters)13 CertStoreException (java.security.cert.CertStoreException)12 ArrayList (java.util.ArrayList)12 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)9 X509CertSelector (java.security.cert.X509CertSelector)9 NoSuchProviderException (java.security.NoSuchProviderException)8 PKIXBuilderParameters (java.security.cert.PKIXBuilderParameters)8 HashSet (java.util.HashSet)7 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)6 Iterator (java.util.Iterator)6 IOException (java.io.IOException)5 CertPathBuilder (java.security.cert.CertPathBuilder)5 CertStoreParameters (java.security.cert.CertStoreParameters)5 TrustAnchor (java.security.cert.TrustAnchor)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 KeyStoreException (java.security.KeyStoreException)4 Certificate (java.security.cert.Certificate)4 CertificateException (java.security.cert.CertificateException)4