public final class SNIHostName extends SNIServerName
host_name in a Server Name
Indication (SNI) extension.
As described in section 3, "Server Name Indication", of TLS Extensions (RFC 6066), "HostName" contains the fully qualified DNS hostname of the server, as understood by the client. The encoded server name value of a hostname is represented as a byte string using ASCII encoding without a trailing dot. This allows the support of Internationalized Domain Names (IDN) through the use of A-labels (the ASCII-Compatible Encoding (ACE) form of a valid string of Internationalized Domain Names for Applications (IDNA)) defined in RFC 5890.
Note that SNIHostName objects are immutable.
- Since:
- 1.8
- See Also:
SNIServerName,StandardConstants.SNI_HOST_NAME
-
Constructor Summary
Constructors Constructor Description SNIHostName(byte[] encoded)Creates anSNIHostNameusing the specified encoded value.SNIHostName(String hostname)Creates anSNIHostNameusing the specified hostname. -
Method Summary
Modifier and Type Method Description static SNIMatchercreateSNIMatcher(String regex)Creates anSNIMatcherobject forSNIHostNames.booleanequals(Object other)Compares this server name to the specified object.StringgetAsciiName()Returns theStandardCharsets.US_ASCII-compliant hostname of thisSNIHostNameobject.inthashCode()Returns a hash code value for thisSNIHostName.StringtoString()Returns a string representation of the object, including the DNS hostname in thisSNIHostNameobject.
-
Constructor Details
-
SNIHostName
Creates anSNIHostNameusing the specified hostname.Note that per RFC 6066, the encoded server name value of a hostname is
StandardCharsets.US_ASCII-compliant. In this method,hostnamecan be a user-friendly Internationalized Domain Name (IDN).IDN.toASCII(String, int)is used to enforce the restrictions on ASCII characters in hostnames (see RFC 3490, RFC 1122, RFC 1123) and translate thehostnameinto ASCII Compatible Encoding (ACE), as:IDN.toASCII(hostname, IDN.USE_STD3_ASCII_RULES);The
hostnameargument is illegal if it:-
hostnameis empty, -
hostnameends with a trailing dot, -
hostnameis not a valid Internationalized Domain Name (IDN) compliant with the RFC 3490 specification.
- Parameters:
hostname- the hostname of this server name- Throws:
NullPointerException- ifhostnameisnullIllegalArgumentException- ifhostnameis illegal
-
-
SNIHostName
public SNIHostName(byte[] encoded)Creates anSNIHostNameusing the specified encoded value.This method is normally used to parse the encoded name value in a requested SNI extension.
Per RFC 6066, the encoded name value of a hostname is
StandardCharsets.US_ASCII-compliant. However, in the previous version of the SNI extension ( RFC 4366), the encoded hostname is represented as a byte string using UTF-8 encoding. For the purpose of version tolerance, this method allows that the charset ofencodedargument can beStandardCharsets.UTF_8, as well asStandardCharsets.US_ASCII.IDN.toASCII(String)is used to translate theencodedargument into ASCII Compatible Encoding (ACE) hostname.It is strongly recommended that this constructor is only used to parse the encoded name value in a requested SNI extension. Otherwise, to comply with RFC 6066, please always use
StandardCharsets.US_ASCII-compliant charset and enforce the restrictions on ASCII characters in hostnames (see RFC 3490, RFC 1122, RFC 1123) forencodedargument, or useSNIHostName(String)instead.The
encodedargument is illegal if it:-
encodedis empty, -
encodedends with a trailing dot, -
encodedis not encoded inStandardCharsets.US_ASCIIorStandardCharsets.UTF_8-compliant charset, -
encodedis not a valid Internationalized Domain Name (IDN) compliant with the RFC 3490 specification.
Note that the
encodedbyte array is cloned to protect against subsequent modification.- Parameters:
encoded- the encoded hostname of this server name- Throws:
NullPointerException- ifencodedisnullIllegalArgumentException- ifencodedis illegal
-
-
-
Method Details
-
getAsciiName
Returns theStandardCharsets.US_ASCII-compliant hostname of thisSNIHostNameobject.Note that, per RFC 6066, the returned hostname may be an internationalized domain name that contains A-labels. See RFC 5890 for more information about the detailed A-label specification.
- Returns:
- the
StandardCharsets.US_ASCII-compliant hostname of thisSNIHostNameobject
-
equals
Compares this server name to the specified object.Per RFC 6066, DNS hostnames are case-insensitive. Two server hostnames are equal if, and only if, they have the same name type, and the hostnames are equal in a case-independent comparison.
- Overrides:
equalsin classSNIServerName- Parameters:
other- the other server name object to compare with.- Returns:
- true if, and only if, the
otheris considered equal to this instance - See Also:
Object.hashCode(),HashMap
-
hashCode
public int hashCode()Returns a hash code value for thisSNIHostName.The hash code value is generated using the case-insensitive hostname of this
SNIHostName.- Overrides:
hashCodein classSNIServerName- Returns:
- a hash code value for this
SNIHostName. - See Also:
Object.equals(java.lang.Object),System.identityHashCode(java.lang.Object)
-
toString
Returns a string representation of the object, including the DNS hostname in thisSNIHostNameobject.The exact details of the representation are unspecified and subject to change, but the following may be regarded as typical:
"type=host_name (0), value=<hostname>"The "<hostname>" is an ASCII representation of the hostname, which may contains A-labels. For example, a returned value of an pseudo hostname may look like:"type=host_name (0), value=www.example.com"or"type=host_name (0), value=xn--fsqu00a.xn--0zwm56d"Please NOTE that the exact details of the representation are unspecified and subject to change.
- Overrides:
toStringin classSNIServerName- Returns:
- a string representation of the object.
-
createSNIMatcher
Creates anSNIMatcherobject forSNIHostNames.This method can be used by a server to verify the acceptable
SNIHostNames. For example,SNIMatcher matcher = SNIHostName.createSNIMatcher("www\\.example\\.com");will accept the hostname "www.example.com".SNIMatcher matcher = SNIHostName.createSNIMatcher("www\\.example\\.(com|org)");will accept hostnames "www.example.com" and "www.example.org".- Parameters:
regex- the regular expression pattern representing the hostname(s) to match- Returns:
- a
SNIMatcherobject forSNIHostNames - Throws:
NullPointerException- ifregexisnullPatternSyntaxException- if the regular expression's syntax is invalid
-