Class CertificateValidationUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PKIXCertPathBuilderResultbuildTrustedCertPath(List<X509Certificate> certificateChain, Collection<X509Certificate> trustedCertificates, Collection<X509Certificate> issuerCertificates) Given a possibly partial certificate chain with at least one certificate in it, builds a path to a trust anchor using a collection of trusted and issuer certificates as possible intermediate and root CAs, and then ensures that at least one certificate in the resulting path is in the trusted collection.static voidcheckApplicationUri(X509Certificate certificate, String applicationUri) Validate that the application URI matches the SubjectAltName URI in the given certificate.static voidcheckEndEntityExtendedKeyUsage(X509Certificate certificate, boolean endEntityIsClient) static voidcheckEndEntityKeyUsage(X509Certificate certificate) static voidcheckHostnameOrIpAddress(X509Certificate certificate, String... hostNames) Validate that one ofhostNamesmatches a SubjectAltName DNSName or IPAddress entry in the certificate.static voidcheckValidity(X509Certificate certificate, boolean endEntity) Check thatcertificateis valid (the current date and time are within the validity period).static StringgetSubjectAltNameUri(X509Certificate certificate) static voidvalidateTrustedCertPath(CertPath certPath, TrustAnchor trustAnchor, Collection<X509CRL> crls, Set<ValidationCheck> validationChecks, boolean endEntityIsClient) Validates the trusted certificate path represented by aTrustAnchorand aCertPaththat may or may not be empty, depending on the length of the path.
-
Constructor Details
-
CertificateValidationUtil
public CertificateValidationUtil()
-
-
Method Details
-
buildTrustedCertPath
public static PKIXCertPathBuilderResult buildTrustedCertPath(List<X509Certificate> certificateChain, Collection<X509Certificate> trustedCertificates, Collection<X509Certificate> issuerCertificates) throws UaException Given a possibly partial certificate chain with at least one certificate in it, builds a path to a trust anchor using a collection of trusted and issuer certificates as possible intermediate and root CAs, and then ensures that at least one certificate in the resulting path is in the trusted collection.Each certificate has its signature and subject/issuer chaining checked. Revocation and other more detailed checks are not done at this stage.
The
CertPathandTrustAnchorfrom the result is meant to be further validated byvalidateTrustedCertPath(CertPath, TrustAnchor, Collection, Set, boolean), which can return more detailed failureStatusCodesin its exceptions because it is dealing with a known trusted path.- Parameters:
certificateChain- a possibly partial certificate chain to build a trusted path from.trustedCertificates- a collection of known trusted certificates.issuerCertificates- a collection of known CAs that can be used in path building but are not considered "trusted" when it comes to determining if the resulting path is "trusted".- Returns:
- a
PKIXCertPathBuilderResultwith aTrustAnchorandCertPath, which combined make up the full trusted path. - Throws:
UaException- if a trusted path cannot be built.
-
validateTrustedCertPath
public static void validateTrustedCertPath(CertPath certPath, TrustAnchor trustAnchor, Collection<X509CRL> crls, Set<ValidationCheck> validationChecks, boolean endEntityIsClient) throws UaException Validates the trusted certificate path represented by aTrustAnchorand aCertPaththat may or may not be empty, depending on the length of the path.Each certificate is checked for validity, key usage, and revocation status. Whether a failed check ultimately results in a thrown exception depends on the set of
ValidationChecks.The function is meant to be used in conjunction with
buildTrustedCertPath(List, Collection, Collection), the result of which contains aCertPathandTrustAnchorthat form a trusted certificate path.- Parameters:
certPath- aCertPathcontaining 0 or more certificates leading to the trust anchor.trustAnchor- aTrustAnchorcontaining the root of trust for the path being validated.crls- a collection ofX509CRLs. Every CA certificate in the trusted path except the leaf should have a CRL, though whether that's enforced or not depends onValidationCheck.REVOCATION_LISTSbeing present.validationChecks- the set ofValidationChecks to enforce.endEntityIsClient-trueif the end-entity is a client,falseif it is a server.- Throws:
UaException- if a check from the set ofValidationChecks failed.
-
checkValidity
Check thatcertificateis valid (the current date and time are within the validity period).- Parameters:
certificate- theX509Certificateto check.endEntity-trueif the certificate is the end entity,falseif it's an issuer.- Throws:
UaException- if the certificate is not valid.
-
checkHostnameOrIpAddress
public static void checkHostnameOrIpAddress(X509Certificate certificate, String... hostNames) throws UaException Validate that one ofhostNamesmatches a SubjectAltName DNSName or IPAddress entry in the certificate.- Parameters:
certificate- the certificate to validate against.hostNames- the host names or ip addresses to look for.- Throws:
UaException- if there is no matching DNSName or IPAddress entry.
-
checkEndEntityKeyUsage
- Throws:
UaException
-
checkEndEntityExtendedKeyUsage
public static void checkEndEntityExtendedKeyUsage(X509Certificate certificate, boolean endEntityIsClient) throws UaException - Throws:
UaException
-
checkApplicationUri
public static void checkApplicationUri(X509Certificate certificate, String applicationUri) throws UaException Validate that the application URI matches the SubjectAltName URI in the given certificate.- Parameters:
certificate- the certificate to validate against.applicationUri- the URI to validate.- Throws:
UaException- if the certificate is invalid, does not contain a uri, or contains a uri that does not match.
-
getSubjectAltNameUri
- Throws:
UaException
-