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

SOCKS proxying does not work with IPv6 connections

XMLWordPrintable

    • b02
    • x86
    • linux_redhat_5.0

        FULL PRODUCT VERSION :
        java version "1.7.0"
        Java(TM) SE Runtime Environment (build 1.7.0-b147)
        Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Red Hat Enterprise Linux Server release 5.6 (kernel version 2.6.18-238.1.1.el5)

        A DESCRIPTION OF THE PROBLEM :
        When proxying an IPv6 connection through a SOCKS proxy there are extra 16 bytes of "garbage" response together with the payload response from the remote server.

        The "garbage" response is nothing but the last 14 bytes of the IP address and 2 bytes representing the port number.

        The culprit is the following in java.net.SocksSocketImpl

        case IPV6:
        len = data[1];
        addr = new byte[len];
        i = readSocksReply(in, addr);
        if (i != len)
        throw new SocketException("Reply from SOCKS server badly formatted");

        As per RFC 1928, the second byte of the SOCKS response holds not the length of the address, but the reply code (which in case of success is 0). So readSocksReply() will read 0 bytes for the address and 2 for the port, hence leaving the last 16 bytes of the SOCKS reply unread.

        P.S. This also affects the case of DOMAIN_NAME.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1. Open a URLConnection through a SOCKS proxy (listening on IPv6 address)
        2. Read the response from the remote server.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The remote response without the extra garbage from the socks reply.
        ACTUAL -
        The remote response with the extra 16 bytes of garbage response.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        SocketAddress socksAddr = new InetSocketAddress("ipv6_addr", 1080);
        Proxy socksProxy = new Proxy(Proxy.Type.SOCKS, socksAddr);
        URL url = new URL("url");
        URLConnection urlcon = url.openConnection(socksProxy);
        String inputLine = "";
        BufferedReader bufRead = new BufferedReader(
        new InputStreamReader(urlcon.getInputStream()));
        while ((inputLine = bufRead.readLine()) != null) {
        System.out.println(inputLine);
        }
        ---------- END SOURCE ----------

              chegar Chris Hegarty
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: