Skip to contentSkip to conversation

Add file to ignore reformatting changes

PATCH New Arne Schwabe 3 participants 15 messages Jul 7, 2020 – Jul 8, 2020 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add file to ignore reformatting changes

This allows git blame to ignore reformatting changes and instead shows the previous commit that changed the line.

To avoid manually building the list of commits this commit adds a file with a list of reformatting commits. I might have missed a few but this should be a good start. To use the file use:

   git blame --ignore-revs-file=.git-blame-ignore-revs file

or to automatically always use the file

git config blame.ignoreRevsFile .git-blame-ignore-revs

Naming the file .git-blame-ignore-revs is a convention.

Some more details in this random blog post:

https://www.moxio.com/blog/43/ignoring-bulk-change-commits-with-git-blame

---
 .git-blame-ignore-revs                        | 29 +++++++++++++++++++
 .../managent-demo/management-demo-server.py   |  0
 contrib/ovpnkeys.py                           |  0
 3 files changed, 29 insertions(+)
 create mode 100644 .git-blame-ignore-revs
 create mode 100644 contrib/managent-demo/management-demo-server.py
 create mode 100644 contrib/ovpnkeys.py
.git-blame-ignore-revs new file +29 -0
new file mode 100644
index 00000000..3cc811cf
@@ -0,0 +1,29 @@
+# Uncrustify the tests/unit_tests/ part of our tree. 
+da1574ef7826d73f01e120cbd1ba40ce39a305b7
+
+# Another round of uncrustify code cleanup.
+9cf7b4925a54d93fbea1cadcf3dc0e11f3ce358f
+
+# networking_sitnl.c: uncrustify file
+2c45d268ca65c522fbabb7c4dab5e721296b4623
+
+# Uncrustify tapctl and openvpnmsica
+6280d3d5536174934ee22d3840457d61896e0e3a
+# tun.c: uncrustify
+baef44fc8769bbd99f4d699ce9f63180c29a5455
+
+# networking_sitnl.c: uncrustify file
+2c45d268ca65c522fbabb7c4dab5e721296b4623
+
+# uncrustify openvpn sources
+f57431cdc88f22fa4d7962946f0d3187fe058539
+
+# More broadly enforce Allman style and braces-around-conditionals
+4cd4899e8e80efae03c584a760fd107251735723
+
+# Merge 'reformatting' branch into master
+1f004b2f06e987d73e48f7fd7b96b0b248274f58
+
+# The Great Reformatting - first phase
+81d882d5302b8b647202a6893b57dfdc61fd6df2
+
contrib/managent-demo/management-demo-server.py new file +0 -0
new file mode 100644
index 00000000..e69de29b
contrib/ovpnkeys.py new file +0 -0
new file mode 100644
index 00000000..e69de29b
Signature · 1 line
2.26.0
#1 lore raw

PATCH 1/1 Add .git-blame-ignore-revs with reformat commits

This allows git blame to ignore reformatting changes and instead shows the previous commit that changed the line.

To avoid manually building the list of commits this commit adds a file with a list of reformatting commits. I might have missed a few but this should be a good start. To use the file use:

   git blame --ignore-revs-file=.git-blame-ignore-revs file

or to automatically always use the file

git config blame.ignoreRevsFile .git-blame-ignore-revs

Naming the file .git-blame-ignore-revs is a convention.

Some more details in this random blog post:

https://www.moxio.com/blog/43/ignoring-bulk-change-commits-with-git-blame

---
 .git-blame-ignore-revs                        | 29 +++++++++++++++++++
 .../managent-demo/management-demo-server.py   |  0
 contrib/ovpnkeys.py                           |  0
 3 files changed, 29 insertions(+)
 create mode 100644 .git-blame-ignore-revs
 create mode 100644 contrib/managent-demo/management-demo-server.py
 create mode 100644 contrib/ovpnkeys.py
.git-blame-ignore-revs new file +29 -0
new file mode 100644
index 00000000..3cc811cf
@@ -0,0 +1,29 @@
+# Uncrustify the tests/unit_tests/ part of our tree. 
+da1574ef7826d73f01e120cbd1ba40ce39a305b7
+
+# Another round of uncrustify code cleanup.
+9cf7b4925a54d93fbea1cadcf3dc0e11f3ce358f
+
+# networking_sitnl.c: uncrustify file
+2c45d268ca65c522fbabb7c4dab5e721296b4623
+
+# Uncrustify tapctl and openvpnmsica
+6280d3d5536174934ee22d3840457d61896e0e3a
+# tun.c: uncrustify
+baef44fc8769bbd99f4d699ce9f63180c29a5455
+
+# networking_sitnl.c: uncrustify file
+2c45d268ca65c522fbabb7c4dab5e721296b4623
+
+# uncrustify openvpn sources
+f57431cdc88f22fa4d7962946f0d3187fe058539
+
+# More broadly enforce Allman style and braces-around-conditionals
+4cd4899e8e80efae03c584a760fd107251735723
+
+# Merge 'reformatting' branch into master
+1f004b2f06e987d73e48f7fd7b96b0b248274f58
+
+# The Great Reformatting - first phase
+81d882d5302b8b647202a6893b57dfdc61fd6df2
+
contrib/managent-demo/management-demo-server.py new file +0 -0
new file mode 100644
index 00000000..e69de29b
contrib/ovpnkeys.py new file +0 -0
new file mode 100644
index 00000000..e69de29b
Signature · 1 line
2.26.0
#2 lore raw

Re: [Openvpn-devel] [PATCH] Add .git-blame-ignore-revs with reformat commits

Am 07.07.20 um 14:16 schrieb Arne Schwabe:

Quoted 2 lines

This allows git blame to ignore reformatting changes and instead shows the previous commit that changed the line.

Ignore the first two patches.

git send-email [email protected] *patch

is a dangerous thing to do. The other three patches are fine.

#3 lore raw

PATCH 1/3 Simplify multi_connection_established.

In reply to Arne Schwabe

Instead of having the whole function as

    if (x) { func }

do

if (!x) func

Due to the whitespace changes in the function body this patch looks very strange. Ignoring whitespace makes the diff look sane.

---
 src/openvpn/multi.c | 476 ++++++++++++++++++++++----------------------
 1 file changed, 239 insertions(+), 237 deletions(-)
src/openvpn/multi.c +239 -237
index 6923d2ce..f1ced9b7 100644
@@ -1784,56 +1784,74 @@ multi_client_connect_setenv(struct multi_context *m,
 static void
 multi_connection_established(struct multi_context *m, struct multi_instance *mi)
 {
-    if (tls_authentication_status(mi->context.c2.tls_multi, 0) == TLS_AUTHENTICATION_SUCCEEDED)
+    if (tls_authentication_status(mi->context.c2.tls_multi, 0) != TLS_AUTHENTICATION_SUCCEEDED)
     {
-        struct gc_arena gc = gc_new();
-        unsigned int option_types_found = 0;
+        return;
+    }
 
-        const unsigned int option_permissions_mask =
-            OPT_P_INSTANCE
-            | OPT_P_INHERIT
-            | OPT_P_PUSH
-            | OPT_P_TIMER
-            | OPT_P_CONFIG
-            | OPT_P_ECHO
-            | OPT_P_COMP
-            | OPT_P_SOCKFLAGS;
+    struct gc_arena gc = gc_new();
+    unsigned int option_types_found = 0;
 
-        int cc_succeeded = true; /* client connect script status */
-        int cc_succeeded_count = 0;
+    const unsigned int option_permissions_mask =
+        OPT_P_INSTANCE
+        | OPT_P_INHERIT
+        | OPT_P_PUSH
+        | OPT_P_TIMER
+        | OPT_P_CONFIG
+        | OPT_P_ECHO
+        | OPT_P_COMP
+        | OPT_P_SOCKFLAGS;
 
-        ASSERT(mi->context.c1.tuntap);
+    int cc_succeeded = true;     /* client connect script status */
+    int cc_succeeded_count = 0;
 
-        /* lock down the common name and cert hashes so they can't change during future TLS renegotiations */
-        tls_lock_common_name(mi->context.c2.tls_multi);
-        tls_lock_cert_hash_set(mi->context.c2.tls_multi);
+    ASSERT(mi->context.c1.tuntap);
 
-        /* generate a msg() prefix for this client instance */
-        generate_prefix(mi);
+    /* lock down the common name and cert hashes so they can't change during future TLS renegotiations */
+    tls_lock_common_name(mi->context.c2.tls_multi);
+    tls_lock_cert_hash_set(mi->context.c2.tls_multi);
 
-        /* delete instances of previous clients with same common-name */
-        if (!mi->context.options.duplicate_cn)
-        {
-            multi_delete_dup(m, mi);
-        }
+    /* generate a msg() prefix for this client instance */
+    generate_prefix(mi);
 
-        /* reset pool handle to null */
-        mi->vaddr_handle = -1;
+    /* delete instances of previous clients with same common-name */
+    if (!mi->context.options.duplicate_cn)
+    {
+        multi_delete_dup(m, mi);
+    }
 
-        /*
-         * Try to source a dynamic config file from the
-         * --client-config-dir directory.
-         */
-        if (mi->context.options.client_config_dir)
-        {
-            const char *ccd_file;
+    /* reset pool handle to null */
+    mi->vaddr_handle = -1;
+
+    /*
+     * Try to source a dynamic config file from the
+     * --client-config-dir directory.
+     */
+    if (mi->context.options.client_config_dir)
+    {
+        const char *ccd_file;
 
+        ccd_file = platform_gen_path(mi->context.options.client_config_dir,
+                                     tls_common_name(mi->context.c2.tls_multi,
+                                                     false),
+                                     &gc);
+
+        /* try common-name file */
+        if (platform_test_file(ccd_file))
+        {
+            options_server_import(&mi->context.options,
+                                  ccd_file,
+                                  D_IMPORT_ERRORS|M_OPTERR,
+                                  option_permissions_mask,
+                                  &option_types_found,
+                                  mi->context.c2.es);
+        }
+        else     /* try default file */
+        {
             ccd_file = platform_gen_path(mi->context.options.client_config_dir,
-                                         tls_common_name(mi->context.c2.tls_multi,
-                                                         false),
+                                         CCD_DEFAULT,
                                          &gc);
 
-            /* try common-name file */
             if (platform_test_file(ccd_file))
             {
                 options_server_import(&mi->context.options,
@@ -1843,262 +1861,246 @@ multi_connection_established(struct multi_context *m, struct multi_instance *mi)
                                       &option_types_found,
                                       mi->context.c2.es);
             }
-            else /* try default file */
-            {
-                ccd_file = platform_gen_path(mi->context.options.client_config_dir,
-                                             CCD_DEFAULT,
-                                             &gc);
-
-                if (platform_test_file(ccd_file))
-                {
-                    options_server_import(&mi->context.options,
-                                          ccd_file,
-                                          D_IMPORT_ERRORS|M_OPTERR,
-                                          option_permissions_mask,
-                                          &option_types_found,
-                                          mi->context.c2.es);
-                }
-            }
         }
+    }
 
-        /*
-         * Select a virtual address from either --ifconfig-push in --client-config-dir file
-         * or --ifconfig-pool.
-         */
-        multi_select_virtual_addr(m, mi);
+    /*
+     * Select a virtual address from either --ifconfig-push in --client-config-dir file
+     * or --ifconfig-pool.
+     */
+    multi_select_virtual_addr(m, mi);
 
-        /* do --client-connect setenvs */
-        multi_client_connect_setenv(m, mi);
+    /* do --client-connect setenvs */
+    multi_client_connect_setenv(m, mi);
 
 #ifdef ENABLE_PLUGIN
-        /*
-         * Call client-connect plug-in.
-         */
-
-        /* deprecated callback, use a file for passing back return info */
-        if (plugin_defined(mi->context.plugins, OPENVPN_PLUGIN_CLIENT_CONNECT))
-        {
-            struct argv argv = argv_new();
-            const char *dc_file = platform_create_temp_file(mi->context.options.tmp_dir,
-                                                            "cc", &gc);
-
-            if (!dc_file)
-            {
-                cc_succeeded = false;
-                goto script_depr_failed;
-            }
+    /*
+     * Call client-connect plug-in.
+     */
 
-            argv_printf(&argv, "%s", dc_file);
-            if (plugin_call(mi->context.plugins, OPENVPN_PLUGIN_CLIENT_CONNECT, &argv, NULL, mi->context.c2.es) != OPENVPN_PLUGIN_FUNC_SUCCESS)
-            {
-                msg(M_WARN, "WARNING: client-connect plugin call failed");
-                cc_succeeded = false;
-            }
-            else
-            {
-                multi_client_connect_post(m, mi, dc_file, option_permissions_mask, &option_types_found);
-                ++cc_succeeded_count;
-            }
+    /* deprecated callback, use a file for passing back return info */
+    if (plugin_defined(mi->context.plugins, OPENVPN_PLUGIN_CLIENT_CONNECT))
+    {
+        struct argv argv = argv_new();
+        const char *dc_file = platform_create_temp_file(mi->context.options.tmp_dir,
+                                                        "cc", &gc);
 
-            if (!platform_unlink(dc_file))
-            {
-                msg(D_MULTI_ERRORS, "MULTI: problem deleting temporary file: %s",
-                    dc_file);
-            }
+        if (!dc_file)
+        {
+            cc_succeeded = false;
+            goto script_depr_failed;
+        }
 
-script_depr_failed:
-            argv_free(&argv);
+        argv_printf(&argv, "%s", dc_file);
+        if (plugin_call(mi->context.plugins, OPENVPN_PLUGIN_CLIENT_CONNECT, &argv, NULL, mi->context.c2.es) != OPENVPN_PLUGIN_FUNC_SUCCESS)
+        {
+            msg(M_WARN, "WARNING: client-connect plugin call failed");
+            cc_succeeded = false;
+        }
+        else
+        {
+            multi_client_connect_post(m, mi, dc_file, option_permissions_mask, &option_types_found);
+            ++cc_succeeded_count;
         }
 
-        /* V2 callback, use a plugin_return struct for passing back return info */
-        if (plugin_defined(mi->context.plugins, OPENVPN_PLUGIN_CLIENT_CONNECT_V2))
+        if (!platform_unlink(dc_file))
         {
-            struct plugin_return pr;
+            msg(D_MULTI_ERRORS, "MULTI: problem deleting temporary file: %s",
+                dc_file);
+        }
 
-            plugin_return_init(&pr);
+script_depr_failed:
+        argv_free(&argv);
+    }
 
-            if (plugin_call(mi->context.plugins, OPENVPN_PLUGIN_CLIENT_CONNECT_V2, NULL, &pr, mi->context.c2.es) != OPENVPN_PLUGIN_FUNC_SUCCESS)
-            {
-                msg(M_WARN, "WARNING: client-connect-v2 plugin call failed");
-                cc_succeeded = false;
-            }
-            else
-            {
-                multi_client_connect_post_plugin(m, mi, &pr, option_permissions_mask, &option_types_found);
-                ++cc_succeeded_count;
-            }
+    /* V2 callback, use a plugin_return struct for passing back return info */
+    if (plugin_defined(mi->context.plugins, OPENVPN_PLUGIN_CLIENT_CONNECT_V2))
+    {
+        struct plugin_return pr;
+
+        plugin_return_init(&pr);
 
-            plugin_return_free(&pr);
+        if (plugin_call(mi->context.plugins, OPENVPN_PLUGIN_CLIENT_CONNECT_V2, NULL, &pr, mi->context.c2.es) != OPENVPN_PLUGIN_FUNC_SUCCESS)
+        {
+            msg(M_WARN, "WARNING: client-connect-v2 plugin call failed");
+            cc_succeeded = false;
+        }
+        else
+        {
+            multi_client_connect_post_plugin(m, mi, &pr, option_permissions_mask, &option_types_found);
+            ++cc_succeeded_count;
         }
+
+        plugin_return_free(&pr);
+    }
 #endif /* ifdef ENABLE_PLUGIN */
 
-        /*
-         * Run --client-connect script.
-         */
-        if (mi->context.options.client_connect_script && cc_succeeded)
-        {
-            struct argv argv = argv_new();
-            const char *dc_file = NULL;
+    /*
+     * Run --client-connect script.
+     */
+    if (mi->context.options.client_connect_script && cc_succeeded)
+    {
+        struct argv argv = argv_new();
+        const char *dc_file = NULL;
 
-            setenv_str(mi->context.c2.es, "script_type", "client-connect");
+        setenv_str(mi->context.c2.es, "script_type", "client-connect");
 
-            dc_file = platform_create_temp_file(mi->context.options.tmp_dir,
-                                                "cc", &gc);
-            if (!dc_file)
-            {
-                cc_succeeded = false;
-                goto script_failed;
-            }
+        dc_file = platform_create_temp_file(mi->context.options.tmp_dir,
+                                            "cc", &gc);
+        if (!dc_file)
+        {
+            cc_succeeded = false;
+            goto script_failed;
+        }
 
-            argv_parse_cmd(&argv, mi->context.options.client_connect_script);
-            argv_printf_cat(&argv, "%s", dc_file);
+        argv_parse_cmd(&argv, mi->context.options.client_connect_script);
+        argv_printf_cat(&argv, "%s", dc_file);
 
-            if (openvpn_run_script(&argv, mi->context.c2.es, 0, "--client-connect"))
-            {
-                multi_client_connect_post(m, mi, dc_file, option_permissions_mask, &option_types_found);
-                ++cc_succeeded_count;
-            }
-            else
-            {
-                cc_succeeded = false;
-            }
+        if (openvpn_run_script(&argv, mi->context.c2.es, 0, "--client-connect"))
+        {
+            multi_client_connect_post(m, mi, dc_file, option_permissions_mask, &option_types_found);
+            ++cc_succeeded_count;
+        }
+        else
+        {
+            cc_succeeded = false;
+        }
 
-            if (!platform_unlink(dc_file))
-            {
-                msg(D_MULTI_ERRORS, "MULTI: problem deleting temporary file: %s",
-                    dc_file);
-            }
+        if (!platform_unlink(dc_file))
+        {
+            msg(D_MULTI_ERRORS, "MULTI: problem deleting temporary file: %s",
+                dc_file);
+        }
 
 script_failed:
-            argv_free(&argv);
-        }
+        argv_free(&argv);
+    }
 
+    /*
+     * Check for client-connect script left by management interface client
+     */
+#ifdef MANAGEMENT_DEF_AUTH
+    if (cc_succeeded && mi->cc_config)
+    {
+        multi_client_connect_mda(m, mi, option_permissions_mask, &option_types_found);
+        ++cc_succeeded_count;
+    }
+#endif
+
+    /*
+     * Check for "disable" directive in client-config-dir file
+     * or config file generated by --client-connect script.
+     */
+    if (mi->context.options.disable)
+    {
+        msg(D_MULTI_ERRORS, "MULTI: client has been rejected due to 'disable' directive");
+        cc_succeeded = false;
+        cc_succeeded_count = 0;
+    }
+
+    if (cc_succeeded)
+    {
         /*
-         * Check for client-connect script left by management interface client
+         * Process sourced options.
          */
-#ifdef MANAGEMENT_DEF_AUTH
-        if (cc_succeeded && mi->cc_config)
+        do_deferred_options(&mi->context, option_types_found);
+
+        /*
+         * make sure we got ifconfig settings from somewhere
+         */
+        if (!mi->context.c2.push_ifconfig_defined)
         {
-            multi_client_connect_mda(m, mi, option_permissions_mask, &option_types_found);
-            ++cc_succeeded_count;
+            msg(D_MULTI_ERRORS, "MULTI: no dynamic or static remote --ifconfig address is available for %s",
+                multi_instance_string(mi, false, &gc));
         }
-#endif
 
         /*
-         * Check for "disable" directive in client-config-dir file
-         * or config file generated by --client-connect script.
+         * make sure that ifconfig settings comply with constraints
          */
-        if (mi->context.options.disable)
+        if (!ifconfig_push_constraint_satisfied(&mi->context))
         {
-            msg(D_MULTI_ERRORS, "MULTI: client has been rejected due to 'disable' directive");
-            cc_succeeded = false;
-            cc_succeeded_count = 0;
+            /* JYFIXME -- this should cause the connection to fail */
+            msg(D_MULTI_ERRORS, "MULTI ERROR: primary virtual IP for %s (%s) violates tunnel network/netmask constraint (%s/%s)",
+                multi_instance_string(mi, false, &gc),
+                print_in_addr_t(mi->context.c2.push_ifconfig_local, 0, &gc),
+                print_in_addr_t(mi->context.options.push_ifconfig_constraint_network, 0, &gc),
+                print_in_addr_t(mi->context.options.push_ifconfig_constraint_netmask, 0, &gc));
         }
 
-        if (cc_succeeded)
+        /*
+         * For routed tunnels, set up internal route to endpoint
+         * plus add all iroute routes.
+         */
+        if (TUNNEL_TYPE(mi->context.c1.tuntap) == DEV_TYPE_TUN)
         {
-            /*
-             * Process sourced options.
-             */
-            do_deferred_options(&mi->context, option_types_found);
-
-            /*
-             * make sure we got ifconfig settings from somewhere
-             */
-            if (!mi->context.c2.push_ifconfig_defined)
+            if (mi->context.c2.push_ifconfig_defined)
             {
-                msg(D_MULTI_ERRORS, "MULTI: no dynamic or static remote --ifconfig address is available for %s",
-                    multi_instance_string(mi, false, &gc));
+                multi_learn_in_addr_t(m, mi, mi->context.c2.push_ifconfig_local, -1, true);
+                msg(D_MULTI_LOW, "MULTI: primary virtual IP for %s: %s",
+                    multi_instance_string(mi, false, &gc),
+                    print_in_addr_t(mi->context.c2.push_ifconfig_local, 0, &gc));
             }
 
-            /*
-             * make sure that ifconfig settings comply with constraints
-             */
-            if (!ifconfig_push_constraint_satisfied(&mi->context))
+            if (mi->context.c2.push_ifconfig_ipv6_defined)
             {
-                /* JYFIXME -- this should cause the connection to fail */
-                msg(D_MULTI_ERRORS, "MULTI ERROR: primary virtual IP for %s (%s) violates tunnel network/netmask constraint (%s/%s)",
+                multi_learn_in6_addr(m, mi, mi->context.c2.push_ifconfig_ipv6_local, -1, true);
+                /* TODO: find out where addresses are "unlearned"!! */
+                msg(D_MULTI_LOW, "MULTI: primary virtual IPv6 for %s: %s",
                     multi_instance_string(mi, false, &gc),
-                    print_in_addr_t(mi->context.c2.push_ifconfig_local, 0, &gc),
-                    print_in_addr_t(mi->context.options.push_ifconfig_constraint_network, 0, &gc),
-                    print_in_addr_t(mi->context.options.push_ifconfig_constraint_netmask, 0, &gc));
+                    print_in6_addr(mi->context.c2.push_ifconfig_ipv6_local, 0, &gc));
             }
 
+            /* add routes locally, pointing to new client, if
+             * --iroute options have been specified */
+            multi_add_iroutes(m, mi);
+
             /*
-             * For routed tunnels, set up internal route to endpoint
-             * plus add all iroute routes.
+             * iroutes represent subnets which are "owned" by a particular
+             * client.  Therefore, do not actually push a route to a client
+             * if it matches one of the client's iroutes.
              */
-            if (TUNNEL_TYPE(mi->context.c1.tuntap) == DEV_TYPE_TUN)
-            {
-                if (mi->context.c2.push_ifconfig_defined)
-                {
-                    multi_learn_in_addr_t(m, mi, mi->context.c2.push_ifconfig_local, -1, true);
-                    msg(D_MULTI_LOW, "MULTI: primary virtual IP for %s: %s",
-                        multi_instance_string(mi, false, &gc),
-                        print_in_addr_t(mi->context.c2.push_ifconfig_local, 0, &gc));
-                }
-
-                if (mi->context.c2.push_ifconfig_ipv6_defined)
-                {
-                    multi_learn_in6_addr(m, mi, mi->context.c2.push_ifconfig_ipv6_local, -1, true);
-                    /* TODO: find out where addresses are "unlearned"!! */
-                    msg(D_MULTI_LOW, "MULTI: primary virtual IPv6 for %s: %s",
-                        multi_instance_string(mi, false, &gc),
-                        print_in6_addr(mi->context.c2.push_ifconfig_ipv6_local, 0, &gc));
-                }
-
-                /* add routes locally, pointing to new client, if
-                 * --iroute options have been specified */
-                multi_add_iroutes(m, mi);
-
-                /*
-                 * iroutes represent subnets which are "owned" by a particular
-                 * client.  Therefore, do not actually push a route to a client
-                 * if it matches one of the client's iroutes.
-                 */
-                remove_iroutes_from_push_route_list(&mi->context.options);
-            }
-            else if (mi->context.options.iroutes)
-            {
-                msg(D_MULTI_ERRORS, "MULTI: --iroute options rejected for %s -- iroute only works with tun-style tunnels",
-                    multi_instance_string(mi, false, &gc));
-            }
+            remove_iroutes_from_push_route_list(&mi->context.options);
+        }
+        else if (mi->context.options.iroutes)
+        {
+            msg(D_MULTI_ERRORS, "MULTI: --iroute options rejected for %s -- iroute only works with tun-style tunnels",
+                multi_instance_string(mi, false, &gc));
+        }
 
-            /* set our client's VPN endpoint for status reporting purposes */
-            mi->reporting_addr = mi->context.c2.push_ifconfig_local;
-            mi->reporting_addr_ipv6 = mi->context.c2.push_ifconfig_ipv6_local;
+        /* set our client's VPN endpoint for status reporting purposes */
+        mi->reporting_addr = mi->context.c2.push_ifconfig_local;
+        mi->reporting_addr_ipv6 = mi->context.c2.push_ifconfig_ipv6_local;
 
-            /* set context-level authentication flag */
-            mi->context.c2.context_auth = CAS_SUCCEEDED;
+        /* set context-level authentication flag */
+        mi->context.c2.context_auth = CAS_SUCCEEDED;
 
 #ifdef ENABLE_ASYNC_PUSH
-            /* authentication complete, send push reply */
-            if (mi->context.c2.push_request_received)
-            {
-                process_incoming_push_request(&mi->context);
-            }
-#endif
-        }
-        else
+        /* authentication complete, send push reply */
+        if (mi->context.c2.push_request_received)
         {
-            /* set context-level authentication flag */
-            mi->context.c2.context_auth = cc_succeeded_count ? CAS_PARTIAL : CAS_FAILED;
+            process_incoming_push_request(&mi->context);
         }
+#endif
+    }
+    else
+    {
+        /* set context-level authentication flag */
+        mi->context.c2.context_auth = cc_succeeded_count ? CAS_PARTIAL : CAS_FAILED;
+    }
 
-        /* increment number of current authenticated clients */
-        ++m->n_clients;
-        update_mstat_n_clients(m->n_clients);
-        --mi->n_clients_delta;
+    /* increment number of current authenticated clients */
+    ++m->n_clients;
+    update_mstat_n_clients(m->n_clients);
+    --mi->n_clients_delta;
 
 #ifdef MANAGEMENT_DEF_AUTH
-        if (management)
-        {
-            management_connection_established(management, &mi->context.c2.mda_context, mi->context.c2.es);
-        }
+    if (management)
+    {
+        management_connection_established(management, &mi->context.c2.mda_context, mi->context.c2.es);
+    }
 #endif
 
-        gc_free(&gc);
-    }
+    gc_free(&gc);
 }
 
 #ifdef ENABLE_ASYNC_PUSH
Signature · 1 line
2.26.2
Acked-by on v1 1/3
#4 lore raw

Re: [Openvpn-devel] [PATCH 1/3] Simplify multi_connection_established.

Hi,

Quoted 7 lines · Arne Schwabe

Instead of having the whole function as

    if (x) { func }

do

if (!x) func

I guess this commit message needs some love? You probably meant:

Instead of..

	if (x) { func }

do

	if (!x) return;
	func

At least, this is what the patch does :-)

Quoted 5 lines

Due to the whitespace changes in the function body this patch looks very strange. Ignoring whitespace makes the diff look sane.

I am super-pro this style.

It makes the whole function easier to read and saves a lot of horizontal spaces by killing one level of indentation.

Reviewing this patch with "git show -w" makes it super obvious.

No functional change included, the patch is just reverting the top condition and returning right away.

Stared at the code and compile-tested. (but please fix the commit message before merging)

Signature · 1 line
Antonio Quartulli
#5 lore raw

[Openvpn-devel] [PATCH applied] Re: Simplify multi_connection_established.

In reply to Arne Schwabe

Your patch has been applied to the master branch.

Commit message amended as ordered by the whitespace dragon.

commit 05ffefcca997708e1f146bed6f5dba9b9f5b1e90

Author: Arne Schwabe
Date:   Tue Jul 7 14:16:13 2020 +0200
     Simplify multi_connection_established.

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Antonio Quartulli <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg20231.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#6 lore raw

PATCH 2/3 Cleanup: Remove unused code of old poor man's NCP.

In reply to Arne Schwabe

Ever since the NCPv2 the ncp_get_best_cipher uses the global options->ncp_enabled option and ignore the tls_session->ncp_enabled option.

The server side's poor man's NCP is implemented as seeing the list of supported ciphers from the peer as just one cipher so this special handling for poor man's NCP of the older NCP here is not needed anymore.

Theoretically we can now get rid of tls_session->ncp_enabled but doing so requires more refactoring since options is not available in the methods that still use it. And when we remove ncp-disable the variable will be removed anyway.

Also document the remaining usage of tls_poor_mans_ncp better.

---
 src/openvpn/init.c |  2 ++
 src/openvpn/ssl.c  | 15 +--------------
 2 files changed, 3 insertions(+), 14 deletions(-)
src/openvpn/init.c +2 -0
index 91b919d5..e9c01629 100644
@@ -2376,6 +2376,8 @@ do_deferred_options(struct context *c, const unsigned int found)
         }
         else if (c->options.ncp_enabled)
         {
+            /* If the server did not push a --cipher, we will switch to the
+             * remote cipher if it is in our ncp-ciphers list */
             tls_poor_mans_ncp(&c->options, c->c2.tls_multi->remote_ciphername);
         }
         struct frame *frame_fragment = NULL;
src/openvpn/ssl.c +1 -14
index 9df7552d..71565dd3 100644
@@ -2463,8 +2463,7 @@ key_method_2_write(struct buffer *buf, struct tls_session *session)
      * generation is postponed until after the pull/push, so we can process pushed
      * cipher directives.
      */
-    if (session->opt->server && !(session->opt->ncp_enabled
-                                  && session->opt->mode == MODE_SERVER && ks->key_id <= 0))
+    if (session->opt->server && !(session->opt->mode == MODE_SERVER && ks->key_id <= 0))
     {
         if (ks->authenticated != KS_AUTH_FALSE)
         {
@@ -2616,18 +2615,6 @@ key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_sessio
     multi->remote_ciphername =
         options_string_extract_option(options, "cipher", NULL);
 
-    if (!tls_peer_supports_ncp(multi->peer_info))
-    {
-        /* Peer does not support NCP, but leave NCP enabled if the local and
-         * remote cipher do not match to attempt 'poor-man's NCP'.
-         */
-        if (multi->remote_ciphername == NULL
-            || 0 == strcmp(multi->remote_ciphername, multi->opt.config_ciphername))
-        {
-            session->opt->ncp_enabled = false;
-        }
-    }
-
     if (tls_session_user_pass_enabled(session))
     {
         /* Perform username/password authentication */
Signature · 1 line
2.26.2
#7 lore raw

Re: [Openvpn-devel] [PATCH 2/3] Cleanup: Remove unused code of old poor man's NCP.

Hi,

Quoted 3 lines · Arne Schwabe

Ever since the NCPv2 the ncp_get_best_cipher uses the global options->ncp_enabled option and ignore the tls_session->ncp_enabled option.

For the record, this breaks "poor man's NCP" for big packets - tested
with 2.3 client and 2.4 with "--ncp-disable". Session is negotiated
fine, key material is generated perfectly fine, both sides agree on ciphers, but if I do the "ping 3000 byte test" I get this on the server:

13:00 <@cron2> Jul 8 12:59:19 gentoo tun-udp-p2mp[30281]: cron2-freebsd-tc-amd64-23/2001:608:0:814::f000:21 TCP/UDP packet too large on write to [AF_INET6]2001:608:0:814::f000:21:35389 (tried=1544,max=1542)

so it seems to get confused about frame size values.

No --mtu-disc involved, no --anything-mtu configured on the server (= all on defaults).

I do remember that this is scary stuff all intertwined...

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#8 lore raw

Re: [Openvpn-devel] [PATCH 2/3] Cleanup: Remove unused code of old poor man's NCP.

Am 08.07.20 um 13:15 schrieb Gert Doering:

Quoted 13 lines

Hi,

Quoted 3 lines · Arne Schwabe

Ever since the NCPv2 the ncp_get_best_cipher uses the global options->ncp_enabled option and ignore the tls_session->ncp_enabled option.

For the record, this breaks "poor man's NCP" for big packets - tested
with 2.3 client and 2.4 with "--ncp-disable". Session is negotiated
fine, key material is generated perfectly fine, both sides agree on ciphers, but if I do the "ping 3000 byte test" I get this on the server:

Quoted 8 lines

13:00 <@cron2> Jul 8 12:59:19 gentoo tun-udp-p2mp[30281]: cron2-freebsd-tc-amd64-23/2001:608:0:814::f000:21 TCP/UDP packet too large on write to [AF_INET6]2001:608:0:814::f000:21:35389 (tried=1544,max=1542)

so it seems to get confused about frame size values.

No --mtu-disc involved, no --anything-mtu configured on the server (= all on defaults).

I do remember that this is scary stuff all intertwined...

Looks like our frame calculation for NCP is somewhat broken and this change just exposed this bug better. This "fix" might work:

src/openvpn/ssl.c +0 -0
@@ -1986,6 +1986,12 @@ tls_session_update_crypto_params(struct

tls_session *session,

             options->keysize = 0;
         }
     }

+ else
+ {
+ /* Very hacky workaround and quick fix for our calculation
+ * not correct to avoid a regression */
+ return tls_session_generate_data_channel_keys(session);
+ }

     init_key_type(&session->opt->key_type, options->ciphername,
                   options->authname, options->keysize, true, true);
#9 lore raw

Re: [Openvpn-devel] [PATCH 2/3] Cleanup: Remove unused code of old poor man's NCP.

Hi,

Review tls_session_update_crypto_params(struct · line 1995

Quoted 12 lines · Arne Schwabe

+++ b/src/openvpn/ssl.c

(quoted diff) +6 -0
@@ -1986,6 +1986,12 @@ tls_session_update_crypto_params(struct
 tls_session *session,
             options->keysize = 0;
         }
     }
+    else
+    {
+      /* Very hacky workaround and quick fix for our calculation
+       * not correct to avoid a regression */
+        return tls_session_generate_data_channel_keys(session);
+    }

Just for the record: that nasty hack made the server happy again.

start client jobs...
23...
Test sets succeeded: 1 1a 1b 1d 2 2a 2b 2c 2d 3 4 5 6 8 8a 9.
Test sets failed: none.
24...
Test sets succeeded: 1 1a 1b 1c 1d 1e 2 2a 2b 2c 2d 2e 3 4 4a 5 6 8 8a 9. Test sets failed: none.
master...
Test sets succeeded: 1 1a 1b 1c 1d 1e 2 2a 2b 2c 2d 2e 3 4 5 6 7 7a 8 8a 9 2f 4b. Test sets failed: none.

So we decided to go "with the hack for now" and clean up the mine field arounding frame size stuff afterwards.

Patch set incoming tomorrow.

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...

A message that is not in the archive (sent off-list or not yet received): [email protected]...

#11 lore raw

Re: [Openvpn-devel] [PATCH 2/3] Cleanup: Remove unused code of old poor man's NCP.

Am 08.07.20 um 12:10 schrieb Steffan Karger:

Quoted 6 lines

Hi,

As discusses in #openvpn-devel on IRC, this patch breaks interop with clients that don't pull, but that will be restored in a follow-up refactoring (before 2.5 rc1). I can live with that, but I think this should be mentioned in the commit message.

I can fix that by reordering the commits but I will that this moves generation of keys for this corner case.

Arne

#12 lore raw

PATCH 3/3 Make key_state->authenticated more state machine like

In reply to Arne Schwabe

This order the states from unauthenticated to authenticated and also changes the comparison for KS_AUTH_FALSE from != to >

Also remove a now obsolete comment and two obsolete ifdefs. While keeping the ifdef in ssl_verify would save a few bytes of code, this is too minor to justify keeping the ifdef

---
 src/openvpn/ssl.c        |  6 +++---
 src/openvpn/ssl_common.h |  7 ++-----
 src/openvpn/ssl_verify.c | 15 ++++-----------
 3 files changed, 9 insertions(+), 19 deletions(-)
src/openvpn/ssl.c +3 -3
index 71565dd3..c73b51c3 100644
@@ -2465,7 +2465,7 @@ key_method_2_write(struct buffer *buf, struct tls_session *session)
      */
     if (session->opt->server && !(session->opt->mode == MODE_SERVER && ks->key_id <= 0))
     {
-        if (ks->authenticated != KS_AUTH_FALSE)
+        if (ks->authenticated > KS_AUTH_FALSE)
         {
             if (!tls_session_generate_data_channel_keys(session))
             {
@@ -2646,7 +2646,7 @@ key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_sessio
     secure_memzero(up, sizeof(*up));
 
     /* Perform final authentication checks */
-    if (ks->authenticated != KS_AUTH_FALSE)
+    if (ks->authenticated > KS_AUTH_FALSE)
     {
         verify_final_auth_checks(multi, session);
     }
@@ -2671,7 +2671,7 @@ key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_sessio
      * Call OPENVPN_PLUGIN_TLS_FINAL plugin if defined, for final
      * veto opportunity over authentication decision.
      */
-    if ((ks->authenticated != KS_AUTH_FALSE)
+    if ((ks->authenticated > KS_AUTH_FALSE)
         && plugin_defined(session->opt->plugins, OPENVPN_PLUGIN_TLS_FINAL))
     {
         key_state_export_keying_material(&ks->ks_ssl, session);
src/openvpn/ssl_common.h +2 -5
index fdf589b5..7d841ffb 100644
@@ -129,8 +129,8 @@ struct key_source2 {
 
 enum ks_auth_state {
   KS_AUTH_FALSE,
-  KS_AUTH_TRUE,
-  KS_AUTH_DEFERRED
+  KS_AUTH_DEFERRED,
+  KS_AUTH_TRUE
 };
 
 /**
@@ -194,8 +194,6 @@ struct key_state
     enum ks_auth_state authenticated;
     time_t auth_deferred_expire;
 
-#ifdef ENABLE_DEF_AUTH
-    /* If auth_deferred is true, authentication is being deferred */
 #ifdef MANAGEMENT_DEF_AUTH
     unsigned int mda_key_id;
     unsigned int mda_status;
@@ -205,7 +203,6 @@ struct key_state
     time_t acf_last_mod;
     char *auth_control_file;
 #endif
-#endif
 };
 
 /** Control channel wrapping (--tls-auth/--tls-crypt) context */
src/openvpn/ssl_verify.c +4 -11
index e28f1f3a..6996d430 100644
@@ -950,7 +950,7 @@ tls_authentication_status(struct tls_multi *multi, const int latency)
             if (DECRYPT_KEY_ENABLED(multi, ks))
             {
                 active = true;
-                if (ks->authenticated != KS_AUTH_FALSE)
+                if (ks->authenticated > KS_AUTH_FALSE)
                 {
 #ifdef ENABLE_DEF_AUTH
                     unsigned int s1 = ACF_DISABLED;
@@ -1414,17 +1414,10 @@ verify_user_pass(struct user_pass *up, struct tls_multi *multi,
              */
             send_push_reply_auth_token(multi);
         }
-#ifdef ENABLE_DEF_AUTH
         msg(D_HANDSHAKE, "TLS: Username/Password authentication %s for username '%s' %s",
             (ks->authenticated == KS_AUTH_DEFERRED) ? "deferred" : "succeeded",
             up->username,
             (session->opt->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME) ? "[CN SET]" : "");
-#else
-        msg(D_HANDSHAKE, "TLS: Username/Password authentication %s for username '%s' %s",
-            "succeeded",
-            up->username,
-            (session->opt->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME) ? "[CN SET]" : "");
-#endif
     }
     else
     {
@@ -1445,7 +1438,7 @@ verify_final_auth_checks(struct tls_multi *multi, struct tls_session *session)
     }
 
     /* Don't allow the CN to change once it's been locked */
-    if (ks->authenticated != KS_AUTH_FALSE && multi->locked_cn)
+    if (ks->authenticated > KS_AUTH_FALSE && multi->locked_cn)
     {
         const char *cn = session->common_name;
         if (cn && strcmp(cn, multi->locked_cn))
@@ -1461,7 +1454,7 @@ verify_final_auth_checks(struct tls_multi *multi, struct tls_session *session)
     }
 
     /* Don't allow the cert hashes to change once they have been locked */
-    if (ks->authenticated != KS_AUTH_FALSE && multi->locked_cert_hash_set)
+    if (ks->authenticated > KS_AUTH_FALSE && multi->locked_cert_hash_set)
     {
         const struct cert_hash_set *chs = session->cert_hash_set;
         if (chs && !cert_hash_compare(chs, multi->locked_cert_hash_set))
@@ -1475,7 +1468,7 @@ verify_final_auth_checks(struct tls_multi *multi, struct tls_session *session)
     }
 
     /* verify --client-config-dir based authentication */
-    if (ks->authenticated != KS_AUTH_FALSE && session->opt->client_config_dir_exclusive)
+    if (ks->authenticated > KS_AUTH_FALSE && session->opt->client_config_dir_exclusive)
     {
         struct gc_arena gc = gc_new();
 
Signature · 1 line
2.26.2
#13 lore raw

Re: [Openvpn-devel] [PATCH 3/3] Make key_state->authenticated more state machine like

Hi,

Quoted 50 lines · Arne Schwabe

This order the states from unauthenticated to authenticated and also changes the comparison for KS_AUTH_FALSE from != to >

Also remove a now obsolete comment and two obsolete ifdefs. While keeping the ifdef in ssl_verify would save a few bytes of code, this is too minor to justify keeping the ifdef

---
 src/openvpn/ssl.c        |  6 +++---
 src/openvpn/ssl_common.h |  7 ++-----
 src/openvpn/ssl_verify.c | 15 ++++-----------
 3 files changed, 9 insertions(+), 19 deletions(-)
src/openvpn/ssl.c +3 -3
index 71565dd3..c73b51c3 100644
@@ -2465,7 +2465,7 @@ key_method_2_write(struct buffer *buf, struct tls_session *session)
      */
     if (session->opt->server && !(session->opt->mode == MODE_SERVER && ks->key_id <= 0))
     {
-        if (ks->authenticated != KS_AUTH_FALSE)
+        if (ks->authenticated > KS_AUTH_FALSE)
         {
             if (!tls_session_generate_data_channel_keys(session))
             {
@@ -2646,7 +2646,7 @@ key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_sessio
     secure_memzero(up, sizeof(*up));
 
     /* Perform final authentication checks */
-    if (ks->authenticated != KS_AUTH_FALSE)
+    if (ks->authenticated > KS_AUTH_FALSE)
     {
         verify_final_auth_checks(multi, session);
     }
@@ -2671,7 +2671,7 @@ key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_sessio
      * Call OPENVPN_PLUGIN_TLS_FINAL plugin if defined, for final
      * veto opportunity over authentication decision.
      */
-    if ((ks->authenticated != KS_AUTH_FALSE)
+    if ((ks->authenticated > KS_AUTH_FALSE)
         && plugin_defined(session->opt->plugins, OPENVPN_PLUGIN_TLS_FINAL))
     {
         key_state_export_keying_material(&ks->ks_ssl, session);
src/openvpn/ssl_common.h +0 -0
index fdf589b5..7d841ffb 100644

src/openvpn/ssl_common.h struct key_source2 { · line 131

Quoted 3 lines
src/openvpn/ssl_common.h +0 -0
@@ -129,8 +129,8 @@ struct key_source2 {
 
 enum ks_auth_state {
   KS_AUTH_FALSE,

I suggest to add comments here describing how states work and how new states should be added.

I.e. something like: "any state before or equal to KS_AUTH_FALSE is considered unauthorized". Not sure the terminology is right, but something like this would help introducing new states, like Steffan reported before.

Maybe he has additional comments too.

Regards,

Quoted 83 lines
src/openvpn/ssl_common.h +2 -5
-  KS_AUTH_TRUE,
-  KS_AUTH_DEFERRED
+  KS_AUTH_DEFERRED,
+  KS_AUTH_TRUE
 };
 
 /**
@@ -194,8 +194,6 @@ struct key_state
     enum ks_auth_state authenticated;
     time_t auth_deferred_expire;
 
-#ifdef ENABLE_DEF_AUTH
-    /* If auth_deferred is true, authentication is being deferred */
 #ifdef MANAGEMENT_DEF_AUTH
     unsigned int mda_key_id;
     unsigned int mda_status;
@@ -205,7 +203,6 @@ struct key_state
     time_t acf_last_mod;
     char *auth_control_file;
 #endif
-#endif
 };
 
 /** Control channel wrapping (--tls-auth/--tls-crypt) context */
src/openvpn/ssl_verify.c +4 -11
index e28f1f3a..6996d430 100644
@@ -950,7 +950,7 @@ tls_authentication_status(struct tls_multi *multi, const int latency)
             if (DECRYPT_KEY_ENABLED(multi, ks))
             {
                 active = true;
-                if (ks->authenticated != KS_AUTH_FALSE)
+                if (ks->authenticated > KS_AUTH_FALSE)
                 {
 #ifdef ENABLE_DEF_AUTH
                     unsigned int s1 = ACF_DISABLED;
@@ -1414,17 +1414,10 @@ verify_user_pass(struct user_pass *up, struct tls_multi *multi,
              */
             send_push_reply_auth_token(multi);
         }
-#ifdef ENABLE_DEF_AUTH
         msg(D_HANDSHAKE, "TLS: Username/Password authentication %s for username '%s' %s",
             (ks->authenticated == KS_AUTH_DEFERRED) ? "deferred" : "succeeded",
             up->username,
             (session->opt->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME) ? "[CN SET]" : "");
-#else
-        msg(D_HANDSHAKE, "TLS: Username/Password authentication %s for username '%s' %s",
-            "succeeded",
-            up->username,
-            (session->opt->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME) ? "[CN SET]" : "");
-#endif
     }
     else
     {
@@ -1445,7 +1438,7 @@ verify_final_auth_checks(struct tls_multi *multi, struct tls_session *session)
     }
 
     /* Don't allow the CN to change once it's been locked */
-    if (ks->authenticated != KS_AUTH_FALSE && multi->locked_cn)
+    if (ks->authenticated > KS_AUTH_FALSE && multi->locked_cn)
     {
         const char *cn = session->common_name;
         if (cn && strcmp(cn, multi->locked_cn))
@@ -1461,7 +1454,7 @@ verify_final_auth_checks(struct tls_multi *multi, struct tls_session *session)
     }
 
     /* Don't allow the cert hashes to change once they have been locked */
-    if (ks->authenticated != KS_AUTH_FALSE && multi->locked_cert_hash_set)
+    if (ks->authenticated > KS_AUTH_FALSE && multi->locked_cert_hash_set)
     {
         const struct cert_hash_set *chs = session->cert_hash_set;
         if (chs && !cert_hash_compare(chs, multi->locked_cert_hash_set))
@@ -1475,7 +1468,7 @@ verify_final_auth_checks(struct tls_multi *multi, struct tls_session *session)
     }
 
     /* verify --client-config-dir based authentication */
-    if (ks->authenticated != KS_AUTH_FALSE && session->opt->client_config_dir_exclusive)
+    if (ks->authenticated > KS_AUTH_FALSE && session->opt->client_config_dir_exclusive)
     {
         struct gc_arena gc = gc_new();
 
Signature · 1 line
Antonio Quartulli
#14 lore raw

PATCH v2 1/1 Make key_state->authenticated more state machine like

In reply to Arne Schwabe

This order the states from unauthenticated to authenticated and also changes the comparison for KS_AUTH_FALSE from != to >

It also add comments and documents part using the state machine better.

Remove a now obsolete comment and two obsolete ifdefs. While keeping the ifdef in ssl_verify would save a few bytes of code, this is too minor to justify keeping the ifdef

---
 src/openvpn/multi.c      | 12 +++++++++---
 src/openvpn/ssl.c        |  7 ++++---
 src/openvpn/ssl_common.h | 14 ++++++++------
 src/openvpn/ssl_verify.c | 18 +++++++-----------
 4 files changed, 28 insertions(+), 23 deletions(-)
src/openvpn/multi.c +9 -3
index f1ced9b7..f1332c8d 100644
@@ -2352,12 +2352,12 @@ multi_process_post(struct multi_context *m, struct multi_instance *mi, const uns
     if (!IS_SIG(&mi->context) && ((flags & MPP_PRE_SELECT) || ((flags & MPP_CONDITIONAL_PRE_SELECT) && !ANY_OUT(&mi->context))))
     {
 #if defined(ENABLE_ASYNC_PUSH) && defined(ENABLE_DEF_AUTH)
-        bool was_authenticated = false;
+        bool was_unauthenticated = true;
         struct key_state *ks = NULL;
         if (mi->context.c2.tls_multi)
         {
             ks = &mi->context.c2.tls_multi->session[TM_ACTIVE].key[KS_PRIMARY];
-            was_authenticated = ks->authenticated;
+            was_unauthenticated = (ks->authenticated == KS_AUTH_FALSE);
         }
 #endif
 
@@ -2366,7 +2366,13 @@ multi_process_post(struct multi_context *m, struct multi_instance *mi, const uns
         pre_select(&mi->context);
 
 #if defined(ENABLE_ASYNC_PUSH) && defined(ENABLE_DEF_AUTH)
-        if (ks && ks->auth_control_file && ks->auth_deferred && !was_authenticated)
+        /*
+         * if we see the state transition from unauthenticated to deferred
+         * and a auth_control_file, we assume it got just added and add
+         * inotify watch to that file
+         */
+        if (ks && ks->auth_control_file && was_unauthenticated
+            && (ks->authenticated == KS_AUTH_DEFERRED))
         {
             /* watch acf file */
             long watch_descriptor = inotify_add_watch(m->top.c2.inotify_fd, ks->auth_control_file, IN_CLOSE_WRITE | IN_ONESHOT);
src/openvpn/ssl.c +4 -3
index 71565dd3..94fb0c5b 100644
@@ -2465,7 +2465,7 @@ key_method_2_write(struct buffer *buf, struct tls_session *session)
      */
     if (session->opt->server && !(session->opt->mode == MODE_SERVER && ks->key_id <= 0))
     {
-        if (ks->authenticated != KS_AUTH_FALSE)
+        if (ks->authenticated > KS_AUTH_FALSE)
         {
             if (!tls_session_generate_data_channel_keys(session))
             {
@@ -2646,7 +2646,7 @@ key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_sessio
     secure_memzero(up, sizeof(*up));
 
     /* Perform final authentication checks */
-    if (ks->authenticated != KS_AUTH_FALSE)
+    if (ks->authenticated > KS_AUTH_FALSE)
     {
         verify_final_auth_checks(multi, session);
     }
@@ -2671,7 +2671,7 @@ key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_sessio
      * Call OPENVPN_PLUGIN_TLS_FINAL plugin if defined, for final
      * veto opportunity over authentication decision.
      */
-    if ((ks->authenticated != KS_AUTH_FALSE)
+    if ((ks->authenticated > KS_AUTH_FALSE)
         && plugin_defined(session->opt->plugins, OPENVPN_PLUGIN_TLS_FINAL))
     {
         key_state_export_keying_material(&ks->ks_ssl, session);
@@ -2702,6 +2702,7 @@ key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_sessio
     return true;
 
 error:
+    ks->authenticated = KS_AUTH_FALSE;
     secure_memzero(ks->key_src, sizeof(*ks->key_src));
     if (up)
     {
src/openvpn/ssl_common.h +8 -6
index fdf589b5..91e55c7a 100644
@@ -128,9 +128,14 @@ struct key_source2 {
 };
 
 enum ks_auth_state {
-  KS_AUTH_FALSE,
-  KS_AUTH_TRUE,
-  KS_AUTH_DEFERRED
+  KS_AUTH_FALSE,              /**< Key state is not authenticated  */
+  KS_AUTH_DEFERRED,           /**< Key state authentication is being deferred,
+                                * by async auth */
+  KS_AUTH_TRUE                /**< Key state is authenticated. TLS and user/pass
+                                * succeeded. This include AUTH_PENDING/OOB
+                                * authentication as those hold the
+                                * connection artifically in KS_AUTH_DEFERRED
+                                */
 };
 
 /**
@@ -194,8 +199,6 @@ struct key_state
     enum ks_auth_state authenticated;
     time_t auth_deferred_expire;
 
-#ifdef ENABLE_DEF_AUTH
-    /* If auth_deferred is true, authentication is being deferred */
 #ifdef MANAGEMENT_DEF_AUTH
     unsigned int mda_key_id;
     unsigned int mda_status;
@@ -205,7 +208,6 @@ struct key_state
     time_t acf_last_mod;
     char *auth_control_file;
 #endif
-#endif
 };
 
 /** Control channel wrapping (--tls-auth/--tls-crypt) context */
src/openvpn/ssl_verify.c +7 -11
index e28f1f3a..990fba99 100644
@@ -950,7 +950,7 @@ tls_authentication_status(struct tls_multi *multi, const int latency)
             if (DECRYPT_KEY_ENABLED(multi, ks))
             {
                 active = true;
-                if (ks->authenticated != KS_AUTH_FALSE)
+                if (ks->authenticated > KS_AUTH_FALSE)
                 {
 #ifdef ENABLE_DEF_AUTH
                     unsigned int s1 = ACF_DISABLED;
@@ -1249,6 +1249,9 @@ verify_user_pass_management(struct tls_session *session,
 
 /*
  * Main username/password verification entry point
+ *
+ * Will set session->ks[KS_PRIMARY].authenticated according to
+ * result of the username/password verifcation
  */
 void
 verify_user_pass(struct user_pass *up, struct tls_multi *multi,
@@ -1414,17 +1417,10 @@ verify_user_pass(struct user_pass *up, struct tls_multi *multi,
              */
             send_push_reply_auth_token(multi);
         }
-#ifdef ENABLE_DEF_AUTH
         msg(D_HANDSHAKE, "TLS: Username/Password authentication %s for username '%s' %s",
             (ks->authenticated == KS_AUTH_DEFERRED) ? "deferred" : "succeeded",
             up->username,
             (session->opt->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME) ? "[CN SET]" : "");
-#else
-        msg(D_HANDSHAKE, "TLS: Username/Password authentication %s for username '%s' %s",
-            "succeeded",
-            up->username,
-            (session->opt->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME) ? "[CN SET]" : "");
-#endif
     }
     else
     {
@@ -1445,7 +1441,7 @@ verify_final_auth_checks(struct tls_multi *multi, struct tls_session *session)
     }
 
     /* Don't allow the CN to change once it's been locked */
-    if (ks->authenticated != KS_AUTH_FALSE && multi->locked_cn)
+    if (ks->authenticated > KS_AUTH_FALSE && multi->locked_cn)
     {
         const char *cn = session->common_name;
         if (cn && strcmp(cn, multi->locked_cn))
@@ -1461,7 +1457,7 @@ verify_final_auth_checks(struct tls_multi *multi, struct tls_session *session)
     }
 
     /* Don't allow the cert hashes to change once they have been locked */
-    if (ks->authenticated != KS_AUTH_FALSE && multi->locked_cert_hash_set)
+    if (ks->authenticated > KS_AUTH_FALSE && multi->locked_cert_hash_set)
     {
         const struct cert_hash_set *chs = session->cert_hash_set;
         if (chs && !cert_hash_compare(chs, multi->locked_cert_hash_set))
@@ -1475,7 +1471,7 @@ verify_final_auth_checks(struct tls_multi *multi, struct tls_session *session)
     }
 
     /* verify --client-config-dir based authentication */
-    if (ks->authenticated != KS_AUTH_FALSE && session->opt->client_config_dir_exclusive)
+    if (ks->authenticated > KS_AUTH_FALSE && session->opt->client_config_dir_exclusive)
     {
         struct gc_arena gc = gc_new();
 
Signature · 1 line
2.26.2
Acked-by on v2 1/1
#15 lore raw

Re: [Openvpn-devel] [PATCH v2] Make key_state->authenticated more state machine like

Hi,

Quoted 96 lines · Arne Schwabe

This order the states from unauthenticated to authenticated and also changes the comparison for KS_AUTH_FALSE from != to >

It also add comments and documents part using the state machine better.

Remove a now obsolete comment and two obsolete ifdefs. While keeping the ifdef in ssl_verify would save a few bytes of code, this is too minor to justify keeping the ifdef

---
 src/openvpn/multi.c      | 12 +++++++++---
 src/openvpn/ssl.c        |  7 ++++---
 src/openvpn/ssl_common.h | 14 ++++++++------
 src/openvpn/ssl_verify.c | 18 +++++++-----------
 4 files changed, 28 insertions(+), 23 deletions(-)
src/openvpn/multi.c +9 -3
index f1ced9b7..f1332c8d 100644
@@ -2352,12 +2352,12 @@ multi_process_post(struct multi_context *m, struct multi_instance *mi, const uns
     if (!IS_SIG(&mi->context) && ((flags & MPP_PRE_SELECT) || ((flags & MPP_CONDITIONAL_PRE_SELECT) && !ANY_OUT(&mi->context))))
     {
 #if defined(ENABLE_ASYNC_PUSH) && defined(ENABLE_DEF_AUTH)
-        bool was_authenticated = false;
+        bool was_unauthenticated = true;
         struct key_state *ks = NULL;
         if (mi->context.c2.tls_multi)
         {
             ks = &mi->context.c2.tls_multi->session[TM_ACTIVE].key[KS_PRIMARY];
-            was_authenticated = ks->authenticated;
+            was_unauthenticated = (ks->authenticated == KS_AUTH_FALSE);
         }
 #endif
 
@@ -2366,7 +2366,13 @@ multi_process_post(struct multi_context *m, struct multi_instance *mi, const uns
         pre_select(&mi->context);
 
 #if defined(ENABLE_ASYNC_PUSH) && defined(ENABLE_DEF_AUTH)
-        if (ks && ks->auth_control_file && ks->auth_deferred && !was_authenticated)
+        /*
+         * if we see the state transition from unauthenticated to deferred
+         * and a auth_control_file, we assume it got just added and add
+         * inotify watch to that file
+         */
+        if (ks && ks->auth_control_file && was_unauthenticated
+            && (ks->authenticated == KS_AUTH_DEFERRED))
         {
             /* watch acf file */
             long watch_descriptor = inotify_add_watch(m->top.c2.inotify_fd, ks->auth_control_file, IN_CLOSE_WRITE | IN_ONESHOT);
src/openvpn/ssl.c +4 -3
index 71565dd3..94fb0c5b 100644
@@ -2465,7 +2465,7 @@ key_method_2_write(struct buffer *buf, struct tls_session *session)
      */
     if (session->opt->server && !(session->opt->mode == MODE_SERVER && ks->key_id <= 0))
     {
-        if (ks->authenticated != KS_AUTH_FALSE)
+        if (ks->authenticated > KS_AUTH_FALSE)
         {
             if (!tls_session_generate_data_channel_keys(session))
             {
@@ -2646,7 +2646,7 @@ key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_sessio
     secure_memzero(up, sizeof(*up));
 
     /* Perform final authentication checks */
-    if (ks->authenticated != KS_AUTH_FALSE)
+    if (ks->authenticated > KS_AUTH_FALSE)
     {
         verify_final_auth_checks(multi, session);
     }
@@ -2671,7 +2671,7 @@ key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_sessio
      * Call OPENVPN_PLUGIN_TLS_FINAL plugin if defined, for final
      * veto opportunity over authentication decision.
      */
-    if ((ks->authenticated != KS_AUTH_FALSE)
+    if ((ks->authenticated > KS_AUTH_FALSE)
         && plugin_defined(session->opt->plugins, OPENVPN_PLUGIN_TLS_FINAL))
     {
         key_state_export_keying_material(&ks->ks_ssl, session);
@@ -2702,6 +2702,7 @@ key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_sessio
     return true;
 
 error:
+    ks->authenticated = KS_AUTH_FALSE;
     secure_memzero(ks->key_src, sizeof(*ks->key_src));
     if (up)
     {
src/openvpn/ssl_common.h +0 -0
index fdf589b5..91e55c7a 100644

src/openvpn/ssl_common.h struct key_source2 { · line 129

Quoted 2 lines
src/openvpn/ssl_common.h +0 -0
@@ -128,9 +128,14 @@ struct key_source2 {
 };
 

I suggest adding a comment on top of this enum declaration. I'd suggest something like this:

/*
* The following enum represents the status of the key-state object
* during its life-cycle. Based on the step taken by the server code,
* the status will move forward by one (or more) values. This allows
* us to make more flexible status checks by using the ">" or "<"
* operator
*/

Quoted 93 lines
src/openvpn/ssl_common.h +8 -6
 enum ks_auth_state {
-  KS_AUTH_FALSE,
-  KS_AUTH_TRUE,
-  KS_AUTH_DEFERRED
+  KS_AUTH_FALSE,              /**< Key state is not authenticated  */
+  KS_AUTH_DEFERRED,           /**< Key state authentication is being deferred,
+                                * by async auth */
+  KS_AUTH_TRUE                /**< Key state is authenticated. TLS and user/pass
+                                * succeeded. This include AUTH_PENDING/OOB
+                                * authentication as those hold the
+                                * connection artifically in KS_AUTH_DEFERRED
+                                */
 };
 
 /**
@@ -194,8 +199,6 @@ struct key_state
     enum ks_auth_state authenticated;
     time_t auth_deferred_expire;
 
-#ifdef ENABLE_DEF_AUTH
-    /* If auth_deferred is true, authentication is being deferred */
 #ifdef MANAGEMENT_DEF_AUTH
     unsigned int mda_key_id;
     unsigned int mda_status;
@@ -205,7 +208,6 @@ struct key_state
     time_t acf_last_mod;
     char *auth_control_file;
 #endif
-#endif
 };
 
 /** Control channel wrapping (--tls-auth/--tls-crypt) context */
src/openvpn/ssl_verify.c +6 -10
index e28f1f3a..990fba99 100644
@@ -950,7 +950,7 @@ tls_authentication_status(struct tls_multi *multi, const int latency)
             if (DECRYPT_KEY_ENABLED(multi, ks))
             {
                 active = true;
-                if (ks->authenticated != KS_AUTH_FALSE)
+                if (ks->authenticated > KS_AUTH_FALSE)
                 {
 #ifdef ENABLE_DEF_AUTH
                     unsigned int s1 = ACF_DISABLED;
@@ -1249,6 +1249,9 @@ verify_user_pass_management(struct tls_session *session,
 
 /*
  * Main username/password verification entry point
+ *
+ * Will set session->ks[KS_PRIMARY].authenticated according to
+ * result of the username/password verifcation
  */
 void
 verify_user_pass(struct user_pass *up, struct tls_multi *multi,
@@ -1414,17 +1417,10 @@ verify_user_pass(struct user_pass *up, struct tls_multi *multi,
              */
             send_push_reply_auth_token(multi);
         }
-#ifdef ENABLE_DEF_AUTH
         msg(D_HANDSHAKE, "TLS: Username/Password authentication %s for username '%s' %s",
             (ks->authenticated == KS_AUTH_DEFERRED) ? "deferred" : "succeeded",
             up->username,
             (session->opt->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME) ? "[CN SET]" : "");
-#else
-        msg(D_HANDSHAKE, "TLS: Username/Password authentication %s for username '%s' %s",
-            "succeeded",
-            up->username,
-            (session->opt->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME) ? "[CN SET]" : "");
-#endif
     }
     else
     {
@@ -1445,7 +1441,7 @@ verify_final_auth_checks(struct tls_multi *multi, struct tls_session *session)
     }
 
     /* Don't allow the CN to change once it's been locked */
-    if (ks->authenticated != KS_AUTH_FALSE && multi->locked_cn)
+    if (ks->authenticated > KS_AUTH_FALSE && multi->locked_cn)
     {
         const char *cn = session->common_name;
         if (cn && strcmp(cn, multi->locked_cn))
@@ -1461,7 +1457,7 @@ verify_final_auth_checks(struct tls_multi *multi, struct tls_session *session)
     }
 
     /* Don't allow the cert hashes to change once they have been locked */
-    if (ks->authenticated != KS_AUTH_FALSE && multi->locked_cert_hash_set)
+    if (ks->authenticated > KS_AUTH_FALSE && multi->locked_cert_hash_set)
     {
         const struct cert_hash_set *chs = session->cert_hash_set;
         if (chs && !cert_hash_compare(chs, multi->locked_cert_hash_set))

src/openvpn/ssl_verify.c verify_final_auth_checks(struct tls_multi *multi, struct tls_session *session) · line 1477

Quoted 8 lines
src/openvpn/ssl_verify.c +1 -1
@@ -1475,7 +1471,7 @@ verify_final_auth_checks(struct tls_multi *multi, struct tls_session *session)
     }
 
     /* verify --client-config-dir based authentication */
-    if (ks->authenticated != KS_AUTH_FALSE && session->opt->client_config_dir_exclusive)
+    if (ks->authenticated > KS_AUTH_FALSE && session->opt->client_config_dir_exclusive)
     {
         struct gc_arena gc = gc_new();
 

The rest looks good!

I don't have a super strong opinion about that comment I proposed, but I think it can help to better understand how the state enum is used and how to modify it in the future.

I'd prefer to have it, but in any case:

Signature · 1 line
Antonio Quartulli