fixes for settings processing and QRCode scanning of bridges

- support new JSON array form bridges.torproject.org
- only enable TransProxy and DNSPort settings if the user enables transproxy
This commit is contained in:
Nathan Freitas 2016-01-12 23:57:37 -05:00
parent 4b31ef849a
commit 8f7165ce57
4 changed files with 55 additions and 74 deletions

View File

@ -56,6 +56,8 @@ import android.widget.ToggleButton;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import org.json.JSONArray;
import org.json.JSONObject;
import org.torproject.android.service.TorService;
import org.torproject.android.service.TorServiceConstants;
import org.torproject.android.service.TorServiceUtils;
@ -263,11 +265,11 @@ public class OrbotMainActivity extends Activity
boolean useVPN = Prefs.useVpn();
mBtnVPN.setChecked(useVPN);
/**
//auto start VPN if VPN is enabled
if (useVPN)
{
startActivity(new Intent(OrbotMainActivity.this,VPNEnableActivity.class));
}*/
}
mBtnVPN.setOnClickListener(new View.OnClickListener ()
{
@ -827,16 +829,31 @@ public class OrbotMainActivity extends Activity
if (results != null && results.length() > 0)
{
try {
results = URLDecoder.decode(results, "UTF-8");
int urlIdx = results.indexOf("://");
if (urlIdx!=-1)
{
results = URLDecoder.decode(results, "UTF-8");
results = results.substring(urlIdx+3);
setNewBridges(results);
}
else
{
JSONArray bridgeJson = new JSONArray(results);
StringBuffer bridgeLines = new StringBuffer();
} catch (UnsupportedEncodingException e) {
for (int i = 0; i < bridgeJson.length(); i++)
{
String bridgeLine = bridgeJson.getString(i);
bridgeLines.append(bridgeLine).append("\n");
}
setNewBridges(bridgeLines.toString());
}
} catch (Exception e) {
Log.e(TAG,"unsupported",e);
}
}

View File

@ -133,6 +133,8 @@ public class TorResourceInstaller implements TorServiceConstants {
streamToFile(is,outFile, false, true);
setExecutable(outFile);
installGeoIP();
return true;
}
@ -196,14 +198,14 @@ public class TorResourceInstaller implements TorServiceConstants {
* Extract the Tor binary from the APK file using ZIP
*/
public boolean installGeoIP () throws IOException, FileNotFoundException
private boolean installGeoIP () throws IOException, FileNotFoundException
{
InputStream is;
File outFile;
is = context.getResources().openRawResource(R.raw.geoip);
outFile = new File(installFolder, GEOIP_ASSET_KEY);
is = context.getResources().openRawResource(R.raw.geoip);
streamToFile(is, outFile, false, true);
is = context.getResources().openRawResource(R.raw.geoip6);

View File

@ -621,8 +621,8 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
fileControlPort = new File(OrbotApp.appBinHome, "control.txt");
extraLines.append(TORRC_CONTROLPORT_FILE_KEY).append(' ').append(fileControlPort.getCanonicalPath()).append('\n');
extraLines.append("RunAsDaemon 1").append('\n');
extraLines.append("AvoidDiskWrites 1").append('\n');
// extraLines.append("RunAsDaemon 1").append('\n');
// extraLines.append("AvoidDiskWrites 1").append('\n');
String socksPortPref = prefs.getString(OrbotConstants.PREF_SOCKS,
String.valueOf(TorServiceConstants.SOCKS_PROXY_PORT_DEFAULT));
@ -634,8 +634,14 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
extraLines.append("TestSocks 0").append('\n');
extraLines.append("WarnUnsafeSocks 1").append('\n');
extraLines.append("TransPort ").append("auto").append('\n');
extraLines.append("DNSPort ").append(TorServiceConstants.TOR_DNS_PORT_DEFAULT).append("\n");
if (Prefs.useTransparentProxying())
{
String transPort = prefs.getString("pref_transport", TorServiceConstants.TOR_TRANSPROXY_PORT_DEFAULT+"");
String dnsPort = prefs.getString("pref_dnsport", TorServiceConstants.TOR_DNS_PORT_DEFAULT+"");
extraLines.append("TransPort ").append(transPort).append('\n');
extraLines.append("DNSPort ").append(dnsPort).append("\n");
if (Prefs.transparentTethering())
{
@ -646,6 +652,8 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
extraLines.append("VirtualAddrNetwork 10.192.0.0/10").append('\n');
extraLines.append("AutomapHostsOnResolve 1").append('\n');
}
extraLines.append("DisableNetwork 0").append('\n');
if (Prefs.useDebugLogging())
@ -654,7 +662,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
extraLines.append("Log info syslog").append('\n');
extraLines.append("SafeLogging 0").append('\n');
//extraLines.append("Log debug stdout").append('\n');
}
processSettingsImpl(extraLines);
@ -1937,17 +1944,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
/*
String socksConfig = prefs.getString(TorConstants.PREF_SOCKS, TorServiceConstants.PORT_SOCKS_DEFAULT);
enableSocks (socksConfig,false);
String transPort = prefs.getString("pref_transport", TorServiceConstants.TOR_TRANSPROXY_PORT_DEFAULT+"");
String dnsPort = prefs.getString("pref_dnsport", TorServiceConstants.TOR_DNS_PORT_DEFAULT+"");
enableTransProxyAndDNSPorts(transPort, dnsPort);
*/
boolean useBridges = Prefs.bridgesEnabled();
boolean becomeRelay = prefs.getBoolean(OrbotConstants.PREF_OR, false);
@ -2034,11 +2030,11 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
for (String bridgeConfigLine : bridgeListLines)
{
if (bridgeConfigLine != null && bridgeConfigLine.length() > 0)
if (!TextUtils.isEmpty(bridgeConfigLine))
{
extraLines.append("Bridge ");
bridgeConfigLine = bridgeConfigLine.replace('<27>', ' ');
//bridgeConfigLine = bridgeConfigLine.replace('<27>', ' ');
StringTokenizer st = new StringTokenizer (bridgeConfigLine," ");
while (st.hasMoreTokens())
@ -2093,14 +2089,12 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
if (entranceNodes.length() > 0 || exitNodes.length() > 0 || excludeNodes.length() > 0)
{
if (enableGeoIP ())
{ //only apply GeoIP if you need it
//only apply GeoIP if you need it
File fileGeoIP = new File(OrbotApp.appBinHome, GEOIP_ASSET_KEY);
File fileGeoIP6 = new File(OrbotApp.appBinHome, GEOIP6_ASSET_KEY);
extraLines.append("GeoIPFile" + ' ' + fileGeoIP.getCanonicalPath()).append('\n');
extraLines.append("GeoIPv6File" + ' ' + fileGeoIP6.getCanonicalPath()).append('\n');
}
}
@ -2354,9 +2348,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
{
try
{
enableGeoIP ();
File fileGeoIP = new File(OrbotApp.appBinHome, GEOIP_ASSET_KEY);
File fileGeoIP6 = new File(OrbotApp.appBinHome, GEOIP6_ASSET_KEY);
@ -2370,8 +2361,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
conn.setConf("DisableNetwork","0");
}
catch (IOException ioe)
{
@ -2380,33 +2369,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
}
}
}
private boolean enableGeoIP ()
{
File fileGeoIP = new File(OrbotApp.appBinHome, GEOIP_ASSET_KEY);
File fileGeoIP6 = new File(OrbotApp.appBinHome, GEOIP6_ASSET_KEY);
try
{
if ((!fileGeoIP.exists()))
{
TorResourceInstaller installer = new TorResourceInstaller(this, OrbotApp.appBinHome);
boolean success = installer.installGeoIP();
}
return true;
}
catch (Exception e)
{
showToolbarNotification (getString(R.string.error_installing_binares),ERROR_NOTIFY_ID,R.drawable.ic_stat_notifyerr);
return false;
}
}
}

View File

@ -150,7 +150,7 @@ public interface TorServiceConstants {
public final static String PDNSD_ASSET_KEY = "pdnsd";
//EXIT COUNTRY CODES
public final static String[] COUNTRY_CODES = {"DE","AT","SE","CH","IS","CA","US","FR","BG","AU","BR","CZ","DK","FI","GB","HU","NL","JP","HK","RO","RU","SG","SK","CN"};
public final static String[] COUNTRY_CODES = {"DE","AT","SE","CH","IS","CA","US","ES","FR","BG","PL","AU","BR","CZ","DK","FI","GB","HU","NL","JP","RO","RU","SG","SK"};
}