commit 544ea7bd75b701678cca9dc6c33fe552f6e0330b Author: n8fr8 nathan@freitas.net Date: Sun Dec 3 17:30:07 2017 +0530
update build to use tor version constant from tor-android-binary --- BUILD | 37 +-- .../org/torproject/android/OrbotMainActivity.java | 5 +- .../android/ui/OrbotDiagnosticsActivity.java | 328 --------------------- orbotservice/build.gradle | 4 +- .../org/torproject/android/service/TorService.java | 2 + .../android/service/TorServiceConstants.java | 2 +- 6 files changed, 15 insertions(+), 363 deletions(-)
diff --git a/BUILD b/BUILD index f9204608..92a5f3bf 100644 --- a/BUILD +++ b/BUILD @@ -2,50 +2,27 @@ This document explains how to properly build an Android package of Orbot from source.
+DECEMBER 2017: We have removed the build process for tor and polipo from Orbot, +and instead now use the new tor-android gradle dependency: https://github.com/n8fr8/tor-android + Orbot includes, in the external directory, git repo submodules of: - - Tor - - OpenSSL (statically built and patched for Android) - - LibEvent - JTorControl: The Tor Control Library for Java
-The Orbot repo also includes the Polipo source code of a recent stable release. - Please install the following prerequisites (instructions for each follows): ant: http://ant.apache.org/ Android Native Dev Kit or NDK (for C/C++ code): http://developer.android.com/sdk/ndk/index.html Android Software Dev Kit or SDK (for Java code): http://developer.android.com/sdk/index.html - AutoMake and AutoConf tool - sudo apt-get install autotools-dev - sudo apt-get install automake - sudo apt-get install autogen autoconf libtool - sudo apt-get install autopoint gettext-base pkg-config - -You will need to run the 'android' command in the SDK to install the necessary -Android platform supports (ICS 4.x or android-15)
Be sure that you have all of the git submodules up-to-date:
git submodule update --init --recursive
-To begin building, from the Orbot root directory, you first need to build all -external C/native dependencies: - - export ANDROID_NDK_HOME={PATH TO YOUR NDK INSTALL} - make -C external - -At this point, you'll have Tor and Polipo binaries that can be run on an -Android handset. You can verify the ARM binary was properly built using the -following command: - - file external/bin/tor external/bin/polipo +You then need to run "ndk-build" from: -You should see something like: - external/bin/tor: ELF 32-bit LSB executable, ARM, version 1 (SYSV), - dynamically linked (uses shared libs), not stripped - external/bin/polipo: ELF 32-bit LSB executable, ARM, version 1 (SYSV), - dynamically linked (uses shared libs), not stripped + cd orbotservice/src/main + ndk-build
This isn't enough though and we'll now sew up the binary into a small package that will handle basic Tor controlling features. @@ -56,7 +33,7 @@ Now build the Android app
(gradle / android studio instructions here)
-This will produce an unsigned Tor package APK. +This will produce an unsigned Orbot package APK.
To produce a usable package, you'll need to sign the .apk. The basics on signing can be found on the Android developer site: diff --git a/app/src/main/java/org/torproject/android/OrbotMainActivity.java b/app/src/main/java/org/torproject/android/OrbotMainActivity.java index 60a3a2c5..17a81806 100644 --- a/app/src/main/java/org/torproject/android/OrbotMainActivity.java +++ b/app/src/main/java/org/torproject/android/OrbotMainActivity.java @@ -90,6 +90,7 @@ import com.google.zxing.integration.android.IntentIntegrator; import com.google.zxing.integration.android.IntentResult;
import static android.support.v4.content.FileProvider.getUriForFile; +import static org.torproject.android.binary.TorServiceConstants.BINARY_TOR_VERSION;
public class OrbotMainActivity extends AppCompatActivity implements OrbotConstants, OnLongClickListener, OnTouchListener { @@ -432,7 +433,7 @@ public class OrbotMainActivity extends AppCompatActivity
});
- ((TextView)findViewById(R.id.torInfo)).setText("Tor v" + TorServiceConstants.BINARY_TOR_VERSION); + ((TextView)findViewById(R.id.torInfo)).setText("Tor v" + BINARY_TOR_VERSION);
}
@@ -534,7 +535,7 @@ public class OrbotMainActivity extends AppCompatActivity String version = "";
try { - version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName + " (Tor " + TorServiceConstants.BINARY_TOR_VERSION + ")"; + version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName + " (Tor " + BINARY_TOR_VERSION + ")"; } catch (NameNotFoundException e) { version = "Version Not Found"; } diff --git a/app/src/main/java/org/torproject/android/ui/OrbotDiagnosticsActivity.java b/app/src/main/java/org/torproject/android/ui/OrbotDiagnosticsActivity.java deleted file mode 100644 index 63c54378..00000000 --- a/app/src/main/java/org/torproject/android/ui/OrbotDiagnosticsActivity.java +++ /dev/null @@ -1,328 +0,0 @@ -package org.torproject.android.ui; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -import org.torproject.android.R; -import org.torproject.android.service.util.TorResourceInstaller; -import org.torproject.android.service.TorServiceConstants; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.os.Environment; -import android.os.Handler; -import android.os.Message; -import android.os.StatFs; -import android.text.format.Formatter; -import android.util.Log; -import android.view.Menu; -import android.view.MenuItem; -import android.widget.TextView; - - -public class OrbotDiagnosticsActivity extends Activity { - - private TextView mTextView = null; - private final static String TAG = "OrbotDiag"; - private StringBuffer log = new StringBuffer(); - Process mProcess; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setContentView(R.layout.layout_diag); - - mTextView = (TextView)findViewById(R.id.diaglog); - - } - - private String getFreeStorage () - { - File path = Environment.getDataDirectory(); - StatFs stat = new StatFs(path.getPath()); - long blockSize = stat.getBlockSize(); - long availableBlocks = stat.getAvailableBlocks(); - return Formatter.formatFileSize(this, availableBlocks * blockSize); - } - - @Override - protected void onPause() { - super.onPause(); - - stopTor(); - } - - @Override - protected void onDestroy() { - - super.onDestroy(); - - } - - private void stopTor () - { - File appBinHome = this.getDir("bin", Context.MODE_PRIVATE); - - File fileTor= new File(appBinHome, TorServiceConstants.TOR_ASSET_KEY); - - if (mProcess != null) - mProcess.destroy(); - - - } - - - - @Override - protected void onResume() { - super.onResume(); - - - log("Hello, Orbot!"); - - try - { - log(android.os.Build.DEVICE); - log(android.os.Build.HARDWARE); - log(android.os.Build.MANUFACTURER); - log(android.os.Build.MODEL); - log(android.os.Build.VERSION.CODENAME); - log(android.os.Build.VERSION.RELEASE); - } - catch (Exception e) - { - log("error getting device info"); - } - - showFileTree (); - - runTorTest(); - } - - private void runTorTest () - { - try - { - File appBinHome = this.getDir("bin", Context.MODE_PRIVATE); - File appDataHome = this.getDir("data", Context.MODE_PRIVATE); - - File fileTor= new File(appBinHome, TorServiceConstants.TOR_ASSET_KEY); - enableBinExec (fileTor, appBinHome); - - InputStream is = getResources().openRawResource(R.raw.torrc); - File fileTorrc = new File(appBinHome, TorServiceConstants.TORRC_ASSET_KEY + "diag"); - TorResourceInstaller.streamToFile(is,fileTorrc, false, false); - - /** - ArrayList<String> alEnv = new ArrayList<String>(); - alEnv.add("HOME=" + appBinHome.getAbsolutePath()); - Shell shell = Shell.startShell(alEnv,appBinHome.getAbsolutePath()); - SimpleCommand cmdTor = new SimpleCommand(fileTor.getAbsolutePath() + " DataDirectory " + appDataHome.getAbsolutePath() + " -f " + fileTorrc.getAbsolutePath()); - shell.add(cmdTor); - **/ - - String cmd = fileTor.getAbsolutePath() + " DataDirectory " + appDataHome.getAbsolutePath() + " -f " + fileTorrc.getAbsolutePath(); - - log ("Executing command> " + cmd); - - mProcess = Runtime.getRuntime().exec(cmd); - - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(mProcess.getInputStream())); - StreamGobbler sg = new StreamGobbler(); - sg.reader = bufferedReader; - sg.process = mProcess; - new Thread(sg).start(); - - if (mProcess.getErrorStream() != null) - { - bufferedReader = new BufferedReader(new InputStreamReader(mProcess.getErrorStream())); - sg = new StreamGobbler(); - sg.reader = bufferedReader; - sg.process = mProcess; - new Thread(sg).start(); - } - - - } - catch (Exception e) - { - Log.d(TAG,"runTorTest exception",e); - } - - } - - class StreamGobbler implements Runnable - { - BufferedReader reader; - Process process; - - public void run () - { - String line = null; - try { - while ( (line = reader.readLine()) != null) - { - Message msg = mHandler.obtainMessage(0); - msg.getData().putString("log", line); - mHandler.sendMessage(msg); - } - - } catch (IOException e) { - Log.d(TAG, "error reading line",e); - } - - //log("Tor exit code=" + process.exitValue() + ";"); - - } - } - - private boolean enableBinExec (File fileBin, File appBinHome) throws Exception - { - - log(fileBin.getName() + ": PRE: Is binary exec? " + fileBin.canExecute()); - - if (!fileBin.canExecute()) - { - log("(re)Setting permission on binary: " + fileBin.getAbsolutePath()); - - Runtime.getRuntime().exec("chmod " + TorServiceConstants.CHMOD_EXE_VALUE + ' ' + fileBin.getAbsolutePath()).waitFor(); - - File fileTest = new File(fileBin.getAbsolutePath()); - log(fileTest.getName() + ": POST: Is binary exec? " + fileTest.canExecute()); - - } - - return fileBin.canExecute(); - } - - private void showFileTree () - { - - File fileDir = this.getDir("bin", Context.MODE_PRIVATE); - - if (fileDir.exists()) - { - log("checking file tree: " + fileDir.getAbsolutePath()); - printDir (fileDir.getName(), fileDir); - } - else - { - log("app_bin does not exist"); - } - - fileDir = this.getDir("data", Context.MODE_PRIVATE); - if (fileDir.exists()) - { - log("checking file tree: " + fileDir.getAbsolutePath()); - printDir (fileDir.getName(), fileDir); - } - else - { - log ("app_data does not exist"); - } - - - } - - private void printDir (String path, File fileDir) - { - File[] files = fileDir.listFiles(); - - if (files != null && files.length > 0) - { - for (File file : files) - { - - try - { - if (file.isDirectory()) - { - printDir(path + '/' + file.getName(), file); - } - else - { - log(path + '/' + file.getName() + " len:" + file.length() + " exec:" + file.canExecute()); - - } - } - catch (Exception e) - { - log("problem printing out file information"); - } - - } - } - } - - Handler mHandler = new Handler () - { - - @Override - public void handleMessage(Message msg) { - - super.handleMessage(msg); - - String logMsg = msg.getData().getString("log"); - log(logMsg); - } - - }; - - private void log (String msg) - { - Log.d(TAG, msg); - mTextView.append(msg + '\n'); - log.append(msg + '\n'); - } - - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate menu resource file. - getMenuInflater().inflate(R.menu.share_menu, menu); - - // Locate MenuItem with ShareActionProvider - MenuItem item = menu.findItem(R.id.menu_item_share); - - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - - case R.id.menu_item_share: - sendLog(); - return true; - - default: - return super.onOptionsItemSelected(item); - } - } - - private void sendLog () - { - int maxLength = 5000; - - String logShare = null; - - if (log.length() > maxLength) - logShare = log.substring(0, maxLength); - else - logShare = log.toString(); - - Intent sendIntent = new Intent(); - sendIntent.setAction(Intent.ACTION_SEND); - sendIntent.putExtra(Intent.EXTRA_TEXT, logShare); - sendIntent.setType("text/plain"); - startActivity(sendIntent); - } - - -} diff --git a/orbotservice/build.gradle b/orbotservice/build.gradle index fa89fa22..b76a3841 100644 --- a/orbotservice/build.gradle +++ b/orbotservice/build.gradle @@ -28,8 +28,8 @@ android {
dependencies { compile project(':jsocksAndroid') - compile 'org.torproject:tor-android-binary:0.3.1.9' - compile 'com.android.support:appcompat-v7:25.0.0' + compile 'org.torproject:tor-android-binary:0.3.1.9a' + compile 'com.android.support:appcompat-v7:25.4.0' compile 'com.jrummyapps:android-shell:1.0.1' compile fileTree(dir: 'libs', include: ['*.jar','*.so']) testCompile 'junit:junit:4.12' diff --git a/orbotservice/src/main/java/org/torproject/android/service/TorService.java b/orbotservice/src/main/java/org/torproject/android/service/TorService.java index b7e48f95..53a40339 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/TorService.java +++ b/orbotservice/src/main/java/org/torproject/android/service/TorService.java @@ -80,6 +80,8 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeoutException;
+import static org.torproject.android.binary.TorServiceConstants.BINARY_TOR_VERSION; + public class TorService extends Service implements TorServiceConstants, OrbotConstants {
diff --git a/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java b/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java index b91f2b2d..4b62a6a8 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java +++ b/orbotservice/src/main/java/org/torproject/android/service/TorServiceConstants.java @@ -135,7 +135,7 @@ public interface TorServiceConstants { String CMD_UPDATE_TRANS_PROXY = "update"; String CMD_SET_EXIT = "setexit";
- String BINARY_TOR_VERSION = "0.3.1.8-openssl1.0.2k"; + // String BINARY_TOR_VERSION = "0.3.1.8-openssl1.0.2k"; String PREF_BINARY_TOR_VERSION_INSTALLED = "BINARY_TOR_VERSION_INSTALLED";
//obfsproxy
tor-commits@lists.torproject.org