Package eu.tneitzel.rmg.networking
Class TrustAllSocketFactory
- java.lang.Object
-
- eu.tneitzel.rmg.networking.TrustAllSocketFactory
-
- All Implemented Interfaces:
RMIClientSocketFactory
public class TrustAllSocketFactory extends Object implements RMIClientSocketFactory
Wrapper around an SSLSocketFactory that trusts all certificates. This is used for TLS protected RMI connections to prevent certificate errors. Furthermore, the class also allows to set custom values for the underlying TCP sockets read and connect timeouts. This is required for the portscan operation.- Author:
- Tobias Neitzel (@qtc_de)
-
-
Constructor Summary
Constructors Constructor Description TrustAllSocketFactory()Creates a new TrustAllSocketFactory by disabling certificate validation on an SSLContext and using the resulting SSLSocketFactory.TrustAllSocketFactory(int readTimeout, int connectTimeout)Same as the previous constructor, but allows user defined values for the timeouts.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SocketcreateSocket(String host, int port)Uses the SSLSocketFactory to create a socket, sets the read timeout on it and connects the socket to the target using the specified connect timeout.SSLSocketFactorygetSSLSocketFactory()Can be used to obtain the underlying SSLSocketFactory
-
-
-
Constructor Detail
-
TrustAllSocketFactory
public TrustAllSocketFactory()
Creates a new TrustAllSocketFactory by disabling certificate validation on an SSLContext and using the resulting SSLSocketFactory. This constructor sets some default values for the read and connect timeouts that are used by the socket.
-
TrustAllSocketFactory
public TrustAllSocketFactory(int readTimeout, int connectTimeout)Same as the previous constructor, but allows user defined values for the timeouts. This can be handy when e.g. connecting to plain text sockets that do not return anything when receiving an incoming SSL handshake. The default behavior of an SSL socket is to hang forever in such a case.- Parameters:
readTimeout- timeout for read operations on the socketconnectTimeout- timeout for the initial socket connect
-
-
Method Detail
-
createSocket
public Socket createSocket(String host, int port) throws IOException
Uses the SSLSocketFactory to create a socket, sets the read timeout on it and connects the socket to the target using the specified connect timeout.- Specified by:
createSocketin interfaceRMIClientSocketFactory- Throws:
IOException
-
getSSLSocketFactory
public SSLSocketFactory getSSLSocketFactory()
Can be used to obtain the underlying SSLSocketFactory- Returns:
- SSLSocketFactory of the TrustAll context
-
-