Class DefaultCertificateChainValidator
- All Implemented Interfaces:
CertificateChainValidator
The trusted CAs are provided at construction time. They can be loaded from any source (for example a KeyStore
or a secure storage) and passed to DefaultCertificateChainValidator(X509Certificate[]), or loaded from an
Application resource file with the fromResource() factory.
A chain root is trusted when it has been signed by one of the trusted CAs. A self-signed root (its signature verifies with its own public key) is its own trust anchor and is trusted only when it is byte-identical to one of the trusted certificates.
- Since:
- 1.0.0
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs a validator with no trusted CA.DefaultCertificateChainValidator(X509Certificate[] trustedCAs) Constructs a validator that anchors trust to the given trusted CAs. -
Method Summary
Modifier and TypeMethodDescriptionCreates a validator whose trusted CAs are loaded from the Application resource file identified by the "appverifier.trustedCAs.path" BON constant (default/trustedCAs.der).protected static booleanisSignedBy(Certificate certificate, PublicKey publicKey) Tells whether the given certificate has been signed by the given public key.booleanvalidateCertificate(Certificate previousCert, Certificate cert, boolean isLast, boolean isAlreadyAuthorized) Asks this validator to check the given certificate, in the context of a certificate chain.protected booleanvalidateRoot(X509Certificate x509cert) Validates the root of the certificate chain against this validator's trust anchor and decides whether the chain is authorized.
-
Constructor Details
-
DefaultCertificateChainValidator
Constructs a validator that anchors trust to the given trusted CAs.- Parameters:
trustedCAs- the trusted CA certificates, in no particular order.
-
DefaultCertificateChainValidator
protected DefaultCertificateChainValidator()Constructs a validator with no trusted CA. This constructor is reserved for subclasses that fully overridevalidateRoot(X509Certificate)to anchor trust differently.
-
-
Method Details
-
fromResource
Creates a validator whose trusted CAs are loaded from the Application resource file identified by the "appverifier.trustedCAs.path" BON constant (default/trustedCAs.der). The file contains the trusted CA certificates concatenated one after another, in no particular order.- Returns:
- a validator anchored to the trusted CAs read from the resource file.
- Throws:
CertificateException- if the resource file is missing or contains no certificate.- Since:
- 1.0.0
-
validateCertificate
public boolean validateCertificate(Certificate previousCert, Certificate cert, boolean isLast, boolean isAlreadyAuthorized) throws CertificateException Description copied from interface:CertificateChainValidatorAsks this validator to check the given certificate, in the context of a certificate chain.For the first certificate in the chain (i.e. when
previousCertisnull), the validator will typically lookup for a Trust Anchor (known certificate that can be trusted) matching the issuer X500 DN embedded in the certificate to validate.- Specified by:
validateCertificatein interfaceCertificateChainValidator- Parameters:
previousCert- the previous certificate in the chain, if any, ornull.cert- the certificate to validate.isLast-trueif this is the last certificate to validate in the chain.isAlreadyAuthorized-trueif a previous certificate in the chain was already authorized.- Returns:
- a boolean indicating if the subject of this certificate is trusted enough to authorize the Application.
Returning
truemeans that this subject is authorized and that the rest of the chain will be checked for validity only, not for authorization. - Throws:
CertificateException- if there was a technical problem validating this certificate. Check the cause to know more about the actual issue.
-
validateRoot
Validates the root of the certificate chain against this validator's trust anchor and decides whether the chain is authorized.This implementation anchors trust to the trusted CAs of this validator: the given root is trusted when it has been signed by one of the trusted CAs, or - for a self-signed root - when it is byte-identical to one of them.
This method is the extension point of this validator. Subclasses may override it to anchor trust differently without altering the certificate-chaining logic of
validateCertificate(Certificate, Certificate, boolean, boolean). UseisSignedBy(Certificate, PublicKey)to perform signature checks from such an override.- Parameters:
x509cert- the root certificate of the chain to validate.- Returns:
trueif the chain is authorized once the root has been validated.- Throws:
CertificateException- if the given root is not anchored to a trusted certificate, or if no trusted certificates are available.- Since:
- 1.0.0
-
isSignedBy
Tells whether the given certificate has been signed by the given public key.This signature primitive is exposed to subclasses so that an alternative trust anchor can be implemented in
validateRoot(X509Certificate)without access to the package-private signature helpers of this library.- Parameters:
certificate- the certificate whose signature is checked.publicKey- the public key expected to have signed the given certificate.- Returns:
trueif the given certificate has been signed by the given public key.- Since:
- 1.0.0
-