use of java.security.cert.CollectionCertStoreParameters in project tomcat70 by apache.
the class JSSESocketFactory 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 = null;
if ("PKIX".equalsIgnoreCase(algorithm)) {
PKIXBuilderParameters xparams = new PKIXBuilderParameters(trustStore, new X509CertSelector());
Collection<? extends CRL> crls = getCRLs(crlf);
CertStoreParameters csp = new CollectionCertStoreParameters(crls);
CertStore store = CertStore.getInstance("Collection", csp);
xparams.addCertStore(store);
xparams.setRevocationEnabled(true);
String trustLength = endpoint.getTrustMaxCertLength();
if (trustLength != null) {
try {
xparams.setMaxPathLength(Integer.parseInt(trustLength));
} catch (Exception ex) {
log.warn("Bad maxCertLength: " + trustLength);
}
}
params = xparams;
} else {
throw new CRLException("CRLs not supported for type: " + algorithm);
}
return params;
}
use of java.security.cert.CollectionCertStoreParameters in project testcases by coheigea.
the class SignatureCRLUnitTest method testCRLRevocation.
@org.junit.Test
public void testCRLRevocation() throws Exception {
System.setProperty("java.security.debug", "all");
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
// Signing Cert
InputStream certInputStream = loadInputStream(this.getClass().getClassLoader(), "keys/wss40rev.jks");
assertNotNull(certInputStream);
KeyStore certKeyStore = KeyStore.getInstance("JKS");
certKeyStore.load(certInputStream, "security".toCharArray());
Certificate[] certs = certKeyStore.getCertificateChain("wss40rev");
assertNotNull(certs);
assertEquals(certs.length, 2);
// List<Certificate> certList = Arrays.asList(certs[0]); // WORKS
// DOESN'T WORK!
List<Certificate> certList = Arrays.asList(certs);
CertPath path = certificateFactory.generateCertPath(certList);
// CA cert
InputStream caInputStream = loadInputStream(this.getClass().getClassLoader(), "keys/wss40CA.jks");
assertNotNull(caInputStream);
KeyStore caKeyStore = KeyStore.getInstance("JKS");
caKeyStore.load(caInputStream, "security".toCharArray());
X509Certificate caCert = (X509Certificate) caKeyStore.getCertificate("wss40CA");
assertNotNull(caCert);
Set<TrustAnchor> set = new HashSet<TrustAnchor>();
TrustAnchor anchor = new TrustAnchor(caCert, null);
set.add(anchor);
// Load CRL
InputStream crlInputStream = loadInputStream(this.getClass().getClassLoader(), "keys/wss40CACRL.pem");
assertNotNull(crlInputStream);
X509CRL crl = (X509CRL) certificateFactory.generateCRL(crlInputStream);
crlInputStream.close();
assertNotNull(crl);
// Construct PKIXParameters
PKIXParameters param = new PKIXParameters(set);
param.setRevocationEnabled(true);
param.addCertStore(CertStore.getInstance("Collection", new CollectionCertStoreParameters(Collections.singletonList(crl))));
// Validate the Cert Path
CertPathValidator validator = CertPathValidator.getInstance("PKIX");
try {
validator.validate(path, param);
fail("Failure expected on a revoked certificate");
} catch (CertPathValidatorException ex) {
assertTrue(ex.getMessage().contains("revoked") || ex.getMessage().contains("revocation"));
}
}
use of java.security.cert.CollectionCertStoreParameters in project j2objc by google.
the class CollectionCertStoreParametersTest method testCollectionCertStoreParametersCollection03.
/**
* Test #3 for <code>CollectionCertStoreParameters(Collection)</code>
* constructor<br>
*/
public final void testCollectionCertStoreParametersCollection03() {
Vector<Certificate> certificates = new Vector<Certificate>();
// create using empty collection
CollectionCertStoreParameters cp = new CollectionCertStoreParameters(certificates);
// check that the reference is used
assertTrue("isRefUsed_1", certificates == cp.getCollection());
// check that collection still empty
assertTrue("isEmpty", cp.getCollection().isEmpty());
// modify our collection
certificates.add(new MyCertificate("TEST", new byte[] { (byte) 1 }));
certificates.add(new MyCertificate("TEST", new byte[] { (byte) 2 }));
// check that internal state has been changed accordingly
assertTrue("isRefUsed_2", certificates.equals(cp.getCollection()));
}
use of java.security.cert.CollectionCertStoreParameters in project j2objc by google.
the class CollectionCertStoreParametersTest method testClone03.
/**
* Test #3 for <code>clone()</code> method<br>
*/
public final void testClone03() {
CollectionCertStoreParameters cp1 = new CollectionCertStoreParameters();
CollectionCertStoreParameters cp2 = (CollectionCertStoreParameters) cp1.clone();
CollectionCertStoreParameters cp3 = (CollectionCertStoreParameters) cp2.clone();
// check that all objects hold the same reference
assertTrue(cp1.getCollection() == cp2.getCollection() && cp3.getCollection() == cp2.getCollection());
}
use of java.security.cert.CollectionCertStoreParameters in project j2objc by google.
the class CollectionCertStoreParametersTest method testToString01.
/**
* Test #1 for <code>toString()</code> method<br>
*/
public final void testToString01() {
CollectionCertStoreParameters cp = new CollectionCertStoreParameters();
String s = cp.toString();
assertNotNull(s);
}
Aggregations