|
39 | 39 | import net.freehaven.tor.control.TorControlCommands; |
40 | 40 | import net.freehaven.tor.control.TorControlConnection; |
41 | 41 |
|
| 42 | +import org.torproject.android.service.util.Bridge; |
42 | 43 | import org.torproject.android.service.util.CustomTorResourceInstaller; |
43 | 44 | import org.torproject.android.service.util.PowerConnectionReceiver; |
44 | 45 | import org.torproject.android.service.util.Prefs; |
@@ -137,16 +138,6 @@ public void stopped(String s, Exception e) { |
137 | 138 |
|
138 | 139 | return mIptProxy; |
139 | 140 | } |
140 | | - /** |
141 | | - * @param bridgeList bridges that were manually entered into Orbot settings |
142 | | - * @return Array with each bridge as an element, no whitespace entries see issue #289... |
143 | | - */ |
144 | | - private static String[] parseBridgesFromSettings(String bridgeList) { |
145 | | - // this regex replaces lines that only contain whitespace with an empty String |
146 | | - bridgeList = bridgeList.trim().replaceAll("(?m)^[ \t]*\r?\n", ""); |
147 | | - return bridgeList.split("\\n"); |
148 | | - } |
149 | | - |
150 | 141 | public void debug(String msg) { |
151 | 142 | Log.d(TAG, msg); |
152 | 143 |
|
@@ -299,12 +290,12 @@ private void stopTorAsync(boolean showNotification) { |
299 | 290 | // todo this needs to handle a lot of different cases that haven't been defined yet |
300 | 291 | // todo particularly this is true for the smart connection case... |
301 | 292 | if (connectionPathway.startsWith(Prefs.PATHWAY_SNOWFLAKE) || Prefs.getPrefSmartTrySnowflake()) { |
302 | | - // mIptProxy.stop |
303 | 293 | mIptProxy.stop(IPtProxy.Snowflake); |
304 | | - } else if (connectionPathway.equals(Prefs.PATHWAY_CUSTOM) || Prefs.getPrefSmartTryObfs4() != null) { |
305 | | - // IPtProxy.stopLyrebird(); |
| 294 | + } |
| 295 | + else if (connectionPathway.equals(Prefs.PATHWAY_CUSTOM) || Prefs.getPrefSmartTryObfs4() != null) { |
| 296 | + mIptProxy.stop(IPtProxy.MeekLite); |
306 | 297 | mIptProxy.stop(IPtProxy.Obfs4); |
307 | | - |
| 298 | + mIptProxy.stop(IPtProxy.Webtunnel); |
308 | 299 | } |
309 | 300 |
|
310 | 301 | stopTor(); |
@@ -1204,7 +1195,7 @@ private StringBuffer processSettingsImpl(StringBuffer extraLines) throws IOExcep |
1204 | 1195 | if (pathway.startsWith(Prefs.PATHWAY_SNOWFLAKE) || Prefs.getPrefSmartTrySnowflake()) { |
1205 | 1196 | extraLines = processSettingsImplSnowflake(extraLines); |
1206 | 1197 | } else if (pathway.equals(Prefs.PATHWAY_CUSTOM) || Prefs.getPrefSmartTryObfs4() != null) { |
1207 | | - extraLines = processSettingsImplObfs4(extraLines); |
| 1198 | + extraLines = processSettingsLyrebird(extraLines); |
1208 | 1199 | } |
1209 | 1200 | } |
1210 | 1201 | var fileGeoIP = new File(appBinHome, GEOIP_ASSET_KEY); |
@@ -1274,20 +1265,32 @@ private StringBuffer processSettingsImplSnowflake(StringBuffer extraLines) { |
1274 | 1265 | return extraLines; |
1275 | 1266 | } |
1276 | 1267 |
|
1277 | | - private StringBuffer processSettingsImplObfs4(StringBuffer extraLines) { |
1278 | | - Log.d(TAG, "in obfs4 torrc config"); |
1279 | | - extraLines.append("ClientTransportPlugin obfs4 socks5 127.0.0.1:" + mIptProxy.port(IPtProxy.Obfs4)).append('\n'); |
| 1268 | + private StringBuffer processSettingsLyrebird(StringBuffer extraLines) { |
| 1269 | + Log.d(TAG, "in Lyrebird torrc config"); |
| 1270 | + |
| 1271 | + var customBridges = getCustomBridges(); |
1280 | 1272 |
|
1281 | | - var bridgeList = ""; |
1282 | | - if (Prefs.getConnectionPathway().equals(Prefs.PATHWAY_CUSTOM)) { |
1283 | | - bridgeList = Prefs.getBridgesList(); |
1284 | | - } else bridgeList = Prefs.getPrefSmartTryObfs4(); |
1285 | | - var customBridges = parseBridgesFromSettings(bridgeList); |
1286 | | - for (var b : customBridges) |
| 1273 | + for (String transport : Bridge.getTransports(customBridges)) { |
| 1274 | + extraLines |
| 1275 | + .append(String.format(Locale.US, "ClientTransportPlugin %s socks5 127.0.0.1:%d", |
| 1276 | + transport, mIptProxy.port(transport))) |
| 1277 | + .append('\n'); |
| 1278 | + } |
| 1279 | + |
| 1280 | + for (var b : customBridges) { |
1287 | 1281 | extraLines.append("Bridge ").append(b).append("\n"); |
| 1282 | + } |
| 1283 | + |
1288 | 1284 | return extraLines; |
1289 | 1285 | } |
1290 | 1286 |
|
| 1287 | + private List<Bridge> getCustomBridges() { |
| 1288 | + return Bridge.parseBridges( |
| 1289 | + Prefs.getConnectionPathway().equals(Prefs.PATHWAY_CUSTOM) |
| 1290 | + ? Prefs.getBridgesList() |
| 1291 | + : Prefs.getPrefSmartTryObfs4()); |
| 1292 | + } |
| 1293 | + |
1291 | 1294 | private StringBuffer processSettingsImplDirectPathway(StringBuffer extraLines) { |
1292 | 1295 | var prefs = Prefs.getSharedPrefs(getApplicationContext()); |
1293 | 1296 | extraLines.append("UseBridges 0").append('\n'); |
@@ -1528,11 +1531,12 @@ public void run() { |
1528 | 1531 | } else if (connectionPathway.equals(Prefs.PATHWAY_SNOWFLAKE_AMP)) { |
1529 | 1532 | startSnowflakeClientAmpRendezvous(); |
1530 | 1533 | } else if (connectionPathway.equals(Prefs.PATHWAY_CUSTOM) || Prefs.getPrefSmartTryObfs4() != null) { |
1531 | | - //IPtProxy.startLyrebird("DEBUG", false, false, null); |
1532 | | - try { |
1533 | | - mIptProxy.start(IPtProxy.Obfs4,""); |
1534 | | - } catch (Exception e) { |
1535 | | - throw new RuntimeException(e); |
| 1534 | + for (var transport : Bridge.getTransports(getCustomBridges())) { |
| 1535 | + try { |
| 1536 | + mIptProxy.start(transport, ""); |
| 1537 | + } catch (Exception e) { |
| 1538 | + throw new RuntimeException(e); |
| 1539 | + } |
1536 | 1540 | } |
1537 | 1541 | } |
1538 | 1542 | startTor(); |
|
0 commit comments