tor-commits
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- 1 participants
- 214282 discussions
r24631: {projects} handling settings update to stop hanging (projects/android/trunk/Orbot/src/org/torproject/android)
by Nathan Freitas 15 Apr '11
by Nathan Freitas 15 Apr '11
15 Apr '11
Author: n8fr8
Date: 2011-04-15 16:39:22 +0000 (Fri, 15 Apr 2011)
New Revision: 24631
Modified:
projects/android/trunk/Orbot/src/org/torproject/android/OnBootReceiver.java
projects/android/trunk/Orbot/src/org/torproject/android/Orbot.java
Log:
handling settings update to stop hanging
Modified: projects/android/trunk/Orbot/src/org/torproject/android/OnBootReceiver.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/OnBootReceiver.java 2011-04-15 16:38:53 UTC (rev 24630)
+++ projects/android/trunk/Orbot/src/org/torproject/android/OnBootReceiver.java 2011-04-15 16:39:22 UTC (rev 24631)
@@ -14,5 +14,6 @@
}
+
}
Modified: projects/android/trunk/Orbot/src/org/torproject/android/Orbot.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/Orbot.java 2011-04-15 16:38:53 UTC (rev 24630)
+++ projects/android/trunk/Orbot/src/org/torproject/android/Orbot.java 2011-04-15 16:39:22 UTC (rev 24631)
@@ -16,6 +16,7 @@
import android.app.Activity;
import android.app.AlertDialog;
import android.app.NotificationManager;
+import android.app.ProgressDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
@@ -44,10 +45,10 @@
{
/* Useful UI bits */
- private TextView txtMessageLog = null; //the full screen log view of Tor control messages
+ //private TextView txtMessageLog = null; //the full screen log view of Tor control messages
private TextView lblStatus = null; //the main text display widget
private ImageView imgStatus = null; //the main touchable image for activating Orbot
-// private ProgressDialog progressDialog;
+ private ProgressDialog progressDialog;
private MenuItem mItemOnOff = null;
/* Some tracking bits */
@@ -59,6 +60,8 @@
/* The primary interface we will be calling on the service. */
ITorService mService = null;
private boolean autoStartOnBind = false;
+
+ SharedPreferences prefs;
Orbot mOrbot = null;
@@ -69,9 +72,9 @@
mOrbot = this;
setTheme(android.R.style.Theme_Black_NoTitleBar);
- //setTitle(getString(R.string.app_name) + ' ' + getString(R.string.app_version));
- showMain();
-
+
+ prefs = PreferenceManager.getDefaultSharedPreferences(this);
+
}
/*
@@ -93,8 +96,8 @@
mItem = menu.add(0, 7, Menu.NONE, getString(R.string.menu_verify));
mItem.setIcon(R.drawable.ic_menu_check);
- mItem = menu.add(0,6, Menu.NONE, getString(R.string.menu_log));
- mItem.setIcon(R.drawable.ic_menu_reports);
+ // mItem = menu.add(0,6, Menu.NONE, getString(R.string.menu_log));
+ // mItem.setIcon(R.drawable.ic_menu_reports);
mItem = menu.add(0, 3, Menu.NONE, getString(R.string.menu_info));
mItem.setIcon(R.drawable.ic_menu_about);
@@ -146,10 +149,6 @@
{
showSettings();
}
- else if (item.getItemId() == 6)
- {
- showMessageLog();
- }
else if (item.getItemId() == 3)
{
showHelp();
@@ -193,6 +192,7 @@
* (non-Javadoc)
* @see android.app.Activity#onKeyDown(int, android.view.KeyEvent)
*/
+ /*
public boolean onKeyDown(int keyCode, KeyEvent event){
if(keyCode==KeyEvent.KEYCODE_BACK){
@@ -209,7 +209,7 @@
return super.onKeyDown(keyCode, event);
- }
+ }*/
/* (non-Javadoc)
* @see android.app.Activity#onPause()
@@ -306,7 +306,8 @@
protected void onResume() {
super.onResume();
-
+ showMain();
+
if (getIntent() == null)
return;
@@ -361,7 +362,8 @@
else
{
-
+ //setTitle(getString(R.string.app_name) + ' ' + getString(R.string.app_version));
+
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancelAll();
@@ -382,6 +384,7 @@
new WizardHelper(this).showWizard();
}
+
}
}
@@ -400,9 +403,6 @@
}
-
-
-
/* (non-Javadoc)
* @see android.app.Activity#onStop()
*/
@@ -419,7 +419,7 @@
*/
private void showMain ()
{
- bindService(); //connect the UI activity to the remote service
+ // bindService(); //connect the UI activity to the remote service
currentView = R.layout.layout_main;
setContentView(currentView);
@@ -458,6 +458,7 @@
/*
* Show the message log UI
*/
+ /*
private void showMessageLog ()
{
currentView = R.layout.layout_log;
@@ -469,7 +470,7 @@
txtMessageLog.setText(logBuffer.toString());
- }
+ }*/
/*
@@ -495,19 +496,17 @@
} catch (RemoteException e) {
e.printStackTrace();
}
+
}
}
private void processSettings () throws RemoteException
{
-
try
{
if (mService == null)
return; //nothing to do if the service isn't connected yet
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
-
boolean useBridges = prefs.getBoolean(PREF_BRIDGES_ENABLED, false);
//boolean autoUpdateBridges = prefs.getBoolean(PREF_BRIDGES_UPDATED, false);
@@ -518,12 +517,10 @@
boolean enableHiddenServices = prefs.getBoolean("pref_hs_enable", false);
-
- boolean enableTransparentProxy = prefs.getBoolean(PREF_TRANSPARENT, false);
-
-
+ boolean enableTransparentProxy = prefs.getBoolean(PREF_TRANSPARENT, false);
mService.updateTransProxy();
+
String bridgeList = prefs.getString(PREF_BRIDGES_LIST,"");
if (useBridges)
@@ -648,11 +645,11 @@
}
else
{
- mService.updateConfiguration("HiddenServiceDir","", false);
-
+ mService.updateConfiguration("HiddenServiceDir","", false);
}
mService.saveConfiguration();
+
}
catch (Exception e)
{
@@ -665,6 +662,7 @@
}
+
private String getHiddenServiceHostname ()
{
String appHome = "/data/data/" + TorServiceConstants.TOR_APP_USERNAME + "/";
@@ -709,7 +707,13 @@
{
imgStatus.setImageResource(R.drawable.toron);
// imgStatus.clearAnimation();
+ if (progressDialog != null)
+ {
+ progressDialog.dismiss();
+ progressDialog = null;
+ }
+
String lblMsg = getString(R.string.status_activated) + "\n" + torServiceMsg;
lblStatus.setText(lblMsg);
@@ -753,10 +757,15 @@
{
imgStatus.setImageResource(R.drawable.torstarting);
+ if (progressDialog == null)
+ {
+ progressDialog =ProgressDialog.show(this, "", getString(R.string.status_starting_up));
+ }
+ else
+ progressDialog.setMessage(torServiceMsg);
+ //lblStatus.setText(torServiceMsg);
- lblStatus.setText(torServiceMsg);
-
/*
int idx = torServiceMsg.indexOf("%");
@@ -774,12 +783,23 @@
imgStatus.setImageResource(R.drawable.torstopping);
// imgStatus.clearAnimation();
+ if (progressDialog != null)
+ {
+ progressDialog.dismiss();
+ progressDialog = null;
+ }
+
lblStatus.setText(getString(R.string.status_shutting_down));
}
else
{
+ if (progressDialog != null)
+ {
+ progressDialog.dismiss();
+ progressDialog = null;
+ }
// imgStatus.clearAnimation();
@@ -953,17 +973,9 @@
break;
case LOG_MSG:
-
- String torLogMsg = (String)msg.getData().getString(HANDLER_TOR_MSG);
+ //do nothing
- logBuffer.append(torLogMsg);
- logBuffer.append('\n');
- if (txtMessageLog != null)
- {
- txtMessageLog.append(torLogMsg + '\n');
- }
-
break;
case ENABLE_TOR_MSG:
1
0
r24630: {} adding binaries to res/raw folder (in projects/android/trunk/Orbot/res: . raw)
by Nathan Freitas 15 Apr '11
by Nathan Freitas 15 Apr '11
15 Apr '11
Author: n8fr8
Date: 2011-04-15 16:38:53 +0000 (Fri, 15 Apr 2011)
New Revision: 24630
Added:
projects/android/trunk/Orbot/res/raw/
projects/android/trunk/Orbot/res/raw/busybox_g1
projects/android/trunk/Orbot/res/raw/iptables_g1
projects/android/trunk/Orbot/res/raw/iptables_n1
projects/android/trunk/Orbot/res/raw/privoxy
projects/android/trunk/Orbot/res/raw/privoxy_config
projects/android/trunk/Orbot/res/raw/tor
projects/android/trunk/Orbot/res/raw/torrc
Log:
adding binaries to res/raw folder
Added: projects/android/trunk/Orbot/res/raw/busybox_g1
===================================================================
(Binary files differ)
Property changes on: projects/android/trunk/Orbot/res/raw/busybox_g1
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: projects/android/trunk/Orbot/res/raw/iptables_g1
===================================================================
(Binary files differ)
Property changes on: projects/android/trunk/Orbot/res/raw/iptables_g1
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: projects/android/trunk/Orbot/res/raw/iptables_n1
===================================================================
(Binary files differ)
Property changes on: projects/android/trunk/Orbot/res/raw/iptables_n1
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: projects/android/trunk/Orbot/res/raw/privoxy
===================================================================
(Binary files differ)
Property changes on: projects/android/trunk/Orbot/res/raw/privoxy
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ application/octet-stream
Added: projects/android/trunk/Orbot/res/raw/privoxy_config
===================================================================
--- projects/android/trunk/Orbot/res/raw/privoxy_config (rev 0)
+++ projects/android/trunk/Orbot/res/raw/privoxy_config 2011-04-15 16:38:53 UTC (rev 24630)
@@ -0,0 +1,27 @@
+# Generally, this file goes in /etc/privoxy/config
+#
+# Tor listens as a SOCKS4a proxy here:
+forward-socks4a / 127.0.0.1:9050 .
+confdir /data/data/org.torproject.android
+logdir /data/data/org.torproject.android
+# actionsfile standard # Internal purpose, recommended
+#actionsfile default.action # Main actions file
+#actionsfile user.action # User customizations
+#filterfile default.filter
+
+# Don't log interesting things, only startup messages, warnings and errors
+#logfile logfile
+#jarfile jarfile
+#debug 1
+#debug 0 # show each GET/POST/CONNECT request
+#debug 4096 # Startup banner and warnings
+#debug 8192 # Errors - *we highly recommended enabling this*
+
+#user-manual /usr/share/doc/privoxy/user-manual
+listen-address 127.0.0.1:8118
+toggle 1
+accept-intercepted-requests 1
+enable-remote-toggle 0
+enable-edit-actions 0
+enable-remote-http-toggle 0
+buffer-limit 4096
\ No newline at end of file
Property changes on: projects/android/trunk/Orbot/res/raw/privoxy_config
___________________________________________________________________
Added: svn:executable
+ *
Added: projects/android/trunk/Orbot/res/raw/tor
===================================================================
(Binary files differ)
Property changes on: projects/android/trunk/Orbot/res/raw/tor
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ application/octet-stream
Added: projects/android/trunk/Orbot/res/raw/torrc
===================================================================
--- projects/android/trunk/Orbot/res/raw/torrc (rev 0)
+++ projects/android/trunk/Orbot/res/raw/torrc 2011-04-15 16:38:53 UTC (rev 24630)
@@ -0,0 +1,12 @@
+SocksPort 9050
+SocksListenAddress 127.0.0.1
+SafeSocks 1
+Log notice stdout
+ControlPort 9051
+CookieAuthentication 1
+RelayBandwidthRate 20 KBytes
+RelayBandwidthBurst 20 KBytes
+UseBridges 0
+AutomapHostsOnResolve 1
+TransPort 9040
+DNSPort 5400
1
0
r24629: {} new gibberbot icon for wizard (projects/android/trunk/Orbot/res/drawable)
by Nathan Freitas 15 Apr '11
by Nathan Freitas 15 Apr '11
15 Apr '11
Author: n8fr8
Date: 2011-04-15 16:38:19 +0000 (Fri, 15 Apr 2011)
New Revision: 24629
Added:
projects/android/trunk/Orbot/res/drawable/ic_launcher_gibberbot.png
Log:
new gibberbot icon for wizard
Added: projects/android/trunk/Orbot/res/drawable/ic_launcher_gibberbot.png
===================================================================
(Binary files differ)
Property changes on: projects/android/trunk/Orbot/res/drawable/ic_launcher_gibberbot.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
1
0
r24628: {projects} update to string for wizard with gibberbot link (in projects/android/trunk/Orbot/res: layout values values-ar values-ca values-de values-es values-fa values-mk values-nl values-pl values-ru values-zh)
by Nathan Freitas 15 Apr '11
by Nathan Freitas 15 Apr '11
15 Apr '11
Author: n8fr8
Date: 2011-04-15 16:37:58 +0000 (Fri, 15 Apr 2011)
New Revision: 24628
Modified:
projects/android/trunk/Orbot/res/layout/layout_main.xml
projects/android/trunk/Orbot/res/layout/layout_wizard_tips.xml
projects/android/trunk/Orbot/res/values-ar/strings.xml
projects/android/trunk/Orbot/res/values-ca/strings.xml
projects/android/trunk/Orbot/res/values-de/strings.xml
projects/android/trunk/Orbot/res/values-es/strings.xml
projects/android/trunk/Orbot/res/values-fa/strings.xml
projects/android/trunk/Orbot/res/values-mk/strings.xml
projects/android/trunk/Orbot/res/values-nl/strings.xml
projects/android/trunk/Orbot/res/values-pl/strings.xml
projects/android/trunk/Orbot/res/values-ru/strings.xml
projects/android/trunk/Orbot/res/values-zh/strings.xml
projects/android/trunk/Orbot/res/values/strings.xml
Log:
update to string for wizard with gibberbot link
Modified: projects/android/trunk/Orbot/res/layout/layout_main.xml
===================================================================
--- projects/android/trunk/Orbot/res/layout/layout_main.xml 2011-04-15 16:37:33 UTC (rev 24627)
+++ projects/android/trunk/Orbot/res/layout/layout_main.xml 2011-04-15 16:37:58 UTC (rev 24628)
@@ -58,7 +58,7 @@
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:textStyle="bold"
- android:width="300px"
+ android:width="330px"
android:height="75px"
android:textColor="#ffffff"
/>
Modified: projects/android/trunk/Orbot/res/layout/layout_wizard_tips.xml
===================================================================
--- projects/android/trunk/Orbot/res/layout/layout_wizard_tips.xml 2011-04-15 16:37:33 UTC (rev 24627)
+++ projects/android/trunk/Orbot/res/layout/layout_wizard_tips.xml 2011-04-15 16:37:58 UTC (rev 24628)
@@ -17,7 +17,7 @@
<TextView android:text="@string/wizard_tips_msg" android:layout_gravity="left" android:textColor="#ffffff" android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
-<Button android:text="@string/wizard_tips_otrchat" android:layout_gravity="left" android:drawableLeft="@drawable/icon_otrchat" android:layout_marginTop="10px" android:id="@+id/WizardRootButtonInstallOtrchat" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
+<Button android:text="@string/wizard_tips_otrchat" android:layout_gravity="left" android:drawableLeft="@drawable/ic_launcher_gibberbot" android:layout_marginTop="10px" android:id="@+id/WizardRootButtonInstallOtrchat" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<Button android:text="@string/wizard_tips_orweb" android:drawableLeft="@drawable/icon_orweb" android:layout_marginTop="10px" android:id="@+id/WizardRootButtonInstallOrweb" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
Modified: projects/android/trunk/Orbot/res/values/strings.xml
===================================================================
--- projects/android/trunk/Orbot/res/values/strings.xml 2011-04-15 16:37:33 UTC (rev 24627)
+++ projects/android/trunk/Orbot/res/values/strings.xml 2011-04-15 16:37:58 UTC (rev 24628)
@@ -94,7 +94,7 @@
<string name="wizard_tips_tricks">Orbot-enabled Apps</string>
<string name="wizard_tips_msg">We encourage you to download & use apps that know how to connect directly to Orbot. Click on the buttons below to install.</string>
- <string name="wizard_tips_otrchat">OTRCHAT - Secure instant messaging client for Android</string>
+ <string name="wizard_tips_otrchat">Gibberbot - Secure instant messaging client for Android</string>
<string name="wizard_tips_orweb">ORWEB (Android 1.x Only) - Browser designed for privacy & for Orbot</string>
<string name="wizard_tips_proxy">Proxy Settings - Learn how to configure apps to work with Orbot</string>
@@ -108,8 +108,8 @@
<string name="wizard_final">Orbot is ready!</string>
<string name="wizard_final_msg">Hundreds of thousands of people around the world use Tor for a wide variety of reasons: journalists and bloggers, human rights workers, law enforcement officers, soldiers, corporations, citizens of repressive regimes, and just ordinary citizens... and now you are ready to, as well!</string>
- <string name="otrchat_apk_url">https://guardianproject.info/getgibber</string>
- <string name="orweb_apk_url">https://guardianproject.info/getorweb</string>
+ <string name="otrchat_apk_url">market://search?q=pname:info.guardianproject.otr.app.im</string>
+ <string name="orweb_apk_url">market://search?q=pname:nfo.guardianproject.browser</string>
<!-- END Welcome Wizard strings (DJH) -->
Modified: projects/android/trunk/Orbot/res/values-ar/strings.xml
===================================================================
--- projects/android/trunk/Orbot/res/values-ar/strings.xml 2011-04-15 16:37:33 UTC (rev 24627)
+++ projects/android/trunk/Orbot/res/values-ar/strings.xml 2011-04-15 16:37:58 UTC (rev 24628)
@@ -97,7 +97,7 @@
<string name="wizard_tips_tricks">تطبيقات مهيئة لأوربوت</string>
<string name="wizard_tips_msg">نشجعكم على تحميل واستخدام التطبيقات التي تعرف كيفية الاتصال مباشرة بأوربوت. اضغط على الأزرار في الأسفل للتثبيت.</string>
- <string name="wizard_tips_otrchat">OTRCHAT - عميل التراسل الفوري الآمن للأندرويد</string>
+ <string name="wizard_tips_otrchat">GibberBot - عميل التراسل الفوري الآمن للأندرويد</string>
<string name="wizard_tips_orweb">ORWEB (أندرويد 1.x فقط) - متصفح مصمّم للخصوصية لأوربوت </string>
<string name="wizard_tips_proxy">إعدادات الوكيل - تعلم كيفية تكوين التطبيقات لتعمل مع أوربوت</string>
@@ -115,7 +115,7 @@
<string name="wizard_final">أوربوت جاهز!</string>
<string name="wizard_final_msg">مئات الآلاف من الناس في جميع أنحاء العالم يستخدمون تور لأسباب عديدة: الصحفيين والمدونين، والعاملين في مجال حقوق الإنسان، والجنود والشركات والمواطنين من الأنظمة القمعية، والمواطنين العاديين ... والآن أنت مستعد لأن تستخدمه كذلك!</string>
- <string name="otrchat_apk_url">https://guardianproject.info/getgibber</string>
+ <string name="otrchat_apk_url">market://search?q=pname:info.guardianproject.otr.app.im</string>
<string name="orweb_apk_url">https://guardianproject.info/getorweb</string>
<!-- END Welcome Wizard strings (DJH) -->
Modified: projects/android/trunk/Orbot/res/values-ca/strings.xml
===================================================================
--- projects/android/trunk/Orbot/res/values-ca/strings.xml 2011-04-15 16:37:33 UTC (rev 24627)
+++ projects/android/trunk/Orbot/res/values-ca/strings.xml 2011-04-15 16:37:58 UTC (rev 24628)
@@ -97,7 +97,7 @@
<string name="wizard_tips_tricks">Aplicacions per a usar-se amb Orbot</string>
<string name="wizard_tips_msg">T\'animem a descarregar-te & utilitza aplicacions que sàpiguen com connectar-se directament a Orbot. Fes clic als botons de sota per instal·lar.</string>
- <string name="wizard_tips_otrchat">OTRCHAT - Client de missatgeria instantània segura per a Android</string>
+ <string name="wizard_tips_otrchat">GibberBot - Client de missatgeria instantània segura per a Android</string>
<string name="wizard_tips_orweb">ORWEB (Només Android 1.x) - Navegador dissenyat per la privacitat & per a Orbot</string>
<string name="wizard_tips_proxy">Coniguració de Proxy - Aprèn a configurar aplicacions per a què funcionin amb Orbot</string>
@@ -115,7 +115,7 @@
<string name="wizard_final">Orbot és a punt!</string>
<string name="wizard_final_msg">Centenars de milers de persones arreu del món utilitzen Tor per un gran ventall de raons: periodistes i blocaires, treballadors pels drets humans, agents de l\'autoritat, soldats, corporacions, ciutadans de règims opressors, i ciutadans qualssevol... I ara tu també ho pots fer!</string>
- <string name="otrchat_apk_url">https://guardianproject.info/getgibber</string>
+ <string name="otrchat_apk_url">market://search?q=pname:info.guardianproject.otr.app.im</string>
<string name="orweb_apk_url">https://guardianproject.info/getorweb</string>
<!-- END Welcome Wizard strings (DJH) -->
Modified: projects/android/trunk/Orbot/res/values-de/strings.xml
===================================================================
--- projects/android/trunk/Orbot/res/values-de/strings.xml 2011-04-15 16:37:33 UTC (rev 24627)
+++ projects/android/trunk/Orbot/res/values-de/strings.xml 2011-04-15 16:37:58 UTC (rev 24628)
@@ -97,7 +97,7 @@
<string name="wizard_tips_tricks">Programme, für die Orbot aktiviert ist</string>
<string name="wizard_tips_msg">Wir raten Ihnen Programme herunterzuladen & zu nutzen, die wissen, wie sie sich direkt mit Orbot verbinden. Klicken Sie zum Installieren auf den Knopf unten.</string>
- <string name="wizard_tips_otrchat">OTRCHAT - Ein sicheres Instant-Messaging-Programm für Android</string>
+ <string name="wizard_tips_otrchat">GibberBot - Ein sicheres Instant-Messaging-Programm für Android</string>
<string name="wizard_tips_orweb">ORWEB (Nur Android 1.x) - Ein für Privatsphäre & Orbot entworfener Browser</string>
<string name="wizard_tips_proxy">Proxy-Einstellungen - Lernen Sie Anwendungen so zu konfigurieren, dass sie mit Orbot zusammenarbeiten.</string>
@@ -115,7 +115,7 @@
<string name="wizard_final">Orbot ist bereit!</string>
<string name="wizard_final_msg">Hunderttausende Menschen auf der ganzen Welt nutzen Tor aus einer Vielzahl von Gründen: Journalisten und Blogger, Menschenrechtsaktivisten, Strafverfolgungsbehörden, Soldaten, Unternehmen, Bürger repressiver Regime und ganz normale Menschen... und sind Sie ebenfalls bereit!</string>
- <string name="otrchat_apk_url">https://guardianproject.info/getgibber</string>
+ <string name="otrchat_apk_url">market://search?q=pname:info.guardianproject.otr.app.im</string>
<string name="orweb_apk_url">https://guardianproject.info/getorweb</string>
<!-- END Welcome Wizard strings (DJH) -->
Modified: projects/android/trunk/Orbot/res/values-es/strings.xml
===================================================================
--- projects/android/trunk/Orbot/res/values-es/strings.xml 2011-04-15 16:37:33 UTC (rev 24627)
+++ projects/android/trunk/Orbot/res/values-es/strings.xml 2011-04-15 16:37:58 UTC (rev 24628)
@@ -97,7 +97,7 @@
<string name="wizard_tips_tricks">Aplicaciones activas en Orbot</string>
<string name="wizard_tips_msg">Le invitamos a descargar y utilizar aplicaciones que saben cómo conectarse directamente a Orbot. Haga clic en los botones a continuación para Instalar.</string>
- <string name="wizard_tips_otrchat">OTRCHAT - Cliente de mensajería instantánea seguro para Android</string>
+ <string name="wizard_tips_otrchat">GibberBot - Cliente de mensajería instantánea seguro para Android</string>
<string name="wizard_tips_orweb">ORWEB (Sólo Android 1.x) - Navegador diseñado para la privacidad y para Orbot</string>
<string name="wizard_tips_proxy">Configuraciones Proxy - Aprenda cómo configurar aplicaciones para que trabajen con Orbot</string>
@@ -115,7 +115,7 @@
<string name="wizard_final">¡Orbot está listo!</string>
<string name="wizard_final_msg">Cientos de miles de personas alrededor del mundo usan Tor por una amplia variedad de razones: periodistas y bloggers, trabajadores de los derechos humanos, oficiales de policía, soldados, corporaciones, ciudadanos de regímenes represivos y ciudadanos ordinarios... ¡y ahora también lo estás!</string>
- <string name="otrchat_apk_url">https://guardianproject.info/getgibber</string>
+ <string name="otrchat_apk_url">market://search?q=pname:info.guardianproject.otr.app.im</string>
<string name="orweb_apk_url">https://guardianproject.info/getorweb</string>
<!-- END Welcome Wizard strings (DJH) -->
Modified: projects/android/trunk/Orbot/res/values-fa/strings.xml
===================================================================
--- projects/android/trunk/Orbot/res/values-fa/strings.xml 2011-04-15 16:37:33 UTC (rev 24627)
+++ projects/android/trunk/Orbot/res/values-fa/strings.xml 2011-04-15 16:37:58 UTC (rev 24628)
@@ -95,7 +95,7 @@
<string name="wizard_tips_tricks">اپلیکیشن هایی که برای اوربات تنظیم شده اند</string>
<string name="wizard_tips_msg">توصیه می کنیم داون لود و فعال کنید؛ اپلیکیشن هایی را استفاده کنید که مستقیم به اوربات وصل می شوند. دکمه های زیر را فشار دهید تا نصب شود. </string>
- <string name="wizard_tips_otrchat">OTRCHAT - کاربر ایمن انتقال پیام فوری برای آندروید</string>
+ <string name="wizard_tips_otrchat">GibberBot - کاربر ایمن انتقال پیام فوری برای آندروید</string>
<string name="wizard_tips_orweb">ORWEB (فقط آندروید 1.x) - مرورگر طراحی شده برای حفظ حریم خصوصی و افزونساز اوربات</string>
<string name="wizard_tips_proxy">تنظیمات پروکسی - یادگیری تنظیم اپلیکیشن ها برای کار با اوربات</string>
@@ -105,7 +105,7 @@
<string name="wizard_final">اوربات آماده استفاده میباشد!</string>
<string name="wizard_final_msg">صدها هزار نفر در سراسر جهان به دلایل گوناگون از Tor استفاده می کنند: روزنامه نویسها و بلاگرها، کارکنان حقوق بشر، ماموران انتظامی، سربازان، شرکتها، شهروندان دولتهای سرکوبگر، و شهروندان عادی، و حالا شما نیز آماده استفاده از آن هستید!</string>
- <string name="otrchat_apk_url">https://guardianproject.info/getgibber</string>
+ <string name="otrchat_apk_url">market://search?q=pname:info.guardianproject.otr.app.im</string>
<string name="orweb_apk_url">https://guardianproject.info/getorweb</string>
<!-- END Welcome Wizard strings (DJH) -->
Modified: projects/android/trunk/Orbot/res/values-mk/strings.xml
===================================================================
--- projects/android/trunk/Orbot/res/values-mk/strings.xml 2011-04-15 16:37:33 UTC (rev 24627)
+++ projects/android/trunk/Orbot/res/values-mk/strings.xml 2011-04-15 16:37:58 UTC (rev 24628)
@@ -95,7 +95,7 @@
<string name="wizard_tips_tricks">Орбот-вклучени апликации</string>
<string name="wizard_tips_msg">Ви препорачуваме да презимате и користите апликации кои што знаат како директно да се поврзат со Орбот. Притиснете на копчињата подолу за инсталирање.</string>
- <string name="wizard_tips_otrchat">OTRCHAT - Безбеден клиент за инстант-пораки за Андроид</string>
+ <string name="wizard_tips_otrchat">GibberBot - Безбеден клиент за инстант-пораки за Андроид</string>
<string name="wizard_tips_orweb">ORWEB (само Андроид 1.x) - Браусер дизајниран за приватност и за Орбот</string>
<string name="wizard_tips_proxy">Подесувања на прокси - Научете како да ги конфигурирате апликациите да работат со Орбот</string>
@@ -109,7 +109,7 @@
<string name="wizard_final">Орбот е спремен!</string>
<string name="wizard_final_msg">Стотици илјади луѓе низ целиот Свет го користат Тор од многу различни причини: новинари и блогери, борци за човекови права, полицајци, војници, корпорации, граѓани на репресивни режими, и обични граѓани... а сега и Вие сте спремин да го користите!</string>
- <string name="otrchat_apk_url">https://guardianproject.info/getgibber</string>
+ <string name="otrchat_apk_url">market://search?q=pname:info.guardianproject.otr.app.im</string>
<string name="orweb_apk_url">https://guardianproject.info/getorweb</string>
<!-- END Welcome Wizard strings (DJH) -->
Modified: projects/android/trunk/Orbot/res/values-nl/strings.xml
===================================================================
--- projects/android/trunk/Orbot/res/values-nl/strings.xml 2011-04-15 16:37:33 UTC (rev 24627)
+++ projects/android/trunk/Orbot/res/values-nl/strings.xml 2011-04-15 16:37:58 UTC (rev 24628)
@@ -97,7 +97,7 @@
<string name="wizard_tips_tricks">Orbot-beschikbare Apps</string>
<string name="wizard_tips_msg">We raden u aan om te apps te downloaden welke zich zich automatisch verbinden met Orbot. Klik op de buttons hier beneden om te installeren.</string>
- <string name="wizard_tips_otrchat">OTRCHAT - Veilige instant message programma voor Android</string>
+ <string name="wizard_tips_otrchat">GibberBot - Veilige instant message programma voor Android</string>
<string name="wizard_tips_orweb">ORWEB (Alleen Android 1.x) - Browser gemaakt voor privacy & voor Orbot</string>
<string name="wizard_tips_proxy">Proxy Instellingen - Leer hoe u uw apps kunt configureren voor Orbot</string>
@@ -114,7 +114,7 @@
<string name="wizard_final">Orbot is klaar!</string>
<string name="wizard_final_msg">Honderdduizenden verschillende mensen over de wereld gebruiken Tor, zoals: journalisten, bloggers, mensen rechten medewerkers, soldaten, bedrijven, burgers met onderdrukte religies, en natuurlijk normale mensen... En nu bent u ook klaar om te gaan!</string>
- <string name="otrchat_apk_url">https://guardianproject.info/getgibber</string>
+ <string name="otrchat_apk_url">market://search?q=pname:info.guardianproject.otr.app.im</string>
<string name="orweb_apk_url">https://guardianproject.info/getorweb</string>
<!-- END Welcome Wizard strings (DJH) -->
Modified: projects/android/trunk/Orbot/res/values-pl/strings.xml
===================================================================
--- projects/android/trunk/Orbot/res/values-pl/strings.xml 2011-04-15 16:37:33 UTC (rev 24627)
+++ projects/android/trunk/Orbot/res/values-pl/strings.xml 2011-04-15 16:37:58 UTC (rev 24628)
@@ -95,7 +95,7 @@
<string name="wizard_tips_tricks">Aplikacje skonfigurowane dla Orbota</string>
<string name="wizard_tips_msg">Zachęcamy do pobierania i używania aplikacji, które wiedzą, jak łączyć się bezpośrednio z Orbotem. Kliknij na poniższe przyciski, by zainstalować.</string>
- <string name="wizard_tips_otrchat">OTRCHAT - Bezpieczny klieny rozmów dla Androida</string>
+ <string name="wizard_tips_otrchat">GibberBot - Bezpieczny klieny rozmów dla Androida</string>
<string name="wizard_tips_orweb">ORWEB (tylko Android 1.x) - Przeglądarka zaprojektowana do prywatności i dla Orbota</string>
<string name="wizard_tips_proxy">Ustawienia Proxy - NDowiedz się, jak konfiguroać aplikacje do współpracy z Orbotem</string>
@@ -109,7 +109,7 @@
<string name="wizard_final">Orbot jest gotowy!</string>
<string name="wizard_final_msg">Setki tysięcy ludzi na całym świecie używają Tora z różnych powodów: dziennikarze i blogerzy, działacze na rzecz praw człowieka, stróże prawa, żołnierze, korporacje, obywatele represyjnych reżimów i zwykli obywatele... teraz Ty też możesz!</string>
- <string name="otrchat_apk_url">https://guardianproject.info/getgibber</string>
+ <string name="otrchat_apk_url">market://search?q=pname:info.guardianproject.otr.app.im</string>
<string name="orweb_apk_url">https://guardianproject.info/getorweb</string>
<!-- END Welcome Wizard strings (DJH) -->
Modified: projects/android/trunk/Orbot/res/values-ru/strings.xml
===================================================================
--- projects/android/trunk/Orbot/res/values-ru/strings.xml 2011-04-15 16:37:33 UTC (rev 24627)
+++ projects/android/trunk/Orbot/res/values-ru/strings.xml 2011-04-15 16:37:58 UTC (rev 24628)
@@ -95,7 +95,7 @@
<string name="wizard_tips_tricks">Orbot-задействованные приложения</string>
<string name="wizard_tips_msg">Мы советуем вам скачать и использовать приложения, которые умеют работать напрямую через Orbot. Нажмите на кнопки ниже, чтобы запустить процесс установки.</string>
- <string name="wizard_tips_otrchat">OTRCHAT - Обезопасте обмен мгновенными сообщениями для клиентов в Android</string>
+ <string name="wizard_tips_otrchat">GibberBot - Обезопасте обмен мгновенными сообщениями для клиентов в Android</string>
<string name="wizard_tips_orweb">ORWEB (Только для версии Android 1.x) - Браузер, разработанный для обеспечения безопасности и для Orbot</string>
<string name="wizard_tips_proxy">Настройки прокси - узнайте как настроить приложения для работы с Orbot</string>
@@ -109,7 +109,7 @@
<string name="wizard_final">Программа Orbot готова к использованию!</string>
<string name="wizard_final_msg">Сотни тысяч людей по всему миру используют Tor по различным причинам: журналисты и блоггеры, активисты организаций, выступающих в защиту прав человека, судебные исполнители, солдаты, корпорации, граждане стран с репрессивным режимом, и простые люди... а теперь готовы и вы!</string>
- <string name="otrchat_apk_url">https://guardianproject.info/getgibber</string>
+ <string name="otrchat_apk_url">market://search?q=pname:info.guardianproject.otr.app.im</string>
<string name="orweb_apk_url">https://guardianproject.info/getorweb</string>
<!-- END Welcome Wizard strings (DJH) -->
Modified: projects/android/trunk/Orbot/res/values-zh/strings.xml
===================================================================
--- projects/android/trunk/Orbot/res/values-zh/strings.xml 2011-04-15 16:37:33 UTC (rev 24627)
+++ projects/android/trunk/Orbot/res/values-zh/strings.xml 2011-04-15 16:37:58 UTC (rev 24628)
@@ -95,7 +95,7 @@
<string name="wizard_tips_tricks">可用 Orbot 的应用程序</string>
<string name="wizard_tips_msg">我们建议您下载和使用能直接连接到 Orbot 的应用程序。点击以下按钮安装。</string>
- <string name="wizard_tips_otrchat">OTRCHAT - Android 上的安全即时消息客户端</string>
+ <string name="wizard_tips_otrchat">GibberBot - Android 上的安全即时消息客户端</string>
<string name="wizard_tips_orweb">ORWEB (仅 Android 1.x) - 着重隐私设计的浏览器</string>
<string name="wizard_tips_proxy">代理设置 - 学习如何配置应用程序使用 Orbot</string>
@@ -108,7 +108,7 @@
<string name="wizard_final">Orbot 已就绪!</string>
<string name="wizard_final_msg">数以万计的各国人们因为各种原因使用 Tor:记者、人权工作者、法律工作者、士兵、公司、迫于实际情况使用的市民,当然也有普通的市民。现在你也即将成为其中的一员!</string>
- <string name="otrchat_apk_url">https://guardianproject.info/getgibber</string>
+ <string name="otrchat_apk_url">market://search?q=pname:info.guardianproject.otr.app.im</string>
<string name="orweb_apk_url">https://guardianproject.info/getorweb</string>
<!-- END Welcome Wizard strings (DJH) -->
1
0
r24627: {projects} update to service with new transproxy/iptables code (projects/android/trunk/Orbot/src/org/torproject/android/service)
by Nathan Freitas 15 Apr '11
by Nathan Freitas 15 Apr '11
15 Apr '11
Author: n8fr8
Date: 2011-04-15 16:37:33 +0000 (Fri, 15 Apr 2011)
New Revision: 24627
Modified:
projects/android/trunk/Orbot/src/org/torproject/android/service/TorBinaryInstaller.java
projects/android/trunk/Orbot/src/org/torproject/android/service/TorService.java
projects/android/trunk/Orbot/src/org/torproject/android/service/TorServiceConstants.java
projects/android/trunk/Orbot/src/org/torproject/android/service/TorServiceUtils.java
projects/android/trunk/Orbot/src/org/torproject/android/service/TorTransProxy.java
Log:
update to service with new transproxy/iptables code
Modified: projects/android/trunk/Orbot/src/org/torproject/android/service/TorBinaryInstaller.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/service/TorBinaryInstaller.java 2011-04-15 16:36:36 UTC (rev 24626)
+++ projects/android/trunk/Orbot/src/org/torproject/android/service/TorBinaryInstaller.java 2011-04-15 16:37:33 UTC (rev 24627)
@@ -12,18 +12,23 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
+import org.torproject.android.R;
+
+import android.content.Context;
import android.util.Log;
public class TorBinaryInstaller implements TorServiceConstants {
- String installPath = null;
- String apkPath = null;
+ String installPath;
+ String apkPath;
+ Context context;
- public TorBinaryInstaller (String installPath, String apkPath)
+ public TorBinaryInstaller (Context context, String installPath, String apkPath)
{
this.installPath = installPath;
this.apkPath = apkPath;
+ this.context = context;
}
/*
@@ -39,13 +44,42 @@
Log.d(TAG,"Privoxy binary exists=" + privoxyBinaryExists);
if (!(torBinaryExists && privoxyBinaryExists) || force)
- installFromZip ();
+ installFromRaw ();
+
+
}
+ //
/*
* Extract the Tor binary from the APK file using ZIP
*/
+ private void installFromRaw ()
+ {
+
+
+ InputStream is = context.getResources().openRawResource(R.raw.tor);
+ streamToFile(is,installPath + TOR_BINARY_ASSET_KEY);
+
+
+ is = context.getResources().openRawResource(R.raw.torrc);
+ streamToFile(is,installPath + TORRC_ASSET_KEY);
+
+ is = context.getResources().openRawResource(R.raw.privoxy);
+ streamToFile(is,installPath + PRIVOXY_ASSET_KEY);
+
+ is = context.getResources().openRawResource(R.raw.privoxy_config);
+ streamToFile(is,installPath + PRIVOXYCONFIG_ASSET_KEY);
+
+
+
+ Log.d(TAG,"SUCCESS: installed tor, privoxy binaries from raw");
+
+
+ }
+ /*
+ * Extract the Tor binary from the APK file using ZIP
+ */
private void installFromZip ()
{
Modified: projects/android/trunk/Orbot/src/org/torproject/android/service/TorService.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/service/TorService.java 2011-04-15 16:36:36 UTC (rev 24626)
+++ projects/android/trunk/Orbot/src/org/torproject/android/service/TorService.java 2011-04-15 16:37:33 UTC (rev 24627)
@@ -52,12 +52,16 @@
private static final int MAX_START_TRIES = 3;
private ArrayList<String> configBuffer = null;
-
+ private ArrayList<String> resetBuffer = null;
+
- private String appHome = "/data/data/" + TOR_APP_USERNAME + "/";;
- private String torBinaryPath = appHome + TOR_BINARY_ASSET_KEY;
- private String privoxyPath = appHome + PRIVOXY_ASSET_KEY;
+ private String appHome;
+ private String appBinHome;
+ private String appDataHome;
+ private String torBinaryPath;
+ private String privoxyPath;
+
private boolean hasRoot = false;
@@ -323,7 +327,8 @@
String[] cmd = { SHELL_CMD_KILL + ' ' + procId + "" };
TorServiceUtils.doShellCommand(cmd,log, false, false);
-
+ try { Thread.sleep(500); }
+ catch (Exception e){}
}
while ((procId = TorServiceUtils.findProcessId(privoxyPath)) != -1)
@@ -333,7 +338,8 @@
String[] cmd = { SHELL_CMD_KILL + ' ' + procId + "" };
TorServiceUtils.doShellCommand(cmd,log, false, false);
-
+ try { Thread.sleep(500); }
+ catch (Exception e){}
}
}
@@ -349,6 +355,7 @@
}
}
+ /*
private String findAPK ()
{
@@ -428,39 +435,29 @@
return null;
- }
+ }*/
+
private boolean checkTorBinaries () throws Exception
{
+ //android.os.Debug.waitForDebugger();
- appHome = "/data/data/" + TOR_APP_USERNAME + "/";
- //appHome = getApplicationContext().getFilesDir().getAbsolutePath();
+ //check and install iptables
+ Api.assertBinaries(this, true);
+ File fileInstall = getDir("",0);
+ String subBinPath = "bin/";
+
+ appHome = fileInstall.getAbsolutePath();
+ appBinHome = appHome + subBinPath;
+ appDataHome = getCacheDir().getAbsolutePath() + '/';
logNotice( "appHome=" + appHome);
- torBinaryPath = appHome + TOR_BINARY_ASSET_KEY;
- privoxyPath = appHome + PRIVOXY_ASSET_KEY;
+
+ torBinaryPath = appBinHome + TOR_BINARY_ASSET_KEY;
+ privoxyPath = appBinHome + PRIVOXY_ASSET_KEY;
logNotice( "checking Tor binaries");
-
- String apkPath = findAPK();
-
- if (apkPath == null)
- throw new Exception ("Unable to locate Orbot binary APK file");
-
- logNotice( "found apk at: " + apkPath);
-
- boolean apkExists = new File(apkPath).exists();
-
- if (!apkExists)
- {
- Log.w(TAG,"APK file not found at: " + apkPath);
- Log.w(TAG,"Binary installation aborted");
- logNotice(getString(R.string.status_install_fail));
- sendCallbackStatusMessage(getString(R.string.status_install_fail));
- return false;
- }
-
-
+
boolean torBinaryExists = new File(torBinaryPath).exists();
boolean privoxyBinaryExists = new File(privoxyPath).exists();
@@ -468,7 +465,7 @@
{
killTorProcess ();
- TorBinaryInstaller installer = new TorBinaryInstaller(appHome, apkPath);
+ TorBinaryInstaller installer = new TorBinaryInstaller(this, appBinHome, appBinHome);
installer.start(true);
torBinaryExists = new File(torBinaryPath).exists();
@@ -552,12 +549,11 @@
private void runTorShellCmd() throws Exception
{
-
StringBuilder log = new StringBuilder();
- String torrcPath = appHome + TORRC_ASSET_KEY;
+ String torrcPath = appBinHome + TORRC_ASSET_KEY;
- String[] torCmd = {torBinaryPath + " -f " + torrcPath + " || exit\n"};
+ String[] torCmd = {torBinaryPath + " DataDirectory " + appDataHome + " -f " + torrcPath + " || exit\n"};
boolean runAsRootFalse = false;
boolean waitForProcess = false;
@@ -623,7 +619,7 @@
{
log = new StringBuilder();
- String privoxyConfigPath = appHome + PRIVOXYCONFIG_ASSET_KEY;
+ String privoxyConfigPath = appBinHome + PRIVOXYCONFIG_ASSET_KEY;
String[] cmds =
{ privoxyPath + " " + privoxyConfigPath + " &" };
@@ -680,28 +676,32 @@
torConnSocket = new Socket(IP_LOCALHOST, TOR_CONTROL_PORT);
conn = TorControlConnection.getConnection(torConnSocket);
+
// conn.authenticate(new byte[0]); // See section 3.2
sendCallbackStatusMessage(getString(R.string.tor_process_connecting_step2));
logNotice( "SUCCESS connected to control port");
- String torAuthCookie = appHome + "data/control_auth_cookie";
+ String torAuthCookie = appDataHome + TOR_CONTROL_COOKIE;
File fileCookie = new File(torAuthCookie);
- byte[] cookie = new byte[(int)fileCookie.length()];
- new FileInputStream(new File(torAuthCookie)).read(cookie);
- conn.authenticate(cookie);
-
- logNotice( "SUCCESS authenticated to control port");
- sendCallbackStatusMessage(getString(R.string.tor_process_connecting_step2) + getString(R.string.tor_process_connecting_step3));
-
- addEventHandler();
+ if (fileCookie.exists())
+ {
+ byte[] cookie = new byte[(int)fileCookie.length()];
+ new FileInputStream(new File(torAuthCookie)).read(cookie);
+ conn.authenticate(cookie);
+
+ logNotice( "SUCCESS authenticated to control port");
+
+ sendCallbackStatusMessage(getString(R.string.tor_process_connecting_step2) + getString(R.string.tor_process_connecting_step3));
+
+ addEventHandler();
+
+ applyPreferences();
+ }
- applyPreferences();
-
-
break; //don't need to retry
}
catch (Exception ce)
@@ -712,8 +712,7 @@
sendCallbackStatusMessage(getString(R.string.tor_process_connecting_step4));
Thread.sleep(1000);
-
-
+
}
}
@@ -1052,9 +1051,14 @@
{
if (configBuffer == null)
configBuffer = new ArrayList<String>();
-
+
+ if (resetBuffer == null)
+ resetBuffer = new ArrayList<String>();
+
if (value == null || value.length() == 0)
{
+
+ /*
if (conn != null)
{
try {
@@ -1063,6 +1067,9 @@
Log.w(TAG, "Unable to reset conf",e);
}
}
+ */
+
+ resetBuffer.add(name);
}
else
configBuffer.add(name + ' ' + value);
@@ -1076,8 +1083,16 @@
{
if (conn != null)
{
- if (configBuffer != null)
+ if (resetBuffer != null && resetBuffer.size() > 0)
+ {
+ conn.resetConf(resetBuffer);
+ resetBuffer = null;
+ }
+
+
+ if (configBuffer != null && configBuffer.size() > 0)
{
+
conn.setConf(configBuffer);
configBuffer = null;
}
@@ -1378,14 +1393,14 @@
}
else
{
- TorTransProxy.purgeIptables(this,AppManager.getApps(this));
+ TorTransProxy.purgeIptables(this);
}
}
}
else if (hasRoot)
{
- TorTransProxy.purgeIptables(this,AppManager.getApps(this));
+ TorTransProxy.purgeIptables(this);
}
return true;
Modified: projects/android/trunk/Orbot/src/org/torproject/android/service/TorServiceConstants.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/service/TorServiceConstants.java 2011-04-15 16:36:36 UTC (rev 24626)
+++ projects/android/trunk/Orbot/src/org/torproject/android/service/TorServiceConstants.java 2011-04-15 16:37:33 UTC (rev 24627)
@@ -19,7 +19,8 @@
//torrc (tor config file)
public final static String TORRC_ASSET_KEY = "torrc";
-
+ public final static String TOR_CONTROL_COOKIE = "control_auth_cookie";
+
//how to launch tor
// public final static String TOR_COMMAND_LINE_ARGS = "-f " + TORRC_INSTALL_PATH + " || exit\n";
@@ -39,8 +40,8 @@
public final static String CHMOD_EXE_VALUE = "777";
//path of the installed APK file
- public final static String APK_PATH = "/data/app/org.torproject.android.apk";
- public final static String APK_PATH_BASE = "/data/app";
+ //public final static String APK_PATH = "/data/app/org.torproject.android.apk";
+ //public final static String APK_PATH_BASE = "/data/app";
Modified: projects/android/trunk/Orbot/src/org/torproject/android/service/TorServiceUtils.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/service/TorServiceUtils.java 2011-04-15 16:36:36 UTC (rev 24626)
+++ projects/android/trunk/Orbot/src/org/torproject/android/service/TorServiceUtils.java 2011-04-15 16:37:33 UTC (rev 24627)
@@ -165,7 +165,6 @@
else
proc = Runtime.getRuntime().exec("sh");
-
OutputStreamWriter out = new OutputStreamWriter(proc.getOutputStream());
for (int i = 0; i < cmds.length; i++)
@@ -181,8 +180,6 @@
if (waitFor)
{
-
-
final char buf[] = new char[10];
// Consume the "stdout"
Modified: projects/android/trunk/Orbot/src/org/torproject/android/service/TorTransProxy.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/service/TorTransProxy.java 2011-04-15 16:36:36 UTC (rev 24626)
+++ projects/android/trunk/Orbot/src/org/torproject/android/service/TorTransProxy.java 2011-04-15 16:37:33 UTC (rev 24627)
@@ -1,5 +1,7 @@
package org.torproject.android.service;
+import java.io.File;
+
import org.torproject.android.TorifiedApp;
import android.content.Context;
@@ -21,6 +23,7 @@
* Check if we have root access
* @return boolean true if we have root
*/
+ /*
public static String getIPTablesVersion() {
@@ -52,43 +55,42 @@
logNotice("Could not acquire check iptables: " + log.toString());
return null;
- }
+ }*/
-
- private static String findBaseDir ()
- {
-
- return ""; //just blank for now
- /*
- String[] cmds = {"/system/bin/iptables -t nat --list"};
+ public static int purgeIptables(Context context) throws Exception {
+
+ String ipTablesPath = new File(context.getDir("bin", 0),"iptables_n1").getAbsolutePath();
+
+ final StringBuilder script = new StringBuilder();
+
StringBuilder res = new StringBuilder();
+ int code = -1;
+
- int code;
- try {
- code = TorServiceUtils.doShellCommand(cmds, res, true, true);
+ script.append(ipTablesPath);
+ script.append(" -t nat");
+ script.append(" -F || exit\n");
+ script.append(ipTablesPath);
+ script.append(" -t filter");
+ script.append(" -F || exit\n");
+
+ String[] cmd = {script.toString()};
+ code = TorServiceUtils.doShellCommand(cmd, res, true, true);
+ String msg = res.toString();
+ logNotice(cmd[0] + ";errCode=" + code + ";resp=" + msg);
+
- if (code != 0) {
- return BASE_DIR;
- }
- else
- return "/system/bin/";
-
- } catch (Exception e) {
- return BASE_DIR;
- }
-
- return "";
-
- */
+ return code;
+
}
+ /*
+ public static int purgeIptablesByApp(Context context, TorifiedApp[] apps) throws Exception {
- public static int purgeIptables(Context context, TorifiedApp[] apps) throws Exception {
-
//restoreDNSResolvConf(); //not working yet
- String baseDir = findBaseDir();
+ String ipTablesPath = new File(context.getDir("bin", 0),"iptables_n1").getAbsolutePath();
final StringBuilder script = new StringBuilder();
@@ -97,13 +99,14 @@
for (int i = 0; i < apps.length; i++)
{
-
//flush nat for every app
- script.append(baseDir);
- script.append("iptables -t nat -m owner --uid-owner ");
+ script.append(ipTablesPath);
+ script.append(" -t nat -m owner --uid-owner ");
script.append(apps[i].getUid());
script.append(" -F || exit\n");
- script.append("iptables -t filter -m owner --uid-owner ");
+
+ script.append(ipTablesPath);
+ script.append(" -t filter -m owner --uid-owner ");
script.append(apps[i].getUid());
script.append(" -F || exit\n");
@@ -118,8 +121,9 @@
return code;
- }
+ }*/
+
/*
// 9/19/2010 - NF This code is in process... /etc path on System partition
// is read-only on Android for now.
@@ -171,39 +175,18 @@
//redirectDNSResolvConf(); //not working yet
- String baseDir = findBaseDir();
+ //String baseDir = context.getDir("bin", 0).getAbsolutePath() + "/";
+ String ipTablesPath = new File(context.getDir("bin", 0),"iptables_n1").getAbsolutePath();
- String iptablesVersion = getIPTablesVersion();
- logNotice( "iptables version: " + iptablesVersion);
-
boolean ipTablesOld = false;
- if (iptablesVersion != null && iptablesVersion.startsWith("1.3")){
- ipTablesOld = true;
- }
StringBuilder script = new StringBuilder();
StringBuilder res = new StringBuilder();
int code = -1;
- for (int i = 0; i < apps.length; i++)
- {
-
- //flush nat for every app
- script.append(baseDir);
- script.append("iptables -t nat -m owner --uid-owner ");
- script.append(apps[i].getUid());
- script.append(" -F || exit\n");
- script.append("iptables -t filter -m owner --uid-owner ");
- script.append(apps[i].getUid());
- script.append(" -F || exit\n");
-
- }
+ purgeIptables(context);
- String[] cmdFlush = {script.toString()};
- code = TorServiceUtils.doShellCommand(cmdFlush, res, true, true);
- //String msg = res.toString(); //get stdout from command
-
script = new StringBuilder();
//build up array of shell cmds to execute under one root context
@@ -231,8 +214,8 @@
//iptables -t nat -A output -p tcp -m owner --uid-owner 100 -m tcp --sync -j REDIRECT --to-ports 9040
//TCP
- script.append(baseDir);
- script.append("iptables -t nat");
+ script.append(ipTablesPath);
+ script.append(" -t nat");
script.append(" -A OUTPUT -p tcp");
script.append(" -m owner --uid-owner ");
script.append(apps[i].getUid());
@@ -248,8 +231,8 @@
script.append(" || exit\n");
//DNS
- script.append(baseDir);
- script.append("iptables -t nat");
+ script.append(ipTablesPath);
+ script.append(" -t nat");
script.append(" -A OUTPUT -p udp -m owner --uid-owner ");
script.append(apps[i].getUid());
script.append(" -m udp --dport ");
@@ -268,8 +251,8 @@
//EVERYTHING ELSE - DROP!
if (ipTablesOld) //for some reason this doesn't work on iptables 1.3.7
{
-
- script.append("iptables -t nat");
+ script.append(ipTablesPath);
+ script.append(" -t nat");
script.append(" -A OUTPUT -m owner --uid-owner ");
script.append(apps[i].getUid());
script.append(" -j DROP");
@@ -277,8 +260,8 @@
}
else
{
- script.append(baseDir);
- script.append("iptables -t filter");
+ script.append(ipTablesPath);
+ script.append(" -t filter");
script.append(" -A OUTPUT -p tcp");
script.append(" -m owner --uid-owner ");
script.append(apps[i].getUid());
@@ -287,8 +270,8 @@
script.append(" -j ACCEPT");
script.append(" || exit\n");
- script.append(baseDir);
- script.append("iptables -t filter");
+ script.append(ipTablesPath);
+ script.append(" -t filter");
script.append(" -A OUTPUT -p udp");
script.append(" -m owner --uid-owner ");
script.append(apps[i].getUid());
@@ -297,8 +280,7 @@
script.append(" -j ACCEPT");
script.append(" || exit\n");
- script.append(baseDir);
- script.append("iptables");
+ script.append(ipTablesPath);
script.append(" -t filter -A OUTPUT -m owner --uid-owner ");
script.append(apps[i].getUid());
script.append(" -j DROP"); //drop all other packets as Tor won't handle them
@@ -307,6 +289,9 @@
}
}
+ else
+ {
+ }
}
@@ -325,15 +310,10 @@
//redirectDNSResolvConf(); //not working yet
- String baseDir = findBaseDir();
+ //String baseDir = context.getDir("bin",0).getAbsolutePath() + '/';
+ String ipTablesPath = new File(context.getDir("bin", 0),"iptables_n1").getAbsolutePath();
- String iptablesVersion = getIPTablesVersion();
- logNotice( "iptables version: " + iptablesVersion);
-
boolean ipTablesOld = false;
- if (iptablesVersion != null && iptablesVersion.startsWith("1.3")){
- ipTablesOld = true;
- }
StringBuilder script = new StringBuilder();
@@ -349,8 +329,8 @@
//TCP
//iptables -t nat -A PREROUTING -i eth0 -p tcp --dport $srcPortNumber -j REDIRECT --to-port $dstPortNumbe
- script.append(baseDir);
- script.append("iptables -t nat");
+ script.append(ipTablesPath);
+ script.append(" -t nat");
script.append(" -A OUTPUT -p tcp");
script.append(" --dport ");
script.append(port);
@@ -365,8 +345,8 @@
script.append(" || exit\n");
- script.append(baseDir);
- script.append("iptables -t nat");
+ script.append(ipTablesPath);
+ script.append(" -t nat");
script.append(" -A OUTPUT -p udp");
script.append(" --dport ");
script.append(port);
@@ -381,8 +361,8 @@
script.append(" || exit\n");
//DNS
- script.append(baseDir);
- script.append("iptables -t nat");
+ script.append(ipTablesPath);
+ script.append(" -t nat");
script.append(" -A OUTPUT -p udp ");
script.append(" -m udp --dport ");
script.append(STANDARD_DNS_PORT);
1
0
r24626: {projects} updated version number (projects/android/trunk/Orbot)
by Nathan Freitas 15 Apr '11
by Nathan Freitas 15 Apr '11
15 Apr '11
Author: n8fr8
Date: 2011-04-15 16:36:36 +0000 (Fri, 15 Apr 2011)
New Revision: 24626
Modified:
projects/android/trunk/Orbot/AndroidManifest.xml
Log:
updated version number
Modified: projects/android/trunk/Orbot/AndroidManifest.xml
===================================================================
--- projects/android/trunk/Orbot/AndroidManifest.xml 2011-04-15 05:57:52 UTC (rev 24625)
+++ projects/android/trunk/Orbot/AndroidManifest.xml 2011-04-15 16:36:36 UTC (rev 24626)
@@ -1,10 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="org.torproject.android" android:versionName="1.0.5" android:versionCode="11">
+ package="org.torproject.android" android:versionName="0.2.2.22-orbot-alpha-1.0.5-dev-debug" android:versionCode="11">
<uses-permission android:name="android.permission.INTERNET" />
- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
-
+
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="false">
<activity android:name=".Orbot"
@@ -40,13 +39,6 @@
</intent-filter>
</service>
- <receiver android:name=".boot.OnbootBroadcastReceiver">
- <intent-filter>
- <action
- android:name="android.intent.action.BOOT_COMPLETED" />
- <category android:name="android.intent.category.HOME" />
- </intent-filter>
- </receiver>
</application>
1
0
[torspec/master] Correct name of the __AllDirActionsPrivate option
by nickm@torproject.org 15 Apr '11
by nickm@torproject.org 15 Apr '11
15 Apr '11
commit 0f11e4f2ed862512cda24b111e72e29e80e7dc9e
Author: Robert Ransom <rransom.8774(a)gmail.com>
Date: Thu Apr 14 18:20:11 2011 -0700
Correct name of the __AllDirActionsPrivate option
---
control-spec.txt | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/control-spec.txt b/control-spec.txt
index f86f94b..d24afab 100644
--- a/control-spec.txt
+++ b/control-spec.txt
@@ -1831,7 +1831,7 @@
normal operations. Unless a controller provides replacement functionality
to fill this gap, Tor will not correctly handle user requests.
- __AllDirOptionsPrivate
+ __AllDirActionsPrivate
If true, Tor will try to launch all directory operations through
anonymous connections. (Ordinarily, Tor only tries to anonymize
1
0
15 Apr '11
commit 6c214bac4239872bf288bd9bb672e8d56d160119
Author: Mike Perry <mikeperry-git(a)fscked.org>
Date: Fri Apr 15 01:07:33 2011 -0700
Bug 2832: Update spoofed useragent.
This will make YouTube work for FF4 users if they opt-in to the HTML5 trial.
We're not going to set the opt-in cookie for them just yet, on the assumption
that there's a good chance the trial mode will become automatic soon.
---
src/defaults/preferences/preferences.js | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/defaults/preferences/preferences.js b/src/defaults/preferences/preferences.js
index f12e849..58c8abe 100644
--- a/src/defaults/preferences/preferences.js
+++ b/src/defaults/preferences/preferences.js
@@ -200,13 +200,13 @@ pref("extensions.torbutton.fix_google_srch", true);
// User agent prefs:
pref("extensions.torbutton.appname_override","Netscape");
-pref("extensions.torbutton.appversion_override","5.0 (Windows; LANG)");
+pref("extensions.torbutton.appversion_override","5.0 (Windows)");
pref("extensions.torbutton.platform_override","Win32");
pref("extensions.torbutton.oscpu_override", "Windows NT 6.1");
-pref("extensions.torbutton.useragent_override", "Mozilla/5.0 (Windows; U; Windows NT 6.1; LANG; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3");
+pref("extensions.torbutton.useragent_override", "Mozilla/5.0 (Windows NT 6.1; rv:2.0) Gecko/20100101 Firefox/4.0");
-pref("extensions.torbutton.productsub_override","20100401");
+pref("extensions.torbutton.productsub_override","20100101");
pref("extensions.torbutton.buildID_override","0");
pref("extensions.torbutton.useragent_vendor", "");
pref("extensions.torbutton.useragent_vendorSub","");
1
0
[torbutton/master] Bug 2838: Make Cookie Protections always available.
by mikeperry@torproject.org 15 Apr '11
by mikeperry@torproject.org 15 Apr '11
15 Apr '11
commit 294629b7c59dba26a882636adadc231efc8f29e3
Author: Mike Perry <mikeperry-git(a)fscked.org>
Date: Fri Apr 15 02:43:16 2011 -0700
Bug 2838: Make Cookie Protections always available.
Also fix a bug referencing an old component name. It seems to work now.
---
src/chrome/content/torbutton.js | 9 ++++++++-
src/chrome/content/torcookie.js | 4 ++--
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/src/chrome/content/torbutton.js b/src/chrome/content/torbutton.js
index 5d0a564..676c311 100644
--- a/src/chrome/content/torbutton.js
+++ b/src/chrome/content/torbutton.js
@@ -1705,7 +1705,14 @@ function torbutton_close_on_toggle(mode) {
function torbutton_check_protections()
{
- var pref = m_tb_prefs.getBoolPref("extensions.torbutton.cookie_protections") && ((!m_tb_prefs.getBoolPref("extensions.torbutton.tor_memory_jar") && m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled")) || (!m_tb_prefs.getBoolPref("extensions.torbutton.nontor_memory_jar") && !m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled")));
+ var pref = m_tb_prefs.getBoolPref("extensions.torbutton.cookie_protections");
+ // XXX: This should always be visible if the user enabled it. It does seem to have
+ // other bugs though.
+ /* && ((!m_tb_prefs.getBoolPref("extensions.torbutton.tor_memory_jar")
+ && m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled"))
+ || (!m_tb_prefs.getBoolPref("extensions.torbutton.nontor_memory_jar")
+ && !m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled")));
+ */
document.getElementById("torbutton-cookie-protector").disabled = !pref;
}
diff --git a/src/chrome/content/torcookie.js b/src/chrome/content/torcookie.js
index dcb420b..b57a263 100644
--- a/src/chrome/content/torcookie.js
+++ b/src/chrome/content/torcookie.js
@@ -53,7 +53,7 @@ function initDialog() {
cookiesTree = document.getElementById("cookiesTree");
prefs =Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
- selector = Components.classes["@stanford.edu/cookie-jar-selector;1"]
+ selector = Components.classes["@torproject.org/cookie-jar-selector;1"]
.getService(Components.interfaces.nsISupports)
.wrappedJSObject;
var tor_enabled = prefs.getBoolPref("extensions.torbutton.tor_enabled");
@@ -403,4 +403,4 @@ function DeleteAllFromTree
document.getElementById(unprotButton).disabled = true;
document.getElementById(protButton).disabled = true;
}
-}
\ No newline at end of file
+}
1
0
r24625: {} adding in iptables API wrapper class from Droidwall (projects/android/trunk/Orbot/src/org/torproject/android/service)
by Nathan Freitas 15 Apr '11
by Nathan Freitas 15 Apr '11
15 Apr '11
Author: n8fr8
Date: 2011-04-15 05:57:52 +0000 (Fri, 15 Apr 2011)
New Revision: 24625
Added:
projects/android/trunk/Orbot/src/org/torproject/android/service/Api.java
Log:
adding in iptables API wrapper class from Droidwall
Added: projects/android/trunk/Orbot/src/org/torproject/android/service/Api.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/service/Api.java (rev 0)
+++ projects/android/trunk/Orbot/src/org/torproject/android/service/Api.java 2011-04-15 05:57:52 UTC (rev 24625)
@@ -0,0 +1,1052 @@
+/**
+ * Contains shared programming interfaces.
+ * All iptables "communication" is handled by this class.
+ *
+ * Copyright (C) 2009-2010 Rodrigo Zechin Rosauro
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @author Rodrigo Zechin Rosauro
+ * @version 1.0
+ */
+
+package org.torproject.android.service;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.StringReader;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.torproject.android.R;
+
+import android.Manifest;
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.util.Log;
+import android.widget.Toast;
+
+/**
+ * Contains shared programming interfaces.
+ * All iptables "communication" is handled by this class.
+ */
+public final class Api {
+ /** application version string */
+ public static final String VERSION = "1.5.1-dev";
+ /** special application UID used to indicate "any application" */
+ public static final int SPECIAL_UID_ANY = -10;
+ /** special application UID used to indicate the Linux Kernel */
+ public static final int SPECIAL_UID_KERNEL = -11;
+ /** root script filename */
+ private static final String SCRIPT_FILE = "droidwall.sh";
+
+ // Preferences
+ public static final String PREFS_NAME = "DroidWallPrefs";
+ public static final String PREF_3G_UIDS = "AllowedUids3G";
+ public static final String PREF_WIFI_UIDS = "AllowedUidsWifi";
+ public static final String PREF_PASSWORD = "Password";
+ public static final String PREF_MODE = "BlockMode";
+ public static final String PREF_ENABLED = "Enabled";
+ public static final String PREF_LOGENABLED = "LogEnabled";
+ // Modes
+ public static final String MODE_WHITELIST = "whitelist";
+ public static final String MODE_BLACKLIST = "blacklist";
+ // Messages
+ public static final String STATUS_CHANGED_MSG = "com.googlecode.droidwall.intent.action.STATUS_CHANGED";
+ public static final String TOGGLE_REQUEST_MSG = "com.googlecode.droidwall.intent.action.TOGGLE_REQUEST";
+ public static final String STATUS_EXTRA = "com.googlecode.droidwall.intent.extra.STATUS";
+
+ // Cached applications
+ public static DroidApp applications[] = null;
+ // Do we have root access?
+ private static boolean hasroot = false;
+ // Flag indicating if this is an ARMv6 device (-1: unknown, 0: no, 1: yes)
+ private static int isARMv6 = -1;
+
+ /**
+ * Display a simple alert box
+ * @param ctx context
+ * @param msg message
+ */
+ public static void alert(Context ctx, CharSequence msg) {
+ if (ctx != null) {
+ new AlertDialog.Builder(ctx)
+ .setNeutralButton(android.R.string.ok, null)
+ .setMessage(msg)
+ .show();
+ }
+ }
+ /**
+ * Check if this is an ARMv6 device
+ * @return true if this is ARMv6
+ */
+ private static boolean isARMv6() {
+ if (isARMv6 == -1) {
+ BufferedReader r = null;
+ try {
+ isARMv6 = 0;
+ r = new BufferedReader(new FileReader("/proc/cpuinfo"));
+ for (String line = r.readLine(); line != null; line = r.readLine()) {
+ if (line.startsWith("Processor") && line.contains("ARMv6")) {
+ isARMv6 = 1;
+ break;
+ } else if (line.startsWith("CPU architecture") && (line.contains("6TE") || line.contains("5TE"))) {
+ isARMv6 = 1;
+ break;
+ }
+ }
+ } catch (Exception ex) {
+ } finally {
+ if (r != null) try {r.close();} catch (Exception ex) {}
+ }
+ }
+ return (isARMv6 == 1);
+ }
+ /**
+ * Create the generic shell script header used to determine which iptables binary to use.
+ * @param ctx context
+ * @return script header
+ */
+ private static String scriptHeader(Context ctx) {
+ final String dir = ctx.getDir("bin",0).getAbsolutePath();
+ final String myiptables = dir + (isARMv6() ? "/iptables_g1" : "/iptables_n1");
+ return "" +
+ "IPTABLES=iptables\n" +
+ "BUSYBOX=busybox\n" +
+ "GREP=grep\n" +
+ "ECHO=echo\n" +
+ "# Try to find busybox\n" +
+ "if " + dir + "/busybox_g1 --help >/dev/null 2>/dev/null ; then\n" +
+ " BUSYBOX="+dir+"/busybox_g1\n" +
+ " GREP=\"$BUSYBOX grep\"\n" +
+ " ECHO=\"$BUSYBOX echo\"\n" +
+ "elif busybox --help >/dev/null 2>/dev/null ; then\n" +
+ " BUSYBOX=busybox\n" +
+ "elif /system/xbin/busybox --help >/dev/null 2>/dev/null ; then\n" +
+ " BUSYBOX=/system/xbin/busybox\n" +
+ "elif /system/bin/busybox --help >/dev/null 2>/dev/null ; then\n" +
+ " BUSYBOX=/system/bin/busybox\n" +
+ "fi\n" +
+ "# Try to find grep\n" +
+ "if ! $ECHO 1 | $GREP -q 1 >/dev/null 2>/dev/null ; then\n" +
+ " if $ECHO 1 | $BUSYBOX grep -q 1 >/dev/null 2>/dev/null ; then\n" +
+ " GREP=\"$BUSYBOX grep\"\n" +
+ " fi\n" +
+ " # Grep is absolutely required\n" +
+ " if ! $ECHO 1 | $GREP -q 1 >/dev/null 2>/dev/null ; then\n" +
+ " $ECHO The grep command is required. DroidWall will not work.\n" +
+ " exit 1\n" +
+ " fi\n" +
+ "fi\n" +
+ "# Try to find iptables\n" +
+ "if " + myiptables + " --version >/dev/null 2>/dev/null ; then\n" +
+ " IPTABLES="+myiptables+"\n" +
+ "fi\n" +
+ "";
+ }
+ /**
+ * Copies a raw resource file, given its ID to the given location
+ * @param ctx context
+ * @param resid resource id
+ * @param file destination file
+ * @param mode file permissions (E.g.: "755")
+ * @throws IOException on error
+ * @throws InterruptedException when interrupted
+ */
+ private static void copyRawFile(Context ctx, int resid, File file, String mode) throws IOException, InterruptedException
+ {
+ final String abspath = file.getAbsolutePath();
+ // Write the iptables binary
+ final FileOutputStream out = new FileOutputStream(file);
+ final InputStream is = ctx.getResources().openRawResource(resid);
+ byte buf[] = new byte[1024];
+ int len;
+ while ((len = is.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ out.close();
+ is.close();
+ // Change the permissions
+ Runtime.getRuntime().exec("chmod "+mode+" "+abspath).waitFor();
+ }
+ /**
+ * Purge and re-add all rules (internal implementation).
+ * @param ctx application context (mandatory)
+ * @param uidsWifi list of selected UIDs for WIFI to allow or disallow (depending on the working mode)
+ * @param uids3g list of selected UIDs for 2G/3G to allow or disallow (depending on the working mode)
+ * @param showErrors indicates if errors should be alerted
+ */
+ private static boolean applyIptablesRulesImpl(Context ctx, List<Integer> uidsWifi, List<Integer> uids3g, boolean showErrors) {
+ if (ctx == null) {
+ return false;
+ }
+ assertBinaries(ctx, showErrors);
+ final String ITFS_WIFI[] = {"tiwlan+", "wlan+", "eth+"};
+ final String ITFS_3G[] = {"rmnet+","pdp+","ppp+","uwbr+","wimax+","vsnet+"};
+ final SharedPreferences prefs = ctx.getSharedPreferences(PREFS_NAME, 0);
+ final boolean whitelist = prefs.getString(PREF_MODE, MODE_WHITELIST).equals(MODE_WHITELIST);
+ final boolean blacklist = !whitelist;
+ final boolean logenabled = ctx.getSharedPreferences(PREFS_NAME, 0).getBoolean(PREF_LOGENABLED, false);
+
+ final StringBuilder script = new StringBuilder();
+ try {
+ int code;
+ script.append(scriptHeader(ctx));
+ script.append("" +
+ "$IPTABLES --version || exit 1\n" +
+ "# Create the droidwall chains if necessary\n" +
+ "$IPTABLES -L droidwall >/dev/null 2>/dev/null || $IPTABLES --new droidwall || exit 2\n" +
+ "$IPTABLES -L droidwall-3g >/dev/null 2>/dev/null || $IPTABLES --new droidwall-3g || exit 3\n" +
+ "$IPTABLES -L droidwall-wifi >/dev/null 2>/dev/null || $IPTABLES --new droidwall-wifi || exit 4\n" +
+ "$IPTABLES -L droidwall-reject >/dev/null 2>/dev/null || $IPTABLES --new droidwall-reject || exit 5\n" +
+ "# Add droidwall chain to OUTPUT chain if necessary\n" +
+ "$IPTABLES -L OUTPUT | $GREP -q droidwall || $IPTABLES -A OUTPUT -j droidwall || exit 6\n" +
+ "# Flush existing rules\n" +
+ "$IPTABLES -F droidwall || exit 7\n" +
+ "$IPTABLES -F droidwall-3g || exit 8\n" +
+ "$IPTABLES -F droidwall-wifi || exit 9\n" +
+ "$IPTABLES -F droidwall-reject || exit 10\n" +
+ "");
+ // Check if logging is enabled
+ if (logenabled) {
+ script.append("" +
+ "# Create the log and reject rules (ignore errors on the LOG target just in case it is not available)\n" +
+ "$IPTABLES -A droidwall-reject -j LOG --log-prefix \"[DROIDWALL] \" --log-uid\n" +
+ "$IPTABLES -A droidwall-reject -j REJECT || exit 11\n" +
+ "");
+ } else {
+ script.append("" +
+ "# Create the reject rule (log disabled)\n" +
+ "$IPTABLES -A droidwall-reject -j REJECT || exit 11\n" +
+ "");
+ }
+ if (whitelist && logenabled) {
+ script.append("# Allow DNS lookups on white-list for a better logging (ignore errors)\n");
+ script.append("$IPTABLES -A droidwall -p udp --dport 53 -j RETURN\n");
+ }
+ script.append("# Main rules (per interface)\n");
+ for (final String itf : ITFS_3G) {
+ script.append("$IPTABLES -A droidwall -o ").append(itf).append(" -j droidwall-3g || exit\n");
+ }
+ for (final String itf : ITFS_WIFI) {
+ script.append("$IPTABLES -A droidwall -o ").append(itf).append(" -j droidwall-wifi || exit\n");
+ }
+
+ script.append("# Filtering rules\n");
+ final String targetRule = (whitelist ? "RETURN" : "droidwall-reject");
+ final boolean any_3g = uids3g.indexOf(SPECIAL_UID_ANY) >= 0;
+ final boolean any_wifi = uidsWifi.indexOf(SPECIAL_UID_ANY) >= 0;
+ if (whitelist && !any_wifi) {
+ // When "white listing" wifi, we need to ensure that the dhcp and wifi users are allowed
+ int uid = android.os.Process.getUidForName("dhcp");
+ if (uid != -1) {
+ script.append("# dhcp user\n");
+ script.append("$IPTABLES -A droidwall-wifi -m owner --uid-owner ").append(uid).append(" -j RETURN || exit\n");
+ }
+ uid = android.os.Process.getUidForName("wifi");
+ if (uid != -1) {
+ script.append("# wifi user\n");
+ script.append("$IPTABLES -A droidwall-wifi -m owner --uid-owner ").append(uid).append(" -j RETURN || exit\n");
+ }
+ }
+ if (any_3g) {
+ if (blacklist) {
+ /* block any application on this interface */
+ script.append("$IPTABLES -A droidwall-3g -j ").append(targetRule).append(" || exit\n");
+ }
+ } else {
+ /* release/block individual applications on this interface */
+ for (final Integer uid : uids3g) {
+ if (uid >= 0) script.append("$IPTABLES -A droidwall-3g -m owner --uid-owner ").append(uid).append(" -j ").append(targetRule).append(" || exit\n");
+ }
+ }
+ if (any_wifi) {
+ if (blacklist) {
+ /* block any application on this interface */
+ script.append("$IPTABLES -A droidwall-wifi -j ").append(targetRule).append(" || exit\n");
+ }
+ } else {
+ /* release/block individual applications on this interface */
+ for (final Integer uid : uidsWifi) {
+ if (uid >= 0) script.append("$IPTABLES -A droidwall-wifi -m owner --uid-owner ").append(uid).append(" -j ").append(targetRule).append(" || exit\n");
+ }
+ }
+ if (whitelist) {
+ if (!any_3g) {
+ if (uids3g.indexOf(SPECIAL_UID_KERNEL) >= 0) {
+ script.append("# hack to allow kernel packets on white-list\n");
+ script.append("$IPTABLES -A droidwall-3g -m owner --uid-owner 0:999999999 -j droidwall-reject || exit\n");
+ } else {
+ script.append("$IPTABLES -A droidwall-3g -j droidwall-reject || exit\n");
+ }
+ }
+ if (!any_wifi) {
+ if (uidsWifi.indexOf(SPECIAL_UID_KERNEL) >= 0) {
+ script.append("# hack to allow kernel packets on white-list\n");
+ script.append("$IPTABLES -A droidwall-wifi -m owner --uid-owner 0:999999999 -j droidwall-reject || exit\n");
+ } else {
+ script.append("$IPTABLES -A droidwall-wifi -j droidwall-reject || exit\n");
+ }
+ }
+ } else {
+ if (uids3g.indexOf(SPECIAL_UID_KERNEL) >= 0) {
+ script.append("# hack to BLOCK kernel packets on black-list\n");
+ script.append("$IPTABLES -A droidwall-3g -m owner --uid-owner 0:999999999 -j RETURN || exit\n");
+ script.append("$IPTABLES -A droidwall-3g -j droidwall-reject || exit\n");
+ }
+ if (uidsWifi.indexOf(SPECIAL_UID_KERNEL) >= 0) {
+ script.append("# hack to BLOCK kernel packets on black-list\n");
+ script.append("$IPTABLES -A droidwall-wifi -m owner --uid-owner 0:999999999 -j RETURN || exit\n");
+ script.append("$IPTABLES -A droidwall-wifi -j droidwall-reject || exit\n");
+ }
+ }
+ final StringBuilder res = new StringBuilder();
+ code = runScriptAsRoot(ctx, script.toString(), res);
+ if (showErrors && code != 0) {
+ String msg = res.toString();
+ Log.e("DroidWall", msg);
+ // Remove unnecessary help message from output
+ if (msg.indexOf("\nTry `iptables -h' or 'iptables --help' for more information.") != -1) {
+ msg = msg.replace("\nTry `iptables -h' or 'iptables --help' for more information.", "");
+ }
+ alert(ctx, "Error applying iptables rules. Exit code: " + code + "\n\n" + msg.trim());
+ } else {
+ return true;
+ }
+ } catch (Exception e) {
+ if (showErrors) alert(ctx, "error refreshing iptables: " + e);
+ }
+ return false;
+ }
+ /**
+ * Purge and re-add all saved rules (not in-memory ones).
+ * This is much faster than just calling "applyIptablesRules", since it don't need to read installed applications.
+ * @param ctx application context (mandatory)
+ * @param showErrors indicates if errors should be alerted
+ */
+ public static boolean applySavedIptablesRules(Context ctx, boolean showErrors) {
+ if (ctx == null) {
+ return false;
+ }
+ final SharedPreferences prefs = ctx.getSharedPreferences(PREFS_NAME, 0);
+ final String savedUids_wifi = prefs.getString(PREF_WIFI_UIDS, "");
+ final String savedUids_3g = prefs.getString(PREF_3G_UIDS, "");
+ final List<Integer> uids_wifi = new LinkedList<Integer>();
+ if (savedUids_wifi.length() > 0) {
+ // Check which applications are allowed on wifi
+ final StringTokenizer tok = new StringTokenizer(savedUids_wifi, "|");
+ while (tok.hasMoreTokens()) {
+ final String uid = tok.nextToken();
+ if (!uid.equals("")) {
+ try {
+ uids_wifi.add(Integer.parseInt(uid));
+ } catch (Exception ex) {
+ }
+ }
+ }
+ }
+ final List<Integer> uids_3g = new LinkedList<Integer>();
+ if (savedUids_3g.length() > 0) {
+ // Check which applications are allowed on 2G/3G
+ final StringTokenizer tok = new StringTokenizer(savedUids_3g, "|");
+ while (tok.hasMoreTokens()) {
+ final String uid = tok.nextToken();
+ if (!uid.equals("")) {
+ try {
+ uids_3g.add(Integer.parseInt(uid));
+ } catch (Exception ex) {
+ }
+ }
+ }
+ }
+ return applyIptablesRulesImpl(ctx, uids_wifi, uids_3g, showErrors);
+ }
+
+ /**
+ * Purge and re-add all rules.
+ * @param ctx application context (mandatory)
+ * @param showErrors indicates if errors should be alerted
+ */
+ public static boolean applyIptablesRules(Context ctx, boolean showErrors) {
+ if (ctx == null) {
+ return false;
+ }
+ saveRules(ctx);
+ return applySavedIptablesRules(ctx, showErrors);
+ }
+
+ /**
+ * Save current rules using the preferences storage.
+ * @param ctx application context (mandatory)
+ */
+ public static void saveRules(Context ctx) {
+ final SharedPreferences prefs = ctx.getSharedPreferences(PREFS_NAME, 0);
+ final DroidApp[] apps = getApps(ctx);
+ // Builds a pipe-separated list of names
+ final StringBuilder newuids_wifi = new StringBuilder();
+ final StringBuilder newuids_3g = new StringBuilder();
+ for (int i=0; i<apps.length; i++) {
+ if (apps[i].selected_wifi) {
+ if (newuids_wifi.length() != 0) newuids_wifi.append('|');
+ newuids_wifi.append(apps[i].uid);
+ }
+ if (apps[i].selected_3g) {
+ if (newuids_3g.length() != 0) newuids_3g.append('|');
+ newuids_3g.append(apps[i].uid);
+ }
+ }
+ // save the new list of UIDs
+ final Editor edit = prefs.edit();
+ edit.putString(PREF_WIFI_UIDS, newuids_wifi.toString());
+ edit.putString(PREF_3G_UIDS, newuids_3g.toString());
+ edit.commit();
+ }
+
+ /**
+ * Purge all iptables rules.
+ * @param ctx mandatory context
+ * @param showErrors indicates if errors should be alerted
+ * @return true if the rules were purged
+ */
+ public static boolean purgeIptables(Context ctx, boolean showErrors) {
+ StringBuilder res = new StringBuilder();
+ try {
+ assertBinaries(ctx, showErrors);
+ int code = runScriptAsRoot(ctx, scriptHeader(ctx) +
+ "$IPTABLES -F droidwall\n" +
+ "$IPTABLES -F droidwall-reject\n" +
+ "$IPTABLES -F droidwall-3g\n" +
+ "$IPTABLES -F droidwall-wifi\n", res);
+ if (code == -1) {
+ if (showErrors) alert(ctx, "error purging iptables. exit code: " + code + "\n" + res);
+ return false;
+ }
+ return true;
+ } catch (Exception e) {
+ if (showErrors) alert(ctx, "error purging iptables: " + e);
+ return false;
+ }
+ }
+
+ /**
+ * Display iptables rules output
+ * @param ctx application context
+ */
+ public static void showIptablesRules(Context ctx) {
+ try {
+ final StringBuilder res = new StringBuilder();
+ runScriptAsRoot(ctx, scriptHeader(ctx) +
+ "$ECHO $IPTABLES\n" +
+ "$IPTABLES -L -v\n", res);
+ alert(ctx, res);
+ } catch (Exception e) {
+ alert(ctx, "error: " + e);
+ }
+ }
+
+ /**
+ * Display logs
+ * @param ctx application context
+ * @return true if the clogs were cleared
+ */
+ public static boolean clearLog(Context ctx) {
+ try {
+ final StringBuilder res = new StringBuilder();
+ int code = runScriptAsRoot(ctx, "dmesg -c >/dev/null || exit\n", res);
+ if (code != 0) {
+ alert(ctx, res);
+ return false;
+ }
+ return true;
+ } catch (Exception e) {
+ alert(ctx, "error: " + e);
+ }
+ return false;
+ }
+ /**
+ * Display logs
+ * @param ctx application context
+ */
+ public static void showLog(Context ctx) {
+ try {
+ StringBuilder res = new StringBuilder();
+ int code = runScriptAsRoot(ctx, scriptHeader(ctx) +
+ "dmesg | $GREP DROIDWALL\n", res);
+ if (code != 0) {
+ if (res.length() == 0) {
+ res.append("Log is empty");
+ }
+ alert(ctx, res);
+ return;
+ }
+ final BufferedReader r = new BufferedReader(new StringReader(res.toString()));
+ final Integer unknownUID = -99;
+ res = new StringBuilder();
+ String line;
+ int start, end;
+ Integer appid;
+ final HashMap<Integer, LogInfo> map = new HashMap<Integer, LogInfo>();
+ LogInfo loginfo = null;
+ while ((line = r.readLine()) != null) {
+ if (line.indexOf("[DROIDWALL]") == -1) continue;
+ appid = unknownUID;
+ if (((start=line.indexOf("UID=")) != -1) && ((end=line.indexOf(" ", start)) != -1)) {
+ appid = Integer.parseInt(line.substring(start+4, end));
+ }
+ loginfo = map.get(appid);
+ if (loginfo == null) {
+ loginfo = new LogInfo();
+ map.put(appid, loginfo);
+ }
+ loginfo.totalBlocked += 1;
+ if (((start=line.indexOf("DST=")) != -1) && ((end=line.indexOf(" ", start)) != -1)) {
+ String dst = line.substring(start+4, end);
+ if (loginfo.dstBlocked.containsKey(dst)) {
+ loginfo.dstBlocked.put(dst, loginfo.dstBlocked.get(dst) + 1);
+ } else {
+ loginfo.dstBlocked.put(dst, 1);
+ }
+ }
+ }
+ final DroidApp[] apps = getApps(ctx);
+ for (Integer id : map.keySet()) {
+ res.append("App ID ");
+ if (id != unknownUID) {
+ res.append(id);
+ for (DroidApp app : apps) {
+ if (app.uid == id) {
+ res.append(" (").append(app.names[0]);
+ if (app.names.length > 1) {
+ res.append(", ...)");
+ } else {
+ res.append(")");
+ }
+ break;
+ }
+ }
+ } else {
+ res.append("(kernel)");
+ }
+ loginfo = map.get(id);
+ res.append(" - Blocked ").append(loginfo.totalBlocked).append(" packets");
+ if (loginfo.dstBlocked.size() > 0) {
+ res.append(" (");
+ boolean first = true;
+ for (String dst : loginfo.dstBlocked.keySet()) {
+ if (!first) {
+ res.append(", ");
+ }
+ res.append(loginfo.dstBlocked.get(dst)).append(" packets for ").append(dst);
+ first = false;
+ }
+ res.append(")");
+ }
+ res.append("\n\n");
+ }
+ if (res.length() == 0) {
+ res.append("Log is empty");
+ }
+ alert(ctx, res);
+ } catch (Exception e) {
+ alert(ctx, "error: " + e);
+ }
+ }
+
+ /**
+ * @param ctx application context (mandatory)
+ * @return a list of applications
+ */
+ public static DroidApp[] getApps(Context ctx) {
+ if (applications != null) {
+ // return cached instance
+ return applications;
+ }
+ final SharedPreferences prefs = ctx.getSharedPreferences(PREFS_NAME, 0);
+ // allowed application names separated by pipe '|' (persisted)
+ final String savedUids_wifi = prefs.getString(PREF_WIFI_UIDS, "");
+ final String savedUids_3g = prefs.getString(PREF_3G_UIDS, "");
+ int selected_wifi[] = new int[0];
+ int selected_3g[] = new int[0];
+ if (savedUids_wifi.length() > 0) {
+ // Check which applications are allowed
+ final StringTokenizer tok = new StringTokenizer(savedUids_wifi, "|");
+ selected_wifi = new int[tok.countTokens()];
+ for (int i=0; i<selected_wifi.length; i++) {
+ final String uid = tok.nextToken();
+ if (!uid.equals("")) {
+ try {
+ selected_wifi[i] = Integer.parseInt(uid);
+ } catch (Exception ex) {
+ selected_wifi[i] = -1;
+ }
+ }
+ }
+ // Sort the array to allow using "Arrays.binarySearch" later
+ Arrays.sort(selected_wifi);
+ }
+ if (savedUids_3g.length() > 0) {
+ // Check which applications are allowed
+ final StringTokenizer tok = new StringTokenizer(savedUids_3g, "|");
+ selected_3g = new int[tok.countTokens()];
+ for (int i=0; i<selected_3g.length; i++) {
+ final String uid = tok.nextToken();
+ if (!uid.equals("")) {
+ try {
+ selected_3g[i] = Integer.parseInt(uid);
+ } catch (Exception ex) {
+ selected_3g[i] = -1;
+ }
+ }
+ }
+ // Sort the array to allow using "Arrays.binarySearch" later
+ Arrays.sort(selected_3g);
+ }
+ try {
+ final PackageManager pkgmanager = ctx.getPackageManager();
+ final List<ApplicationInfo> installed = pkgmanager.getInstalledApplications(0);
+ final HashMap<Integer, DroidApp> map = new HashMap<Integer, DroidApp>();
+ final Editor edit = prefs.edit();
+ boolean changed = false;
+ String name = null;
+ String cachekey = null;
+ DroidApp app = null;
+ for (final ApplicationInfo apinfo : installed) {
+ app = map.get(apinfo.uid);
+ // filter applications which are not allowed to access the Internet
+ if (app == null && PackageManager.PERMISSION_GRANTED != pkgmanager.checkPermission(Manifest.permission.INTERNET, apinfo.packageName)) {
+ continue;
+ }
+ // try to get the application label from our cache - getApplicationLabel() is horribly slow!!!!
+ cachekey = "cache.label."+apinfo.packageName;
+ name = prefs.getString(cachekey, "");
+ if (name.length() == 0) {
+ // get label and put on cache
+ name = pkgmanager.getApplicationLabel(apinfo).toString();
+ edit.putString(cachekey, name);
+ changed = true;
+ }
+ if (app == null) {
+ app = new DroidApp();
+ app.uid = apinfo.uid;
+ app.names = new String[] { name };
+ map.put(apinfo.uid, app);
+ } else {
+ final String newnames[] = new String[app.names.length + 1];
+ System.arraycopy(app.names, 0, newnames, 0, app.names.length);
+ newnames[app.names.length] = name;
+ app.names = newnames;
+ }
+ // check if this application is selected
+ if (!app.selected_wifi && Arrays.binarySearch(selected_wifi, app.uid) >= 0) {
+ app.selected_wifi = true;
+ }
+ if (!app.selected_3g && Arrays.binarySearch(selected_3g, app.uid) >= 0) {
+ app.selected_3g = true;
+ }
+ }
+ if (changed) {
+ edit.commit();
+ }
+ /* add special applications to the list */
+ final DroidApp special[] = {
+ new DroidApp(SPECIAL_UID_ANY,"(Any application) - Same as selecting all applications", false, false),
+ new DroidApp(SPECIAL_UID_KERNEL,"(Kernel) - Linux kernel", false, false),
+ new DroidApp(android.os.Process.getUidForName("root"), "(root) - Applications running as root", false, false),
+ new DroidApp(android.os.Process.getUidForName("media"), "Media server", false, false),
+ new DroidApp(android.os.Process.getUidForName("vpn"), "VPN networking", false, false),
+ new DroidApp(android.os.Process.getUidForName("shell"), "Linux shell", false, false),
+ };
+ for (int i=0; i<special.length; i++) {
+ app = special[i];
+ if (app.uid != -1 && !map.containsKey(app.uid)) {
+ // check if this application is allowed
+ if (Arrays.binarySearch(selected_wifi, app.uid) >= 0) {
+ app.selected_wifi = true;
+ }
+ if (Arrays.binarySearch(selected_3g, app.uid) >= 0) {
+ app.selected_3g = true;
+ }
+ map.put(app.uid, app);
+ }
+ }
+ applications = new DroidApp[map.size()];
+ int index = 0;
+ for (DroidApp application : map.values()) applications[index++] = application;
+ return applications;
+ } catch (Exception e) {
+ alert(ctx, "error: " + e);
+ }
+ return null;
+ }
+ /**
+ * Check if we have root access
+ * @param ctx mandatory context
+ * @param showErrors indicates if errors should be alerted
+ * @return boolean true if we have root
+ */
+ public static boolean hasRootAccess(Context ctx, boolean showErrors) {
+ if (hasroot) return true;
+ final StringBuilder res = new StringBuilder();
+ try {
+ // Run an empty script just to check root access
+ if (runScriptAsRoot(ctx, "exit 0", res) == 0) {
+ hasroot = true;
+ return true;
+ }
+ } catch (Exception e) {
+ }
+ if (showErrors) {
+ alert(ctx, "Could not acquire root access.\n" +
+ "You need a rooted phone to run DroidWall.\n\n" +
+ "If this phone is already rooted, please make sure DroidWall has enough permissions to execute the \"su\" command.\n" +
+ "Error message: " + res.toString());
+ }
+ return false;
+ }
+ /**
+ * Runs a script, wither as root or as a regular user (multiple commands separated by "\n").
+ * @param ctx mandatory context
+ * @param script the script to be executed
+ * @param res the script output response (stdout + stderr)
+ * @param timeout timeout in milliseconds (-1 for none)
+ * @return the script exit code
+ */
+ public static int runScript(Context ctx, String script, StringBuilder res, long timeout, boolean asroot) {
+ final File file = new File(ctx.getDir("bin",0), SCRIPT_FILE);
+ final ScriptRunner runner = new ScriptRunner(file, script, res, asroot);
+ runner.start();
+ try {
+ if (timeout > 0) {
+ runner.join(timeout);
+ } else {
+ runner.join();
+ }
+ if (runner.isAlive()) {
+ // Timed-out
+ runner.interrupt();
+ runner.join(150);
+ runner.destroy();
+ runner.join(50);
+ }
+ } catch (InterruptedException ex) {}
+ return runner.exitcode;
+ }
+ /**
+ * Runs a script as root (multiple commands separated by "\n").
+ * @param ctx mandatory context
+ * @param script the script to be executed
+ * @param res the script output response (stdout + stderr)
+ * @param timeout timeout in milliseconds (-1 for none)
+ * @return the script exit code
+ */
+ public static int runScriptAsRoot(Context ctx, String script, StringBuilder res, long timeout) {
+ return runScript(ctx, script, res, timeout, true);
+ }
+ /**
+ * Runs a script as root (multiple commands separated by "\n") with a default timeout of 20 seconds.
+ * @param ctx mandatory context
+ * @param script the script to be executed
+ * @param res the script output response (stdout + stderr)
+ * @param timeout timeout in milliseconds (-1 for none)
+ * @return the script exit code
+ * @throws IOException on any error executing the script, or writing it to disk
+ */
+ public static int runScriptAsRoot(Context ctx, String script, StringBuilder res) throws IOException {
+ return runScriptAsRoot(ctx, script, res, 40000);
+ }
+ /**
+ * Runs a script as a regular user (multiple commands separated by "\n") with a default timeout of 20 seconds.
+ * @param ctx mandatory context
+ * @param script the script to be executed
+ * @param res the script output response (stdout + stderr)
+ * @param timeout timeout in milliseconds (-1 for none)
+ * @return the script exit code
+ * @throws IOException on any error executing the script, or writing it to disk
+ */
+ public static int runScript(Context ctx, String script, StringBuilder res) throws IOException {
+ return runScript(ctx, script, res, 40000, false);
+ }
+ /**
+ * Asserts that the binary files are installed in the cache directory.
+ * @param ctx context
+ * @param showErrors indicates if errors should be alerted
+ * @return false if the binary files could not be installed
+ */
+ public static boolean assertBinaries(Context ctx, boolean showErrors) {
+ boolean changed = false;
+ try {
+ // Check iptables_g1
+ File file = new File(ctx.getDir("bin",0), "iptables_g1");
+ if ((!file.exists()) && isARMv6()) {
+ copyRawFile(ctx, R.raw.iptables_g1, file, "755");
+ changed = true;
+ }
+ // Check iptables_n1
+ file = new File(ctx.getDir("bin",0), "iptables_n1");
+ if ((!file.exists()) && (!isARMv6())) {
+ copyRawFile(ctx, R.raw.iptables_n1, file, "755");
+ changed = true;
+ }
+ // Check busybox
+ file = new File(ctx.getDir("bin",0), "busybox_g1");
+ if (!file.exists()) {
+ copyRawFile(ctx, R.raw.busybox_g1, file, "755");
+ changed = true;
+ }
+ if (changed) {
+ Toast.makeText(ctx, R.string.status_install_success, Toast.LENGTH_LONG).show();
+ }
+ } catch (Exception e) {
+ if (showErrors) alert(ctx, "Error installing binary files: " + e);
+ return false;
+ }
+ return true;
+ }
+ /**
+ * Check if the firewall is enabled
+ * @param ctx mandatory context
+ * @return boolean
+ */
+ public static boolean isEnabled(Context ctx) {
+ if (ctx == null) return false;
+ return ctx.getSharedPreferences(PREFS_NAME, 0).getBoolean(PREF_ENABLED, false);
+ }
+
+ /**
+ * Defines if the firewall is enabled and broadcasts the new status
+ * @param ctx mandatory context
+ * @param enabled enabled flag
+ */
+ public static void setEnabled(Context ctx, boolean enabled) {
+ if (ctx == null) return;
+ final SharedPreferences prefs = ctx.getSharedPreferences(PREFS_NAME, 0);
+ if (prefs.getBoolean(PREF_ENABLED, false) == enabled) {
+ return;
+ }
+ final Editor edit = prefs.edit();
+ edit.putBoolean(PREF_ENABLED, enabled);
+ if (!edit.commit()) {
+ alert(ctx, "Error writing to preferences");
+ return;
+ }
+ /* notify */
+ final Intent message = new Intent(Api.STATUS_CHANGED_MSG);
+ message.putExtra(Api.STATUS_EXTRA, enabled);
+ ctx.sendBroadcast(message);
+ }
+ /**
+ * Called when an application in removed (un-installed) from the system.
+ * This will look for that application in the selected list and update the persisted values if necessary
+ * @param ctx mandatory app context
+ * @param uid UID of the application that has been removed
+ */
+ public static void applicationRemoved(Context ctx, int uid) {
+ final SharedPreferences prefs = ctx.getSharedPreferences(PREFS_NAME, 0);
+ final Editor editor = prefs.edit();
+ // allowed application names separated by pipe '|' (persisted)
+ final String savedUids_wifi = prefs.getString(PREF_WIFI_UIDS, "");
+ final String savedUids_3g = prefs.getString(PREF_3G_UIDS, "");
+ final String uid_str = uid + "";
+ boolean changed = false;
+ // look for the removed application in the "wi-fi" list
+ if (savedUids_wifi.length() > 0) {
+ final StringBuilder newuids = new StringBuilder();
+ final StringTokenizer tok = new StringTokenizer(savedUids_wifi, "|");
+ while (tok.hasMoreTokens()) {
+ final String token = tok.nextToken();
+ if (uid_str.equals(token)) {
+ Log.d("DroidWall", "Removing UID " + token + " from the wi-fi list (package removed)!");
+ changed = true;
+ } else {
+ if (newuids.length() > 0) newuids.append('|');
+ newuids.append(token);
+ }
+ }
+ if (changed) {
+ editor.putString(PREF_WIFI_UIDS, newuids.toString());
+ }
+ }
+ // look for the removed application in the "3g" list
+ if (savedUids_3g.length() > 0) {
+ final StringBuilder newuids = new StringBuilder();
+ final StringTokenizer tok = new StringTokenizer(savedUids_3g, "|");
+ while (tok.hasMoreTokens()) {
+ final String token = tok.nextToken();
+ if (uid_str.equals(token)) {
+ Log.d("DroidWall", "Removing UID " + token + " from the 3G list (package removed)!");
+ changed = true;
+ } else {
+ if (newuids.length() > 0) newuids.append('|');
+ newuids.append(token);
+ }
+ }
+ if (changed) {
+ editor.putString(PREF_3G_UIDS, newuids.toString());
+ }
+ }
+ // if anything has changed, save the new prefs...
+ if (changed) {
+ editor.commit();
+ if (isEnabled(ctx)) {
+ // .. and also re-apply the rules if the firewall is enabled
+ applySavedIptablesRules(ctx, false);
+ }
+ }
+ }
+
+ /**
+ * Small structure to hold an application info
+ */
+ public static final class DroidApp {
+ /** linux user id */
+ int uid;
+ /** application names belonging to this user id */
+ String names[];
+ /** indicates if this application is selected for wifi */
+ boolean selected_wifi;
+ /** indicates if this application is selected for 3g */
+ boolean selected_3g;
+ /** toString cache */
+ String tostr;
+
+ public DroidApp() {
+ }
+ public DroidApp(int uid, String name, boolean selected_wifi, boolean selected_3g) {
+ this.uid = uid;
+ this.names = new String[] {name};
+ this.selected_wifi = selected_wifi;
+ this.selected_3g = selected_3g;
+ }
+ /**
+ * Screen representation of this application
+ */
+ @Override
+ public String toString() {
+ if (tostr == null) {
+ final StringBuilder s = new StringBuilder();
+ if (uid > 0) s.append(uid + ": ");
+ for (int i=0; i<names.length; i++) {
+ if (i != 0) s.append(", ");
+ s.append(names[i]);
+ }
+ s.append("\n");
+ tostr = s.toString();
+ }
+ return tostr;
+ }
+ }
+ /**
+ * Small internal structure used to hold log information
+ */
+ private static final class LogInfo {
+ private int totalBlocked; // Total number of packets blocked
+ private HashMap<String, Integer> dstBlocked; // Number of packets blocked per destination IP address
+ private LogInfo() {
+ this.dstBlocked = new HashMap<String, Integer>();
+ }
+ }
+ /**
+ * Internal thread used to execute scripts (as root or not).
+ */
+ private static final class ScriptRunner extends Thread {
+ private final File file;
+ private final String script;
+ private final StringBuilder res;
+ private final boolean asroot;
+ public int exitcode = -1;
+ private Process exec;
+
+ /**
+ * Creates a new script runner.
+ * @param file temporary script file
+ * @param script script to run
+ * @param res response output
+ * @param asroot if true, executes the script as root
+ */
+ public ScriptRunner(File file, String script, StringBuilder res, boolean asroot) {
+ this.file = file;
+ this.script = script;
+ this.res = res;
+ this.asroot = asroot;
+ }
+ @Override
+ public void run() {
+ try {
+ file.createNewFile();
+ final String abspath = file.getAbsolutePath();
+ // make sure we have execution permission on the script file
+ Runtime.getRuntime().exec("chmod 777 "+abspath).waitFor();
+ // Write the script to be executed
+ final OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file));
+ if (new File("/system/bin/sh").exists()) {
+ out.write("#!/system/bin/sh\n");
+ }
+ out.write(script);
+ if (!script.endsWith("\n")) out.write("\n");
+ out.write("exit\n");
+ out.flush();
+ out.close();
+ if (this.asroot) {
+ // Create the "su" request to run the script
+ exec = Runtime.getRuntime().exec("su -c "+abspath);
+ } else {
+ // Create the "sh" request to run the script
+ exec = Runtime.getRuntime().exec("sh "+abspath);
+ }
+ InputStreamReader r = new InputStreamReader(exec.getInputStream());
+ final char buf[] = new char[1024];
+ int read = 0;
+ // Consume the "stdout"
+ while ((read=r.read(buf)) != -1) {
+ if (res != null) res.append(buf, 0, read);
+ }
+ // Consume the "stderr"
+ r = new InputStreamReader(exec.getErrorStream());
+ read=0;
+ while ((read=r.read(buf)) != -1) {
+ if (res != null) res.append(buf, 0, read);
+ }
+ // get the process exit code
+ if (exec != null) this.exitcode = exec.waitFor();
+ } catch (InterruptedException ex) {
+ if (res != null) res.append("\nOperation timed-out");
+ } catch (Exception ex) {
+ if (res != null) res.append("\n" + ex);
+ } finally {
+ destroy();
+ }
+ }
+ /**
+ * Destroy this script runner
+ */
+ public synchronized void destroy() {
+ if (exec != null) exec.destroy();
+ exec = null;
+ }
+ }
+}
1
0