auth-user-pass: add support for inline credentials
PATCH 1/2 auth-user-pass: add support for inline credentials
--auth-user-pass is probably the only option expecting a filename as argument that cannot be inline'd as of today.
This patch allows specifying username and password inline in the config file within the <auth-user-pass></auth-user-pass> tag.
This logic was already implemented for --http-proxy-user-pass, therefore it was just about applying it to this specific option as well. Note that the current logic expects username and password to always be specified when inline. Therefore omitting the password will result in storing an empty password.
A later patch will change this behaviour to make it consistent with the classic case (username writte in file), where the password is requested via stdin when missing.
While a it, add an empty line between prototypes in init.c to make uncrustify happy.
--- Changes.rst | 4 ++++ src/openvpn/init.c | 9 +++++++-- src/openvpn/options.c | 12 +++++++----- src/openvpn/options.h | 1 + src/openvpn/ssl.c | 24 ++++++++++++++++++------ src/openvpn/ssl.h | 6 ++++-- src/openvpn/ssl_common.h | 1 + 7 files changed, 42 insertions(+), 15 deletions(-)
Changes.rst +4 -0
@@ -87,6 +87,10 @@ Data channel offloading with ovpn-dco this implies that peers must be running 2.6.0+ in order to have P2P-NCP which brings DATA_V2 packet support. +Inline auth username and password + Username and password can now be specified inline in the configuration file + within the <auth-user-pass></auth-user-pass> tags. + Deprecated features -------------------
src/openvpn/init.c +7 -2
@@ -71,6 +71,7 @@ static const char *saved_pid_file_name; /* GLOBAL */#define CF_INIT_TLS_AUTH_STANDALONE (1<<2)static void do_init_first_time (struct context *c); +static bool do_deferred_p2p_ncp (struct context *c);void
@@ -593,9 +594,12 @@ init_query_passwords(const struct context *c)if (c->options.auth_user_pass_file) {#ifdef ENABLE_MANAGEMENT -auth_user_pass_setup (c->options.auth_user_pass_file, &c->options.sc_info); +auth_user_pass_setup (c->options.auth_user_pass_file, + c->options.auth_user_pass_file, + &c->options.sc_info);#else -auth_user_pass_setup (c->options.auth_user_pass_file,NULL ); +auth_user_pass_setup (c->options.auth_user_pass_file, + c->options.auth_user_pass_file,NULL );#endif } }
@@ -3061,6 +3065,7 @@ do_init_crypto_tls(struct context *c, const unsigned int flags) to.client_config_dir_exclusive = options->client_config_dir; } to.auth_user_pass_file = options->auth_user_pass_file; + to.auth_user_pass_file_inline = options->auth_user_pass_file_inline; to.auth_token_generate = options->auth_token_generate; to.auth_token_lifetime = options->auth_token_lifetime; to.auth_token_call_auth = options->auth_token_call_auth;
src/openvpn/options.c +7 -5
@@ -1556,7 +1556,7 @@ show_p2mp_parms(const struct options *o)SHOW_BOOL (client);SHOW_BOOL (pull); -SHOW_STR (auth_user_pass_file); +SHOW_STR_INLINE (auth_user_pass_file);gc_free (&gc); }
@@ -4027,9 +4027,10 @@ options_postprocess_filechecks(struct options *options) options->management_user_pass,R_OK , "--management user/password file");#endif /* ENABLE_MANAGEMENT */ - errs |=check_file_access (CHKACC_FILE |CHKACC_ACPTSTDIN |CHKACC_PRIVATE , - options->auth_user_pass_file,R_OK , -"--auth-user-pass" ); + errs |=check_file_access_inline (options->auth_user_pass_file_inline, +CHKACC_FILE |CHKACC_ACPTSTDIN |CHKACC_PRIVATE , + options->auth_user_pass_file,R_OK , +"--auth-user-pass" );/* ** System related ** */ errs |=check_file_access (CHKACC_FILE , options->chroot_dir,R_OK |X_OK ,"--chroot directory" );
@@ -7705,10 +7706,11 @@ add_option(struct options *options, }else if (streq (p[0 ],"auth-user-pass" ) && !p[2 ]) { -VERIFY_PERMISSION (OPT_P_GENERAL ); +VERIFY_PERMISSION (OPT_P_GENERAL |OPT_P_INLINE );if (p[1 ]) { options->auth_user_pass_file = p[1 ]; + options->auth_user_pass_file_inline = is_inline; }else {
src/openvpn/options.h +1 -0
@@ -523,6 +523,7 @@ struct optionsint push_continuation;unsigned int push_option_types_found;const char *auth_user_pass_file; +bool auth_user_pass_file_inline;struct options_pre_connect *pre_connect;int scheduled_exit_interval;
src/openvpn/ssl.c +18 -6
@@ -396,23 +396,32 @@ static char *auth_challenge; /* GLOBAL */#endif void -auth_user_pass_setup (const char *auth_file,const struct static_challenge_info *sci) +auth_user_pass_setup (const char *auth_file,bool is_inline, +const struct static_challenge_info *sci) { +unsigned int flags =GET_USER_PASS_MANAGEMENT ; + +if (is_inline) + { + flags |=GET_USER_PASS_INLINE_CREDS ; + } + auth_user_pass_enabled = true;if (!auth_user_pass.defined && !auth_token.defined) {#ifdef ENABLE_MANAGEMENT if (auth_challenge)/* dynamic challenge/response */ { + flags |=GET_USER_PASS_DYNAMIC_CHALLENGE ;get_user_pass_cr (&auth_user_pass, auth_file,UP_TYPE_AUTH , -GET_USER_PASS_MANAGEMENT |GET_USER_PASS_DYNAMIC_CHALLENGE , + flags, auth_challenge); }else if (sci)/* static challenge response */ { -int flags =GET_USER_PASS_MANAGEMENT |GET_USER_PASS_STATIC_CHALLENGE ; + flags |=GET_USER_PASS_STATIC_CHALLENGE ;if (sci->flags &SC_ECHO ) { flags |=GET_USER_PASS_STATIC_CHALLENGE_ECHO ;
@@ -425,7 +434,7 @@ auth_user_pass_setup(const char *auth_file, const struct static_challenge_info * } else#endif /* ifdef ENABLE_MANAGEMENT */ -get_user_pass (&auth_user_pass, auth_file,UP_TYPE_AUTH ,GET_USER_PASS_MANAGEMENT ); +get_user_pass (&auth_user_pass, auth_file,UP_TYPE_AUTH , flags); } }
@@ -2165,9 +2174,12 @@ key_method_2_write(struct buffer *buf, struct tls_multi *multi, struct tls_sessiif (auth_user_pass_enabled || (auth_token.token_defined && auth_token.defined)) {#ifdef ENABLE_MANAGEMENT -auth_user_pass_setup (session->opt->auth_user_pass_file, session->opt->sci); +auth_user_pass_setup (session->opt->auth_user_pass_file, + session->opt->auth_user_pass_file_inline, + session->opt->sci);#else -auth_user_pass_setup (session->opt->auth_user_pass_file,NULL ); +auth_user_pass_setup (session->opt->auth_user_pass_file, + session->opt->auth_user_pass_file_inline,NULL );#endif struct user_pass *up = &auth_user_pass;
src/openvpn/ssl.h +4 -2
@@ -367,9 +367,11 @@ void pem_password_setup(const char *auth_file);/* * Setup authentication username and password. If auth_file is given, use the -* credentials stored in the file. +* credentials stored in the file, however, if is_inline is true then auth_file +* contains the username/password inline. */ -void auth_user_pass_setup (const char *auth_file,const struct static_challenge_info *sc_info); +void auth_user_pass_setup (const char *auth_file,bool is_inline, +const struct static_challenge_info *sc_info);/* * Ensure that no caching is performed on authentication information
src/openvpn/ssl_common.h +1 -0
@@ -366,6 +366,7 @@ struct tls_optionsbool auth_user_pass_verify_script_via_file;const char *tmp_dir;const char *auth_user_pass_file; +bool auth_user_pass_file_inline;bool auth_token_generate;/**< Generate auth-tokens on successful * user/pass auth,seet via
Signature · 1 line
2.35.1
PATCH 2/2 get_user_pass_cr: get password from stdin if missing inline
Until now, when HTTP proxy user and password were specified inline, it was assumed that both creds were specified. A missing password would result in an empty password being stored.
This behaviour is not ideal, as we want to allow the user to store the username, but let the password be entered via stdin.
This affects both http proxy and authentication inline'd creds.
--- Changes.rst | 4 +++- src/openvpn/misc.c | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-)
Changes.rst +3 -1
@@ -89,7 +89,9 @@ Data channel offloading with ovpn-dco Inline auth username and password Username and password can now be specified inline in the configuration file - within the <auth-user-pass></auth-user-pass> tags. + within the <auth-user-pass></auth-user-pass> tags. If the password is + missing OpenVPN will prompt for input via stdin. This applies to inline'd + http-proxy-user-pass too. Deprecated features
src/openvpn/misc.c +5 -0
@@ -197,6 +197,11 @@ get_user_pass_cr(struct user_pass *up,buf_parse (&buf,'\n' , up->username,USER_PASS_LEN ); }buf_parse (&buf,'\n' , up->password,USER_PASS_LEN ); + +if (strlen (up->password) ==0 ) + { + password_from_stdin =1 ; + } }/* * Read from auth file unless this is a dynamic challenge request.
Signature · 1 line
2.35.1
Re: [Openvpn-devel] [PATCH 2/2] get_user_pass_cr: get password from stdin if missing inline
Quoted 37 lines · Antonio Quartulli
Until now, when HTTP proxy user and password were specified inline, it was assumed that both creds were specified. A missing password would result in an empty password being stored.
This behaviour is not ideal, as we want to allow the user to store the username, but let the password be entered via stdin.
This affects both http proxy and authentication inline'd creds.
Signed-off-by Antonio Quartulli <[email protected]...>--- Changes.rst | 4 +++- src/openvpn/misc.c | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-)Changes.rst +0
-0@@ -89,7 +89,9 @@ Data channel offloading with ovpn-dco Inline auth username and password Username and password can now be specified inline in theconfiguration file
Changes.rst +2
-1- within the <auth-user-pass></auth-user-pass> tags. + within the <auth-user-pass></auth-user-pass> tags. If the password is + missing OpenVPN will prompt for input via stdin. This applies toinline'd
Changes.rst +1
-0+ http-proxy-user-pass too. Deprecated featuressrc/openvpn/misc.c +0
-0
src/openvpn/misc.c get_user_pass_cr(struct user_pass *up, · line 204
Quoted 8 lines
src/openvpn/misc.c +4
-0@@ -197,6 +197,11 @@ get_user_pass_cr(struct user_pass *up,buf_parse (&buf,'\n' , up->username,USER_PASS_LEN ); }buf_parse (&buf,'\n' , up->password,USER_PASS_LEN ); + +if (strlen (up->password) ==0 ) + { + password_from_stdin =1 ;
This works when stdin is available, but reading username from file and password from the management interface is still not possible. Currently, if --management-query-passwords and --auth-user-pass are used, the file must contain username and password (management i/f not queried). This patch allows username only files, but only if reading from stdin is possible.
It may be a bit tricky to prompt the management interface in such cases, but if we are improving the UX, this is a good opportunity to do a better job.
Selva
Quoted 14 lines
src/openvpn/misc.c +1
-0+ } }/* * Read from auth file unless this is a dynamic challenge request.
--
2.35.1_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Re: [Openvpn-devel] [PATCH 2/2] get_user_pass_cr: get password from stdin if missing inline
Hi,
Quoted 14 lines · Selva Nair
diff --git a/src/openvpn/misc.c b/src/openvpn/misc.c
index 07f6e202..50f7f975 100644
--- a/src/openvpn/misc.c
+++ b/src/openvpn/misc.c
@@ -197,6 +197,11 @@ get_user_pass_cr(struct user_pass *up,
buf_parse(&buf, '\n', up->username, USER_PASS_LEN);
}
buf_parse(&buf, '\n', up->password, USER_PASS_LEN);
+
+ if (strlen(up->password) == 0)
+ {
+ password_from_stdin = 1;Quoted 1 line
This works when stdin is available, but reading username from file and password from the management interface is still not possible. Currently, if --management-query-passwords and --auth-user-pass are used, the file must contain username and password (management i/f not queried). This patch allows username only files, but only if reading from stdin is possible.
Just to make sure I got your comment right: this patch is not allowing files to have no password (this is allowed already without this patch). This patch is only allowing having no password when doing inline credentials.
Does your comment still apply?
If the mgmt interface has troubles with querying the password, then it means we already have this problem without the patch, right?
Signature · 1 line
Antonio Quartulli
Re: [Openvpn-devel] [PATCH 2/2] get_user_pass_cr: get password from stdin if missing inline
Quoted 29 lines · Antonio Quartulli
Hi,
Quoted 14 lines · Selva Nair
diff --git a/src/openvpn/misc.c b/src/openvpn/misc.c index 07f6e202..50f7f975 100644 --- a/src/openvpn/misc.c +++ b/src/openvpn/misc.c @@ -197,6 +197,11 @@ get_user_pass_cr(struct user_pass *up, buf_parse(&buf, '\n', up->username, USER_PASS_LEN); } buf_parse(&buf, '\n', up->password, USER_PASS_LEN); + + if (strlen(up->password) == 0) + { + password_from_stdin = 1;Quoted 6 lines
This works when stdin is available, but reading username from file and password from the management interface is still not possible. Currently, if --management-query-passwords and --auth-user-pass are used, the file must contain username and password (management i/f not queried). This patch allows username only files, but only if reading from stdin is possible.
Just to make sure I got your comment right: this patch is not allowing files to have no password (this is allowed already without this patch). This patch is only allowing having no password when doing inline credentials.
Quoted 5 lines
Does your comment still apply?
If the mgmt interface has troubles with querying the password, then it means we already have this problem without the patch, right?
Yes, on re-reading the patches, my comment was not totally accurate..
The issue is long-standing one with username/password in file --- if password is missing it's not prompted from the management interface even if management-query-passwords is in effect. Instead it's prompted from stdin which is generally not available when run from a GUI.
So, yes, its not a fault of this patch, except that its committing the same "mistake" of not using the management interface instead of stdin as the fallback when "--management-query-passwords" is in effect.
Selva
Re: [Openvpn-devel] [PATCH 2/2] get_user_pass_cr: get password from stdin if missing inline
Hi,
Quoted 43 lines · Selva Nair
On Wed, Sep 14, 2022 at 3:30 PM Antonio Quartulli <[email protected]... <mailto:[email protected]...>> wrote:
Hi,
On 14/09/2022 21:26, Selva Nair wrote:
> diff --gita/src/openvpn/misc.cb/src/openvpn/misc.c> index07f6e202..50f7f975100644
> ---a/src/openvpn/misc.c
> +++b/src/openvpn/misc.c
> @@ -197,6 +197,11 @@ get_user_pass_cr(structuser_pass*up, > buf_parse(&buf, '\n',up->username,
USER_PASS_LEN);
> }
> buf_parse(&buf, '\n',up->password,USER_PASS_LEN); > +
> + if (strlen(up->password)== 0)
> + {
> +password_from_stdin= 1;
>
>
> This works when stdin is available, but reading username from
file and
> password from the management interface is still not possible.
Currently,
> if --management-query-passwords and --auth-user-pass are used,
the file
> must contain username and password (management i/f not queried).
This
> patch allows username only files, but only if reading from stdin is > possible.Just to make sure I got your comment right: this patch is not allowing files to have no password (this is allowed already without this patch). This patch is only allowing having no password when doing inline credentials.
Does your comment still apply?
If the mgmt interface has troubles with querying the password, then it means we already have this problem without the patch, right?
Quoted 6 lines
Yes, on re-reading the patches, my comment was not totally accurate..
The issue is long-standing one with username/password in file --- if password is missing it's not prompted from the management interface even if management-query-passwords is in effect. Instead it's prompted from stdin which is generally not available when run from a GUI.
So, yes, its not a fault of this patch, except that its committing the same "mistake" of not using the management interface instead of stdin as the fallback when "--management-query-passwords" is in effect.
Ok, thanks for clarifying. Now it all fits together.
I'd say this patch is basically adding another case for which we need password_from_stdin.
How password_from_stdin is consumed is something happened down below in misc.c.
IMHO that would require a separate patch to fix that exact (mis)behaviour. Especially because it requires some extra shuffling of this function (that's my guess at first glance).
But thanks for raising this point - I was not aware of this issue.
Cheers,
Quoted 1 line
Selva
Signature · 1 line
Antonio Quartulli
Hi,
src/openvpn/init.c init_query_passwords(const struct context *c) · line 603
Quoted 10 lines · Antonio Quartulli
#ifdef
ENABLE_MANAGEMENTsrc/openvpn/init.c +5
-2-auth_user_pass_setup (c->options.auth_user_pass_file, &c->options.sc_info); +auth_user_pass_setup (c->options.auth_user_pass_file, + c->options.auth_user_pass_file, + &c->options.sc_info);#else -auth_user_pass_setup (c->options.auth_user_pass_file,NULL ); +auth_user_pass_setup (c->options.auth_user_pass_file, + c->options.auth_user_pass_file,NULL );#endif
This does not look like it would work... the second "..._pass_file" arguments wants to be "..._inline", no?
src/openvpn/ssl.c key_method_2_write(struct buffer *buf, struct tls_multi *multi, struct tls_sessi · line 2183
Quoted 13 lines
src/openvpn/ssl.c +5
-2@@ -2165,9 +2174,12 @@ key_method_2_write(struct buffer *buf, struct tls_multi *multi, struct tls_sessiif (auth_user_pass_enabled || (auth_token.token_defined && auth_token.defined)) {#ifdef ENABLE_MANAGEMENT -auth_user_pass_setup (session->opt->auth_user_pass_file, session->opt->sci); +auth_user_pass_setup (session->opt->auth_user_pass_file, + session->opt->auth_user_pass_file_inline, + session->opt->sci);#else -auth_user_pass_setup (session->opt->auth_user_pass_file,NULL ); +auth_user_pass_setup (session->opt->auth_user_pass_file, + session->opt->auth_user_pass_file_inline,NULL );#endif
This one is better :-)
This aside, the change is surprisingly simple. Seems proxy-user-pass did the grunt work for us...
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]...Hi,
Quoted 14 lines · Gert Doering
Hi,
src/openvpn/init.c init_query_passwords(const struct context *c) · line 603
Quoted 10 lines · Antonio Quartulli
#ifdef ENABLE_MANAGEMENTsrc/openvpn/init.c +5
-2-auth_user_pass_setup (c->options.auth_user_pass_file, &c->options.sc_info); +auth_user_pass_setup (c->options.auth_user_pass_file, + c->options.auth_user_pass_file, + &c->options.sc_info);#else -auth_user_pass_setup (c->options.auth_user_pass_file,NULL ); +auth_user_pass_setup (c->options.auth_user_pass_file, + c->options.auth_user_pass_file,NULL );#endif
Quoted 2 lines
This does not look like it would work... the second "..._pass_file" arguments wants to be "..._inline", no?
ehm, right!
Cheers,
Quoted 22 lines
Quoted 5 lines
src/openvpn/ssl.c +0
-0@@ -2165,9 +2174,12 @@ key_method_2_write(struct buffer *buf, struct tls_multi *multi, struct tls_sessiif (auth_user_pass_enabled || (auth_token.token_defined && auth_token.defined)) {src/openvpn/ssl.c key_method_2_write(struct buffer *buf, struct tls_multi *multi, struct tls_sessi · line 2183
Quoted 10 lines
src/openvpn/ssl.c +5
-2#ifdef ENABLE_MANAGEMENT -auth_user_pass_setup (session->opt->auth_user_pass_file, session->opt->sci); +auth_user_pass_setup (session->opt->auth_user_pass_file, + session->opt->auth_user_pass_file_inline, + session->opt->sci);#else -auth_user_pass_setup (session->opt->auth_user_pass_file,NULL ); +auth_user_pass_setup (session->opt->auth_user_pass_file, + session->opt->auth_user_pass_file_inline,NULL );#endif This one is better :-)
This aside, the change is surprisingly simple. Seems proxy-user-pass did the grunt work for us...
gert
Signature · 1 line
Antonio Quartulli
PATCH v2 1/2 auth-user-pass: add support for inline credentials
In reply to Antonio Quartulli--auth-user-pass is probably the only option expecting a filename as argument that cannot be inline'd as of today.
This patch allows specifying username and password inline in the config file within the <auth-user-pass></auth-user-pass> tag.
This logic was already implemented for --http-proxy-user-pass, therefore it was just about applying it to this specific option as well. Note that the current logic expects username and password to always be specified when inline. Therefore omitting the password will result in storing an empty password.
A later patch will change this behaviour to make it consistent with the classic case (username writte in file), where the password is requested via stdin when missing.
While a it, add an empty line between prototypes in init.c to make uncrustify happy.
---
Changes from v1:
* properly add _inline suffix to 2nd argument of auth_user_pass_setup()
--- Changes.rst | 4 ++++ src/openvpn/init.c | 9 +++++++-- src/openvpn/options.c | 12 +++++++----- src/openvpn/options.h | 1 + src/openvpn/ssl.c | 24 ++++++++++++++++++------ src/openvpn/ssl.h | 6 ++++-- src/openvpn/ssl_common.h | 1 + 7 files changed, 42 insertions(+), 15 deletions(-)
Changes.rst +4 -0
@@ -87,6 +87,10 @@ Data channel offloading with ovpn-dco this implies that peers must be running 2.6.0+ in order to have P2P-NCP which brings DATA_V2 packet support. +Inline auth username and password + Username and password can now be specified inline in the configuration file + within the <auth-user-pass></auth-user-pass> tags. + Deprecated features -------------------
src/openvpn/init.c +7 -2
@@ -71,6 +71,7 @@ static const char *saved_pid_file_name; /* GLOBAL */#define CF_INIT_TLS_AUTH_STANDALONE (1<<2)static void do_init_first_time (struct context *c); +static bool do_deferred_p2p_ncp (struct context *c);void
@@ -593,9 +594,12 @@ init_query_passwords(const struct context *c)if (c->options.auth_user_pass_file) {#ifdef ENABLE_MANAGEMENT -auth_user_pass_setup (c->options.auth_user_pass_file, &c->options.sc_info); +auth_user_pass_setup (c->options.auth_user_pass_file, + c->options.auth_user_pass_file_inline, + &c->options.sc_info);#else -auth_user_pass_setup (c->options.auth_user_pass_file,NULL ); +auth_user_pass_setup (c->options.auth_user_pass_file, + c->options.auth_user_pass_file_inline,NULL );#endif } }
@@ -3061,6 +3065,7 @@ do_init_crypto_tls(struct context *c, const unsigned int flags) to.client_config_dir_exclusive = options->client_config_dir; } to.auth_user_pass_file = options->auth_user_pass_file; + to.auth_user_pass_file_inline = options->auth_user_pass_file_inline; to.auth_token_generate = options->auth_token_generate; to.auth_token_lifetime = options->auth_token_lifetime; to.auth_token_call_auth = options->auth_token_call_auth;
src/openvpn/options.c +7 -5
@@ -1556,7 +1556,7 @@ show_p2mp_parms(const struct options *o)SHOW_BOOL (client);SHOW_BOOL (pull); -SHOW_STR (auth_user_pass_file); +SHOW_STR_INLINE (auth_user_pass_file);gc_free (&gc); }
@@ -4027,9 +4027,10 @@ options_postprocess_filechecks(struct options *options) options->management_user_pass,R_OK , "--management user/password file");#endif /* ENABLE_MANAGEMENT */ - errs |=check_file_access (CHKACC_FILE |CHKACC_ACPTSTDIN |CHKACC_PRIVATE , - options->auth_user_pass_file,R_OK , -"--auth-user-pass" ); + errs |=check_file_access_inline (options->auth_user_pass_file_inline, +CHKACC_FILE |CHKACC_ACPTSTDIN |CHKACC_PRIVATE , + options->auth_user_pass_file,R_OK , +"--auth-user-pass" );/* ** System related ** */ errs |=check_file_access (CHKACC_FILE , options->chroot_dir,R_OK |X_OK ,"--chroot directory" );
@@ -7705,10 +7706,11 @@ add_option(struct options *options, }else if (streq (p[0 ],"auth-user-pass" ) && !p[2 ]) { -VERIFY_PERMISSION (OPT_P_GENERAL ); +VERIFY_PERMISSION (OPT_P_GENERAL |OPT_P_INLINE );if (p[1 ]) { options->auth_user_pass_file = p[1 ]; + options->auth_user_pass_file_inline = is_inline; }else {
src/openvpn/options.h +1 -0
@@ -523,6 +523,7 @@ struct optionsint push_continuation;unsigned int push_option_types_found;const char *auth_user_pass_file; +bool auth_user_pass_file_inline;struct options_pre_connect *pre_connect;int scheduled_exit_interval;
src/openvpn/ssl.c +18 -6
@@ -396,23 +396,32 @@ static char *auth_challenge; /* GLOBAL */#endif void -auth_user_pass_setup (const char *auth_file,const struct static_challenge_info *sci) +auth_user_pass_setup (const char *auth_file,bool is_inline, +const struct static_challenge_info *sci) { +unsigned int flags =GET_USER_PASS_MANAGEMENT ; + +if (is_inline) + { + flags |=GET_USER_PASS_INLINE_CREDS ; + } + auth_user_pass_enabled = true;if (!auth_user_pass.defined && !auth_token.defined) {#ifdef ENABLE_MANAGEMENT if (auth_challenge)/* dynamic challenge/response */ { + flags |=GET_USER_PASS_DYNAMIC_CHALLENGE ;get_user_pass_cr (&auth_user_pass, auth_file,UP_TYPE_AUTH , -GET_USER_PASS_MANAGEMENT |GET_USER_PASS_DYNAMIC_CHALLENGE , + flags, auth_challenge); }else if (sci)/* static challenge response */ { -int flags =GET_USER_PASS_MANAGEMENT |GET_USER_PASS_STATIC_CHALLENGE ; + flags |=GET_USER_PASS_STATIC_CHALLENGE ;if (sci->flags &SC_ECHO ) { flags |=GET_USER_PASS_STATIC_CHALLENGE_ECHO ;
@@ -425,7 +434,7 @@ auth_user_pass_setup(const char *auth_file, const struct static_challenge_info * } else#endif /* ifdef ENABLE_MANAGEMENT */ -get_user_pass (&auth_user_pass, auth_file,UP_TYPE_AUTH ,GET_USER_PASS_MANAGEMENT ); +get_user_pass (&auth_user_pass, auth_file,UP_TYPE_AUTH , flags); } }
@@ -2165,9 +2174,12 @@ key_method_2_write(struct buffer *buf, struct tls_multi *multi, struct tls_sessiif (auth_user_pass_enabled || (auth_token.token_defined && auth_token.defined)) {#ifdef ENABLE_MANAGEMENT -auth_user_pass_setup (session->opt->auth_user_pass_file, session->opt->sci); +auth_user_pass_setup (session->opt->auth_user_pass_file, + session->opt->auth_user_pass_file_inline, + session->opt->sci);#else -auth_user_pass_setup (session->opt->auth_user_pass_file,NULL ); +auth_user_pass_setup (session->opt->auth_user_pass_file, + session->opt->auth_user_pass_file_inline,NULL );#endif struct user_pass *up = &auth_user_pass;
src/openvpn/ssl.h +4 -2
@@ -367,9 +367,11 @@ void pem_password_setup(const char *auth_file);/* * Setup authentication username and password. If auth_file is given, use the -* credentials stored in the file. +* credentials stored in the file, however, if is_inline is true then auth_file +* contains the username/password inline. */ -void auth_user_pass_setup (const char *auth_file,const struct static_challenge_info *sc_info); +void auth_user_pass_setup (const char *auth_file,bool is_inline, +const struct static_challenge_info *sc_info);/* * Ensure that no caching is performed on authentication information
src/openvpn/ssl_common.h +1 -0
@@ -366,6 +366,7 @@ struct tls_optionsbool auth_user_pass_verify_script_via_file;const char *tmp_dir;const char *auth_user_pass_file; +bool auth_user_pass_file_inline;bool auth_token_generate;/**< Generate auth-tokens on successful * user/pass auth,seet via
Signature · 1 line
2.35.1
This is, amazingly, quite straightforward. I assumed major complications but our magic "ask for username and password" function *already* supports inline, we just didn't use it for --aup yet...
I have stared at the code for a bit (looks good, though the multi-line calls to get_user_pass_cr() could use some "folding up" now), and tested with inline
<auth-user-pass>
username
pass
</auth-user-pass>
and also classic --auth-user-pass with/without filename combinations (and, me twisted mind, multiple --auth-user-pass statements in the same invocation - "last one wins").
Works :-)
Your patch has been applied to the master branch.
commit 7d48d31b8226d5e3a5638e2369876381038bf5e2
Author: Antonio Quartulli Date: Sat Sep 17 15:48:32 2022 +0200
auth-user-pass: add support for inline credentials
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg25236.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [PATCH applied] Re: get_user_pass_cr: get password from stdin if missing inline
In reply to Antonio QuartulliAmazingly trivial, as soon as one understands the intricacies of get_user_pass_cr() ;-) - of course I have tested this. Without the patch, <auth-user-pass> with no password will send an empty password, with the patch, it will query on stdin and things will succeed (hard to test in an automated way, though).
I have not tested if this would query via systemd, as I don't have any systemd systems - but since this is using already-existing paths to query for password, I'd expect so.
Now, to management interface - as Selva correctly remarked, all these "we have a username and now need to query for a password" cases should really work via management interface as well, otherwise the user experience (especially on windows) will be fairly poor. Inside auth_user_pass_cr() this should be doable with some reshuffling, and from the documentation I see that the managment interface already knows how to query "only for password". So maybe something like
Quoted 1 line
PASSWORD:Need 'Auth' password user=$username
(extend Need 'Auth' with a username) and the GUI could then present a user/password dialogue with a non-editable "user" field, or so...
Your patch has been applied to the master branch.
commit 39619b7fab213e9cadaa4a8b50b795ad63d9d91f
Author: Antonio Quartulli Date: Wed Sep 14 20:59:37 2022 +0200
get_user_pass_cr: get password from stdin if missing inline
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg25215.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering