SOCKS5 Proxy using SSLSocket

故事扮演 提交于 2019-12-06 06:22:14

问题


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 underlying 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!


回答1:


        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);


来源:https://stackoverflow.com/questions/5783832/socks5-proxy-using-sslsocket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!