Class HostNameTrustManager

java.lang.Object
com.unboundid.util.ssl.HostNameTrustManager
All Implemented Interfaces:
TrustManager, X509TrustManager

This class provides an SSL trust manager that will only accept certificates whose hostname (as contained in the CN subject attribute or a subjectAltName extension) matches an expected value. Only the dNSName, iPAddress, and uniformResourceIdentifier subjectAltName formats are supported.

This implementation optionally supports wildcard certificates, which have a hostname that starts with an asterisk followed by a period and domain or subdomain. For example, "*.example.com" could be considered a match for anything in the "example.com" domain. If wildcards are allowed, then only the CN subject attribute and dNSName subjectAltName extension will be examined, and only the leftmost element of a hostname may be a wildcard character.

Note that no other elements of the certificate are examined, so it is strongly recommended that this trust manager be used in an AggregateTrustManager in conjunction with other trust managers that perform other forms of validation.
  • Constructor Details

    • HostNameTrustManager

      public HostNameTrustManager(boolean allowWildcards, @NotNull String... acceptableHostNames)
      Creates a new hostname trust manager with the provided information.
      Parameters:
      allowWildcards - Indicates whether to allow wildcard certificates which contain an asterisk as the first component of a CN subject attribute or dNSName subjectAltName extension.
      acceptableHostNames - The set of hostnames and/or IP addresses that will be considered acceptable. Only certificates with a CN or subjectAltName value that exactly matches one of these names (ignoring differences in capitalization) will be considered acceptable. It must not be null or empty.
    • HostNameTrustManager

      public HostNameTrustManager(boolean allowWildcards, @NotNull Collection<String> acceptableHostNames)
      Creates a new hostname trust manager with the provided information.
      Parameters:
      allowWildcards - Indicates whether to allow wildcard certificates which contain an asterisk as the first component of a CN subject attribute or dNSName subjectAltName extension.
      acceptableHostNames - The set of hostnames and/or IP addresses that will be considered acceptable. Only certificates with a CN or subjectAltName value that exactly matches one of these names (ignoring differences in capitalization) will be considered acceptable. It must not be null or empty.
    • HostNameTrustManager

      public HostNameTrustManager(boolean allowWildcards, boolean checkCNWhenSubjectAltNameIsPresent, @NotNull Collection<String> acceptableHostNames)
      Creates a new hostname trust manager with the provided information.
      Parameters:
      allowWildcards - Indicates whether to allow wildcard certificates that contain an asterisk in the leftmost component of a hostname in the dNSName or uniformResourceIdentifier of the subject alternative name extension, or in the CN attribute of the subject DN.
      checkCNWhenSubjectAltNameIsPresent - Indicates whether to check the CN attribute in the peer certificate's subject DN if the certificate also contains a subject alternative name extension that contains at least one dNSName, uniformResourceIdentifier, or iPAddress value. Although RFC 6125 section 6.4.4 indicates that the CN attribute should not be checked in certificates that have an appropriate subject alternative name extension, LDAP clients historically treat both sources as equally valid.
      acceptableHostNames - The set of hostnames and/or IP addresses that will be considered acceptable. Only certificates with a CN or subjectAltName value that exactly matches one of these names (ignoring differences in capitalization) will be considered acceptable. It must not be null or empty.
  • Method Details