more work to get bridge VPN mode to work

This commit is contained in:
Nathan Freitas 2015-02-23 12:29:21 -05:00
parent 0fc3805997
commit b2ec768d8d
2 changed files with 57 additions and 31 deletions

View File

@ -218,7 +218,6 @@ public class HttpProxy extends Thread
while (true)
{
Socket client = server.accept();
HttpProxy.vpnService.protect(client);
ProxyThread t = new ProxyThread(client, fwdServer, fwdPort);
t.setDebug(debugLevel, debugOut);
t.setTimeout(ptTimeout);
@ -331,6 +330,7 @@ class ProxyThread extends Thread
try
{
server = SocketChannel.open().socket();
InetSocketAddress remoteHost = new InetSocketAddress(hostName, hostPort);
if ((null != server) && (null != HttpProxy.vpnService)) {
HttpProxy.vpnService.protect(server);
@ -338,18 +338,13 @@ class ProxyThread extends Thread
if ((fwdServer.length() > 0) && (fwdPort > 0))
{
//server = new Socket(fwdServer, fwdPort);
server.connect(new InetSocketAddress(fwdServer, fwdPort));
} else {
//server = new Socket(hostName, hostPort);
server.connect(new InetSocketAddress(hostName, hostPort));
server.connect(remoteHost);
}
HttpProxy.vpnService.protect(server);
} catch (Exception e) {
// tell the client there was an error
String errMsg = "HTTP/1.0 500\nContent Type: text/plain\n\n" +
@ -360,9 +355,13 @@ class ProxyThread extends Thread
if (server != null)
{
server.setSoTimeout(socketTimeout);
BufferedInputStream serverIn = new BufferedInputStream(server.getInputStream());
BufferedOutputStream serverOut = new BufferedOutputStream(server.getOutputStream());
if (requestLength > 0)
{
// send the request out
serverOut.write(request, 0, requestLength);
serverOut.flush();
@ -386,6 +385,27 @@ class ProxyThread extends Thread
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;
}
}
// send the response back to the client, if we haven't already
if (debugLevel > 1)
@ -488,6 +508,16 @@ class ProxyThread extends Thread
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

View File

@ -16,16 +16,12 @@
package org.torproject.android.vpn;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Locale;
import org.torproject.android.service.TorServiceConstants;
import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.net.VpnService;