[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [orbot/master] switch to using tor-android binary in TorService



commit 3d729fc867666f68598965506d9d69476968a15c
Author: n8fr8 <nathan@xxxxxxxxxxx>
Date:   Sun Dec 3 15:11:10 2017 +0530

    switch to using tor-android binary in TorService
---
 .../org/torproject/android/service/TorService.java |  10 +-
 ...eInstaller.java => OtherResourceInstaller.java} | 201 ++++++---------------
 2 files changed, 62 insertions(+), 149 deletions(-)

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 6c20a23e..b7e48f95 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/TorService.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/TorService.java
@@ -41,12 +41,13 @@ import android.widget.RemoteViews;
 import com.jrummyapps.android.shell.CommandResult;
 import com.jrummyapps.android.shell.Shell;
 
+import org.torproject.android.binary.TorResourceInstaller;
 import org.torproject.android.control.ConfigEntry;
 import org.torproject.android.control.TorControlConnection;
+import org.torproject.android.service.util.OtherResourceInstaller;
 import org.torproject.android.service.vpn.TorifiedApp;
 import org.torproject.android.service.util.DummyActivity;
 import org.torproject.android.service.util.Prefs;
-import org.torproject.android.service.util.TorResourceInstaller;
 import org.torproject.android.service.util.TorServiceUtils;
 import org.torproject.android.service.util.Utils;
 import org.torproject.android.service.vpn.OrbotVpnManager;
@@ -626,14 +627,17 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
             boolean success = installer.installResources();
             
             if (success)
-                prefs.edit().putString(PREF_BINARY_TOR_VERSION_INSTALLED,BINARY_TOR_VERSION).commit();    
+                prefs.edit().putString(PREF_BINARY_TOR_VERSION_INSTALLED,BINARY_TOR_VERSION).commit();
+
+            OtherResourceInstaller oInstaller = new OtherResourceInstaller(this, appBinHome);
+            oInstaller.installResources();
         }
 
         updateTorConfigFile ();
         isTorUpgradeAndConfigComplete = true;
     }
 
-    private boolean updateTorConfigFile () throws FileNotFoundException, IOException, TimeoutException
+    private boolean updateTorConfigFile () throws IOException, TimeoutException
     {
         SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
 
diff --git a/orbotservice/src/main/java/org/torproject/android/service/util/TorResourceInstaller.java b/orbotservice/src/main/java/org/torproject/android/service/util/OtherResourceInstaller.java
similarity index 59%
rename from orbotservice/src/main/java/org/torproject/android/service/util/TorResourceInstaller.java
rename to orbotservice/src/main/java/org/torproject/android/service/util/OtherResourceInstaller.java
index 8e2a6e02..6c1506b3 100644
--- a/orbotservice/src/main/java/org/torproject/android/service/util/TorResourceInstaller.java
+++ b/orbotservice/src/main/java/org/torproject/android/service/util/OtherResourceInstaller.java
@@ -1,6 +1,3 @@
-/* Copyright (c) 2009, Nathan Freitas, Orbot / The Guardian Project - http://openideals.com/guardian */
-/* See LICENSE for licensing information */
-
 package org.torproject.android.service.util;
 
 import java.io.DataInputStream;
@@ -26,19 +23,19 @@ import org.torproject.android.service.OrbotConstants;
 import org.torproject.android.service.R;
 import org.torproject.android.service.TorServiceConstants;
 
-public class TorResourceInstaller implements TorServiceConstants {
+public class OtherResourceInstaller implements TorServiceConstants {
+
 
-    
     File installFolder;
     Context context;
-    
-    public TorResourceInstaller (Context context, File installFolder)
+
+    public OtherResourceInstaller (Context context, File installFolder)
     {
         this.installFolder = installFolder;
-        
+
         this.context = context;
     }
-    
+
     public void deleteDirectory(File file) {
         if( file.exists() ) {
             if (file.isDirectory()) {
@@ -52,153 +49,65 @@ public class TorResourceInstaller implements TorServiceConstants {
                     }
                 }
             }
-                
+
             file.delete();
         }
     }
-    
+
     private final static String COMMAND_RM_FORCE = "rm -f ";
     private final static String MP3_EXT = ".mp3";
-    //        
+    //
     /*
      * Extract the Tor resources from the APK file using ZIP
      */
     public boolean installResources () throws IOException, FileNotFoundException, TimeoutException
     {
-        
+
         InputStream is;
         File outFile;
 
         String cpuPath = "armeabi";
-            
+
         if (Build.CPU_ABI.contains("x86"))
-        	cpuPath = "x86";
+            cpuPath = "x86";
 
         deleteDirectory(installFolder);
-        
-        installFolder.mkdirs();
 
-        is = context.getResources().openRawResource(R.raw.torrc);
-        outFile = new File(installFolder, TORRC_ASSET_KEY);
-        streamToFile(is,outFile, false, false);
-        
-        is = context.getResources().openRawResource(R.raw.torpolipo);
-        outFile = new File(installFolder, POLIPOCONFIG_ASSET_KEY);
-        streamToFile(is,outFile, false, false);
+        installFolder.mkdirs();
 
         is = context.getAssets().open(cpuPath + '/' + OBFSCLIENT_ASSET_KEY + MP3_EXT);
         outFile = new File(installFolder, OBFSCLIENT_ASSET_KEY);
         streamToFile(is,outFile, false, true);
         setExecutable(outFile);
 
-        is = context.getAssets().open(cpuPath + '/' + TOR_ASSET_KEY + MP3_EXT);
-        outFile = new File(installFolder, TOR_ASSET_KEY);
-        streamToFile(is,outFile, false, true);
-        setExecutable(outFile);
-    
-        is = context.getAssets().open(cpuPath + '/' + POLIPO_ASSET_KEY + MP3_EXT);
-        outFile = new File(installFolder, POLIPO_ASSET_KEY);
-        streamToFile(is,outFile, false, true);
-        setExecutable(outFile);
-    
         is = context.getAssets().open(cpuPath + '/' + PDNSD_ASSET_KEY + MP3_EXT);
         outFile = new File(installFolder, PDNSD_ASSET_KEY);
         streamToFile(is,outFile, false, true);
         setExecutable(outFile);
-        
-        installGeoIP();
-    
+
+
         return true;
     }
-    
+
     public boolean updateTorConfigCustom (File fileTorRcCustom, String extraLines) throws IOException, FileNotFoundException, TimeoutException
     {
-    	if (fileTorRcCustom.exists())
-    	{
-    		fileTorRcCustom.delete();
-    		Log.d("torResources","deleting existing torrc.custom");
-    	}
-    	else
-    		fileTorRcCustom.createNewFile();
-    	
-    	FileOutputStream fos = new FileOutputStream(fileTorRcCustom, false);
-    	PrintStream ps = new PrintStream(fos);
-    	ps.print(extraLines);
-    	ps.close();
-    	
-        return true;
-    }
-    
-    public boolean updatePolipoConfig (File filePolipo, String extraLines) throws IOException, FileNotFoundException, TimeoutException
-    {
-        
-        InputStream is;
-        
-
-        is = context.getResources().openRawResource(R.raw.torpolipo);        
-        streamToFile(is,filePolipo, false, false);
-
-        if (extraLines != null && extraLines.length() > 0)
+        if (fileTorRcCustom.exists())
         {
-            StringBufferInputStream sbis = new StringBufferInputStream('\n' + extraLines + '\n');
-            streamToFile(sbis,filePolipo,true,false);
+            fileTorRcCustom.delete();
+            Log.d("torResources","deleting existing torrc.custom");
         }
-        
+        else
+            fileTorRcCustom.createNewFile();
 
-        return true;
-    }
-    
-    public boolean installPolipoConf () throws IOException, FileNotFoundException, TimeoutException
-    {
-        
-        InputStream is;
-        File outFile;
-        
+        FileOutputStream fos = new FileOutputStream(fileTorRcCustom, false);
+        PrintStream ps = new PrintStream(fos);
+        ps.print(extraLines);
+        ps.close();
 
-        is = context.getResources().openRawResource(R.raw.torpolipo);
-        outFile = new File(installFolder, POLIPOCONFIG_ASSET_KEY);
-        streamToFile(is,outFile, false, false);
-        
-        return true;
-    }
-    
-    /*
-     * Extract the Tor binary from the APK file using ZIP
-     */
-    
-    private boolean installGeoIP () throws IOException, FileNotFoundException
-    {
-        
-        InputStream is;
-        File outFile;
-        
-        outFile = new File(installFolder, GEOIP_ASSET_KEY);
-        is = context.getResources().openRawResource(R.raw.geoip);
-        streamToFile(is, outFile, false, true);
-        
-        is = context.getResources().openRawResource(R.raw.geoip6);
-        outFile = new File(installFolder, GEOIP6_ASSET_KEY);
-        streamToFile(is, outFile, false, true);
-    
         return true;
     }
-    
-    /*
-    private static void copyAssetFile(Context ctx, String asset, File file) throws IOException, InterruptedException
-    {
-        
-        DataOutputStream out = new DataOutputStream(new FileOutputStream(file));
-        InputStream is = new GZIPInputStream(ctx.getAssets().open(asset));
-        
-        byte buf[] = new byte[8172];
-        int len;
-        while ((len = is.read(buf)) > 0) {
-            out.write(buf, 0, len);
-        }
-        out.close();
-        is.close();
-    }*/
-    
+
+
     /*
      * Write the inputstream contents to the file
      */
@@ -211,15 +120,15 @@ public class TorResourceInstaller implements TorServiceConstants {
 
         OutputStream stmOut = new FileOutputStream(outFile.getAbsolutePath(), append);
         ZipInputStream zis = null;
-        
+
         if (zip)
         {
-            zis = new ZipInputStream(stm);            
+            zis = new ZipInputStream(stm);
             ZipEntry ze = zis.getNextEntry();
             stm = zis;
-            
+
         }
-        
+
         while ((bytecount = stm.read(buffer)) > 0)
         {
 
@@ -229,55 +138,55 @@ public class TorResourceInstaller implements TorServiceConstants {
 
         stmOut.close();
         stm.close();
-        
+
         if (zis != null)
             zis.close();
-        
-        
+
+
         return true;
 
     }
-    
+
     //copy the file from inputstream to File output - alternative impl
     public static boolean copyFile (InputStream is, File outputFile)
     {
-        
+
         try {
-        	if (outputFile.exists())
-        		outputFile.delete();
-        	
+            if (outputFile.exists())
+                outputFile.delete();
+
             boolean newFile = outputFile.createNewFile();
             DataOutputStream out = new DataOutputStream(new FileOutputStream(outputFile));
             DataInputStream in = new DataInputStream(is);
-            
+
             int b = -1;
             byte[] data = new byte[1024];
-            
+
             while ((b = in.read(data)) != -1) {
                 out.write(data);
             }
-            
+
             if (b == -1); //rejoice
-            
+
             //
             out.flush();
             out.close();
             in.close();
             // chmod?
-            
+
             return newFile;
-            
-            
+
+
         } catch (IOException ex) {
             Log.e(OrbotConstants.TAG, "error copying binary", ex);
             return false;
         }
 
     }
-    
-    
 
-   
+
+
+
     /**
      * Copies a raw resource file, given its ID to the given location
      * @param ctx context
@@ -293,14 +202,14 @@ public class TorResourceInstaller implements TorServiceConstants {
         // Write the iptables binary
         final FileOutputStream out = new FileOutputStream(file);
         InputStream is = ctx.getResources().openRawResource(resid);
-        
+
         if (isZipd)
         {
-            ZipInputStream zis = new ZipInputStream(is);            
+            ZipInputStream zis = new ZipInputStream(is);
             ZipEntry ze = zis.getNextEntry();
             is = zis;
         }
-        
+
         byte buf[] = new byte[1024];
         int len;
         while ((len = is.read(buf)) > 0) {
@@ -320,14 +229,14 @@ public class TorResourceInstaller implements TorServiceConstants {
     /*
     public static boolean assertIpTablesBinaries(Context ctx, boolean showErrors) throws Exception {
         boolean changed = false;
-        
+
         // Check iptables_g1
         File file = new File(ctx.getDir("bin",0), "iptables");
         copyRawFile(ctx, R.raw.iptables, file, CHMOD_EXEC, false);
-                
+
         return true;
     }*/
-    
+
 
     private void setExecutable(File fileBin) {
         fileBin.setReadable(true);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits