add support for meek PT

This commit is contained in:
Nathan Freitas 2015-02-14 00:44:09 -05:00
parent 1e5651eec3
commit bff6d0f567
3 changed files with 165 additions and 81 deletions

View File

@ -99,6 +99,12 @@ public class TorResourceInstaller implements TorServiceConstants {
shell.add(new SimpleCommand(COMMAND_RM_FORCE + outFile.getAbsolutePath())).waitForFinish(); shell.add(new SimpleCommand(COMMAND_RM_FORCE + outFile.getAbsolutePath())).waitForFinish();
streamToFile(is,outFile, false, true); streamToFile(is,outFile, false, true);
is = context.getResources().openRawResource(R.raw.meek);
outFile = new File(installFolder, MEEK_ASSET_KEY);
shell.add(new SimpleCommand(COMMAND_RM_FORCE + outFile.getAbsolutePath())).waitForFinish();
streamToFile(is,outFile, false, true);
is = context.getResources().openRawResource(R.raw.xtables); is = context.getResources().openRawResource(R.raw.xtables);
outFile = new File(installFolder, IPTABLES_ASSET_KEY); outFile = new File(installFolder, IPTABLES_ASSET_KEY);
shell.add(new SimpleCommand(COMMAND_RM_FORCE + outFile.getAbsolutePath())).waitForFinish(); shell.add(new SimpleCommand(COMMAND_RM_FORCE + outFile.getAbsolutePath())).waitForFinish();

View File

@ -115,6 +115,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
private File fileTor; private File fileTor;
private File filePolipo; private File filePolipo;
private File fileObfsclient; private File fileObfsclient;
private File fileMeekclient;
private File fileXtables; private File fileXtables;
private File fileTorRc; private File fileTorRc;
@ -650,6 +651,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
fileObfsclient = new File(appBinHome, OBFSCLIENT_ASSET_KEY); fileObfsclient = new File(appBinHome, OBFSCLIENT_ASSET_KEY);
fileMeekclient = new File(appBinHome, MEEK_ASSET_KEY);
fileTorRc = new File(appBinHome, TORRC_ASSET_KEY); fileTorRc = new File(appBinHome, TORRC_ASSET_KEY);
fileXtables = new File(appBinHome, IPTABLES_ASSET_KEY); fileXtables = new File(appBinHome, IPTABLES_ASSET_KEY);
@ -770,6 +773,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
prefPersistNotifications = prefs.getBoolean(TorConstants.PREF_PERSIST_NOTIFICATIONS, true); prefPersistNotifications = prefs.getBoolean(TorConstants.PREF_PERSIST_NOTIFICATIONS, true);
mUseVPN = prefs.getBoolean("pref_vpn", false);
} }
private void startTor () throws Exception private void startTor () throws Exception
@ -784,6 +788,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
enableBinExec(fileTor); enableBinExec(fileTor);
enableBinExec(filePolipo); enableBinExec(filePolipo);
enableBinExec(fileObfsclient); enableBinExec(fileObfsclient);
enableBinExec(fileMeekclient);
enableBinExec(fileXtables); enableBinExec(fileXtables);
updateSettings (); updateSettings ();
@ -791,7 +796,12 @@ public class TorService extends Service implements TorServiceConstants, TorConst
logNotice(getString(R.string.status_starting_up)); logNotice(getString(R.string.status_starting_up));
sendCallbackLogMessage(getString(R.string.status_starting_up)); sendCallbackLogMessage(getString(R.string.status_starting_up));
Shell shellUser = Shell.startShell(); ArrayList<String> customEnv = new ArrayList<String>();
// customEnv.add("TOR_PT_MANAGED_TRANSPORT_VER=1");
// customEnv.add("TOR_PT_CLIENT_TRANSPORTS=meek");
String baseDirectory = fileTor.getParent();
Shell shellUser = Shell.startShell(customEnv, baseDirectory);
boolean success = runTorShellCmd(shellUser); boolean success = runTorShellCmd(shellUser);
@ -809,11 +819,13 @@ public class TorService extends Service implements TorServiceConstants, TorConst
shellRoot.close(); shellRoot.close();
} }
else if (mUseVPN)
if (mUseVPN) //we need to turn on VPN here so the proxy is running
{ {
enableVpnProxy(); enableVpnProxy();
} }
getHiddenServiceHostname (); getHiddenServiceHostname ();
} }
else else
@ -1434,12 +1446,18 @@ public class TorService extends Service implements TorServiceConstants, TorConst
SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext()); SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
Editor ePrefs = prefs.edit(); Editor ePrefs = prefs.edit();
ePrefs.putBoolean("pref_vpn", true);
/*
ePrefs.putString("pref_proxy_type", "socks5"); ePrefs.putString("pref_proxy_type", "socks5");
ePrefs.putString("pref_proxy_host", "127.0.0.1"); ePrefs.putString("pref_proxy_host", "127.0.0.1");
ePrefs.putString("pref_proxy_port", "9999"); ePrefs.putString("pref_proxy_port", "9999");
ePrefs.remove("pref_proxy_username"); ePrefs.remove("pref_proxy_username");
ePrefs.remove("pref_proxy_password"); ePrefs.remove("pref_proxy_password");
*/
ePrefs.commit(); ePrefs.commit();
processSettings(); processSettings();
Intent intent = new Intent(TorService.this, OrbotVpnService.class); Intent intent = new Intent(TorService.this, OrbotVpnService.class);
@ -1455,14 +1473,12 @@ public class TorService extends Service implements TorServiceConstants, TorConst
mUseVPN = false; mUseVPN = false;
SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext()); SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
Editor ePrefs = prefs.edit(); Editor ePrefs = prefs.edit();
ePrefs.remove("pref_proxy_type"); ePrefs.putBoolean("pref_vpn", false);
ePrefs.remove("pref_proxy_host");
ePrefs.remove("pref_proxy_port");
ePrefs.remove("pref_proxy_username");
ePrefs.remove("pref_proxy_password");
ePrefs.commit(); ePrefs.commit();
processSettings(); processSettings();
Intent intent = new Intent(TorService.this, OrbotVpnService.class); Intent intent = new Intent(TorService.this, OrbotVpnService.class);
@ -2091,8 +2107,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
boolean useBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_ENABLED, false); boolean useBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_ENABLED, false);
//boolean autoUpdateBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_UPDATED, false);
boolean becomeRelay = prefs.getBoolean(TorConstants.PREF_OR, false); boolean becomeRelay = prefs.getBoolean(TorConstants.PREF_OR, false);
boolean ReachableAddresses = prefs.getBoolean(TorConstants.PREF_REACHABLE_ADDRESSES,false); boolean ReachableAddresses = prefs.getBoolean(TorConstants.PREF_REACHABLE_ADDRESSES,false);
boolean enableHiddenServices = prefs.getBoolean("pref_hs_enable", false); boolean enableHiddenServices = prefs.getBoolean("pref_hs_enable", false);
@ -2102,35 +2116,49 @@ public class TorService extends Service implements TorServiceConstants, TorConst
String exitNodes = prefs.getString("pref_exit_nodes", ""); String exitNodes = prefs.getString("pref_exit_nodes", "");
String excludeNodes = prefs.getString("pref_exclude_nodes", ""); String excludeNodes = prefs.getString("pref_exclude_nodes", "");
String proxyType = prefs.getString("pref_proxy_type", null); if (!useBridges)
if (proxyType != null && proxyType.length() > 0)
{ {
String proxyHost = prefs.getString("pref_proxy_host", null); if (mUseVPN) //set the proxy here if we aren't using a bridge
String proxyPort = prefs.getString("pref_proxy_port", null); {
String proxyUser = prefs.getString("pref_proxy_username", null); String proxyType = "socks5";
String proxyPass = prefs.getString("pref_proxy_password", null); String proxyHost = "127.0.0.1";
int proxyPort = 9999;
updateConfiguration(proxyType + "Proxy", proxyHost + ':' + proxyPort, false);
if ((proxyHost != null && proxyHost.length()>0) && (proxyPort != null && proxyPort.length() > 0)) }
{ else
updateConfiguration(proxyType + "Proxy", proxyHost + ':' + proxyPort, false); {
String proxyType = prefs.getString("pref_proxy_type", null);
if (proxyType != null && proxyType.length() > 0)
{
String proxyHost = prefs.getString("pref_proxy_host", null);
String proxyPort = prefs.getString("pref_proxy_port", null);
String proxyUser = prefs.getString("pref_proxy_username", null);
String proxyPass = prefs.getString("pref_proxy_password", null);
if (proxyUser != null && proxyPass != null) if ((proxyHost != null && proxyHost.length()>0) && (proxyPort != null && proxyPort.length() > 0))
{ {
if (proxyType.equalsIgnoreCase("socks5")) updateConfiguration(proxyType + "Proxy", proxyHost + ':' + proxyPort, false);
{
updateConfiguration("Socks5ProxyUsername", proxyUser, false);
updateConfiguration("Socks5ProxyPassword", proxyPass, false);
}
else
updateConfiguration(proxyType + "ProxyAuthenticator", proxyUser + ':' + proxyPort, false);
} if (proxyUser != null && proxyPass != null)
else if (proxyPass != null) {
updateConfiguration(proxyType + "ProxyAuthenticator", proxyUser + ':' + proxyPort, false); if (proxyType.equalsIgnoreCase("socks5"))
{
updateConfiguration("Socks5ProxyUsername", proxyUser, false);
updateConfiguration("Socks5ProxyPassword", proxyPass, false);
}
else
updateConfiguration(proxyType + "ProxyAuthenticator", proxyUser + ':' + proxyPort, false);
}
else if (proxyPass != null)
updateConfiguration(proxyType + "ProxyAuthenticator", proxyUser + ':' + proxyPort, false);
} }
}
}
} }
if (entranceNodes.length() > 0 || exitNodes.length() > 0 || excludeNodes.length() > 0) if (entranceNodes.length() > 0 || exitNodes.length() > 0 || excludeNodes.length() > 0)
@ -2173,56 +2201,101 @@ public class TorService extends Service implements TorServiceConstants, TorConst
String bridgeList = prefs.getString(TorConstants.PREF_BRIDGES_LIST,null); String bridgeList = prefs.getString(TorConstants.PREF_BRIDGES_LIST,null);
if (bridgeList == null || bridgeList.length() == 0) if (bridgeList != null && bridgeList.length() > 1) //longer then 1 = some real values here
{ {
String msgBridge = getString(R.string.bridge_requires_ip) + String bridgeDelim = "\n";
getString(R.string.send_email_for_bridges);
showToolbarNotification(msgBridge, ERROR_NOTIFY_ID, R.drawable.ic_stat_tor);
debug(msgBridge);
return false; if (bridgeList.indexOf(",") != -1)
} {
bridgeDelim = ",";
}
showToolbarNotification(getString(R.string.notification_using_bridges) + ": " + bridgeList, TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor);
String bridgeDelim = "\n"; StringTokenizer st = new StringTokenizer(bridgeList,bridgeDelim);
while (st.hasMoreTokens())
{
String bridgeConfigLine = st.nextToken().trim();
debug("Adding bridge: " + bridgeConfigLine);
updateConfiguration(bridgeCfgKey, bridgeConfigLine, false);
if (bridgeList.indexOf(",") != -1) }
{
bridgeDelim = ",";
}
showToolbarNotification(getString(R.string.notification_using_bridges) + ": " + bridgeList, TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor); //check if any PT bridges are needed
boolean obfsBridges = bridgeList.contains("obfs2")||bridgeList.contains("obfs3")||bridgeList.contains("scramblesuit");
StringTokenizer st = new StringTokenizer(bridgeList,bridgeDelim); if (obfsBridges)
while (st.hasMoreTokens()) {
{ String bridgeConfig = "obfs2,obfs3,scramblesuit exec " + fileObfsclient.getCanonicalPath();
String bridgeConfigLine = st.nextToken().trim();
debug("Adding bridge: " + bridgeConfigLine);
updateConfiguration(bridgeCfgKey, bridgeConfigLine, false);
} debug ("Using OBFUSCATED bridges: " + bridgeConfig);
//check if any PT bridges are needed updateConfiguration("ClientTransportPlugin",bridgeConfig, false);
boolean obfsBridges = bridgeList.contains("obfs2")||bridgeList.contains("obfs3")||bridgeList.contains("scramblesuit"); }
if (obfsBridges)
{
String bridgeConfig = "obfs2,obfs3,scramblesuit exec " + fileObfsclient.getCanonicalPath();
debug ("Using OBFUSCATED bridges: " + bridgeConfig);
updateConfiguration("ClientTransportPlugin",bridgeConfig, false);
} }
else else
{ {
debug ("Using standard bridges"); //time to do autobridges, aka meek
debug ("Using meek bridges");
String proxyBridge = "";
String proxyType = prefs.getString("pref_proxy_type", null);
if (mUseVPN)
{
proxyType = "socks5";
String proxyHost = "127.0.0.1";
int proxyPort = 9999;
proxyBridge = " proxyurl=" + proxyType + "://" + proxyHost + ':' + proxyPort;
}
else if (proxyType != null && proxyType.length() > 0)
{
String proxyHost = prefs.getString("pref_proxy_host", null);
String proxyPort = prefs.getString("pref_proxy_port", null);
proxyBridge = " proxyurl=" + proxyType + "://" + proxyHost + ':' + proxyPort;
}
String[] meekBridge =
{
"meek 0.0.2.0:1 url=https://meek-reflect.appspot.com/ front=www.google.com",
"meek 0.0.2.0:2 url=https://d2zfqthxsdq309.cloudfront.net/ front=a0.awsstatic.com",
"meek 0.0.2.0:3 url=https://az668014.vo.msecnd.net/ front=ajax.aspnetcdn.com"
};
int meekIdx = 2; //let's use Azure by default
if (bridgeList != null && bridgeList.length() == 1)
{
try
{
meekIdx = Integer.parseInt(bridgeList);
if (meekIdx+1 > meekBridge.length)
throw new Exception("not valid meek idx");
}
catch (Exception e)
{
debug("invalid meek type; please enter 0=Google, 1=AWS, 2=Azure");
}
}
updateConfiguration(bridgeCfgKey, meekBridge[meekIdx] + proxyBridge, false);
String bridgeConfig = "meek exec " + fileMeekclient.getCanonicalPath();// + " --log /data/local/tmp/meek-tor.log";
//updateConfiguration(bridgeCfgKey, "meek 0.0.2.0:1", false);
//String bridgeConfig = "meek exec " + fileMeekclient.getCanonicalPath() + " --url=https://meek-reflect.appspot.com/ --front=www.google.com --log meek-client.log";
updateConfiguration("ClientTransportPlugin",bridgeConfig, false);
} }
// updateConfiguration("UpdateBridgesFromAuthority", "0", false);
updateConfiguration("UpdateBridgesFromAuthority", "0", false);
updateConfiguration("UseBridges", "1", false); updateConfiguration("UseBridges", "1", false);

View File

@ -92,6 +92,11 @@ public interface TorServiceConstants {
//obfsproxy //obfsproxy
public static final String OBFSCLIENT_ASSET_KEY = "obfsclient"; public static final String OBFSCLIENT_ASSET_KEY = "obfsclient";
public static final String MEEK_ASSET_KEY = "meek-client";
public static final int MESSAGE_TRAFFIC_COUNT = 5; public static final int MESSAGE_TRAFFIC_COUNT = 5;