-
Notifications
You must be signed in to change notification settings - Fork 9.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SOCKS proxy not working on Android platform #2315
Comments
Seems it's a bug inside Android Socket implementation. SOCKS working fine on Oracle JRE and OpenJDK JRE, and I looked into their code: if (epoint.isUnresolved())
impl.connect(addr.getHostName(), port);
else
impl.connect(addr, port); That's what I found in Android framework: InetSocketAddress inetAddr = (InetSocketAddress) remoteAddr;
InetAddress addr;
if ((addr = inetAddr.getAddress()) == null) {
throw new UnknownHostException("Host is unresolved: " + inetAddr.getHostName());
}
int port = inetAddr.getPort();
checkDestination(addr, port);
synchronized (connectLock) {
try {
if (!isBound()) {
// socket already created at this point by earlier call or
// checkOpenAndCreate this caused us to lose socket
// options on create
// impl.create(true);
if (!usingSocks()) {
impl.bind(Inet6Address.ANY, 0);
}
isBound = true;
}
impl.connect(remoteAddr, timeout);
isConnected = true;
cacheLocalAddress();
} catch (IOException e) {
impl.close();
throw e;
}
} Android only accept resolved |
Could you report this issue upstream to AOSP? I’m not particularly eager to implement a SOCKS proxy inside of OkHttp. You might need to implement your own SocketFactory that implements SOCKS. |
No action for us to take on this. |
This is currently nonfunctional due to an interaction between InetAddress.createUnresolved and the SOCKS 4 protocol. Fixes square#2315
This is currently nonfunctional due to an interaction between InetAddress.createUnresolved and the SOCKS 4 protocol. Fixes square#2315
Currently, setting a SOCKS proxy in OkHttpClient.Builder silently overrides any custom DNS setting. This changes behavior for users who are currently using both settings in a single Builder, but any such usage is likely already buggy because the custom DNS setting is being ignored. This also fixes square#2315 (SOCKS 4 support) if users "opt in" by adding a custom DNS setting in their Builder.
Currently, setting a SOCKS proxy in OkHttpClient.Builder silently overrides any custom DNS setting. This changes behavior for users who are currently using both settings in a single Builder, but any such usage is likely already buggy because the custom DNS setting is being ignored. This also fixes square#2315 (SOCKS 4 support) if users "opt in" by adding a custom DNS setting in their Builder.
SOCKS proxy is completely broken on Android. When I set up SOCKS proxy in my app, all requests failed, when I wrote an instrumentation test, I found even create a default okhttp instance with a SOCKS proxy, it fails.
Here's the stack trace:
Sample code:
The text was updated successfully, but these errors were encountered: