Certificate validator for X.509 certificates.
[!WARNING]
Please note that this project is not being maintained.A fork is being maintained under https://github.com/felleslosninger/efm-common/tree/development/certvalidator for the purpose of eFormidlings certificate validation.
This validator is not a single validator, it is set of rules to build the certificate validator (using X.509 certificates) fitting the needs of your business case.
A lot of sensible defaults is used to make it easy to get started using this library. Use a proper IDE to customize to your needs.
Include dependency in your pom.xml:
<dependency>
<groupId>no.difi.commons</groupId>
<artifactId>commons-certvalidator</artifactId>
<version>2.1.1</version>
</dependency>
Create your own validator(s):
// Generic validator
Validator validator = ValidatorBuilder.newInstance()
.addRule(new ExpirationRule())
.addRule(new SigningRule())
.addRule(new CRLRule())
.addRule(new OCSPRule())
.build();
// Accept only non-expired self-signed certificates
Validator validator = ValidatorBuilder.newInstance()
.addRule(new ExpirationRule())
.addRule(SigningRule.SelfSignedOnly())
.build();
// Is the certificate expiring in less than 7 days?
Validator validator = ValidatorBuilder.newInstance()
.addRule(new ExpirationSoonRule(7 * 24 * 60 * 60 * 1000))
.build();
// Validate your certificate (throws exception on error)
validator.validate(...);
// Validate your certificate (returns boolean)
validator.isValid(...);
Please note the Validator
accepts InputStream
, byte[]
and X509Certificate
as input for validation.
Validators may not only be used to judge a given certificate when in situation to trust or not to trust a certificate. A validator instance may be used to implement logic helping users to handle certificates in a better manner (ie. give a warning before certificate expires).
All new validation rules must implement the very simple ValidatorRule
interface to be included in a chain of rules.