use of java.security.cert.CollectionCertStoreParameters in project MonjaDB by Kanatoko.
the class MSecurityUtil method isValidChain.
// --------------------------------------------------------------------------------
public static boolean isValidChain(List chain) {
// root, im, leaf�̏��Ԃ�chain�ł��邱�Ƃ�����
if (chain.size() < 2) {
return false;
}
try {
X509Certificate root = null;
X509Certificate leaf = null;
List imList = new ArrayList();
for (int i = 0; i < chain.size(); ++i) {
if (i == 0) {
// root
root = (X509Certificate) chain.get(i);
} else if (i == chain.size() - 1) {
leaf = (X509Certificate) chain.get(i);
} else {
imList.add(chain.get(i));
}
}
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(null, null);
ks.setCertificateEntry("root", root);
X509CertSelector target = new X509CertSelector();
target.setCertificate(leaf);
PKIXBuilderParameters params = new PKIXBuilderParameters(ks, target);
CertStoreParameters intermediates = new CollectionCertStoreParameters(imList);
params.addCertStore(CertStore.getInstance("Collection", intermediates));
params.setRevocationEnabled(false);
CertPathBuilder builder = CertPathBuilder.getInstance("PKIX");
CertPathBuilderResult result = builder.build(params);
return true;
} catch (Exception e) {
return false;
}
}
use of java.security.cert.CollectionCertStoreParameters in project SKMCLauncher by SKCraft.
the class X509KeyStore method verify.
/**
* Verify that a given certificate is trusted.
*
* @param chain certificate chain
* @throws CertPathBuilderException thrown on verification error
* @throws CertificateVerificationException thrown on any error
*/
public void verify(X509Certificate[] chain) throws CertificateVerificationException, CertPathBuilderException {
try {
X509CertSelector selector = new X509CertSelector();
selector.setCertificate(chain[0]);
// Root certificates
Set<TrustAnchor> trustAnchors = new HashSet<TrustAnchor>();
for (X509Certificate rootCert : rootCerts) {
trustAnchors.add(new TrustAnchor(rootCert, null));
}
PKIXBuilderParameters pkixParams = new PKIXBuilderParameters(trustAnchors, selector);
pkixParams.setRevocationEnabled(true);
// Built-in intermediate certificates
pkixParams.addCertStore(CertStore.getInstance("Collection", new CollectionCertStoreParameters(intermediateCerts)));
// Additional intermediate certificates
pkixParams.addCertStore(CertStore.getInstance("Collection", new CollectionCertStoreParameters(Arrays.asList(chain))));
CertPathBuilder builder = CertPathBuilder.getInstance("PKIX");
// Will error on failure to verify
builder.build(pkixParams);
} catch (InvalidAlgorithmParameterException e) {
throw new CertificateVerificationException(e);
} catch (NoSuchAlgorithmException e) {
throw new CertificateVerificationException(e);
}
}
use of java.security.cert.CollectionCertStoreParameters in project j2objc by google.
the class CollectionCertStoreParametersTest method testToString02.
/**
* Test #2 for <code>toString()</code> method<br>
*/
public final void testToString02() {
Vector<Certificate> certificates = new Vector<Certificate>();
certificates.add(new MyCertificate("TEST", new byte[] { (byte) 4 }));
CollectionCertStoreParameters cp = new CollectionCertStoreParameters(certificates);
assertNotNull(cp.toString());
}
use of java.security.cert.CollectionCertStoreParameters in project j2objc by google.
the class CollectionCertStoreParametersTest method testGetCollection01.
/**
* Test #1 for <code>getCollection()</code> method<br>
*/
public final void testGetCollection01() {
CollectionCertStoreParameters cp = new CollectionCertStoreParameters();
assertNotNull(cp.getCollection());
}
use of java.security.cert.CollectionCertStoreParameters in project j2objc by google.
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);
}
Aggregations