From 2fd948b81d663e6a73f20b343a7d8ff028c97dc6 Mon Sep 17 00:00:00 2001 From: akwizgran Date: Tue, 7 Jun 2022 12:18:24 +0100 Subject: [PATCH] Use non-default obfs4 bridges in countries that use DPI. --- .../bramble/plugin/tor/CircumventionProvider.java | 8 ++++---- .../plugin/tor/CircumventionProviderImpl.java | 9 ++++----- .../plugin/tor/CircumventionProviderTest.java | 15 +++++++-------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/bramble-core/src/main/java/org/briarproject/bramble/plugin/tor/CircumventionProvider.java b/bramble-core/src/main/java/org/briarproject/bramble/plugin/tor/CircumventionProvider.java index 50936b931..ff5033bf1 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/plugin/tor/CircumventionProvider.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/plugin/tor/CircumventionProvider.java @@ -27,7 +27,7 @@ public interface CircumventionProvider { * Countries where bridge connections are likely to work. * Should be a subset of {@link #BLOCKED} and the union of * {@link #DEFAULT_BRIDGES}, {@link #NON_DEFAULT_BRIDGES} and - * {@link #MEEK_BRIDGES}. + * {@link #DPI_BRIDGES}. */ String[] BRIDGES = {"BY", "CN", "EG", "IR", "RU", "TM", "VE"}; @@ -44,10 +44,10 @@ public interface CircumventionProvider { String[] NON_DEFAULT_BRIDGES = {"BY", "RU", "TM"}; /** - * Countries where obfs4 and vanilla bridges won't work and meek is needed. - * Should be a subset of {@link #BRIDGES}. + * Countries where vanilla bridges are blocked via DPI but non-default + * obfs4 bridges and meek may work. Should be a subset of {@link #BRIDGES}. */ - String[] MEEK_BRIDGES = {"CN", "IR"}; + String[] DPI_BRIDGES = {"CN", "IR"}; /** * Returns true if vanilla Tor connections are blocked in the given country. diff --git a/bramble-core/src/main/java/org/briarproject/bramble/plugin/tor/CircumventionProviderImpl.java b/bramble-core/src/main/java/org/briarproject/bramble/plugin/tor/CircumventionProviderImpl.java index fae5044bc..461ce5c31 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/plugin/tor/CircumventionProviderImpl.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/plugin/tor/CircumventionProviderImpl.java @@ -14,7 +14,6 @@ import javax.annotation.concurrent.Immutable; import javax.inject.Inject; import static java.util.Arrays.asList; -import static java.util.Collections.singletonList; import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull; import static org.briarproject.bramble.plugin.tor.CircumventionProvider.BridgeType.DEFAULT_OBFS4; import static org.briarproject.bramble.plugin.tor.CircumventionProvider.BridgeType.MEEK; @@ -35,8 +34,8 @@ class CircumventionProviderImpl implements CircumventionProvider { new HashSet<>(asList(DEFAULT_BRIDGES)); private static final Set NON_DEFAULT_BRIDGE_COUNTRIES = new HashSet<>(asList(NON_DEFAULT_BRIDGES)); - private static final Set MEEK_COUNTRIES = - new HashSet<>(asList(MEEK_BRIDGES)); + private static final Set DPI_COUNTRIES = + new HashSet<>(asList(DPI_BRIDGES)); @Inject CircumventionProviderImpl() { @@ -58,8 +57,8 @@ class CircumventionProviderImpl implements CircumventionProvider { return asList(DEFAULT_OBFS4, VANILLA); } else if (NON_DEFAULT_BRIDGE_COUNTRIES.contains(countryCode)) { return asList(NON_DEFAULT_OBFS4, VANILLA); - } else if (MEEK_COUNTRIES.contains(countryCode)) { - return singletonList(MEEK); + } else if (DPI_COUNTRIES.contains(countryCode)) { + return asList(NON_DEFAULT_OBFS4, MEEK); } else { return asList(DEFAULT_OBFS4, VANILLA); } diff --git a/bramble-core/src/test/java/org/briarproject/bramble/plugin/tor/CircumventionProviderTest.java b/bramble-core/src/test/java/org/briarproject/bramble/plugin/tor/CircumventionProviderTest.java index 593275ed6..7dd380d68 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/plugin/tor/CircumventionProviderTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/plugin/tor/CircumventionProviderTest.java @@ -7,7 +7,6 @@ import java.util.HashSet; import java.util.Set; import static java.util.Arrays.asList; -import static java.util.Collections.singletonList; import static org.briarproject.bramble.plugin.tor.CircumventionProvider.BLOCKED; import static org.briarproject.bramble.plugin.tor.CircumventionProvider.BRIDGES; import static org.briarproject.bramble.plugin.tor.CircumventionProvider.BridgeType.DEFAULT_OBFS4; @@ -15,7 +14,7 @@ import static org.briarproject.bramble.plugin.tor.CircumventionProvider.BridgeTy import static org.briarproject.bramble.plugin.tor.CircumventionProvider.BridgeType.NON_DEFAULT_OBFS4; import static org.briarproject.bramble.plugin.tor.CircumventionProvider.BridgeType.VANILLA; import static org.briarproject.bramble.plugin.tor.CircumventionProvider.DEFAULT_BRIDGES; -import static org.briarproject.bramble.plugin.tor.CircumventionProvider.MEEK_BRIDGES; +import static org.briarproject.bramble.plugin.tor.CircumventionProvider.DPI_BRIDGES; import static org.briarproject.bramble.plugin.tor.CircumventionProvider.NON_DEFAULT_BRIDGES; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -32,18 +31,18 @@ public class CircumventionProviderTest extends BrambleTestCase { Set defaultBridges = new HashSet<>(asList(DEFAULT_BRIDGES)); Set nonDefaultBridges = new HashSet<>(asList(NON_DEFAULT_BRIDGES)); - Set meekBridges = new HashSet<>(asList(MEEK_BRIDGES)); + Set dpiBridges = new HashSet<>(asList(DPI_BRIDGES)); // BRIDGES should be a subset of BLOCKED assertTrue(blocked.containsAll(bridges)); // BRIDGES should be the union of the bridge type sets Set union = new HashSet<>(defaultBridges); union.addAll(nonDefaultBridges); - union.addAll(meekBridges); + union.addAll(dpiBridges); assertEquals(bridges, union); // The bridge type sets should not overlap assertEmptyIntersection(defaultBridges, nonDefaultBridges); - assertEmptyIntersection(defaultBridges, meekBridges); - assertEmptyIntersection(nonDefaultBridges, meekBridges); + assertEmptyIntersection(defaultBridges, dpiBridges); + assertEmptyIntersection(nonDefaultBridges, dpiBridges); } @Test @@ -56,8 +55,8 @@ public class CircumventionProviderTest extends BrambleTestCase { assertEquals(asList(NON_DEFAULT_OBFS4, VANILLA), provider.getSuitableBridgeTypes(country)); } - for (String country : MEEK_BRIDGES) { - assertEquals(singletonList(MEEK), + for (String country : DPI_BRIDGES) { + assertEquals(asList(NON_DEFAULT_OBFS4, MEEK), provider.getSuitableBridgeTypes(country)); } assertEquals(asList(DEFAULT_OBFS4, VANILLA),