|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.avalon.cornerstone.blocks.sockets.AbstractTLSSocketFactory
org.apache.avalon.cornerstone.blocks.sockets.TLSSocketFactory
public class TLSSocketFactory
Manufactures TLS client sockets. Configuration element inside a SocketManager would look like:
<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.
Field Summary | |
---|---|
private javax.net.ssl.SSLSocketFactory |
m_factory
|
private boolean |
m_verifyServerIdentity
|
Fields inherited from class org.apache.avalon.cornerstone.blocks.sockets.AbstractTLSSocketFactory |
---|
m_socketTimeOut |
Constructor Summary | |
---|---|
TLSSocketFactory()
|
Method Summary | |
---|---|
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. |
Methods inherited from class org.apache.avalon.cornerstone.blocks.sockets.AbstractTLSSocketFactory |
---|
contextualize, initialize |
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled |
---|
enableLogging, getLogger, setupLogger, setupLogger, setupLogger |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.apache.avalon.framework.context.Contextualizable |
---|
contextualize |
Methods inherited from interface org.apache.avalon.framework.activity.Initializable |
---|
initialize |
Field Detail |
---|
private javax.net.ssl.SSLSocketFactory m_factory
private boolean m_verifyServerIdentity
Constructor Detail |
---|
public TLSSocketFactory()
Method Detail |
---|
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.Configurable
configure
in class AbstractTLSSocketFactory
configuration
- the Configuration
org.apache.avalon.framework.configuration.ConfigurationException
- if an error occursprotected void visitBuilder(SSLFactoryBuilder builder)
AbstractTLSSocketFactory
visitBuilder
in class AbstractTLSSocketFactory
private java.net.Socket initSocket(java.net.Socket socket) throws java.io.IOException
java.io.IOException
private 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 bareSocket
java.io.IOException
private 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.SocketFactory
address
- the remote addressport
- the remote port
java.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.SocketFactory
address
- the remote addressport
- the remote portlocalAddress
- the local addresslocalPort
- the local port
java.io.IOException
- if an error occurs
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |