Class CertificateValidator
java.lang.Object
com.codename1.backend.security.pki.CertificateValidator
Validates a certificate chain against trust anchors the application names.
CertificateValidator validator = new CertificateValidator(
Certificate.listFromPem(KeyFiles.read("/etc/app/partner-ca.pem")))
.forHost("partner.example.com");
List<Certificate> path = validator.validate(Certificate.listFromPem(presented));
There is no default trust store: nothing is trusted unless it is given. A path is built from the first certificate, the leaf, through the other certificates given (in any order) to one of the anchors, and every link is checked:
- each certificate is signed by the next, within the signature profile of
Certificate.getSignatureAlgorithm(); - each certificate, the leaf and the intermediates, is inside its validity period at the validation time;
- each issuer below the anchor is a CA by its basic constraints, has
keyCertSignwhen it carries a key usage, and its path length is not exceeded; - no certificate carries a critical extension this validator does not understand (name constraints and certificate policies among them);
- when
forHost(String)orforPurpose(String)is set, the leaf matches.
An anchor is trusted as given: its signature, validity and constraints are not checked, as RFC 5280 treats an anchor as a name and a key. Revocation (CRL, OCSP) is not checked.
-
Constructor Summary
ConstructorsConstructorDescriptionCertificateValidator(List<Certificate> anchors) A validator that trustsanchorsand nothing else. -
Method Summary
Modifier and TypeMethodDescriptionat(long millis) Validates atmillisinstead of the current time.Requires the leaf to be forhost, byCertificate.matchesHost(String), and to allowCertificate.SERVER_AUTHwhen it restricts its purposes.forPurpose(String extendedKeyUsage) Requires the leaf to allow an extended key usage, such asCertificate.CLIENT_AUTHfor a client certificate.validate(List<Certificate> chain) Validateschain, the leaf first.
-
Constructor Details
-
CertificateValidator
A validator that trustsanchorsand nothing else.
-
-
Method Details
-
at
Validates atmillisinstead of the current time. -
forHost
Requires the leaf to be forhost, byCertificate.matchesHost(String), and to allowCertificate.SERVER_AUTHwhen it restricts its purposes. -
forPurpose
Requires the leaf to allow an extended key usage, such asCertificate.CLIENT_AUTHfor a client certificate. A leaf with no extended key usage extension allows every purpose. -
validate
Validateschain, the leaf first.- Returns:
- the path from the leaf to the anchor, both included
- Throws:
CertificateException- naming the certificate that failed and whyIOException
-