more work to get bridge VPN mode to work
This commit is contained in:
parent
0fc3805997
commit
b2ec768d8d
|
@ -218,7 +218,6 @@ public class HttpProxy extends Thread
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Socket client = server.accept();
|
Socket client = server.accept();
|
||||||
HttpProxy.vpnService.protect(client);
|
|
||||||
ProxyThread t = new ProxyThread(client, fwdServer, fwdPort);
|
ProxyThread t = new ProxyThread(client, fwdServer, fwdPort);
|
||||||
t.setDebug(debugLevel, debugOut);
|
t.setDebug(debugLevel, debugOut);
|
||||||
t.setTimeout(ptTimeout);
|
t.setTimeout(ptTimeout);
|
||||||
|
@ -331,6 +330,7 @@ class ProxyThread extends Thread
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
server = SocketChannel.open().socket();
|
server = SocketChannel.open().socket();
|
||||||
|
InetSocketAddress remoteHost = new InetSocketAddress(hostName, hostPort);
|
||||||
|
|
||||||
if ((null != server) && (null != HttpProxy.vpnService)) {
|
if ((null != server) && (null != HttpProxy.vpnService)) {
|
||||||
HttpProxy.vpnService.protect(server);
|
HttpProxy.vpnService.protect(server);
|
||||||
|
@ -338,18 +338,13 @@ class ProxyThread extends Thread
|
||||||
|
|
||||||
if ((fwdServer.length() > 0) && (fwdPort > 0))
|
if ((fwdServer.length() > 0) && (fwdPort > 0))
|
||||||
{
|
{
|
||||||
//server = new Socket(fwdServer, fwdPort);
|
|
||||||
server.connect(new InetSocketAddress(fwdServer, fwdPort));
|
server.connect(new InetSocketAddress(fwdServer, fwdPort));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//server = new Socket(hostName, hostPort);
|
server.connect(remoteHost);
|
||||||
server.connect(new InetSocketAddress(hostName, hostPort));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HttpProxy.vpnService.protect(server);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// tell the client there was an error
|
// tell the client there was an error
|
||||||
String errMsg = "HTTP/1.0 500\nContent Type: text/plain\n\n" +
|
String errMsg = "HTTP/1.0 500\nContent Type: text/plain\n\n" +
|
||||||
|
@ -360,31 +355,56 @@ class ProxyThread extends Thread
|
||||||
if (server != null)
|
if (server != null)
|
||||||
{
|
{
|
||||||
server.setSoTimeout(socketTimeout);
|
server.setSoTimeout(socketTimeout);
|
||||||
|
|
||||||
|
|
||||||
BufferedInputStream serverIn = new BufferedInputStream(server.getInputStream());
|
BufferedInputStream serverIn = new BufferedInputStream(server.getInputStream());
|
||||||
BufferedOutputStream serverOut = new BufferedOutputStream(server.getOutputStream());
|
BufferedOutputStream serverOut = new BufferedOutputStream(server.getOutputStream());
|
||||||
|
|
||||||
// send the request out
|
if (requestLength > 0)
|
||||||
serverOut.write(request, 0, requestLength);
|
|
||||||
serverOut.flush();
|
|
||||||
|
|
||||||
// and get the response; if we're not at a debug level that
|
|
||||||
// requires us to return the data in the response, just stream
|
|
||||||
// it back to the client to save ourselves from having to
|
|
||||||
// create and destroy an unnecessary byte array. Also, we
|
|
||||||
// should set the waitForDisconnect parameter to 'true',
|
|
||||||
// because some servers (like Google) don't always set the
|
|
||||||
// Content-Length header field, so we have to listen until
|
|
||||||
// they decide to disconnect (or the connection times out).
|
|
||||||
if (debugLevel > 1)
|
|
||||||
{
|
{
|
||||||
response = getHTTPData(serverIn, true);
|
// send the request out
|
||||||
responseLength = Array.getLength(response);
|
serverOut.write(request, 0, requestLength);
|
||||||
} else {
|
serverOut.flush();
|
||||||
responseLength = streamHTTPData(serverIn, clientOut, true);
|
|
||||||
|
// and get the response; if we're not at a debug level that
|
||||||
|
// requires us to return the data in the response, just stream
|
||||||
|
// it back to the client to save ourselves from having to
|
||||||
|
// create and destroy an unnecessary byte array. Also, we
|
||||||
|
// should set the waitForDisconnect parameter to 'true',
|
||||||
|
// because some servers (like Google) don't always set the
|
||||||
|
// Content-Length header field, so we have to listen until
|
||||||
|
// they decide to disconnect (or the connection times out).
|
||||||
|
if (debugLevel > 1)
|
||||||
|
{
|
||||||
|
response = getHTTPData(serverIn, true);
|
||||||
|
responseLength = Array.getLength(response);
|
||||||
|
} else {
|
||||||
|
responseLength = streamHTTPData(serverIn, clientOut, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
serverIn.close();
|
||||||
|
serverOut.close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
byte[] buffer = new byte[4096];
|
||||||
|
|
||||||
|
int avail = clientIn.available();
|
||||||
|
while (avail > 0 && (i = clientIn.read(buffer,0,avail))!=-1)
|
||||||
|
{
|
||||||
|
serverOut.write(buffer,0,i);
|
||||||
|
avail = clientIn.available();
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((i = serverIn.read(buffer))!=-1)
|
||||||
|
clientOut.write(buffer,0,i);
|
||||||
|
|
||||||
|
clientOut.close();
|
||||||
|
clientIn.close();
|
||||||
|
pSocket.close();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
serverIn.close();
|
|
||||||
serverOut.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// send the response back to the client, if we haven't already
|
// send the response back to the client, if we haven't already
|
||||||
|
@ -488,6 +508,16 @@ class ProxyThread extends Thread
|
||||||
debugOut.println("Error parsing response code " + rcString);
|
debugOut.println("Error parsing response code " + rcString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//CONNECT www.comodo.com:443 HTTP/1.1
|
||||||
|
|
||||||
|
else if (data.toLowerCase().startsWith("connect "))
|
||||||
|
{
|
||||||
|
|
||||||
|
String connectHost = data.substring(pos+1, data.indexOf(" ", pos+1));
|
||||||
|
host.append(connectHost);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the rest of the header info
|
// get the rest of the header info
|
||||||
|
|
|
@ -16,16 +16,12 @@
|
||||||
|
|
||||||
package org.torproject.android.vpn;
|
package org.torproject.android.vpn;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.torproject.android.service.TorServiceConstants;
|
import org.torproject.android.service.TorServiceConstants;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.Notification;
|
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.VpnService;
|
import android.net.VpnService;
|
||||||
|
|
Loading…
Reference in New Issue