com.sun.slamd.example
Class JSSEBlindTrustSocketFactory

java.lang.Object
  extended by javax.net.SocketFactory
      extended by javax.net.ssl.SSLSocketFactory
          extended by com.sun.slamd.example.JSSEBlindTrustSocketFactory
All Implemented Interfaces:
javax.net.ssl.TrustManager, javax.net.ssl.X509TrustManager, netscape.ldap.LDAPSocketFactory

public class JSSEBlindTrustSocketFactory
extends javax.net.ssl.SSLSocketFactory
implements netscape.ldap.LDAPSocketFactory, javax.net.ssl.X509TrustManager

This class provides an implementation of an SSL socket factory that will use JSSE to create the SSL socket. In addition, it will implement a trust mechanism in such a way that it will blindly trust any certificate that the server presents to it, regardless of what we might think is wrong with it.

Author:
Neil A. Wilson

Constructor Summary
JSSEBlindTrustSocketFactory()
          Creates a new instance of this LDAP socket factory.
JSSEBlindTrustSocketFactory(boolean debugMode)
          Creates a new instance of this LDAP socket factory, optionally operating in debug mode.
 
Method Summary
 void checkClientTrusted(java.security.cert.X509Certificate[] chain, java.lang.String authType)
          Determines whether the provided client certificate should be trusted.
 void checkServerTrusted(java.security.cert.X509Certificate[] chain, java.lang.String authType)
          Determines whether the provided server certificate should be trusted.
 java.net.Socket createSocket(java.net.InetAddress host, int port)
          Creates a new SSL socket connected to the specified host and port.
 java.net.Socket createSocket(java.net.InetAddress host, int port, java.net.InetAddress localAddress, int localPort)
          Creates a new SSL socket connected to the specified host and port.
 java.net.Socket createSocket(java.net.Socket socket, java.lang.String host, int port, boolean autoClose)
          Converts the provided socket to an SSL socket using this socket factory.
 java.net.Socket createSocket(java.lang.String host, int port)
          Creates a new SSL socket connected to the specified host and port.
 java.net.Socket createSocket(java.lang.String host, int port, java.net.InetAddress localHost, int localPort)
          Creates a new SSL socket connected to the specified host and port.
 java.security.cert.X509Certificate[] getAcceptedIssuers()
          Retrieves an array of CA certificates that are trusted for authenticating peers.
 java.lang.String[] getCiphers()
          Retrieves the names of the ciphers that should be used for SSL sockets created by this socket factory.
 java.lang.String[] getDefaultCipherSuites()
          Retrieves the set of cipher suites that are enabled by default.
 boolean getDisableSessionReuse()
          Indicates whether SSL sessions may be reused across multiple connections.
 java.lang.String[] getSupportedCipherSuites()
          Retrieves the set of cipher suites that can be used to create SSL sockets.
 java.net.Socket makeSocket(java.lang.String host, int port)
          Establishes an SSL socket to the provided host and port that can be used by the LDAP SDK for Java for communicating with an LDAP directory server.
 void setCipher(java.lang.String cipherName)
          Specifies the name of the cipher that should be used for SSL sockets created by this socket factory.
 void setCiphers(java.lang.String[] cipherNames)
          Specifies the names of the cipher that should be used for SSL sockets created by this socket factory.
 void setDisableSessionReuse(boolean disableSessionReuse)
          Specifies whether to disable SSL session reuse across multiple connections.
 
Methods inherited from class javax.net.ssl.SSLSocketFactory
getDefault
 
Methods inherited from class javax.net.SocketFactory
createSocket
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSSEBlindTrustSocketFactory

public JSSEBlindTrustSocketFactory()
                            throws netscape.ldap.LDAPException
Creates a new instance of this LDAP socket factory.

Throws:
netscape.ldap.LDAPException - If a problem occurs while initializing this socket factory.

JSSEBlindTrustSocketFactory

public JSSEBlindTrustSocketFactory(boolean debugMode)
                            throws netscape.ldap.LDAPException
Creates a new instance of this LDAP socket factory, optionally operating in debug mode.

Parameters:
debugMode - Indicates whether to operate in debug mode. If this is enabled, a message will be printed to standard error any time of of the methods of this class is called.
Throws:
netscape.ldap.LDAPException - If a problem occurs while initializing this socket factory.
Method Detail

checkClientTrusted

public void checkClientTrusted(java.security.cert.X509Certificate[] chain,
                               java.lang.String authType)
Determines whether the provided client certificate should be trusted. In this case, the certificate will always be trusted.

Specified by:
checkClientTrusted in interface javax.net.ssl.X509TrustManager
Parameters:
chain - The peer certificate chain.
authType - The authentication type based on the client certificate.

checkServerTrusted

public void checkServerTrusted(java.security.cert.X509Certificate[] chain,
                               java.lang.String authType)
Determines whether the provided server certificate should be trusted. In this case, the certificate will always be trusted.

Specified by:
checkServerTrusted in interface javax.net.ssl.X509TrustManager
Parameters:
chain - The peer certificate chain.
authType - The authentication type based on the server certificate.

getAcceptedIssuers

public java.security.cert.X509Certificate[] getAcceptedIssuers()
Retrieves an array of CA certificates that are trusted for authenticating peers.

Specified by:
getAcceptedIssuers in interface javax.net.ssl.X509TrustManager
Returns:
An empty array, because we don't care about any list of CAs.

makeSocket

public java.net.Socket makeSocket(java.lang.String host,
                                  int port)
                           throws netscape.ldap.LDAPException
Establishes an SSL socket to the provided host and port that can be used by the LDAP SDK for Java for communicating with an LDAP directory server.

Specified by:
makeSocket in interface netscape.ldap.LDAPSocketFactory
Parameters:
host - The address of the server to which the connection is to be established.
port - The port number of the server to which the connection is to be established.
Returns:
The SSL socket that may be used for communicating with the directory server.
Throws:
netscape.ldap.LDAPException - If a problem occurs while trying to establish the connection.

createSocket

public java.net.Socket createSocket(java.lang.String host,
                                    int port)
                             throws java.io.IOException
Creates a new SSL socket connected to the specified host and port.

Specified by:
createSocket in class javax.net.SocketFactory
Parameters:
host - The address of the system to which the SSL socket should be connected.
port - The port on the target system to which the SSL socket should be connected.
Returns:
The created SSL socket.
Throws:
java.io.IOException - If a problem occurs while creating the SSL socket.

createSocket

public java.net.Socket createSocket(java.lang.String host,
                                    int port,
                                    java.net.InetAddress localHost,
                                    int localPort)
                             throws java.io.IOException
Creates a new SSL socket connected to the specified host and port.

Specified by:
createSocket in class javax.net.SocketFactory
Parameters:
host - The address of the system to which the SSL socket should be connected.
port - The port on the target system to which the SSL socket should be connected.
localHost - The address on the local system from which the socket should originate.
localPort - The port on the local system from which the socket should originate.
Returns:
The created SSL socket.
Throws:
java.io.IOException - If a problem occurs while creating the SSL socket.

createSocket

public java.net.Socket createSocket(java.net.InetAddress host,
                                    int port)
                             throws java.io.IOException
Creates a new SSL socket connected to the specified host and port.

Specified by:
createSocket in class javax.net.SocketFactory
Parameters:
host - The address of the system to which the SSL socket should be connected.
port - The port on the target system to which the SSL socket should be connected.
Returns:
The created SSL socket.
Throws:
java.io.IOException - If a problem occurs while creating the SSL socket.

createSocket

public java.net.Socket createSocket(java.net.InetAddress host,
                                    int port,
                                    java.net.InetAddress localAddress,
                                    int localPort)
                             throws java.io.IOException
Creates a new SSL socket connected to the specified host and port.

Specified by:
createSocket in class javax.net.SocketFactory
Parameters:
host - The address of the system to which the SSL socket should be connected.
port - The port on the target system to which the SSL socket should be connected.
localAddress - The address on the local system from which the socket should originate.
localPort - The port on the local system from which the socket should originate.
Returns:
The created SSL socket.
Throws:
java.io.IOException - If a problem occurs while creating the SSL socket.

createSocket

public java.net.Socket createSocket(java.net.Socket socket,
                                    java.lang.String host,
                                    int port,
                                    boolean autoClose)
                             throws java.io.IOException
Converts the provided socket to an SSL socket using this socket factory.

Specified by:
createSocket in class javax.net.ssl.SSLSocketFactory
Parameters:
socket - The socket to convert to an SSL socket.
host - The host to which the socket is connected.
port - The port to which the socket is connected.
autoClose - Indicates whether the underlying socket should be closed when the returned SSL socket is closed.
Returns:
The created SSL socket.
Throws:
java.io.IOException - If a problem occurs while creating the SSL socket.

getCiphers

public java.lang.String[] getCiphers()
Retrieves the names of the ciphers that should be used for SSL sockets created by this socket factory.

Returns:
The names of the ciphers that should be used for SSL sockets created by this socket factory.

setCipher

public void setCipher(java.lang.String cipherName)
Specifies the name of the cipher that should be used for SSL sockets created by this socket factory.

Parameters:
cipherName - The name of the cipher that should be used for SSL sockets created by this socket factory.

setCiphers

public void setCiphers(java.lang.String[] cipherNames)
Specifies the names of the cipher that should be used for SSL sockets created by this socket factory.

Parameters:
cipherNames - The names of the cipher that should be used for SSL sockets created by this socket factory.

getDefaultCipherSuites

public java.lang.String[] getDefaultCipherSuites()
Retrieves the set of cipher suites that are enabled by default.

Specified by:
getDefaultCipherSuites in class javax.net.ssl.SSLSocketFactory
Returns:
The set of cipher suites that are enabled by default.

getSupportedCipherSuites

public java.lang.String[] getSupportedCipherSuites()
Retrieves the set of cipher suites that can be used to create SSL sockets.

Specified by:
getSupportedCipherSuites in class javax.net.ssl.SSLSocketFactory
Returns:
The set of cipher suites that can be used to create SSL sockets.

getDisableSessionReuse

public boolean getDisableSessionReuse()
Indicates whether SSL sessions may be reused across multiple connections.

Returns:
true if SSL sessions may be reused across multiple connections, or false if not.

setDisableSessionReuse

public void setDisableSessionReuse(boolean disableSessionReuse)
Specifies whether to disable SSL session reuse across multiple connections.

Parameters:
disableSessionReuse - Indicates whether to disable SSL session reuse across multiple connections.