use of java.security.cert.CertPathValidator in project zm-mailbox by Zimbra.
the class CertValidationUtil method validateCertificate.
public static void validateCertificate(X509Certificate cert, boolean revocationCheckEnabled, Set<TrustAnchor> trustedCertsSet) throws CertificateException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, CertPathValidatorException {
cert.checkValidity();
if (revocationCheckEnabled) {
List<X509Certificate> certificates = new ArrayList<X509Certificate>();
certificates.add(cert);
CertificateFactory cf;
CertPath cp;
cf = CertificateFactory.getInstance("X509");
cp = cf.generateCertPath(certificates);
// init PKIX parameters
PKIXParameters params;
params = new PKIXParameters(trustedCertsSet);
params.setRevocationEnabled(revocationCheckEnabled);
// perform validation
CertPathValidator cpv;
cpv = CertPathValidator.getInstance("PKIX");
PKIXCertPathValidatorResult cpv_result = (PKIXCertPathValidatorResult) cpv.validate(cp, params);
ZimbraLog.account.debug("Certificate Validation Result %s", cpv_result.toString());
}
}
Aggregations