Package com.unboundid.util.ssl
Class HostNameTrustManager
- java.lang.Object
-
- com.unboundid.util.ssl.HostNameTrustManager
-
- All Implemented Interfaces:
javax.net.ssl.TrustManager
,javax.net.ssl.X509TrustManager
@NotMutable @ThreadSafety(level=COMPLETELY_THREADSAFE) public final class HostNameTrustManager extends java.lang.Object implements javax.net.ssl.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 anAggregateTrustManager
in conjunction with other trust managers that perform other forms of validation.
-
-
Constructor Summary
Constructors Constructor Description HostNameTrustManager(boolean allowWildcards, java.lang.String... acceptableHostNames)
Creates a new hostname trust manager with the provided information.HostNameTrustManager(boolean allowWildcards, java.util.Collection<java.lang.String> acceptableHostNames)
Creates a new hostname trust manager with the provided information.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
allowWildcards()
Indicates whether wildcard certificates should be allowed, which may match multiple hosts in a given domain or subdomain.void
checkClientTrusted(java.security.cert.X509Certificate[] chain, java.lang.String authType)
Checks to determine whether the provided client certificate chain should be trusted.void
checkServerTrusted(java.security.cert.X509Certificate[] chain, java.lang.String authType)
Checks to determine whether the provided server certificate chain should be trusted.java.util.Set<java.lang.String>
getAcceptableHostNames()
Retrieves the set of hostnames that will be considered acceptable.java.security.cert.X509Certificate[]
getAcceptedIssuers()
Retrieves the accepted issuer certificates for this trust manager.
-
-
-
Constructor Detail
-
HostNameTrustManager
public HostNameTrustManager(boolean allowWildcards, java.lang.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 benull
or empty.
-
HostNameTrustManager
public HostNameTrustManager(boolean allowWildcards, java.util.Collection<java.lang.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 benull
or empty.
-
-
Method Detail
-
allowWildcards
public boolean allowWildcards()
Indicates whether wildcard certificates should be allowed, which may match multiple hosts in a given domain or subdomain.- Returns:
true
if wildcard certificates should be allowed, orfalse
if not.
-
getAcceptableHostNames
public java.util.Set<java.lang.String> getAcceptableHostNames()
Retrieves the set of hostnames that will be considered acceptable.- Returns:
- The set of hostnames that will be considered acceptable.
-
checkClientTrusted
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, java.lang.String authType) throws java.security.cert.CertificateException
Checks to determine whether the provided client certificate chain should be trusted.- Specified by:
checkClientTrusted
in interfacejavax.net.ssl.X509TrustManager
- Parameters:
chain
- The client certificate chain for which to make the determination.authType
- The authentication type based on the client certificate.- Throws:
java.security.cert.CertificateException
- If the provided client certificate chain should not be trusted.
-
checkServerTrusted
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, java.lang.String authType) throws java.security.cert.CertificateException
Checks to determine whether the provided server certificate chain should be trusted.- Specified by:
checkServerTrusted
in interfacejavax.net.ssl.X509TrustManager
- Parameters:
chain
- The server certificate chain for which to make the determination.authType
- The key exchange algorithm used.- Throws:
java.security.cert.CertificateException
- If the provided server certificate chain should not be trusted.
-
getAcceptedIssuers
public java.security.cert.X509Certificate[] getAcceptedIssuers()
Retrieves the accepted issuer certificates for this trust manager. This will always return an empty array.- Specified by:
getAcceptedIssuers
in interfacejavax.net.ssl.X509TrustManager
- Returns:
- The accepted issuer certificates for this trust manager.
-
-