Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8136098 | emb-9 | Artem Smotrakov | P3 | Resolved | Fixed | team |
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
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
- backported by
-
JDK-8136098 socksProxyVersion system property ignored for Socket(Proxy)
-
- Resolved
-