Skip to content
This repository was archived by the owner on Dec 18, 2022. It is now read-only.

Commit ae478da

Browse files
authored
Merge pull request thaliproject#141 from sisbell/bug-30767b
Bug 30767: Custom obfs4 bridge does not work on Tor Browser for Android
2 parents a720e25 + 0a482a7 commit ae478da

File tree

1 file changed

+26
-37
lines changed

1 file changed

+26
-37
lines changed

universal/src/main/java/com/msopentech/thali/toronionproxy/TorConfigBuilder.java

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -99,25 +99,32 @@ public TorConfigBuilder bridgeCustom(String config) {
9999
return this;
100100
}
101101

102+
@SettingsConfig
103+
public TorConfigBuilder bridgesFromSettings() {
104+
try {
105+
addBridgesFromResources();
106+
} catch (IOException e) {
107+
e.printStackTrace();
108+
}
109+
return this;
110+
}
111+
102112
public TorConfigBuilder configurePluggableTransportsFromSettings(File pluggableTransportClient) throws IOException {
103-
List<String> supportedBridges = settings.getListOfSupportedBridges();
104-
if (pluggableTransportClient == null || !settings.hasBridges() || supportedBridges.size() < 1) {
113+
if (pluggableTransportClient == null) {
105114
return this;
106115
}
107116

108-
if (!pluggableTransportClient.exists() || !pluggableTransportClient.canExecute()) {
117+
if (!pluggableTransportClient.exists()) {
109118
throw new IOException("Bridge binary does not exist: " + pluggableTransportClient
110119
.getCanonicalPath());
111120
}
112121

113-
if (supportedBridges.contains("obfs3") || supportedBridges.contains("obfs4")) {
114-
transportPluginObfs(pluggableTransportClient.getCanonicalPath());
115-
}
116-
if (supportedBridges.contains("meek")) {
117-
transportPluginMeek(pluggableTransportClient.getCanonicalPath());
122+
if (!pluggableTransportClient.canExecute()) {
123+
throw new IOException("Bridge binary is not executable: " + pluggableTransportClient
124+
.getCanonicalPath());
118125
}
119-
String type = supportedBridges.contains("meek") ? "meek_lite" : "obfs4";
120-
addBridgesFromResources(type, 2);
126+
127+
transportPlugin(pluggableTransportClient.getCanonicalPath());
121128
return this;
122129
}
123130

@@ -471,14 +478,8 @@ public TorConfigBuilder transPortFromSettings() {
471478
return transPort(settings.transPort());
472479
}
473480

474-
public TorConfigBuilder transportPluginMeek(String clientPath) {
475-
buffer.append("ClientTransportPlugin meek_lite exec ").append(clientPath).append('\n');
476-
return this;
477-
}
478-
479-
public TorConfigBuilder transportPluginObfs(String clientPath) {
480-
buffer.append("ClientTransportPlugin obfs3 exec ").append(clientPath).append('\n');
481-
buffer.append("ClientTransportPlugin obfs4 exec ").append(clientPath).append('\n');
481+
public TorConfigBuilder transportPlugin(String clientPath) {
482+
buffer.append("ClientTransportPlugin meek_lite,obfs3,obfs4 exec ").append(clientPath).append('\n');
482483
return this;
483484
}
484485

@@ -489,7 +490,7 @@ public TorConfigBuilder useBridges() {
489490

490491
@SettingsConfig
491492
public TorConfigBuilder useBridgesFromSettings() {
492-
return !settings.hasBridges() ? dontUseBridges() : this;
493+
return settings.hasBridges() ? useBridges() : this;
493494
}
494495

495496
public TorConfigBuilder virtualAddressNetwork(String address) {
@@ -518,12 +519,12 @@ public TorConfigBuilder virtualAddressNetworkFromSettings() {
518519
* </code>
519520
*
520521
*/
521-
TorConfigBuilder addBridgesFromResources(String type, int maxBridges) throws IOException {
522+
TorConfigBuilder addBridgesFromResources() throws IOException {
522523
if(settings.hasBridges()) {
523524
InputStream bridgesStream = context.getInstaller().openBridgesStream();
524525
int formatType = bridgesStream.read();
525-
if(formatType == 0) {
526-
addBridges(bridgesStream, type, maxBridges);
526+
if (formatType == 0) {
527+
addBridges(bridgesStream);
527528
} else {
528529
addCustomBridges(bridgesStream);
529530
}
@@ -534,23 +535,14 @@ TorConfigBuilder addBridgesFromResources(String type, int maxBridges) throws IOE
534535
/**
535536
* Add bridges from bridges.txt file.
536537
*/
537-
private void addBridges(InputStream input, String bridgeType, int maxBridges) {
538-
if (input == null || isNullOrEmpty(bridgeType) || maxBridges < 1) {
538+
private void addBridges(InputStream input) {
539+
if (input == null) {
539540
return;
540541
}
541-
boolean hasAddedBridge = false;
542542
List<Bridge> bridges = readBridgesFromStream(input);
543-
Collections.shuffle(bridges, new Random(System.nanoTime()));
544-
int bridgeCount = 0;
545543
for (Bridge b : bridges) {
546-
if (b.type.equals(bridgeType)) {
547-
bridge(b.type, b.config);
548-
hasAddedBridge = true;
549-
if (++bridgeCount > maxBridges)
550-
break;
551-
}
544+
bridge(b.type, b.config);
552545
}
553-
if(hasAddedBridge) useBridges();
554546
}
555547

556548
/**
@@ -560,15 +552,12 @@ private void addCustomBridges(InputStream input) {
560552
if (input == null) {
561553
return;
562554
}
563-
boolean hasAddedBridge = false;
564555
List<Bridge> bridges = readCustomBridgesFromStream(input);
565556
for (Bridge b : bridges) {
566557
if (b.type.equals("custom")) {
567558
bridgeCustom(b.config);
568-
hasAddedBridge = true;
569559
}
570560
}
571-
if(hasAddedBridge) useBridges();
572561
}
573562

574563
private static List<Bridge> readBridgesFromStream(InputStream input) {

0 commit comments

Comments
 (0)