public class HostnameChecker extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
private static int |
ALTNAME_DNS |
private static int |
ALTNAME_IP |
private byte |
checkType |
private static HostnameChecker |
INSTANCE_LDAP |
private static HostnameChecker |
INSTANCE_TLS |
static byte |
TYPE_LDAP |
static byte |
TYPE_TLS |
| 限定符 | 构造器和说明 |
|---|---|
private |
HostnameChecker(byte checkType) |
| 限定符和类型 | 方法和说明 |
|---|---|
static HostnameChecker |
getInstance(byte checkType)
Get a HostnameChecker instance. checkType should be one of the
TYPE_* constants defined in this class.
|
static String |
getServerName(Principal principal)
Return the Server name from Kerberos principal.
|
static sun.security.x509.X500Name |
getSubjectX500Name(X509Certificate cert)
Return the subject of a certificate as X500Name, by reparsing if
necessary.
|
private static boolean |
hasIllegalWildcard(String domain,
String template,
boolean chainsToPublicCA)
Returns true if the template contains an illegal wildcard character.
|
private static boolean |
isIpAddress(String name)
Test whether the given hostname looks like a literal IPv4 or IPv6
address.
|
private boolean |
isMatched(String name,
String template,
boolean chainsToPublicCA)
Returns true if name matches against template.
|
static boolean |
match(String expectedName,
Principal principal)
Perform the check for Kerberos.
|
void |
match(String expectedName,
X509Certificate cert) |
void |
match(String expectedName,
X509Certificate cert,
boolean chainsToPublicCA)
Perform the check.
|
private static boolean |
matchAllWildcards(String name,
String template)
Returns true if name matches against template.
|
private void |
matchDNS(String expectedName,
X509Certificate cert,
boolean chainsToPublicCA)
Check if the certificate allows use of the given DNS name.
|
private static void |
matchIP(String expectedIP,
X509Certificate cert)
Check if the certificate allows use of the given IP address.
|
private static boolean |
matchLeftmostWildcard(String name,
String template)
Returns true if name matches against template.
|
private static boolean |
matchWildCards(String name,
String template)
Returns true if the name matches against the template that may
contain wildcard char *
|
public static final byte TYPE_TLS
private static final HostnameChecker INSTANCE_TLS
public static final byte TYPE_LDAP
private static final HostnameChecker INSTANCE_LDAP
private static final int ALTNAME_DNS
private static final int ALTNAME_IP
private final byte checkType
public static HostnameChecker getInstance(byte checkType)
public void match(String expectedName, X509Certificate cert, boolean chainsToPublicCA) throws CertificateException
expectedName - the expected host name or ip addresscert - the certificate to check againstchainsToPublicCA - true if the certificate chains to a public
root CA (as pre-installed in the cacerts file)CertificateException - if the name does not match any of
the names specified in the certificatepublic void match(String expectedName, X509Certificate cert) throws CertificateException
public static boolean match(String expectedName, Principal principal)
public static String getServerName(Principal principal)
private static boolean isIpAddress(String name)
private static void matchIP(String expectedIP, X509Certificate cert) throws CertificateException
private void matchDNS(String expectedName, X509Certificate cert, boolean chainsToPublicCA) throws CertificateException
public static sun.security.x509.X500Name getSubjectX500Name(X509Certificate cert) throws CertificateParsingException
private boolean isMatched(String name, String template, boolean chainsToPublicCA)
The matching is performed as per RFC 2818 rules for TLS and RFC 2830 rules for LDAP.
The name parameter should represent a DNS name. The
template parameter may contain the wildcard character '*'.
private static boolean hasIllegalWildcard(String domain, String template, boolean chainsToPublicCA)
private static boolean matchAllWildcards(String name, String template)
According to RFC 2818, section 3.1 - Names may contain the wildcard character * which is considered to match any single domain name component or component fragment. E.g., *.a.com matches foo.a.com but not bar.foo.a.com. f*.com matches foo.com but not bar.com.
private static boolean matchLeftmostWildcard(String name, String template)
As per RFC 2830, section 3.6 - The "*" wildcard character is allowed. If present, it applies only to the left-most name component. E.g. *.bar.com would match a.bar.com, b.bar.com, etc. but not bar.com.
Copyright © 2023. All rights reserved.