Java Reference
In-Depth Information
SSLSocket sslSocket = (SSLSocket)
sslServerSocket.accept();
System.out.println("closing socket");
sslSocket.close();
sslServerSocket.close();
} catch (IOException e) {
System.out.println(e);
} finally {
try {
sslServerSocket.close();
} catch (IOException ex) {
System.out.println(ex);
}
}
How It Works
The Server Name Indication (SNI) extension provides a server with a list of valid serv-
ers for connection when attempting a handshake. The SNI extension uses SSL/TLS
protocols to provide this functionality. Given a specified server name, an application
can determine whether it is a valid address for opening an SSLSocket or
SSLEngine connection.
To indicate a server name, use the SSLParamet-
ers.setServerNames(List<SNIServerName> serverNames) method
and pass a list containing valid server names. In the recipe example, the server name of
gmail.com is set as valid using the following lines of code:
SNIHostName serverName = new SNIHostName(host);
List<SNIServerName> serverNames = new ArrayList<>(1);
serverNames.add(serverName);
SSLParameters params = sslSocket.getSSLParameters();
params.setServerNames(serverNames);
sslSocket.setSSLParameters(params);
Search WWH ::




Custom Search