Search in sources :

Example 26 with CertPathValidator

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());
    }
}
Also used : CertPathValidator(java.security.cert.CertPathValidator) PKIXParameters(java.security.cert.PKIXParameters) PKIXCertPathValidatorResult(java.security.cert.PKIXCertPathValidatorResult) ArrayList(java.util.ArrayList) CertPath(java.security.cert.CertPath) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate)

Aggregations

CertPathValidator (java.security.cert.CertPathValidator)26 CertPath (java.security.cert.CertPath)9 X509Certificate (java.security.cert.X509Certificate)8 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)7 PKIXCertPathValidatorResult (java.security.cert.PKIXCertPathValidatorResult)7 CertPathValidatorException (java.security.cert.CertPathValidatorException)6 CertPathValidatorResult (java.security.cert.CertPathValidatorResult)6 CertificateFactory (java.security.cert.CertificateFactory)6 PKIXParameters (java.security.cert.PKIXParameters)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 CertPathBuilderException (java.security.cert.CertPathBuilderException)5 NoSuchProviderException (java.security.NoSuchProviderException)4 CertPathBuilder (java.security.cert.CertPathBuilder)4 PKIXBuilderParameters (java.security.cert.PKIXBuilderParameters)4 X509CertSelector (java.security.cert.X509CertSelector)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 CertPathBuilderResult (java.security.cert.CertPathBuilderResult)3 CertificateParsingException (java.security.cert.CertificateParsingException)3 CollectionCertStoreParameters (java.security.cert.CollectionCertStoreParameters)3