netlayer
netlayer copied to clipboard
TorSocket.isConnected always returns false
TorSocket delegates the socket.isConnected() call to SocksSocket which always returns false, even when the TorSocket has successfully connected to the endpoint.
This is a problem when wrapping the TorSocket in a java SSLSocket, as the first thing that SSLSocketImpl does is check if the socket is connected:
if (!sock.isConnected()) { throw new SocketException("Underlying socket is not connected"); }
While it's unnecessary to wrap Tor connections in SSL, sometimes you don't get a choice of server protocol.
A workaround is to use Java reflection to retrieve SocksSocket from TorSocket and set the connected member variable to true.