Search in sources :

Example 1 with CertPathParameters

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

the class CertPathValidatorSpiTest method testCertPathValidatorSpi01.

/**
     * Test for <code>CertPathValidatorSpi</code> constructor Assertion:
     * constructs CertPathValidatorSpi
     */
public void testCertPathValidatorSpi01() throws CertPathValidatorException, InvalidAlgorithmParameterException {
    CertPathValidatorSpi certPathValid = new MyCertPathValidatorSpi();
    CertPathParameters params = null;
    CertPath certPath = null;
    CertPathValidatorResult cpvResult = certPathValid.engineValidate(certPath, params);
    assertNull("Not null CertPathValidatorResult", cpvResult);
    try {
        certPathValid.engineValidate(certPath, params);
        fail("CertPathValidatorException must be thrown");
    } catch (CertPathValidatorException e) {
    }
    try {
        certPathValid.engineValidate(certPath, params);
        fail("InvalidAlgorithmParameterException must be thrown");
    } catch (InvalidAlgorithmParameterException e) {
    }
}
Also used : CertPathValidatorException(java.security.cert.CertPathValidatorException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) CertPathParameters(java.security.cert.CertPathParameters) CertPath(java.security.cert.CertPath) CertPathValidatorResult(java.security.cert.CertPathValidatorResult) MyCertPathValidatorSpi(org.apache.harmony.security.tests.support.cert.MyCertPathValidatorSpi) MyCertPathValidatorSpi(org.apache.harmony.security.tests.support.cert.MyCertPathValidatorSpi) CertPathValidatorSpi(java.security.cert.CertPathValidatorSpi)

Example 2 with CertPathParameters

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

the class myCertPathBuilder method testBuild.

// Test passed on RI
@KnownFailure(value = "expired certificate bug 2322662")
public void testBuild() throws Exception {
    TestUtils.initCertPathSSCertChain();
    CertPathParameters params = TestUtils.getCertPathParameters();
    CertPathBuilder builder = TestUtils.getCertPathBuilder();
    try {
        CertPathBuilderResult result = builder.build(params);
        assertNotNull("builder result is null", result);
        CertPath certPath = result.getCertPath();
        assertNotNull("certpath of builder result is null", certPath);
    } catch (InvalidAlgorithmParameterException e) {
        fail("unexpected Exception: " + e);
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) CertPathBuilderResult(java.security.cert.CertPathBuilderResult) CertPathParameters(java.security.cert.CertPathParameters) CertPathBuilder(java.security.cert.CertPathBuilder) CertPath(java.security.cert.CertPath) KnownFailure(dalvik.annotation.KnownFailure)

Example 3 with CertPathParameters

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

the class MyCertPathParameters method test_ConstructorLjava_security_cert_CertPathParameters.

/**
     * javax.net.ssl.CertPathTrustManagerParameters#
     *     CertPathTrustManagerParameters(java.security.cert.CertPathParameters)
     * Case 1: Try to construct object.
     * Case 2: Check NullPointerException.
     */
public void test_ConstructorLjava_security_cert_CertPathParameters() {
    // case 1: Try to construct object.
    try {
        CertPathParameters parameters = new MyCertPathParameters();
        CertPathTrustManagerParameters p = new CertPathTrustManagerParameters(parameters);
        assertNotSame("Parameters were cloned incorrectly", parameters, p.getParameters());
    } catch (Exception e) {
        fail("Unexpected exception " + e.toString());
    }
    // case 2: Check NullPointerException.
    try {
        new CertPathTrustManagerParameters(null);
        fail("Expected CertPathTrustManagerParameters was not thrown");
    } catch (NullPointerException npe) {
    // expected
    }
}
Also used : CertPathTrustManagerParameters(javax.net.ssl.CertPathTrustManagerParameters) CertPathParameters(java.security.cert.CertPathParameters)

Example 4 with CertPathParameters

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

the class MyCertPathParameters method test_getParameters.

/**
     * javax.net.ssl.CertPathTrustManagerParameters#getParameters()
     */
public void test_getParameters() {
    CertPathParameters parameters = new MyCertPathParameters();
    CertPathTrustManagerParameters p = new CertPathTrustManagerParameters(parameters);
    if (!(p.getParameters() instanceof MyCertPathParameters)) {
        fail("incorrect parameters");
    }
    assertNotSame("Parameters were cloned incorrectly", parameters, p.getParameters());
}
Also used : CertPathTrustManagerParameters(javax.net.ssl.CertPathTrustManagerParameters) CertPathParameters(java.security.cert.CertPathParameters)

Example 5 with CertPathParameters

use of java.security.cert.CertPathParameters in project tomcat70 by apache.

the class JSSESocketFactory method getTrustManagers.

/**
 * Gets the initialized trust managers.
 */
protected TrustManager[] getTrustManagers(String keystoreType, String keystoreProvider, String algorithm) throws Exception {
    String crlf = endpoint.getCrlFile();
    String className = endpoint.getTrustManagerClassName();
    if (className != null && className.length() > 0) {
        ClassLoader classLoader = getClass().getClassLoader();
        Class<?> clazz = classLoader.loadClass(className);
        if (!(TrustManager.class.isAssignableFrom(clazz))) {
            throw new InstantiationException(sm.getString("jsse.invalidTrustManagerClassName", className));
        }
        Object trustManagerObject = clazz.newInstance();
        TrustManager trustManager = (TrustManager) trustManagerObject;
        return new TrustManager[] { trustManager };
    }
    TrustManager[] tms = null;
    KeyStore trustStore = getTrustStore(keystoreType, keystoreProvider);
    if (trustStore != null || endpoint.getTrustManagerClassName() != null) {
        if (crlf == null) {
            TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm);
            tmf.init(trustStore);
            tms = tmf.getTrustManagers();
        } else {
            TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm);
            CertPathParameters params = getParameters(algorithm, crlf, trustStore);
            ManagerFactoryParameters mfp = new CertPathTrustManagerParameters(params);
            tmf.init(mfp);
            tms = tmf.getTrustManagers();
        }
    }
    return tms;
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory) CertPathTrustManagerParameters(javax.net.ssl.CertPathTrustManagerParameters) CertPathParameters(java.security.cert.CertPathParameters) KeyStore(java.security.KeyStore) ManagerFactoryParameters(javax.net.ssl.ManagerFactoryParameters) TrustManager(javax.net.ssl.TrustManager)

Aggregations

CertPathParameters (java.security.cert.CertPathParameters)14 CertPathTrustManagerParameters (javax.net.ssl.CertPathTrustManagerParameters)6 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)4 KeyStore (java.security.KeyStore)4 CRLException (java.security.cert.CRLException)4 ManagerFactoryParameters (javax.net.ssl.ManagerFactoryParameters)4 TrustManager (javax.net.ssl.TrustManager)4 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)4 CertPathBuilderResult (java.security.cert.CertPathBuilderResult)3 IOException (java.io.IOException)2 CertPath (java.security.cert.CertPath)2 CertPathBuilderException (java.security.cert.CertPathBuilderException)2 CertPathBuilderSpi (java.security.cert.CertPathBuilderSpi)2 CertPathValidator (java.security.cert.CertPathValidator)2 CertPathValidatorException (java.security.cert.CertPathValidatorException)2 CertStore (java.security.cert.CertStore)2 CertStoreParameters (java.security.cert.CertStoreParameters)2 CertificateException (java.security.cert.CertificateException)2 CollectionCertStoreParameters (java.security.cert.CollectionCertStoreParameters)2 PKIXBuilderParameters (java.security.cert.PKIXBuilderParameters)2