Search in sources :

Example 1 with CertStoreException

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

the class CMSSignedData method replaceCertificatesAndCRLs.

/**
     * Replace the certificate and CRL information associated with this
     * CMSSignedData object with the new one passed in.
     * 
     * @param signedData the signed data object to be used as a base.
     * @param certsAndCrls the new certificates and CRLs to be used.
     * @return a new signed data object.
     * @exception CMSException if there is an error processing the CertStore
     * @deprecated use method taking Store arguments.
     */
public static CMSSignedData replaceCertificatesAndCRLs(CMSSignedData signedData, CertStore certsAndCrls) throws CMSException {
    //
    // copy
    //
    CMSSignedData cms = new CMSSignedData(signedData);
    //
    // replace the certs and crls in the SignedData object
    //
    ASN1Set certs = null;
    ASN1Set crls = null;
    try {
        ASN1Set set = CMSUtils.createBerSetFromList(CMSUtils.getCertificatesFromStore(certsAndCrls));
        if (set.size() != 0) {
            certs = set;
        }
    } catch (CertStoreException e) {
        throw new CMSException("error getting certs from certStore", e);
    }
    try {
        ASN1Set set = CMSUtils.createBerSetFromList(CMSUtils.getCRLsFromStore(certsAndCrls));
        if (set.size() != 0) {
            crls = set;
        }
    } catch (CertStoreException e) {
        throw new CMSException("error getting crls from certStore", e);
    }
    //
    // replace the CMS structure.
    //
    cms.signedData = new SignedData(signedData.signedData.getDigestAlgorithms(), signedData.signedData.getEncapContentInfo(), certs, crls, signedData.signedData.getSignerInfos());
    //
    // replace the contentInfo with the new one
    //
    cms.contentInfo = new ContentInfo(cms.contentInfo.getContentType(), cms.signedData);
    return cms;
}
Also used : ASN1Set(org.bouncycastle.asn1.ASN1Set) SignedData(org.bouncycastle.asn1.cms.SignedData) ContentInfo(org.bouncycastle.asn1.cms.ContentInfo) CertStoreException(java.security.cert.CertStoreException)

Example 2 with CertStoreException

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

the class CertStore2Test method testGetCRLs.

public void testGetCRLs() {
    CertStore certStore = null;
    try {
        certStore = CertStore.getInstance(CERT_STORE_NAME, new MyCertStoreParameters());
    } catch (InvalidAlgorithmParameterException e) {
        fail("unexpected exception: " + e);
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected exception: " + e);
    }
    assertNotNull(certStore);
    try {
        Collection<? extends CRL> ls = certStore.getCRLs(null);
        assertNull(ls);
    } catch (CertStoreException e) {
        fail("unexpected exception: " + e);
    }
    try {
        Collection<? extends CRL> ls = certStore.getCRLs(new MyCRLSelector());
        assertNotNull(ls);
        assertTrue(ls.isEmpty());
    } catch (CertStoreException e) {
        fail("unexpected exception: " + e);
    }
    try {
        certStore.getCRLs(new MyOtherCRLSelector());
        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 3 with CertStoreException

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

the class CertStoreExceptionTest method testCertStoreException09.

/**
     * Test for <code>CertStoreException(String, Throwable)</code> constructor
     * Assertion: constructs CertStoreException when <code>cause</code> is not
     * null <code>msg</code> is not null
     */
public void testCertStoreException09() {
    CertStoreException tE;
    for (int i = 0; i < msgs.length; i++) {
        tE = new CertStoreException(msgs[i], tCause);
        String getM = tE.getMessage();
        String toS = tCause.toString();
        if (msgs[i].length() > 0) {
            assertTrue("getMessage() must contain ".concat(msgs[i]), getM.indexOf(msgs[i]) != -1);
            if (!getM.equals(msgs[i])) {
                assertTrue("getMessage() should contain ".concat(toS), getM.indexOf(toS) != -1);
            }
        }
        assertNotNull("getCause() must not return null", tE.getCause());
        assertEquals("getCause() must return ".concat(tCause.toString()), tE.getCause(), tCause);
    }
}
Also used : CertStoreException(java.security.cert.CertStoreException)

Example 4 with CertStoreException

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

the class CertStoreExceptionTest method testCertStoreException07.

/**
     * Test for <code>CertStoreException(String, Throwable)</code> constructor
     * Assertion: constructs CertStoreException when <code>cause</code> is
     * null <code>msg</code> is not null
     */
public void testCertStoreException07() {
    CertStoreException tE;
    for (int i = 0; i < msgs.length; i++) {
        tE = new CertStoreException(msgs[i], null);
        assertEquals("getMessage() must return: ".concat(msgs[i]), tE.getMessage(), msgs[i]);
        assertNull("getCause() must return null", tE.getCause());
    }
}
Also used : CertStoreException(java.security.cert.CertStoreException)

Example 5 with CertStoreException

use of java.security.cert.CertStoreException in project XobotOS by xamarin.

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)

Aggregations

CertStoreException (java.security.cert.CertStoreException)23 CertStore (java.security.cert.CertStore)10 X509Certificate (java.security.cert.X509Certificate)5 IOException (java.io.IOException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 HashSet (java.util.HashSet)4 Iterator (java.util.Iterator)4 Set (java.util.Set)4 StoreException (org.bouncycastle.util.StoreException)4 X509Store (org.bouncycastle.x509.X509Store)4 InputStream (java.io.InputStream)3 URLConnection (java.net.URLConnection)3 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)3 CertificateException (java.security.cert.CertificateException)3 HttpURLConnection (java.net.HttpURLConnection)2 KeyStoreException (java.security.KeyStoreException)2 UnrecoverableKeyException (java.security.UnrecoverableKeyException)2 Collection (java.util.Collection)2 URI (java.net.URI)1 CodeSigner (java.security.CodeSigner)1