Search in sources :

Example 6 with CertPathParameters

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

the class JSSE14SocketFactory method getTrustManagers.

/**
 * Gets the initialized trust managers.
 */
protected TrustManager[] getTrustManagers(String algorithm) throws Exception {
    String crlFile = (String) attributes.get("crlFile");
    TrustManager[] tms = null;
    KeyStore[] trustStores = getTrustStore();
    if (trustStores != null) {
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm);
        if (crlFile == null) {
            for (KeyStore trustStore : trustStores) {
                tmf.init(trustStore);
            }
        } else {
            for (KeyStore trustStore : trustStores) {
                CertPathParameters params = getParameters(algorithm, crlFile, 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)

Example 7 with CertPathParameters

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

the class JSSEUtil method getTrustManagers.

@Override
public TrustManager[] getTrustManagers() throws Exception {
    String className = sslHostConfig.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 = sslHostConfig.getTruststore();
    if (trustStore != null) {
        checkTrustStoreEntries(trustStore);
        String algorithm = sslHostConfig.getTruststoreAlgorithm();
        String crlf = sslHostConfig.getCertificateRevocationListFile();
        boolean revocationEnabled = sslHostConfig.getRevocationEnabled();
        if ("PKIX".equalsIgnoreCase(algorithm)) {
            TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm);
            CertPathParameters params = getParameters(crlf, trustStore, revocationEnabled);
            ManagerFactoryParameters mfp = new CertPathTrustManagerParameters(params);
            tmf.init(mfp);
            tms = tmf.getTrustManagers();
        } else {
            TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm);
            tmf.init(trustStore);
            tms = tmf.getTrustManagers();
            if (crlf != null && crlf.length() > 0) {
                throw new CRLException(sm.getString("jsseUtil.noCrlSupport", algorithm));
            }
            log.warn(sm.getString("jsseUtil.noVerificationDepth", algorithm));
        }
    }
    return tms;
}
Also used : CertPathTrustManagerParameters(javax.net.ssl.CertPathTrustManagerParameters) CertPathParameters(java.security.cert.CertPathParameters) KeyStore(java.security.KeyStore) TrustManager(javax.net.ssl.TrustManager) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) CRLException(java.security.cert.CRLException) ManagerFactoryParameters(javax.net.ssl.ManagerFactoryParameters)

Example 8 with CertPathParameters

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

the class CertPathValidator2Test method testValidate.

public void testValidate() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException {
    MyCertPath mCP = new MyCertPath(new byte[0]);
    CertPathParameters params = new PKIXParameters(TestUtils.getTrustAnchorSet());
    CertPathValidator certPV = CertPathValidator.getInstance(defaultAlg);
    try {
        certPV.validate(mCP, params);
    } catch (InvalidAlgorithmParameterException e) {
        fail("unexpected exception: " + e);
    } catch (CertPathValidatorException e) {
        fail("unexpected exception: " + e);
    }
    try {
        certPV.validate(null, params);
        fail("NullPointerException must be thrown");
    } catch (InvalidAlgorithmParameterException e) {
        fail("unexpected exception: " + e);
    } catch (CertPathValidatorException e) {
    // ok
    }
    try {
        certPV.validate(mCP, null);
        fail("InvalidAlgorithmParameterException must be thrown");
    } catch (InvalidAlgorithmParameterException e) {
    // ok
    } catch (CertPathValidatorException e) {
        fail("unexpected exception");
    }
}
Also used : MyCertPath(org.apache.harmony.security.tests.support.cert.MyCertPath) CertPathValidator(java.security.cert.CertPathValidator) CertPathValidatorException(java.security.cert.CertPathValidatorException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) PKIXParameters(java.security.cert.PKIXParameters) CertPathParameters(java.security.cert.CertPathParameters)

Example 9 with CertPathParameters

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

the class CertPathValidator3Test method testValidate01.

/**
     * Test for <code>validate(CertPath certpath, CertPathParameters params)</code> method
     * Assertion: throws InvalidAlgorithmParameterException
     * when params is instance of PKIXParameters and
     * certpath is not X.509 type
     *
     */
public void testValidate01() throws InvalidAlgorithmParameterException, CertPathValidatorException {
    if (!PKIXSupport) {
        fail(NotSupportMsg);
        return;
    }
    MyCertPath mCP = new MyCertPath(new byte[0]);
    CertPathParameters params = new PKIXParameters(TestUtils.getTrustAnchorSet());
    CertPathValidator[] certPV = createCPVs();
    assertNotNull("CertPathValidator objects were not created", certPV);
    for (int i = 0; i < certPV.length; i++) {
        try {
            certPV[i].validate(mCP, null);
            fail("InvalidAlgorithmParameterException must be thrown");
        } catch (InvalidAlgorithmParameterException e) {
        }
        try {
            certPV[i].validate(null, params);
            fail("NullPointerException must be thrown");
        } catch (NullPointerException e) {
        }
    }
}
Also used : MyCertPath(org.apache.harmony.security.tests.support.cert.MyCertPath) CertPathValidator(java.security.cert.CertPathValidator) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) PKIXParameters(java.security.cert.PKIXParameters) CertPathParameters(java.security.cert.CertPathParameters)

Example 10 with CertPathParameters

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

the class CertPathBuilderSpiTest method testCertPathBuilderSpi01.

/**
     * Test for <code>CertPathBuilderSpi</code> constructor Assertion:
     * constructs CertPathBuilderSpi
     */
public void testCertPathBuilderSpi01() throws CertPathBuilderException, InvalidAlgorithmParameterException {
    CertPathBuilderSpi certPathBuilder = new MyCertPathBuilderSpi();
    CertPathParameters cpp = null;
    try {
        certPathBuilder.engineBuild(cpp);
        fail("CertPathBuilderException must be thrown");
    } catch (CertPathBuilderException e) {
    }
    CertPathBuilderResult cpbResult = certPathBuilder.engineBuild(cpp);
    assertNull("Not null CertPathBuilderResult", cpbResult);
}
Also used : MyCertPathBuilderSpi(org.apache.harmony.security.tests.support.cert.MyCertPathBuilderSpi) CertPathBuilderSpi(java.security.cert.CertPathBuilderSpi) MyCertPathBuilderSpi(org.apache.harmony.security.tests.support.cert.MyCertPathBuilderSpi) CertPathBuilderException(java.security.cert.CertPathBuilderException) CertPathBuilderResult(java.security.cert.CertPathBuilderResult) CertPathParameters(java.security.cert.CertPathParameters)

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