Created
October 24, 2016 13:50
-
-
Save venator85/c677ebcd93ef4c339331314608acde25 to your computer and use it in GitHub Desktop.
Manually verify a certificate (chain) against a root
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void validateCertificate(X509Certificate toVerify, X509Certificate root) throws Exception { | |
CertificateFactory cf = CertificateFactory.getInstance("X.509"); | |
CertPath cp = cf.generateCertPath(Collections.singletonList(toVerify)); | |
TrustAnchor trustAnchor = new TrustAnchor(root, null); | |
CertPathValidator cpv = CertPathValidator.getInstance("PKIX"); | |
PKIXParameters pkixParams = new PKIXParameters(Collections.singleton(trustAnchor)); | |
pkixParams.setRevocationEnabled(false); | |
cpv.validate(cp, pkixParams); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment