Skip to contentSkip to conversation

Fix OpenVPN querying user/password if auth-token with user expires

PATCH Superseded Arne Schwabe 4 participants 7 messages Feb 17, 2022 – Oct 10, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 Fix OpenVPN querying user/password if auth-token with user expires

The problematic behaviour happens when start a profile without auth-user-pass and connect to a server that pushes auth-token When the auth token expires OpenVPN asks for auth User and password again.

The problem is that the auth_user_pass_setup sets auth_user_pass_enabled = true; This function is called from two places. In ssl.c it is only called with an auth-token present or that variable already set. The other one is init_query_passwords.

Move setting auth_user_pass_enabled to the second place to ensure it is only set if we really want passwords.

Patch v2: Remove unrelated code change
Patch v3: Rebase to master

---
 src/openvpn/init.c | 1 +
 src/openvpn/ssl.c  | 7 ++++++-
 src/openvpn/ssl.h  | 3 +++
 3 files changed, 10 insertions(+), 1 deletion(-)
src/openvpn/init.c +1 -0
index 21adc3cf..e5fba621 100644
@@ -590,6 +590,7 @@ init_query_passwords(const struct context *c)
     /* Auth user/pass input */
     if (c->options.auth_user_pass_file)
     {
+        enable_auth_user_pass();
 #ifdef ENABLE_MANAGEMENT
         auth_user_pass_setup(c->options.auth_user_pass_file, &c->options.sc_info);
 #else
src/openvpn/ssl.c +6 -1
index 14a943a7..b68708b0 100644
@@ -398,9 +398,14 @@ static char *auth_challenge; /* GLOBAL */
 #endif
 
 void
-auth_user_pass_setup(const char *auth_file, const struct static_challenge_info *sci)
+enable_auth_user_pass()
 {
     auth_user_pass_enabled = true;
+}
+
+void
+auth_user_pass_setup(const char *auth_file, const struct static_challenge_info *sci)
+{
     if (!auth_user_pass.defined && !auth_token.defined)
     {
 #ifdef ENABLE_MANAGEMENT
src/openvpn/ssl.h +3 -0
index cf754ad2..76d8a7dc 100644
@@ -436,6 +436,9 @@ void tls_post_encrypt(struct tls_multi *multi, struct buffer *buf);
  */
 void pem_password_setup(const char *auth_file);
 
+/* Enables the use of user/password authentication */
+void enable_auth_user_pass();
+
 /*
  * Setup authentication username and password. If auth_file is given, use the
  * credentials stored in the file.
Signature · 1 line
2.33.0
Acked-by on v3 1/1
#1 lore raw
Quoted 1 line · Arne Schwabe

The problematic behaviour happens when start a profile without

That sentence can be improved slightly; can be done commit time. I propose:

The problematic behaviour happens when a profile is started without

Quoted 9 lines

auth-user-pass and connect to a server that pushes auth-token When the auth token expires OpenVPN asks for auth User and password again.

The problem is that the auth_user_pass_setup sets auth_user_pass_enabled = true; This function is called from two places. In ssl.c it is only called with an auth-token present or that variable already set. The other one is init_query_passwords.

Quoted 7 lines

Move setting auth_user_pass_enabled to the second place to ensure it is only set if we really want passwords.

Patch v2: Remove unrelated code change
Patch v3: Rebase to master

I've done several attempts to reproduce the ill behavior with
OpenVPN 2.5.7, both local server (using the --management interface), OpenVPN Cloud and OpenVPN Access Server (auto-login profile) without being able to trigger this behavior. Maybe my testing just didn't run long enough. Connections was restarted, servers restarted to wipe state, etc. But it just reconnected again without any issues. So behavior this patch fixes is clearly in the "corner case" area of bugs.

That said, the code looks fine and sane. I can understand the code path and I can see that username/passwords should - in theory - not be asked for when the auth-token expires with this fix; and that it would ask for it without this fix.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
Acked-by on v3 1/1
#2 lore raw
In reply to Arne Schwabe
Quoted 8 lines · On Donnerstag, 17. Februar 2022 19:22:34 CEST Arne Schwabe wrote:
src/openvpn/init.c +1 -0
@@ -590,6 +590,7 @@ init_query_passwords(const struct context *c)
     /* Auth user/pass input */
     if (c->options.auth_user_pass_file)
     {
+        enable_auth_user_pass();
 #ifdef ENABLE_MANAGEMENT
         auth_user_pass_setup(c->options.auth_user_pass_file,

&c->options.sc_info); #else

This should be inside the #ifdef to do exactly the same as before, i.e. doesn't introduce side effects potentially. But then we want to get rid of ENABLE_MANAGEMENT soonish, thus it may not matter.

#3 lore raw

Hi,

Quoted 13 lines · Heiko Hund
Quoted 8 lines · On Donnerstag, 17. Februar 2022 19:22:34 CEST Arne Schwabe wrote:
src/openvpn/init.c +1 -0
@@ -590,6 +590,7 @@ init_query_passwords(const struct context *c)
     /* Auth user/pass input */
     if (c->options.auth_user_pass_file)
     {
+        enable_auth_user_pass();
 #ifdef ENABLE_MANAGEMENT
         auth_user_pass_setup(c->options.auth_user_pass_file,

&c->options.sc_info); #else

This should be inside the #ifdef to do exactly the same as before, i.e. doesn't introduce side effects potentially.

Actually, it shouldn't. The #ifdef is

  #ifdef ENABLE_MANAGEMENT
    auth_user_pass_setup(..., foo)
  #else
    auth_user_pass_setup(..., NULL)
  #endif

so either the enable_auth_user_pass() goes before the #ifdef, or would need to be in both branches. So the patch is fine as it is, one can just not see this from the hunk alone.

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 v4 1/1 Fix OpenVPN querying user/password if auth-token with user expires

In reply to Arne Schwabe

The problematic behaviour happens when start a profile without auth-user-pass and connect to a server that pushes auth-token When the auth token expires OpenVPN asks for auth User and password again.

The problem is that the auth_user_pass_setup sets auth_user_pass_enabled = true; This function is called from two places. In ssl.c it is only called with an auth-token present or that variable already set. The other one is init_query_passwords.

Move setting auth_user_pass_enabled to the second place to ensure it is only set if we really want passwords.

Patch v2: Remove unrelated code change
Patch v3: Rebase to master
Patch v4: Rebase to master

---
 src/openvpn/init.c | 1 +
 src/openvpn/ssl.c  | 7 ++++++-
 src/openvpn/ssl.h  | 3 +++
 3 files changed, 10 insertions(+), 1 deletion(-)
src/openvpn/init.c +1 -0
index 80b077653..5141a35c2 100644
@@ -595,6 +595,7 @@ init_query_passwords(const struct context *c)
     /* Auth user/pass input */
     if (c->options.auth_user_pass_file)
     {
+        enable_auth_user_pass();
 #ifdef ENABLE_MANAGEMENT
         auth_user_pass_setup(c->options.auth_user_pass_file,
                              c->options.auth_user_pass_file_inline,
src/openvpn/ssl.c +6 -1
index 4f28eb568..5ed71f0c5 100644
@@ -394,6 +394,12 @@ static struct user_pass auth_token;     /* GLOBAL */
 static char *auth_challenge; /* GLOBAL */
 #endif
 
+void
+enable_auth_user_pass()
+{
+    auth_user_pass_enabled = true;
+}
+
 void
 auth_user_pass_setup(const char *auth_file, bool is_inline,
                      const struct static_challenge_info *sci)
@@ -405,7 +411,6 @@ auth_user_pass_setup(const char *auth_file, bool is_inline,
         flags |= GET_USER_PASS_INLINE_CREDS;
     }
 
-    auth_user_pass_enabled = true;
     if (!auth_user_pass.defined && !auth_token.defined)
     {
 #ifdef ENABLE_MANAGEMENT
src/openvpn/ssl.h +3 -0
index f8c30762e..9ae6ae8fc 100644
@@ -371,6 +371,9 @@ void tls_post_encrypt(struct tls_multi *multi, struct buffer *buf);
  */
 void pem_password_setup(const char *auth_file);
 
+/* Enables the use of user/password authentication */
+void enable_auth_user_pass();
+
 /*
  * Setup authentication username and password. If auth_file is given, use the
  * credentials stored in the file, however, if is_inline is true then auth_file
Signature · 1 line
2.37.0 (Apple Git-136)
#5 lore raw

Verified that this is just a rebase of v3, to accomodate for the auth_user_pass_setup() changes that have happened in the meantime.

Recording David's and Heiko's ACK, they have done the stare-at-code and actual testing (I have run t_client tests, but they do not excercise this problem with my current test servers - need to add more variants).

I have reworded the commit message along the lines David suggested.

This is a bugfix, so it goes into release/2.5 as well - needed a bit of manual massaging (auth_user_pass_setup() change)

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

commit 7d291e10bccd1d6b9e584307fb5fe3ebfb114ec9 (master) commit af546d798213587285b225cd0031944a81e8e26c (release/2.5)

Author: Arne Schwabe
Date:   Sun Oct 9 15:08:05 2022 +0200
     Fix OpenVPN querying user/password if auth-token with user expires

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

--
kind regards,

Gert Doering

#6 lore raw

Hi,

Quoted 3 lines · Gert Doering

Recording David's and Heiko's ACK, they have done the stare-at-code and actual testing (I have run t_client tests, but they do not excercise this problem with my current test servers - need to add more variants).

Just for the records - testing this with 2.x OpenVPN as server seems to be impossible using built-in --auth-gen-token or using the script interface to --auth-user-pass-verify + --client-connect, because of various reasons (--auth-gen-token does not even trigger when there is no initial username, and the script approach interferes with TLS username locking - patch for that on the list).

That said, I found a way to stage the server side, and can now confirm that *without* this patch, the sequence

- client without --auth-user-pass
- server pushes --auth-token-user + --auth-token
- client sends these as future username/password
- token expire, servers sends AUTH_FAIL

will lead to

- client stops, asking for "Enter Auth Username:" without the patch

- client reverts to sending "no username+password" *with* the patch (the client declares this a "reconnect" and waits 5 seconds, but the connection will recover without user interaction)

(tested for both 2.5 and master)

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]...