public class TLSSocketFactory extends AbstractTLSSocketFactory implements org.apache.avalon.cornerstone.services.sockets.SocketFactory, org.apache.avalon.framework.context.Contextualizable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.Initializable
<factory name="secure"
class="org.apache.avalon.cornerstone.blocks.sockets.TLSSocketFactory" >
<ssl-factory /> <!-- see SSLFactoryBuilder -->
<timeout> 0 </timeout>
<!-- if the value is greater than zero, a read() call on the
InputStream associated with this Socket will block for only this
amount of time in milliseconds. Default value is 0. -->
<verify-server-identity>true|false</verify-server-identity>
<!-- whether or not the server identity should be verified.
Defaults to false. -->
</factory>
Server identity verification currently includes only comparing the certificate Common Name received with the host name in the passed address. Identity verification requires that SSL handshake is completed for the socket, so it takes longer to get a verified socket (and won't play well with non-blocking application like SEDA).
Another thing to keep in mind when using identity verification is
that InetAddress objects for the remote hosts should be
built using InetAddress.getByName(java.lang.String) with
the host name (matching the certificate CN) as the
argument. Failure to do so may cause relatively costly DNS lookups
and false rejections caused by inconsistencies between forward and
reverse resolution.
| Modifier and Type | Field and Description |
|---|---|
private javax.net.ssl.SSLSocketFactory |
m_factory |
private boolean |
m_verifyServerIdentity |
m_socketTimeOut| Constructor and Description |
|---|
TLSSocketFactory() |
| Modifier and Type | Method and Description |
|---|---|
private java.lang.StringBuffer |
bytesToString(byte[] data) |
void |
configure(org.apache.avalon.framework.configuration.Configuration configuration)
Configures the factory.
|
java.net.Socket |
createSocket(java.net.InetAddress address,
int port)
Creates a socket connected to the specified remote address.
|
java.net.Socket |
createSocket(java.net.InetAddress address,
int port,
java.net.InetAddress localAddress,
int localPort)
Creates a socket and connected to the specified remote address
originating from specified local address.
|
private java.lang.String |
getCN(java.lang.String DN)
Extracts the Common Name from the given Distinguished
Name.
|
private java.net.Socket |
initSocket(java.net.Socket socket)
Performs the unconditional part of socket initialization that
applies to all Sockets.
|
private javax.net.ssl.SSLSocket |
sslWrap(java.net.Socket bareSocket,
java.net.InetAddress address,
int port)
Wraps an ssl socket over an existing socket and compares the
host name from the address to the common name in the server
certificate.
|
protected void |
visitBuilder(SSLFactoryBuilder builder)
The child factories have to use an instance of
SSLFactoryBuilder to obtain their factories.
|
contextualize, initializeenableLogging, getLogger, setupLogger, setupLogger, setupLoggerprivate javax.net.ssl.SSLSocketFactory m_factory
private boolean m_verifyServerIdentity
public void configure(org.apache.avalon.framework.configuration.Configuration configuration)
throws org.apache.avalon.framework.configuration.ConfigurationException
configure in interface org.apache.avalon.framework.configuration.Configurableconfigure in class AbstractTLSSocketFactoryconfiguration - the Configurationorg.apache.avalon.framework.configuration.ConfigurationException - if an error occursprotected void visitBuilder(SSLFactoryBuilder builder)
AbstractTLSSocketFactoryvisitBuilder in class AbstractTLSSocketFactoryprivate java.net.Socket initSocket(java.net.Socket socket)
throws java.io.IOException
java.io.IOExceptionprivate javax.net.ssl.SSLSocket sslWrap(java.net.Socket bareSocket,
java.net.InetAddress address,
int port)
throws java.io.IOException
bareSocket - plain socket connected to the serveraddress - destination of the bareSocketport - destination of the bareSocketjava.io.IOExceptionprivate java.lang.StringBuffer bytesToString(byte[] data)
private java.lang.String getCN(java.lang.String DN)
public java.net.Socket createSocket(java.net.InetAddress address,
int port)
throws java.io.IOException
createSocket in interface org.apache.avalon.cornerstone.services.sockets.SocketFactoryaddress - the remote addressport - the remote portjava.io.IOException - if an error occurspublic java.net.Socket createSocket(java.net.InetAddress address,
int port,
java.net.InetAddress localAddress,
int localPort)
throws java.io.IOException
createSocket in interface org.apache.avalon.cornerstone.services.sockets.SocketFactoryaddress - the remote addressport - the remote portlocalAddress - the local addresslocalPort - the local portjava.io.IOException - if an error occurs