Skip to contentSkip to conversation

Pending authentication improvements

PATCH Superseded Arne Schwabe 4 participants 29 messages Sep 30, 2020 – Jan 25, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Pending authentication improvements

This patchset brings a number of improvements:

- Allow a tiemout that is different from the default 60s for pending authentication. 60s is a bit tight, especially when being redirected to a complicated web login process.
- Make the server side auth-pending support no longer dependent on management interface but also allow scripts and plugins to utilise it.
- Introduce deffered authentication support for scripts. Deferred authentication is a necessary requirement for pending authentication.

The branch is also available here: https://github.com/schwabe/openvpn/tree/schwabe/auth_pending

Arne Schwabe (11):
Change pull request timeout use a timeout rather than a number Implement client side handling of AUTH_PENDING message Implement server side of AUTH_PENDING with extending timeout Introduce management client state for AUTH_PENDING notifications Change parameter of send_auth_pending_messages from context to
tls_multi
Add S_EXITCODE flag for openvpn_run_script to report exit code Refactor extract_var_peer_info into standalone function and add
ssl_util.c
Allow pending auth to be send from a auth plugin Implement deferred auth for scripts
Implement --client-crresponse script options and plugin interface Add example script demonstrating TOTP via auth-pending

 Changes.rst                          |  18 ++
 doc/man-sections/generic-options.rst |   3 +-
 doc/man-sections/script-options.rst  |  45 ++++-
 doc/man-sections/server-options.rst  |   4 +
 doc/man-sections/tls-options.rst     |   4 +
 doc/management-notes.txt             |  39 +++-
 include/openvpn-plugin.h.in          |  15 +-
 sample/sample-scripts/totpauth.py    | 107 ++++++++++
 src/openvpn/Makefile.am              |   1 +
 src/openvpn/forward.c                |  27 ++-
 src/openvpn/forward.h                |   9 +
 src/openvpn/init.c                   |   1 +
 src/openvpn/integer.h                |  25 +++
 src/openvpn/manage.c                 |  29 ++-
 src/openvpn/manage.h                 |   5 +-
 src/openvpn/multi.c                  |  29 +--
 src/openvpn/openvpn.h                |   2 +-
 src/openvpn/openvpn.vcxproj          |   2 +
 src/openvpn/openvpn.vcxproj.filters  |   6 +
 src/openvpn/options.c                |  15 ++
 src/openvpn/options.h                |   1 +
 src/openvpn/platform.c               |  35 ++++
 src/openvpn/platform.h               |   5 +-
 src/openvpn/push.c                   | 157 ++++++++++++++-
 src/openvpn/push.h                   |  23 ++-
 src/openvpn/run_command.c            |  25 ++-
 src/openvpn/run_command.h            |  14 +-
 src/openvpn/ssl.c                    |   8 +-
 src/openvpn/ssl.h                    |   3 +
 src/openvpn/ssl_common.h             |   4 +
 src/openvpn/ssl_ncp.c                |  20 +-
 src/openvpn/ssl_util.c               |  59 ++++++
 src/openvpn/ssl_util.h               |  49 +++++
 src/openvpn/ssl_verify.c             | 283 +++++++++++++++++++++++++--
 src/openvpn/ssl_verify.h             |  25 ++-
 tests/unit_tests/openvpn/Makefile.am |   3 +-
 36 files changed, 982 insertions(+), 118 deletions(-)
 create mode 100755 sample/sample-scripts/totpauth.py
 create mode 100644 src/openvpn/ssl_util.c
 create mode 100644 src/openvpn/ssl_util.h
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/1 Allow 'none' cipher being specified in --data-ciphers

Although we want to get rid of none as cipher, we still have not deprecated it. In order to use it currently you need --ncp-disable together with --cipher none to use the none cipher.

In our current situation allowing none to be specified in data-ciphers is the lesser evil.

This commit also fixes that we use '[null-cipher]' instead 'none' when setting remote_cipher

Patch V2: Also work correctly if remote_cipher is NULL.

---
 src/openvpn/ssl.c                   |  8 ++++++++
 src/openvpn/ssl_ncp.c               | 16 +++++++++++++++-
 tests/unit_tests/openvpn/test_ncp.c | 10 ++++++++--
 3 files changed, 31 insertions(+), 3 deletions(-)
src/openvpn/ssl.c +8 -0
index 3fcaa25f..69bede27 100644
@@ -2518,6 +2518,14 @@ key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_sessio
     multi->remote_ciphername =
         options_string_extract_option(options, "cipher", NULL);
 
+    /* In OCC we send '[null-cipher]' instead 'none' */
+    if (multi->remote_ciphername
+        && strcmp(multi->remote_ciphername, "[null-cipher]") == 0)
+    {
+        free(multi->remote_ciphername);
+        multi->remote_ciphername = string_alloc("none", NULL);
+    }
+
     if (tls_session_user_pass_enabled(session))
     {
         /* Perform username/password authentication */
src/openvpn/ssl_ncp.c +15 -1
index 55496395..c8229044 100644
@@ -110,7 +110,15 @@ mutate_ncp_cipher_list(const char *list, struct gc_arena *gc)
          * e.g. replacing AeS-128-gCm with AES-128-GCM
          */
         const cipher_kt_t *ktc = cipher_kt_get(token);
-        if (!ktc)
+        if (strcmp(token, "none") == 0)
+        {
+            msg(M_WARN, "WARNING: cipher 'none' specified for --data-ciphers. "
+                        "This allows negotiation of NO encryption and "
+                        "tunnelled data WILL then be transmitted in clear text "
+                        "over the network! "
+                        "PLEASE DO RECONSIDER THIS SETTING!");
+        }
+        if (!ktc && strcmp(token, "none")!= 0)
         {
             msg(M_WARN, "Unsupported cipher in --data-ciphers: %s", token);
             error_found = true;
@@ -118,6 +126,12 @@ mutate_ncp_cipher_list(const char *list, struct gc_arena *gc)
         else
         {
             const char *ovpn_cipher_name = cipher_kt_name(ktc);
+            if (ktc == NULL)
+            {
+                /* NULL resolves to [null-cipher] but we need none for
+                 * data-ciphers */
+                ovpn_cipher_name = "none";
+            }
 
             if (buf_len(&new_list)> 0)
             {
tests/unit_tests/openvpn/test_ncp.c +8 -2
index a4334c89..046c6876 100644
@@ -50,7 +50,9 @@ test_check_ncp_ciphers_list(void **state)
     struct gc_arena gc = gc_new();
     bool have_chacha = cipher_kt_get("CHACHA20-POLY1305");
 
-
+    assert_string_equal(mutate_ncp_cipher_list("none", &gc), "none");
+    assert_string_equal(mutate_ncp_cipher_list("AES-256-GCM:none", &gc),
+                        "AES-256-GCM:none");
 
     assert_string_equal(mutate_ncp_cipher_list(aes_ciphers, &gc), aes_ciphers);
 
@@ -139,7 +141,7 @@ test_poor_man(void **state)
     char *best_cipher;
 
     const char *serverlist = "CHACHA20_POLY1305:AES-128-GCM";
-    const char *serverlistbfcbc = "CHACHA20_POLY1305:AES-128-GCM:BF-CBC";
+    const char *serverlistbfcbc = "CHACHA20_POLY1305:AES-128-GCM:BF-CBC:none";
 
     best_cipher = ncp_get_best_cipher(serverlist,
                                       "IV_YOLO=NO\nIV_BAR=7",
@@ -166,6 +168,10 @@ test_poor_man(void **state)
 
     assert_string_equal(best_cipher, "AES-128-GCM");
 
+    best_cipher = ncp_get_best_cipher(serverlist, NULL,
+                                      "none", &gc);
+    assert_string_equal(best_cipher, "none");
+
     best_cipher = ncp_get_best_cipher(serverlist, NULL,NULL, &gc);
     assert_ptr_equal(best_cipher, NULL);
 
Signature · 1 line
2.26.2
#6 lore raw

PATCH 1/11 Change pull request timeout use a timeout rather than a number

In reply to Arne Schwabe

This commit changes the count n_sent_push_requests to time_t based push_request_timeout. This is more in line to our other timeouts which are also time based instead of number retries based.

This does not change the behaviour but it prepares allowing to extend the pull request timeout during a pending authentication. As a user visible change we print the the time we waited for a timeout instead

Also update the man page to actually document that hand-window controls this timeout.

---
 doc/man-sections/tls-options.rst | 4 ++++
 src/openvpn/forward.c            | 1 +
 src/openvpn/openvpn.h            | 2 +-
 src/openvpn/push.c               | 9 ++++++---
 4 files changed, 12 insertions(+), 4 deletions(-)
doc/man-sections/tls-options.rst +4 -0
index 8c2db7cd..4d9ee2dc 100644
@@ -200,6 +200,10 @@ certificates and keys: https://github.com/OpenVPN/easy-rsa
   will still use our expiring key for up to ``--tran-window`` seconds to
   maintain continuity of transmission of tunnel data.
 
+  The ``--hand-window`` parameter also controls the amount of of time that
+  the OpenVPN client repeats the pull request until it times out on pull
+  requests until giving up.
+
 --key file
   Local peer's private key in .pem format. Use the private key which was
   generated when you built your peer's certificate (see ``--cert file``
src/openvpn/forward.c +1 -0
index 7ed8d0d7..325f1373 100644
@@ -292,6 +292,7 @@ check_connection_established(struct context *c)
             }
 #endif
             /* fire up push request right away (already 1s delayed) */
+            c->c2.push_request_timeout = now + c->options.handshake_window;
             event_timeout_init(&c->c2.push_request_interval, 0, now);
             reset_coarse_timers(c);
         }
src/openvpn/openvpn.h +1 -1
index a7b59774..4630b33e 100644
@@ -462,7 +462,7 @@ struct context_2
     enum client_connect_status context_auth;
 
     struct event_timeout push_request_interval;
-    int n_sent_push_requests;
+    time_t push_request_timeout;
     bool did_pre_pull_restore;
 
     /* hash of pulled options, so we can compare when options change */
src/openvpn/push.c +6 -3
index e0d2eeaf..5fc3eb18 100644
@@ -369,14 +369,17 @@ cleanup:
 bool
 send_push_request(struct context *c)
 {
-    const int max_push_requests = c->options.handshake_window / PUSH_REQUEST_INTERVAL;
-    if (++c->c2.n_sent_push_requests <= max_push_requests)
+    struct tls_session *session = &c->c2.tls_multi->session[TM_ACTIVE];
+    struct key_state *ks = &session->key[KS_PRIMARY];
+
+    if (c->c2.push_request_timeout > now)
     {
         return send_control_channel_string(c, "PUSH_REQUEST", D_PUSH);
     }
     else
     {
-        msg(D_STREAM_ERRORS, "No reply from server after sending %d push requests", max_push_requests);
+        msg(D_STREAM_ERRORS, "No reply from server to push requests in %ds",
+            (int)(now - ks->established));
         c->sig->signal_received = SIGUSR1; /* SOFT-SIGUSR1 -- server-pushed connection reset */
         c->sig->signal_text = "no-push-reply";
         return false;
Signature · 1 line
2.26.2
#8 lore raw

PATCH 2/11 Implement client side handling of AUTH_PENDING message

In reply to Arne Schwabe

This allows a client to extend the timeout of pull-request response while waiting for the user to complete a pending authentication. A timeout of 60s for a normal authentication might still works for a simple 2FA (but still challenging). With a sophisticated (or overly complicated) web based authentication 60s are quite short.

To avoid not detecting network problem in this phase, we use the constant sending of PUSH_REQUEST/AUTH_PENDING as keepalive signal and still timeout the session after the handshake window time.

---
 doc/man-sections/server-options.rst |  4 ++
 doc/management-notes.txt            | 39 ++++++++++++----
 src/openvpn/forward.c               | 11 ++++-
 src/openvpn/integer.h               | 25 ++++++++++
 src/openvpn/push.c                  | 72 ++++++++++++++++++++++++++++-
 src/openvpn/push.h                  |  9 ++++
 src/openvpn/ssl.c                   |  3 ++
 src/openvpn/ssl.h                   |  3 ++
 src/openvpn/ssl_common.h            |  1 +
 9 files changed, 156 insertions(+), 11 deletions(-)
doc/man-sections/server-options.rst +4 -0
index 5a689452..271c54d0 100644
@@ -473,6 +473,10 @@ fast hardware. SSL/TLS authentication must be used in this mode.
     - bit 1: The peer supports peer-id floating mechanism
     - bit 2: The client expects a push-reply and the server may
       send this reply without waiting for a push-request first.
+    - bit 3: The client is capable of doing key derivation using
+      RFC5705 key material exporter.
+    - bit 4: The client is capable of accepting additional arguments
+      to the `AUTH_PENDING` message.
 
   :code:`IV_NCP=2`
         Negotiable ciphers, client supports ``--cipher`` pushed by
doc/management-notes.txt +30 -9
index 61daaf07..99ba178a 100644
@@ -600,14 +600,30 @@ to signal a pending authenticating to the client. A pending auth means
 that the connecting requires extra authentication like a one time
 password or doing a single sign one via web.
 
-    client-pending-auth {CID} {EXTRA}
-
-The server will send AUTH_PENDING and INFO_PRE,{EXTRA} to the client.
-The client is expected to inform the user that authentication is pending and
-display the extra information. For the format of EXTRA see below
-For the OpenVPN server this is stateless operation and needs to be
-followed by a client-deny/client-auth[-nt] command (that is the result of the
-out of band authentication).
+    client-pending-auth {CID} {EXTRA} {TIMEOUT}
+
+The server will send AUTH_PENDING and INFO_PRE,{EXTRA} to the client. If the
+client supports accepting keywords to AUTH_PENDING (announced via IV_PROTO),
+TIMEOUT parameter will be also be announced to the client to allow it to modify
+its own timeout. The client is expected to inform the user that authentication
+is pending and display the extra information and also show the user the
+remaining time to complete the auth if applicable.
+
+Receiving a AUTH_PENDING message will make the client change its timeout the
+timeout proposed by the server, even if the timeout is shorter.
+If the client does not receive a packet from the server for hand-window the
+connection times out regardless of the timeout. This ensures that the connection
+still times out relatively quickly in case of network problems. The client will
+continously send PULL_REQUEST messages to the server until the timeout is reached.
+This message also triggers an ACK message from the server that resets the
+hand-window based timeout.
+
+Both client and server limit the maximum timeout to the smaller value of half the
+--tls-reneg minimum time and --hand-window time (defaults to 60s).
+
+For the format of EXTRA see below. For the OpenVPN server this is a stateless
+operation and needs to be followed by a client-deny/client-auth[-nt] command
+(that is the result of the out of band authentication).
 
 Before issuing a client-pending-auth to a client instead of a
 client-auth/client-deny, the server should check the IV_SSO
@@ -620,7 +636,7 @@ set
     setenv IV_SSO openurl,crtext
 
 The variable name IV_SSO is historic as AUTH_PENDING was first used
-to signal single sign on support. To keep compatiblity with existing
+to signal single sign on support. To keep compatibility with existing
 implementations the name IV_SSO is kept in lieu of a better name.
 
 openurl
@@ -636,6 +652,11 @@ The space in a control message is limited, so this url should be kept
 short to avoid issues. If a loger url is required a URL that redirects
 to the longer URL should be sent instead.
 
+A complete documentation how URLs should be handled on the client is available
+in the openvpn3 repository:
+
+https://github.com/OpenVPN/openvpn3/blob/master/doc/webauth.md
+
 url_proxy
 ========
 To avoid issues with OpenVPN connection persist-tun and not able
src/openvpn/forward.c +10 -1
index 325f1373..7d559544 100644
@@ -233,6 +233,10 @@ check_incoming_control_channel(struct context *c)
         {
             receive_cr_response(c, &buf);
         }
+        else if (buf_string_match_head_str(&buf, "AUTH_PENDING"))
+        {
+            receive_auth_pending(c, &buf);
+        }
         else
         {
             msg(D_PUSH_ERRORS, "WARNING: Received unknown control message: %s", BSTR(&buf));
@@ -292,7 +296,12 @@ check_connection_established(struct context *c)
             }
 #endif
             /* fire up push request right away (already 1s delayed) */
-            c->c2.push_request_timeout = now + c->options.handshake_window;
+            /* We might receive a AUTH_PENDING request before we armed this
+             * timer. In that case we don't change the value */
+            if (c->c2.push_request_timeout < now)
+            {
+                c->c2.push_request_timeout = now + c->options.handshake_window;
+            }
             event_timeout_init(&c->c2.push_request_interval, 0, now);
             reset_coarse_timers(c);
         }
src/openvpn/integer.h +25 -0
index 3755f43f..0c3511e6 100644
@@ -39,6 +39,31 @@
 /*
  * min/max functions
  */
+static inline unsigned int
+max_uint(unsigned int x, unsigned int y)
+{
+    if (x > y)
+    {
+        return x;
+    }
+    else
+    {
+        return y;
+    }
+}
+
+static inline unsigned int
+min_uint(unsigned int x, unsigned int y)
+{
+    if (x < y)
+    {
+        return x;
+    }
+    else
+    {
+        return y;
+    }
+}
 
 static inline int
 max_int(int x, int y)
src/openvpn/push.c +71 -1

84 lines not on this page · raw message

src/openvpn/push.h +9 -0
index 2faf19a6..01847671 100644
@@ -89,5 +89,14 @@ void send_restart(struct context *c, const char *kill_msg);
  */
 void send_push_reply_auth_token(struct tls_multi *multi);
 
+/**
+ * Parses an AUTH_PENDING message and if in pull mode extends the timeout
+ *
+ * @param c             The context struct
+ * @param buffer        Buffer containing the control message with AUTH_PENDING
+ */
+void
+receive_auth_pending(struct context *c, const struct buffer *buffer);
+
 #endif /* if P2MP */
 #endif /* ifndef PUSH_H */
src/openvpn/ssl.c +3 -0
index 3fcaa25f..c019c194 100644
@@ -2218,6 +2218,7 @@ push_peer_info(struct buffer *buf, struct tls_session *session)
         if(session->opt->pull)
         {
             iv_proto |= IV_PROTO_REQUEST_PUSH;
+            iv_proto |= IV_PROTO_AUTH_PENDING_KW;
         }
 
         buf_printf(&out, "IV_PROTO=%d\n", iv_proto);
@@ -3669,6 +3670,8 @@ tls_pre_decrypt(struct tls_multi *multi,
             }
         }
     }
+    /* Remember that we received a valid control channel packet */
+    ks->peer_last_packet = now;
 
 done:
     buf->len = 0;
src/openvpn/ssl.h +3 -0
index 005628f6..cce61354 100644
@@ -117,6 +117,9 @@
 #define IV_PROTO_REQUEST_PUSH   (1<<2)
 
 
+/** Supports signaling keywords with AUTH_PENDING, e.g. timeout=xy */
+#define IV_PROTO_AUTH_PENDING_KW (1<<4)
+
 /* Default field in X509 to be username */
 #define X509_USERNAME_FIELD_DEFAULT "CN"
 
src/openvpn/ssl_common.h +1 -0
index 96897e48..d0a2c89b 100644
@@ -178,6 +178,7 @@ struct key_state
     time_t established;         /* when our state went S_ACTIVE */
     time_t must_negotiate;      /* key negotiation times out if not finished before this time */
     time_t must_die;            /* this object is destroyed at this time */
+    time_t peer_last_packet;    /* Last time we received a paket in this control session */
 
     int initial_opcode;         /* our initial P_ opcode */
     struct session_id session_id_remote; /* peer's random session ID */
Signature · 1 line
2.26.2
#11 lore raw

PATCH 3/11 Implement server side of AUTH_PENDING with extending timeout

In reply to Arne Schwabe
---
 src/openvpn/manage.c     | 26 +++++++++++++------
 src/openvpn/manage.h     |  3 ++-
 src/openvpn/multi.c      | 27 +++-----------------
 src/openvpn/push.c       | 55 +++++++++++++++++++++++++++++++++++++---
 src/openvpn/push.h       | 10 ++++++++
 src/openvpn/ssl.c        |  1 +
 src/openvpn/ssl_common.h |  1 +
 7 files changed, 87 insertions(+), 36 deletions(-)
src/openvpn/manage.c +18 -8
index 898cb3b3..8df60d7a 100644
@@ -990,19 +990,26 @@ parse_cid(const char *str, unsigned long *cid)
 }
 
 static bool
-parse_kid(const char *str, unsigned int *kid)
+parse_uint(const char *str, const char* what, unsigned int *uint)
 {
-    if (sscanf(str, "%u", kid) == 1)
+    if (sscanf(str, "%u", uint) == 1)
     {
         return true;
     }
     else
     {
-        msg(M_CLIENT, "ERROR: cannot parse KID");
+        msg(M_CLIENT, "ERROR: cannot parse %s", what);
         return false;
     }
 }
 
+static bool
+parse_kid(const char *str, unsigned int *kid)
+{
+    return parse_uint(str, "KID", kid);
+}
+
+
 /**
  * Will send a notification to the client that succesful authentication
  * will require an additional step (web based SSO/2-factor auth/etc)
@@ -1013,15 +1020,18 @@ parse_kid(const char *str, unsigned int *kid)
  *                      the information of the additional steps
  */
 static void
-man_client_pending_auth(struct management *man, const char *cid_str, const char *extra)
+man_client_pending_auth(struct management *man, const char *cid_str,
+                        const char *extra, const char *timeout_str)
 {
     unsigned long cid = 0;
-    if (parse_cid(cid_str, &cid))
+    unsigned int timeout = 0;
+    if (parse_cid(cid_str, &cid)
+        && parse_uint(timeout_str, "TIMEOUT", &timeout))
     {
         if (man->persist.callback.client_pending_auth)
         {
             bool ret = (*man->persist.callback.client_pending_auth)
-                           (man->persist.callback.arg, cid, extra);
+                           (man->persist.callback.arg, cid, extra, timeout);
 
             if (ret)
             {
@@ -1582,9 +1592,9 @@ man_dispatch_command(struct management *man, struct status_output *so, const cha
     }
     else if (streq(p[0], "client-pending-auth"))
     {
-        if (man_need(man, p, 2, 0))
+        if (man_need(man, p, 3, 0))
         {
-            man_client_pending_auth(man, p[1], p[2]);
+            man_client_pending_auth(man, p[1], p[2], p[3]);
         }
     }
 #ifdef MANAGEMENT_PF
src/openvpn/manage.h +2 -1
index 881bfb14..1c497427 100644
@@ -176,7 +176,8 @@ struct management_callback
                          struct buffer_list *cc_config); /* ownership transferred */
     bool (*client_pending_auth) (void *arg,
                                  const unsigned long cid,
-                                 const char *url);
+                                 const char *extra,
+                                 unsigned int timeout);
     char *(*get_peer_info) (void *arg, const unsigned long cid);
 #endif
 #ifdef MANAGEMENT_PF
src/openvpn/multi.c +3 -24
index 13738180..50e2e350 100644
@@ -1771,28 +1771,6 @@ multi_client_connect_setenv(struct multi_context *m,
     gc_free(&gc);
 }
 
-/**
- * Extracts the IV_PROTO variable and returns its value or 0
- * if it cannot be extracted.
- *
- */
-static unsigned int
-extract_iv_proto(const char *peer_info)
-{
-
-    const char *optstr = peer_info ? strstr(peer_info, "IV_PROTO=") : NULL;
-    if (optstr)
-    {
-        int proto = 0;
-        int r = sscanf(optstr, "IV_PROTO=%d", &proto);
-        if (r == 1 && proto > 0)
-        {
-            return proto;
-        }
-    }
-    return 0;
-}
-
 /**
  * Calculates the options that depend on the client capabilities
  * based on local options and available peer info
@@ -3917,14 +3895,15 @@ management_kill_by_cid(void *arg, const unsigned long cid, const char *kill_msg)
 static bool
 management_client_pending_auth(void *arg,
                                const unsigned long cid,
-                               const char *extra)
+                               const char *extra,
+                               unsigned int timeout)
 {
     struct multi_context *m = (struct multi_context *) arg;
     struct multi_instance *mi = lookup_by_cid(m, cid);
     if (mi)
     {
         /* sends INFO_PRE and AUTH_PENDING messages to client */
-        bool ret = send_auth_pending_messages(&mi->context, extra);
+        bool ret = send_auth_pending_messages(&mi->context, extra, timeout);
         multi_schedule_context_wakeup(m, mi);
         return ret;
     }
src/openvpn/push.c +52 -3

82 lines not on this page · raw message

src/openvpn/push.h +10 -0
index 01847671..a2192114 100644
@@ -89,6 +89,16 @@ void send_restart(struct context *c, const char *kill_msg);
  */
 void send_push_reply_auth_token(struct tls_multi *multi);
 
+
+/**
+ * Extracts the IV_PROTO variable and returns its value or 0
+ * if it cannot be extracted.
+ *
+ * @param peer_info     peer info string to search for IV_PROTO
+ */
+unsigned int
+extract_iv_proto(const char *peer_info);
+
 /**
  * Parses an AUTH_PENDING message and if in pull mode extends the timeout
  *
src/openvpn/ssl.c +1 -0
index c019c194..f0664a0f 100644
@@ -2709,6 +2709,7 @@ tls_process(struct tls_multi *multi,
             buf = reliable_get_buf_output_sequenced(ks->send_reliable);
             if (buf)
             {
+                ks->initial = now;
                 ks->must_negotiate = now + session->opt->handshake_window;
                 ks->auth_deferred_expire = now + auth_deferred_expire_window(session->opt);
 
src/openvpn/ssl_common.h +1 -0
index d0a2c89b..7ccd1abb 100644
@@ -175,6 +175,7 @@ struct key_state
 
     struct key_state_ssl ks_ssl; /* contains SSL object and BIOs for the control channel */
 
+    time_t initial;             /* when we created this session */
     time_t established;         /* when our state went S_ACTIVE */
     time_t must_negotiate;      /* key negotiation times out if not finished before this time */
     time_t must_die;            /* this object is destroyed at this time */
Signature · 1 line
2.26.2
#13 lore raw

PATCH 4/11 Introduce management client state for AUTH_PENDING notifications

In reply to Arne Schwabe

This allows a UI client to display the correct state. Technically the client is still waiting for PUSH_REPLY but for every practical concern this is a different state as we are waiting for the pending authentication to finish.

---
 src/openvpn/manage.c |  3 +++
 src/openvpn/manage.h |  2 ++
 src/openvpn/push.c   | 18 ++++++++++++++++++
 3 files changed, 23 insertions(+)
src/openvpn/manage.c +3 -0
index 8df60d7a..58ff0155 100644
@@ -171,6 +171,9 @@ man_state_name(const int state)
         case OPENVPN_STATE_TCP_CONNECT:
             return "TCP_CONNECT";
 
+        case OPENVPN_STATE_AUTH_PENDING:
+            return "AUTH_PENDING";
+
         default:
             return "?";
     }
src/openvpn/manage.h +2 -0
index 1c497427..1681e141 100644
@@ -506,6 +506,8 @@ management_enable_def_auth(const struct management *man)
 #define OPENVPN_STATE_GET_CONFIG    9  /* Downloading configuration from server */
 #define OPENVPN_STATE_RESOLVE       10 /* DNS lookup */
 #define OPENVPN_STATE_TCP_CONNECT   11 /* Connecting to TCP server */
+#define OPENVPN_STATE_AUTH_PENDING  12 /* Waiting in auth-pending mode
+                                        * techhnically variant of GET_CONFIG */
 
 #define OPENVPN_STATE_CLIENT_BASE   7  /* Base index of client-only states */
 
src/openvpn/push.c +18 -0
index ece63650..59f8f33c 100644
@@ -248,12 +248,30 @@ parse_auth_pending_keywords(const struct buffer *buffer,
     if (!buf_advance(&buf, strlen("AUTH_PENDING"))
         || !(buf_read_u8(&buf) == ',') || !BLEN(&buf))
     {
+#ifdef ENABLE_MANAGEMENT
+        if (management)
+        {
+            management_set_state(management, OPENVPN_STATE_AUTH_PENDING,
+                                 "", NULL, NULL, NULL, NULL);
+        }
+#endif
+
         return;
     }
 
     /* parse the keywords in the same way that push options are parsed */
     char line[OPTION_LINE_SIZE];
 
+#ifdef ENABLE_MANAGEMENT
+    /* Need to do the management notification with the keywords before
+     * buf_parse is called, as it will insert \0 bytes into the buffer */
+    if (management)
+    {
+        management_set_state(management, OPENVPN_STATE_AUTH_PENDING,
+                             BSTR(&buf), NULL, NULL, NULL, NULL);
+    }
+#endif
+
     while (buf_parse(&buf, ',', line, sizeof(line)))
     {
         if (sscanf(line, "timeout %u", server_timeout) == 1)
Signature · 1 line
2.26.2
#15 lore raw

PATCH 5/11 Change parameter of send_auth_pending_messages from context to tls_multi

In reply to Arne Schwabe

This prepares send_auth_pending_messages to be used a in context that does not have context c available but also does not need to schedule an immediate sending of the message (auth plugin/script)

---
 src/openvpn/forward.c | 17 +++++++++--------
 src/openvpn/forward.h |  9 +++++++++
 src/openvpn/multi.c   |  4 +++-
 src/openvpn/push.c    |  9 ++++-----
 src/openvpn/push.h    |  4 +++-
 5 files changed, 28 insertions(+), 15 deletions(-)
src/openvpn/forward.c +9 -8
index 7d559544..7c759a62 100644
@@ -335,6 +335,14 @@ send_control_channel_string_dowork(struct tls_multi *multi,
     return stat;
 }
 
+void reschedule_multi_process(struct context *c)
+{
+
+    interval_action(&c->c2.tmp_int);
+    context_immediate_reschedule(c); /* ZERO-TIMEOUT */
+}
+
+
 bool
 send_control_channel_string(struct context *c, const char *str, int msglevel)
 {
@@ -342,15 +350,8 @@ send_control_channel_string(struct context *c, const char *str, int msglevel)
     {
         bool ret = send_control_channel_string_dowork(c->c2.tls_multi,
                                                       str, msglevel);
-        /*
-         * Reschedule tls_multi_process.
-         * NOTE: in multi-client mode, usually the below two statements are
-         * insufficient to reschedule the client instance object unless
-         * multi_schedule_context_wakeup(m, mi) is also called.
-         */
+        reschedule_multi_process(c);
 
-        interval_action(&c->c2.tmp_int);
-        context_immediate_reschedule(c); /* ZERO-TIMEOUT */
         return ret;
     }
     return true;
src/openvpn/forward.h +9 -0
index a8b19f69..4336db5a 100644
@@ -317,6 +317,15 @@ bool
 send_control_channel_string_dowork(struct tls_multi *multi,
                                    const char *str, int msglevel);
 
+
+/**
+ * Reschedule tls_multi_process.
+ * NOTE: in multi-client mode, usually the below two statements are
+ * insufficient to reschedule the client instance object unless
+ * multi_schedule_context_wakeup(m, mi) is also called.
+ */
+void reschedule_multi_process(struct context *c);
+
 #define PIPV4_PASSTOS                   (1<<0)
 #define PIP_MSSFIX                      (1<<1)         /* v4 and v6 */
 #define PIP_OUTGOING                    (1<<2)
src/openvpn/multi.c +3 -1
index 50e2e350..e2454753 100644
@@ -3903,7 +3903,9 @@ management_client_pending_auth(void *arg,
     if (mi)
     {
         /* sends INFO_PRE and AUTH_PENDING messages to client */
-        bool ret = send_auth_pending_messages(&mi->context, extra, timeout);
+        bool ret = send_auth_pending_messages(mi->context.c2.tls_multi, extra,
+                                              timeout);
+        reschedule_multi_process(&mi->context);
         multi_schedule_context_wakeup(m, mi);
         return ret;
     }
src/openvpn/push.c +4 -5
index 59f8f33c..58e20baa 100644
@@ -367,14 +367,13 @@ send_auth_failed(struct context *c, const char *client_reason)
 
 
 bool
-send_auth_pending_messages(struct context *c, const char *extra,
+send_auth_pending_messages(struct tls_multi *tls_multi, const char *extra,
                            unsigned int timeout)
 {
     struct key_state *ks = &tls_multi->session[TM_ACTIVE].key[KS_PRIMARY];
 
     static const char info_pre[] = "INFO_PRE,";
 
-    struct tls_multi *tls_multi = c->c2.tls_multi;
     const char *const peer_info = tls_multi->peer_info;
     unsigned int proto = extract_iv_proto(peer_info);
 
@@ -388,7 +387,7 @@ send_auth_pending_messages(struct context *c, const char *extra,
     struct gc_arena gc = gc_new();
     if ((proto & IV_PROTO_AUTH_PENDING_KW) == 0)
     {
-        send_control_channel_string(c, "AUTH_PENDING", D_PUSH);
+        send_control_channel_string_dowork(tls_multi, "AUTH_PENDING", D_PUSH);
     }
     else
     {
@@ -399,7 +398,7 @@ send_auth_pending_messages(struct context *c, const char *extra,
         struct buffer buf = alloc_buf_gc(len, &gc);
         buf_printf(&buf, auth_pre);
         buf_printf(&buf, "%u", timeout);
-        send_control_channel_string(c, BSTR(&buf), D_PUSH);
+        send_control_channel_string_dowork(tls_multi, BSTR(&buf), D_PUSH);
     }
 
 
@@ -413,7 +412,7 @@ send_auth_pending_messages(struct context *c, const char *extra,
     struct buffer buf = alloc_buf_gc(len, &gc);
     buf_printf(&buf, info_pre);
     buf_printf(&buf, "%s", extra);
-    send_control_channel_string(c, BSTR(&buf), D_PUSH);
+    send_control_channel_string_dowork(tls_multi, BSTR(&buf), D_PUSH);
 
     ks->auth_deferred_expire = now + timeout;
 
src/openvpn/push.h +3 -1
index a2192114..377f94a6 100644
@@ -77,7 +77,9 @@ void send_auth_failed(struct context *c, const char *client_reason);
  * doc/management-notes.txt under client-pending-auth for
  * more details on message format
  */
-bool send_auth_pending_messages(struct context *c, const char *extra);
+bool
+send_auth_pending_messages(struct tls_multi *tls_multi, const char *extra,
+                           unsigned int timeout);
 
 void send_restart(struct context *c, const char *kill_msg);
 
Signature · 1 line
2.26.2
#17 lore raw

PATCH 6/11 Add S_EXITCODE flag for openvpn_run_script to report exit code

In reply to Arne Schwabe

This allows to use script that have more than just fail/sucess but also deferred as status

---
 src/openvpn/platform.c    | 35 +++++++++++++++++++++++++++++++++++
 src/openvpn/platform.h    |  5 ++++-
 src/openvpn/run_command.c | 25 ++++++++++++++++---------
 src/openvpn/run_command.h | 14 ++++++++++----
 4 files changed, 65 insertions(+), 14 deletions(-)
src/openvpn/platform.c +35 -0
index 53d07f9c..5545a133 100644
@@ -240,6 +240,41 @@ platform_system_ok(int stat)
 #endif
 }
 
+#ifdef _WIN32
+int
+platform_ret_code(int stat)
+{
+
+    if (stat >= 0 && stat < 255)
+    {
+        return stat;
+    }
+    else
+    {
+        return -1;
+    }
+}
+#else
+int
+platform_ret_code(int stat)
+{
+    if (!WIFEXITED(stat) || stat == -1)
+    {
+        return -1;
+    }
+
+    int status = WEXITSTATUS(stat);
+    if (status >= 0 && status < 255)
+    {
+        return status;
+    }
+    else
+    {
+        return -1;
+    }
+}
+#endif
+
 int
 platform_access(const char *path, int mode)
 {
src/openvpn/platform.h +4 -1
index 091fc9c4..c7f6aae1 100644
@@ -119,9 +119,12 @@ void platform_mlockall(bool print_msg);  /* Disable paging */
 
 int platform_chdir(const char *dir);
 
-/* interpret the status code returned by execve() */
+/** interpret the status code returned by execve() */
 bool platform_system_ok(int stat);
 
+/** Return a return code if valid and between 0 and 255, -1 otherwise */
+int platform_ret_code(int stat);
+
 int platform_access(const char *path, int mode);
 
 void platform_sleep_milliseconds(unsigned int n);
src/openvpn/run_command.c +16 -9
index 4c4adf97..c1dd102c 100644
@@ -191,27 +191,34 @@ openvpn_execve(const struct argv *a, const struct env_set *es, const unsigned in
 /*
  * Wrapper around openvpn_execve
  */
-bool
+int
 openvpn_execve_check(const struct argv *a, const struct env_set *es, const unsigned int flags, const char *error_message)
 {
     struct gc_arena gc = gc_new();
     const int stat = openvpn_execve(a, es, flags);
     int ret = false;
 
-    if (platform_system_ok(stat))
+    if(flags & S_EXITCODE)
+    {
+        ret = platform_ret_code(stat);
+        if (ret != -1) {
+            goto done;
+        }
+    }
+    else if (platform_system_ok(stat))
     {
         ret = true;
+        goto done;
     }
-    else
+    if (error_message)
     {
-        if (error_message)
-        {
-            msg(((flags & S_FATAL) ? M_FATAL : M_WARN), "%s: %s",
-                error_message,
-                system_error_message(stat, &gc));
-        }
+        msg(((flags & S_FATAL) ? M_FATAL : M_WARN), "%s: %s",
+            error_message,
+            system_error_message(stat, &gc));
     }
+done:
     gc_free(&gc);
+
     return ret;
 }
 
src/openvpn/run_command.h +10 -4
index 7ccb13c6..e322ebd1 100644
@@ -42,18 +42,24 @@ int script_security(void);
 void script_security_set(int level);
 
 /* openvpn_execve flags */
-#define S_SCRIPT (1<<0)
-#define S_FATAL  (1<<1)
+#define S_SCRIPT    (1<<0)
+#define S_FATAL     (1<<1)
+/** Instead of returning 1/0 for success/fail,
+ * return exit code when between 0 and 255 and -1 otherwise */
+#define S_EXITCODE  (1<<2)
 
 /* wrapper around the execve() call */
 int openvpn_popen(const struct argv *a,  const struct env_set *es);
 
 bool openvpn_execve_allowed(const unsigned int flags);
 
-bool openvpn_execve_check(const struct argv *a, const struct env_set *es,
+int openvpn_execve_check(const struct argv *a, const struct env_set *es,
                           const unsigned int flags, const char *error_message);
 
-static inline bool
+/**
+ * Will run a script and return the exit code if it
+ */
+static inline int
 openvpn_run_script(const struct argv *a, const struct env_set *es,
                    const unsigned int flags, const char *hook)
 {
Signature · 1 line
2.26.2
#19 lore raw

PATCH 7/11 Refactor extract_var_peer_info into standalone function and add ssl_util.c

In reply to Arne Schwabe

Our "natural" place for this function would be ssl.c but ssl.c has a lot of dependencies on all kinds of other compilation units so including ssl.c into unit tests is near impossible currently. Instead create a new file ssl_util.c that holds small utility functions like this one.

---
 src/openvpn/Makefile.am              |  1 +
 src/openvpn/openvpn.vcxproj          |  2 +
 src/openvpn/openvpn.vcxproj.filters  |  6 +++
 src/openvpn/ssl.c                    |  2 +-
 src/openvpn/ssl_ncp.c                | 20 ++--------
 src/openvpn/ssl_util.c               | 59 ++++++++++++++++++++++++++++
 src/openvpn/ssl_util.h               | 49 +++++++++++++++++++++++
 src/openvpn/ssl_verify.c             |  1 +
 tests/unit_tests/openvpn/Makefile.am |  3 +-
 9 files changed, 125 insertions(+), 18 deletions(-)
 create mode 100644 src/openvpn/ssl_util.c
 create mode 100644 src/openvpn/ssl_util.h
src/openvpn/Makefile.am +1 -0
index 37b002c6..ec84929b 100644
@@ -119,6 +119,7 @@ openvpn_SOURCES = \
 	ssl_openssl.c ssl_openssl.h \
 	ssl_mbedtls.c ssl_mbedtls.h \
 	ssl_ncp.c ssl_ncp.h \
+	ssl_util.c ssl_util.h \
 	ssl_common.h \
 	ssl_verify.c ssl_verify.h ssl_verify_backend.h \
 	ssl_verify_openssl.c ssl_verify_openssl.h \
src/openvpn/openvpn.vcxproj +2 -0
index 3863854b..cf31940c 100644
@@ -212,6 +212,7 @@
     <ClCompile Include="ssl.c" />
     <ClCompile Include="ssl_openssl.c" />
     <ClCompile Include="ssl_ncp.c" />
+    <ClCompile Include="ssl_util.c" />
     <ClCompile Include="ssl_verify.c" />
     <ClCompile Include="ssl_verify_openssl.c" />
     <ClCompile Include="status.c" />
@@ -300,6 +301,7 @@
     <ClInclude Include="ssl_common.h" />
     <ClInclude Include="ssl_ncp.h" />
     <ClInclude Include="ssl_openssl.h" />
+    <ClInclude Include="ssl_util.h" />
     <ClInclude Include="ssl_verify.h" />
     <ClInclude Include="ssl_verify_backend.h" />
     <ClInclude Include="ssl_verify_openssl.h" />
src/openvpn/openvpn.vcxproj.filters +6 -0
index cf5748c7..e8aed2c5 100644
@@ -243,6 +243,9 @@
     <ClCompile Include="ssl_ncp.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="ssl_util.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="base64.h">
@@ -509,6 +512,9 @@
     <ClInclude Include="ssl_ncp.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="ssl_util.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="openvpn_win32_resources.rc">
src/openvpn/ssl.c +1 -1
index f0664a0f..a125afa2 100644
@@ -4138,4 +4138,4 @@ delayed_auth_pass_purge(void)
 {
     auth_user_pass.wait_for_push = false;
     purge_user_pass(&auth_user_pass, false);
-}
+}
\ No newline at end of file
src/openvpn/ssl_ncp.c +4 -16
index 55496395..f4d755af 100644
@@ -48,6 +48,7 @@
 #include "common.h"
 
 #include "ssl_ncp.h"
+#include "ssl_util.h"
 #include "openvpn.h"
 
 /**
@@ -181,23 +182,10 @@ const char *
 tls_peer_ncp_list(const char *peer_info, struct gc_arena *gc)
 {
     /* Check if the peer sends the IV_CIPHERS list */
-    const char *ncp_ciphers_start;
-    if (peer_info && (ncp_ciphers_start = strstr(peer_info, "IV_CIPHERS=")))
+    const char *iv_ciphers = extract_var_peer_info(peer_info,"IV_CIPHERS=", gc);
+    if (iv_ciphers)
     {
-        ncp_ciphers_start += strlen("IV_CIPHERS=");
-        const char *ncp_ciphers_end = strstr(ncp_ciphers_start, "\n");
-        if (!ncp_ciphers_end)
-        {
-            /* IV_CIPHERS is at end of the peer_info list and no '\n'
-             * follows */
-            ncp_ciphers_end = ncp_ciphers_start + strlen(ncp_ciphers_start);
-        }
-
-        char *ncp_ciphers_peer = string_alloc(ncp_ciphers_start, gc);
-        /* NULL terminate the copy at the right position */
-        ncp_ciphers_peer[ncp_ciphers_end - ncp_ciphers_start] = '\0';
-        return ncp_ciphers_peer;
-
+        return iv_ciphers;
     }
     else if (tls_peer_info_ncp_ver(peer_info)>=2)
     {
src/openvpn/ssl_util.c new file +59 -0

60 lines not on this page · raw message

src/openvpn/ssl_util.h new file +49 -0

50 lines not on this page · raw message

src/openvpn/ssl_verify.c +1 -0
index 97ccb93b..e7e62afa 100644
@@ -46,6 +46,7 @@
 #endif
 #include "auth_token.h"
 #include "push.h"
+#include "ssl_util.h"
 
 /** Maximum length of common name */
 #define TLS_USERNAME_LEN 64
tests/unit_tests/openvpn/Makefile.am +2 -1
index f0880a6b..50f3a02e 100644
@@ -125,4 +125,5 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \
 	$(openvpn_srcdir)/crypto_openssl.c \
 	$(openvpn_srcdir)/otime.c \
 	$(openvpn_srcdir)/packet_id.c \
-	$(openvpn_srcdir)/platform.c
+	$(openvpn_srcdir)/platform.c \
+	$(openvpn_srcdir)/ssl_util.c
Signature · 1 line
2.26.2
#21 lore raw

PATCH 8/11 Allow pending auth to be send from a auth plugin

In reply to Arne Schwabe
---
 doc/man-sections/generic-options.rst |   3 +-
 include/openvpn-plugin.h.in          |   8 ++
 src/openvpn/ssl.c                    |   2 +-
 src/openvpn/ssl_common.h             |   1 +
 src/openvpn/ssl_verify.c             | 165 ++++++++++++++++++++++++---
 src/openvpn/ssl_verify.h             |   2 +-
 6 files changed, 165 insertions(+), 16 deletions(-)
doc/man-sections/generic-options.rst +2 -1
index d5f08839..32eeda68 100644
@@ -409,7 +409,8 @@ which mode OpenVPN is configured as.
 
   * :code:`OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY` plug-in hooks returns
     success/failure via :code:`auth_control_file` when using deferred auth
-    method
+    method and pending authentification via :code:`pending_auth_file`.
+
 
   * :code:`OPENVPN_PLUGIN_ENABLE_PF` plugin hook to pass filtering rules
     via ``pf_file``
include/openvpn-plugin.h.in +8 -0
index 64b20886..bb561643 100644
@@ -567,6 +567,14 @@ OPENVPN_PLUGIN_DEF openvpn_plugin_handle_t OPENVPN_PLUGIN_FUNC(openvpn_plugin_op
  * auth_control_file/client_connect_deferred_file
  * in the environmental variable list (envp).
  *
+ * Additionally the auth_pending_file can be written, which causes the openvpn
+ * server to send a pending auth request to the client. See doc/management.txt
+ * for more details on this authentication mechanism. The format of the
+ * auth_pending_file is
+ * line 1: timeout in seconds
+ * line 2: Pending auth method the client needs to support (e.g. openurl)
+ * line 3: EXTRA (e.g. OPEN_URL:http://www.example.com)
+ *
  * In addition the OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER and
  * OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2 are called when OpenVPN tries to
  * get the deferred result. For a V2 call implementing this function is
src/openvpn/ssl.c +1 -1
index a125afa2..815f896e 100644
@@ -994,7 +994,7 @@ key_state_free(struct key_state *ks, bool clear)
     packet_id_free(&ks->crypto_options.packet_id);
 
 #ifdef PLUGIN_DEF_AUTH
-    key_state_rm_auth_control_file(ks);
+    key_state_rm_auth_control_files(ks);
 #endif
 
     if (clear)
src/openvpn/ssl_common.h +1 -0
index 7ccd1abb..98afc88c 100644
@@ -216,6 +216,7 @@ struct key_state
     unsigned int auth_control_status;
     time_t acf_last_mod;
     char *auth_control_file;
+    char *auth_pending_file;
 #endif
 };
 
src/openvpn/ssl_verify.c +152 -13

225 lines not on this page · raw message

src/openvpn/ssl_verify.h +1 -1
index b1ced956..5b413c57 100644
@@ -93,7 +93,7 @@ int tls_authentication_status(struct tls_multi *multi, const int latency);
  *
  * @param ks    The key state the remove the file for
  */
-void key_state_rm_auth_control_file(struct key_state *ks);
+void key_state_rm_auth_control_files(struct key_state *ks);
 
 /**
  * Frees the given set of certificate hashes.
Signature · 1 line
2.26.2
#23 lore raw

PATCH 9/11 Implement deferred auth for scripts

In reply to Arne Schwabe
---
 Changes.rst                         |  9 +++++
 doc/man-sections/script-options.rst | 14 +++++++-
 src/openvpn/ssl_verify.c            | 56 ++++++++++++++++++++++++-----
 3 files changed, 70 insertions(+), 9 deletions(-)
Changes.rst +9 -0
index f67e1d76..7e60eb64 100644
@@ -1,3 +1,12 @@
+Overview of changes in 2.6
+==========================
+
+
+New features
+------------
+Deferred auth support for scripts
+    The ``--auth-user-pass-verify`` script supports now deferred authentication.
+
 Overview of changes in 2.5
 ==========================
 
doc/man-sections/script-options.rst +13 -1
index a4df6732..e0cc10c2 100644
@@ -90,7 +90,19 @@ SCRIPT HOOKS
 
   The script should examine the username and password, returning a success
   exit code (:code:`0`) if the client's authentication request is to be
-  accepted, or a failure code (:code:`1`) to reject the client.
+  accepted, a failure code (:code:`1`) to reject the client, or a that
+  the authentication is deferred (:code:`2`). If the authentication is
+  deferred, the script must fork/start a background or another non-blocking
+  operation to continue the authentication in the background. When finshing
+  the authentication, a :code:`1` or :code:`0` must be written to the
+  file specified by the :code:`auth_control_file`.
+
+  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
+  seconds and the second line the EXTRA as documented in the
+  ``client-pending-auth`` section of `doc/management.txt`.
+
 
   This directive is designed to enable a plugin-style interface for
   extending OpenVPN's authentication capabilities.
src/openvpn/ssl_verify.c +48 -8

100 lines not on this page · raw message

Signature · 1 line
2.26.2
#26 lore raw

PATCH 10/11 Implement --client-crresponse script options and plugin interface

In reply to Arne Schwabe

This is allows scripts and pluginsto parse/react to a CR_RESPONSE message

---
 Changes.rst                         |  7 ++++
 doc/man-sections/script-options.rst | 28 ++++++++++++-
 include/openvpn-plugin.h.in         |  7 +++-
 src/openvpn/init.c                  |  1 +
 src/openvpn/options.c               | 15 +++++++
 src/openvpn/options.h               |  1 +
 src/openvpn/push.c                  |  4 ++
 src/openvpn/ssl_common.h            |  1 +
 src/openvpn/ssl_verify.c            | 63 +++++++++++++++++++++++++++++
 src/openvpn/ssl_verify.h            | 23 +++++++++++
 10 files changed, 147 insertions(+), 3 deletions(-)
Changes.rst +7 -0
index 7e60eb64..0717c349 100644
@@ -7,6 +7,13 @@ New features
 Deferred auth support for scripts
     The ``--auth-user-pass-verify`` script supports now deferred authentication.
 
+Pending auth support for plugins and scripts
+    Both auth plugin and script can now signal pending authentication to
+    the client when using deferred authentication. The new ``client-crresponse``
+    script option and ``OPENVPN_PLUGIN_CLIENT_CRRESPONSE`` plugin function can
+    be used to parse a client response to a ``CR_TEXT`` two factor challenge.
+
+
 Overview of changes in 2.5
 ==========================
 
doc/man-sections/script-options.rst +26 -2
index e0cc10c2..66bf3662 100644
@@ -52,6 +52,11 @@ Script Order of Execution
    Executed in ``--mode server`` mode on new client connections, when the
    client is still untrusted.
 
+#. ``--client-crresponse``
+
+    Execute in ``--mode server`` whenever a client sends a
+    :code:`CR_RESPONSE` message
+
 SCRIPT HOOKS
 ------------
 
@@ -72,7 +77,7 @@ SCRIPT HOOKS
   double-quoted and/or escaped using a backslash, and should be separated
   by one or more spaces.
 
-  If ``method`` is set to :code:`via-env`, OpenVPN will call ``script``
+  If ``method`` is set to :code:`via-env`, OpenVPN will call ``cmd``
   with the environmental variables :code:`username` and :code:`password`
   set to the username/password strings provided by the client. *Beware*
   that this method is insecure on some platforms which make the environment
@@ -80,7 +85,7 @@ SCRIPT HOOKS
 
   If ``method`` is set to :code:`via-file`, OpenVPN will write the username
   and password to the first two lines of a temporary file. The filename
-  will be passed as an argument to ``script``, and the file will be
+  will be passed as an argument to ``cmd``, and the file will be
   automatically deleted by OpenVPN after the script returns. The location
   of the temporary file is controlled by the ``--tmp-dir`` option, and
   will default to the current directory if unspecified. For security,
@@ -123,6 +128,25 @@ SCRIPT HOOKS
   For a sample script that performs PAM authentication, see
   :code:`sample-scripts/auth-pam.pl` in the OpenVPN source distribution.
 
+--client-crresponse
+    Executed when the client sends a text based challenge response.
+
+    Valid syntax:
+    ::
+
+        client-crresponse cmd method
+
+  OpenVPN will write the response of the client into a temporary file.
+  The filename will be passed as an argument to ``cmd``, and the file will be
+  automatically deleted by OpenVPN after the script returns.
+
+  The response is passed as is from the client. The script needs to check
+  itself if the input is valid, e.g. if the input is valid base64 encoding.
+
+  The script can either directly write the result of the verification to
+  :code:`auth_control_file or further defer it. See ``--auth-user-pass-verify``
+  for details.
+
 --client-connect cmd
   Run command ``cmd`` on client connection.
 
include/openvpn-plugin.h.in +6 -1
index bb561643..62e3c3b7 100644
@@ -84,6 +84,10 @@ extern "C" {
  * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_CLIENT_CONNECT_V2
  * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_LEARN_ADDRESS
  *
+ * The OPENVPN_PLUGIN_CLIENT_CRRESPONSE function is called when the client sends
+ * the CR_RESPONSE message, this is *typically* after OPENVPN_PLUGIN_TLS_FINAL
+ * but may also occur much later.
+ *
  * [Client session ensues]
  *
  * For each "TLS soft reset", according to reneg-sec option (or similar):
@@ -131,7 +135,8 @@ extern "C" {
 #define OPENVPN_PLUGIN_ROUTE_PREDOWN            12
 #define OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER     13
 #define OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2  14
-#define OPENVPN_PLUGIN_N                        15
+#define OPENVPN_PLUGIN_CLIENT_CRRESPONSE        15
+#define OPENVPN_PLUGIN_N                        16
 
 /*
  * Build a mask out of a set of plug-in types.
src/openvpn/init.c +1 -0
index d1ad5c8f..6597b66a 100644
@@ -2940,6 +2940,7 @@ do_init_crypto_tls(struct context *c, const unsigned int flags)
 
     to.auth_user_pass_verify_script = options->auth_user_pass_verify_script;
     to.auth_user_pass_verify_script_via_file = options->auth_user_pass_verify_script_via_file;
+    to.client_crresponse_script = options->client_crresponse_script;
     to.tmp_dir = options->tmp_dir;
     if (options->ccd_exclusive)
     {
src/openvpn/options.c +15 -0
index 3df803db..703927da 100644
@@ -1286,6 +1286,7 @@ show_p2mp_parms(const struct options *o)
     SHOW_STR(client_connect_script);
     SHOW_STR(learn_address_script);
     SHOW_STR(client_disconnect_script);
+    SHOW_STR(client_crresponse_script);
     SHOW_STR(client_config_dir);
     SHOW_BOOL(ccd_exclusive);
     SHOW_STR(tmp_dir);
@@ -2427,6 +2428,10 @@ options_postprocess_verify_ce(const struct options *options, const struct connec
         {
             msg(M_USAGE, "--client-connect requires --mode server");
         }
+        if (options->client_crresponse_script)
+        {
+            msg(M_USAGE, "--client-crresponse requires --mode server");
+        }
         if (options->client_disconnect_script)
         {
             msg(M_USAGE, "--client-disconnect requires --mode server");
@@ -7070,6 +7075,16 @@ add_option(struct options *options,
         set_user_script(options, &options->client_connect_script,
                         p[1], "client-connect", true);
     }
+    else if (streq(p[0], "client-crresponse") && p[1])
+    {
+        VERIFY_PERMISSION(OPT_P_SCRIPT);
+        if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
+        {
+            goto err;
+        }
+        set_user_script(options, &options->client_crresponse_script,
+                        p[1], "client-crresponse", true);
+    }
     else if (streq(p[0], "client-disconnect") && p[1])
     {
         VERIFY_PERMISSION(OPT_P_SCRIPT);
src/openvpn/options.h +1 -0
index 877e9396..a63a1967 100644
@@ -440,6 +440,7 @@ struct options
     const char *client_connect_script;
     const char *client_disconnect_script;
     const char *learn_address_script;
+    const char *client_crresponse_script;
     const char *client_config_dir;
     bool ccd_exclusive;
     bool disable;
src/openvpn/push.c +4 -0
index 58e20baa..e5c92e17 100644
@@ -227,6 +227,10 @@ receive_cr_response(struct context *c, const struct buffer *buffer)
 
 
     management_notify_client_cr_response(key_id, mda, es, m);
+#endif
+#if ENABLE_PLUGIN
+    verify_crresponse_plugin(c->c2.tls_multi, m);
+    verify_crresponse_script(c->c2.tls_multi, m);
 #endif
     msg(D_PUSH, "CR response was sent by client ('%s')", m);
 }
src/openvpn/ssl_common.h +1 -0
index 98afc88c..87877c88 100644
@@ -314,6 +314,7 @@ struct tls_options
 
     /* used for username/password authentication */
     const char *auth_user_pass_verify_script;
+    const char *client_crresponse_script;
     bool auth_user_pass_verify_script_via_file;
     const char *tmp_dir;
     const char *auth_user_pass_file;
src/openvpn/ssl_verify.c +63 -0

69 lines not on this page · raw message

src/openvpn/ssl_verify.h +23 -0
index 5b413c57..f355053a 100644
@@ -185,6 +185,29 @@ tls_common_name_hash(const struct tls_multi *multi, const char **cn, uint32_t *c
 void verify_user_pass(struct user_pass *up, struct tls_multi *multi,
                       struct tls_session *session);
 
+
+
+/**
+ * Runs the --client-crresponse script if one is defined.
+ *
+ * As with the management interface the script is stateless in the sense that
+ * it does not directly participate in the authentication but rather should set
+ * the files for the deferred auth like the management commands.
+ *
+ */
+void
+verify_crresponse_script(struct tls_multi *multi, const char *cr_response);
+
+/**
+ * Call the plugin OPENVPN_PLUGIN_CLIENT_CRRESPONSE.
+ *
+ * As with the management interface calling the plugin is stateless in the sense
+ * that it does not directly participate in the authentication but rather
+ * should set the files for the deferred auth like the management commands.
+ */
+void
+verify_crresponse_plugin(struct tls_multi *multi, const char *cr_response);
+
 /**
  * Perform final authentication checks, including locking of the cn, the allowed
  * certificate hashes, and whether a client config entry exists in the
Signature · 1 line
2.26.2
#28 lore raw

PATCH 11/11 Add example script demonstrating TOTP via auth-pending

In reply to Arne Schwabe
---
 Changes.rst                         |   2 +
 doc/man-sections/script-options.rst |   3 +
 sample/sample-scripts/totpauth.py   | 107 ++++++++++++++++++++++++++++
 3 files changed, 112 insertions(+)
 create mode 100755 sample/sample-scripts/totpauth.py
Changes.rst +2 -0
index 0717c349..7b7d1491 100644
@@ -13,6 +13,8 @@ Pending auth support for plugins and scripts
     script option and ``OPENVPN_PLUGIN_CLIENT_CRRESPONSE`` plugin function can
     be used to parse a client response to a ``CR_TEXT`` two factor challenge.
 
+    See ``sample/sample-scripts/totpauth.py`` for an example.
+
 
 Overview of changes in 2.5
 ==========================
doc/man-sections/script-options.rst +3 -0
index 66bf3662..fff3d166 100644
@@ -147,6 +147,9 @@ SCRIPT HOOKS
   :code:`auth_control_file or further defer it. See ``--auth-user-pass-verify``
   for details.
 
+  For a sample script that implement TOTP (RFC 6238) based two-factor
+  authentication, see :code:`sample-scripts/totp.py`.
+
 --client-connect cmd
   Run command ``cmd`` on client connection.
 
sample/sample-scripts/totpauth.py new file +107 -0

107 lines not on this page · raw message

Signature · 1 line
2.26.2
#2 lore raw

Re: [Openvpn-devel] [PATCH] Allow 'none' cipher being specified in --data-ciphers

In reply to Arne Schwabe

Hi,

Quoted 11 lines · Arne Schwabe

Although we want to get rid of none as cipher, we still have not deprecated it. In order to use it currently you need --ncp-disable together with --cipher none to use the none cipher.

In our current situation allowing none to be specified in data-ciphers is the lesser evil.

This commit also fixes that we use '[null-cipher]' instead 'none' when setting remote_cipher

Patch V2: Also work correctly if remote_cipher is NULL.

I was about to ACK-and-merge it, but it fails the "ping IPv4 with 3000 bytes" test, triggering

2020-10-04 15:10:58 us=638418 cron2-freebsd-tc-amd64/2001:608:0:814::f000:21 TCP/UDP packet too large on write to [AF_INET6]2001:608:0:814::f000:21:50629 (tried=1529,max=1526)

on the server side.

"Wat?"

(I could speculate that this was always broken for --cipher none, but since you've made me add two new testcases for it, I want this to actually work...)

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

Re: [Openvpn-devel] [PATCH] Allow 'none' cipher being specified in --data-ciphers

Hi,

Quoted 1 line · Gert Doering

"Wat?"

Also, the unit test fails for me (on Linux):

[ RUN ] test_poor_man
[ ERROR ] --- Test failed with exception: Segmentation fault(11)

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

PATCH v3 1/1 Allow 'none' cipher being specified in --data-ciphers

In reply to Arne Schwabe

Although we want to get rid of none as cipher, we still have not deprecated it. In order to use it currently you need --ncp-disable together with --cipher none to use the none cipher otherwise OpenVPN will spit out an error about an unrecognised cipher in --data-ciphers.

In our current situation allowing none to be specified in data-ciphers is the lesser evil.

This commit also fixes that we use '[null-cipher]' instead 'none' when setting remote_cipher.

Note that negotiating to cipher 'none' can the same the same problems with frame size calculation as any other non AEAD cipher. If --cipher none is also specified in the configuration, the workaround of commit e539c95dc will also apply to cipher none.

Patch V2: Also work correctly if remote_cipher is NULL. Patch V3: fix unit tests, add note about corner case

---
 src/openvpn/ssl.c                   |  8 ++++++++
 src/openvpn/ssl_ncp.c               | 16 +++++++++++++++-
 tests/unit_tests/openvpn/test_ncp.c | 14 ++++++++++++--
 3 files changed, 35 insertions(+), 3 deletions(-)
src/openvpn/ssl.c +8 -0
index 3535fc72..f90c6a85 100644
@@ -2554,6 +2554,14 @@ key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_sessio
     multi->remote_ciphername =
         options_string_extract_option(options, "cipher", NULL);
 
+    /* In OCC we send '[null-cipher]' instead 'none' */
+    if (multi->remote_ciphername
+        && strcmp(multi->remote_ciphername, "[null-cipher]") == 0)
+    {
+        free(multi->remote_ciphername);
+        multi->remote_ciphername = string_alloc("none", NULL);
+    }
+
     if (tls_session_user_pass_enabled(session))
     {
         /* Perform username/password authentication */
src/openvpn/ssl_ncp.c +15 -1
index 55496395..c8229044 100644
@@ -110,7 +110,15 @@ mutate_ncp_cipher_list(const char *list, struct gc_arena *gc)
          * e.g. replacing AeS-128-gCm with AES-128-GCM
          */
         const cipher_kt_t *ktc = cipher_kt_get(token);
-        if (!ktc)
+        if (strcmp(token, "none") == 0)
+        {
+            msg(M_WARN, "WARNING: cipher 'none' specified for --data-ciphers. "
+                        "This allows negotiation of NO encryption and "
+                        "tunnelled data WILL then be transmitted in clear text "
+                        "over the network! "
+                        "PLEASE DO RECONSIDER THIS SETTING!");
+        }
+        if (!ktc && strcmp(token, "none")!= 0)
         {
             msg(M_WARN, "Unsupported cipher in --data-ciphers: %s", token);
             error_found = true;
@@ -118,6 +126,12 @@ mutate_ncp_cipher_list(const char *list, struct gc_arena *gc)
         else
         {
             const char *ovpn_cipher_name = cipher_kt_name(ktc);
+            if (ktc == NULL)
+            {
+                /* NULL resolves to [null-cipher] but we need none for
+                 * data-ciphers */
+                ovpn_cipher_name = "none";
+            }
 
             if (buf_len(&new_list)> 0)
             {
tests/unit_tests/openvpn/test_ncp.c +12 -2
index a4334c89..4077be5e 100644
@@ -50,7 +50,9 @@ test_check_ncp_ciphers_list(void **state)
     struct gc_arena gc = gc_new();
     bool have_chacha = cipher_kt_get("CHACHA20-POLY1305");
 
-
+    assert_string_equal(mutate_ncp_cipher_list("none", &gc), "none");
+    assert_string_equal(mutate_ncp_cipher_list("AES-256-GCM:none", &gc),
+                        "AES-256-GCM:none");
 
     assert_string_equal(mutate_ncp_cipher_list(aes_ciphers, &gc), aes_ciphers);
 
@@ -139,7 +141,7 @@ test_poor_man(void **state)
     char *best_cipher;
 
     const char *serverlist = "CHACHA20_POLY1305:AES-128-GCM";
-    const char *serverlistbfcbc = "CHACHA20_POLY1305:AES-128-GCM:BF-CBC";
+    const char *serverlistbfcbc = "CHACHA20_POLY1305:AES-128-GCM:BF-CBC:none";
 
     best_cipher = ncp_get_best_cipher(serverlist,
                                       "IV_YOLO=NO\nIV_BAR=7",
@@ -166,6 +168,14 @@ test_poor_man(void **state)
 
     assert_string_equal(best_cipher, "AES-128-GCM");
 
+    best_cipher = ncp_get_best_cipher(serverlist, NULL,
+                                      "none", &gc);
+    assert_ptr_equal(best_cipher, NULL);
+
+    best_cipher = ncp_get_best_cipher(serverlistbfcbc, NULL,
+                                      "none", &gc);
+    assert_string_equal(best_cipher, "none");
+
     best_cipher = ncp_get_best_cipher(serverlist, NULL,NULL, &gc);
     assert_ptr_equal(best_cipher, NULL);
 
Signature · 1 line
2.26.2
Acked-by on v3 1/1
#5 lore raw

[Openvpn-devel] [PATCH applied] Re: Allow 'none' cipher being specified in --data-ciphers

I have added two new cases to my server test suite: client with "--data-ciphers none" and "--ncp-disable --cipher none", against a server instance that permits "none" as part of its data-ciphers.

The first case failed on the client side ("unrecognized
cipher: none"), the second case was refused by the server side ("No common cipher... client supports cipher '[null-cipher]').

Of course the server side *also* needs the patch to accept "none" as part of --data-ciphers :-)

Then, this works:

2020-10-04 15:04:28 us=208824 2001:608:4:0:669a:56c1:4175:2c5b peer info: IV_CIPHERS=none
2020-10-04 15:04:28 us=251968 Data Channel: using negotiated cipher 'none'
2020-10-04 15:04:28 us=252006 ******* WARNING *******: '--cipher none' was ...

The warning in the logs is very clear and explicit - and I think this is good. This is a very special-use setting, and should only be used with sufficient information and consideration.

Big IPv4 packets (t_client test with 3000 bytes) do not work - something is wrong in our mtu/overhead calcululation. But this is not something new (as the v3 commit message rightly points out) - if I do "client connects with --data-cipher DES-EDE3-CBC" (non AEAD) I get the same

TCP/UDP packet too large on write to ... (tried=1544,max=1542)

error as I have with "none" (there, it is tried=1529,max=1526). Strange enough this only happens for IPv4 packets.

Your patch has been applied to the master and release/2.5 branch.

commit c018fc00be25aee5921d234531f87753a3a7aec7 (master) commit f308251acdc539acb370aeccf46b0ec5587129c1 (release/2.5)

Author: Arne Schwabe
Date:   Thu Oct 8 13:59:59 2020 +0200
     Allow 'none' cipher being specified in --data-ciphers

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

--
kind regards,

Gert Doering

#7 lore raw

Re: [Openvpn-devel] [PATCH 01/11] Change pull request timeout use a timeout rather than a number

In reply to Arne Schwabe

Hi,

Quoted 1 line

+ The ``--hand-window`` parameter also controls the amount of of time that

"of of"

doc/man-sections/tls-options.rst certificates and keys: https://github.com/OpenVPN/easy-rsa · line 205

Quoted 2 lines
doc/man-sections/tls-options.rst +2 -0
+  the OpenVPN client repeats the pull request until it times out on pull
+  requests until giving up.

Looks like repetition. Just leave " repeats the pull request until it times out" ?

#9 lore raw

Re: [Openvpn-devel] [PATCH 02/11] Implement client side handling of AUTH_PENDING message

In reply to Arne Schwabe

Hi,

Please not that I got errors applying this patch, so I reviewed
corresponding commit
from github (https://github.com/schwabe/openvpn/commit/3901e46127a2db3e6dfb20c44e8d8e30adea58c7).

doc/management-notes.txt to signal a pending authenticating to the client. A pending auth means · line 613

Quoted 2 lines
doc/management-notes.txt +2 -0
+Receiving a AUTH_PENDING message will make the client change its timeout the
+timeout proposed by the server, even if the timeout is shorter.

Typo.

src/openvpn/integer.h line 43

Quoted 5 lines

/*
* min/max functions
*/

src/openvpn/integer.h +2 -0
+static inline unsigned int
+max_uint(unsigned int x, unsigned int y)

It is 2021 and we have to write our own min/max :(

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

Quoted 6 lines
src/openvpn/push.c +6 -0
+    while (buf_parse(&buf, ',', line, sizeof(line)))
+    {
+        if (sscanf(line, "timeout %u", server_timeout) == 1)
+        {
+            ;
+        }

This looks odd. Why not reverting if and getting rid of this empty "then" branch?

Quoted 1 line

+ time_t peer_last_packet; /* Last time we received a paket in this control session */

Typo.

Thanks for the in-line comments, code is much nicer to read this way.

Waiting for typo fixes and rebase to ACK.

Signature · 1 line
-Lev
#12 lore raw

Re: [Openvpn-devel] [PATCH 03/11] Implement server side of AUTH_PENDING with extending timeout

In reply to Arne Schwabe

Hi,

Note that I didn't manage to apply this patch on the latest master so I had to apply commit from
https://github.com/schwabe/openvpn/commit/42ae41d812668c4c00badaf592825684fa387d9d

Quoted 2 lines
src/openvpn/manage.c +2 -0
+static bool
+parse_kid(const char *str, unsigned int *kid)

<snip>

Quoted 1 line

+ && parse_uint(timeout_str, "TIMEOUT", &timeout))

Since you've added wrapper "parse_kid", why not add "parse_timeout" for consistency?

Quoted 19 lines

+ bool ret = send_auth_pending_messages(&mi->context, extra, timeout);

C:\Users\lev\Projects\openvpn\src\openvpn\multi.c(3907,68): error C2220: the following warning is treated as an error C:\Users\lev\Projects\openvpn\src\openvpn\multi.c(3907,68): warning C4020: 'send_auth_pending_messages': too many actual parameters

src/openvpn/push.c +3 -2
-send_auth_pending_messages(struct context *c, const char *extra)
+send_auth_pending_messages(struct context *c, const char *extra,
+                           unsigned int timeout)
 {
-    send_control_channel_string(c, "AUTH_PENDING", D_PUSH);
+    struct key_state *ks = &tls_multi->session[TM_ACTIVE].key[KS_PRIMARY];

C:\Users\lev\Projects\openvpn\src\openvpn\push.c(354,1): error C2220: the following warning is treated as an error C:\Users\lev\Projects\openvpn\src\openvpn\push.c(354,1): warning C4029: declared formal parameter list different from definition C:\Users\lev\Projects\openvpn\src\openvpn\push.c(355,38): error C2065: 'tls_multi': undeclared identifier C:\Users\lev\Projects\openvpn\src\openvpn\push.c(355,40): error C2223: left of '->session' must point to struct/union

+ size_t len = 20 + 1 + sizeof(auth_pre);

<snip>

Quoted 1 line
     size_t len = strlen(extra)+1 + sizeof(info_pre);

Whitespace inconsistency.

src/openvpn/push.c remove_iroutes_from_push_route_list(struct options *o) · line 1049

Quoted 5 lines
src/openvpn/push.c +5 -0
+unsigned int
+extract_iv_proto(const char *peer_info)
+{
+
+    const char *optstr = peer_info ? strstr(peer_info, "IV_PROTO=") : NULL;

Unnecessary line break.

Signature · 1 line
-Lev
Acked-by on v1 5/11
#16 lore raw

Re: [Openvpn-devel] [PATCH 05/11] Change parameter of send_auth_pending_messages from context to tls_multi

In reply to Arne Schwabe

Hi,

Quoted 3 lines

+/**
+ * Reschedule tls_multi_process.
+ * NOTE: in multi-client mode, usually the below two statements are

I realize that this comment is copied from existing code, but "below two statements" is bit misleading here in the context of function definition. Maybe just "this function" ?

Stared at the code, compiled with MSVC.

Signature · 1 line
-Lev
Acked-by on v1 6/11
#18 lore raw

Re: [Openvpn-devel] [PATCH 06/11] Add S_EXITCODE flag for openvpn_run_script to report exit code

In reply to Arne Schwabe

Hi,

src/openvpn/platform.c platform_system_ok(int stat) · line 248

Quoted 4 lines
src/openvpn/platform.c +4 -0
+platform_ret_code(int stat)
+{
+
+    if (stat >= 0 && stat < 255)

Unneeded line break.

src/openvpn/platform.h void platform_mlockall(bool print_msg); /* Disable paging */ · line 126

Quoted 6 lines
src/openvpn/platform.h +3 -1
-/* interpret the status code returned by execve() */
+/** interpret the status code returned by execve() */
 bool platform_system_ok(int stat);
 
+/** Return a return code if valid and between 0 and 255, -1 otherwise */
+int platform_ret_code(int stat);

"Return a return code" looks odd. Maybe "status code" or "exit code" ?

Quoted 1 line

+ if(flags & S_EXITCODE)

Missing whitespace after if.

Quoted 3 lines

+/**
+ * Will run a script and return the exit code if it
+ */

"If it" what?

Assuming committer will fix those nit-picks (especially last one),

Acked-by on v1 7/11
#20 lore raw

Re: [Openvpn-devel] [PATCH 07/11] Refactor extract_var_peer_info into standalone function and add ssl_util.c

In reply to Arne Schwabe

Hi,

Both new files have

Quoted 2 lines

+}
\ No newline at end of file

Can probably be fixed by the committer.

Stared at the come, compiled with MSVC.
No "brand new" code added, just existing one factored out into a separate function and generalized.

Acked with distinction for updating MSVC project files.

#22 lore raw

Re: [Openvpn-devel] [PATCH 08/11] Allow pending auth to be send from a auth plugin

In reply to Arne Schwabe
Quoted 10 lines · Arne Schwabe
---
  doc/man-sections/generic-options.rst |   3 +-
  include/openvpn-plugin.h.in          |   8 ++
  src/openvpn/ssl.c                    |   2 +-
  src/openvpn/ssl_common.h             |   1 +
  src/openvpn/ssl_verify.c             | 165 ++++++++++++++++++++++++---
  src/openvpn/ssl_verify.h             |   2 +-
  6 files changed, 165 insertions(+), 16 deletions(-)

So far just glared at the code, but the change below needs to be fixed first. This patchset has also aged so much it does no longer apply on top of latest git master.

[...snip...]

src/openvpn/ssl_verify.c[...snip...] verify_user_pass_script(struct tls_session *session, struct tls_multi *multi, · line 1199

Quoted 10 lines
src/openvpn/ssl_verify.c[...snip...] renamed from src/openvpn/ssl_verify.c +1 -1
index e7e62afa..fc3a1116 100644
@@ -1067,7 +1196,7 @@ verify_user_pass_script(struct tls_session *session, struct tls_multi *multi,
      struct gc_arena gc = gc_new();
      struct argv argv = argv_new();
      const char *tmp_file = "";
-    bool ret = false;
+    bool ret = OPENVPN_PLUGIN_FUNC_ERROR;

This is wrong. OPENVPN_PLUGIN_FUNC_ERROR is 1, which means "true". I see this is being corrected again in the next patch; but lets make it correct from the beginning to avoid making a potential bisect in the future more confusing than needed.

The rest of the code looks reasonable. I've not tested it yet, as there are some merge conflicts now. Since the surrounding code has changed a bit since this patch series , I consider it a bit risky to conclude on testing this on a older code base without many of the fixes in between in place.

Most of the merge conflicts is probably related to commit 99d217b20064 (removing --disable-def-auth), but there are other AUTH related changes as well. This needs to be carefully tested with all these auth changes in place too.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#24 lore raw

Re: [Openvpn-devel] [PATCH 09/11] Implement deferred auth for scripts

In reply to Arne Schwabe
Quoted 7 lines · Arne Schwabe
---
  Changes.rst                         |  9 +++++
  doc/man-sections/script-options.rst | 14 +++++++-
  src/openvpn/ssl_verify.c            | 56 ++++++++++++++++++++++++-----
  3 files changed, 70 insertions(+), 9 deletions(-)

Only glared at the code here too. In addition to prior merge conflicts, commit bbcada8abb410 seems to add even more confusion when applying this patch.

Changes.rst

Quoted 4 lines
Changes.rst +0 -0
index f67e1d76..7e60eb64 100644

Ignoring merge conflicts here though. Not important in this round.

Quoted 8 lines
src/openvpn/ssl_verify.c +0 -0
index fc3a1116..5e15fa32 100644
@@ -1189,14 +1189,14 @@ tls_authenticate_key(struct tls_multi *multi, const unsigned int mda_key_id, con
  /*
   * Verify the user name and password using a script
   */

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

Quoted 10 lines
src/openvpn/ssl_verify.c +2 -2
-static bool
+static int
  verify_user_pass_script(struct tls_session *session, struct tls_multi *multi,
                          const struct user_pass *up)
  {
      struct gc_arena gc = gc_new();
      struct argv argv = argv_new();
      const char *tmp_file = "";
-    bool ret = OPENVPN_PLUGIN_FUNC_ERROR;
+    int retval = OPENVPN_PLUGIN_FUNC_ERROR;

Good fixing this mistake from previous round, but incorrect indenting.

Quoted 6 lines
src/openvpn/ssl_verify.c +0 -0
      /* Is username defined? */
      if ((session->opt->ssl_flags & SSLF_AUTH_USER_PASS_OPTIONAL) || strlen(up->username))
@@ -1247,10 +1247,45 @@ verify_user_pass_script(struct tls_session *session, struct tls_multi *multi,
          argv_parse_cmd(&argv, session->opt->auth_user_pass_verify_script);
          argv_printf_cat(&argv, "%s", tmp_file);

src/openvpn/ssl_verify.c verify_user_pass_script(struct tls_session *session, struct tls_multi *multi, · line 1256

Quoted 10 lines
src/openvpn/ssl_verify.c +6 -2
 
+        /* Add files needed for deferred auth */
+        key_state_gen_auth_control_files(&session->key[KS_PRIMARY],
+                                         session->opt);
+
          /* call command */
-        ret = openvpn_run_script(&argv, session->opt->es, 0,
-                                 "--auth-user-pass-verify");
+        int script_ret = openvpn_run_script(&argv, session->opt->es, S_EXITCODE,
+                                            "--auth-user-pass-verify");

Perhaps move the retval declaration down here, as we're touching it anyhow? This switch() is the first place we use it, unless I'm overlooking something.

Quoted 12 lines
src/openvpn/ssl_verify.c +12 -0
+        switch (script_ret)
+        {
+           case 0:
+               retval = OPENVPN_PLUGIN_FUNC_SUCCESS;
+               break;
+           case 2:
+               retval = OPENVPN_PLUGIN_FUNC_DEFERRED;
+               break;
+           default:
+               retval = OPENVPN_PLUGIN_FUNC_ERROR;
+               break;
+           }

[...snip...]

src/openvpn/ssl_verify.c verify_user_pass(struct user_pass *up, struct tls_multi *multi, · line 1444

Quoted 8 lines

/*

src/openvpn/ssl_verify.c +1 -1
@@ -1406,7 +1441,7 @@ verify_user_pass(struct user_pass *up, struct tls_multi *multi,
                   struct tls_session *session)
  {
      int s1 = OPENVPN_PLUGIN_FUNC_SUCCESS;
-    bool s2 = true;
+    int s2 = OPENVPN_PLUGIN_FUNC_SUCCESS;

Indenting issues?

[...snip...]

src/openvpn/ssl_verify.c verify_user_pass(struct user_pass *up, struct tls_multi *multi, · line 1544

Quoted 13 lines
src/openvpn/ssl_verify.c +5 -1
@@ -1499,7 +1534,11 @@ verify_user_pass(struct user_pass *up, struct tls_multi *multi,
  #ifdef PLUGIN_DEF_AUTH
           || s1 == OPENVPN_PLUGIN_FUNC_DEFERRED
  #endif
-         ) && s2
+         ) &&
+        ((s2 == OPENVPN_PLUGIN_FUNC_SUCCESS)
+#ifdef ENABLE_DEF_AUTH
+         || s2 ==  OPENVPN_PLUGIN_FUNC_DEFERRED)
+#endif
  #ifdef MANAGEMENT_DEF_AUTH
          && man_def_auth != KMDA_ERROR
  #endif

Yikes! This if() statement is unreadable. Since you are doing changes here, could we improve this whole logic. Perhaps using a helper macro like this (incorrect code-style, for e-mail readability)

     #define PLUGIN_AUTH_RESULT_PASS(s) \
          (OPENVPN_PLUGIN_FUNC_SUCCESS == s\
           || OPENVPN_PLUGIN_FUNC_DEFERRED == s)

     [...]
     if (PLUGIN_AUTH_RESULT_PASS(s1)
         && PLUGIN_AUTH_RESULT_PASS(s2)
         && tls_lock_username(multi, up->username))
     {
#ifdef ENABLE_MANGEMENT
	if (KMDA_ERROR == man_def_auth)
	{
		/* ... error handling ... */
		goto error;
        }
	if (KMDA_UNDEF == man_def_auth)
	{
		ks->authenticated = KS_AUTH_DEFERRED;
	}

#endif // ENABLE_MANAGEMENT

        /* ... rest of the if block content ... */

	return;  // Success
      }

error:

     /* ... existing error handling from if-else block... */

This is just a quick draft skeleton. Right now the code is pretty messy, and we should improve the code quality on such critical code paths such as user authentication.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#27 lore raw

Re: [Openvpn-devel] [PATCH 10/11] Implement --client-crresponse script options and plugin interface

In reply to Arne Schwabe
Quoted 4 lines · Arne Schwabe

This is allows scripts and pluginsto parse/react to a CR_RESPONSE message

Quoted 13 lines
---
  Changes.rst                         |  7 ++++
  doc/man-sections/script-options.rst | 28 ++++++++++++-
  include/openvpn-plugin.h.in         |  7 +++-
  src/openvpn/init.c                  |  1 +
  src/openvpn/options.c               | 15 +++++++
  src/openvpn/options.h               |  1 +
  src/openvpn/push.c                  |  4 ++
  src/openvpn/ssl_common.h            |  1 +
  src/openvpn/ssl_verify.c            | 63 +++++++++++++++++++++++++++++
  src/openvpn/ssl_verify.h            | 23 +++++++++++
  10 files changed, 147 insertions(+), 3 deletions(-)

Only glared at the code here too.

[...snip...]

doc/man-sections/script-options.rst

Quoted 4 lines
doc/man-sections/script-options.rst +0 -0
index e0cc10c2..66bf3662 100644

[...snip...]
@@ -123,6 +128,25 @@ SCRIPT HOOKS
For a sample script that performs PAM authentication, see :code:sample-scripts/auth-pam.pl in the OpenVPN source distribution.

+--client-crresponse
+    Executed when the client sends a text based challenge response.

+
+ Valid syntax:
+ ::
+
+ client-crresponse cmd method
+

[...snip...]

Quoted 4 lines
src/openvpn/options.c +0 -0
index 3df803db..703927da 100644

[...snip...]

Quoted 4 lines
src/openvpn/options.c +0 -0
@@ -7070,6 +7075,16 @@ add_option(struct options *options,
          set_user_script(options, &options->client_connect_script,
                          p[1], "client-connect", true);
      }

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

Quoted 10 lines
src/openvpn/options.c +10 -0
+    else if (streq(p[0], "client-crresponse") && p[1])
+    {
+        VERIFY_PERMISSION(OPT_P_SCRIPT);
+        if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
+        {
+            goto err;
+        }
+        set_user_script(options, &options->client_crresponse_script,
+                        p[1], "client-crresponse", true);
+    }

Either the doc is wrong, or the option parser is lacking parsing of "method".

[...snip...]

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

Quoted 9 lines
src/openvpn/options.h +1 -0
index 877e9396..a63a1967 100644
@@ -440,6 +440,7 @@ struct options
      const char *client_connect_script;
      const char *client_disconnect_script;
      const char *learn_address_script;
+    const char *client_crresponse_script;

Indentation.

[...snip...]

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

Quoted 12 lines
src/openvpn/push.c +4 -0
index 58e20baa..e5c92e17 100644
@@ -227,6 +227,10 @@ receive_cr_response(struct context *c, const struct buffer *buffer)
 
 
      management_notify_client_cr_response(key_id, mda, es, m);
+#endif
+#if ENABLE_PLUGIN
+    verify_crresponse_plugin(c->c2.tls_multi, m);
+    verify_crresponse_script(c->c2.tls_multi, m);

Any reason the script feature is insdie the ENABLE_PLUGIN fence?

[...snip...]

src/openvpn/ssl_common.h struct tls_options · line 317

Quoted 9 lines
src/openvpn/ssl_common.h +1 -0
index 98afc88c..87877c88 100644
@@ -314,6 +314,7 @@ struct tls_options
 
      /* used for username/password authentication */
      const char *auth_user_pass_verify_script;
+    const char *client_crresponse_script;

Indentation.

I've not looked that carefully at the rest of the code, as I would like to test those code paths when completing the review. It looks reasonable though at a first glance, but might be I stumble across something during testing.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#10 lore raw

Re: [Openvpn-devel] [PATCH 02/11] Implement client side handling of AUTH_PENDING message

In reply to Lev Stipakov

Am 15.01.21 um 14:13 schrieb Lev Stipakov:

Quoted 12 lines

Hi,

Please not that I got errors applying this patch, so I reviewed
corresponding commit
from github (https://github.com/schwabe/openvpn/commit/3901e46127a2db3e6dfb20c44e8d8e30adea58c7).

doc/management-notes.txt to signal a pending authenticating to the client. A pending auth means · line 613

Quoted 2 lines
doc/management-notes.txt +2 -0
+Receiving a AUTH_PENDING message will make the client change its timeout the
+timeout proposed by the server, even if the timeout is shorter.

Typo.

Quoted 7 lines

src/openvpn/integer.h line 43

Quoted 5 lines

/*
* min/max functions
*/

src/openvpn/integer.h +2 -0
+static inline unsigned int
+max_uint(unsigned int x, unsigned int y)

It is 2021 and we have to write our own min/max :(

Yes. We had a discussion on #openvpn-devel and there seem to be no (non-float) min/max version in the standard library. The linux kernel also has a macro for this. This would be min_t(unsigned int, x, y) iirc in the kernel, so similar to what we do here

Arne

#25 lore raw

Re: [Openvpn-devel] [PATCH 09/11] Implement deferred auth for scripts

In reply to David Sommerseth
Quoted 8 lines
Quoted 4 lines

+        int script_ret = openvpn_run_script(&argv, session->opt->es, S_EXITCODE,
+                                            "--auth-user-pass-verify");

Perhaps move the retval declaration down here, as we're touching it anyhow?  This switch() is the first place we use it, unless I'm overlooking something.

You are overlooking the 'goto done' code path for error handling.

Quoted 11 lines
Quoted 11 lines
(quoted diff) +0 -0
@@ -1499,7 +1534,11 @@ verify_user_pass(struct user_pass *up, struct
 tls_multi *multi,
   #ifdef PLUGIN_DEF_AUTH

           || s1 == OPENVPN_PLUGIN_FUNC_DEFERRED
  #endif
-         ) && s2
+         ) &&
+        ((s2 == OPENVPN_PLUGIN_FUNC_SUCCESS)
+#ifdef ENABLE_DEF_AUTH
+         || s2 ==  OPENVPN_PLUGIN_FUNC_DEFERRED)

Quoted 9 lines
Quoted 4 lines

+#endif
  #ifdef MANAGEMENT_DEF_AUTH
          && man_def_auth != KMDA_ERROR
  #endif

Yikes!  This if() statement is unreadable.  Since you are doing changes here, could we improve this whole logic.  Perhaps using a helper macro like this (incorrect code-style, for e-mail readability)

This is already the improved version after the connect patches cleaned it up a bit :P

I really don't like hiding condition behind macros just make them shorter, I will propose a variant that extracts parts of the condition into individual booleans.

Arne