Allow inlining of --auth-user-pass
Thanks for reporting! I have poor connectivity and little time this week, but I will look at it when I have a chance.
Sent from mobile
[email protected]... wrote:
and another problem:
Configs without "auth-user-pass" will segfault, for in options_postprocess_verify_ce you do a
streq(options->auth_user_pass_file, "stdin")
without checking first, if options->auth_user_pass_file is not NULL.
so here is fix number three for src/openvpn/misc.c (in fact, it is "old" number one and three) ;-)
[...]
#if P2MP
- if (options->auth_user_pass_file && !options->pull)
+ if ( ( options->auth_user_pass_file || options->auth_user_pass_file_inline) && !options->pull)
msg (M_USAGE, "--auth-user-pass requires --pull");
+
+ if ( ( (options->auth_user_pass_file && !streq(options->auth_user_pass_file, "stdin")) || options->auth_user_pass_file_inline) && options->auth_nocache) + msg (M_USAGE, "Cannot use --auth-nocache with credentials from file");
+
+#ifdef ENABLE_CLIENT_CR
+ if ( ( (options->auth_user_pass_file && !streq(options->auth_user_pass_file, "stdin")) || options->auth_user_pass_file_inline) && options->sc_info.challenge_text) + msg (M_USAGE, "Credentials cannot be in a file if using --static-challenge");
+#endif
[...]
A quick test did work with and without user authentication (only tested inline settzing, not with a file).
Joerg
-------- Original-Nachricht --------
Gesendet: Samstag, 05. Oktober 2013 um 15:57 Uhr
Von: "Max Muster" <[email protected]...>
An: "Davide Brini" <[email protected]...>
Cc: [email protected]
Betreff: Re: [Openvpn-devel] [PATCH] Allow inlining of --auth-user-pass oops, just took my "debug" version of src/openvpn/ssl.c ...
Of course output of string length and especially password in log file is not intended ;-)
Joerg
-------- Original-Nachricht --------
Betreff: Re: [Openvpn-devel] [PATCH] Allow inlining of --auth-user-pass
Von: [email protected]...
An: Davide Brini <[email protected]...>
Kopie (CC): [email protected]
Datum: Sa 05 Okt 2013 15:48:42 CEST
Quoted 435 lines
Hi Davide,
nice idea. But I think I found two small bugs:
First, it won't compile in a config w/oENABLE_CLIENT_CRdefined (there is no "sc_info").
Second, if I'm not mistaken, name and password are not copied correctly:
If # of charachters is (pos - prev), the last charakter is at [pos - prev -1] and to terminate the string you should set [pos - prev] to '\0'. My suggestion (not sure, if the first one works with management enabled, only tested w/o).
Fix insrc/openvpn/misc.c(add #ifdef):
[...]
+
+ if ( ( !streq(options->auth_user_pass_file, "stdin") ||options->auth_user_pass_file_inline) &&options->auth_nocache)
+ msg (M_USAGE, "Cannot use --auth-nocache with credentials from file");(quoted diff) +3
-0+ +#ifdef ENABLE_CLIENT_CR + if ( ( !streq(options->auth_user_pass_file, "stdin") ||
options->auth_user_pass_file_inline) &&options->sc_info.challenge_text)
+ msg (M_USAGE, "Credentials cannot be in a file if using --static-challenge");(quoted diff) +5
-0+#endif + + if (options->auth_user_pass_file_inline) + { + int n_inlined = 0;in
src/openvpn/ssl.cyo should use [pos - prev] instead of [pos - prev +1] [...]
+ {
+strncpy(inlined_username, prev, pos - prev);
+ inlined_username[pos - prev] = '\0';
+ msg (M_INFO, "Using inlined username: %s (POS=%d PREV=%d)",inlined_username, pos, prev);
+ }
+ else
+ {
+strncpy(inlined_password, prev, pos - prev);
+ inlined_password[pos - prev] = '\0';
+ msg (M_INFO, "Using inlined password:
...**%s**",inlined_password);
+ }
[...]I hope it's o.k. just to give the idea but not post full patches again.
Regards
Joerg
*Gesendet:* Donnerstag, 03. Oktober 2013 um 10:30 Uhr
*Von:* "Davide Brini" <[email protected]...>
*An:* [email protected]
*Betreff:* Re: [Openvpn-devel] [PATCH] Allow inlining of --auth-user-pass (previous version contained a leftover debug line left by mistake, sorry)This patch allows inlining of the --auth-user-pass directive, so it is now possible to do
<auth-user-pass>
myusername
mypassword
</auth-user-pass>or supply just the username, eg
<auth-user-pass>
myusername
</auth-user-pass>(in this case the user is prompted for the password only).
The most changed files areoptions.c(sanity check of inlined credentials) andssl.c(actual parsing of the inlined credentials).Udates to the documentation will be provided in a separate patch if and when the present patch is accepted.
As discussed on IRC, for the time being the non-inlined syntax
auth-user-pass [up]
is still supported and [up] is expected to contain username and password on two lines.
Signed-off-by Davide Brini <[email protected]...>---
src/openvpn/init.c| 6 +--src/openvpn/misc.c| 2 +-src/openvpn/options.c| 56 ++++++++++++++++++++++++----src/openvpn/options.h| 2 +src/openvpn/ssl.c| 98 +++++++++++++++++++++++++++++++++++++------------src/openvpn/ssl.h| 2 +-6 files changed, 131 insertions(+), 35 deletions(-)src/openvpn/init.c +3
-3@@ -400,12 +400,12 @@ init_query_passwords (struct context *c)#if P2MP /* Auth user/pass input */ -if (c->options.auth_user_pass_file) +if (c->options.auth_user_pass_file || c->options.auth_user_pass_file_inline) {#ifdef ENABLE_CLIENT_CR -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 }
#endifsrc/openvpn/misc.c +1
-1@@ -1036,7 +1036,7 @@ get_user_pass_cr (struct user_pass *up,if (!up->defined) { -const bool from_stdin = (!auth_file || !strcmp (auth_file,"stdin" )); +const bool from_stdin = (!auth_file ||streq (auth_file,"stdin" ));if (flags &GET_USER_PASS_PREVIOUS_CREDS_FAILED )msg (M_WARN ,"Note: previous '%s' credentials failed" , prefix);src/openvpn/options.c +2
-1@@ -1233,6 +1233,7 @@ show_p2mp_parms (const struct options *o)SHOW_BOOL (client);SHOW_BOOL (pull);SHOW_STR (auth_user_pass_file); +SHOW_STR (auth_user_pass_file_inline);gc_free (&gc); }@@ -2080,7 +2081,7 @@ options_postprocess_verify_ce (const struct options *options, const struct conne if (options->ifconfig_ipv6_local && !options->tun_ipv6 )msg (M_INFO ,"Warning: --ifconfig-ipv6 without --tun-ipv6 will not do IPv6" ); -if (options->auth_user_pass_file) +if ( options->auth_user_pass_file || options->auth_user_pass_file_inline )msg (
M_USAGE, "--auth-user-pass cannot be used with --mode server (it should be used on the client side only)");
if (options->ccd_exclusive&& !options->client_config_dir)
msg (M_USAGE, "--ccd-exclusive must be used with --client-config-dir");src/openvpn/options.c +1
-1@@ -2274,7 +2275,7 @@ options_postprocess_verify_ce (const struct options *options, const struct conne if (sum == 0) {#if P2MP - if (!options->auth_user_pass_file) + if (!options->auth_user_pass_file && !options->auth_user_pass_file_inline)#endif msg (
M_USAGE, "No client-side authentication method is specified. You must use either --cert/--key, --pkcs12, or --auth-user-pass");
}src/openvpn/options.c +6
-1@@ -2350,8 +2351,42 @@ options_postprocess_verify_ce (const struct options *options, const struct conne#endif /* ENABLE_SSL */ #if P2MP -if (options->auth_user_pass_file && !options->pull) +if ( ( options->auth_user_pass_file || options->auth_user_pass_file_inline) && !options->pull)msg (M_USAGE ,"--auth-user-pass requires --pull" ); + +if ( ( !streq (options->auth_user_pass_file,"stdin" ) || options->auth_user_pass_file_inline) && options->auth_nocache) +msg (M_USAGE ,"Cannot use --auth-nocache with credentials from file" ); + + if ( ( !streq(options->auth_user_pass_file, "stdin") ||
options->auth_user_pass_file_inline) &&options->sc_info.challenge_text)
+ msg (M_USAGE, "Credentials cannot be in a file if using --static-challenge");src/openvpn/options.c +28
-0+ +if (options->auth_user_pass_file_inline) + { +int n_inlined =0 ; +const char *pos = options->auth_user_pass_file_inline; +const char *prev = pos; + +if (strlen (pos) ==0 ) +msg (M_USAGE ,"Invalid format for inlined --auth-user-pass" ); + +while ( (pos =strchr (pos,'\n' )) !=NULL ) + { + n_inlined++; + +if (n_inlined >2 ) +msg (M_USAGE ,"Too many lines in inlined --auth-user-pass" ); + +if ( pos - prev >USER_PASS_LEN -1 ) +msg (M_USAGE ,"Line too long in inlined --auth-user-pass" ); + + pos++; + prev = pos; + } + +if ( (n_inlined ==0 ) || (*prev !='\0' ) ) +msg (M_USAGE ,"Invalid format for inlined --auth-user-pass" ); + + }#endif
uninit_options(&defaults);src/openvpn/options.c +10
-4@@ -2719,9 +2754,10 @@ options_postprocess_filechecks (struct options *options) "--management user/password file");#endif /* ENABLE_MANAGEMENT */ #if P2MP - errs |=check_file_access (CHKACC_FILE |CHKACC_ACPTSTDIN , - options->auth_user_pass_file,R_OK , -"--auth-user-pass" ); +if (!streq (options->auth_user_pass_file,INLINE_FILE_TAG )) + errs |=check_file_access (CHKACC_FILE |CHKACC_ACPTSTDIN , + options->auth_user_pass_file,R_OK , +"--auth-user-pass" );#endif /* P2MP */ /* ** System related ** */ @@ -5894,7 +5930,12 @@ add_option (struct options *options,VERIFY_PERMISSION (OPT_P_GENERAL );if (p[1 ]) { - options->auth_user_pass_file = p[1 ]; + options->auth_user_pass_file = p[1 ]; +if (streq (p[1 ],INLINE_FILE_TAG ) && p[2 ]) + { + options->auth_user_pass_file ="stdin" ; + options->auth_user_pass_file_inline = p[2 ]; + } }else
options->auth_user_pass_file= "stdin";src/openvpn/options.c +1
-0@@ -6591,6 +6632,7 @@ add_option (struct options *options,else if (streq (p[0 ],"auth-nocache" )) {VERIFY_PERMISSION (OPT_P_GENERAL ); + options->auth_nocache = true;ssl_set_auth_nocache (); }else if (streq (p[0 ],"auth-token" ) && p[1 ])src/openvpn/options.h +1
-0@@ -292,6 +292,7 @@ struct optionsbool up_delay;bool up_restart;bool daemon; +bool auth_nocache;int remap_sigusr1;@@ -460,6 +461,7 @@ struct optionsbool pull; /* client pull of config options from server */ int
push_continuation;
const char*auth_user_pass_file;
+ const char*auth_user_pass_file_inline;
structoptions_pre_pull*pre_pull;int
server_poll_timeout;src/openvpn/ssl.c +0
-0@@ -354,36 +354,88 @@ static char *auth_challenge; /* GLOBAL */#endif void
-auth_user_pass_setup (const char*auth_file, const structstatic_challenge_info*sci)
+auth_user_pass_setup (const char*auth_file, const char*auth_file_inline, const structstatic_challenge_info*sci)
{src/openvpn/ssl.c +6
-0+ +int extra_flags =0 ; +int n_inlined =0 ; +char inlined_username[USER_PASS_LEN ]; +char inlined_password[USER_PASS_LEN ]; +
auth_user_pass_enabled= true;
+
if (!auth_user_pass.defined)
{
+ if (auth_file&& streq (auth_file, "stdin") &&auth_file_inline)
+ {
+ /* check how much is inlined. */
+ const char *pos =auth_file_inline;
+ const char *prev = pos;src/openvpn/ssl.c +34
-0+ +while ( (pos =strchr (pos,'\n' )) !=NULL ) + { + n_inlined++; + +if (n_inlined ==1 ) + { +strncpy (inlined_username, prev, pos - prev); + inlined_username[pos - prev +1 ] ='\0' ; +msg (M_INFO ,"Using inlined username: %s" , inlined_username); + } +else + { +strncpy (inlined_password, prev, pos - prev); + inlined_password[pos - prev +1 ] ='\0' ; +msg (M_INFO ,"Using inlined password: ..." ); + } + + pos++; + prev = pos; + } + +if (n_inlined ==1 ) + extra_flags =GET_USER_PASS_PASSWORD_ONLY ; + } + +if (n_inlined ==2 ) + { +strcpy (auth_user_pass.username, inlined_username); +strcpy (auth_user_pass.password, inlined_password); + auth_user_pass.defined = true; + } +else + {#if
AUTO_USERID
-get_user_pass_auto_userid(&auth_user_pass,auth_file);
+get_user_pass_auto_userid(&auth_user_pass,auth_file); #else# ifdef ENABLE_CLIENT_CR - if (auth_challenge) /* dynamic challenge/response */ - get_user_pass_cr (&auth_user_pass, - auth_file, - UP_TYPE_AUTH, - GET_USER_PASS_MANAGEMENT|GET_USER_PASS_SENSITIVE|GET_USER_PASS_DYNAMIC_CHALLENGE, - auth_challenge); - else if (sci) /* static challenge response */ - { - int flags = GET_USER_PASS_MANAGEMENT|GET_USER_PASS_SENSITIVE|GET_USER_PASS_STATIC_CHALLENGE; - if (sci->flags & SC_ECHO) - flags |= GET_USER_PASS_STATIC_CHALLENGE_ECHO; - get_user_pass_cr (&auth_user_pass, - auth_file, - UP_TYPE_AUTH, - flags, - sci->challenge_text); - } - else + if (auth_challenge) /* dynamic challenge/response */ + get_user_pass_cr (&auth_user_pass, + auth_file, + UP_TYPE_AUTH, + GET_USER_PASS_MANAGEMENT|GET_USER_PASS_SENSITIVE|GET_USER_PASS_DYNAMIC_CHALLENGE|extra_flags, + auth_challenge); + else if (sci) /* static challenge response */ + { + int flags = GET_USER_PASS_MANAGEMENT|GET_USER_PASS_SENSITIVE|GET_USER_PASS_STATIC_CHALLENGE|extra_flags; + if (sci->flags & SC_ECHO) + flags |= GET_USER_PASS_STATIC_CHALLENGE_ECHO; + + get_user_pass_cr (&auth_user_pass, + auth_file, + UP_TYPE_AUTH, + flags, + sci->challenge_text); + } + else # endif - get_user_pass (&auth_user_pass, auth_file, UP_TYPE_AUTH, GET_USER_PASS_MANAGEMENT|GET_USER_PASS_SENSITIVE); + get_user_pass (&auth_user_pass, auth_file, UP_TYPE_AUTH, GET_USER_PASS_MANAGEMENT|GET_USER_PASS_SENSITIVE|extra_flags); #endif + }src/openvpn/ssl.c +4
-0+ +if (n_inlined ==1 ) +strcpy (auth_user_pass.username, inlined_username); +}
}src/openvpn/ssl.c +2
-2@@ -1892,9 +1944,9 @@ key_method_2_write (struct buffer *buf, struct tls_session *session)if (auth_user_pass_enabled) {#ifdef ENABLE_CLIENT_CR -auth_user_pass_setup (NULL , session->opt->sci); +auth_user_pass_setup (NULL ,NULL , session->opt->sci);#else -auth_user_pass_setup (NULL ,NULL ); +auth_user_pass_setup (NULL ,NULL ,NULL );#endif if (!write_string (buf, auth_user_pass.username,-1 ))goto error;
src/openvpn/ssl.h +1
-1@@ -388,7 +388,7 @@ 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. */ -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,const char *auth_file_inline,const struct static_challenge_info *sc_info);/*
* Ensure that no caching is performed on authentication information
-- 1.7.10.4------------------------------------------------------------------------------ October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel[https://lists.sourceforge.net/lists/listinfo/openvpn-devel]------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk]
Quoted 4 lines
_______________________________________________
Openvpn-devel mailing list
[email protected]...; https://lists.sourceforge.net/lists/listinfo/openvpn-devel[https://lists.sourceforge.net/lists/listinfo/openvpn-devel]
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk[http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk]
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel[https://lists.sourceforge.net/lists/listinfo/openvpn-devel]
Hi Davide,
I had some time today, so I did some changes ("improvements", I hope ;-)) to your code:
First thing you do in add_option() if inline is used: auth_pass_file is set (to "stdin").
So there is no need to check for both (options->auth_user_pass_file || options->auth_user_pass_file_inline), the "existing" check only for "options->auth_user_pass_file" will suffice. That simplifies the patch.
Fixed terminating the copy of the strings.
Simplify tests in options_postprocess_verify_ce():
Fist check if options->auth_user_pass_file is set (as above, it is "allways" set in any auth_user_path case), then it is always safe to do "streq" on options->auth_user_pass_file, too.
Use existing file_check for inline files "CHKACC_INLINE" in options_postprocess_filechecks()
In auth_user_pass_setup() don't change indents, only add "extra_flags"
Kind regards
Joerg
-------- Original-Nachricht --------
Betreff: Re: [Openvpn-devel] [PATCH] Allow inlining of --auth-user-pass
Von: Davide Brini <[email protected]...>
An: [email protected]...
Kopie (CC): [email protected]
Datum: So 06 Okt 2013 21:01:04 CEST
Quoted 5 lines
Thanks for reporting! I have poor connectivity and little time this week, but I will look at it when I have a chance.
Sent from mobile
[email protected]... wrote:
[... snip ...]
openvpn/init.c +2 -2
@@ -401,9 +401,9 @@if (c->options.auth_user_pass_file) {#ifdef ENABLE_CLIENT_CR -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 }#endif
openvpn/misc.c +1 -1
@@ -1044,7 +1044,7 @@if (!up->defined) { -const bool from_stdin = (!auth_file || !strcmp (auth_file,"stdin" )); +const bool from_stdin = (!auth_file ||streq (auth_file,"stdin" ));if (flags &GET_USER_PASS_PREVIOUS_CREDS_FAILED )msg (M_WARN ,"Note: previous '%s' credentials failed" , prefix);
openvpn/options.c +45 -2
77 lines not on this page · raw message
openvpn/options.h +2 -0
@@ -290,6 +290,7 @@bool up_delay;bool up_restart;bool daemon; +bool auth_nocache;int remap_sigusr1;
@@ -459,6 +460,7 @@bool pull;/* client pull of config options from server */ int push_continuation;const char *auth_user_pass_file; +const char *auth_user_pass_file_inline;struct options_pre_pull *pre_pull;int server_poll_timeout;
openvpn/ssl.c +55 -6
94 lines not on this page · raw message
openvpn/ssl.h +1 -1
@@ -388,7 +388,7 @@* Setup authentication username and password. If auth_file is given, use the * credentials stored in the file. */ -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,const char *auth_file_inline,const struct static_challenge_info *sc_info);/* * Ensure that no caching is performed on authentication information
So here we go, your points are all valid. The patch you attached has a spurious line, or maybe it's just my client that doesn't show it correctly, I see
@@ -5835,7 +5872,12 @@
VERIFY_PERMISSION (OPT_P_GENERAL);
if (p[1]) {
- options->auth_user_pass_file = p[1];
+ options->auth_user_pass_file = p[1];
+ if (streq (p[1], INLINE_FILE_TAG) && p[2])
+ { msg (M_WARN, "options.c \n !!!SETTING !!! \n_ +5930,12 @@ add_optio");
+ options->auth_user_pass_file = "stdin";
+ options->auth_user_pass_file_inline = p[2];
+ }
}
I don't think the !!!SETTING !!! line should be there, so I'm going to send a revised patch in a few minutes which essentially includes all your suggestions (and is against master, I'm not sure yours was against master). I'm also citing your contribution in the new text, which I think is deserved.
Thanks also for showing that there is at least another person besides me interested in this functionality!
Signature · 1 line
D.
Yes, your right, there is this one "debugging" line left
(it was just to be sure, the setting of auth_user_pass_file to "stdin" is the first thing done).
-------- Original-Nachricht --------
Betreff: Re: [Openvpn-devel] [PATCH] Allow inlining of --auth-user-pass
Von: Davide Brini <[email protected]...>
An: Max Muster <[email protected]...>
Kopie (CC): [email protected]
Datum: Sa 12 Okt 2013 18:25:56 CEST
Quoted 26 lines
So here we go, your points are all valid. The patch you attached has a spurious line, or maybe it's just my client that doesn't show it correctly, I see
openvpn/options.c +6
-1@@ -5835,7 +5872,12 @@VERIFY_PERMISSION (OPT_P_GENERAL );if (p[1 ]) { - options->auth_user_pass_file = p[1 ]; + options->auth_user_pass_file = p[1 ]; +if (streq (p[1 ],INLINE_FILE_TAG ) && p[2 ]) + {msg (M_WARN ,"options.c \n !!!SETTING !!! \n_ +5930,12 @@ add_optio" ); + options->auth_user_pass_file ="stdin" ; + options->auth_user_pass_file_inline = p[2 ]; + } }I don't think the !!!SETTING !!! line should be there, so I'm going to send a revised patch in a few minutes which essentially includes all your suggestions (and is against master, I'm not sure yours was against master). I'm also citing your contribution in the new text, which I think is deserved.
Thanks also for showing that there is at least another person besides me interested in this functionality!
PATCH 1/1 Allow inlining of --auth-user-pass
This patch allows inlining of the --auth-user-pass directive, so it is now possible to do
<auth-user-pass>
myusername
mypassword
</auth-user-pass>
or supply just the username, eg
<auth-user-pass>
myusername
</auth-user-pass>
(in this case the user is prompted for the password only).
The most changed files are options.c (sanity check of inlined credentials) and ssl.c (actual parsing of the inlined credentials).
Udates to the documentation will be provided in a separate patch if and when the present patch is accepted.
As discussed on IRC, for the time being the non-inlined syntax
auth-user-pass [up]
is still supported and [up] is expected to contain username and password on two lines.
Updated patch to current master, removed printing of the username/password.
--- doc/openvpn.8 | 3 +-- src/openvpn/init.c | 5 ++-- src/openvpn/misc.c | 2 +- src/openvpn/options.c | 43 +++++++++++++++++++++++++++++++++- src/openvpn/options.h | 2 ++ src/openvpn/ssl.c | 61 +++++++++++++++++++++++++++++++++++++++++++----- src/openvpn/ssl.h | 2 +- src/openvpn/ssl_common.h | 1 + 8 files changed, 106 insertions(+), 13 deletions(-)
doc/openvpn.8 +1 -2
@@ -6399,8 +6399,7 @@ X509_1_C=KG .SH INLINE FILE SUPPORT OpenVPN allows including files in the main configuration for the .B \-\-ca, \-\-cert, \-\-dh, \-\-extra\-certs, \-\-key, \-\-pkcs12, \-\-secret -and -.B \-\-tls\-auth +.B \-\-tls\-auth and \-\-auth-user-pass options. Each inline file started by the line
src/openvpn/init.c +3 -2
@@ -421,9 +421,9 @@ init_query_passwords (const struct context *c)if (c->options.auth_user_pass_file) {#ifdef ENABLE_CLIENT_CR -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 }#endif
@@ -2263,6 +2263,7 @@ do_init_crypto_tls (struct context *c, const unsigned int flags)if (options->ccd_exclusive) 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;#endif #ifdef ENABLE_X509_TRACK
src/openvpn/misc.c +1 -1
@@ -1003,7 +1003,7 @@ get_user_pass_cr (struct user_pass *up,if (!up->defined) { -const bool from_stdin = (!auth_file || !strcmp (auth_file,"stdin" )); +const bool from_stdin = (!auth_file ||streq (auth_file,"stdin" ));if (flags &GET_USER_PASS_PREVIOUS_CREDS_FAILED )msg (M_WARN ,"Note: previous '%s' credentials failed" , prefix);
src/openvpn/options.c +42 -1
67 lines not on this page · raw message
src/openvpn/options.h +2 -0
@@ -292,6 +292,7 @@ struct optionsbool up_delay;bool up_restart;bool daemon; +bool auth_nocache;int remap_sigusr1;
@@ -457,6 +458,7 @@ struct optionsint push_continuation;unsigned int push_option_types_found;const char *auth_user_pass_file; +const char *auth_user_pass_file_inline;struct options_pre_pull *pre_pull;int server_poll_timeout;
src/openvpn/ssl.c +55 -6
94 lines not on this page · raw message
src/openvpn/ssl.h +1 -1
@@ -389,7 +389,7 @@ 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. */ -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,const char *auth_file_inline,const struct static_challenge_info *sc_info);/* * Ensure that no caching is performed on authentication information
src/openvpn/ssl_common.h +1 -0
@@ -278,6 +278,7 @@ struct tls_optionsbool auth_user_pass_verify_script_via_file;const char *tmp_dir;const char *auth_user_pass_file; +const char *auth_user_pass_file_inline;/* use the client-config-dir as a positive authenticator */ const char *client_config_dir_exclusive;
Signature · 1 line
2.1.4
PATCH v2 1/1 Allow inlining of --auth-user-pass
This patch allows inlining of the --auth-user-pass directive, so it is now possible to do
<auth-user-pass>
myusername
mypassword
</auth-user-pass>
or supply just the username, eg
<auth-user-pass>
myusername
</auth-user-pass>
(in this case the user is prompted for the password only).
The most changed files are options.c (sanity check of inlined credentials) and ssl.c (actual parsing of the inlined credentials).
Udates to the documentation will be provided in a separate patch if and when the present patch is accepted.
As discussed on IRC, for the time being the non-inlined syntax
auth-user-pass [up]
is still supported and [up] is expected to contain username and password on two lines.
Updated patch to current master, removed printing of the username/password.
--- doc/openvpn.8 | 3 +-- src/openvpn/init.c | 5 ++-- src/openvpn/misc.c | 2 +- src/openvpn/options.c | 45 +++++++++++++++++++++++++++++++++-- src/openvpn/options.h | 2 ++ src/openvpn/ssl.c | 61 +++++++++++++++++++++++++++++++++++++++++++----- src/openvpn/ssl.h | 2 +- src/openvpn/ssl_common.h | 1 + 8 files changed, 107 insertions(+), 14 deletions(-)
doc/openvpn.8 +1 -2
@@ -6399,8 +6399,7 @@ X509_1_C=KG .SH INLINE FILE SUPPORT OpenVPN allows including files in the main configuration for the .B \-\-ca, \-\-cert, \-\-dh, \-\-extra\-certs, \-\-key, \-\-pkcs12, \-\-secret -and -.B \-\-tls\-auth +.B \-\-tls\-auth and \-\-auth-user-pass options. Each inline file started by the line
src/openvpn/init.c +3 -2
@@ -421,9 +421,9 @@ init_query_passwords (const struct context *c)if (c->options.auth_user_pass_file) {#ifdef ENABLE_CLIENT_CR -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 }#endif
@@ -2263,6 +2263,7 @@ do_init_crypto_tls (struct context *c, const unsigned int flags)if (options->ccd_exclusive) 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;#endif #ifdef ENABLE_X509_TRACK
src/openvpn/misc.c +1 -1
@@ -1003,7 +1003,7 @@ get_user_pass_cr (struct user_pass *up,if (!up->defined) { -const bool from_stdin = (!auth_file || !strcmp (auth_file,"stdin" )); +const bool from_stdin = (!auth_file ||streq (auth_file,"stdin" ));if (flags &GET_USER_PASS_PREVIOUS_CREDS_FAILED )msg (M_WARN ,"Note: previous '%s' credentials failed" , prefix);
src/openvpn/options.c +43 -2
74 lines not on this page · raw message
src/openvpn/options.h +2 -0
@@ -292,6 +292,7 @@ struct optionsbool up_delay;bool up_restart;bool daemon; +bool auth_nocache;int remap_sigusr1;
@@ -457,6 +458,7 @@ struct optionsint push_continuation;unsigned int push_option_types_found;const char *auth_user_pass_file; +const char *auth_user_pass_file_inline;struct options_pre_pull *pre_pull;int server_poll_timeout;
src/openvpn/ssl.c +55 -6
94 lines not on this page · raw message
src/openvpn/ssl.h +1 -1
@@ -389,7 +389,7 @@ 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. */ -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,const char *auth_file_inline,const struct static_challenge_info *sc_info);/* * Ensure that no caching is performed on authentication information
src/openvpn/ssl_common.h +1 -0
@@ -278,6 +278,7 @@ struct tls_optionsbool auth_user_pass_verify_script_via_file;const char *tmp_dir;const char *auth_user_pass_file; +const char *auth_user_pass_file_inline;/* use the client-config-dir as a positive authenticator */ const char *client_config_dir_exclusive;
Signature · 1 line
2.1.4
Ack from me.
Tested:
- <auth-user-pass>
myusername
mypassword
</auth-user-pass>
- <auth-user-pass>
myusername
</auth-user-pass>
- auth-userpass username.txt
where username.txt contains only the username. in the last 2 cases openvpn correctly queries the user for the password.
JJK
Quoted 324 lines · Adriaan de Jong
This patch allows inlining of the --auth-user-pass directive, so it is now possible to do
<auth-user-pass>
myusername
mypassword
</auth-user-pass>or supply just the username, eg
<auth-user-pass>
myusername
</auth-user-pass>(in this case the user is prompted for the password only).
The most changed files areoptions.c(sanity check of inlined credentials) andssl.c(actual parsing of the inlined credentials).Udates to the documentation will be provided in a separate patch if and when the present patch is accepted.
As discussed on IRC, for the time being the non-inlined syntax
auth-user-pass [up]
is still supported and [up] is expected to contain username and password on two lines.
Signed-off-by Davide Brini <[email protected]...>Updated patch to current master, removed printing of the username/password.
Signed-off-by Adriaan de Jong <[email protected]...>--- doc/openvpn.8 | 3 +-- src/openvpn/init.c | 5 ++-- src/openvpn/misc.c | 2 +- src/openvpn/options.c | 45 +++++++++++++++++++++++++++++++++-- src/openvpn/options.h | 2 ++ src/openvpn/ssl.c | 61 +++++++++++++++++++++++++++++++++++++++++++----- src/openvpn/ssl.h | 2 +- src/openvpn/ssl_common.h | 1 + 8 files changed, 107 insertions(+), 14 deletions(-)doc/openvpn.8 +1
-2@@ -6399,8 +6399,7 @@ X509_1_C=KG .SH INLINE FILE SUPPORT OpenVPN allows including files in the main configuration for the .B \-\-ca, \-\-cert, \-\-dh, \-\-extra\-certs, \-\-key, \-\-pkcs12, \-\-secret -and -.B \-\-tls\-auth +.B \-\-tls\-auth and \-\-auth-user-pass options. Each inline file started by the linesrc/openvpn/init.c +3
-2@@ -421,9 +421,9 @@ init_query_passwords (const struct context *c)if (c->options.auth_user_pass_file) {#ifdef ENABLE_CLIENT_CR -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 }#endif @@ -2263,6 +2263,7 @@ do_init_crypto_tls (struct context *c, const unsigned int flags)if (options->ccd_exclusive) 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;#endif #ifdef ENABLE_X509_TRACK src/openvpn/misc.c +1
-1@@ -1003,7 +1003,7 @@ get_user_pass_cr (struct user_pass *up,if (!up->defined) { -const bool from_stdin = (!auth_file || !strcmp (auth_file,"stdin" )); +const bool from_stdin = (!auth_file ||streq (auth_file,"stdin" ));if (flags &GET_USER_PASS_PREVIOUS_CREDS_FAILED )msg (M_WARN ,"Note: previous '%s' credentials failed" , prefix);src/openvpn/options.c +43
-2@@ -2320,6 +2320,41 @@ options_postprocess_verify_ce (const struct options *options, const struct conne#if P2MP if (options->auth_user_pass_file && !options->pull)msg (M_USAGE ,"--auth-user-pass requires --pull" ); +if (options->auth_user_pass_file) + { +if ( (!streq (options->auth_user_pass_file,"stdin" ) || options->auth_user_pass_file_inline) && options->auth_nocache) +msg (M_USAGE ,"Cannot use --auth-nocache with credentials from file" ); +#ifdef ENABLE_CLIENT_CR +if ( (!streq (options->auth_user_pass_file,"stdin" ) || options->auth_user_pass_file_inline) && options->sc_info.challenge_text) +msg (M_USAGE ,"Credentials cannot be in a file if using --static-challenge" ); +#endif + } +if (options->auth_user_pass_file_inline) + { +int n_inlined =0 ; +const char *pos = options->auth_user_pass_file_inline; +const char *prev = pos; + +if (strlen (pos) ==0 ) +msg (M_USAGE ,"Invalid format for inlined --auth-user-pass" ); + +while ( (pos =strchr (pos,'\n' )) !=NULL ) + { + n_inlined++; + +if (n_inlined >2 ) +msg (M_USAGE ,"Too many lines in inlined --auth-user-pass" ); + +if ( pos - prev >USER_PASS_LEN -1 ) +msg (M_USAGE ,"Line too long in inlined --auth-user-pass" ); + + pos++; + prev = pos; + } + +if ( (n_inlined ==0 ) || (*prev !='\0' ) ) +msg (M_USAGE ,"Invalid format for inlined --auth-user-pass" ); + }#endif uninit_options (&defaults);@@ -2744,7 +2779,7 @@ options_postprocess_filechecks (struct options *options) "--management user/password file");#endif /* ENABLE_MANAGEMENT */ #if P2MP - errs |=check_file_access (CHKACC_FILE |CHKACC_ACPTSTDIN , + errs |=check_file_access (CHKACC_FILE |CHKACC_ACPTSTDIN |CHKACC_INLINE , options->auth_user_pass_file,R_OK ,"--auth-user-pass" );#endif /* P2MP */ @@ -5932,12 +5967,17 @@ add_option (struct options *options,VERIFY_PERMISSION (OPT_P_GENERAL ); options->server_poll_timeout =positive_atoi (p[1 ]); } -else if (streq (p[0 ],"auth-user-pass" ) && !p[2 ]) +else if (streq (p[0 ],"auth-user-pass" ) && p[1 ] && ((streq (p[1 ],INLINE_FILE_TAG ) && p[2 ]) || !p[2 ]) && !p[3 ]) {VERIFY_PERMISSION (OPT_P_GENERAL );if (p[1 ]) { options->auth_user_pass_file = p[1 ]; +if (streq (p[1 ],INLINE_FILE_TAG ) && p[2 ]) + { + options->auth_user_pass_file ="stdin" ; + options->auth_user_pass_file_inline = p[2 ]; + } }else options->auth_user_pass_file ="stdin" ;@@ -6665,6 +6705,7 @@ add_option (struct options *options,else if (streq (p[0 ],"auth-nocache" ) && !p[1 ]) {VERIFY_PERMISSION (OPT_P_GENERAL ); + options->auth_nocache = true;ssl_set_auth_nocache (); }else if (streq (p[0 ],"auth-token" ) && p[1 ] && !p[2 ])src/openvpn/options.h +2
-0@@ -292,6 +292,7 @@ struct optionsbool up_delay;bool up_restart;bool daemon; +bool auth_nocache;int remap_sigusr1;@@ -457,6 +458,7 @@ struct optionsint push_continuation;unsigned int push_option_types_found;const char *auth_user_pass_file; +const char *auth_user_pass_file_inline;struct options_pre_pull *pre_pull;int server_poll_timeout;src/openvpn/ssl.c +55
-6@@ -362,11 +362,57 @@ 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,const char *auth_file_inline,const struct static_challenge_info *sci) { +int extra_flags =0 ; +int n_inlined =0 ; +char inlined_username[USER_PASS_LEN ]; +char inlined_password[USER_PASS_LEN ]; + auth_user_pass_enabled = true; +if (!auth_user_pass.defined) { +if (auth_file &&streq (auth_file,"stdin" ) && auth_file_inline) + { +/* check how much is inlined. */ +const char *pos = auth_file_inline; +const char *prev = pos; + +while ( (pos =strchr (pos,'\n' )) !=NULL ) + { + n_inlined++; + +if (n_inlined ==1 ) + { +strncpy (inlined_username, prev, pos - prev); + inlined_username[pos - prev] ='\0' ; +msg (M_INFO ,"Using inlined username: %s" , inlined_username); + } +else + { +strncpy (inlined_password, prev, pos - prev); + inlined_password[pos - prev] ='\0' ; +msg (M_INFO ,"Using inlined password: ... " ); + } + + pos++; + prev = pos; + } + +if (n_inlined ==1 ) + extra_flags =GET_USER_PASS_PASSWORD_ONLY ; + } + +if (n_inlined ==2 ) + { +strcpy (auth_user_pass.username, inlined_username); +strcpy (auth_user_pass.password, inlined_password); + auth_user_pass.defined = true; + } +else + { +#if AUTO_USERID get_user_pass_auto_userid (&auth_user_pass, auth_file);#else @@ -375,11 +421,11 @@ auth_user_pass_setup (const char *auth_file, const struct static_challenge_infoget_user_pass_cr (&auth_user_pass, auth_file,UP_TYPE_AUTH , -GET_USER_PASS_MANAGEMENT |GET_USER_PASS_SENSITIVE |GET_USER_PASS_DYNAMIC_CHALLENGE , +GET_USER_PASS_MANAGEMENT |GET_USER_PASS_SENSITIVE |GET_USER_PASS_DYNAMIC_CHALLENGE |extra_flags, auth_challenge); else if (sci) /* static challenge response */ { -int flags =GET_USER_PASS_MANAGEMENT |GET_USER_PASS_SENSITIVE |GET_USER_PASS_STATIC_CHALLENGE ; +int flags =GET_USER_PASS_MANAGEMENT |GET_USER_PASS_SENSITIVE |GET_USER_PASS_STATIC_CHALLENGE |extra_flags;if (sci->flags &SC_ECHO ) flags |=GET_USER_PASS_STATIC_CHALLENGE_ECHO ; get_user_pass_cr (&auth_user_pass,@@ -390,8 +436,11 @@ auth_user_pass_setup (const char *auth_file, const struct static_challenge_info } else# endif -get_user_pass (&auth_user_pass, auth_file,UP_TYPE_AUTH ,GET_USER_PASS_MANAGEMENT |GET_USER_PASS_SENSITIVE ); +get_user_pass (&auth_user_pass, auth_file,UP_TYPE_AUTH ,GET_USER_PASS_MANAGEMENT |GET_USER_PASS_SENSITIVE |extra_flags);#endif + } +if (n_inlined ==1 ) +strcpy (auth_user_pass.username, inlined_username); } }@@ -1925,9 +1974,9 @@ key_method_2_write (struct buffer *buf, struct tls_session *session)if (auth_user_pass_enabled) {#ifdef ENABLE_CLIENT_CR -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 if (!write_string (buf, auth_user_pass.username,-1 )) goto error;src/openvpn/ssl.h +1
-1@@ -389,7 +389,7 @@ 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. */ -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,const char *auth_file_inline,const struct static_challenge_info *sc_info);/* * Ensure that no caching is performed on authentication information src/openvpn/ssl_common.h +1
-0@@ -278,6 +278,7 @@ struct tls_optionsbool auth_user_pass_verify_script_via_file;const char *tmp_dir;const char *auth_user_pass_file; +const char *auth_user_pass_file_inline;/* use the client-config-dir as a positive authenticator */ const char *client_config_dir_exclusive;
Hi,
Quoted 2 lines · Adriaan de Jong
This patch allows inlining of the --auth-user-pass directive, so it is now possible to do
Streams have somewhat crossed here, and I'm not sure if this patch is conflict-free with commit
commit 6e9373c84639382c16d9eb8f1f78f60079bb89df
Author: Michal Ludvig <[email protected]...> Date: Sun Oct 11 10:44:20 2015 +0200
Support for username-only auth file.
"it *should*", but at least one change is causing a conflict:
src/openvpn/misc.c get_user_pass_cr (struct user_pass *up, · line 1009
Quoted 11 lines
src/openvpn/misc.c +1
-1@@ -1003,7 +1003,7 @@ get_user_pass_cr (struct user_pass *up,if (!up->defined) { -const bool from_stdin = (!auth_file || !strcmp (auth_file,"stdin" )); +const bool from_stdin = (!auth_file ||streq (auth_file,"stdin" ));if (flags &GET_USER_PASS_PREVIOUS_CREDS_FAILED )msg (M_WARN ,"Note: previous '%s' credentials failed" , prefix);
This one does no longer apply, as this line is no longer there - OTOH, it's basically just cleanup and no functional change, so the hunk could be left off.
Since you've reviewed this already - could you give it a quick check whether it still does the right thing with the misc.c hunk left off? "I think it does", but would welcome a second opinion.
(No need to re-send the patch, I can just take out this part)
gert
Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...Hi,
Quoted 7 lines · Adriaan de Jong
This patch allows inlining of the --auth-user-pass directive, so it is now possible to do
<auth-user-pass>
myusername
mypassword
</auth-user-pass>
[..]
I still think that this is a useful patch, but it might need a rewrite, given that get_user_pass_cr() learned inline file handling in James' change
commit c9a35a20812aafdacc3682a0379f52126bd567ae
Author: James Yonan <[email protected]...> Date: Thu Mar 3 01:19:05 2016 -0700
Added directive to specify HTTP proxy credentials in config.
The inline directive http-proxy-user-pass can be used to specify proxy credentials in config, e.g.:
(which adds INLINE_TAG handling to the general user/pass auth mechanism)
Quoted 5 lines
src/openvpn/options.c +5
-0+if (options->auth_user_pass_file_inline) + { +int n_inlined =0 ; +const char *pos = options->auth_user_pass_file_inline; +const char *prev = pos;
src/openvpn/options.c options_postprocess_verify_ce (const struct options *options, const struct conne · line 2346
Quoted 10 lines
src/openvpn/options.c +10
-0+ +if (strlen (pos) ==0 ) +msg (M_USAGE ,"Invalid format for inlined --auth-user-pass" ); + +while ( (pos =strchr (pos,'\n' )) !=NULL ) + { + n_inlined++; + +if (n_inlined >2 ) +msg (M_USAGE ,"Too many lines in inlined --auth-user-pass" );
... so this explicit handling is no longer needed, and should go to the general function (if possible).
It also looks like a lot of code, compared to James' patch which does mostly the same thing for http-proxy-user-pass user/password... (but maybe this is just because the generic auth-user-pass stuff is called from many more places).
gert
Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...