Commit 784919d8 authored by sisbell's avatar sisbell
Browse files

Fixes #18: Custom Tor Install Process

parent da7aaaf1
......@@ -49,7 +49,6 @@ dependencies {
sdkVer28Implementation 'com.android.support:appcompat-v7:28.0.0'
sdkVer26Implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'net.freehaven.tor.control:jtorctl:0.2'
compileOnly 'org.torproject:tor-android-binary:0.3.5.8-rc-v2'
implementation 'org.slf4j:slf4j-api:1.7.25'
implementation 'org.slf4j:slf4j-android:1.7.25'
......
obfs4 78.215.187.186:45675 AE907EE5FAA5D0D27E0C83EFA6ADF8E79FCC0FF1 cert=/TRjMo+RinKaixARMjMtZZBhystaBe+aDaapPrbiITFtWx3M/AJcvpjHjO54tJqLd1+IWQ iat-mode=0
obfs4 107.160.7.24:443 7A0904F6D182B81BEFE0DEDAFEC974494672627B cert=a5/IlZMnDvb8d92LTHMfsBIgL7QlDLPiXiLwe85uedC80mGD0QerygzmsWnMEdwG9ER9Eg iat-mode=0
obfs4 79.136.160.201:46501 66AC975BF7CB429D057AE07FC0312C57D61BAEC1 cert=dCtn9Ya8z+R8YQikdWgC3XTAt58z5Apnm95QHrJwnhFSdnphPPEz+NMm6OawWc2srKLjJg iat-mode=0
meek_lite 0.0.2.0:2 97700DFE9F483596DDA6264C4D7DF7641E1E39CE url=https://meek.azureedge.net/ front=ajax.aspnetcdn.com
This diff is collapsed.
This diff is collapsed.
RunAsDaemon 1
AvoidDiskWrites 0
ControlPort auto
SOCKSPort 0
DNSPort 0
TransPort 0
CookieAuthentication 1
DisableNetwork 1
package org.torproject.android.service;
import android.content.Context;
import android.util.Log;
import com.msopentech.thali.toronionproxy.TorInstaller;
import java.io.*;
import java.util.concurrent.TimeoutException;
public class CustomTorInstaller extends TorInstaller {
private final Context context;
private final File torrcFile;
private final File configDir;
public CustomTorInstaller(Context context, File configDir, File torrcFile) {
this.context = context;
this.torrcFile = torrcFile;
this.configDir = configDir;
}
@Override
public void setup() throws IOException {
copy(context.getAssets().open("common/geoip"), new File(configDir, "geoip"));
copy(context.getAssets().open("common/geoip6"), new File(configDir, "geoip6"));
copy(context.getAssets().open("common/torrc"), new File(configDir, "torrc"));
copy(context.getAssets().open("common/bridges.txt"), new File(configDir, "bridges.txt"));
}
@Override
public void updateTorConfigCustom(String content) throws IOException, TimeoutException {
updateTorConfigCustom(torrcFile, content);
}
@Override
public InputStream openBridgesStream() throws IOException {
return context.getResources().openRawResource(R.raw.bridges);
}
private static void copy(InputStream is, File target) throws IOException {
FileOutputStream os = new FileOutputStream(target);
byte[] buffer = new byte[8192];
int length = is.read(buffer);
while (length > 0) {
os.write(buffer, 0, length);
length = is.read(buffer);
}
os.close();
}
private static boolean updateTorConfigCustom(File fileTorRcCustom, String content) throws IOException {
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(content);
ps.close();
return true;
}
}
......@@ -10,11 +10,8 @@ import android.util.Log;
import com.msopentech.thali.toronionproxy.EventBroadcaster;
import com.msopentech.thali.toronionproxy.TorConfig;
import com.msopentech.thali.toronionproxy.TorConfigBuilder;
import org.torproject.android.binary.Utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.*;
final class DataService {
......@@ -90,7 +87,7 @@ final class DataService {
if (file.exists()) {
ContentValues fields = new ContentValues();
try {
String onionHostname = Utils.readString(new FileInputStream(file)).trim();
String onionHostname = readString(new FileInputStream(file)).trim();
if (authCookie == 1) {
String[] aux = onionHostname.split(" ");
onionHostname = aux[0];
......@@ -164,4 +161,19 @@ final class DataService {
}
return builder;
}
private static String readString(InputStream stream) {
StringBuilder out = new StringBuilder();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String line;
while ((line = reader.readLine()) != null) {
out.append(line).append("\n");
}
} catch (IOException e) {
e.printStackTrace();
}
return out.toString();
}
}
......@@ -16,18 +16,22 @@ import android.support.annotation.RequiresApi;
import android.text.TextUtils;
import android.util.Log;
import com.msopentech.thali.android.toronionproxy.AndroidOnionProxyManager;
import com.msopentech.thali.toronionproxy.TorConfig;
import com.msopentech.thali.toronionproxy.TorConfigBuilder;
import com.msopentech.thali.toronionproxy.TorInstaller;
import org.torproject.android.service.util.NotificationBuilderCompat;
import org.torproject.android.service.util.Prefs;
import org.torproject.android.service.util.TorServiceUtils;
import org.torproject.android.service.vpn.TorVpnService;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public final class TorService extends Service implements TorServiceConstants, OrbotConstants {
public final static String TOR_VERSION = org.torproject.android.binary.TorServiceConstants.BINARY_TOR_VERSION;
public final static String TOR_VERSION = "0.3.5.8-rc-openssl1.0.2p";
private static final int NOTIFY_ID = 1;
private static final int ERROR_NOTIFY_ID = 3;
private final static String NOTIFICATION_CHANNEL_ID = "orbot_channel_1";
......@@ -213,9 +217,15 @@ public final class TorService extends Service implements TorServiceConstants, Or
AndroidTorSettings androidTorSettings = new AndroidTorSettings(this, mPrefs);
mEventBroadcaster = new AndroidEventBroadcaster(getApplicationContext(), androidTorSettings);
mEventHandler = new TorEventHandler(this, mEventBroadcaster);
File configDir = getDir("torservice", Context.MODE_PRIVATE);
File nativeDir = new File(getApplicationInfo().nativeLibraryDir);
TorConfig torConfig = createConfig(nativeDir, configDir);
TorInstaller torInstaller = new CustomTorInstaller(getApplicationContext(), configDir, torConfig.getTorrcFile());
onionProxyManager =
new AndroidOnionProxyManager(getApplicationContext(), "torfiles", "torfiles", androidTorSettings,
mEventBroadcaster, mEventHandler);
new AndroidOnionProxyManager(getApplicationContext(), torConfig,
torInstaller, androidTorSettings, mEventBroadcaster, mEventHandler);
mDataService = new DataService(getApplicationContext(), this, onionProxyManager.getContext().getConfig(),
mEventBroadcaster);
......@@ -291,6 +301,12 @@ public final class TorService extends Service implements TorServiceConstants, Or
.updating_settings_in_tor_service));
TorConfigBuilder builder = onionProxyManager.getContext()
.newConfigBuilder().updateTorConfig();
File nativeDir = new File(getApplicationInfo().nativeLibraryDir);
File pluggableTransport = new File(nativeDir, "libObfs4proxy.so");
if(!pluggableTransport.canExecute()) pluggableTransport.setExecutable(true);
builder.configurePluggableTransportsFromSettings(pluggableTransport);
mDataService.updateConfigBuilder(builder);
onionProxyManager.getTorInstaller().updateTorConfigCustom
(builder.asString());
......@@ -422,4 +438,13 @@ public final class TorService extends Service implements TorServiceConstants, Or
}
}
}
private static TorConfig createConfig(File nativeDir, File configDir) {
TorConfig.Builder builder = new TorConfig.Builder(nativeDir, configDir);
// builder.dataDir(configDir);
File exe = new File(nativeDir, "libTor.so");
exe.setExecutable(true);
builder.torExecutable(exe);
return builder.build();
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment