]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add a switch to toggle the feature on/off
authorGeorge Kadianakis <desnacked@riseup.net>
Mon, 12 Jul 2021 08:45:31 +0000 (11:45 +0300)
committerGeorge Kadianakis <desnacked@riseup.net>
Mon, 12 Jul 2021 09:22:58 +0000 (12:22 +0300)
doc/man/tor.1.txt
src/app/config/config.c
src/app/config/or_options_st.h
src/core/or/circuitbuild.c
src/feature/client/entrynodes.c
src/feature/client/entrynodes.h
src/test/test_entrynodes.c

index 89afe5958202a3d9c6782640deba1058dc4a39fe..2b5a1d9df7989e9e3ceeefed73c3a0e00345dcb8 100644 (file)
@@ -1749,6 +1749,13 @@ The following options are useful only for clients (that is, if
     the guard-n-primary-guards consensus parameter, and default to 3 if the
     consensus parameter isn't set. (Default: 0)
 
+[[VanguardsLiteEnabled]] **VanguardsLiteEnabled** **0**|**1**|**auto**::
+    This option specifies whether clients should use the vanguards-lite
+    subsystem to protect against guard discovery attacks. If it's set to
+    'auto', clients will do what the vanguards-lite-enabled consensus parameter
+    tells them to do, and will default to enable the subsystem if the consensus
+    parameter isn't set. (Default: auto)
+
 [[UseMicrodescriptors]] **UseMicrodescriptors** **0**|**1**|**auto**::
     Microdescriptors are a smaller version of the information that Tor needs
     in order to build its circuits.  Using microdescriptors makes Tor clients
index 078df506774434d1822e5e693e4608db491ce85a..15b45859542bbb3609e3d076dbec868321745271 100644 (file)
@@ -669,6 +669,7 @@ static const config_var_t option_vars_[] = {
   VAR("UseEntryGuards",          BOOL,     UseEntryGuards_option, "1"),
   OBSOLETE("UseEntryGuardsAsDirGuards"),
   V(UseGuardFraction,            AUTOBOOL, "auto"),
+  V(VanguardsLiteEnabled,        AUTOBOOL, "auto"),
   V(UseMicrodescriptors,         AUTOBOOL, "auto"),
   OBSOLETE("UseNTorHandshake"),
   V_IMMUTABLE(User,              STRING,   NULL),
index b28986598315bf8eb681e25b193cb3cf712564b0..812fa92cae9790afbf01fdbd009ddfca90842b3f 100644 (file)
@@ -594,6 +594,9 @@ struct or_options_t {
                            * If 0, use value from NumEntryGuards. */
   int NumPrimaryGuards; /**< How many primary guards do we want? */
 
+  /** Boolean: Switch to toggle the vanguards-lite subsystem */
+  int VanguardsLiteEnabled;
+
   int RephistTrackTime; /**< How many seconds do we keep rephist info? */
   /** Should we always fetch our dir info on the mirror schedule (which
    * means directly from the authorities) no matter our other config? */
index 84a8bec4215d56007f8a7b35530ea0d7e89638d5..31e3868b65ba43b947c34f323d5faabaad0e6bae 100644 (file)
@@ -2254,6 +2254,11 @@ middle_node_must_be_vanguard(const or_options_t *options,
     return 0;
   }
 
+  /* Don't even bother if the feature is disabled */
+  if (!vanguards_lite_is_enabled()) {
+    return 0;
+  }
+
   /* If we are a hidden service circuit, always use either vanguards-lite
    * or HSLayer2Nodes for 2nd hop. */
   if (cur_len == 1) {
index 1e9416c9cfd2e505134bdc34de9d92ba29a7526d..33de8a6b109b726fd148661d7150b5a6638f3193 100644 (file)
@@ -3932,7 +3932,7 @@ guard_selection_free_(guard_selection_t *gs)
 
 /**********************************************************************/
 
-/** Layer2 guard subsystem used for onion service circuits. */
+/** Layer2 guard subsystem (vanguards-lite) used for onion service circuits */
 
 /** A simple representation of a layer2 guard. We just need its identity so
  *  that we feed it into a routerset, and a sampled timestamp to do expiration
@@ -3947,6 +3947,30 @@ typedef struct layer2_guard_t {
 #define layer2_guard_free(val) \
   FREE_AND_NULL(layer2_guard_t, layer2_guard_free_, (val))
 
+/** Return true if the vanguards-lite subsystem is enabled */
+bool
+vanguards_lite_is_enabled(void)
+{
+  /* First check torrc option and then maybe also the consensus parameter. */
+  const or_options_t *options = get_options();
+
+  /* If the option is explicitly disabled, that's the final word here */
+  if (options->VanguardsLiteEnabled == 0) {
+    return false;
+  }
+
+  /* If the option is set to auto, then check the consensus parameter */
+  if (options->VanguardsLiteEnabled == -1) {
+    return networkstatus_get_param(NULL, "vanguards-lite-enabled",
+                                   1, /* default to "on" */
+                                   0, 1);
+  }
+
+  /* else it's enabled */
+  tor_assert_nonfatal(options->VanguardsLiteEnabled == 1);
+  return options->VanguardsLiteEnabled;
+}
+
 static void
 layer2_guard_free_(layer2_guard_t *l2)
 {
index 9c38c2b5f81ae9aac1e237926ddd7c7f0aed76be..08fd7cf745c60ed69df3980343b2a99a34b1aceb 100644 (file)
@@ -651,6 +651,7 @@ guard_get_guardfraction_bandwidth(guardfraction_bandwidth_t *guardfraction_bw,
                                   int orig_bandwidth,
                                   uint32_t guardfraction_percentage);
 
+bool vanguards_lite_is_enabled(void);
 const routerset_t *get_layer2_guards(void);
 void maintain_layer2_guards(void);
 void purge_vanguards_lite(void);
index 4d353e8480a84229aed0731658d0695c9f841a6a..118b66dfa78c189044e5c08aede043353d3c857a 100644 (file)
@@ -3099,7 +3099,22 @@ test_entry_guard_layer2_guards(void *arg)
   (void) arg;
   MOCK(router_have_minimum_dir_info, mock_router_have_minimum_dir_info);
 
-  /* Create the guardset */
+  /* First check the enable/disable switch */
+  get_options_mutable()->VanguardsLiteEnabled = 0;
+  tt_int_op(vanguards_lite_is_enabled(), OP_EQ, 0);
+
+  get_options_mutable()->VanguardsLiteEnabled = 1;
+  tt_int_op(vanguards_lite_is_enabled(), OP_EQ, 1);
+
+  get_options_mutable()->VanguardsLiteEnabled = -1;
+  tt_int_op(vanguards_lite_is_enabled(), OP_EQ, 1);
+
+  /* OK now let's move to actual testing */
+
+  /* Remove restrictions to route around Big Fake Network restrictions */
+  get_options_mutable()->EnforceDistinctSubnets = 0;
+
+  /* Create the L2 guardset */
   maintain_layer2_guards();
 
   const routerset_t *l2_guards = get_layer2_guards();