]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
compat-mode: allow user to specify version to be compatible with
authorAntonio Quartulli <a@unstable.cc>
Wed, 8 Sep 2021 07:26:06 +0000 (09:26 +0200)
committerGert Doering <gert@greenie.muc.de>
Wed, 8 Sep 2021 08:23:35 +0000 (10:23 +0200)
This changes introduces the basic infrastructure required
to allow the user to specify a specific OpenVPN version to be
compatible with.

The next commits will modify defaults to more modern and safer
values, while allowing backwards-compatible behaviour on demand.

The backwards-compatible behaviour is intructed via the config
knob '--compat-mode' implemented in this patch.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by:
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20210908072606.5863-1-a@unstable.cc>
URL: https://www.mail-archive.com/search?l=mid&q=20210908072606.5863-1-a@unstable.cc
Signed-off-by: Gert Doering <gert@greenie.muc.de>
Changes.rst
doc/man-sections/generic-options.rst
src/openvpn/options.c
src/openvpn/options.h

index 637ed97a6383e331bd38552ae31d2d929db84771..7efb34934f950a5ed4af48b4c9340a278a738087 100644 (file)
@@ -45,6 +45,12 @@ Pending auth support for plugins and scripts
 
     See ``sample/sample-scripts/totpauth.py`` for an example.
 
+Compatibility mode (``--compat-mode``)
+    The modernisation of defaults can impact the compatibility of OpenVPN 2.6.0
+    with older peers. The options ``--compat-mode`` allows UIs to provide users
+    with an easy way to still connect to older servers.
+
+
 Deprecated features
 -------------------
 ``inetd`` has been removed
index 203e35f57426fdaa177b5f75b4faa69100f8c917..c746e2323c2c81ad277a2486234557c8a09f42a6 100644 (file)
@@ -52,6 +52,15 @@ which mode OpenVPN is configured as.
   BSDs implement a getrandom() or getentropy() syscall that removes the
   need for /dev/urandom to be available.
 
+--compat-mode version
+  This option provides a way to alter the default of OpenVPN to be more
+  compatible with the version ``version`` specified. All of the changes
+  this option does can also be achieved using individual configuration
+  options.
+
+  Note: Using this option reverts defaults to no longer recommended
+  values and should be avoided if possible.
+
 --config file
   Load additional config options from ``file`` where each line corresponds
   to one command line option, but with the leading '--' removed.
index f00b30196a8ba670ee81fa1b31200efdbc366995..1f0f87839687f3a6e7b5a4bda82ee41deb62e153 100644 (file)
@@ -3147,6 +3147,35 @@ options_postprocess_cipher(struct options *o)
     }
 }
 
+/**
+ * The option --compat-mode is used to set up default settings to values 
+ * used on the specified openvpn version and earlier.
+ *
+ * This function is used in various "default option" paths to test if the
+ * user requested compatibility with a version before the one specified
+ * as argument. This way some default settings can be automatically 
+ * altered to guarantee compatibility with the version specified by the 
+ * user via --compat-mode.
+ *
+ * @param version   need compatibility with openvpn versions before the
+ *                  one specified (20401 = before 2.4.1)
+ * @return          whether compatibility should be enabled
+ */
+static bool
+need_compatibility_before(const struct options *o, unsigned int version)
+{
+    return o->backwards_compatible != 0 && o->backwards_compatible < version;
+}
+
+/**
+ * Changes default values so that OpenVPN can be compatible with the user
+ * specified version
+ */
+static void
+options_set_backwards_compatible_options(struct options *o)
+{
+}
+
 static void
 options_postprocess_mutate(struct options *o)
 {
@@ -3160,6 +3189,8 @@ options_postprocess_mutate(struct options *o)
     helper_tcp_nodelay(o);
 
     options_postprocess_setdefault_ncpciphers(o);
+    options_set_backwards_compatible_options(o);
+
     options_postprocess_cipher(o);
     options_postprocess_mutate_invariant(o);
 
@@ -6728,6 +6759,18 @@ add_option(struct options *options,
             setenv_str(es, p[1], p[2] ? p[2] : "");
         }
     }
+    else if (streq(p[0], "compat-mode") && p[1] && !p[3])
+    {
+        unsigned int major, minor, patch;
+        if (!(sscanf(p[1], "%u.%u.%u", &major, &minor, &patch) == 3))
+        {
+            msg(msglevel, "cannot parse version number for --compat-mode: %s",
+                p[1]);
+            goto err;
+        }
+
+        options->backwards_compatible = major * 10000 + minor * 100 + patch;
+    }
     else if (streq(p[0], "setenv-safe") && p[1] && !p[3])
     {
         VERIFY_PERMISSION(OPT_P_SETENV);
index b0e40cb7f9bbd665d2624a22bb9e553d59a84a8a..98c21a2a8adffa48c116e907e061ac3de7668f2e 100644 (file)
@@ -225,6 +225,10 @@ struct options
 
     /* enable forward compatibility for post-2.1 features */
     bool forward_compatible;
+    /** What version we should try to be compatible with as major * 10000 +
+      * minor * 100 + patch, e.g. 2.4.7 => 20407 */
+    unsigned int backwards_compatible;
+
     /* list of options that should be ignored even if unknown */
     const char **ignore_unknown_option;