commit 3ce57ded27baa63dfff074e9a10a62365dc3bc25 Author: Matthew Finkel sysrqb@torproject.org Date: Fri Feb 7 02:18:21 2020 +0000
Bug 30767: Support custom PT bridges on Android --- ...ustom-obfs4-bridge-does-not-work-on-Tor-B.patch | 146 +++++++++++++++++++++ projects/tor-onion-proxy-library/build | 1 + projects/tor-onion-proxy-library/config | 1 + 3 files changed, 148 insertions(+)
diff --git a/projects/tor-onion-proxy-library/0001-Bug-30767-Custom-obfs4-bridge-does-not-work-on-Tor-B.patch b/projects/tor-onion-proxy-library/0001-Bug-30767-Custom-obfs4-bridge-does-not-work-on-Tor-B.patch new file mode 100644 index 0000000..2d1bc51 --- /dev/null +++ b/projects/tor-onion-proxy-library/0001-Bug-30767-Custom-obfs4-bridge-does-not-work-on-Tor-B.patch @@ -0,0 +1,146 @@ +From 0a482a749fd770827d3d6c71debb112a07e7fae3 Mon Sep 17 00:00:00 2001 +From: sisbell shane.isbell@gmail.com +Date: Thu, 14 Nov 2019 13:43:09 -0800 +Subject: [PATCH] Bug 30767: Custom obfs4 bridge does not work on Tor Browser + for Android + +TOPL fixes #134 +--- + .../thali/toronionproxy/TorConfigBuilder.java | 63 ++++++++----------- + 1 file changed, 26 insertions(+), 37 deletions(-) + +diff --git a/universal/src/main/java/com/msopentech/thali/toronionproxy/TorConfigBuilder.java b/universal/src/main/java/com/msopentech/thali/toronionproxy/TorConfigBuilder.java +index e324d9f..da9a6a2 100644 +--- a/universal/src/main/java/com/msopentech/thali/toronionproxy/TorConfigBuilder.java ++++ b/universal/src/main/java/com/msopentech/thali/toronionproxy/TorConfigBuilder.java +@@ -99,25 +99,32 @@ public final class TorConfigBuilder { + return this; + } + ++ @SettingsConfig ++ public TorConfigBuilder bridgesFromSettings() { ++ try { ++ addBridgesFromResources(); ++ } catch (IOException e) { ++ e.printStackTrace(); ++ } ++ return this; ++ } ++ + public TorConfigBuilder configurePluggableTransportsFromSettings(File pluggableTransportClient) throws IOException { +- List<String> supportedBridges = settings.getListOfSupportedBridges(); +- if (pluggableTransportClient == null || !settings.hasBridges() || supportedBridges.size() < 1) { ++ if (pluggableTransportClient == null) { + return this; + } + +- if (!pluggableTransportClient.exists() || !pluggableTransportClient.canExecute()) { ++ if (!pluggableTransportClient.exists()) { + throw new IOException("Bridge binary does not exist: " + pluggableTransportClient + .getCanonicalPath()); + } + +- if (supportedBridges.contains("obfs3") || supportedBridges.contains("obfs4")) { +- transportPluginObfs(pluggableTransportClient.getCanonicalPath()); +- } +- if (supportedBridges.contains("meek")) { +- transportPluginMeek(pluggableTransportClient.getCanonicalPath()); ++ if (!pluggableTransportClient.canExecute()) { ++ throw new IOException("Bridge binary is not executable: " + pluggableTransportClient ++ .getCanonicalPath()); + } +- String type = supportedBridges.contains("meek") ? "meek_lite" : "obfs4"; +- addBridgesFromResources(type, 2); ++ ++ transportPlugin(pluggableTransportClient.getCanonicalPath()); + return this; + } + +@@ -471,14 +478,8 @@ public final class TorConfigBuilder { + return transPort(settings.transPort()); + } + +- public TorConfigBuilder transportPluginMeek(String clientPath) { +- buffer.append("ClientTransportPlugin meek_lite exec ").append(clientPath).append('\n'); +- return this; +- } +- +- public TorConfigBuilder transportPluginObfs(String clientPath) { +- buffer.append("ClientTransportPlugin obfs3 exec ").append(clientPath).append('\n'); +- buffer.append("ClientTransportPlugin obfs4 exec ").append(clientPath).append('\n'); ++ public TorConfigBuilder transportPlugin(String clientPath) { ++ buffer.append("ClientTransportPlugin meek_lite,obfs3,obfs4 exec ").append(clientPath).append('\n'); + return this; + } + +@@ -489,7 +490,7 @@ public final class TorConfigBuilder { + + @SettingsConfig + public TorConfigBuilder useBridgesFromSettings() { +- return !settings.hasBridges() ? dontUseBridges() : this; ++ return settings.hasBridges() ? useBridges() : this; + } + + public TorConfigBuilder virtualAddressNetwork(String address) { +@@ -518,12 +519,12 @@ public final class TorConfigBuilder { + * </code> + * + */ +- TorConfigBuilder addBridgesFromResources(String type, int maxBridges) throws IOException { ++ TorConfigBuilder addBridgesFromResources() throws IOException { + if(settings.hasBridges()) { + InputStream bridgesStream = context.getInstaller().openBridgesStream(); + int formatType = bridgesStream.read(); +- if(formatType == 0) { +- addBridges(bridgesStream, type, maxBridges); ++ if (formatType == 0) { ++ addBridges(bridgesStream); + } else { + addCustomBridges(bridgesStream); + } +@@ -534,23 +535,14 @@ public final class TorConfigBuilder { + /** + * Add bridges from bridges.txt file. + */ +- private void addBridges(InputStream input, String bridgeType, int maxBridges) { +- if (input == null || isNullOrEmpty(bridgeType) || maxBridges < 1) { ++ private void addBridges(InputStream input) { ++ if (input == null) { + return; + } +- boolean hasAddedBridge = false; + List<Bridge> bridges = readBridgesFromStream(input); +- Collections.shuffle(bridges, new Random(System.nanoTime())); +- int bridgeCount = 0; + for (Bridge b : bridges) { +- if (b.type.equals(bridgeType)) { +- bridge(b.type, b.config); +- hasAddedBridge = true; +- if (++bridgeCount > maxBridges) +- break; +- } ++ bridge(b.type, b.config); + } +- if(hasAddedBridge) useBridges(); + } + + /** +@@ -560,15 +552,12 @@ public final class TorConfigBuilder { + if (input == null) { + return; + } +- boolean hasAddedBridge = false; + List<Bridge> bridges = readCustomBridgesFromStream(input); + for (Bridge b : bridges) { + if (b.type.equals("custom")) { + bridgeCustom(b.config); +- hasAddedBridge = true; + } + } +- if(hasAddedBridge) useBridges(); + } + + private static List<Bridge> readBridgesFromStream(InputStream input) { +-- +2.20.1 + diff --git a/projects/tor-onion-proxy-library/build b/projects/tor-onion-proxy-library/build index 0f2d976..9a8b31e 100644 --- a/projects/tor-onion-proxy-library/build +++ b/projects/tor-onion-proxy-library/build @@ -21,6 +21,7 @@ cd /var/tmp/build/[% project %]-[% c('version') %] # build will pull down the correct android tool versions patch -p1 < $rootdir/gradle.patch patch -p1 < $rootdir/canceldormant.patch +patch -p1 < $rootdir/0001-Bug-30767-Custom-obfs4-bridge-does-not-work-on-Tor-B.patch
# Extract obfs4proxy from TorBrowser/Tor/PluggableTransports/obfs4proxy tar --strip-components=4 -xf $rootdir/[% c('input_files_by_name/obfs4') %] diff --git a/projects/tor-onion-proxy-library/config b/projects/tor-onion-proxy-library/config index ff3432c..d76949d 100644 --- a/projects/tor-onion-proxy-library/config +++ b/projects/tor-onion-proxy-library/config @@ -32,3 +32,4 @@ input_files: exec: '[% INCLUDE "fetch-gradle-dependencies" %]' - filename: gradle.patch - filename: canceldormant.patch + - filename: 0001-Bug-30767-Custom-obfs4-bridge-does-not-work-on-Tor-B.patch
tbb-commits@lists.torproject.org