Skip to contentSkip to conversation

Implement additional two step authentication methods

PATCH In review Arne Schwabe 3 participants 16 messages May 19, 2020 – Jun 20, 2020

lore
Share & tools
lore
#0 lore raw

v3 cover Implement additional two step authentication methods

This patchset implements the basic blocks for a more flexible authentication protocol in OpenVPN. The basic idea is to instead of giving a immediate deny/accept the client gets a additional challgen via the info message to a 2FA method or external authentication with URL (e.g. via SAML).

The patch already sends the AUTH_PENDING control message. An OpenVPN3 cliets needs this to scale back pull request frequency, OpenVPN2 currently logs a warning about an unknown. This will be fixed in a follw up patch

Currently both client and server side need a management interface make the support work. For a server script follow up patch, I am currently waiting for the client-connect patch set to be merge and for the client side, David offered to help with helping with the getting an async password input working.

Arne Schwabe (5):
Implement parsing and sending INFO and INFO_PRE control messages Implement support for signalling IV_SSO to server Implement sending response to challenge via CR_RESPONSE Implement sending AUTH_PENDING challenges to clients Implement forwarding client CR_RESPONSE messages to management

 doc/management-notes.txt | 130 ++++++++++++++++++++++++++++++++++++++-
 src/openvpn/forward.c    |  12 ++++
 src/openvpn/init.c       |  39 ++++++++++++
 src/openvpn/manage.c     | 113 +++++++++++++++++++++++++++++++++-
 src/openvpn/manage.h     |   9 +++
 src/openvpn/multi.c      |  19 ++++++
 src/openvpn/push.c       |  78 +++++++++++++++++++++++
 src/openvpn/push.h       |  12 ++++
 src/openvpn/ssl.c        |   4 +-
 9 files changed, 412 insertions(+), 4 deletions(-)
Signature · 1 line
2.26.0
#1 lore raw

PATCH v3 1/5 Implement parsing and sending INFO and INFO_PRE control messages

OpenVPN 3 implements these messages to send information during the authentication to the UI, implement these message also in OpenVPN 2.x

---
 src/openvpn/forward.c |  8 ++++++++
 src/openvpn/push.c    | 32 ++++++++++++++++++++++++++++++++
 src/openvpn/push.h    |  3 +++
 3 files changed, 43 insertions(+)
src/openvpn/forward.c +8 -0
index fd08f12d..3b088f87 100644
@@ -395,6 +395,14 @@ check_incoming_control_channel_dowork(struct context *c)
             {
                 server_pushed_signal(c, &buf, false, 4);
             }
+            else if (buf_string_match_head_str(&buf, "INFO_PRE"))
+            {
+                server_pushed_info(c, &buf, 8);
+            }
+            else if (buf_string_match_head_str(&buf, "INFO"))
+            {
+                server_pushed_info(c, &buf, 4);
+            }
             else
             {
                 msg(D_PUSH_ERRORS, "WARNING: Received unknown control message: %s", BSTR(&buf));
src/openvpn/push.c +32 -0
index 0e58b839..965dd139 100644
@@ -177,6 +177,38 @@ server_pushed_signal(struct context *c, const struct buffer *buffer, const bool
     }
 }
 
+void
+server_pushed_info(struct context *c, const struct buffer *buffer,
+                   const int adv)
+{
+    const char *m = "";
+    struct buffer buf = *buffer;
+
+    if (buf_advance(&buf, adv) && buf_read_u8(&buf) == ',' && BLEN(&buf))
+    {
+        m = BSTR(&buf);
+    }
+
+#ifdef ENABLE_MANAGEMENT
+    struct gc_arena gc;
+    if (management)
+    {
+        gc = gc_new();
+
+        /*
+         * We use >INFOMSG here instead of plain >INFO since INFO is used to
+         * for management greeting and we don't want to confuse the client
+         */
+        struct buffer out = alloc_buf_gc(256, &gc);
+        buf_printf(&out, ">%s:%s", "INFOMSG", m);
+        management_notify_generic(management, BSTR(&out));
+
+        gc_free(&gc);
+    }
+    #endif
+    msg(D_PUSH, "Info command was pushed by server ('%s')", m);
+}
+
 /**
  * Add an option to the given push list by providing a format string.
  *
src/openvpn/push.h +3 -0
index 53deae02..1898f238 100644
@@ -50,6 +50,9 @@ 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 server_pushed_info(struct context *c, const struct buffer *buffer,
+                        const int adv);
+
 void incoming_push_message(struct context *c, const struct buffer *buffer);
 
 void clone_push_list(struct options *o);
Signature · 1 line
2.26.0
Acked-by on v3 1/5
#2 lore raw

Re: [Openvpn-devel] [PATCH v3 1/5] Implement parsing and sending INFO and INFO_PRE control messages

Quoted 10 lines · Arne Schwabe

OpenVPN 3 implements these messages to send information during the authentication to the UI, implement these message also in OpenVPN 2.x

---
 src/openvpn/forward.c |  8 ++++++++
 src/openvpn/push.c    | 32 ++++++++++++++++++++++++++++++++
 src/openvpn/push.h    |  3 +++
 3 files changed, 43 insertions(+)

[...]

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#3 lore raw

[Openvpn-devel] [PATCH applied] Re: Implement parsing and sending INFO and INFO_PRE control messages

In reply to Arne Schwabe

Your patch has been applied to the master branch.

commit 7bdba5319b4d8b8af9c38c91b51b03a7630db99c

Author: Arne Schwabe
Date:   Wed May 20 00:00:00 2020 +0200
     Implement parsing and sending INFO and INFO_PRE control messages

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

--
kind regards,

Gert Doering

#4 lore raw

PATCH v3 2/5 Implement support for signalling IV_SSO to server

In reply to Arne Schwabe
---
 src/openvpn/ssl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
src/openvpn/ssl.c +3 -1
index c2e9a4f3..f85ef3eb 100644
@@ -2333,7 +2333,9 @@ push_peer_info(struct buffer *buf, struct tls_session *session)
                 if ((((strncmp(e->string, "UV_", 3)==0
                        || strncmp(e->string, "IV_PLAT_VER=", sizeof("IV_PLAT_VER=")-1)==0)
                       && session->opt->push_peer_info_detail >= 2)
-                     || (strncmp(e->string,"IV_GUI_VER=",sizeof("IV_GUI_VER=")-1)==0))
+                     || (strncmp(e->string,"IV_GUI_VER=",sizeof("IV_GUI_VER=")-1)==0)
+                     || (strncmp(e->string,"IV_SSO=",sizeof("IV_SSO=")-1)==0)
+                     )
                     && buf_safe(&out, strlen(e->string)+1))
                 {
                     buf_printf(&out, "%s\n", e->string);
Signature · 1 line
2.26.0
Acked-by on v3 2/5
#5 lore raw

Re: [Openvpn-devel] [PATCH v3 2/5] Implement support for signalling IV_SSO to server

Quoted 11 lines · Arne Schwabe
---
 src/openvpn/ssl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
src/openvpn/ssl.c +0 -0
index c2e9a4f3..f85ef3eb 100644

src/openvpn/ssl.c push_peer_info(struct buffer *buf, struct tls_session *session) · line 2341

Quoted 10 lines
src/openvpn/ssl.c +3 -1
@@ -2333,7 +2333,9 @@ push_peer_info(struct buffer *buf, struct tls_session *session)
                 if ((((strncmp(e->string, "UV_", 3)==0
                        || strncmp(e->string, "IV_PLAT_VER=", sizeof("IV_PLAT_VER=")-1)==0)
                       && session->opt->push_peer_info_detail >= 2)
-                     || (strncmp(e->string,"IV_GUI_VER=",sizeof("IV_GUI_VER=")-1)==0))
+                     || (strncmp(e->string,"IV_GUI_VER=",sizeof("IV_GUI_VER=")-1)==0)
+                     || (strncmp(e->string,"IV_SSO=",sizeof("IV_SSO=")-1)==0)
+                     )
                     && buf_safe(&out, strlen(e->string)+1))
                 {
                     buf_printf(&out, "%s\n", e->string);
Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#6 lore raw

[Openvpn-devel] [PATCH applied] Re: Implement support for signalling IV_SSO to server

In reply to Arne Schwabe

Your patch has been applied to the master branch.

commit 1f76bbb5e5111d0a529ec192443e66ed436c83db

Author: Arne Schwabe
Date:   Wed May 20 00:00:01 2020 +0200
     Implement support for signalling IV_SSO to server

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

--
kind regards,

Gert Doering

#7 lore raw

PATCH v3 3/5 Implement sending response to challenge via CR_RESPONSE

In reply to Arne Schwabe

When a client announces its support to support text based challenge/response via IV_SSO=crtext,the client needs to also be able to reply to that response.

This adds the "cr-response" management function to be able to do this. The answer should be base64 encoded.

---
 doc/management-notes.txt | 14 ++++++++++++++
 src/openvpn/init.c       | 39 +++++++++++++++++++++++++++++++++++++++
 src/openvpn/manage.c     | 39 ++++++++++++++++++++++++++++++++++++++-
 src/openvpn/manage.h     |  1 +
 4 files changed, 92 insertions(+), 1 deletion(-)
doc/management-notes.txt +14 -0
index e54e1082..a7ae84e3 100644
@@ -806,6 +806,20 @@ To accept connecting to the host and port directly, use this command:
 
   proxy NONE
 
+COMMAND -- cr-response (OpenVPN 2.5 or higher)
+-------------------------------------------------
+Provides support for sending responses a challenge/response
+query via INFOMSG,CR_TEXT. The response should be base64 encoded:
+
+  cr-response SGFsbG8gV2VsdCE=
+
+The document is intended to be used after the client received a
+CR_TEXT challenge (see send-pending-auth section). The answer is
+the answer to the challenge and depends on the challenge itself
+for a TOTP challenge this would the number encoded as base64 or
+just a string for a challenge like what "day is it today?".
+
+
 COMMAND -- pk-sig (OpenVPN 2.5 or higher, management version > 1)
 COMMAND -- rsa-sig (OpenVPN 2.3 or higher, management version <= 1)
 -----------------------------------------------------------------
src/openvpn/init.c +39 -0
index 70cd493a..2c8db68d 100644
@@ -291,6 +291,44 @@ ce_management_query_proxy(struct context *c)
     return ret;
 }
 
+/**
+ * This method sends a custom control channel message
+ *
+ * This will write the control message
+ *
+ *  command parm1,parm2,..
+ *  .
+ * to the control channel.
+ *
+ * @param arg           The context struct
+ * @param command       The command being sent
+ * @param parameters    the parameters to the command
+ * @return              if sending was successful
+ */
+static bool
+management_callback_send_cc_message(void *arg,
+                                    const char *command,
+                                    const char *parameters)
+{
+    struct context *c = (struct context *) arg;
+    size_t len = strlen(command) + 1 + sizeof(parameters) + 1;
+    if (len > PUSH_BUNDLE_SIZE)
+    {
+        return false;
+    }
+
+    struct gc_arena gc = gc_new();
+    struct buffer buf = alloc_buf_gc(len, &gc);
+    ASSERT(buf_printf(&buf, "%s", command));
+    if (parameters)
+    {
+        ASSERT(buf_printf(&buf, ",%s", parameters));
+    }
+    bool status = send_control_channel_string(c, BSTR(&buf), D_PUSH);
+
+    gc_free(&gc);
+    return status;
+}
 
 static bool
 management_callback_remote_cmd(void *arg, const char **p)
@@ -3973,6 +4011,7 @@ init_management_callback_p2p(struct context *c)
         cb.show_net = management_show_net_callback;
         cb.proxy_cmd = management_callback_proxy_cmd;
         cb.remote_cmd = management_callback_remote_cmd;
+        cb.send_cc_message = management_callback_send_cc_message;
 #ifdef TARGET_ANDROID
         cb.network_change = management_callback_network_change;
 #endif
src/openvpn/manage.c +38 -1
index 195941ca..a72c7678 100644
@@ -75,6 +75,7 @@ man_help(void)
     msg(M_CLIENT, "auth-retry t           : Auth failure retry mode (none,interact,nointeract).");
     msg(M_CLIENT, "bytecount n            : Show bytes in/out, update every n secs (0=off).");
     msg(M_CLIENT, "echo [on|off] [N|all]  : Like log, but only show messages in echo buffer.");
+    msg(M_CLIENT, "cr-response response   : Send a challenge response answer via CR_RESPONSE to server");
     msg(M_CLIENT, "exit|quit              : Close management session.");
     msg(M_CLIENT, "forget-passwords       : Forget passwords entered so far.");
     msg(M_CLIENT, "help                   : Print this message.");
@@ -779,6 +780,27 @@ man_net(struct management *man)
     }
 }
 
+static void
+man_send_cc_message(struct management *man, const char *message, const char *parameters)
+{
+    if (man->persist.callback.send_cc_message)
+    {
+        const bool status = (*man->persist.callback.send_cc_message)
+                                (man->persist.callback.arg, message, parameters);
+        if (status)
+        {
+            msg(M_CLIENT, "SUCCESS: command succeeded");
+        }
+        else
+        {
+            msg(M_CLIENT, "ERROR: command failed");
+        }
+    }
+    else
+    {
+        msg(M_CLIENT, "ERROR: This command is not supported by the current daemon mode");
+    }
+}
 #ifdef ENABLE_PKCS11
 
 static void
@@ -1144,7 +1166,15 @@ man_load_stats(struct management *man)
 }
 
 #define MN_AT_LEAST (1<<0)
-
+/**
+ * Checks if the correct number of arguments to a management command are present
+ * and otherwise prints an error and returns false.
+ *
+ * @param p         pointer to the parameter array
+ * @param n         number of arguments required
+ * @param flags     if MN_AT_LEAST require at least n parameters and not exactly n
+ * @return          Return whether p has n (or at least n) parameters
+ */
 static bool
 man_need(struct management *man, const char **p, const int n, unsigned int flags)
 {
@@ -1460,6 +1490,13 @@ man_dispatch_command(struct management *man, struct status_output *so, const cha
             man_query_need_str(man, p[1], p[2]);
         }
     }
+    else if (streq(p[0], "cr-response"))
+    {
+        if (man_need(man, p, 1, 0))
+        {
+            man_send_cc_message(man, "CR_RESPONSE", p[1]);
+        }
+    }
     else if (streq(p[0], "net"))
     {
         man_net(man);
src/openvpn/manage.h +1 -0
index 6f5f34c1..e1dabceb 100644
@@ -164,6 +164,7 @@ struct management_callback
     int (*kill_by_addr) (void *arg, const in_addr_t addr, const int port);
     void (*delete_event) (void *arg, event_t event);
     int (*n_clients) (void *arg);
+    bool (*send_cc_message) (void *arg, const char *message, const char *parameter);
 #ifdef MANAGEMENT_DEF_AUTH
     bool (*kill_by_cid)(void *arg, const unsigned long cid, const char *kill_msg);
     bool (*client_auth) (void *arg,
Signature · 1 line
2.26.0
Acked-by on v3 3/5
#8 lore raw

Re: [Openvpn-devel] [PATCH v3 3/5] Implement sending response to challenge via CR_RESPONSE

Quoted 25 lines · Arne Schwabe

When a client announces its support to support text based challenge/response via IV_SSO=crtext,the client needs to also be able to reply to that response.

This adds the "cr-response" management function to be able to do this. The answer should be base64 encoded.

---
 doc/management-notes.txt | 14 ++++++++++++++
 src/openvpn/init.c       | 39 +++++++++++++++++++++++++++++++++++++++
 src/openvpn/manage.c     | 39 ++++++++++++++++++++++++++++++++++++++-
 src/openvpn/manage.h     |  1 +
 4 files changed, 92 insertions(+), 1 deletion(-)
doc/management-notes.txt +2 -0
index e54e1082..a7ae84e3 100644
@@ -806,6 +806,20 @@ To accept connecting to the host and port directly, use this command:
 
   proxy NONE
 
+COMMAND -- cr-response (OpenVPN 2.5 or higher)
+-------------------------------------------------

doc/management-notes.txt To accept connecting to the host and port directly, use this command: · line 820

Quoted 10 lines
doc/management-notes.txt +10 -0
+Provides support for sending responses a challenge/response
+query via INFOMSG,CR_TEXT. The response should be base64 encoded:
+
+  cr-response SGFsbG8gV2VsdCE=
+
+The document is intended to be used after the client received a
+CR_TEXT challenge (see send-pending-auth section). The answer is
+the answer to the challenge and depends on the challenge itself
+for a TOTP challenge this would the number encoded as base64 or
+just a string for a challenge like what "day is it today?".

The quoting should probably start before "what" instead of after. This can be fixed during commit time if we care enough about that typo.

I've only glared at this patch, as I tested the previous version quite a bit.
Changes requested are added to this.

Arne and I have discussed the IV_SSO naming a bit, I realize we need to keep at least the IV_SSO as changing that would be an incompatible protocol change with OpenVPN Access Server (already in production) and OpenVPN Cloud (recently released). This is something we can consider change later on, then in cooperation with OpenVPN Access Server and OpenVPN Cloud.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#9 lore raw

[Openvpn-devel] [PATCH applied] Re: Implement sending response to challenge via CR_RESPONSE

In reply to Arne Schwabe

Your patch has been applied to the master branch.

doc/management-notes.txt has been re-quoted as requested.

(I have only done basic compile / t_client tests on this series, which will not really excercise any of the new code bits - but at least makes sure that nothing breaks there. We need something in the test framework that actually uses the management interface on both ends to test this...)

commit adb9bb918de6ceda1ab027aa02942e8c4efc3183

Author: Arne Schwabe
Date:   Wed May 20 00:00:02 2020 +0200
     Implement sending response to challenge via CR_RESPONSE

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

--
kind regards,

Gert Doering

#10 lore raw

PATCH v3 4/5 Implement sending AUTH_PENDING challenges to clients

In reply to Arne Schwabe

This implements sending AUTH_PENDING and INFO_PRE messages to clients that indicate that the clients should be continue authentication with a second factor. This can currently be out of band (openurl) or a normal challenge/response two like TOTP (CR_TEXT).

Unfortunately this patch spend so much time in review in openvpn2 that the corosponding IV_SSO commit in openvpn3 (34a3f264) already made its way to released products so changing this right now is difficult.

https://github.com/OpenVPN/openvpn3/commit/34a3f264f56bd050d9b26d2e7163f88af9a559e2

---
 doc/management-notes.txt | 86 ++++++++++++++++++++++++++++++++++++++++
 src/openvpn/manage.c     | 46 +++++++++++++++++++++
 src/openvpn/manage.h     |  3 ++
 src/openvpn/multi.c      | 19 +++++++++
 src/openvpn/push.c       | 24 +++++++++++
 src/openvpn/push.h       |  7 ++++
 6 files changed, 185 insertions(+)
doc/management-notes.txt +86 -0
index a7ae84e3..ce32b85f 100644
@@ -592,6 +592,92 @@ interface to approve client connections.
 CID,KID -- client ID and Key ID.  See documentation for ">CLIENT:"
 notification for more info.
 
+COMMAND -- client-pending-auth  (OpenVPN 2.5 or higher)
+----------------------------------------------------
+
+Instruct OpenVPN server to send AUTH_PENDING and INFO_PRE message
+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).
+
+Before issuing a client-pending-auth to a client instead of a
+client-auth/client-deny, the server should check the IV_SSO
+environment variable if the method is support. The currently
+defined method are crtext for challenge/response using text
+(e.g. TOTP), openurl and proxy_url for opening an URL in the client to
+continue authentication. A client supporting the first two methods would
+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
+implementations the name IV_SSO is kept in lieu of a better name.
+
+openurl
+========
+For a web based extra authentication (like for
+SSO/SAML) EXTRA should be
+
+    OPEN_URL:url
+          
+and client should ask to the user to open the URL to continue.
+
+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.
+
+url_proxy
+========
+To avoid issues with OpenVPN connection persist-tun and not able
+to reach the web server, a method a virant of openurl via a HTTPS
+Proxy exists. The client should announce url_proxy in its IV_SSO
+and parse the PROXY_URL message. The format is
+
+    PROXY_URL:<proxy>:<proxy_port>:<proxyuser_base64>:<proxy_password_bade64>:url
+
+The proxy should be a literal IPv4 address or Ipv6 address in [] to avoid
+ambiguity in parsing. A literal IP address is preferred as DNS might not
+be available when the needs to open the url. The IP address will usually
+be the address that client uses to connect to the server. For dual-homed
+server, the server should respond with the same address that the client
+connects to.
+
+This address is also usually excluded from being redirected over the VPN
+by a host route. If the platform (like Android) uses another way of protecting
+the VPN connection routing loops the client needs to also exclude the
+connection to the proxy in the same manner.
+
+Should another IP be used the VPN configuration should include the route
+statement to exclude that route from being routed over the VPN.
+
+crtext
+=======
+
+The format of EXTRA is similar to the already used two step authentication
+described in Challenge/Response Protocol section of this document. Since
+most of the fields are not necessary or can be infered only the <flags>
+and <challgenge_text> fields are used:
+
+    CR_TEXT:<flags>:<challenge_text>
+
+<flags>: a series of optional, comma-separated flags:
+ E : echo the response when the user types it.
+ R : a response is required.
+
+<challenge_text>: the challenge text to be shown to the user.
+
+
+
 COMMAND -- client-deny  (OpenVPN 2.1 or higher)
 -----------------------------------------------
 
src/openvpn/manage.c +46 -0

64 lines not on this page · raw message

src/openvpn/manage.h +3 -0
index e1dabceb..e28b11d1 100644
@@ -174,6 +174,9 @@ struct management_callback
                          const char *reason,
                          const char *client_reason,
                          struct buffer_list *cc_config); /* ownership transferred */
+    bool (*client_pending_auth) (void *arg,
+                                 const unsigned long cid,
+                                 const char *url);
     char *(*get_peer_info) (void *arg, const unsigned long cid);
 #endif
 #ifdef MANAGEMENT_PF
src/openvpn/multi.c +19 -0
index 7f61350d..74e035e5 100644
@@ -3310,6 +3310,24 @@ 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)
+{
+    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);
+        multi_schedule_context_wakeup(m, mi);
+        return ret;
+    }
+    return false;
+}
+
+
 static bool
 management_client_auth(void *arg,
                        const unsigned long cid,
@@ -3417,6 +3435,7 @@ init_management_callback_multi(struct multi_context *m)
 #ifdef MANAGEMENT_DEF_AUTH
         cb.kill_by_cid = management_kill_by_cid;
         cb.client_auth = management_client_auth;
+        cb.client_pending_auth = management_client_pending_auth;
         cb.get_peer_info = management_get_peer_info;
 #endif
 #ifdef MANAGEMENT_PF
src/openvpn/push.c +24 -0
index 965dd139..a5fa87d8 100644
@@ -265,6 +265,30 @@ send_auth_failed(struct context *c, const char *client_reason)
     gc_free(&gc);
 }
 
+bool
+send_auth_pending_messages(struct context *c, const char* extra)
+{
+    send_control_channel_string(c, "AUTH_PENDING", D_PUSH);
+
+    static const char info_pre[] = "INFO_PRE,";
+
+
+    size_t len = strlen(extra)+1 + sizeof(info_pre);
+    if (len > PUSH_BUNDLE_SIZE)
+    {
+        return false;
+    }
+    struct gc_arena gc = gc_new();
+
+    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);
+
+    gc_free(&gc);
+    return true;
+}
+
 /*
  * Send restart message from server to client.
  */
src/openvpn/push.h +7 -0
index 1898f238..42ab100d 100644
@@ -70,6 +70,13 @@ void remove_iroutes_from_push_route_list(struct options *o);
 
 void send_auth_failed(struct context *c, const char *client_reason);
 
+/**
+ * Sends the auth pending control messages to a client. See
+ * 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);
+
 void send_restart(struct context *c, const char *kill_msg);
 
 /**
Signature · 1 line
2.26.0
Acked-by on v3 4/5
#11 lore raw

Re: [Openvpn-devel] [PATCH v3 4/5] Implement sending AUTH_PENDING challenges to clients

Quoted 12 lines · Arne Schwabe

This implements sending AUTH_PENDING and INFO_PRE messages to clients that indicate that the clients should be continue authentication with a second factor. This can currently be out of band (openurl) or a normal challenge/response two like TOTP (CR_TEXT).

Unfortunately this patch spend so much time in review in openvpn2 that the corosponding IV_SSO commit in openvpn3 (34a3f264) already made its way to released products so changing this right now is difficult.

https://github.com/OpenVPN/openvpn3/commit/34a3f264f56bd050d9b26d2e7163f88af9a559e2

Quoted 9 lines
---
 doc/management-notes.txt | 86 ++++++++++++++++++++++++++++++++++++++++
 src/openvpn/manage.c     | 46 +++++++++++++++++++++
 src/openvpn/manage.h     |  3 ++
 src/openvpn/multi.c      | 19 +++++++++
 src/openvpn/push.c       | 24 +++++++++++
 src/openvpn/push.h       |  7 ++++
 6 files changed, 185 insertions(+)

[...]

Only compile tested, as I've done quite some testing earlier. Requested changes are in, with the exception of IV_SSO which we can't change now.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#12 lore raw

[Openvpn-devel] [PATCH applied] Re: Implement sending AUTH_PENDING challenges to clients

In reply to Arne Schwabe

Your patch has been applied to the master branch.

I have fixed a few typos in doc/management-notes.txt while at it ("virant" -> "variant").

commit 1114b985dffaf7b2dcb04dfced5397562bb6606a

Author: Arne Schwabe
Date:   Wed May 20 00:00:03 2020 +0200
     Implement sending AUTH_PENDING challenges to clients

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

--
kind regards,

Gert Doering

#13 lore raw

PATCH v3 5/5 Implement forwarding client CR_RESPONSE messages to management

In reply to Arne Schwabe

When signalling the client that it should do Challenge response without reconnecting (IV_SSO=crtext/INFOPRE=CR_TEXT), the server needs forward the response via the management console.

---
 doc/management-notes.txt | 30 +++++++++++++++++++++++++++++-
 src/openvpn/forward.c    |  4 ++++
 src/openvpn/manage.c     | 28 +++++++++++++++++++++++++++-
 src/openvpn/manage.h     |  5 +++++
 src/openvpn/push.c       | 22 ++++++++++++++++++++++
 src/openvpn/push.h       |  2 ++
 6 files changed, 89 insertions(+), 2 deletions(-)
doc/management-notes.txt +29 -1
index ce32b85f..5cfbb70a 100644
@@ -1052,7 +1052,7 @@ The ">CLIENT:" notification is enabled by the --management-client-auth
 OpenVPN configuration directive that gives the management interface client
 the responsibility to authenticate OpenVPN clients after their client
 certificate has been verified.  CLIENT notifications may be multi-line, and
-the sequentiality of a given CLIENT notification, its associated environmental
+the sequentially of a given CLIENT notification, its associated environmental
 variables, and the terminating ">CLIENT:ENV,END" line are guaranteed to be
 atomic.
 
@@ -1094,6 +1094,34 @@ CLIENT notification types:
 
     >CLIENT:ADDRESS,{CID},{ADDR},{PRI}
 
+(5) Text based challenge/Response
+
+   >CLIENT:CR_RESPONSE,{CID},{KID},{response_base64}
+   >CLIENT:ENV,name1=val1
+   >CLIENT:ENV,name2=val2
+   >CLIENT:ENV,...
+   >CLIENT:ENV,END
+
+   Using the cr-response command on the client side will trigger this
+   message on the server side.
+
+   CR_RESPONSE notification. The >CR_RESPONSE fulfils the same purpose as the
+   CRV1 response in the traditional challenge/response. See that section
+   below for more details. Since this still uses the same cid as the original
+   response, we do not use the username and opaque session data in this
+   response but only contains the actual response.
+
+   It is important to note that OpenVPN2 merely passes the authentication
+   information and does not do any further checks. (E.g. if a CR was issued
+   before or if multiple CR responses were sent from the client or if
+   data has a valid base64 encoding)
+
+   This interface should be be sufficient for almost all challenge/response
+   system that can be implemented with a single round and base64 encoding the
+   response. Mechanisms that need multiple rounds or more complex answers
+   should implement a different response type than CR_RESPONSE.
+
+
 Variables:
 
 CID --  Client ID, numerical ID for each connecting client, sequence = 0,1,2,...
src/openvpn/forward.c +4 -0
index 3b088f87..885cf126 100644
@@ -403,6 +403,10 @@ check_incoming_control_channel_dowork(struct context *c)
             {
                 server_pushed_info(c, &buf, 4);
             }
+            else if (buf_string_match_head_str(&buf, "CR_RESPONSE"))
+            {
+                receive_cr_response(c, &buf);
+            }
             else
             {
                 msg(D_PUSH_ERRORS, "WARNING: Received unknown control message: %s", BSTR(&buf));
src/openvpn/manage.c +27 -1
index 3ebe72ec..898cb3b3 100644
@@ -2908,7 +2908,7 @@ management_notify_generic(struct management *man, const char *str)
 #ifdef MANAGEMENT_DEF_AUTH
 
 static void
-man_output_peer_info_env(struct management *man, struct man_def_auth_context *mdac)
+man_output_peer_info_env(struct management *man, const struct man_def_auth_context *mdac)
 {
     char line[256];
     if (man->persist.callback.get_peer_info)
@@ -2958,6 +2958,32 @@ management_notify_client_needing_auth(struct management *management,
     }
 }
 
+void
+management_notify_client_cr_response(unsigned mda_key_id,
+                                     const struct man_def_auth_context *mdac,
+                                     const struct env_set *es,
+                                     const char *response)
+{
+    struct gc_arena gc;
+    if (management)
+    {
+        gc = gc_new();
+
+        struct buffer out = alloc_buf_gc(256, &gc);
+        msg(M_CLIENT, ">CLIENT:CR_RESPONSE,%lu,%u,%s",
+            mdac->cid, mda_key_id, response);
+        man_output_extra_env(management, "CLIENT");
+        if (management->connection.env_filter_level>0)
+        {
+            man_output_peer_info_env(management, mdac);
+        }
+        man_output_env(es, true, management->connection.env_filter_level, "CLIENT");
+        management_notify_generic(management, BSTR(&out));
+
+        gc_free(&gc);
+    }
+}
+
 void
 management_connection_established(struct management *management,
                                   struct man_def_auth_context *mdac,
src/openvpn/manage.h +5 -0
index e28b11d1..8c824ca7 100644
@@ -434,6 +434,11 @@ void management_learn_addr(struct management *management,
                            const struct mroute_addr *addr,
                            const bool primary);
 
+void management_notify_client_cr_response(unsigned mda_key_id,
+                                          const struct man_def_auth_context *mdac,
+                                          const struct env_set *es,
+                                          const char *response);
+
 #endif
 
 char *management_query_pk_sig(struct management *man, const char *b64_data,
src/openvpn/push.c +22 -0
index a5fa87d8..26460490 100644
@@ -209,6 +209,28 @@ server_pushed_info(struct context *c, const struct buffer *buffer,
     msg(D_PUSH, "Info command was pushed by server ('%s')", m);
 }
 
+void
+receive_cr_response(struct context *c, const struct buffer *buffer)
+{
+    struct buffer buf = *buffer;
+    const char *m = "";
+
+    if (buf_advance(&buf, 11) && buf_read_u8(&buf) == ',' && BLEN(&buf))
+    {
+        m = BSTR(&buf);
+    }
+#ifdef MANAGEMENT_DEF_AUTH
+    struct tls_session *session = &c->c2.tls_multi->session[TM_ACTIVE];
+    struct man_def_auth_context *mda = session->opt->mda_context;
+    struct env_set *es = session->opt->es;
+    int key_id = session->key[KS_PRIMARY].key_id;
+
+
+    management_notify_client_cr_response(key_id, mda, es, m);
+#endif
+    msg(D_PUSH, "CR response was sent by client ('%s')", m);
+}
+
 /**
  * Add an option to the given push list by providing a format string.
  *
src/openvpn/push.h +2 -0
index 42ab100d..2faf19a6 100644
@@ -53,6 +53,8 @@ void server_pushed_signal(struct context *c, const struct buffer *buffer, const
 void server_pushed_info(struct context *c, const struct buffer *buffer,
                         const int adv);
 
+void receive_cr_response(struct context *c, const struct buffer *buffer);
+
 void incoming_push_message(struct context *c, const struct buffer *buffer);
 
 void clone_push_list(struct options *o);
Signature · 1 line
2.26.0
Acked-by on v3 5/5
#14 lore raw

Re: [Openvpn-devel] [PATCH v3 5/5] Implement forwarding client CR_RESPONSE messages to management

Quoted 5 lines · Arne Schwabe

When signalling the client that it should do Challenge response without reconnecting (IV_SSO=crtext/INFOPRE=CR_TEXT), the server needs forward the response via the management console.

Quoted 9 lines
---
 doc/management-notes.txt | 30 +++++++++++++++++++++++++++++-
 src/openvpn/forward.c    |  4 ++++
 src/openvpn/manage.c     | 28 +++++++++++++++++++++++++++-
 src/openvpn/manage.h     |  5 +++++
 src/openvpn/push.c       | 22 ++++++++++++++++++++++
 src/openvpn/push.h       |  2 ++
 6 files changed, 89 insertions(+), 2 deletions(-)

[...]

Basing this also on prior testing, looking good. Only done compile testing in this round.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#15 lore raw

[Openvpn-devel] [PATCH applied] Re: Implement forwarding client CR_RESPONSE messages to management

In reply to Arne Schwabe

Your patch has been applied to the master branch.

Fixed a typo in doc/management-notes.txt ("sequentiality" was meant to be exactly this, not "sequentially").

Stared a bit at the code and ran basic t_client tests, but no real testing and no real review.

commit 06498f21cdf051b0643606efda96b27b3c358e0c

Author: Arne Schwabe
Date:   Wed May 20 00:00:04 2020 +0200
     Implement forwarding client CR_RESPONSE messages to management

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

--
kind regards,

Gert Doering