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;
}
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;
}
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");
}
}
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) {
}
}
}
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);
}
Aggregations