SOCKS5 Proxy using SSLSocket
I have a client/server application that remotely connects to a server via Java's SSLSocket.
I'm trying to implement an optional mode that enables connections via an authenticated SOCKS v5 proxy.
I tried using the relevant tutorial but it doesn't mention anything about SSL specifically.
I've tried setting the system-wide properties ("socksProxyHost" and "socksProxyPort") but it doesn't seem to do anything.
My next approach was to use factory method in SSLSocketFactory:
String proxyHost = Config.prefs.get("PROXY_NAME", "localhost");
int proxyPort = Config.prefs.getInt("PROXY_PORT", 1080);
InetSocketAddress proxyAddr = new InetSocketAddress(proxyHost, proxyPort);
Socket underlying = new SSLSocket(new Proxy(Proxy.Type.SOCKS, proxyAddr));
underlying.connect(new InetSocketAddress(getHost(), getPort()));
socket = (SSLSocket) factory.createSocket(
underlying,
getHost(),
getPort(),
true);
But the problem with this approach is that the createSocket method requires the und开发者_运维知识库erlying socket to be already connected, and my server won't accept non SSL connections.
What's the best way to connect to my remote server using SOCKS? Also, I have next to no idea how to supply a username/password for authenticated SOCKS in this system.
Thanks!
String proxyHost = Config.prefs.get("PROXY_NAME", "localhost");
int proxyPort = Config.prefs.getInt("PROXY_PORT", 1080);
InetSocketAddress proxyAddr = new InetSocketAddress(proxyHost, proxyPort);
Socket underlying = new Socket(new Proxy(Proxy.Type.SOCKS, proxyAddr));
underlying.connect(new InetSocketAddress(getHost(), getPort()));
socket = (SSLSocket) factory.createSocket(
underlying,
proxyHost,
proxyPort,
true);
精彩评论