Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8129444

socksProxyVersion system property ignored for Socket(Proxy)

    XMLWordPrintable

Details

    • b73
    • Verified

    Backports

      Description

        If a socket was created with Socket(Proxy) constructor [1] like the following

        Socket s = new Socket(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("socks.mydom.com", 1080)));

        , then it doesn't take into account "socksProxyVersion" system property. As a result, it is not possible to use SOCKS V4 (V5 is used by default [2]).

        Please see Socket(Proxy) constructor:

        http://hg.openjdk.java.net/jdk9/dev/jdk/file/0bc25016547c/src/java.base/share/classes/java/net/Socket.java#l117

        ...
            public Socket(Proxy proxy) {
        ...
                Proxy p = proxy == Proxy.NO_PROXY ? Proxy.NO_PROXY
                                                  : sun.net.ApplicationProxy.create(proxy);
                Proxy.Type type = p.type();
                if (type == Proxy.Type.SOCKS || type == Proxy.Type.HTTP) {
        ...
                    impl = type == Proxy.Type.SOCKS ? new SocksSocketImpl(p)
                                                    : new HttpConnectSocketImpl(p);
                    impl.setSocket(this);
                } else {
        ...
            }
        ...

        SocksSocketImpl(Proxy) constructor doesn't check if SOCKS protocol version was specified:

        http://hg.openjdk.java.net/jdk9/dev/jdk/file/0bc25016547c/src/java.base/share/classes/java/net/SocksSocketImpl.java#l64

        ...
            SocksSocketImpl(Proxy proxy) {
                SocketAddress a = proxy.address();
                if (a instanceof InetSocketAddress) {
                    InetSocketAddress ad = (InetSocketAddress) a;
                    // Use getHostString() to avoid reverse lookups
                    server = ad.getHostString();
                    serverPort = ad.getPort();
                }
            }
        ...

        This may be fixed by updating SocksSocketImpl(Proxy) constructor to check if SOCKS V4 was specified by "socksProxyVersion" system property. Also such a check should be added to SocksSocketImpl.connect() and SocksSocketImpl.socksBind() methods. Please see the webrev below:

        http://cr.openjdk.java.net/~asmotrak/socks4/webrev.00/

        This fix also makes DefaultProxySelector read "socksProxyVersion" once during class initialization. This way, apps in the same jvm can't affect each other unexpectedly.

        java/net/Socket/SocksProxy.java test in the webrev above reproduces the problem.

        This is not a regression. Latest JDK 9 ws, JDK 8 b132 fcs, JDK 7 b147 fcs have this issue.

        [1] http://docs.oracle.com/javase/8/docs/api/java/net/Socket.html#Socket-java.net.Proxy-
        [2] http://docs.oracle.com/javase/8/docs/api/java/net/doc-files/net-properties.html

        Attachments

          Issue Links

            Activity

              People

                asmotrak Artem Smotrakov
                asmotrak Artem Smotrakov
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: