Skip to contentSkip to conversation

Implement exit notifcation via control channel and temporary AUTH_FAIL

PATCH Superseded Arne Schwabe 5 participants 34 messages May 20, 2022 – Sep 20, 2022

lore
Share & tools
lore
#0 lore raw

v2 cover Implement exit notifcation via control channel and temporary AUTH_FAIL

This patchset consts of three patches and one small clean up patches. The first patch deals with exit notification via control channel instead of using OCC data message if both peers support it.
This is need to avoid implementing OCC exit messages in DCO implementation. In p2p mode this is also implemented keeps the behaviour that an OCC_EXIT triggers a SIGTERM on receiving side. This is questionable but should be addressed in a different patch after a discussion.

The second patch implements a way for OpenVPN server to temporarily reject a user or send them directly to the next server.

To allow testing and using this feature without needing to use the management interface and client-deny, the third patch adds support for providing a AUTH_FAIL message from plugins and scripts.

Finally, here is my own script that I use for testing the custom AUTH_FAIL and auth-pending messages. It will change its behaviour depending on the username:
https://gist.github.com/schwabe/2d412ae9236888b398063317ed6a9be4

Patchset v2 includes the comment from Frank to patch 1-3 and patch 4 is resent to have a complete patch set again, so v1 can be ignored

Arne Schwabe (4):
Implement exit notification via control channel Cleanup receive_auth_failed and simplify method Implement AUTH_FAIL,TEMP message support
Allow scripts and plugins to set a custom AUTH_FAILED message

 doc/man-sections/client-options.rst  |   7 +-
 doc/man-sections/script-options.rst  |  36 ++++++++
 src/openvpn/Makefile.am              |   1 +
 src/openvpn/crypto.h                 |   5 ++
 src/openvpn/forward.c                |   4 +
 src/openvpn/init.c                   |   9 +-
 src/openvpn/multi.c                  |   5 ++
 src/openvpn/openvpn.vcxproj          |   2 +
 src/openvpn/openvpn.vcxproj.filters  |   3 +
 src/openvpn/options.c                |  20 +++++
 src/openvpn/options.h                |   9 +-
 src/openvpn/options_util.c           | 104 ++++++++++++++++++++++
 src/openvpn/options_util.h           |  33 +++++++
 src/openvpn/push.c                   | 127 ++++++++++++++++-----------
 src/openvpn/push.h                   |   2 +
 src/openvpn/sig.c                    |  27 +++++-
 src/openvpn/ssl.c                    |  16 +++-
 src/openvpn/ssl.h                    |   6 ++
 src/openvpn/ssl_common.h             |   1 +
 src/openvpn/ssl_ncp.c                |   5 ++
 src/openvpn/ssl_verify.c             |  74 +++++++++++++++-
 tests/unit_tests/openvpn/Makefile.am |   1 +
 tests/unit_tests/openvpn/test_misc.c |  49 +++++++++++
 23 files changed, 486 insertions(+), 60 deletions(-)
 create mode 100644 src/openvpn/options_util.c
 create mode 100644 src/openvpn/options_util.h
Signature · 1 line
2.32.0 (Apple Git-132)
#1 lore raw

PATCH v2 1/4 Implement exit notification via control channel

Current exit notification relies on data channel messages with specific prefix. Adding these to new data channel modules (DCO) adds unncessary complexity for the data for messages that from their idea belong to the control channel anyway.

This patch adds announcing support for control channel and sending/receving it. We use the simple EXIT message for this.

Patch V2: add comment about protocol-flags to be not a user visible option,
fix various grammar mistakes, remove unused argument to receive_exit_message

---
 doc/man-sections/client-options.rst |  7 ++++++-
 src/openvpn/crypto.h                |  5 +++++
 src/openvpn/forward.c               |  4 ++++
 src/openvpn/multi.c                 |  5 +++++
 src/openvpn/options.c               | 20 ++++++++++++++++++++
 src/openvpn/push.c                  | 19 +++++++++++++++++++
 src/openvpn/push.h                  |  2 ++
 src/openvpn/sig.c                   | 27 +++++++++++++++++++++++++--
 src/openvpn/ssl.c                   |  3 +++
 src/openvpn/ssl.h                   |  3 +++
 src/openvpn/ssl_ncp.c               |  5 +++++
 11 files changed, 97 insertions(+), 3 deletions(-)
doc/man-sections/client-options.rst +6 -1
index 8e0e4f18a..5a906895b 100644
@@ -220,9 +220,14 @@ configuration.
   immediately close its client instance object rather than waiting for a
   timeout.
 
+  If both server and client support sending this message using the control
+  channel, the message will be sent as control-channel message. Otherwise
+  the message is sent as data-channel message, which will be ignored by
+  data-channel offloaded peers.
+
   The **n** parameter (default :code:`1` if not present) controls the
   maximum number of attempts that the client will try to resend the exit
-  notification message.
+  notification message if messages are sent in data-channel mode.
 
   In UDP server mode, send :code:`RESTART` control channel command to
   connected clients. The ``n`` parameter (default :code:`1` if not present)
src/openvpn/crypto.h +5 -0
index 98e2c7664..5ea889081 100644
@@ -264,6 +264,11 @@ struct crypto_options
     /**< Bit-flag indicating that we do not allow clients that do
      * not support resending the wrapped client key (WKc) with the
      * third packet of the three-way handshake */
+#define CO_USE_CC_EXIT_NOTIFY       (1<<6)
+    /**< Bit-flag indicating that explicit exit notifies should be
+     * sent via the control channel instead of using an OCC message
+     */
+
     unsigned int flags;         /**< Bit-flags determining behavior of
                                  *   security operation functions. */
 };
src/openvpn/forward.c +4 -0
index 6afe152b4..4fb3a20d7 100644
@@ -241,6 +241,10 @@ check_incoming_control_channel(struct context *c)
         {
             receive_auth_pending(c, &buf);
         }
+        else if (buf_string_match_head_str(&buf, "EXIT"))
+        {
+            receive_exit_message(c);
+        }
         else
         {
             msg(D_PUSH_ERRORS, "WARNING: Received unknown control message: %s", BSTR(&buf));
src/openvpn/multi.c +5 -0
index ba2f6d581..e7c99f813 100644
@@ -1777,6 +1777,11 @@ multi_client_set_protocol_options(struct context *c)
     }
 #endif
 
+    if (proto & IV_PROTO_CC_EXIT_NOTIFY)
+    {
+        o->data_channel_crypto_flags |= CO_USE_CC_EXIT_NOTIFY;
+    }
+
     /* Select cipher if client supports Negotiable Crypto Parameters */
 
     /* if we have already created our key, we cannot *change* our own
src/openvpn/options.c +20 -0
index 9ff384d09..427d58392 100644
@@ -8326,6 +8326,8 @@ add_option(struct options *options,
     }
     else if (streq(p[0], "key-derivation") && p[1])
     {
+        /* NCP only option that is pushed by the server to enable EKM,
+         * should not be used by normal users in config files*/
         VERIFY_PERMISSION(OPT_P_NCP)
 #ifdef HAVE_EXPORT_KEYING_MATERIAL
         if (streq(p[1], "tls-ekm"))
@@ -8338,6 +8340,24 @@ add_option(struct options *options,
             msg(msglevel, "Unknown key-derivation method %s", p[1]);
         }
     }
+    else if (streq(p[0], "protocol-flags") && p[1])
+    {
+        /* NCP only option that is pushed by the server to enable protocol
+         * features that are negotiated, should not be used by normal users
+         * in config files */
+        VERIFY_PERMISSION(OPT_P_NCP)
+        for (size_t j = 1; j < MAX_PARMS && p[j] != NULL; j++)
+        {
+            if (streq(p[j], "cc-exit"))
+            {
+                options->data_channel_crypto_flags |= CO_USE_CC_EXIT_NOTIFY;
+            }
+            else
+            {
+                msg(msglevel, "Unknown protocol-flags flag: %s", p[j]);
+            }
+        }
+    }
     else if (streq(p[0], "prng") && p[1] && !p[3])
     {
         msg(M_WARN, "NOTICE: --prng option ignored (SSL library PRNG is used)");
src/openvpn/push.c +19 -0
index 70fd1c3ce..fa0def7f8 100644
@@ -176,6 +176,21 @@ server_pushed_signal(struct context *c, const struct buffer *buffer, const bool
     }
 }
 
+void
+receive_exit_message(struct context *c)
+{
+    dmsg(D_STREAM_ERRORS, "Exit message received by peer");
+    c->sig->signal_received = SIGTERM;
+    c->sig->signal_text = "remote-exit";
+#ifdef ENABLE_MANAGEMENT
+    if (management)
+    {
+        management_notify(management, "info", c->sig->signal_text, "EXIT");
+    }
+#endif
+}
+
+
 void
 server_pushed_info(struct context *c, const struct buffer *buffer,
                    const int adv)
@@ -604,6 +619,10 @@ prepare_push_reply(struct context *c, struct gc_arena *gc,
     {
         push_option_fmt(gc, push_list, M_USAGE, "key-derivation tls-ekm");
     }
+    if (o->data_channel_crypto_flags & CO_USE_CC_EXIT_NOTIFY)
+    {
+        push_option_fmt(gc, push_list, M_USAGE, "protocol-flags cc-exit");
+    }
     return true;
 }
 
src/openvpn/push.h +2 -0
index 62fad4a14..7138055a7 100644
@@ -48,6 +48,8 @@ void receive_auth_failed(struct context *c, const struct buffer *buffer);
 
 void server_pushed_signal(struct context *c, const struct buffer *buffer, const bool restart, const int adv);
 
+void receive_exit_message(struct context *c);
+
 void server_pushed_info(struct context *c, const struct buffer *buffer,
                         const int adv);
 
src/openvpn/sig.c +25 -2
index e06edd216..d6683d2d1 100644
@@ -321,20 +321,43 @@ print_status(const struct context *c, struct status_output *so)
     gc_free(&gc);
 }
 
+
+/* Small helper function to determine if we should send the exit notification
+ * via control channel */
+static inline bool
+cc_exit_notify_enabled(struct context *c)
+{
+    /* Check if we have TLS active at all */
+    if (!c->c2.tls_multi)
+    {
+        return false;
+    }
+
+    const struct key_state *ks = get_primary_key(c->c2.tls_multi);
+    return (ks->crypto_options.flags & CO_USE_CC_EXIT_NOTIFY);
+}
+
 /*
  * Handle the triggering and time-wait of explicit
  * exit notification.
  */
-
 static void
 process_explicit_exit_notification_init(struct context *c)
 {
     msg(M_INFO, "SIGTERM received, sending exit notification to peer");
     event_timeout_init(&c->c2.explicit_exit_notification_interval, 1, 0);
     reset_coarse_timers(c);
+
     signal_reset(c->sig);
     halt_non_edge_triggered_signals();
     c->c2.explicit_exit_notification_time_wait = now;
+
+    /* Check if we are in TLS mode and should send the notification via data
+     * channel */
+    if (cc_exit_notify_enabled(c))
+    {
+        send_control_channel_string(c, "EXIT", D_PUSH);
+    }
 }
 
 void
@@ -351,7 +374,7 @@ process_explicit_exit_notification_timer_wakeup(struct context *c)
             c->sig->signal_received = SIGTERM;
             c->sig->signal_text = "exit-with-notification";
         }
-        else
+        else if (!cc_exit_notify_enabled(c))
         {
             c->c2.occ_op = OCC_EXIT;
         }
src/openvpn/ssl.c +3 -0
index 61dea996d..4506b7504 100644
@@ -1940,6 +1940,9 @@ push_peer_info(struct buffer *buf, struct tls_session *session)
         /* support for P_DATA_V2 */
         int iv_proto = IV_PROTO_DATA_V2;
 
+        /* support for exit notify via control channel */
+        iv_proto |= IV_PROTO_CC_EXIT_NOTIFY;
+
         /* support for receiving push_reply before sending
          * push request, also signal that the client wants
          * to get push-reply messages without without requiring a round
src/openvpn/ssl.h +3 -0
index 0ba86d3e6..1b8b736b9 100644
@@ -93,6 +93,9 @@
  * result. */
 #define IV_PROTO_NCP_P2P         (1<<5)
 
+/** Support for explicit exit notify via control channel */
+#define IV_PROTO_CC_EXIT_NOTIFY  (1<<7)
+
 /* Default field in X509 to be username */
 #define X509_USERNAME_FIELD_DEFAULT "CN"
 
src/openvpn/ssl_ncp.c +5 -0
index 5d7e6dd38..4a083e247 100644
@@ -419,6 +419,11 @@ p2p_ncp_set_options(struct tls_multi *multi, struct tls_session *session)
         multi->peer_id = 0x76706e; /* 'v' 'p' 'n' */
     }
 
+    if (iv_proto_peer & IV_PROTO_CC_EXIT_NOTIFY)
+    {
+        session->opt->crypto_flags |= CO_USE_CC_EXIT_NOTIFY;
+    }
+
 #if defined(HAVE_EXPORT_KEYING_MATERIAL)
     if (iv_proto_peer & IV_PROTO_TLS_KEY_EXPORT)
     {
Signature · 1 line
2.32.0 (Apple Git-132)
#10 lore raw

PATCH v2 2/4 Cleanup receive_auth_failed and simplify method

In reply to Arne Schwabe

This simplifies the buffer handling in the method and adds a quick return instead of wrapping the whole method in a if (pull) block

Patch V2: remove uncessary ifdef/endif and unnecassary block

---
 src/openvpn/push.c | 99 ++++++++++++++++++++++++----------------------
 1 file changed, 51 insertions(+), 48 deletions(-)
src/openvpn/push.c +51 -48
index fa0def7f8..1c4e637e4 100644
@@ -53,64 +53,67 @@ receive_auth_failed(struct context *c, const struct buffer *buffer)
     msg(M_VERB0, "AUTH: Received control message: %s", BSTR(buffer));
     c->options.no_advance = true;
 
-    if (c->options.pull)
+    if (!c->options.pull)
     {
-        /* Before checking how to react on AUTH_FAILED, first check if the
-         * failed auth might be the result of an expired auth-token.
-         * Note that a server restart will trigger a generic AUTH_FAILED
-         * instead an AUTH_FAILED,SESSION so handle all AUTH_FAILED message
-         * identical for this scenario */
-        if (ssl_clean_auth_token())
-        {
-            c->sig->signal_received = SIGUSR1; /* SOFT-SIGUSR1 -- Auth failure error */
-            c->sig->signal_text = "auth-failure (auth-token)";
-        }
-        else
+        return;
+    }
+
+    struct buffer buf = *buffer;
+
+    /* If the AUTH_FAIL message ends with a , it is an extended message that
+     * contains further flags */
+    bool authfail_extended = buf_string_compare_advance(&buf, "AUTH_FAILED,");
+
+    /* Before checking how to react on AUTH_FAILED, first check if the
+     * failed auth might be the result of an expired auth-token.
+     * Note that a server restart will trigger a generic AUTH_FAILED
+     * instead an AUTH_FAILED,SESSION so handle all AUTH_FAILED message
+     * identical for this scenario */
+    if (ssl_clean_auth_token())
+    {
+        c->sig->signal_received = SIGUSR1;     /* SOFT-SIGUSR1 -- Auth failure error */
+        c->sig->signal_text = "auth-failure (auth-token)";
+    }
+    else
+    {
+        switch (auth_retry_get())
         {
-            switch (auth_retry_get())
-            {
-                case AR_NONE:
-                    c->sig->signal_received = SIGTERM; /* SOFT-SIGTERM -- Auth failure error */
-                    break;
+            case AR_NONE:
+                c->sig->signal_received = SIGTERM;     /* SOFT-SIGTERM -- Auth failure error */
+                break;
 
-                case AR_INTERACT:
-                    ssl_purge_auth(false);
+            case AR_INTERACT:
+                ssl_purge_auth(false);
 
-                case AR_NOINTERACT:
-                    c->sig->signal_received = SIGUSR1; /* SOFT-SIGUSR1 -- Auth failure error */
-                    break;
+            case AR_NOINTERACT:
+                c->sig->signal_received = SIGUSR1;     /* SOFT-SIGUSR1 -- Auth failure error */
+                break;
 
-                default:
-                    ASSERT(0);
-            }
-            c->sig->signal_text = "auth-failure";
+            default:
+                ASSERT(0);
         }
+        c->sig->signal_text = "auth-failure";
+    }
 #ifdef ENABLE_MANAGEMENT
-        if (management)
-        {
-            const char *reason = NULL;
-            struct buffer buf = *buffer;
-            if (buf_string_compare_advance(&buf, "AUTH_FAILED,") && BLEN(&buf))
-            {
-                reason = BSTR(&buf);
-            }
-            management_auth_failure(management, UP_TYPE_AUTH, reason);
-        }
-#endif
-        /*
-         * Save the dynamic-challenge text even when management is defined
-         */
+    if (management)
+    {
+        const char *reason = NULL;
+        if (authfail_extended && BLEN(&buf))
         {
-#ifdef ENABLE_MANAGEMENT
-            struct buffer buf = *buffer;
-            if (buf_string_match_head_str(&buf, "AUTH_FAILED,CRV1:") && BLEN(&buf))
-            {
-                buf_advance(&buf, 12); /* Length of "AUTH_FAILED," substring */
-                ssl_put_auth_challenge(BSTR(&buf));
-            }
-#endif
+            reason = BSTR(&buf);
         }
+        management_auth_failure(management, UP_TYPE_AUTH, reason);
+    }
+    /*
+     * Save the dynamic-challenge text even when management is defined
+     */
+    if (authfail_extended
+        && buf_string_match_head_str(&buf, "CRV1:") && BLEN(&buf))
+    {
+        ssl_put_auth_challenge(BSTR(&buf));
     }
+#endif
+
 }
 
 /*
Signature · 1 line
2.32.0 (Apple Git-132)
#16 lore raw

PATCH v2 3/4 Implement AUTH_FAIL, TEMP message support

In reply to Arne Schwabe

This allows a server to indicate a temporary problem on the server and allows the server to indicate how to proceed (i.e. move to the next server, retry the same server, wait a certain time,...)

This adds options_utils.c/h to be able to unit test the new function.

Patch v2: Improve documentation, format man page better, comment that
protocol-flags is not a user usable option.

---
 doc/man-sections/script-options.rst  |  36 ++++++++++
 src/openvpn/Makefile.am              |   1 +
 src/openvpn/init.c                   |   9 ++-
 src/openvpn/openvpn.vcxproj          |   2 +
 src/openvpn/openvpn.vcxproj.filters  |   3 +
 src/openvpn/options.h                |   9 ++-
 src/openvpn/options_util.c           | 104 +++++++++++++++++++++++++++
 src/openvpn/options_util.h           |  33 +++++++++
 src/openvpn/push.c                   |  11 ++-
 src/openvpn/ssl.c                    |  13 ++--
 src/openvpn/ssl.h                    |   3 +
 tests/unit_tests/openvpn/Makefile.am |   1 +
 tests/unit_tests/openvpn/test_misc.c |  49 +++++++++++++
 13 files changed, 266 insertions(+), 8 deletions(-)
 create mode 100644 src/openvpn/options_util.c
 create mode 100644 src/openvpn/options_util.h
doc/man-sections/script-options.rst +36 -0
index 6be0686d7..8a58eaad0 100644
@@ -97,6 +97,42 @@ SCRIPT HOOKS
   the authentication, a :code:`1` or :code:`0` must be written to the
   file specified by the :code:`auth_control_file`.
 
+  If the file specified by :code:`auth_failed_reason` exists and has non-empty
+  content, the content of this file will be used as AUTH_FAILED message. To
+  avoid race conditions, this file should be written before
+  :code:`auth_control_file`.
+
+  This auth fail reason can be something simple like "User has been permanently
+  disabled" but there are also some special auth failed messages.
+
+  The ``TEMP`` message indicates that the authentication
+  temporarily failed and that the client should continue to retry to connect.
+  The server can optionally give a user readable message and hint the client a
+  behavior how to proceed. The keywords of the ``AUTH_FAILED,TEMP`` message
+  are comma separated keys/values and provide a hint to the client how to
+  proceed. Currently defined keywords are:
+
+  ``backoff`` :code:`s`
+        instructs the client to wait at least :code:`s` seconds before the next
+        connection attempt. If the client already uses a higher delay for
+        reconnection attempt, the delay will not be shortened.
+
+  ``advance addr``
+        Instructs the client to reconnect to the next (IP) address of the
+        current server.
+
+  ``advance remote``
+        Instructs the client to skip the remaining IP addresses of the current
+        server and instead connect to the next server specified in the
+        configuration file.
+
+  ``advance no``
+        Instructs the client to retry connecting to the same server again.
+
+  For example, the message ``TEMP[backoff 42,advance no]: No free IP addresses``
+  indicates that the VPN connection can currently not succeed and instructs
+  the client to retry in 42 seconds again.
+
   When deferred authentication is in use, the script can also request
   pending authentication by writing to the file specified by the
   :code:`auth_pending_file`. The first line must be the timeout in
src/openvpn/Makefile.am +1 -0
index 577294804..a619aac38 100644
@@ -95,6 +95,7 @@ openvpn_SOURCES = \
 	pkcs11_mbedtls.c \
 	openvpn.c openvpn.h \
 	options.c options.h \
+    options_util.c options_util.h \
 	otime.c otime.h \
 	packet_id.c packet_id.h \
 	perf.c perf.h \
src/openvpn/init.c +8 -1
index b0c62a859..b2a1e92a5 100644
@@ -483,13 +483,15 @@ next_connection_entry(struct context *c)
             /* Check if there is another resolved address to try for
              * the current connection */
             if (c->c1.link_socket_addr.current_remote
-                && c->c1.link_socket_addr.current_remote->ai_next)
+                && c->c1.link_socket_addr.current_remote->ai_next
+                && !c->options.advance_next_remote)
             {
                 c->c1.link_socket_addr.current_remote =
                     c->c1.link_socket_addr.current_remote->ai_next;
             }
             else
             {
+                c->options.advance_next_remote = false;
                 /* FIXME (schwabe) fix the persist-remote-ip option for real,
                  * this is broken probably ever since connection lists and multiple
                  * remote existed
@@ -2357,6 +2359,11 @@ socket_restart_pause(struct context *c)
             /* sec is less than 2^16; we can left shift it by up to 15 bits without overflow */
             sec = max_int(sec, 1) << min_int(backoff, 15);
         }
+        if (c->options.server_backoff_time)
+        {
+            sec = max_int(sec, c->options.server_backoff_time);
+            c->options.server_backoff_time = 0;
+        }
 
         if (sec > c->options.ce.connect_retry_seconds_max)
         {
src/openvpn/openvpn.vcxproj +2 -0
index 860ef8926..e82be2698 100644
@@ -306,6 +306,7 @@
     <ClCompile Include="occ.c" />
     <ClCompile Include="openvpn.c" />
     <ClCompile Include="options.c" />
+    <ClCompile Include="options_util.c" />
     <ClCompile Include="otime.c" />
     <ClCompile Include="packet_id.c" />
     <ClCompile Include="perf.c" />
@@ -395,6 +396,7 @@
     <ClInclude Include="occ.h" />
     <ClInclude Include="openvpn.h" />
     <ClInclude Include="options.h" />
+    <ClInclude Include="options_util.h" />
     <ClInclude Include="otime.h" />
     <ClInclude Include="packet_id.h" />
     <ClInclude Include="perf.h" />
src/openvpn/openvpn.vcxproj.filters +3 -0
index f76e59235..616b71ab2 100644
@@ -395,6 +395,9 @@
     <ClInclude Include="options.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="options_util.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
     <ClInclude Include="otime.h">
       <Filter>Header Files</Filter>
     </ClInclude>
src/openvpn/options.h +8 -1
index c2937dc37..0c1a31389 100644
@@ -272,10 +272,17 @@ struct options
     struct connection_list *connection_list;
 
     struct remote_list *remote_list;
-    /* Do not advanced the connection or remote addr list*/
+    /* Do not advance the connection or remote addr list*/
     bool no_advance;
+    /* Advance directly to the next remote, skipping remaining addresses of the
+     * current remote */
+    bool advance_next_remote;
     /* Counts the number of unsuccessful connection attempts */
     unsigned int unsuccessful_attempts;
+    /* the server can suggest a backoff time to the client, it
+     * will still be capped by the max timeout between connections
+     * (300s by default) */
+    int server_backoff_time;
 
 #if ENABLE_MANAGEMENT
     struct http_proxy_options *http_proxy_override;
src/openvpn/options_util.c new file +104 -0

105 lines not on this page · raw message

src/openvpn/options_util.h new file +33 -0
new file mode 100644
index 000000000..9785bb239
@@ -0,0 +1,33 @@
+/*
+ *  OpenVPN -- An application to securely tunnel IP networks
+ *             over a single TCP/UDP port, with support for SSL/TLS-based
+ *             session authentication and key exchange,
+ *             packet encryption, packet authentication, and
+ *             packet compression.
+ *
+ *  Copyright (C) 2002-2022 OpenVPN Inc <[email protected]...>
+ *  Copyright (C) 2010-2021 Fox Crypto B.V. <[email protected]...>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef OPTIONS_UTIL_H_
+#define OPTIONS_UTIL_H_
+
+#include "options.h"
+
+const char *
+parse_auth_failed_temp(struct options *o, const struct buffer *buf);
+
+#endif
\ No newline at end of file
src/openvpn/push.c +9 -2
index 1c4e637e4..3b3dce642 100644
@@ -38,6 +38,7 @@
 
 #include "memdbg.h"
 #include "ssl_util.h"
+#include "options_util.h"
 
 static char push_reply_cmd[] = "PUSH_REPLY";
 
@@ -51,7 +52,6 @@ void
 receive_auth_failed(struct context *c, const struct buffer *buffer)
 {
     msg(M_VERB0, "AUTH: Received control message: %s", BSTR(buffer));
-    c->options.no_advance = true;
 
     if (!c->options.pull)
     {
@@ -64,15 +64,22 @@ receive_auth_failed(struct context *c, const struct buffer *buffer)
      * contains further flags */
     bool authfail_extended = buf_string_compare_advance(&buf, "AUTH_FAILED,");
 
+    if (authfail_extended && buf_string_match_head_str(&buf, "TEMP"))
+    {
+        parse_auth_failed_temp(&c->options, &buf);
+        c->sig->signal_received = SIGUSR1;
+        c->sig->signal_text = "auth-temp-failure (server temporary reject)";
+    }
     /* Before checking how to react on AUTH_FAILED, first check if the
      * failed auth might be the result of an expired auth-token.
      * Note that a server restart will trigger a generic AUTH_FAILED
      * instead an AUTH_FAILED,SESSION so handle all AUTH_FAILED message
      * identical for this scenario */
-    if (ssl_clean_auth_token())
+    else if (ssl_clean_auth_token())
     {
         c->sig->signal_received = SIGUSR1;     /* SOFT-SIGUSR1 -- Auth failure error */
         c->sig->signal_text = "auth-failure (auth-token)";
+        c->options.no_advance = true;
     }
     else
     {
src/openvpn/ssl.c +9 -4
index 4506b7504..f11b3afb3 100644
@@ -1943,14 +1943,19 @@ push_peer_info(struct buffer *buf, struct tls_session *session)
         /* support for exit notify via control channel */
         iv_proto |= IV_PROTO_CC_EXIT_NOTIFY;
 
-        /* support for receiving push_reply before sending
-         * push request, also signal that the client wants
-         * to get push-reply messages without without requiring a round
-         * trip for a push request message*/
         if (session->opt->pull)
         {
+            /* support for receiving push_reply before sending
+             * push request, also signal that the client wants
+             * to get push-reply messages without requiring a round
+             * trip for a push request message*/
             iv_proto |= IV_PROTO_REQUEST_PUSH;
+
+            /* Support keywords in the AUTH_PENDING control message */
             iv_proto |= IV_PROTO_AUTH_PENDING_KW;
+
+            /* support for AUTH_FAIL,TEMP control message */
+            iv_proto |= IV_PROTO_AUTH_FAIL_TEMP;
         }
 
         /* support for Negotiable Crypto Parameters */
src/openvpn/ssl.h +3 -0
index 1b8b736b9..981bb3403 100644
@@ -93,6 +93,9 @@
  * result. */
 #define IV_PROTO_NCP_P2P         (1<<5)
 
+/** Support for AUTH_FAIL,TEMP messages */
+#define IV_PROTO_AUTH_FAIL_TEMP  (1<<6)
+
 /** Support for explicit exit notify via control channel */
 #define IV_PROTO_CC_EXIT_NOTIFY  (1<<7)
 
tests/unit_tests/openvpn/Makefile.am +1 -0
index 63b53a6ac..65cf9549c 100644
@@ -176,5 +176,6 @@ misc_testdriver_LDFLAGS = @TEST_LDFLAGS@
 misc_testdriver_SOURCES = test_misc.c mock_msg.c \
     mock_get_random.c \
 	$(openvpn_srcdir)/buffer.c \
+	$(openvpn_srcdir)/options_util.c \
 	$(openvpn_srcdir)/ssl_util.c \
 	$(openvpn_srcdir)/platform.c
tests/unit_tests/openvpn/test_misc.c +49 -0

63 lines not on this page · raw message

Signature · 1 line
2.32.0 (Apple Git-132)
#20 lore raw

PATCH v2 4/4 Allow scripts and plugins to set a custom AUTH_FAILED message

In reply to Arne Schwabe

This is currently only possible when using the management interface and the client-deny functionality.

---
 src/openvpn/ssl_common.h |  1 +
 src/openvpn/ssl_verify.c | 74 ++++++++++++++++++++++++++++++++++++++--
 2 files changed, 73 insertions(+), 2 deletions(-)
src/openvpn/ssl_common.h +1 -0
index cef2611b9..433563068 100644
@@ -155,6 +155,7 @@ struct auth_deferred_status
 {
     char *auth_control_file;
     char *auth_pending_file;
+    char *auth_failed_reason_file;
     unsigned int auth_control_status;
 };
 
src/openvpn/ssl_verify.c +72 -2

131 lines not on this page · raw message

Signature · 1 line
2.32.0 (Apple Git-132)
Acked-by on v2 2/4
#11 lore raw

Re: [Openvpn-devel] [PATCH v2 2/4] Cleanup receive_auth_failed and simplify method

In reply to Arne Schwabe

Best viewed with "git show -w" ;)

AFAICT this is a good cleanup without any behavioral change.

Quoted 120 lines

Arne Schwabe <[email protected]...> hat am 20.05.2022 23:32 geschrieben:
This simplifies the buffer handling in the method and adds a quick return instead of wrapping the whole method in a if (pull) block

Patch V2: remove uncessary ifdef/endif and unnecassary block

---
 src/openvpn/push.c | 99 ++++++++++++++++++++++++----------------------
 1 file changed, 51 insertions(+), 48 deletions(-)
src/openvpn/push.c +45 -48
index fa0def7f8..1c4e637e4 100644
@@ -53,64 +53,67 @@ receive_auth_failed(struct context *c, const struct buffer *buffer)
     msg(M_VERB0, "AUTH: Received control message: %s", BSTR(buffer));
     c->options.no_advance = true;
 
-    if (c->options.pull)
+    if (!c->options.pull)
     {
-        /* Before checking how to react on AUTH_FAILED, first check if the
-         * failed auth might be the result of an expired auth-token.
-         * Note that a server restart will trigger a generic AUTH_FAILED
-         * instead an AUTH_FAILED,SESSION so handle all AUTH_FAILED message
-         * identical for this scenario */
-        if (ssl_clean_auth_token())
-        {
-            c->sig->signal_received = SIGUSR1; /* SOFT-SIGUSR1 -- Auth failure error */
-            c->sig->signal_text = "auth-failure (auth-token)";
-        }
-        else
+        return;
+    }
+
+    struct buffer buf = *buffer;
+
+    /* If the AUTH_FAIL message ends with a , it is an extended message that
+     * contains further flags */
+    bool authfail_extended = buf_string_compare_advance(&buf, "AUTH_FAILED,");
+
+    /* Before checking how to react on AUTH_FAILED, first check if the
+     * failed auth might be the result of an expired auth-token.
+     * Note that a server restart will trigger a generic AUTH_FAILED
+     * instead an AUTH_FAILED,SESSION so handle all AUTH_FAILED message
+     * identical for this scenario */
+    if (ssl_clean_auth_token())
+    {
+        c->sig->signal_received = SIGUSR1;     /* SOFT-SIGUSR1 -- Auth failure error */
+        c->sig->signal_text = "auth-failure (auth-token)";
+    }
+    else
+    {
+        switch (auth_retry_get())
         {
-            switch (auth_retry_get())
-            {
-                case AR_NONE:
-                    c->sig->signal_received = SIGTERM; /* SOFT-SIGTERM -- Auth failure error */
-                    break;
+            case AR_NONE:
+                c->sig->signal_received = SIGTERM;     /* SOFT-SIGTERM -- Auth failure error */
+                break;
 
-                case AR_INTERACT:
-                    ssl_purge_auth(false);
+            case AR_INTERACT:
+                ssl_purge_auth(false);
 
-                case AR_NOINTERACT:
-                    c->sig->signal_received = SIGUSR1; /* SOFT-SIGUSR1 -- Auth failure error */
-                    break;
+            case AR_NOINTERACT:
+                c->sig->signal_received = SIGUSR1;     /* SOFT-SIGUSR1 -- Auth failure error */
+                break;
 
-                default:
-                    ASSERT(0);
-            }
-            c->sig->signal_text = "auth-failure";
+            default:
+                ASSERT(0);
         }
+        c->sig->signal_text = "auth-failure";
+    }
 #ifdef ENABLE_MANAGEMENT
-        if (management)
-        {
-            const char *reason = NULL;
-            struct buffer buf = *buffer;
-            if (buf_string_compare_advance(&buf, "AUTH_FAILED,") && BLEN(&buf))
-            {
-                reason = BSTR(&buf);
-            }
-            management_auth_failure(management, UP_TYPE_AUTH, reason);
-        }
-#endif
-        /*
-         * Save the dynamic-challenge text even when management is defined
-         */
+    if (management)
+    {
+        const char *reason = NULL;
+        if (authfail_extended && BLEN(&buf))
         {
-#ifdef ENABLE_MANAGEMENT
-            struct buffer buf = *buffer;
-            if (buf_string_match_head_str(&buf, "AUTH_FAILED,CRV1:") && BLEN(&buf))
-            {
-                buf_advance(&buf, 12); /* Length of "AUTH_FAILED," substring */
-                ssl_put_auth_challenge(BSTR(&buf));
-            }
-#endif
+            reason = BSTR(&buf);
         }
+        management_auth_failure(management, UP_TYPE_AUTH, reason);
+    }
+    /*
+     * Save the dynamic-challenge text even when management is defined
+     */

src/openvpn/push.c receive_auth_failed(struct context *c, const struct buffer *buffer) · line 119

Quoted 10 lines
src/openvpn/push.c +6 -0
+    if (authfail_extended
+        && buf_string_match_head_str(&buf, "CRV1:") && BLEN(&buf))
+    {
+        ssl_put_auth_challenge(BSTR(&buf));
     }
+#endif
+
 }
 
 /*

--
Frank Lichtenheld

#21 lore raw

Re: [Openvpn-devel] [PATCH v2 4/4] Allow scripts and plugins to set a custom AUTH_FAILED message

In reply to Arne Schwabe
Quoted 8 lines

Arne Schwabe <[email protected]...> hat am 20.05.2022 23:32 geschrieben:
This is currently only possible when using the management interface and the client-deny functionality.

---
 src/openvpn/ssl_common.h |  1 +
 src/openvpn/ssl_verify.c | 74 ++++++++++++++++++++++++++++++++++++++--
 2 files changed, 73 insertions(+), 2 deletions(-)

[...]

Quoted 4 lines
src/openvpn/ssl_verify.c +0 -0
index c01841fa9..4cf772fef 100644

[...]

Quoted 8 lines
src/openvpn/ssl_verify.c +4 -0
@@ -1184,6 +1218,20 @@ tls_authentication_status(struct tls_multi *multi)
 #endif
     if (failed_auth)
     {
+        struct gc_arena gc = gc_new();
+        const struct key_state *ks = get_primary_key(multi);
+        const char *plugin_message = key_state_check_auth_failed_message_file(&ks->plugin_auth, multi, &gc);
+        const char *script_message = key_state_check_auth_failed_message_file(&ks->script_auth, multi, &gc);

src/openvpn/ssl_verify.c tls_authentication_status(struct tls_multi *multi) · line 1234

Quoted 10 lines
src/openvpn/ssl_verify.c +10 -0
+
+        if (plugin_message)
+        {
+            auth_set_client_reason(multi, plugin_message);
+        }
+        if (script_message)
+        {
+            auth_set_client_reason(multi, script_message);
+        }
+

Isn't there a gc_free missing here?

src/openvpn/ssl_verify.c tls_authenticate_key(struct tls_multi *multi, const unsigned int mda_key_id, con · line 1301

Quoted 10 lines
src/openvpn/ssl_verify.c +3 -0
         /* We have at least one session that failed authentication. There
          * might be still another session with valid keys.
          * Although our protocol allows keeping the VPN session alive
@@ -1248,6 +1296,21 @@ tls_authenticate_key(struct tls_multi *multi, const unsigned int mda_key_id, con
  * this is the place to start.
  *************************************************************************** */
 
+/**
+ * Check if the script/plugin left a message in the auth failed message
+ * file and rely it to the user */

"relay"

Quoted 5 lines
src/openvpn/ssl_verify.c +5 -0
+static void
+check_for_client_reason(struct tls_multi *multi,
+                        struct auth_deferred_status *status)
+{
+    struct gc_arena gc = gc_new();

src/openvpn/ssl_verify.c tls_authenticate_key(struct tls_multi *multi, const unsigned int mda_key_id, con · line 1316

Quoted 10 lines
src/openvpn/ssl_verify.c +7 -0
+    const char *msg = key_state_check_auth_failed_message_file(status, multi, &gc);
+    if (msg)
+    {
+        auth_set_client_reason(multi, msg);
+    }
+    gc_free(&gc);
+}
 /*
  * Verify the user name and password using a script
  */

Regards,
--
Frank Lichtenheld

#2 lore raw

Re: [Openvpn-devel] [PATCH v2 1/4] Implement exit notification via control channel

In reply to Arne Schwabe
Quoted 25 lines · Arne Schwabe

Current exit notification relies on data channel messages with specific prefix. Adding these to new data channel modules (DCO) adds unncessary complexity for the data for messages that from their idea belong to the control channel anyway.

This patch adds announcing support for control channel and sending/receving it. We use the simple EXIT message for this.

Patch V2: add comment about protocol-flags to be not a user visible option,
fix various grammar mistakes, remove unused argument to receive_exit_message

---
  doc/man-sections/client-options.rst |  7 ++++++-
  src/openvpn/crypto.h                |  5 +++++
  src/openvpn/forward.c               |  4 ++++
  src/openvpn/multi.c                 |  5 +++++
  src/openvpn/options.c               | 20 ++++++++++++++++++++
  src/openvpn/push.c                  | 19 +++++++++++++++++++
  src/openvpn/push.h                  |  2 ++
  src/openvpn/sig.c                   | 27 +++++++++++++++++++++++++--
  src/openvpn/ssl.c                   |  3 +++
  src/openvpn/ssl.h                   |  3 +++
  src/openvpn/ssl_ncp.c               |  5 +++++
  11 files changed, 97 insertions(+), 3 deletions(-)

[...snip...]

src/openvpn/options.c add_option(struct options *options, · line 8330

Quoted 10 lines
src/openvpn/options.c +2 -0
index 9ff384d09..427d58392 100644
@@ -8326,6 +8326,8 @@ add_option(struct options *options,
      }
      else if (streq(p[0], "key-derivation") && p[1])
      {
+        /* NCP only option that is pushed by the server to enable EKM,
+         * should not be used by normal users in config files*/

This part seems unrelated.

Quoted 15 lines
src/openvpn/options.c +8 -0
          VERIFY_PERMISSION(OPT_P_NCP)
  #ifdef HAVE_EXPORT_KEYING_MATERIAL
          if (streq(p[1], "tls-ekm"))
@@ -8338,6 +8340,24 @@ add_option(struct options *options,
              msg(msglevel, "Unknown key-derivation method %s", p[1]);
          }
      }
+    else if (streq(p[0], "protocol-flags") && p[1])
+    {
+        /* NCP only option that is pushed by the server to enable protocol
+         * features that are negotiated, should not be used by normal users
+         * in config files */
+        VERIFY_PERMISSION(OPT_P_NCP)
+        for (size_t j = 1; j < MAX_PARMS && p[j] != NULL; j++)
+        {

src/openvpn/options.c add_option(struct options *options, · line 8360

Quoted 10 lines
src/openvpn/options.c +10 -0
+            if (streq(p[j], "cc-exit"))
+            {
+                options->data_channel_crypto_flags |= CO_USE_CC_EXIT_NOTIFY;
+            }
+            else
+            {
+                msg(msglevel, "Unknown protocol-flags flag: %s", p[j]);
+            }
+        }
+    }

Isn't it possible to do this by pushing IV_PROTO from the server to the client? That could be more compact than adding 22 more bytes to the PUSH_REPLY while IV_PROTO takes less "space" on the wire to indicate a feature. Plus the client already sends the IV_PROTO with the CC_EXIT_NOTIFY feature flag to the server with this patch.

The rest of the code otherwise looks reasonable with the current "option approach". The client also sends the IV_PROTO_CC_EXIT_NOTIFY flag to the server, as expected.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#17 lore raw

Re: [Openvpn-devel] [PATCH v2 3/4] Implement AUTH_FAIL, TEMP message support

In reply to Arne Schwabe
Quoted 26 lines · Arne Schwabe

This allows a server to indicate a temporary problem on the server and allows the server to indicate how to proceed (i.e. move to the next server, retry the same server, wait a certain time,...)

This adds options_utils.c/h to be able to unit test the new function.

Patch v2: Improve documentation, format man page better, comment that
protocol-flags is not a user usable option.

---
  doc/man-sections/script-options.rst  |  36 ++++++++++
  src/openvpn/Makefile.am              |   1 +
  src/openvpn/init.c                   |   9 ++-
  src/openvpn/openvpn.vcxproj          |   2 +
  src/openvpn/openvpn.vcxproj.filters  |   3 [email protected]...
  src/openvpn/options.h                |   9 ++-
  src/openvpn/options_util.c           | 104 +++++++++++++++++++++++++++
  src/openvpn/options_util.h           |  33 +++++++++
  src/openvpn/push.c                   |  11 ++-
  src/openvpn/ssl.c                    |  13 ++--
  src/openvpn/ssl.h                    |   3 +
  tests/unit_tests/openvpn/Makefile.am |   1 +
  tests/unit_tests/openvpn/test_misc.c |  49 +++++++++++++
  13 files changed, 266 insertions(+), 8 deletions(-)

create mode 100644 src/openvpn/options_util.c
create mode 100644 src/openvpn/options_util.h

[...snip...]

src/openvpn/Makefile.am openvpn_SOURCES = \ · line 98

Quoted 9 lines
src/openvpn/Makefile.am +1 -0
index 577294804..a619aac38 100644
@@ -95,6 +95,7 @@ openvpn_SOURCES = \
  	pkcs11_mbedtls.c \
  	openvpn.c openvpn.h \
  	options.c options.h \
+    options_util.c options_util.h \

Indent mismatch. Makefile.am uses tabs ... because traditional Make needed it. Since the rest of our Makefile.am files uses tabs, we continue with that for now.

[...snip...]

Quoted 6 lines
src/openvpn/options_util.c new file +0 -0
new file mode 100644
index 000000000..d8a7e2343

src/openvpn/options_util.c line 9

Quoted 9 lines
src/openvpn/options_util.c new file +9 -0
@@ -0,0 +1,104 @@
+/*
+ *  OpenVPN -- An application to securely tunnel IP networks
+ *             over a single TCP/UDP port, with support for SSL/TLS-based
+ *             session authentication and key exchange,
+ *             packet encryption, packet authentication, and
+ *             packet compression.
+ *
+ *  Copyright (C) 2002-2022 OpenVPN Inc <[email protected]...>
+ *  Copyright (C) 2010-2021 Fox Crypto B.V. <[email protected]...>
                               ^^^^^^^^^^^^^^

Does any of the code in this file come from Fox at all? If not, you could probably consider removing that last line.

[...snip...]

src/openvpn/options_util.c line 37

Quoted 3 lines
src/openvpn/options_util.c new file +3 -0
+const char *
+parse_auth_failed_temp(struct options *o, const struct buffer *buf)
+{

The code here looks nice and clean; unit tests runs fine as well.

Quoted 6 lines
src/openvpn/options_util.h new file +0 -0
new file mode 100644
index 000000000..9785bb239

src/openvpn/options_util.h line 9

Quoted 9 lines
src/openvpn/options_util.h new file +9 -0
@@ -0,0 +1,33 @@
+/*
+ *  OpenVPN -- An application to securely tunnel IP networks
+ *             over a single TCP/UDP port, with support for SSL/TLS-based
+ *             session authentication and key exchange,
+ *             packet encryption, packet authentication, and
+ *             packet compression.
+ *
+ *  Copyright (C) 2002-2022 OpenVPN Inc <[email protected]...>
+ *  Copyright (C) 2010-2021 Fox Crypto B.V. <[email protected]...>

Same copyright note as for the options_util.c.

[...snip...]

src/openvpn/ssl.h line 98

Quoted 9 lines
src/openvpn/ssl.h +3 -0
@@ -93,6 +93,9 @@
   * result. */
  #define IV_PROTO_NCP_P2P         (1<<5)
 
+/** Support for AUTH_FAIL,TEMP messages */
+#define IV_PROTO_AUTH_FAIL_TEMP  (1<<6)
+

This conflicts with IV_PROTO_DNS_OPTION which has already been merged to git master.

[...snip...]

I've not yet tested this code in a functional test; it compiles fine without warnings and unit tests runs fine. Since some minor changes are need, I just wanted to get this feedback sent before I run some more testing.

One thing I spotted, and I'm not sure if it's my Thunderbird fooling me or what it is ... there were spurious indenting "errors" here and there.
But the patch I pulled down directly from Patchwork had no such issues
at all. I'll check that more carefully on my end. One issue I know is real I've commented here already.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#3 lore raw

Re: [Openvpn-devel] [PATCH v2 1/4] Implement exit notification via control channel

In reply to David Sommerseth

Am 30.06.2022 um 22:25 schrieb David Sommerseth:

Quoted 29 lines · Arne Schwabe
Quoted 25 lines

Current exit notification relies on data channel messages with specific prefix. Adding these to new data channel modules (DCO) adds unncessary complexity for the data for messages that from their idea belong to the control channel anyway.

This patch adds announcing support for control channel and sending/receving it. We use the simple EXIT message for this.

Patch V2: add comment about protocol-flags to be not a user visible option, fix various grammar mistakes, remove unused argument to receive_exit_message
---
  doc/man-sections/client-options.rst |  7 ++++++- src/openvpn/crypto.h                |  5 +++++ src/openvpn/forward.c               |  4 ++++ src/openvpn/multi.c                 |  5 +++++ src/openvpn/options.c               | 20 ++++++++++++++++++++ src/openvpn/push.c                  | 19 +++++++++++++++++++ src/openvpn/push.h                  |  2 ++

  src/openvpn/sig.c                   | 27 +++++++++++++++++++++++++--
  src/openvpn/ssl.c                   |  3 +++
  src/openvpn/ssl.h                   |  3 +++
  src/openvpn/ssl_ncp.c               |  5 +++++
  11 files changed, 97 insertions(+), 3 deletions(-)

[...snip...]

Quoted 12 lines

src/openvpn/options.c add_option(struct options *options, · line 8330

Quoted 10 lines
src/openvpn/options.c +2 -0
index 9ff384d09..427d58392 100644
@@ -8326,6 +8326,8 @@ add_option(struct options *options,
       }
       else if (streq(p[0], "key-derivation") && p[1])
       {
+        /* NCP only option that is pushed by the server to enable EKM,
+         * should not be used by normal users in config files*/

This part seems unrelated.

Yes. But basically adding that documentation for the other push only protocol felt related and small enough to not warrant an extra patch.

Quoted 23 lines
Quoted 23 lines
src/openvpn/options.c +3 -0
           VERIFY_PERMISSION(OPT_P_NCP)
   #ifdef HAVE_EXPORT_KEYING_MATERIAL
           if (streq(p[1], "tls-ekm"))
@@ -8338,6 +8340,24 @@ add_option(struct options *options,
               msg(msglevel, "Unknown key-derivation method %s", p[1]);
           }
       }
+    else if (streq(p[0], "protocol-flags") && p[1])
+    {
+        /* NCP only option that is pushed by the server to enable 

protocol
+         * features that are negotiated, should not be used by normal users
+         * in config files */
+        VERIFY_PERMISSION(OPT_P_NCP)
+        for (size_t j = 1; j < MAX_PARMS && p[j] != NULL; j++) +        {
+            if (streq(p[j], "cc-exit"))
+            {
+                options->data_channel_crypto_flags |= CO_USE_CC_EXIT_NOTIFY;
+            }

Quoted 8 lines
Quoted 6 lines

+            else
+            {
+                msg(msglevel, "Unknown protocol-flags flag: %s", p[j]); +            }
+        }
+    }

Isn't it possible to do this by pushing IV_PROTO from the server to the client?  That could be more compact than adding 22 more bytes to the PUSH_REPLY while IV_PROTO takes less "space" on the wire to indicate a feature.  Plus the client already sends the IV_PROTO with the CC_EXIT_NOTIFY feature flag to the server with this patch.

The whole peer info field is empty and happens at a very different time before even looking at ccd/connect-script/deferred password aut etc that might influence what is pushed to a client. So pushing configuration at a completely different time that is extremely early is just adding a lot of extra complexity. We do it this way in p2p mode by comparing IV_PROTO values from two clients but that p2p mode has nothing after the initial handshake and will consider a session established after the initial handshake.

Space in push reply is not really a big concern as push replies don't have the tight limit that the packet the IV_PROTO contains has. If we wanted to have something that is more space efficient, we could change  protocol-flags cc-exit feat2 feat3 to proto-flgs 82734 like IV_PROTO. Basically if I had been a bit more forwarding looking we would now have protocol-flags ekm cc-exit instead of key-derivation ekm and protocol-flags cc-exit

Quoted 4 lines

The rest of the code otherwise looks reasonable with the current "option approach".  The client also sends the IV_PROTO_CC_EXIT_NOTIFY flag to the server, as expected.

#12 lore raw

[Openvpn-devel] [PATCH applied] Re: Cleanup receive_auth_failed and simplify method

In reply to Arne Schwabe

As Frank said, "best viewed with diff -w" :-) - the cleanup bits are also straightforward.

I do not have a good test case for this - but my usual client tests with "expect AUTH_FAILED..." all pass.

Your patch has been applied to the master branch.

commit 88823adebac31958cee83572241cff9fc775a601

Author: Arne Schwabe
Date:   Fri May 20 23:32:48 2022 +0200
     Cleanup receive_auth_failed and simplify method

     Acked-by: Frank Lichtenheld <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg24412.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#4 lore raw

Re: [Openvpn-devel] [PATCH v2 1/4] Implement exit notification via control channel

In reply to Arne Schwabe
Quoted 3 lines · On Freitag, 1. Juli 2022 00:42:55 CEST Arne Schwabe wrote:

Basically if I had been a bit more forwarding looking we would now have protocol-flags ekm cc-exit instead of key-derivation ekm and protocol-flags cc-exit

Then maybe also add support for handling ekm via --protocol-flags and deprecate/remove sending --key-derivation?

#6 lore raw

Re: [Openvpn-devel] [PATCH v2 1/4] Implement exit notification via control channel

In reply to Arne Schwabe

Patch and thus series doesn't apply anymore, in addition to eventual changes also please rebase.

doc/man-sections/client-options.rst configuration. · line 230

Quoted 9 lines · On Freitag, 20. Mai 2022 23:32:47 CEST Arne Schwabe wrote:
doc/man-sections/client-options.rst +6 -1
+  If both server and client support sending this message using the control
+  channel, the message will be sent as control-channel message. Otherwise
+  the message is sent as data-channel message, which will be ignored by
+  data-channel offloaded peers.
+
   The **n** parameter (default :code:`1` if not present) controls the
   maximum number of attempts that the client will try to resend the exit
-  notification message.
+  notification message if messages are sent in data-channel mode.

You don't need the "n" for the control channel exit notification because of the reliability layer, right?!

src/openvpn/multi.c multi_client_set_protocol_options(struct context *c) · line 1783

Quoted 4 lines
src/openvpn/multi.c +4 -0
+    if (proto & IV_PROTO_CC_EXIT_NOTIFY)
+    {
+        o->data_channel_crypto_flags |= CO_USE_CC_EXIT_NOTIFY;
+    }

The flags variable is named confusingly now. Is renaming an option?

Quoted 6 lines

static void process_explicit_exit_notification_init(struct context *c)

 {
     msg(M_INFO, "SIGTERM received, sending exit notification to peer");
     event_timeout_init(&c->c2.explicit_exit_notification_interval, 1, 0);
     reset_coarse_timers(c);

Do we need to timer event if !cc_exit_notify_enabled(c)?

Acked-by on v2 2/4
#13 lore raw

Re: [Openvpn-devel] [PATCH v2 2/4] Cleanup receive_auth_failed and simplify method

In reply to Arne Schwabe
Quoted 4 lines · On Freitag, 20. Mai 2022 23:32:48 CEST Arne Schwabe wrote:

This simplifies the buffer handling in the method and adds a quick return instead of wrapping the whole method in a if (pull) block

Patch V2: remove uncessary ifdef/endif and unnecassary block

#18 lore raw

Re: [Openvpn-devel] [PATCH v2 3/4] Implement AUTH_FAIL, TEMP message support

In reply to Arne Schwabe
Quoted 26 lines · On Freitag, 20. Mai 2022 23:32:49 CEST Arne Schwabe wrote:

This allows a server to indicate a temporary problem on the server and allows the server to indicate how to proceed (i.e. move to the next server, retry the same server, wait a certain time,...)

This adds options_utils.c/h to be able to unit test the new function.

Patch v2: Improve documentation, format man page better, comment that
protocol-flags is not a user usable option.

---
 doc/man-sections/script-options.rst  |  36 ++++++++++
 src/openvpn/Makefile.am              |   1 +
 src/openvpn/init.c                   |   9 ++-
 src/openvpn/openvpn.vcxproj          |   2 +
 src/openvpn/openvpn.vcxproj.filters  |   3 +
 src/openvpn/options.h                |   9 ++-
 src/openvpn/options_util.c           | 104 +++++++++++++++++++++++++++
 src/openvpn/options_util.h           |  33 +++++++++
 src/openvpn/push.c                   |  11 ++-
 src/openvpn/ssl.c                    |  13 ++--
 src/openvpn/ssl.h                    |   3 +
 tests/unit_tests/openvpn/Makefile.am |   1 +
 tests/unit_tests/openvpn/test_misc.c |  49 +++++++++++++
 13 files changed, 266 insertions(+), 8 deletions(-)
 create mode 100644 src/openvpn/options_util.c
 create mode 100644 src/openvpn/options_util.h

Review

Quoted 1 line
(quoted diff) +0 -0

This is more related to 4/4 and should go there for code archaeology reasons.

src/openvpn/options.h struct options · line 285

Quoted 4 lines
src/openvpn/options.h +4 -0
+    /* the server can suggest a backoff time to the client, it
+     * will still be capped by the max timeout between connections
+     * (300s by default) */
+    int server_backoff_time;

This should be (parsed as) an unsigned value. Negative backup requires too advanced physics. ;-)

src/openvpn/options_util.c line 42

Quoted 8 lines
src/openvpn/options_util.c new file +8 -0
+const char *
+parse_auth_failed_temp(struct options *o, const struct buffer *buf)
+{
+    struct gc_arena gc = gc_new();
+    char *m = string_alloc(BSTR(buf), &gc);
+    /* skip TEMP */
+    m += strlen("TEMP");
+    const char *message = BSTR(buf) + 4;

I think if we string_alloc(BSTR(buf) + 4, ...) it's prettier. We have the magic number 4 for message anyway, and it's not so magic if we keep the comment around.

Generally I wanted to comment on the alloc only for reasons of \0 terminating to options, but The code is not prettier if it is changed and performance if not the issue here, so no comment (technically).

Quoted 1 line

\ No newline at end of file

That.

Quoted 2 lines

+++ b/src/openvpn/options_util.h
\ No newline at end of file

Again

src/openvpn/push.c void · line 57

Quoted 12 lines
src/openvpn/push.c +0 -1
index 1c4e637e4..3b3dce642 100644
@@ -51,7 +52,6 @@ void
 receive_auth_failed(struct context *c, const struct buffer *buffer)
 {
     msg(M_VERB0, "AUTH: Received control message: %s", BSTR(buffer));
-    c->options.no_advance = true;
 
     if (!c->options.pull)
     {

I think we want to keep this as the default. If I read the code correctly, at the moment the default behavior is "advance addr" if none is given, which feel wrong to me, given what I have read about the feature.

#22 lore raw

Re: [Openvpn-devel] [PATCH v2 4/4] Allow scripts and plugins to set a custom AUTH_FAILED message

In reply to Arne Schwabe

What Frank said, and the nitpick about this hunk which should be removed:

Quoted 9 lines · On Freitag, 20. Mai 2022 23:32:50 CEST Arne Schwabe wrote:
(quoted diff) +0 -0
@@ -1376,6 +1440,7 @@ verify_user_pass_plugin(struct tls_session *session,

struct tls_multi *multi, /* call command */

     retval = plugin_call(session->opt->plugins,

OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY, NULL, NULL, session->opt->es);

+

     if (retval == OPENVPN_PLUGIN_FUNC_DEFERRED)
     {
         /* Check if the plugin has written the pending auth control
#14 lore raw

Re: [Openvpn-devel] [PATCH v2 2/4] Cleanup receive_auth_failed and simplify method

In reply to Heiko Hund

Hi,

Quoted 7 lines · Heiko Hund
Quoted 4 lines · On Freitag, 20. Mai 2022 23:32:48 CEST Arne Schwabe wrote:

This simplifies the buffer handling in the method and adds a quick return instead of wrapping the whole method in a if (pull) block

Patch V2: remove uncessary ifdef/endif and unnecassary block

Thanks for the extra ACK :-) - this got already merged as

commit 88823adebac31958cee83572241cff9fc775a601

Author: Arne Schwabe <[email protected]...>
Date:   Fri May 20 23:32:48 2022 +0200

Cleanup receive_auth_failed and simplify method

with an ACK from Frank.

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]...
#5 lore raw

Re: [Openvpn-devel] [PATCH v2 1/4] Implement exit notification via control channel

In reply to Heiko Hund

Am 18.08.22 um 16:38 schrieb Heiko Hund:

Quoted 8 lines · On Freitag, 1. Juli 2022 00:42:55 CEST Arne Schwabe wrote:
Quoted 3 lines

Basically if I had been a bit more forwarding looking we would now have protocol-flags ekm cc-exit instead of key-derivation ekm and protocol-flags cc-exit

Then maybe also add support for handling ekm via --protocol-flags and deprecate/remove sending --key-derivation?

Yeah, I can do that in follow up patch to add ekm as accepted in protocol-flags

Arne

#7 lore raw

Re: [Openvpn-devel] [PATCH v2 1/4] Implement exit notification via control channel

In reply to Heiko Hund

Am 18.08.22 um 16:39 schrieb Heiko Hund:

Quoted 17 lines

Patch and thus series doesn't apply anymore, in addition to eventual changes also please rebase.

doc/man-sections/client-options.rst configuration. · line 230

Quoted 9 lines · On Freitag, 20. Mai 2022 23:32:47 CEST Arne Schwabe wrote:
doc/man-sections/client-options.rst +6 -1
+  If both server and client support sending this message using the control
+  channel, the message will be sent as control-channel message. Otherwise
+  the message is sent as data-channel message, which will be ignored by
+  data-channel offloaded peers.
+
    The **n** parameter (default :code:`1` if not present) controls the
    maximum number of attempts that the client will try to resend the exit
-  notification message.
+  notification message if messages are sent in data-channel mode.

You don't need the "n" for the control channel exit notification because of the reliability layer, right?!

Quoted 6 lines

src/openvpn/multi.c multi_client_set_protocol_options(struct context *c) · line 1783

Quoted 4 lines
src/openvpn/multi.c +4 -0
+    if (proto & IV_PROTO_CC_EXIT_NOTIFY)
+    {
+        o->data_channel_crypto_flags |= CO_USE_CC_EXIT_NOTIFY;
+    }

The flags variable is named confusingly now. Is renaming an option?

Yes it is. But it is also still fitting, because it is affecting data channel to not send it via this :P

Quoted 10 lines
Quoted 7 lines
  static void
  process_explicit_exit_notification_init(struct context *c)
  {
      msg(M_INFO, "SIGTERM received, sending exit notification to peer");
      event_timeout_init(&c->c2.explicit_exit_notification_interval, 1, 0);
      reset_coarse_timers(c);

Do we need to timer event if !cc_exit_notify_enabled(c)?

Iirc yes. The timer will will trigger the dealyed exit.

Arne

#15 lore raw

Re: [Openvpn-devel] [PATCH v2 2/4] Cleanup receive_auth_failed and simplify method

In reply to Gert Doering
Quoted 9 lines · On Donnerstag, 18. August 2022 19:20:33 CEST Gert Doering wrote:
Quoted 4 lines · Heiko Hund
Quoted 1 line · On Freitag, 20. Mai 2022 23:32:48 CEST Arne Schwabe wrote:

Patch V2: remove uncessary ifdef/endif and unnecassary block

Thanks for the extra ACK :-) - this got already merged as

commit 88823adebac31958cee83572241cff9fc775a601

Hm, was still showing in patchwork.

#8 lore raw

PATCH v3 1/1 Implement exit notification via control channel

In reply to Arne Schwabe

Current exit notification relies on data channel messages with specific prefix. Adding these to new data channel modules (DCO) adds unncessary complexity for the data for messages that from their idea belong to the control channel anyway.

This patch adds announcing support for control channel and sending/receving it. We use the simple EXIT message for this.

Patch V2: add comment about protocol-flags to be not a user visible option,
fix various grammar mistakes, remove unused argument to receive_exit_message

Patch V3: rename data_channel_crypto_flags to imported_protocol_flags
add tls-ekm to protocol-flags.

---
 doc/man-sections/client-options.rst |  7 +++++-
 src/openvpn/crypto.h                |  5 +++++
 src/openvpn/forward.c               |  4 ++++
 src/openvpn/multi.c                 |  7 +++++-
 src/openvpn/options.c               | 28 +++++++++++++++++++++--
 src/openvpn/options.h               |  2 +-
 src/openvpn/push.c                  | 35 +++++++++++++++++++++++++----
 src/openvpn/push.h                  |  2 ++
 src/openvpn/sig.c                   | 30 +++++++++++++++++++++++--
 src/openvpn/ssl.c                   |  5 ++++-
 src/openvpn/ssl.h                   |  4 ++++
 src/openvpn/ssl_ncp.c               |  5 +++++
 12 files changed, 122 insertions(+), 12 deletions(-)
doc/man-sections/client-options.rst +6 -1
index 940175eaf..07651479f 100644
@@ -220,9 +220,14 @@ configuration.
   immediately close its client instance object rather than waiting for a
   timeout.
 
+  If both server and client support sending this message using the control
+  channel, the message will be sent as control-channel message. Otherwise
+  the message is sent as data-channel message, which will be ignored by
+  data-channel offloaded peers.
+
   The **n** parameter (default :code:`1` if not present) controls the
   maximum number of attempts that the client will try to resend the exit
-  notification message.
+  notification message if messages are sent in data-channel mode.
 
   In UDP server mode, send :code:`RESTART` control channel command to
   connected clients. The ``n`` parameter (default :code:`1` if not present)
src/openvpn/crypto.h +5 -0
index 98e2c7664..5ea889081 100644
@@ -264,6 +264,11 @@ struct crypto_options
     /**< Bit-flag indicating that we do not allow clients that do
      * not support resending the wrapped client key (WKc) with the
      * third packet of the three-way handshake */
+#define CO_USE_CC_EXIT_NOTIFY       (1<<6)
+    /**< Bit-flag indicating that explicit exit notifies should be
+     * sent via the control channel instead of using an OCC message
+     */
+
     unsigned int flags;         /**< Bit-flags determining behavior of
                                  *   security operation functions. */
 };
src/openvpn/forward.c +4 -0
index d70b4f52e..0b6180799 100644
@@ -260,6 +260,10 @@ check_incoming_control_channel(struct context *c)
         {
             receive_auth_pending(c, &buf);
         }
+        else if (buf_string_match_head_str(&buf, "EXIT"))
+        {
+            receive_exit_message(c);
+        }
         else
         {
             msg(D_PUSH_ERRORS, "WARNING: Received unknown control message: %s", BSTR(&buf));
src/openvpn/multi.c +6 -1
index 95414429f..6d5b43412 100644
@@ -1799,10 +1799,15 @@ multi_client_set_protocol_options(struct context *c)
 #ifdef HAVE_EXPORT_KEYING_MATERIAL
     if (proto & IV_PROTO_TLS_KEY_EXPORT)
     {
-        o->data_channel_crypto_flags |= CO_USE_TLS_KEY_MATERIAL_EXPORT;
+        o->imported_protocol_flags |= CO_USE_TLS_KEY_MATERIAL_EXPORT;
     }
 #endif
 
+    if (proto & IV_PROTO_CC_EXIT_NOTIFY)
+    {
+        o->imported_protocol_flags |= CO_USE_CC_EXIT_NOTIFY;
+    }
+
     /* Select cipher if client supports Negotiable Crypto Parameters */
 
     /* if we have already created our key, we cannot *change* our own
src/openvpn/options.c +26 -2
index 413268080..1bbbe77c0 100644
@@ -3345,7 +3345,7 @@ pre_connect_restore(struct options *o, struct gc_arena *gc)
 
     o->push_continuation = 0;
     o->push_option_types_found = 0;
-    o->data_channel_crypto_flags = 0;
+    o->imported_protocol_flags = 0;
 }
 
 static void
@@ -8497,11 +8497,13 @@ add_option(struct options *options,
     }
     else if (streq(p[0], "key-derivation") && p[1])
     {
+        /* NCP only option that is pushed by the server to enable EKM,
+         * should not be used by normal users in config files*/
         VERIFY_PERMISSION(OPT_P_NCP)
 #ifdef HAVE_EXPORT_KEYING_MATERIAL
         if (streq(p[1], "tls-ekm"))
         {
-            options->data_channel_crypto_flags |= CO_USE_TLS_KEY_MATERIAL_EXPORT;
+            options->imported_protocol_flags |= CO_USE_TLS_KEY_MATERIAL_EXPORT;
         }
         else
 #endif
@@ -8509,6 +8511,28 @@ add_option(struct options *options,
             msg(msglevel, "Unknown key-derivation method %s", p[1]);
         }
     }
+    else if (streq(p[0], "protocol-flags") && p[1])
+    {
+        /* NCP only option that is pushed by the server to enable protocol
+         * features that are negotiated, should not be used by normal users
+         * in config files */
+        VERIFY_PERMISSION(OPT_P_NCP)
+        for (size_t j = 1; j < MAX_PARMS && p[j] != NULL; j++)
+        {
+            if (streq(p[j], "cc-exit"))
+            {
+                options->imported_protocol_flags |= CO_USE_CC_EXIT_NOTIFY;
+            }
+            else if (streq(p[j], "tls-ekm"))
+            {
+                options->imported_protocol_flags |= CO_USE_TLS_KEY_MATERIAL_EXPORT;
+            }
+            else
+            {
+                msg(msglevel, "Unknown protocol-flags flag: %s", p[j]);
+            }
+        }
+    }
     else if (streq(p[0], "prng") && p[1] && !p[3])
     {
         msg(M_WARN, "NOTICE: --prng option ignored (SSL library PRNG is used)");
src/openvpn/options.h +1 -1
index bc20c29e0..a9015e121 100644
@@ -684,7 +684,7 @@ struct options
     bool allow_recursive_routing;
 
     /* data channel crypto flags set by push/pull. Reuses the CO_* crypto_flags */
-    unsigned int data_channel_crypto_flags;
+    unsigned int imported_protocol_flags;
 };
 
 #define streq(x, y) (!strcmp((x), (y)))
src/openvpn/push.c +31 -4
index d43ab0f5a..27a9e0a79 100644
@@ -179,6 +179,21 @@ server_pushed_signal(struct context *c, const struct buffer *buffer, const bool
     }
 }
 
+void
+receive_exit_message(struct context *c)
+{
+    dmsg(D_STREAM_ERRORS, "Exit message received by peer");
+    c->sig->signal_received = SIGTERM;
+    c->sig->signal_text = "remote-exit";
+#ifdef ENABLE_MANAGEMENT
+    if (management)
+    {
+        management_notify(management, "info", c->sig->signal_text, "EXIT");
+    }
+#endif
+}
+
+
 void
 server_pushed_info(struct context *c, const struct buffer *buffer,
                    const int adv)
@@ -606,10 +621,6 @@ prepare_push_reply(struct context *c, struct gc_arena *gc,
     {
         push_option_fmt(gc, push_list, M_USAGE, "cipher %s", o->ciphername);
     }
-    if (o->data_channel_crypto_flags & CO_USE_TLS_KEY_MATERIAL_EXPORT)
-    {
-        push_option_fmt(gc, push_list, M_USAGE, "key-derivation tls-ekm");
-    }
 
     /* Push our mtu to the peer if it supports pushable MTUs */
     int client_max_mtu = 0;
@@ -627,6 +638,22 @@ prepare_push_reply(struct context *c, struct gc_arena *gc,
         }
     }
 
+    if (o->imported_protocol_flags & CO_USE_CC_EXIT_NOTIFY)
+    {
+        const char *ekm = "";
+        if (o->imported_protocol_flags & CO_USE_TLS_KEY_MATERIAL_EXPORT)
+        {
+            ekm = " tls-ekm";
+        }
+        push_option_fmt(gc, push_list, M_USAGE, "protocol-flags cc-exit%s", ekm);
+    }
+    else if (o->imported_protocol_flags & CO_USE_TLS_KEY_MATERIAL_EXPORT)
+    {
+        push_option_fmt(gc, push_list, M_USAGE, "key-derivation tls-ekm");
+    }
+
+
+
     return true;
 }
 
src/openvpn/push.h +2 -0
index 62fad4a14..7138055a7 100644
@@ -48,6 +48,8 @@ void receive_auth_failed(struct context *c, const struct buffer *buffer);
 
 void server_pushed_signal(struct context *c, const struct buffer *buffer, const bool restart, const int adv);
 
+void receive_exit_message(struct context *c);
+
 void server_pushed_info(struct context *c, const struct buffer *buffer,
                         const int adv);
 
src/openvpn/sig.c +28 -2
index e06edd216..65cd25c65 100644
@@ -321,20 +321,46 @@ print_status(const struct context *c, struct status_output *so)
     gc_free(&gc);
 }
 
+
+/* Small helper function to determine if we should send the exit notification
+ * via control channel */
+static inline bool
+cc_exit_notify_enabled(struct context *c)
+{
+    /* Check if we have TLS active at all */
+    if (!c->c2.tls_multi)
+    {
+        return false;
+    }
+
+    const struct key_state *ks = get_primary_key(c->c2.tls_multi);
+    return (ks->crypto_options.flags & CO_USE_CC_EXIT_NOTIFY);
+}
+
 /*
  * Handle the triggering and time-wait of explicit
  * exit notification.
  */
-
 static void
 process_explicit_exit_notification_init(struct context *c)
 {
     msg(M_INFO, "SIGTERM received, sending exit notification to peer");
+    /* init the timeout to send the OCC_EXIT messages if cc exit is not
+     * enabled and also to exit after waiting for retries of resending of
+     * exit messages */
     event_timeout_init(&c->c2.explicit_exit_notification_interval, 1, 0);
     reset_coarse_timers(c);
+
     signal_reset(c->sig);
     halt_non_edge_triggered_signals();
     c->c2.explicit_exit_notification_time_wait = now;
+
+    /* Check if we are in TLS mode and should send the notification via data
+     * channel */
+    if (cc_exit_notify_enabled(c))
+    {
+        send_control_channel_string(c, "EXIT", D_PUSH);
+    }
 }
 
 void
@@ -351,7 +377,7 @@ process_explicit_exit_notification_timer_wakeup(struct context *c)
             c->sig->signal_received = SIGTERM;
             c->sig->signal_text = "exit-with-notification";
         }
-        else
+        else if (!cc_exit_notify_enabled(c))
         {
             c->c2.occ_op = OCC_EXIT;
         }
src/openvpn/ssl.c +4 -1
index c06ce6417..31722fbfb 100644
@@ -1719,7 +1719,7 @@ tls_session_update_crypto_params(struct tls_multi *multi,
     }
 
     /* Import crypto settings that might be set by pull/push */
-    session->opt->crypto_flags |= options->data_channel_crypto_flags;
+    session->opt->crypto_flags |= options->imported_protocol_flags;
 
     return tls_session_update_crypto_params_do_work(multi, session, options,
                                                     frame, frame_fragment, lsi);
@@ -1969,6 +1969,9 @@ push_peer_info(struct buffer *buf, struct tls_session *session)
         /* support for the --dns option */
         iv_proto |= IV_PROTO_DNS_OPTION;
 
+        /* support for exit notify via control channel */
+        iv_proto |= IV_PROTO_CC_EXIT_NOTIFY;
+
         /* support for receiving push_reply before sending
          * push request, also signal that the client wants
          * to get push-reply messages without without requiring a round
src/openvpn/ssl.h +4 -0
index 76b1b6743..12ffd44d7 100644
@@ -96,6 +96,10 @@
 /** Supports the --dns option introduced in version 2.6 */
 #define IV_PROTO_DNS_OPTION      (1<<6)
 
+/** Support for explicit exit notify via control channel
+ *  This also includes support for the protocol-flags pushed option */
+#define IV_PROTO_CC_EXIT_NOTIFY  (1<<7)
+
 /* Default field in X509 to be username */
 #define X509_USERNAME_FIELD_DEFAULT "CN"
 
src/openvpn/ssl_ncp.c +5 -0
index a58ced537..fe8491925 100644
@@ -419,6 +419,11 @@ p2p_ncp_set_options(struct tls_multi *multi, struct tls_session *session)
         multi->peer_id = 0x76706e; /* 'v' 'p' 'n' */
     }
 
+    if (iv_proto_peer & IV_PROTO_CC_EXIT_NOTIFY)
+    {
+        session->opt->crypto_flags |= CO_USE_CC_EXIT_NOTIFY;
+    }
+
 #if defined(HAVE_EXPORT_KEYING_MATERIAL)
     if (iv_proto_peer & IV_PROTO_TLS_KEY_EXPORT)
     {
Signature · 1 line
2.32.1 (Apple Git-133)
#19 lore raw

Re: [Openvpn-devel] [PATCH v2 3/4] Implement AUTH_FAIL, TEMP message support

In reply to Heiko Hund
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +0 -0

This is more related to 4/4 and should go there for code archaeology reasons.

Quoted 7 lines

src/openvpn/options.h struct options · line 285

Quoted 4 lines
src/openvpn/options.h +4 -0
+    /* the server can suggest a backoff time to the client, it
+     * will still be capped by the max timeout between connections
+     * (300s by default) */
+    int server_backoff_time;

This should be (parsed as) an unsigned value. Negative backup requires too advanced physics. ;-)

*All* other connect related settings (connect_retry_seconds, connect_retry_seconds_max, connect_timeout, ...) are int. Making this single one unsigned int means mixing integer types and having to cast
one parameter of max_int(a, b), so I would rather be consistent in having all the same type.

Quoted 5 lines
Quoted 3 lines

+++ b/src/openvpn/options_util.h
\ No newline at end of file

Again

uncrustify does not complain about that. Will add manually

Quoted 11 lines
Quoted 11 lines
src/openvpn/push.c +0 -1
index 1c4e637e4..3b3dce642 100644
@@ -51,7 +52,6 @@ void
  receive_auth_failed(struct context *c, const struct buffer *buffer)
  {
      msg(M_VERB0, "AUTH: Received control message: %s", BSTR(buffer));
-    c->options.no_advance = true;
 
Quoted 7 lines

src/openvpn/push.c void · line 57

Quoted 2 lines
src/openvpn/push.c +0 -0
      if (!c->options.pull)
      {

I think we want to keep this as the default. If I read the code correctly, at the moment the default behavior is "advance addr" if none is given, which feel wrong to me, given what I have read about the feature.

That looks like a mistake

Arne

#23 lore raw

PATCH v3 1/1 Implement AUTH_FAIL, TEMP message support

In reply to Arne Schwabe

This allows a server to indicate a temporary problem on the server and allows the server to indicate how to proceed (i.e. move to the next server, retry the same server, wait a certain time,...)

This adds options_utils.c/h to be able to unit test the new function.

Patch v2: Improve documentation, format man page better, comment that
protocol-flags is not a user usable option.

Patch v3: cleanup parse_auth_failed_temp to use a simple const string
instead of a buffer

---
 doc/man-sections/script-options.rst  |  36 ++++++++++
 src/openvpn/Makefile.am              |   1 +
 src/openvpn/init.c                   |   9 ++-
 src/openvpn/openvpn.vcxproj          |   2 +
 src/openvpn/openvpn.vcxproj.filters  |   3 +
 src/openvpn/options.h                |   9 ++-
 src/openvpn/options_util.c           | 102 +++++++++++++++++++++++++++
 src/openvpn/options_util.h           |  33 +++++++++
 src/openvpn/push.c                   |  33 +++++----
 src/openvpn/ssl.c                    |  13 ++--
 src/openvpn/ssl.h                    |   3 +
 tests/unit_tests/openvpn/Makefile.am |   1 +
 tests/unit_tests/openvpn/test_misc.c |  40 +++++++++++
 13 files changed, 267 insertions(+), 18 deletions(-)
 create mode 100644 src/openvpn/options_util.c
 create mode 100644 src/openvpn/options_util.h
doc/man-sections/script-options.rst +36 -0
index 74c6a1fc6..be718ef26 100644
@@ -102,6 +102,42 @@ SCRIPT HOOKS
   the authentication, a :code:`1` or :code:`0` must be written to the
   file specified by the :code:`auth_control_file`.
 
+  If the file specified by :code:`auth_failed_reason` exists and has non-empty
+  content, the content of this file will be used as AUTH_FAILED message. To
+  avoid race conditions, this file should be written before
+  :code:`auth_control_file`.
+
+  This auth fail reason can be something simple like "User has been permanently
+  disabled" but there are also some special auth failed messages.
+
+  The ``TEMP`` message indicates that the authentication
+  temporarily failed and that the client should continue to retry to connect.
+  The server can optionally give a user readable message and hint the client a
+  behavior how to proceed. The keywords of the ``AUTH_FAILED,TEMP`` message
+  are comma separated keys/values and provide a hint to the client how to
+  proceed. Currently defined keywords are:
+
+  ``backoff`` :code:`s`
+        instructs the client to wait at least :code:`s` seconds before the next
+        connection attempt. If the client already uses a higher delay for
+        reconnection attempt, the delay will not be shortened.
+
+  ``advance addr``
+        Instructs the client to reconnect to the next (IP) address of the
+        current server.
+
+  ``advance remote``
+        Instructs the client to skip the remaining IP addresses of the current
+        server and instead connect to the next server specified in the
+        configuration file.
+
+  ``advance no``
+        Instructs the client to retry connecting to the same server again.
+
+  For example, the message ``TEMP[backoff 42,advance no]: No free IP addresses``
+  indicates that the VPN connection can currently not succeed and instructs
+  the client to retry in 42 seconds again.
+
   When deferred authentication is in use, the script can also request
   pending authentication by writing to the file specified by the
   :code:`auth_pending_file`. The first line must be the timeout in
src/openvpn/Makefile.am +1 -0
index 5dbff4c6c..957494b10 100644
@@ -102,6 +102,7 @@ openvpn_SOURCES = \
 	pkcs11_mbedtls.c \
 	openvpn.c openvpn.h \
 	options.c options.h \
+    options_util.c options_util.h \
 	otime.c otime.h \
 	packet_id.c packet_id.h \
 	perf.c perf.h \
src/openvpn/init.c +8 -1
index 977f0f96c..f400495f0 100644
@@ -484,13 +484,15 @@ next_connection_entry(struct context *c)
             /* Check if there is another resolved address to try for
              * the current connection */
             if (c->c1.link_socket_addr.current_remote
-                && c->c1.link_socket_addr.current_remote->ai_next)
+                && c->c1.link_socket_addr.current_remote->ai_next
+                && !c->options.advance_next_remote)
             {
                 c->c1.link_socket_addr.current_remote =
                     c->c1.link_socket_addr.current_remote->ai_next;
             }
             else
             {
+                c->options.advance_next_remote = false;
                 /* FIXME (schwabe) fix the persist-remote-ip option for real,
                  * this is broken probably ever since connection lists and multiple
                  * remote existed
@@ -2528,6 +2530,11 @@ socket_restart_pause(struct context *c)
             /* sec is less than 2^16; we can left shift it by up to 15 bits without overflow */
             sec = max_int(sec, 1) << min_int(backoff, 15);
         }
+        if (c->options.server_backoff_time)
+        {
+            sec = max_int(sec, c->options.server_backoff_time);
+            c->options.server_backoff_time = 0;
+        }
 
         if (sec > c->options.ce.connect_retry_seconds_max)
         {
src/openvpn/openvpn.vcxproj +2 -0
index ccd29cd87..04dda0edb 100644
@@ -309,6 +309,7 @@
     <ClCompile Include="occ.c" />
     <ClCompile Include="openvpn.c" />
     <ClCompile Include="options.c" />
+    <ClCompile Include="options_util.c" />
     <ClCompile Include="otime.c" />
     <ClCompile Include="packet_id.c" />
     <ClCompile Include="perf.c" />
@@ -402,6 +403,7 @@
     <ClInclude Include="occ.h" />
     <ClInclude Include="openvpn.h" />
     <ClInclude Include="options.h" />
+    <ClInclude Include="options_util.h" />
     <ClInclude Include="otime.h" />
     <ClInclude Include="ovpn_dco_linux.h" />
     <ClInclude Include="ovpn_dco_win.h" />
src/openvpn/openvpn.vcxproj.filters +3 -0
index bf0ba7082..9c53c01ab 100644
@@ -416,6 +416,9 @@
     <ClInclude Include="options.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="options_util.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
     <ClInclude Include="otime.h">
       <Filter>Header Files</Filter>
     </ClInclude>
src/openvpn/options.h +8 -1
index a9015e121..9f98184fe 100644
@@ -275,10 +275,17 @@ struct options
     struct connection_list *connection_list;
 
     struct remote_list *remote_list;
-    /* Do not advanced the connection or remote addr list*/
+    /* Do not advance the connection or remote addr list*/
     bool no_advance;
+    /* Advance directly to the next remote, skipping remaining addresses of the
+     * current remote */
+    bool advance_next_remote;
     /* Counts the number of unsuccessful connection attempts */
     unsigned int unsuccessful_attempts;
+    /* the server can suggest a backoff time to the client, it
+     * will still be capped by the max timeout between connections
+     * (300s by default) */
+    int server_backoff_time;
 
 #if ENABLE_MANAGEMENT
     struct http_proxy_options *http_proxy_override;
src/openvpn/options_util.c new file +102 -0

102 lines not on this page · raw message

src/openvpn/options_util.h new file +33 -0
new file mode 100644
index 000000000..17d62047b
@@ -0,0 +1,33 @@
+/*
+ *  OpenVPN -- An application to securely tunnel IP networks
+ *             over a single TCP/UDP port, with support for SSL/TLS-based
+ *             session authentication and key exchange,
+ *             packet encryption, packet authentication, and
+ *             packet compression.
+ *
+ *  Copyright (C) 2002-2022 OpenVPN Inc <[email protected]...>
+ *  Copyright (C) 2010-2021 Fox Crypto B.V. <[email protected]...>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef OPTIONS_UTIL_H_
+#define OPTIONS_UTIL_H_
+
+#include "options.h"
+
+const char *
+parse_auth_failed_temp(struct options *o, const char *reason);
+
+#endif
src/openvpn/push.c +21 -12
index 27a9e0a79..0a66902a8 100644
@@ -38,6 +38,7 @@
 
 #include "memdbg.h"
 #include "ssl_util.h"
+#include "options_util.h"
 
 static char push_reply_cmd[] = "PUSH_REPLY";
 
@@ -58,15 +59,34 @@ receive_auth_failed(struct context *c, const struct buffer *buffer)
         return;
     }
 
+    struct buffer buf = *buffer;
+
+    /* If the AUTH_FAIL message ends with a , it is an extended message that
+     * contains further flags */
+    bool authfail_extended = buf_string_compare_advance(&buf, "AUTH_FAILED,");
+
+    const char *reason = NULL;
+    if (authfail_extended && BLEN(&buf))
+    {
+        reason = BSTR(&buf);
+    }
+
+    if (authfail_extended && buf_string_match_head_str(&buf, "TEMP"))
+    {
+        parse_auth_failed_temp(&c->options, reason);
+        c->sig->signal_received = SIGUSR1;
+        c->sig->signal_text = "auth-temp-failure (server temporary reject)";
+    }
     /* Before checking how to react on AUTH_FAILED, first check if the
      * failed auth might be the result of an expired auth-token.
      * Note that a server restart will trigger a generic AUTH_FAILED
      * instead an AUTH_FAILED,SESSION so handle all AUTH_FAILED message
      * identical for this scenario */
-    if (ssl_clean_auth_token())
+    else if (ssl_clean_auth_token())
     {
         c->sig->signal_received = SIGUSR1;     /* SOFT-SIGUSR1 -- Auth failure error */
         c->sig->signal_text = "auth-failure (auth-token)";
+        c->options.no_advance = true;
     }
     else
     {
@@ -89,19 +109,8 @@ receive_auth_failed(struct context *c, const struct buffer *buffer)
         c->sig->signal_text = "auth-failure";
     }
 #ifdef ENABLE_MANAGEMENT
-    struct buffer buf = *buffer;
-
-    /* If the AUTH_FAIL message ends with a , it is an extended message that
-     * contains further flags */
-    bool authfail_extended = buf_string_compare_advance(&buf, "AUTH_FAILED,");
-
     if (management)
     {
-        const char *reason = NULL;
-        if (authfail_extended && BLEN(&buf))
-        {
-            reason = BSTR(&buf);
-        }
         management_auth_failure(management, UP_TYPE_AUTH, reason);
     }
     /*
src/openvpn/ssl.c +9 -4
index 0dd723f30..f7c8d6f4c 100644
@@ -1972,17 +1972,22 @@ push_peer_info(struct buffer *buf, struct tls_session *session)
         /* support for exit notify via control channel */
         iv_proto |= IV_PROTO_CC_EXIT_NOTIFY;
 
-        /* support for receiving push_reply before sending
-         * push request, also signal that the client wants
-         * to get push-reply messages without without requiring a round
-         * trip for a push request message*/
         if (session->opt->pull)
         {
+            /* support for receiving push_reply before sending
+             * push request, also signal that the client wants
+             * to get push-reply messages without requiring a round
+             * trip for a push request message*/
             iv_proto |= IV_PROTO_REQUEST_PUSH;
+
+            /* Support keywords in the AUTH_PENDING control message */
             iv_proto |= IV_PROTO_AUTH_PENDING_KW;
 
             /* support for tun-mtu as part of the push message */
             buf_printf(&out, "IV_MTU=%d\n", session->opt->frame.tun_max_mtu);
+
+            /* support for AUTH_FAIL,TEMP control message */
+            iv_proto |= IV_PROTO_AUTH_FAIL_TEMP;
         }
 
         /* support for Negotiable Crypto Parameters */
src/openvpn/ssl.h +3 -0
index 12ffd44d7..8ca4c4aa8 100644
@@ -100,6 +100,9 @@
  *  This also includes support for the protocol-flags pushed option */
 #define IV_PROTO_CC_EXIT_NOTIFY  (1<<7)
 
+/** Support for AUTH_FAIL,TEMP messages */
+#define IV_PROTO_AUTH_FAIL_TEMP  (1<<8)
+
 /* Default field in X509 to be username */
 #define X509_USERNAME_FIELD_DEFAULT "CN"
 
tests/unit_tests/openvpn/Makefile.am +1 -0
index 63b53a6ac..65cf9549c 100644
@@ -176,5 +176,6 @@ misc_testdriver_LDFLAGS = @TEST_LDFLAGS@
 misc_testdriver_SOURCES = test_misc.c mock_msg.c \
     mock_get_random.c \
 	$(openvpn_srcdir)/buffer.c \
+	$(openvpn_srcdir)/options_util.c \
 	$(openvpn_srcdir)/ssl_util.c \
 	$(openvpn_srcdir)/platform.c
tests/unit_tests/openvpn/test_misc.c +40 -0
index 636fc45d6..589b0bcd2 100644
@@ -37,6 +37,7 @@
 #include <cmocka.h>
 
 #include "ssl_util.h"
+#include "options_util.h"
 
 static void
 test_compat_lzo_string(void **state)
@@ -72,8 +73,47 @@ test_compat_lzo_string(void **state)
     gc_free(&gc);
 }
 
+static void
+test_auth_fail_temp_no_flags(void **state)
+{
+    struct options o;
+
+    const char *teststr = "TEMP:There are no flags here [really not]";
+
+    const char *msg = parse_auth_failed_temp(&o, teststr);
+    assert_string_equal(msg, "There are no flags here [really not]");
+}
+
+static void
+test_auth_fail_temp_flags(void **state)
+{
+    struct options o;
+
+    const char *teststr = "TEMP[backoff 42,advance no]";
+
+    const char *msg = parse_auth_failed_temp(&o, teststr);
+    assert_string_equal(msg, "");
+    assert_int_equal(o.server_backoff_time, 42);
+    assert_int_equal(o.no_advance, true);
+}
+
+static void
+test_auth_fail_temp_flags_msg(void **state)
+{
+    struct options o;
+
+    const char *teststr = "TEMP[advance remote,backoff 77]:go round and round";
+
+    const char *msg = parse_auth_failed_temp(&o, teststr);
+    assert_string_equal(msg, "go round and round");
+    assert_int_equal(o.server_backoff_time, 77);
+}
+
 const struct CMUnitTest misc_tests[] = {
     cmocka_unit_test(test_compat_lzo_string),
+    cmocka_unit_test(test_auth_fail_temp_no_flags),
+    cmocka_unit_test(test_auth_fail_temp_flags),
+    cmocka_unit_test(test_auth_fail_temp_flags_msg),
 };
 
 int
Signature · 1 line
2.32.1 (Apple Git-133)
#25 lore raw

PATCH v3 4/4 Allow scripts and plugins to set a custom AUTH_FAILED message

In reply to Arne Schwabe

This is currently only possible when using the management interface and the client-deny functionality.

Patch v3: add missing gc_free

---
 src/openvpn/ssl_common.h |  1 +
 src/openvpn/ssl_verify.c | 74 ++++++++++++++++++++++++++++++++++++++--
 2 files changed, 73 insertions(+), 2 deletions(-)
src/openvpn/ssl_common.h +1 -0
index bf3ac67a5..f1cade2ef 100644
@@ -155,6 +155,7 @@ struct auth_deferred_status
 {
     char *auth_control_file;
     char *auth_pending_file;
+    char *auth_failed_reason_file;
     unsigned int auth_control_status;
 };
 
src/openvpn/ssl_verify.c +72 -2

131 lines not on this page · raw message

Signature · 1 line
2.32.1 (Apple Git-133)
Acked-by on v3 1/1
#9 lore raw

Re: [Openvpn-devel] [PATCH v3] Implement exit notification via control channel

In reply to Arne Schwabe
Quoted 8 lines · On Freitag, 19. August 2022 14:38:53 CEST Arne Schwabe wrote:

Current exit notification relies on data channel messages with specific prefix. Adding these to new data channel modules (DCO) adds unncessary complexity for the data for messages that from their idea belong to the control channel anyway.

This patch adds announcing support for control channel and sending/receving it. We use the simple EXIT message for this.

Quoted 6 lines

Patch V2: add comment about protocol-flags to be not a user visible option,
fix various grammar mistakes, remove unused argument to receive_exit_message

Patch V3: rename data_channel_crypto_flags to imported_protocol_flags
add tls-ekm to protocol-flags.

Hunks #2 and #3 in push.c do not apply to master anymore, thus some rebase action is needed. Besides that:

Acked-by on v3 4/4
#26 lore raw

Re: [Openvpn-devel] [PATCH v3 4/4] Allow scripts and plugins to set a custom AUTH_FAILED message

In reply to Arne Schwabe
Quoted 4 lines · On Mittwoch, 24. August 2022 16:08:48 CEST Arne Schwabe wrote:

This is currently only possible when using the management interface and the client-deny functionality.

Patch v3: add missing gc_free

Acked-by on v3 1/1
#24 lore raw

Re: [Openvpn-devel] [PATCH v3] Implement AUTH_FAIL, TEMP message support

In reply to Arne Schwabe
Quoted 2 lines · On Mittwoch, 24. August 2022 14:58:58 CEST Arne Schwabe wrote:

Patch v3: cleanup parse_auth_failed_temp to use a simple const string
instead of a buffer

Besides the pending rebase and the one code smell below:

Quoted 1 line
 src/openvpn/openvpn.vcxproj.filters  |   3 +

This file is gone in the meantime

Quoted 1 line
 src/openvpn/ssl.c                    |  13 ++--

Doesn't apply to master anymore

src/openvpn/options_util.c line 40

Quoted 5 lines
src/openvpn/options_util.c new file +5 -0
+parse_auth_failed_temp(struct options *o, const char *reason)
+{
+    struct gc_arena gc = gc_new();
+    /* skip TEMP */
+    const char *message = reason + strlen("TEMP");

This should be checked more. Or probably better, "reason" should be passed from the outside as "reason + 4".

#28 lore raw

PATCH v4 1/1 Implement exit notification via control channel

In reply to Arne Schwabe

Current exit notification relies on data channel messages with specific prefix. Adding these to new data channel modules (DCO) adds unncessary complexity for the data for messages that from their idea belong to the control channel anyway.

This patch adds announcing support for control channel and sending/receving it. We use the simple EXIT message for this.

Patch v2: add comment about protocol-flags to be not a user visible option,
fix various grammar mistakes, remove unused argument to receive_exit_message

Patch v3: rename data_channel_crypto_flags to imported_protocol_flags
add tls-ekm to protocol-flags.

Patch v4: rebase, use a buffer for the code that prepares the push reply

---
 doc/man-sections/client-options.rst |  7 +++++-
 src/openvpn/crypto.h                |  5 ++++
 src/openvpn/forward.c               |  4 ++++
 src/openvpn/multi.c                 |  7 +++++-
 src/openvpn/options.c               | 30 +++++++++++++++++++++--
 src/openvpn/options.h               |  2 +-
 src/openvpn/push.c                  | 37 ++++++++++++++++++++++++++++-
 src/openvpn/push.h                  |  2 ++
 src/openvpn/sig.c                   | 30 +++++++++++++++++++++--
 src/openvpn/ssl.c                   |  5 +++-
 src/openvpn/ssl.h                   |  4 ++++
 src/openvpn/ssl_ncp.c               |  5 ++++
 12 files changed, 129 insertions(+), 9 deletions(-)
doc/man-sections/client-options.rst +6 -1
index 8e0e4f18a..5a906895b 100644
@@ -220,9 +220,14 @@ configuration.
   immediately close its client instance object rather than waiting for a
   timeout.
 
+  If both server and client support sending this message using the control
+  channel, the message will be sent as control-channel message. Otherwise
+  the message is sent as data-channel message, which will be ignored by
+  data-channel offloaded peers.
+
   The **n** parameter (default :code:`1` if not present) controls the
   maximum number of attempts that the client will try to resend the exit
-  notification message.
+  notification message if messages are sent in data-channel mode.
 
   In UDP server mode, send :code:`RESTART` control channel command to
   connected clients. The ``n`` parameter (default :code:`1` if not present)
src/openvpn/crypto.h +5 -0
index 98e2c7664..5ea889081 100644
@@ -264,6 +264,11 @@ struct crypto_options
     /**< Bit-flag indicating that we do not allow clients that do
      * not support resending the wrapped client key (WKc) with the
      * third packet of the three-way handshake */
+#define CO_USE_CC_EXIT_NOTIFY       (1<<6)
+    /**< Bit-flag indicating that explicit exit notifies should be
+     * sent via the control channel instead of using an OCC message
+     */
+
     unsigned int flags;         /**< Bit-flags determining behavior of
                                  *   security operation functions. */
 };
src/openvpn/forward.c +4 -0
index 468eeee01..6a45b9e91 100644
@@ -260,6 +260,10 @@ check_incoming_control_channel(struct context *c)
         {
             receive_auth_pending(c, &buf);
         }
+        else if (buf_string_match_head_str(&buf, "EXIT"))
+        {
+            receive_exit_message(c);
+        }
         else
         {
             msg(D_PUSH_ERRORS, "WARNING: Received unknown control message: %s", BSTR(&buf));
src/openvpn/multi.c +6 -1
index 1bbeab7d4..b9b087e01 100644
@@ -1801,10 +1801,15 @@ multi_client_set_protocol_options(struct context *c)
 #ifdef HAVE_EXPORT_KEYING_MATERIAL
     if (proto & IV_PROTO_TLS_KEY_EXPORT)
     {
-        o->data_channel_crypto_flags |= CO_USE_TLS_KEY_MATERIAL_EXPORT;
+        o->imported_protocol_flags |= CO_USE_TLS_KEY_MATERIAL_EXPORT;
     }
 #endif
 
+    if (proto & IV_PROTO_CC_EXIT_NOTIFY)
+    {
+        o->imported_protocol_flags |= CO_USE_CC_EXIT_NOTIFY;
+    }
+
     /* Select cipher if client supports Negotiable Crypto Parameters */
 
     /* if we have already created our key, we cannot *change* our own
src/openvpn/options.c +28 -2
index 765695daf..e702f18f7 100644
@@ -3336,7 +3336,7 @@ pre_connect_restore(struct options *o, struct gc_arena *gc)
 
     o->push_continuation = 0;
     o->push_option_types_found = 0;
-    o->data_channel_crypto_flags = 0;
+    o->imported_protocol_flags = 0;
 }
 
 static void
@@ -8481,11 +8481,13 @@ add_option(struct options *options,
     }
     else if (streq(p[0], "key-derivation") && p[1])
     {
+        /* NCP only option that is pushed by the server to enable EKM,
+         * should not be used by normal users in config files*/
         VERIFY_PERMISSION(OPT_P_NCP)
 #ifdef HAVE_EXPORT_KEYING_MATERIAL
         if (streq(p[1], "tls-ekm"))
         {
-            options->data_channel_crypto_flags |= CO_USE_TLS_KEY_MATERIAL_EXPORT;
+            options->imported_protocol_flags |= CO_USE_TLS_KEY_MATERIAL_EXPORT;
         }
         else
 #endif
@@ -8493,6 +8495,30 @@ add_option(struct options *options,
             msg(msglevel, "Unknown key-derivation method %s", p[1]);
         }
     }
+    else if (streq(p[0], "protocol-flags") && p[1])
+    {
+        /* NCP only option that is pushed by the server to enable protocol
+         * features that are negotiated, should not be used by normal users
+         * in config files */
+        VERIFY_PERMISSION(OPT_P_NCP)
+        for (size_t j = 1; j < MAX_PARMS && p[j] != NULL; j++)
+        {
+            if (streq(p[j], "cc-exit"))
+            {
+                options->imported_protocol_flags |= CO_USE_CC_EXIT_NOTIFY;
+            }
+#ifdef HAVE_EXPORT_KEYING_MATERIAL
+            else if (streq(p[j], "tls-ekm"))
+            {
+                options->imported_protocol_flags |= CO_USE_TLS_KEY_MATERIAL_EXPORT;
+            }
+#endif
+            else
+            {
+                msg(msglevel, "Unknown protocol-flags flag: %s", p[j]);
+            }
+        }
+    }
     else if (streq(p[0], "prng") && p[1] && !p[3])
     {
         msg(M_WARN, "NOTICE: --prng option ignored (SSL library PRNG is used)");
src/openvpn/options.h +1 -1
index 5488db310..f4549edba 100644
@@ -681,7 +681,7 @@ struct options
     bool allow_recursive_routing;
 
     /* data channel crypto flags set by push/pull. Reuses the CO_* crypto_flags */
-    unsigned int data_channel_crypto_flags;
+    unsigned int imported_protocol_flags;
 };
 
 #define streq(x, y) (!strcmp((x), (y)))
src/openvpn/push.c +36 -1
index 4cbc89e4c..47a799282 100644
@@ -179,6 +179,21 @@ server_pushed_signal(struct context *c, const struct buffer *buffer, const bool
     }
 }
 
+void
+receive_exit_message(struct context *c)
+{
+    dmsg(D_STREAM_ERRORS, "Exit message received by peer");
+    c->sig->signal_received = SIGTERM;
+    c->sig->signal_text = "remote-exit";
+#ifdef ENABLE_MANAGEMENT
+    if (management)
+    {
+        management_notify(management, "info", c->sig->signal_text, "EXIT");
+    }
+#endif
+}
+
+
 void
 server_pushed_info(struct context *c, const struct buffer *buffer,
                    const int adv)
@@ -606,10 +621,30 @@ prepare_push_reply(struct context *c, struct gc_arena *gc,
     {
         push_option_fmt(gc, push_list, M_USAGE, "cipher %s", o->ciphername);
     }
-    if (o->data_channel_crypto_flags & CO_USE_TLS_KEY_MATERIAL_EXPORT)
+
+    struct buffer proto_flags = alloc_buf_gc(128, gc);
+
+    if (o->imported_protocol_flags & CO_USE_CC_EXIT_NOTIFY)
+    {
+        buf_printf(&proto_flags, " cc-exit");
+
+        /* if the cc exit flag is supported, pushing tls-ekm via protocol-flags
+         * is also supported */
+        if (o->imported_protocol_flags & CO_USE_TLS_KEY_MATERIAL_EXPORT)
+        {
+            buf_printf(&proto_flags, " tls-ekm");
+        }
+    }
+    else if (o->imported_protocol_flags & CO_USE_TLS_KEY_MATERIAL_EXPORT)
     {
         push_option_fmt(gc, push_list, M_USAGE, "key-derivation tls-ekm");
     }
+
+    if (buf_len(&proto_flags) > 0)
+    {
+        push_option_fmt(gc, push_list, M_USAGE, "protocol-flags%s", buf_str(&proto_flags));
+    }
+
     return true;
 }
 
src/openvpn/push.h +2 -0
index 62fad4a14..7138055a7 100644
@@ -48,6 +48,8 @@ void receive_auth_failed(struct context *c, const struct buffer *buffer);
 
 void server_pushed_signal(struct context *c, const struct buffer *buffer, const bool restart, const int adv);
 
+void receive_exit_message(struct context *c);
+
 void server_pushed_info(struct context *c, const struct buffer *buffer,
                         const int adv);
 
src/openvpn/sig.c +28 -2
index e06edd216..65cd25c65 100644
@@ -321,20 +321,46 @@ print_status(const struct context *c, struct status_output *so)
     gc_free(&gc);
 }
 
+
+/* Small helper function to determine if we should send the exit notification
+ * via control channel */
+static inline bool
+cc_exit_notify_enabled(struct context *c)
+{
+    /* Check if we have TLS active at all */
+    if (!c->c2.tls_multi)
+    {
+        return false;
+    }
+
+    const struct key_state *ks = get_primary_key(c->c2.tls_multi);
+    return (ks->crypto_options.flags & CO_USE_CC_EXIT_NOTIFY);
+}
+
 /*
  * Handle the triggering and time-wait of explicit
  * exit notification.
  */
-
 static void
 process_explicit_exit_notification_init(struct context *c)
 {
     msg(M_INFO, "SIGTERM received, sending exit notification to peer");
+    /* init the timeout to send the OCC_EXIT messages if cc exit is not
+     * enabled and also to exit after waiting for retries of resending of
+     * exit messages */
     event_timeout_init(&c->c2.explicit_exit_notification_interval, 1, 0);
     reset_coarse_timers(c);
+
     signal_reset(c->sig);
     halt_non_edge_triggered_signals();
     c->c2.explicit_exit_notification_time_wait = now;
+
+    /* Check if we are in TLS mode and should send the notification via data
+     * channel */
+    if (cc_exit_notify_enabled(c))
+    {
+        send_control_channel_string(c, "EXIT", D_PUSH);
+    }
 }
 
 void
@@ -351,7 +377,7 @@ process_explicit_exit_notification_timer_wakeup(struct context *c)
             c->sig->signal_received = SIGTERM;
             c->sig->signal_text = "exit-with-notification";
         }
-        else
+        else if (!cc_exit_notify_enabled(c))
         {
             c->c2.occ_op = OCC_EXIT;
         }
src/openvpn/ssl.c +4 -1
index 33e145b3f..d3f7a0203 100644
@@ -1719,7 +1719,7 @@ tls_session_update_crypto_params(struct tls_multi *multi,
     }
 
     /* Import crypto settings that might be set by pull/push */
-    session->opt->crypto_flags |= options->data_channel_crypto_flags;
+    session->opt->crypto_flags |= options->imported_protocol_flags;
 
     return tls_session_update_crypto_params_do_work(multi, session, options,
                                                     frame, frame_fragment, lsi);
@@ -1969,6 +1969,9 @@ push_peer_info(struct buffer *buf, struct tls_session *session)
         /* support for the --dns option */
         iv_proto |= IV_PROTO_DNS_OPTION;
 
+        /* support for exit notify via control channel */
+        iv_proto |= IV_PROTO_CC_EXIT_NOTIFY;
+
         /* support for receiving push_reply before sending
          * push request, also signal that the client wants
          * to get push-reply messages without without requiring a round
src/openvpn/ssl.h +4 -0
index 76b1b6743..12ffd44d7 100644
@@ -96,6 +96,10 @@
 /** Supports the --dns option introduced in version 2.6 */
 #define IV_PROTO_DNS_OPTION      (1<<6)
 
+/** Support for explicit exit notify via control channel
+ *  This also includes support for the protocol-flags pushed option */
+#define IV_PROTO_CC_EXIT_NOTIFY  (1<<7)
+
 /* Default field in X509 to be username */
 #define X509_USERNAME_FIELD_DEFAULT "CN"
 
src/openvpn/ssl_ncp.c +5 -0
index a58ced537..fe8491925 100644
@@ -419,6 +419,11 @@ p2p_ncp_set_options(struct tls_multi *multi, struct tls_session *session)
         multi->peer_id = 0x76706e; /* 'v' 'p' 'n' */
     }
 
+    if (iv_proto_peer & IV_PROTO_CC_EXIT_NOTIFY)
+    {
+        session->opt->crypto_flags |= CO_USE_CC_EXIT_NOTIFY;
+    }
+
 #if defined(HAVE_EXPORT_KEYING_MATERIAL)
     if (iv_proto_peer & IV_PROTO_TLS_KEY_EXPORT)
     {
Signature · 1 line
2.37.0 (Apple Git-136)
#30 lore raw

PATCH v4 1/1 Implement AUTH_FAIL, TEMP message support

In reply to Arne Schwabe

This allows a server to indicate a temporary problem on the server and allows the server to indicate how to proceed (i.e. move to the next server, retry the same server, wait a certain time,...)

This adds options_utils.c/h to be able to unit test the new function.

Patch v2: Improve documentation, format man page better, comment that
protocol-flags is not a user usable option.

Patch v3: cleanup parse_auth_failed_temp to use a simple const string
instead of a buffer

Patch v4: move message + strlen(TEMP) to caller

---
 doc/man-sections/script-options.rst  |  36 ++++++++++
 src/openvpn/Makefile.am              |   1 +
 src/openvpn/init.c                   |   9 ++-
 src/openvpn/openvpn.vcxproj          |   2 +
 src/openvpn/options.h                |   9 ++-
 src/openvpn/options_util.c           | 102 +++++++++++++++++++++++++++
 src/openvpn/options_util.h           |  33 +++++++++
 src/openvpn/push.c                   |  33 +++++----
 src/openvpn/ssl.c                    |  13 ++--
 src/openvpn/ssl.h                    |   3 +
 tests/unit_tests/openvpn/Makefile.am |   1 +
 tests/unit_tests/openvpn/test_misc.c |  40 +++++++++++
 12 files changed, 264 insertions(+), 18 deletions(-)
 create mode 100644 src/openvpn/options_util.c
 create mode 100644 src/openvpn/options_util.h
doc/man-sections/script-options.rst +36 -0
index 61c89b0ad..2a2e70fca 100644
@@ -102,6 +102,42 @@ SCRIPT HOOKS
   the authentication, a :code:`1` or :code:`0` must be written to the
   file specified by the :code:`auth_control_file`.
 
+  If the file specified by :code:`auth_failed_reason` exists and has non-empty
+  content, the content of this file will be used as AUTH_FAILED message. To
+  avoid race conditions, this file should be written before
+  :code:`auth_control_file`.
+
+  This auth fail reason can be something simple like "User has been permanently
+  disabled" but there are also some special auth failed messages.
+
+  The ``TEMP`` message indicates that the authentication
+  temporarily failed and that the client should continue to retry to connect.
+  The server can optionally give a user readable message and hint the client a
+  behavior how to proceed. The keywords of the ``AUTH_FAILED,TEMP`` message
+  are comma separated keys/values and provide a hint to the client how to
+  proceed. Currently defined keywords are:
+
+  ``backoff`` :code:`s`
+        instructs the client to wait at least :code:`s` seconds before the next
+        connection attempt. If the client already uses a higher delay for
+        reconnection attempt, the delay will not be shortened.
+
+  ``advance addr``
+        Instructs the client to reconnect to the next (IP) address of the
+        current server.
+
+  ``advance remote``
+        Instructs the client to skip the remaining IP addresses of the current
+        server and instead connect to the next server specified in the
+        configuration file.
+
+  ``advance no``
+        Instructs the client to retry connecting to the same server again.
+
+  For example, the message ``TEMP[backoff 42,advance no]: No free IP addresses``
+  indicates that the VPN connection can currently not succeed and instructs
+  the client to retry in 42 seconds again.
+
   When deferred authentication is in use, the script can also request
   pending authentication by writing to the file specified by the
   :code:`auth_pending_file`. The first line must be the timeout in
src/openvpn/Makefile.am +1 -0
index 71648ef18..79a3f9574 100644
@@ -101,6 +101,7 @@ openvpn_SOURCES = \
 	pkcs11_mbedtls.c \
 	openvpn.c openvpn.h \
 	options.c options.h \
+    options_util.c options_util.h \
 	otime.c otime.h \
 	packet_id.c packet_id.h \
 	perf.c perf.h \
src/openvpn/init.c +8 -1
index c40e975ed..d0ae7ac7d 100644
@@ -484,13 +484,15 @@ next_connection_entry(struct context *c)
             /* Check if there is another resolved address to try for
              * the current connection */
             if (c->c1.link_socket_addr.current_remote
-                && c->c1.link_socket_addr.current_remote->ai_next)
+                && c->c1.link_socket_addr.current_remote->ai_next
+                && !c->options.advance_next_remote)
             {
                 c->c1.link_socket_addr.current_remote =
                     c->c1.link_socket_addr.current_remote->ai_next;
             }
             else
             {
+                c->options.advance_next_remote = false;
                 /* FIXME (schwabe) fix the persist-remote-ip option for real,
                  * this is broken probably ever since connection lists and multiple
                  * remote existed
@@ -2513,6 +2515,11 @@ socket_restart_pause(struct context *c)
             /* sec is less than 2^16; we can left shift it by up to 15 bits without overflow */
             sec = max_int(sec, 1) << min_int(backoff, 15);
         }
+        if (c->options.server_backoff_time)
+        {
+            sec = max_int(sec, c->options.server_backoff_time);
+            c->options.server_backoff_time = 0;
+        }
 
         if (sec > c->options.ce.connect_retry_seconds_max)
         {
src/openvpn/openvpn.vcxproj +2 -0
index a45fb993f..9b5e416fa 100644
@@ -308,6 +308,7 @@
     <ClCompile Include="occ.c" />
     <ClCompile Include="openvpn.c" />
     <ClCompile Include="options.c" />
+    <ClCompile Include="options_util.c" />
     <ClCompile Include="otime.c" />
     <ClCompile Include="packet_id.c" />
     <ClCompile Include="perf.c" />
@@ -400,6 +401,7 @@
     <ClInclude Include="occ.h" />
     <ClInclude Include="openvpn.h" />
     <ClInclude Include="options.h" />
+    <ClInclude Include="options_util.h" />
     <ClInclude Include="otime.h" />
     <ClInclude Include="ovpn_dco_win.h" />
     <ClInclude Include="packet_id.h" />
src/openvpn/options.h +8 -1
index f4549edba..c0c0417ef 100644
@@ -272,10 +272,17 @@ struct options
     struct connection_list *connection_list;
 
     struct remote_list *remote_list;
-    /* Do not advanced the connection or remote addr list*/
+    /* Do not advance the connection or remote addr list*/
     bool no_advance;
+    /* Advance directly to the next remote, skipping remaining addresses of the
+     * current remote */
+    bool advance_next_remote;
     /* Counts the number of unsuccessful connection attempts */
     unsigned int unsuccessful_attempts;
+    /* the server can suggest a backoff time to the client, it
+     * will still be capped by the max timeout between connections
+     * (300s by default) */
+    int server_backoff_time;
 
 #if ENABLE_MANAGEMENT
     struct http_proxy_options *http_proxy_override;
src/openvpn/options_util.c new file +102 -0

102 lines not on this page · raw message

src/openvpn/options_util.h new file +33 -0
new file mode 100644
index 000000000..17d62047b
@@ -0,0 +1,33 @@
+/*
+ *  OpenVPN -- An application to securely tunnel IP networks
+ *             over a single TCP/UDP port, with support for SSL/TLS-based
+ *             session authentication and key exchange,
+ *             packet encryption, packet authentication, and
+ *             packet compression.
+ *
+ *  Copyright (C) 2002-2022 OpenVPN Inc <[email protected]...>
+ *  Copyright (C) 2010-2021 Fox Crypto B.V. <[email protected]...>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef OPTIONS_UTIL_H_
+#define OPTIONS_UTIL_H_
+
+#include "options.h"
+
+const char *
+parse_auth_failed_temp(struct options *o, const char *reason);
+
+#endif
src/openvpn/push.c +21 -12
index 47a799282..9f47b5d5a 100644
@@ -38,6 +38,7 @@
 
 #include "memdbg.h"
 #include "ssl_util.h"
+#include "options_util.h"
 
 static char push_reply_cmd[] = "PUSH_REPLY";
 
@@ -58,15 +59,34 @@ receive_auth_failed(struct context *c, const struct buffer *buffer)
         return;
     }
 
+    struct buffer buf = *buffer;
+
+    /* If the AUTH_FAIL message ends with a , it is an extended message that
+     * contains further flags */
+    bool authfail_extended = buf_string_compare_advance(&buf, "AUTH_FAILED,");
+
+    const char *reason = NULL;
+    if (authfail_extended && BLEN(&buf))
+    {
+        reason = BSTR(&buf);
+    }
+
+    if (authfail_extended && buf_string_match_head_str(&buf, "TEMP"))
+    {
+        parse_auth_failed_temp(&c->options, reason + strlen("TEMP"));
+        c->sig->signal_received = SIGUSR1;
+        c->sig->signal_text = "auth-temp-failure (server temporary reject)";
+    }
     /* Before checking how to react on AUTH_FAILED, first check if the
      * failed auth might be the result of an expired auth-token.
      * Note that a server restart will trigger a generic AUTH_FAILED
      * instead an AUTH_FAILED,SESSION so handle all AUTH_FAILED message
      * identical for this scenario */
-    if (ssl_clean_auth_token())
+    else if (ssl_clean_auth_token())
     {
         c->sig->signal_received = SIGUSR1;     /* SOFT-SIGUSR1 -- Auth failure error */
         c->sig->signal_text = "auth-failure (auth-token)";
+        c->options.no_advance = true;
     }
     else
     {
@@ -89,19 +109,8 @@ receive_auth_failed(struct context *c, const struct buffer *buffer)
         c->sig->signal_text = "auth-failure";
     }
 #ifdef ENABLE_MANAGEMENT
-    struct buffer buf = *buffer;
-
-    /* If the AUTH_FAIL message ends with a , it is an extended message that
-     * contains further flags */
-    bool authfail_extended = buf_string_compare_advance(&buf, "AUTH_FAILED,");
-
     if (management)
     {
-        const char *reason = NULL;
-        if (authfail_extended && BLEN(&buf))
-        {
-            reason = BSTR(&buf);
-        }
         management_auth_failure(management, UP_TYPE_AUTH, reason);
     }
     /*
src/openvpn/ssl.c +9 -4
index d3f7a0203..672cd9c84 100644
@@ -1972,14 +1972,19 @@ push_peer_info(struct buffer *buf, struct tls_session *session)
         /* support for exit notify via control channel */
         iv_proto |= IV_PROTO_CC_EXIT_NOTIFY;
 
-        /* support for receiving push_reply before sending
-         * push request, also signal that the client wants
-         * to get push-reply messages without without requiring a round
-         * trip for a push request message*/
         if (session->opt->pull)
         {
+            /* support for receiving push_reply before sending
+             * push request, also signal that the client wants
+             * to get push-reply messages without requiring a round
+             * trip for a push request message*/
             iv_proto |= IV_PROTO_REQUEST_PUSH;
+
+            /* Support keywords in the AUTH_PENDING control message */
             iv_proto |= IV_PROTO_AUTH_PENDING_KW;
+
+            /* support for AUTH_FAIL,TEMP control message */
+            iv_proto |= IV_PROTO_AUTH_FAIL_TEMP;
         }
 
         /* support for Negotiable Crypto Parameters */
src/openvpn/ssl.h +3 -0
index 12ffd44d7..8ca4c4aa8 100644
@@ -100,6 +100,9 @@
  *  This also includes support for the protocol-flags pushed option */
 #define IV_PROTO_CC_EXIT_NOTIFY  (1<<7)
 
+/** Support for AUTH_FAIL,TEMP messages */
+#define IV_PROTO_AUTH_FAIL_TEMP  (1<<8)
+
 /* Default field in X509 to be username */
 #define X509_USERNAME_FIELD_DEFAULT "CN"
 
tests/unit_tests/openvpn/Makefile.am +1 -0
index 63b53a6ac..65cf9549c 100644
@@ -176,5 +176,6 @@ misc_testdriver_LDFLAGS = @TEST_LDFLAGS@
 misc_testdriver_SOURCES = test_misc.c mock_msg.c \
     mock_get_random.c \
 	$(openvpn_srcdir)/buffer.c \
+	$(openvpn_srcdir)/options_util.c \
 	$(openvpn_srcdir)/ssl_util.c \
 	$(openvpn_srcdir)/platform.c
tests/unit_tests/openvpn/test_misc.c +40 -0
index 636fc45d6..90c9a1214 100644
@@ -37,6 +37,7 @@
 #include <cmocka.h>
 
 #include "ssl_util.h"
+#include "options_util.h"
 
 static void
 test_compat_lzo_string(void **state)
@@ -72,8 +73,47 @@ test_compat_lzo_string(void **state)
     gc_free(&gc);
 }
 
+static void
+test_auth_fail_temp_no_flags(void **state)
+{
+    struct options o;
+
+    const char *teststr = "TEMP:There are no flags here [really not]";
+
+    const char *msg = parse_auth_failed_temp(&o, teststr + strlen("TEMP"));
+    assert_string_equal(msg, "There are no flags here [really not]");
+}
+
+static void
+test_auth_fail_temp_flags(void **state)
+{
+    struct options o;
+
+    const char *teststr = "[backoff 42,advance no]";
+
+    const char *msg = parse_auth_failed_temp(&o, teststr);
+    assert_string_equal(msg, "");
+    assert_int_equal(o.server_backoff_time, 42);
+    assert_int_equal(o.no_advance, true);
+}
+
+static void
+test_auth_fail_temp_flags_msg(void **state)
+{
+    struct options o;
+
+    const char *teststr = "[advance remote,backoff 77]:go round and round";
+
+    const char *msg = parse_auth_failed_temp(&o, teststr);
+    assert_string_equal(msg, "go round and round");
+    assert_int_equal(o.server_backoff_time, 77);
+}
+
 const struct CMUnitTest misc_tests[] = {
     cmocka_unit_test(test_compat_lzo_string),
+    cmocka_unit_test(test_auth_fail_temp_no_flags),
+    cmocka_unit_test(test_auth_fail_temp_flags),
+    cmocka_unit_test(test_auth_fail_temp_flags_msg),
 };
 
 int
Signature · 1 line
2.37.0 (Apple Git-136)
#27 lore raw

[Openvpn-devel] [PATCH applied] Re: Allow scripts and plugins to set a custom AUTH_FAILED message

In reply to Arne Schwabe

My server test rig has a "--auth-user-pass-verify" script that already does client-controlled success/failure returns (setenv UV...), and this has now learned to return client-specific messages if $auth_failed_reason_file is set...

2022-09-17 17:44:53 AUTH: Received control message: AUTH_FAILED,you stink

.. works.

For the plugin case, I've tried to test this with my existing "--client-connect magic hooks plugin", but it seems this functionality is not exported to client-connect (so, CC plugin fails can only return basic AUTH_FAIL). So I've hacked this into plugin-auth-pam, which is used in a different server instance, and that one also works:

2022-09-17 18:07:47 AUTH: Received control message: AUTH_FAILED,my plugin does not like you

All the other tests (client+server) still works as well, no files are left around in /tmp/, etc.

Staring at the code took me a bit, because of the two-fold way you did the checks - half the locations call check_for_client_reason(), while tls_authentication_status() prefers to do it "inline" (... leading to the gc_free()... ;-) ). Could this be unified, or am I overlooking something? Anyway, decided to not stop progress because of this.

Your patch has been applied to the master branch.

commit 8893fe49a4c593387d469ccc4a73ec0714f69315

Author: Arne Schwabe
Date:   Wed Aug 24 16:08:48 2022 +0200
     Allow scripts and plugins to set a custom AUTH_FAILED message

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

--
kind regards,

Gert Doering

Acked-by on v4 1/1
#29 lore raw

[Openvpn-devel] [PATCH applied] Re: Implement exit notification via control channel

In reply to Arne Schwabe

Adding my ACK to Heiko's, because the push_option_fmt() thing is sufficiently different from v3 so I had a very close look.

Testing this is not very easy with the current test framework, as it needs this patch on both ends to become effective.

This said, I've subjected this to extensive client/server tests against 2.3...master peers, to see if it would break compat with anything (no tls-ekm, old tls-ekm, new tls-ekm) - seems not so :-)

Testing client and server both with this patch leads to the expected protocol-flags message:

... peer info: IV_PROTO=222
... SENT CONTROL ... protocol-flags cc-exit tls-ekm' (status=1)

and on ctrl-c, to

client:

 2022-09-18 17:10:59 SIGTERM received, sending exit notification to peer
 2022-09-18 17:10:59 SENT CONTROL [server]: 'EXIT' (status=1)

server:

 Sep 18 17:10:59 ... Exit message received by peer
 Sep 18 17:10:59 ... SIGTERM[soft,remote-exit] received, client-instance exiting

(and of course, --explicit-exit-notify with old<->new client/server combinations also still works, showing the "old" messages)

Testing this against a DCO enabled p2mp server also makes client-to-server --explicit-exit-notify work now. Did not test DCO P2P.

NOTE: the commit message does not mention this, but the manpage says so, without it being clear to the uninvited - p2mp server to client will never use this new EXIT message or the old OCC_EXIT signalling, and has always sent "RESTART..." control-channel messages. This was not really clear to me before I started untangling this...

NOTE2: p2p peers still exit() on receipt of --explicit-exit-notify messages. Not sure if we consider this reasonable behaviour (see separate mail thread).

Your patch has been applied to the master branch.

commit 179b3728b71013413885e453e477997f5a396f78

Author: Arne Schwabe
Date:   Wed Sep 14 18:50:41 2022 +0200
     Implement exit notification via control channel

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

--
kind regards,

Gert Doering

#31 lore raw

Re: [Openvpn-devel] [PATCH v4] Implement AUTH_FAIL, TEMP message support

In reply to Arne Schwabe

Hi,

Quoted 1 line · Arne Schwabe
 src/openvpn/openvpn.vcxproj          |   2 +

This file is still gone, so the hunk also needs to go. But I can ignore this.

doc/man-sections/script-options.rst SCRIPT HOOKS · line 105

Quoted 9 lines
doc/man-sections/script-options.rst +1 -0
index 61c89b0ad..2a2e70fca 100644
@@ -102,6 +102,42 @@ SCRIPT HOOKS
   the authentication, a :code:`1` or :code:`0` must be written to the
   file specified by the :code:`auth_control_file`.
 
+  If the file specified by :code:`auth_failed_reason` exists and has non-empty

If this is referring to the environment variable, it needs to be "auth_failed_reason_file". If you agree, I'll change that on merge.

[..]

src/openvpn/Makefile.am openvpn_SOURCES = \ · line 104

Quoted 9 lines
src/openvpn/Makefile.am +1 -0
index 71648ef18..79a3f9574 100644
@@ -101,6 +101,7 @@ openvpn_SOURCES = \
 	pkcs11_mbedtls.c \
 	openvpn.c openvpn.h \
 	options.c options.h \
+    options_util.c options_util.h \

Makefile wants a real TAB here, which I'll fix on commit.

More detailed stare-at-code and test to follow.

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]...
#32 lore raw

Re: [Openvpn-devel] [PATCH v4] Implement AUTH_FAIL, TEMP message support

Am 18.09.2022 um 18:25 schrieb Gert Doering:

Quoted 15 lines

Hi,

Quoted 1 line · Arne Schwabe
  src/openvpn/openvpn.vcxproj          |   2 +

This file is still gone, so the hunk also needs to go. But I can ignore this.

Quoted 8 lines
doc/man-sections/script-options.rst +0 -0
index 61c89b0ad..2a2e70fca 100644
@@ -102,6 +102,42 @@ SCRIPT HOOKS
    the authentication, a :code:`1` or :code:`0` must be written to the
    file specified by the :code:`auth_control_file`.
 
Quoted 3 lines

doc/man-sections/script-options.rst SCRIPT HOOKS · line 105

Quoted 1 line
doc/man-sections/script-options.rst +1 -0
+  If the file specified by :code:`auth_failed_reason` exists and has non-empty

If this is referring to the environment variable, it needs to be "auth_failed_reason_file". If you agree, I'll change that on merge.

Yes sorry. My mistake.

Arne

#33 lore raw

[Openvpn-devel] [PATCH applied] Re: Implement AUTH_FAIL, TEMP message support

In reply to Arne Schwabe

Stared-at-code.

Fixed file name reference in the documentation (as agreed), and TAB in Makefile.am.

Tested with the "regular" server and client setups - nothing breaks, but the new functionality isn't excercised, so this is not surprising.

Unit tests pass, too, which is good :-) - there is no real test for "advance addr" vs. "advance remote" (there is "advance remote", but the flags are not tested). Maybe these could be added?

To actually *test* (and continuiously verify) the functionality I needed to trick around a bit, creating a server-side script that "remembers" the last TEMP fail, and succeeds on the 4th try... but with that, it does what it says on the tin - advance (to next addr) or not, stick to the specified backoff time (remember to configure "--connect-retry 1" to *see* the effect of short backoff timers :-) )

Your patch has been applied to the master branch.

commit c9474fa316a6f73286ed97b36c8f8b1ba62141bd

Author: Arne Schwabe
Date:   Wed Sep 14 19:01:34 2022 +0200
     Implement AUTH_FAIL, TEMP message support

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

--
kind regards,

Gert Doering