APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.net.ssl

public final Class SNIHostName

extends SNIServerName
Class Inheritance
Imports
java.net.IDN, java.nio.ByteBuffer, java.nio.charset.CodingErrorAction, .StandardCharsets, .CharsetDecoder, .CharacterCodingException, java.util.Locale, .Objects, java.util.regex.Pattern, .PatternSyntaxException

Instances of this class represent a server name of type 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
External Specification
https://www.rfc-editor.org/info/rfc5890, https://www.rfc-editor.org/info/rfc6066
See Also
SNIServerName, StandardConstants#SNI_HOST_NAME

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final String

Constructor Summary

AccessConstructor and Description
public
SNIHostName(String
the hostname of this server name
hostname
)

Creates an SNIHostName using the specified hostname.

public
SNIHostName(byte[]
the encoded hostname of this server name
encoded
)

Creates an SNIHostName using the specified encoded value.

Method Summary

Modifier and TypeMethod and Description
private void
public static SNIMatcher

Returns:

a SNIMatcher object for SNIHostNames
createSNIMatcher
(String
the regular expression pattern representing the hostname(s) to match
regex
)

Creates an SNIMatcher object for SNIHostNames.

public boolean

Returns:

true if, and only if, the other is considered equal to this instance
equals
(Object
the other server name object to compare with.
other
)

Overrides javax.net.ssl.SNIServerName.equals.

Compares this server name to the specified object.

public String

Returns:

the StandardCharsets#US_ASCII-compliant hostname of this SNIHostName object
getAsciiName
()

Returns the StandardCharsets#US_ASCII-compliant hostname of this SNIHostName object.

public int

Returns:

a hash code value for this SNIHostName.
hashCode
()

Overrides javax.net.ssl.SNIServerName.hashCode.

Returns a hash code value for this SNIHostName.

public String

Returns:

a string representation of the object.
toString
()

Overrides javax.net.ssl.SNIServerName.toString.

Returns a string representation of the object, including the DNS hostname in this SNIHostName object.

Inherited from javax.net.ssl.SNIServerName:
getEncodedgetType

Field Detail

hostnameback to summary
private final String hostname

Constructor Detail

SNIHostNameback to summary
public SNIHostName(String hostname)

Creates an SNIHostName using the specified hostname.

Note that per RFC 6066, the encoded server name value of a hostname is StandardCharsets#US_ASCII-compliant. In this method, hostname can 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 the hostname into ASCII Compatible Encoding (ACE), as:

    IDN.toASCII(hostname, IDN.USE_STD3_ASCII_RULES);

The hostname argument is illegal if it:

  • hostname is empty,
  • hostname ends with a trailing dot,
  • hostname is not a valid Internationalized Domain Name (IDN) compliant with the RFC 3490 specification.
Parameters
hostname:String

the hostname of this server name

Exceptions
NullPointerException:
if hostname is null
IllegalArgumentException:
if hostname is illegal
External Specification
https://www.rfc-editor.org/info/rfc1122, https://www.rfc-editor.org/info/rfc1123, https://www.rfc-editor.org/info/rfc3490, https://www.rfc-editor.org/info/rfc6066
SNIHostNameback to summary
public SNIHostName(byte[] encoded)

Creates an SNIHostName using 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 of encoded argument can be StandardCharsets#UTF_8, as well as StandardCharsets#US_ASCII. IDN#toASCII(String) is used to translate the encoded argument 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) for encoded argument, or use SNIHostName#SNIHostName(String) instead.

The encoded argument is illegal if it:

  • encoded is empty,
  • encoded ends with a trailing dot,
  • encoded is not encoded in StandardCharsets#US_ASCII or StandardCharsets#UTF_8-compliant charset,
  • encoded is not a valid Internationalized Domain Name (IDN) compliant with the RFC 3490 specification.

Note that the encoded byte array is cloned to protect against subsequent modification.

Parameters
encoded:byte[]

the encoded hostname of this server name

Exceptions
NullPointerException:
if encoded is null
IllegalArgumentException:
if encoded is illegal
External Specification
https://www.rfc-editor.org/info/rfc1122, https://www.rfc-editor.org/info/rfc1123, https://www.rfc-editor.org/info/rfc3490, https://www.rfc-editor.org/info/rfc4366, https://www.rfc-editor.org/info/rfc6066

Method Detail

checkHostNameback to summary
private void checkHostName()
createSNIMatcherback to summary
public static SNIMatcher createSNIMatcher(String regex)

Creates an SNIMatcher object for SNIHostNames.

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:String

the regular expression pattern representing the hostname(s) to match

Returns:SNIMatcher

a SNIMatcher object for SNIHostNames

Exceptions
NullPointerException:
if regex is null
PatternSyntaxException:
if the regular expression's syntax is invalid
equalsback to summary
public boolean equals(Object other)

Overrides javax.net.ssl.SNIServerName.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.

Parameters
other:Object

the other server name object to compare with.

Returns:boolean

true if, and only if, the other is considered equal to this instance

Annotations
@Override
External Specification
https://www.rfc-editor.org/info/rfc6066
getAsciiNameback to summary
public String getAsciiName()

Returns the StandardCharsets#US_ASCII-compliant hostname of this SNIHostName object.

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:String

the StandardCharsets#US_ASCII-compliant hostname of this SNIHostName object

External Specification
https://www.rfc-editor.org/info/rfc5890, https://www.rfc-editor.org/info/rfc6066
hashCodeback to summary
public int hashCode()

Overrides javax.net.ssl.SNIServerName.hashCode.

Returns a hash code value for this SNIHostName.

The hash code value is generated using the case-insensitive hostname of this SNIHostName.

Returns:int

a hash code value for this SNIHostName.

Annotations
@Override
toStringback to summary
public String toString()

Overrides javax.net.ssl.SNIServerName.toString.

Returns a string representation of the object, including the DNS hostname in this SNIHostName object.

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 contain A-labels. For example, a returned value of a 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.

Returns:String

a string representation of the object.

Annotations
@Override
javax.net.ssl back to summary

private final Class SNIHostName.SNIHostNameMatcher

extends SNIMatcher
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Pattern

Constructor Summary

AccessConstructor and Description
pack-priv
SNIHostNameMatcher(String
the regular expression pattern representing the hostname(s) to match
regex
)

Creates an SNIHostNameMatcher object.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if, and only if, the matcher matches the given serverName
matches
(SNIServerName
the SNIServerName instance on which this matcher performs match operations
serverName
)

Implements abstract javax.net.ssl.SNIMatcher.matches.

Attempts to match the given SNIServerName.

Inherited from javax.net.ssl.SNIMatcher:
getType

Field Detail

patternback to summary
private final Pattern pattern

Constructor Detail

SNIHostNameMatcherback to summary
pack-priv SNIHostNameMatcher(String regex)

Creates an SNIHostNameMatcher object.

Parameters
regex:String

the regular expression pattern representing the hostname(s) to match

Exceptions
NullPointerException:
if regex is null
PatternSyntaxException:
if the regular expression's syntax is invalid

Method Detail

matchesback to summary
public boolean matches(SNIServerName serverName)

Implements abstract javax.net.ssl.SNIMatcher.matches.

Attempts to match the given SNIServerName.

Parameters
serverName:SNIServerName

the SNIServerName instance on which this matcher performs match operations

Returns:boolean

true if, and only if, the matcher matches the given serverName

Annotations
@Override
Exceptions
NullPointerException:
if serverName is null
IllegalArgumentException:
if serverName is not of StandardConstants#SNI_HOST_NAME type
See Also
SNIServerName