isolate hidden services configuration dirs

This commit is contained in:
arrase 2016-11-23 00:12:06 +01:00
parent 53e53d6fff
commit 0818b0c963
4 changed files with 21 additions and 12 deletions

View File

@ -9,10 +9,13 @@ import org.torproject.android.storage.ExternalStorage;
import java.io.File; import java.io.File;
public class BackupUtils { public class BackupUtils {
private static File appCacheHome; private static File mHSBasePath;
public BackupUtils(Context context) { public BackupUtils(Context context) {
appCacheHome = context.getDir(TorServiceConstants.DIRECTORY_TOR_DATA, Application.MODE_PRIVATE); mHSBasePath = context.getDir(
TorServiceConstants.DIRECTORY_TOR_DATA + "/" + TorServiceConstants.HIDDEN_SERVICES_DIR,
Application.MODE_PRIVATE
);
} }
public String createOnionBackup(Integer port) { public String createOnionBackup(Integer port) {
@ -25,8 +28,8 @@ public class BackupUtils {
String zip_path = storage_path + "/hs" + port + ".zip"; String zip_path = storage_path + "/hs" + port + ".zip";
String files[] = { String files[] = {
appCacheHome + "/hs" + port + "/hostname", mHSBasePath + "/hs" + port + "/hostname",
appCacheHome + "/hs" + port + "/private_key" mHSBasePath + "/hs" + port + "/private_key"
}; };
ZipIt zip = new ZipIt(files, zip_path); ZipIt zip = new ZipIt(files, zip_path);
@ -40,6 +43,6 @@ public class BackupUtils {
public void restoreOnionBackup(Integer port, String path) { public void restoreOnionBackup(Integer port, String path) {
ZipIt zip = new ZipIt(null, path); ZipIt zip = new ZipIt(null, path);
zip.unzip(appCacheHome + "/hs" + port); zip.unzip(mHSBasePath + "/hs" + port);
} }
} }

View File

@ -121,7 +121,6 @@ public class HSContentProvider extends ContentProvider {
} }
public static final class HiddenService implements BaseColumns { public static final class HiddenService implements BaseColumns {
//Nombres de columnas
public static final String NAME = "name"; public static final String NAME = "name";
public static final String PORT = "port"; public static final String PORT = "port";
public static final String ONION_PORT = "onion_port"; public static final String ONION_PORT = "onion_port";

View File

@ -23,14 +23,12 @@ import android.content.ContextWrapper;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.database.Cursor; import android.database.Cursor;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.os.RemoteException; import android.os.RemoteException;
import android.provider.BaseColumns; import android.provider.BaseColumns;
@ -128,18 +126,20 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
public static File fileObfsclient; public static File fileObfsclient;
public static File fileXtables; public static File fileXtables;
public static File fileTorRc; public static File fileTorRc;
private File mHSBasePath;
private Shell mShell; private Shell mShell;
private Shell mShellPolipo; private Shell mShellPolipo;
private static final Uri CONTENT_URI = Uri.parse("content://org.torproject.android.ui.hs.providers/hs"); private static final Uri CONTENT_URI = Uri.parse("content://org.torproject.android.ui.hs.providers/hs");
public static final class HiddenService implements BaseColumns { public static final class HiddenService implements BaseColumns {
//Nombres de columnas
public static final String NAME = "name"; public static final String NAME = "name";
public static final String PORT = "port"; public static final String PORT = "port";
public static final String ONION_PORT = "onion_port"; public static final String ONION_PORT = "onion_port";
public static final String DOMAIN = "domain"; public static final String DOMAIN = "domain";
public static final String CREATED_BY_USER = "created_by_user";
private HiddenService() { private HiddenService() {
} }
@ -147,7 +147,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
private String[] mProjection = new String[]{ private String[] mProjection = new String[]{
HiddenService._ID, HiddenService._ID,
HiddenService.NAME,
HiddenService.DOMAIN, HiddenService.DOMAIN,
HiddenService.PORT, HiddenService.PORT,
HiddenService.ONION_PORT}; HiddenService.ONION_PORT};
@ -532,6 +531,12 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
fileXtables = new File(appBinHome, TorServiceConstants.IPTABLES_ASSET_KEY); fileXtables = new File(appBinHome, TorServiceConstants.IPTABLES_ASSET_KEY);
fileTorRc = new File(appBinHome, TorServiceConstants.TORRC_ASSET_KEY); fileTorRc = new File(appBinHome, TorServiceConstants.TORRC_ASSET_KEY);
mHSBasePath = new File(appCacheHome , TorServiceConstants.HIDDEN_SERVICES_DIR);
if (!mHSBasePath.isDirectory()) {
mHSBasePath.mkdirs();
}
mEventHandler = new TorEventHandler(this); mEventHandler = new TorEventHandler(this);
if (mNotificationManager == null) if (mNotificationManager == null)
@ -773,7 +778,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
// Update only new domains // Update only new domains
if(HSDomain == null || HSDomain.length() < 1) { if(HSDomain == null || HSDomain.length() < 1) {
String hsDirPath = new File(appCacheHome,"hs" + HSLocalPort).getCanonicalPath(); String hsDirPath = new File(mHSBasePath.getAbsolutePath(),"hs" + HSLocalPort).getCanonicalPath();
File file = new File(hsDirPath, "hostname"); File file = new File(hsDirPath, "hostname");
if (file.exists()) if (file.exists())
@ -1782,7 +1787,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
while (hidden_services.moveToNext()) { while (hidden_services.moveToNext()) {
Integer HSLocalPort = hidden_services.getInt(hidden_services.getColumnIndex(HiddenService.PORT)); Integer HSLocalPort = hidden_services.getInt(hidden_services.getColumnIndex(HiddenService.PORT));
Integer HSOnionPort = hidden_services.getInt(hidden_services.getColumnIndex(HiddenService.ONION_PORT)); Integer HSOnionPort = hidden_services.getInt(hidden_services.getColumnIndex(HiddenService.ONION_PORT));
String hsDirPath = new File(appCacheHome,"hs" + HSLocalPort).getCanonicalPath(); String hsDirPath = new File(mHSBasePath.getAbsolutePath(),"hs" + HSLocalPort).getCanonicalPath();
debug("Adding hidden service on port: " + HSLocalPort); debug("Adding hidden service on port: " + HSLocalPort);

View File

@ -159,4 +159,6 @@ public interface TorServiceConstants {
"meek_lite 0.0.2.0:3 url=https://az668014.vo.msecnd.net/ front=ajax.aspnetcdn.com" "meek_lite 0.0.2.0:3 url=https://az668014.vo.msecnd.net/ front=ajax.aspnetcdn.com"
}; };
public static final String HIDDEN_SERVICES_DIR = "hidden_services";
} }