Search in sources :

Example 11 with CertStoreParameters

use of java.security.cert.CertStoreParameters 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 12 with CertStoreParameters

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

the class CollectionCertStoreParametersTest method testCollectionCertStoreParameters01.

//
// Tests
//
/**
     * Test #1 for <code>CollectionCertStoreParameters()</code> constructor<br>
     */
public final void testCollectionCertStoreParameters01() {
    CertStoreParameters cp = new CollectionCertStoreParameters();
    assertTrue("isCollectionCertStoreParameters", cp instanceof CollectionCertStoreParameters);
}
Also used : CollectionCertStoreParameters(java.security.cert.CollectionCertStoreParameters) CertStoreParameters(java.security.cert.CertStoreParameters) CollectionCertStoreParameters(java.security.cert.CollectionCertStoreParameters)

Example 13 with CertStoreParameters

use of java.security.cert.CertStoreParameters in project Payara by payara.

the class JSSE14SocketFactory method getParameters.

/**
 * Return the initialization parameters for the TrustManager. Currently, only the default <code>PKIX</code> is
 * supported.
 *
 * @param algorithm The algorithm to get parameters for.
 * @param crlf The path to the CRL file.
 * @param trustStore The configured TrustStore.
 *
 * @return The parameters including the CRLs and TrustStore.
 */
protected CertPathParameters getParameters(String algorithm, String crlf, KeyStore trustStore) throws Exception {
    CertPathParameters params;
    if ("PKIX".equalsIgnoreCase(algorithm)) {
        PKIXBuilderParameters xparams = new PKIXBuilderParameters(trustStore, new X509CertSelector());
        Collection crls = getCRLs(crlf);
        CertStoreParameters csp = new CollectionCertStoreParameters(crls);
        CertStore store = CertStore.getInstance("Collection", csp);
        xparams.addCertStore(store);
        xparams.setRevocationEnabled(true);
        String trustLength = (String) attributes.get("trustMaxCertLength");
        if (trustLength != null) {
            try {
                xparams.setMaxPathLength(Integer.parseInt(trustLength));
            } catch (Exception ex) {
                logger.warning("Bad maxCertLength: " + trustLength);
            }
        }
        params = xparams;
    } else {
        throw new CRLException("CRLs not supported for type: " + algorithm);
    }
    return params;
}
Also used : CertStoreParameters(java.security.cert.CertStoreParameters) CollectionCertStoreParameters(java.security.cert.CollectionCertStoreParameters) CollectionCertStoreParameters(java.security.cert.CollectionCertStoreParameters) PKIXBuilderParameters(java.security.cert.PKIXBuilderParameters) Collection(java.util.Collection) CertPathParameters(java.security.cert.CertPathParameters) X509CertSelector(java.security.cert.X509CertSelector) CertStore(java.security.cert.CertStore) CRLException(java.security.cert.CRLException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) SSLException(javax.net.ssl.SSLException) CRLException(java.security.cert.CRLException)

Aggregations

CertStoreParameters (java.security.cert.CertStoreParameters)13 CertStore (java.security.cert.CertStore)7 CollectionCertStoreParameters (java.security.cert.CollectionCertStoreParameters)7 PKIXBuilderParameters (java.security.cert.PKIXBuilderParameters)6 X509CertSelector (java.security.cert.X509CertSelector)6 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 X509Certificate (java.security.cert.X509Certificate)4 CertPathBuilder (java.security.cert.CertPathBuilder)3 LDAPCertStoreParameters (java.security.cert.LDAPCertStoreParameters)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 KeyStore (java.security.KeyStore)2 CertPathBuilderResult (java.security.cert.CertPathBuilderResult)2 Certificate (java.security.cert.Certificate)2 CertificateException (java.security.cert.CertificateException)2 CertificateFactory (java.security.cert.CertificateFactory)2 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 CRLException (java.security.cert.CRLException)1