SNIHostName

public final class SNIHostName extends SNIServerName

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.

Public Constructor Summary

SNIHostName(String hostname)
Creates an SNIHostName using the specified hostname.
SNIHostName(byte[] encoded)
Creates an SNIHostName using the specified encoded value.

Public Method Summary

static SNIMatcher
createSNIMatcher(String regex)
Creates an SNIMatcher object for SNIHostNames.
boolean
equals(Object other)
Compares this server name to the specified object.
String
getAsciiName()
Returns the US_ASCII-compliant hostname of this SNIHostName object.
int
hashCode()
Returns a hash code value for this SNIHostName.
String
toString()
Returns a string representation of the object, including the DNS hostname in this SNIHostName object.

Inherited Method Summary

Public Constructors

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 US_ASCII-compliant. In this method, hostname can be a user-friendly Internationalized Domain Name (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 the hostname of this server name
Throws
NullPointerException if hostname is null
IllegalArgumentException if hostname is illegal

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 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 UTF_8, as well as US_ASCII. 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 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(String) instead.

The encoded argument is illegal if it:

  • encoded is empty,
  • encoded ends with a trailing dot,
  • encoded is not encoded in US_ASCII or 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 the encoded hostname of this server name
Throws
NullPointerException if encoded is null
IllegalArgumentException if encoded is illegal

Public Methods

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 the regular expression pattern representing the hostname(s) to match
Returns
  • a SNIMatcher object for SNIHostNames
Throws
NullPointerException if regex is null
PatternSyntaxException if the regular expression's syntax is invalid