Java Reference
In-Depth Information
public String [] getSupportedProtocols(). Returns an array containing
the security protocols that can be enabled for this particular socket con-
nection. You can expect SSL as well as TLS, the Transport Layer Security,
to be supported.
public void setNeedClientAuth(boolean flag). Denotes that clients con-
necting to this server socket must be authenticated. By default, clients'
connections do not require authentication. If turned on, clients must be
authenticated, or else the connection will close immediately after the
server accepts the client connection.
public void setWantClientAuth(boolean flag). Denotes that clients con-
necting to this server socket should be authenticated. Clients should pro-
vide authentication information, but the connection is still maintained if
they do not.
A server program for SSL sockets uses a factory to create a secure server
socket. The following SSLServerDemo program demonstrates the steps a
server takes to accept secure client connections. Study the program and its out-
put carefully, which is shown in Figure 17.4.
import java.net.*;
import javax.net.ssl.*;
import java.io.*;
public class SSLServerDemo
{
public static void main(String [] args)
{
int port = Integer.parseInt(args[0]);
try
{
System.out.println(“Locating server socket factory for
SSL...”);
SSLServerSocketFactory factory =
(SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
System.out.println(“Creating a server socket on port “ +
port);
SSLServerSocket serverSocket =
(SSLServerSocket) factory.createServerSocket(port);
String [] suites =
serverSocket.getSupportedCipherSuites();
System.out.println(“Support cipher suites are:”);
for(int i = 0; i < suites.length; i++)
{
System.out.println(suites[i]);
}
serverSocket.setEnabledCipherSuites(suites);
System.out.println(“Support protocols are:”);
String [] protocols =
serverSocket.getSupportedProtocols();
for(int i = 0; i < protocols.length; i++)
Search WWH ::




Custom Search