|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--java.net.Socket
|
+--iaik.security.ssl.SSLSocket
This class implements the SSL/TLS transport over Java sockets.
It extends java.net.Socket and therefore can be used
anywhere in its place making it very easy to secure existing
applications. The actual TLS functionality is located in the
SSLTransport class, see there for more general documentation.
Note that by default the TLS handshake is automatically
started when you call getInputStream() or
getOutputStream(). This will be the desired behaviour
in most cases, but not when connecting through proxies.
In that case you have three options:
proxyConnect() in the Utils class.
SSLTransport,
Utils.proxyConnect(java.net.InetAddress, int, iaik.security.ssl.SSLContext)| Constructor Summary | |
SSLSocket(java.net.InetAddress address,
int port,
java.net.InetAddress localAddr,
int localPort,
SSLContext context)
Creates a SSL socket and connects it to the specified remote address on the specified remote port. |
|
SSLSocket(java.net.InetAddress address,
int port,
SSLContext context)
Creates a SSL stream socket and connects it to the specified port number at the specified IP address. |
|
SSLSocket(java.net.Socket socket,
SSLContext context)
Create an SSLSocket from an existing socket. |
|
SSLSocket(java.net.Socket socket,
SSLContext context,
java.lang.String address,
int port)
|
|
SSLSocket(java.lang.String host,
int port,
java.net.InetAddress localAddr,
int localPort,
SSLContext context)
Creates a SSL socket and connects it to the specified remote host on the specified remote port. |
|
SSLSocket(java.lang.String host,
int port,
SSLContext context)
Creates a SSL stream socket and connects it to the specified port number on the named host. |
|
| Method Summary | |
void |
close()
Close this SSL socket. |
CipherSuite |
getActiveCipherSuite()
Returns the active cipher suite. |
CompressionMethod |
getActiveCompressionMethod()
Returns the active compression method. |
int |
getActiveProtocolVersion()
Return the active SSL protocol version. |
CipherSuite[] |
getClientSupportedCipherSuites()
Deprecated. use getPeerSupportedCipherSuiteList() |
CompressionMethod[] |
getClientSupportedCompressionMethods()
Deprecated. use getPeerSupportedCompressionMethods() |
SSLContext |
getContext()
Returns the SSLContext of this SSLSocket. |
java.net.InetAddress |
getInetAddress()
See JDK documentation of java.net.Socket for a description of this method. |
java.io.InputStream |
getInputStream()
Returns an input stream for this socket. |
java.net.InetAddress |
getLocalAddress()
See JDK documentation of java.net.Socket for a description of this method. |
int |
getLocalPort()
See JDK documentation of java.net.Socket for a description of this method. |
java.io.OutputStream |
getOutputStream()
Returns an output stream for this socket. |
X509Certificate[] |
getPeerCertificateChain()
Returns the certificate chain sent by the peer or null if the peer has no certificate. |
CipherSuiteList |
getPeerSupportedCipherSuiteList()
Return the list of cipher suites known to be supported by the remote peer. |
CompressionMethod[] |
getPeerSupportedCompressionMethods()
Return the compression methods supported by the remote peer. |
int |
getPort()
See JDK documentation of java.net.Socket for a description of this method. |
Session |
getSession()
Returns the currently active Session for this SSLSocket. |
int |
getSoLinger()
See JDK documentation of java.net.Socket for a description of this method. |
int |
getSoTimeout()
See JDK documentation of java.net.Socket for a description of this method. |
boolean |
getTcpNoDelay()
See JDK documentation of java.net.Socket for a description of this method. |
SSLTransport |
getTransport()
Get the SSLTransport this socket is talking over. |
boolean |
getUseClientMode()
Returns whether or not this socket resides on the client side of the connection. |
void |
init(java.net.Socket s,
SSLContext context,
boolean useClientMode)
Initialize the SSLSocket. |
boolean |
isServer()
Deprecated. use getUseClientMode() |
void |
renegotiate()
Start a renegotiating SSL handshake. |
void |
setAutoHandshake(boolean on)
Can be used to switch off the automatic start of the handshake procedure. |
void |
setDebugStream(java.io.OutputStream os)
Enables debugging mode. |
void |
setDebugStream(java.io.Writer writer)
Enables debugging mode. |
void |
setSoLinger(boolean on,
int val)
See JDK documentation of java.net.Socket for a description of this method. |
void |
setSoTimeout(int timeout)
See JDK documentation of java.net.Socket for a description of this method. |
void |
setTcpNoDelay(boolean on)
See JDK documentation of java.net.Socket for a description of this method. |
void |
setUseClientMode(boolean mode)
Select client or server mode for this socket. |
void |
shutdown()
Shuts the SSL layer down. |
void |
startHandshake()
Start the SSL handshake process. |
| Methods inherited from class java.net.Socket |
getReceiveBufferSize,
getSendBufferSize,
setReceiveBufferSize,
setSendBufferSize,
setSocketImplFactory,
toString |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
| Constructor Detail |
public SSLSocket(java.net.Socket socket,
SSLContext context)
throws java.io.IOException
public SSLSocket(java.lang.String host,
int port,
SSLContext context)
throws java.io.IOException,
java.net.UnknownHostException
All properties of this SSLSocket are defined in the SSLContext.
host - the host name.port - the port number.context - the SSLContext for the new socket
public SSLSocket(java.net.InetAddress address,
int port,
SSLContext context)
throws java.io.IOException
All properties of this SSLSocket are defined in the SSLContext.
address - the IP address.port - the port number.context - the SSLContext for the new socket
public SSLSocket(java.lang.String host,
int port,
java.net.InetAddress localAddr,
int localPort,
SSLContext context)
throws java.io.IOException
All properties of this SSLSocket are defined in the SSLContext.
host - the name of the remote hostport - the remote portlocalAddr - the local address the socket is bound tolocalPort - the local port the socket is bound tocontext - the SSLContext for the new socket
public SSLSocket(java.net.InetAddress address,
int port,
java.net.InetAddress localAddr,
int localPort,
SSLContext context)
throws java.io.IOException
All properties of this SSLSocket are defined in the SSLContext.
address - the remote addressport - the remote portlocalAddr - the local address the socket is bound tolocalPort - the local port the socket is bound tocontext - the SSLContext for the new socket
public SSLSocket(java.net.Socket socket,
SSLContext context,
java.lang.String address,
int port)
throws java.io.IOException
| Method Detail |
public SSLTransport getTransport()
public void init(java.net.Socket s,
SSLContext context,
boolean useClientMode)
throws java.io.IOException
context - the SSLContext of this socketisServer - is this the SSLSocket of a server
public void setUseClientMode(boolean mode)
throws java.io.IOException
This selection can only be made prior to the initial SSL handshake. If the method is called made afterwards an SSLException is thrown.
public boolean getUseClientMode()
public SSLContext getContext()
public void setAutoHandshake(boolean on)
If auto handshake is switched off the application has to start the handshaking process manually using the method startHandshake(). This kind of operation is used when connecting over a proxy or firewall.
on - true if handshake should start automatically, false otherwiseSSLCommunication.startHandshake()public X509Certificate[] getPeerCertificateChain()
In SSLv2 this will always just return the server's certificate (protocol limitation). Note that some SSLv3/TLS server do not include self signed certificates as those will have to be obtained and verified using a different method anyway.
public int getActiveProtocolVersion()
SSLContextpublic CipherSuite getActiveCipherSuite()
CipherSuitepublic CompressionMethod getActiveCompressionMethod()
CompressionMethodpublic CipherSuiteList getPeerSupportedCipherSuiteList()
CipherSuite,
SSLCommunication.getActiveCipherSuite()public CompressionMethod[] getPeerSupportedCompressionMethods()
getPeerSupportedCipherSuiteList(), see there with
the exception of the SSLv2 case. As there are no compression
in SSLv2 the empty array is returned.CompressionMethod,
SSLCommunication.getActiveCompressionMethod()public Session getSession()
public void renegotiate()
throws java.io.IOException
getSession().invalidate() before
calling renegotiate, see below for more information.
Basically there are two reasons you might want to initiate renegotiation:
This method locks the InputStream and the OutputStream for exclusive access before proceeding with the handshake. That means that for the duration of the handshake procedure no communication is possible and more importantly that the handshake can not begin until possible blocking read() and write() calls by other threads have completed.
public void startHandshake()
throws java.io.IOException
This method locks the InputStream and the OutputStream for exclusive access before proceeding with the handshake. That means that for the duration of the handshake procedure no communication is possible and more importantly that the handshake can not begin until possible blocking read() and write() calls by other threads have completed.
SSLCommunication.setAutoHandshake(boolean)
public java.io.OutputStream getOutputStream()
throws java.io.IOException
public java.io.InputStream getInputStream()
throws java.io.IOException
public void setDebugStream(java.io.Writer writer)
writer - the Writer to which debug information shall be writtenpublic void setDebugStream(java.io.OutputStream os)
os - the OutputStream to which debug information shall be written
public void shutdown()
throws java.io.IOException
A SSL layer shutdown occurs in the following cases:
public void close()
throws java.io.IOException
This method will never be called by the library itself, it will always just call shutdown(). It is the responsibility of the application to always close the socket when communication has been completed. Once the socket has been closed read() and write() calls will throw SocketExceptions. The behaviour described here is compatible with the original Java sockets.
public CipherSuite[] getClientSupportedCipherSuites()
public CompressionMethod[] getClientSupportedCompressionMethods()
public boolean isServer()
public java.net.InetAddress getInetAddress()
public java.net.InetAddress getLocalAddress()
public int getPort()
public int getLocalPort()
public void setTcpNoDelay(boolean on)
throws java.net.SocketException
public boolean getTcpNoDelay()
throws java.net.SocketException
public void setSoLinger(boolean on,
int val)
throws java.net.SocketException
public int getSoLinger()
throws java.net.SocketException
public void setSoTimeout(int timeout)
throws java.net.SocketException
public int getSoTimeout()
throws java.net.SocketException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||