Java Reference
In-Depth Information
public void setEnabledCipherSuites(String [] suites). Sets the cipher
suites available for this connection. The client and server need to share
at least one common cipher suite before handshaking can occur.
public void addHandshakeCompletedListener(HandshakeComplet-
edListener h). Adds the specified listener to the connection. Whenever
a handshake is completed successfully, the listener is notified via the
handshakeCompleted() method in the HandshakeCompletedListener
interface.
public SSLSession getSession(). Gets the session of this SSL connection,
which is created after handshaking occurs. The SSLSession object con-
tains information about the connection, for example, which cipher suite
and protocol is being used, as well as the identity of the client and server.
Notice that the SSLSocket class is a source of a HandshakeCompletedEvent.
This allows you to determine information about the security parameters used
to establish the connection, such as the cipher suite used or any security cer-
tificates used. The following MyHandshakeListener class demonstrates writ-
ing a listener for this event.
import javax.net.ssl.*;
public class MyHandshakeListener
implements HandshakeCompletedListener
{
public void handshakeCompleted(HandshakeCompletedEvent e)
{
System.out.println(“Handshake succesful!”);
System.out.println(“Using cipher suite: “
+ e.getCipherSuite());
}
}
The following SSLClientDemo program demonstrates a client creating an
SSL connection to the SSLServerDemo application by using the SSLSocket
class. Study the program and try to determine what is happening and what the
output will be, which is shown in Figure 17.5.
Figure 17.5 Output of the SSLClientDemo program, which starts a handshake with the
server to ensure that secure communication can occur successfully.
Search WWH ::




Custom Search