Skip to contentSkip to conversation

Move querying username/password from management to a function

PATCH Superseded [email protected]... 3 participants 23 messages Mar 29, 2020 – Apr 5, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Move querying username/password from management to a function

From: Selva Nair <[email protected]...>

This helps the next patch. No functionality changes, only refactoring.

---
 src/openvpn/misc.c | 54 ++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 34 insertions(+), 20 deletions(-)
src/openvpn/misc.c +34 -20
index 1931149..0d5ac30 100644
@@ -116,6 +116,38 @@ hostname_randomize(const char *hostname, struct gc_arena *gc)
 #undef n_rnd_bytes
 }
 
+#ifdef ENABLE_MANAGEMENT
+/* Get username/password from the management interface */
+static bool
+auth_user_pass_mgmt(struct user_pass *up, const char *prefix, const unsigned int flags,
+                    const char *auth_challenge)
+{
+    const char *sc = NULL;
+
+    if (flags & GET_USER_PASS_PREVIOUS_CREDS_FAILED)
+    {
+        management_auth_failure(management, prefix, "previous auth credentials failed");
+    }
+
+    if (auth_challenge && (flags & GET_USER_PASS_STATIC_CHALLENGE))
+    {
+        sc = auth_challenge;
+    }
+    if (!management_query_user_pass(management, up, prefix, flags, sc))
+    {
+        if ((flags & GET_USER_PASS_NOFATAL) != 0)
+        {
+            return false;
+        }
+        else
+        {
+            msg(M_FATAL, "ERROR: could not read %s username/password/ok/string from management interface", prefix);
+        }
+    }
+    return true;
+}
+#endif
+
 /*
  * Get and store a username/password
  */
@@ -149,28 +181,10 @@ get_user_pass_cr(struct user_pass *up,
             && (!from_authfile && (flags & GET_USER_PASS_MANAGEMENT))
             && management_query_user_pass_enabled(management))
         {
-            const char *sc = NULL;
             response_from_stdin = false;
-
-            if (flags & GET_USER_PASS_PREVIOUS_CREDS_FAILED)
+            if (!auth_user_pass_mgmt(up, prefix, flags, auth_challenge))
             {
-                management_auth_failure(management, prefix, "previous auth credentials failed");
-            }
-
-            if (auth_challenge && (flags & GET_USER_PASS_STATIC_CHALLENGE))
-            {
-                sc = auth_challenge;
-            }
-            if (!management_query_user_pass(management, up, prefix, flags, sc))
-            {
-                if ((flags & GET_USER_PASS_NOFATAL) != 0)
-                {
-                    return false;
-                }
-                else
-                {
-                    msg(M_FATAL, "ERROR: could not read %s username/password/ok/string from management interface", prefix);
-                }
+                return false;
             }
         }
         else
Signature · 1 line
2.1.4
#1 lore raw

PATCH 2/2 When auth-user-pass file has no password, query the management

From: Selva Nair <[email protected]...>

If only username is found in the file, redirect the auth-user-pass query to the management on Windows if (i) management-query-passwords is enabled and (ii) stdout is redirected to a log file. These restrictions avoid regressive behaviour: those running from the command line will continue to get the prompt on the console and if both username and password are in the file those will continue to get used.

Note that the management will prompt for both username and password ignoring the username read from the file. As the GUI saves the username, this is a one-time inconvenience.

Currently, the password is queried on the console (or systemd) in such cases. This is not sensible on windows if log file is redirected (prompt goes to the log file), or the console is not available as happens when the GUI is in use.

Trac # 757

---
 src/openvpn/error.c |  9 +++++++++
 src/openvpn/error.h |  3 +++
 src/openvpn/misc.c  | 17 +++++++++++++++++
 3 files changed, 29 insertions(+)
src/openvpn/error.c +9 -0
index ad4f0ef..8ce6873 100644
@@ -190,6 +190,15 @@ errors_to_stderr(void)
 }
 
 /*
+ * Return true if stdout is redirected to log file
+ */
+bool
+is_stdout_redirected(void)
+{
+    return std_redir;
+}
+
+/*
  * Return a file to print messages to before syslog is opened.
  */
 FILE *
src/openvpn/error.h +3 -0
index eaedf17..5078f6a 100644
@@ -398,6 +398,9 @@ nonfatal(const unsigned int err)
     return err & M_FATAL ? (err ^ M_FATAL) | M_NONFATAL : err;
 }
 
+/** Return true if stdout is redirected to log file */
+bool is_stdout_redirected(void);
+
 #include "errlevel.h"
 
 #endif /* ifndef ERROR_H */
src/openvpn/misc.c +17 -0
index 0d5ac30..02afd98 100644
@@ -261,6 +261,23 @@ get_user_pass_cr(struct user_pass *up,
             {
                 strncpy(up->password, password_buf, USER_PASS_LEN);
             }
+            /* The auth-file does not have the password: if we are on Windows
+             * and stdout has been redirected to log file, try to get both username
+             * and password from the management.
+             * Otherwise set to read password from console.
+             */
+#if defined(ENABLE_MANAGEMENT) && defined(_WIN32)
+            else if (is_stdout_redirected()
+                     && management
+                     && (flags & GET_USER_PASS_MANAGEMENT)
+                     && management_query_user_pass_enabled(management))
+            {
+                if (!auth_user_pass_mgmt(up, prefix, flags, auth_challenge))
+                {
+                    return false;
+                }
+            }
+#endif
             else
             {
                 password_from_stdin = 1;
Signature · 1 line
2.1.4
#2 lore raw

Re: [Openvpn-devel] [PATCH 2/2] When auth-user-pass file has no password, query the management

Hi,

Quoted 11 lines · On Sun, Mar 29, 2020 at 4:34 PM <[email protected]...> wrote:

From: Selva Nair <[email protected]...>

If only username is found in the file, redirect the auth-user-pass query to the management on Windows if (i) management-query-passwords is enabled and (ii) stdout is redirected to a log file. These restrictions avoid regressive behaviour: those running from the command line will continue to get the prompt on the console and if both username and password are in the file those will continue to get used.

Quoted 8 lines

Note that the management will prompt for both username and password ignoring the username read from the file. As the GUI saves the username, this is a one-time inconvenience.

Currently, the password is queried on the console (or systemd) in such cases. This is not sensible on windows if log file is redirected (prompt goes to the log file), or the console is not available as happens when the GUI is in use.

Why only Windows? I'd like this for macOS, too!

On a Mac using Tunnelblick (which uses the management interface with management-query-passwords enabled), if the auth-user-pass file contains only the password (and a LF), then the following occurs:

neither stdin nor stderr are a tty device and you have neither a
controlling tty nor systemd - can't ask for 'Enter Auth Password:'. If you used --daemon, you need to use --askpass to make passphrase-protected keys work, and you can not use --auth-nocache.
Exiting due to fatal error

Note: Tunnelblick uses the "--log" option to redirect output to a file. I am assuming that's what is meant by "stdout is redirected to a log file".

It would be nice to have the same behavior on both Windows and Mac. For Tunnelblick, too, the username from the file would be lost but, as with the Windows GUI, the user can opt to save it so it isn't asked for again.

Best regards,

Jon Bullard

author
#3 lore raw

Re: [Openvpn-devel] [PATCH 2/2] When auth-user-pass file has no password, query the management

Hi,

Quoted 19 lines · Jonathan K. Bullard

Hi,

Quoted 15 lines · On Sun, Mar 29, 2020 at 4:34 PM <[email protected]...> wrote:

From: Selva Nair <[email protected]...>

If only username is found in the file, redirect the auth-user-pass query to the management on Windows if (i) management-query-passwords is enabled and (ii) stdout is redirected to a log file. These restrictions avoid regressive behaviour: those running from the command line will continue to get the prompt on the console and if both username and password are in the file those will continue to get used.

Note that the management will prompt for both username and password ignoring the username read from the file. As the GUI saves the username, this is a one-time inconvenience.

Quoted 6 lines
Quoted 4 lines

Currently, the password is queried on the console (or systemd) in such cases. This is not sensible on windows if log file is redirected (prompt goes to the log file), or the console is not available as happens when the GUI is in use.

Why only Windows? I'd like this for macOS, too!

I did not know what other platforms were affected and, in particular, how to handle them.

We can't make this the default as some have systemd. Also on unix-like OSes, we can and we do prompt on the controlling tty even if stdout and stderr are redirected to files or /dev/null.

Quoted 10 lines

On a Mac using Tunnelblick (which uses the management interface with management-query-passwords enabled), if the auth-user-pass file contains only the password (and a LF), then the following occurs:

neither stdin nor stderr are a tty device and you have neither a
controlling tty nor systemd - can't ask for 'Enter Auth Password:'. If you used --daemon, you need to use --askpass to make passphrase-protected keys work, and you can not use --auth-nocache.
Exiting due to fatal error

In those cases it looks obviously wrong to use auth-file with username only, and I would consider that a user error. The purpose of my patch was to handle only some naive usages where the user expects the console prompt to get automatically directed to the GUI. Indeed, that does happen (from user's POV) for all cases except user-pass with only username in a file.

But I agree, we should do something like this for other GUIs such as tunnelblick too.

Quoted 4 lines

Note: Tunnelblick uses the "--log" option to redirect output to a file. I am assuming that's what is meant by "stdout is redirected to a log file".

Yes, that's right. However, that logic wont be proper on OS-X, would it? Command line users who use --log can still see password prompt on /dev/tty. We'll be breaking that behaviour.

I considered checking for env vars like IV_UI_VER set by the UI client, but that's not readily accessible from auth_user_pass_cr() call. Alternatives like checking whether /dev/tty can be opened and/or systemd is available didn't appeal to me. If at all, that would have to be a separate patch.

Any suggestions?

Selva

#4 lore raw

Re: [Openvpn-devel] [PATCH 2/2] When auth-user-pass file has no password, query the management

Hi,

Quoted 4 lines · Selva Nair

Hi,

On Sun, Mar 29, 2020 at 7:13 PM Jonathan K. Bullard <[email protected]...> wrote:

<snip>

Quoted 21 lines
Quoted 9 lines

On a Mac using Tunnelblick (which uses the management interface with management-query-passwords enabled), if the auth-user-pass file contains only the password (and a LF), then the following occurs:

neither stdin nor stderr are a tty device and you have neither a
controlling tty nor systemd - can't ask for 'Enter Auth Password:'. If you used --daemon, you need to use --askpass to make passphrase-protected keys work, and you can not use --auth-nocache.
Exiting due to fatal error

In those cases it looks obviously wrong to use auth-file with username only, and I would consider that a user error. The purpose of my patch was to handle only some naive usages where the user expects the console prompt to get automatically directed to the GUI. Indeed, that does happen (from user's POV) for all cases except user-pass with only username in a file.

But I agree, we should do something like this for other GUIs such as tunnelblick too.

Quoted 1 line
Quoted 7 lines
Quoted 3 lines

Note: Tunnelblick uses the "--log" option to redirect output to a file. I am assuming that's what is meant by "stdout is redirected to a log file".

Yes, that's right. However, that logic wont be proper on OS-X, would it? Command line users who use --log can still see password prompt on /dev/tty. We'll be breaking that behaviour.

If the OS X command line user was using --management-query-passwords (as Tunnelblick does), they wouldn't see the password prompt on /dev/tty, would they? Your patch checks for that, so wouldn't you only need to change

     && defined(_WIN32)
to something like
     && (defined(_WIN32) || TARGET_OSX)

(and add OS X to the comment at the start of the patch).

#5 lore raw

Re: [Openvpn-devel] [PATCH 2/2] When auth-user-pass file has no password, query the management

In reply to Selva Nair

Hi,

Quoted 9 lines · Selva Nair

Yes, that's right. However, that logic wont be proper on OS-X, would it? Command line users who use --log can still see password prompt on /dev/tty. We'll be breaking that behaviour.

I considered checking for env vars like IV_UI_VER set by the UI client, but that's not readily accessible from auth_user_pass_cr() call. Alternatives like checking whether /dev/tty can be opened and/or systemd is available didn't appeal to me. If at all, that would have to be a separate patch.

Not sure if the case "there is an active management client, and --management-query-passwords is set, but we *could* ask on /dev/tty" is really worth considering.

(There might be cases where the management interface is not used for password prompting, in which case /dev/tty is the way to go).

Not sure I'd worry too much about systemd here - as far as I understand, this is somewhat orthogonal to "management interface". So if run from systemd, and querying via systemd, you have no management client connected.

Am I making sense? It's monday morning, halfway through my first cup of tea :-)

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

Re: [Openvpn-devel] [PATCH 2/2] When auth-user-pass file has no password, query the management

Hi,

Quoted 14 lines · Gert Doering

Hi,

Quoted 9 lines · Selva Nair

Yes, that's right. However, that logic wont be proper on OS-X, would it? Command line users who use --log can still see password prompt on /dev/tty. We'll be breaking that behaviour.

I considered checking for env vars like IV_UI_VER set by the UI client, but that's not readily accessible from auth_user_pass_cr() call. Alternatives like checking whether /dev/tty can be opened and/or systemd is available didn't appeal to me. If at all, that would have to be a separate patch.

Quoted 3 lines

Not sure if the case "there is an active management client, and --management-query-passwords is set, but we *could* ask on /dev/tty" is really worth considering.

I agree, but the problem is that we currently do that when auth-file has username but no password.

Current behaviour:
if auth-file is set always read from it
else query management if management-query-passwords is set etc. else ask on /dev/tty or windows console
with a quirk that if auth-file has username but no password, ask on /dev/tty or console, not the management ever..

(ignoring systemd which just replaces the query on console).

I'm all for changing the latter behaviour to query the management if possible,
/dev/tty otherwise. But that's a regression and some may complain.

Quoted 4 lines · Jonathan K. Bullard

If the OS X command line user was using --management-query-passwords (as Tunnelblick does), they wouldn't see the password prompt on /dev/tty, would they?

In case of auth-file missing password, they would see it on /dev/tty on linux, and I would guess on OSX as well, but I've not checked.

Selva

#7 lore raw

Re: [Openvpn-devel] [PATCH 2/2] When auth-user-pass file has no password, query the management

Hi,

Quoted 8 lines · Selva Nair
Quoted 4 lines · Jonathan K. Bullard

If the OS X command line user was using --management-query-passwords (as Tunnelblick does), they wouldn't see the password prompt on /dev/tty, would they?

In case of auth-file missing password, they would see it on /dev/tty on linux, and I would guess on OSX as well, but I've not checked.

The password prompt appears on /dev/tty on OS X only if --daemon is not used.

If --daemon and --management-query-passwords are used but --askpass is not (whether or not --auth-nocache is also used), which is typical for a Tunnelblick configuration on OS X, the following appears in the log:

neither stdin nor stderr are a tty device and you have neither a
controlling tty nor systemd - can't ask for 'Enter Auth Password:'. If you used --daemon, you need to use --askpass to make passphrase-protected keys work, and you can not use --auth-nocache.
Exiting due to fatal error

if --daemon, --management-query-passwords, and --askpass are all used (whether or not --auth-nocache is used), you get:

Need password(s) from management interface, waiting...

If Windows GUI uses --daemon, that could be an additional requirement that would work for Tunnelblick and OS X, which would mean one less incompatibility between Windows and OS X.

Or it could test for Windows || (OS X && --daemon).

Best regards,

Jon Bullard

author
#8 lore raw

Re: [Openvpn-devel] [PATCH 2/2] When auth-user-pass file has no password, query the management

Hi,

Quoted 27 lines · Jonathan K. Bullard

Hi,

Quoted 8 lines · Selva Nair
Quoted 4 lines · Jonathan K. Bullard

If the OS X command line user was using --management-query-passwords (as Tunnelblick does), they wouldn't see the password prompt on /dev/tty, would they?

In case of auth-file missing password, they would see it on /dev/tty on linux, and I would guess on OSX as well, but I've not checked.

The password prompt appears on /dev/tty on OS X only if --daemon is not used.

If --daemon and --management-query-passwords are used but --askpass is not (whether or not --auth-nocache is also used), which is typical for a Tunnelblick configuration on OS X, the following appears in the log:

neither stdin nor stderr are a tty device and you have neither a
controlling tty nor systemd - can't ask for 'Enter Auth
Password:'.
If you used --daemon, you need to use --askpass to make passphrase-protected keys work, and you can not use --auth-nocache.
Exiting due to fatal error

Quoted 9 lines

if --daemon, --management-query-passwords, and --askpass are all used (whether or not --auth-nocache is used), you get:

Need password(s) from management interface, waiting...

If Windows GUI uses --daemon, that could be an additional requirement that would work for Tunnelblick and OS X, which would mean one less incompatibility between Windows and OS X.

--daemon is a unix/linux option (not supported on Windows) and after deamonizing there is no controlling tty leading to the behaviour you mention above. I think that's documented.

Quoted 2 lines

Or it could test for Windows || (OS X && --daemon).

Personally I would prefer to enable this code for all platforms although its a minor regression.

That is, if management-query-passwords is enabled and auth file is missing password, query the management, not on console irrespective of other options and OS. If that's acceptable, I'll submit a v2.

Selva

Quoted 4 lines

Best regards,

Jon Bullard

#9 lore raw

Re: [Openvpn-devel] [PATCH 2/2] When auth-user-pass file has no password, query the management

Hi,

Quoted 6 lines · Selva Nair

Personally I would prefer to enable this code for all platforms although its a minor regression.

That is, if management-query-passwords is enabled and auth file is missing password, query the management, not on console irrespective of other options and OS. If that's acceptable, I'll submit a v2.

I find this reasonable, and can't really think of a situation where the current behaviour might be desirable.

So, yes, changing user-visible behaviour, but in a way that avoids one particular hard-to-explain (or even document) corner case.

For master = 2.5, I'd definitely do this.

For 2.4, I'm not totally sure, but this is something we can discuss in the community meeting if people have a strong opposing opinion (*I* consider the current behaviour to be a bug, and the change a bugfix).

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

Re: [Openvpn-devel] [PATCH 2/2] When auth-user-pass file has no password, query the management

In reply to Selva Nair
Quoted 3 lines · Selva Nair

That is, if management-query-passwords is enabled and auth file is missing password, query the management, not on console irrespective of other options and OS. If that's acceptable, I'll submit a v2.

That's fine with me (and Tunnelblick), thanks.

Best regards,

Jon Bullard

#11 lore raw

PATCH v2 1/2 Move querying username/password from management to a function

In reply to [email protected]...

From: Selva Nair <[email protected]...>

This helps the next patch. No functionality changes, only refactoring.

---
No changes from v1

 src/openvpn/misc.c | 54 ++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 34 insertions(+), 20 deletions(-)
src/openvpn/misc.c +34 -20
index 1931149..0d5ac30 100644
@@ -116,6 +116,38 @@ hostname_randomize(const char *hostname, struct gc_arena *gc)
 #undef n_rnd_bytes
 }
 
+#ifdef ENABLE_MANAGEMENT
+/* Get username/password from the management interface */
+static bool
+auth_user_pass_mgmt(struct user_pass *up, const char *prefix, const unsigned int flags,
+                    const char *auth_challenge)
+{
+    const char *sc = NULL;
+
+    if (flags & GET_USER_PASS_PREVIOUS_CREDS_FAILED)
+    {
+        management_auth_failure(management, prefix, "previous auth credentials failed");
+    }
+
+    if (auth_challenge && (flags & GET_USER_PASS_STATIC_CHALLENGE))
+    {
+        sc = auth_challenge;
+    }
+    if (!management_query_user_pass(management, up, prefix, flags, sc))
+    {
+        if ((flags & GET_USER_PASS_NOFATAL) != 0)
+        {
+            return false;
+        }
+        else
+        {
+            msg(M_FATAL, "ERROR: could not read %s username/password/ok/string from management interface", prefix);
+        }
+    }
+    return true;
+}
+#endif
+
 /*
  * Get and store a username/password
  */
@@ -149,28 +181,10 @@ get_user_pass_cr(struct user_pass *up,
             && (!from_authfile && (flags & GET_USER_PASS_MANAGEMENT))
             && management_query_user_pass_enabled(management))
         {
-            const char *sc = NULL;
             response_from_stdin = false;
-
-            if (flags & GET_USER_PASS_PREVIOUS_CREDS_FAILED)
+            if (!auth_user_pass_mgmt(up, prefix, flags, auth_challenge))
             {
-                management_auth_failure(management, prefix, "previous auth credentials failed");
-            }
-
-            if (auth_challenge && (flags & GET_USER_PASS_STATIC_CHALLENGE))
-            {
-                sc = auth_challenge;
-            }
-            if (!management_query_user_pass(management, up, prefix, flags, sc))
-            {
-                if ((flags & GET_USER_PASS_NOFATAL) != 0)
-                {
-                    return false;
-                }
-                else
-                {
-                    msg(M_FATAL, "ERROR: could not read %s username/password/ok/string from management interface", prefix);
-                }
+                return false;
             }
         }
         else
Signature · 1 line
2.1.4
#12 lore raw

PATCH v2 2/2 When auth-user-pass file has no password, query the management

From: Selva Nair <[email protected]...>

When only username is found in the file, redirect the auth-user-pass query to the management if management-query-passwords is enabled. Otherwise the user is prompted on console, if available, as before.

This changes the behaviour for those who run from the command line, with --management-query-passwords, but still expect the prompt on the console.

Note that the management will prompt for both username and password ignoring the username read from the file. As most GUIs can save the the username, this is a one-time inconvenience.

Currently, the password is queried on the console (or systemd) in such cases. This is not sensible when console is not available (windows GUI, tunnelblick etc.) or when the log is redirected to a file on Windows (for some reason prompt goes to the log file).

Trac # 757

---

v2: Following discussions with Jonathan and Gert, removed the dependence on stdout redirection and applied to all platforms.

 src/openvpn/misc.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
src/openvpn/misc.c +16 -0
index 0d5ac30..546cd71 100644
@@ -261,6 +261,22 @@ get_user_pass_cr(struct user_pass *up,
             {
                 strncpy(up->password, password_buf, USER_PASS_LEN);
             }
+            /* The auth-file does not have the password: get both username
+             * and password from the management if possible.
+             * Otherwise set to read password from console.
+             */
+#if defined(ENABLE_MANAGEMENT)
+            else if (management
+                     && (flags & GET_USER_PASS_MANAGEMENT)
+                     && management_query_user_pass_enabled(management))
+            {
+                msg(D_LOW, "No password found in %s authfile '%s'. Querying the management", prefix, auth_file);
+                if (!auth_user_pass_mgmt(up, prefix, flags, auth_challenge))
+                {
+                    return false;
+                }
+            }
+#endif
             else
             {
                 password_from_stdin = 1;
Signature · 1 line
2.1.4
#13 lore raw

Re: [Openvpn-devel] [PATCH v2 2/2] When auth-user-pass file has no password, query the management

Hi,

Quoted 48 lines · On Mon, Mar 30, 2020 at 2:06 PM <[email protected]...> wrote:

From: Selva Nair <[email protected]...>

When only username is found in the file, redirect the auth-user-pass query to the management if management-query-passwords is enabled. Otherwise the user is prompted on console, if available, as before.

This changes the behaviour for those who run from the command line, with --management-query-passwords, but still expect the prompt on the console.

Note that the management will prompt for both username and password ignoring the username read from the file. As most GUIs can save the the username, this is a one-time inconvenience.

Currently, the password is queried on the console (or systemd) in such cases. This is not sensible when console is not available (windows GUI, tunnelblick etc.) or when the log is redirected to a file on Windows (for some reason prompt goes to the log file).

Trac # 757

---

v2: Following discussions with Jonathan and Gert, removed the dependence on stdout redirection and applied to all platforms.

 src/openvpn/misc.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
src/openvpn/misc.c +9 -0
index 0d5ac30..546cd71 100644
@@ -261,6 +261,22 @@ get_user_pass_cr(struct user_pass *up,
             {
                 strncpy(up->password, password_buf, USER_PASS_LEN);
             }
+            /* The auth-file does not have the password: get both username
+             * and password from the management if possible.
+             * Otherwise set to read password from console.
+             */
+#if defined(ENABLE_MANAGEMENT)
+            else if (management
+                     && (flags & GET_USER_PASS_MANAGEMENT)
+                     && management_query_user_pass_enabled(management))
+            {

src/openvpn/misc.c get_user_pass_cr(struct user_pass *up, · line 282

Quoted 10 lines
src/openvpn/misc.c +7 -0
+                msg(D_LOW, "No password found in %s authfile '%s'. Querying the management", prefix, auth_file);
+                if (!auth_user_pass_mgmt(up, prefix, flags, auth_challenge))
+                {
+                    return false;
+                }
+            }
+#endif
             else
             {
                 password_from_stdin = 1;

Works for Tunnelblick, thanks!

One minor point: in all four places, plus in the email subject, "the management" should be changed to "the management interface".

"Management interface" is the term that is used on the man page.

Best regards,

Jon Bullard

author
#14 lore raw

Re: [Openvpn-devel] [PATCH v2 2/2] When auth-user-pass file has no password, query the management

Hi,

Quoted 23 lines · Jonathan K. Bullard

Hi,

Quoted 20 lines · On Mon, Mar 30, 2020 at 2:06 PM <[email protected]...> wrote:

From: Selva Nair <[email protected]...>

When only username is found in the file, redirect the auth-user-pass query to the management if management-query-passwords is enabled. Otherwise the user is prompted on console, if available, as before.

This changes the behaviour for those who run from the command line, with --management-query-passwords, but still expect the prompt on the console.

Note that the management will prompt for both username and password ignoring the username read from the file. As most GUIs can save the the username, this is a one-time inconvenience.

Currently, the password is queried on the console (or systemd) in such cases. This is not sensible when console is not available (windows GUI, tunnelblick etc.) or when the log is redirected to a file on Windows (for some reason prompt goes to the log file).

Quoted 8 lines
Quoted 1 line

Trac # 757

snip..

Works for Tunnelblick, thanks!

Good to know.

Quoted 5 lines

One minor point: in all four places, plus in the email subject, "the management" should be changed to "the management interface".

agreed.

Selva

Acked-by on v2 2/2
#15 lore raw

[Openvpn-devel] [PATCH applied] Re: When auth-user-pass file has no password, query the management interface

In reply to [email protected]...

Stared-at-code, basic compile / t_client test (which would not excercise this particular code path) on mingw + freebsd. Happily taking Jonathan's "I've tested this on MacOS X with Tunnelblick" as "good enough for me" :-)

I have adjusted all occurrences of "the management" to "the management interface", though I find "I have to go and ask the management" to be a fairly telling statement in itself :-) - I have also changed the commit message subject slightly to point out that there this does not happen "always". The main text is clear enough.

Your patch has been applied to the master branch.

Can I have a joint patch for 2.4 that also updates Changes.rst, please?

(Changes.rst in the master branch needs a "redo from scratch" for the 2.5 release, but this should be mentioned for the 2.4.9 release in release/2.4/Changes.rst)

thanks :)

commit 57578310992d1fbe8eff97049087c5308089acb5

Author: Selva Nair
Date:   Mon Mar 30 14:05:27 2020 -0400
     When auth-user-pass file has no password, query the management interface

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

--
kind regards,

Gert Doering

Acked-by on v2 1/2
#16 lore raw
In reply to [email protected]...

Your patch has been applied to the master branch.

Stared-at-code, test compiled on linux and MinGW. Really just moving code, though "git show --colour-moved=zebra" does not really want to show it.

I've tried to apply it to release/2.4 (as it's a prerequisite for the next patch, which I consider a bugfix) but there are massive merge conflicts due to #ifdef ENABLE_CLIENT_CR and #ifdef ENABLE_CRYPTO still present. So if you could send a backport of both 1v2 + 2v2 to 2.4 (possibly as a joint patch?), as soon as both are merged, that would be appreciated.

commit 8e5d30cf47da63040114c00eab838bbb1c520781 (master)

Author: Selva Nair
Date:   Mon Mar 30 14:05:26 2020 -0400
     Move querying username/password from management to a function

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

--
kind regards,

Gert Doering

#17 lore raw

PATCH 1/2 Move querying username/password from management interface to a function

In reply to [email protected]...

From: Selva Nair <[email protected]...>

This helps the next patch. No functionality changes, only refactoring.

Same as commit 461e566fb274d6f7647dc3aa81c02e4fbf362a23 in master except for additional ifdef ENABLE_CLIENT_CR

---
 src/openvpn/misc.c | 61 ++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 39 insertions(+), 22 deletions(-)
src/openvpn/misc.c +39 -22
index f44c65f..2b0d10c 100644
@@ -880,6 +880,43 @@ absolute_pathname(const char *pathname)
     }
 }
 
+#ifdef ENABLE_MANAGEMENT
+
+/* Get username/password from the management interface */
+static bool
+auth_user_pass_mgmt(struct user_pass *up, const char *prefix, const unsigned int flags,
+                    const char *auth_challenge)
+{
+    const char *sc = NULL;
+
+    if (flags & GET_USER_PASS_PREVIOUS_CREDS_FAILED)
+    {
+        management_auth_failure(management, prefix, "previous auth credentials failed");
+    }
+
+#ifdef ENABLE_CLIENT_CR
+    if (auth_challenge && (flags & GET_USER_PASS_STATIC_CHALLENGE))
+    {
+        sc = auth_challenge;
+    }
+#endif
+
+    if (!management_query_user_pass(management, up, prefix, flags, sc))
+    {
+        if ((flags & GET_USER_PASS_NOFATAL) != 0)
+        {
+            return false;
+        }
+        else
+        {
+            msg(M_FATAL, "ERROR: could not read %s username/password/ok/string from management interface", prefix);
+        }
+    }
+    return true;
+}
+
+#endif /* ifdef ENABLE_MANAGEMENT */
+
 /*
  * Get and store a username/password
  */
@@ -913,30 +950,10 @@ get_user_pass_cr(struct user_pass *up,
             && (!from_authfile && (flags & GET_USER_PASS_MANAGEMENT))
             && management_query_user_pass_enabled(management))
         {
-            const char *sc = NULL;
             response_from_stdin = false;
-
-            if (flags & GET_USER_PASS_PREVIOUS_CREDS_FAILED)
-            {
-                management_auth_failure(management, prefix, "previous auth credentials failed");
-            }
-
-#ifdef ENABLE_CLIENT_CR
-            if (auth_challenge && (flags & GET_USER_PASS_STATIC_CHALLENGE))
+            if (!auth_user_pass_mgmt(up, prefix, flags, auth_challenge))
             {
-                sc = auth_challenge;
-            }
-#endif
-            if (!management_query_user_pass(management, up, prefix, flags, sc))
-            {
-                if ((flags & GET_USER_PASS_NOFATAL) != 0)
-                {
-                    return false;
-                }
-                else
-                {
-                    msg(M_FATAL, "ERROR: could not read %s username/password/ok/string from management interface", prefix);
-                }
+                return false;
             }
         }
         else
Signature · 1 line
2.1.4
#18 lore raw

PATCH 2/2 When auth-user-pass file has no password query the management interface (if available).

From: Selva Nair <[email protected]...>

When only username is found in the file, redirect the auth-user-pass query to the management interface if management-query-passwords is enabled. Otherwise the user is prompted on console, if available, as before.

This changes the behaviour for those who run from the command line, with --management-query-passwords, but still expect the prompt on the console.

Note that the management interface will prompt for both username and password ignoring the username read from the file. As most GUIs can save the the username, this is a one-time inconvenience.

Currently, the password is queried on the console (or systemd) in such cases. This is not sensible when console is not available (windows GUI, tunnelblick etc.) or when the log is redirected to a file on Windows (for some reason prompt goes to the log file).

Trac # 757

---
This may be cherry-picked from 57578310992d1fbe8eff97049087c5308089acb5 in master without conflicts.

 src/openvpn/misc.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
src/openvpn/misc.c +16 -0
index 2b0d10c..9c5e96e 100644
@@ -1030,6 +1030,22 @@ get_user_pass_cr(struct user_pass *up,
             {
                 strncpy(up->password, password_buf, USER_PASS_LEN);
             }
+            /* The auth-file does not have the password: get both username
+             * and password from the management interface if possible.
+             * Otherwise set to read password from console.
+             */
+#if defined(ENABLE_MANAGEMENT)
+            else if (management
+                     && (flags & GET_USER_PASS_MANAGEMENT)
+                     && management_query_user_pass_enabled(management))
+            {
+                msg(D_LOW, "No password found in %s authfile '%s'. Querying the management interface", prefix, auth_file);
+                if (!auth_user_pass_mgmt(up, prefix, flags, auth_challenge))
+                {
+                    return false;
+                }
+            }
+#endif
             else
             {
                 password_from_stdin = 1;
Signature · 1 line
2.1.4
Acked-by on v1 2/2
#19 lore raw

Re: [Openvpn-devel] [PATCH 2/2] When auth-user-pass file has no password query the management interface (if available).

HI,

Quoted 6 lines · On Fri, Apr 03, 2020 at 09:17:44PM -0400, [email protected]... wrote:

From: Selva Nair <[email protected]...>

When only username is found in the file, redirect the auth-user-pass query to the management interface if management-query-passwords is enabled. Otherwise the user is prompted on console, if available, as before.

[..]

Quoted 3 lines

---
This may be cherry-picked from 57578310992d1fbe8eff97049087c5308089acb5 in master without conflicts.

And this is what I've done. So we have:

commit 2fe84732d19243df6c7713c185998507419155cd (HEAD -> release/2.4)

Author: Selva Nair <[email protected]...>
Date:   Mon Mar 30 14:05:27 2020 -0400
    When auth-user-pass file has no password query the management interface
    (if available).

    Signed-off-by: Selva Nair <[email protected]...>
    Acked-by: Gert Doering <[email protected]...>
    Message-Id: <[email protected]...>
    URL: https://www.mail-archive.com/[email protected]/msg19655.html
    Signed-off-by: Gert Doering <[email protected]...>
    (cherry picked from commit 57578310992d1fbe8eff97049087c5308089acb5)

quick test build on MinGW and Linux just to ensure I didn't break anything unexpected due to "different context in 2.4, some variables not available" etc, but no :-)

thanks,

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

Re: [Openvpn-devel] [PATCH 2/2] When auth-user-pass file has no password query the management interface (if available).

Hi,

Quoted 12 lines · Gert Doering
Quoted 6 lines · On Fri, Apr 03, 2020 at 09:17:44PM -0400, [email protected]... wrote:

From: Selva Nair <[email protected]...>

When only username is found in the file, redirect the auth-user-pass query to the management interface if management-query-passwords is enabled. Otherwise the user is prompted on console, if available, as before.

[..]

Quoted 3 lines

---
This may be cherry-picked from 57578310992d1fbe8eff97049087c5308089acb5 in master without conflicts.

Quoted 7 lines

And this is what I've done. So we have:

commit 2fe84732d19243df6c7713c185998507419155cd (HEAD -> release/2.4)

Author: Selva Nair <[email protected]...>
Date:   Mon Mar 30 14:05:27 2020 -0400

Shouldn't do early sunday morning merges - one of the main points of asking for a 2.4-specific commit was "Changes.rst", which needs to be updated to document changed behaviour... which I had forgotten again.

I'll do this on the "prepare for 2.4.9 release" commit now, but would really prefer to have it in the commit that contains the actual change (if feasible).

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]...
Acked-by on v1 1/2
#21 lore raw

[Openvpn-devel] [PATCH applied] Re: Move querying username/password from management interface to a function

In reply to [email protected]...

Thanks. Verified that it's indeed the same change with an extra #ifdef ENABLE_CLIENT_CR - "diffing the diffs" wasn't straightforward here.

Your patch has been applied to the release/2.4 branch.

commit 908eae5ce4b0b696fc335b6244b2e85c4d49c22a

Author: Selva Nair
Date:   Fri Apr 3 21:17:43 2020 -0400
     Move querying username/password from management interface to a function

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

--
kind regards,

Gert Doering

Acked-by on v1 1/2
#22 lore raw

[Openvpn-devel] [PATCH applied] Re: Move querying username/password from management interface to a function

In reply to [email protected]...

Thanks. Verified that it's indeed the same change with an extra #ifdef ENABLE_CLIENT_CR - "diffing the diffs" wasn't straightforward here.

Your patch has been applied to the release/2.4 branch.

commit 908eae5ce4b0b696fc335b6244b2e85c4d49c22a

Author: Selva Nair
Date:   Fri Apr 3 21:17:43 2020 -0400
     Move querying username/password from management interface to a function

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

--
kind regards,

Gert Doering