Make push-peer-info visible in "normal" per-instance environment.
PATCH 1/1 Make push-peer-info visible in "normal" per-instance environment.
Without this patch, peer-info pushed by clients in the TLS handshake is only visible on the management interface, and only if --management-client-auth is enabled.
With this patch, received records are sanitized and put into the normal "multi instance" environment, where it can be evaluated by --client-connect or --auth-user-pass-verify scripts and plugins, etc. Only records matching a fairly strict "name=value" format are accepted, and only names starting with IV_ or UV_ are exported, to avoid clients sending funny stuff and playing havoc with script/plugin environments on the server.
The change is somewhat invasive as reception of the peer_info string was only done when username+password are expected from the client, but the data is always there (if the client sends no username/password, it will send 0-length strings, so always extracting 3 strings is safe). Also, the sanitation function validate_peer_info_line() and the opts->peer_info field were only compiled in #ifdef MANGEMENT_DEF_AUTH...
Remaining drawback: now this data is sent *twice* on the management interface, so this needs to be fixed. Patch v1 just to collect feedback.
--- src/openvpn/manage.c | 27 ------------------------ src/openvpn/multi.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ src/openvpn/multi.h | 3 ++ src/openvpn/ssl.c | 35 ++++++++++++++++++++------------ src/openvpn/ssl_common.h | 8 ++++-- 5 files changed, 80 insertions(+), 43 deletions(-)
src/openvpn/manage.c +0 -27
@@ -2361,33 +2361,6 @@ management_notify_generic (struct management *man, const char *str)#ifdef MANAGEMENT_DEF_AUTH -static bool -validate_peer_info_line (const char *line) -{ -uint8_t c; -int state =0 ; -while ((c=*line++)) - { -switch (state) - { -case 0 : -case 1 : -if (c =='=' && state ==1 ) - state =2 ; -else if (isalnum (c) || c =='_' ) - state =1 ; -else -return false; -case 2 : -if (isprint (c)) - ; -else -return false; - } - } -return (state ==2 ); -} -static void man_output_peer_info_env (struct management *man,struct man_def_auth_context *mdac) {
src/openvpn/multi.c +50 -0
56 lines not on this page · raw message
src/openvpn/multi.h +3 -0
@@ -312,6 +312,9 @@ void multi_close_instance_on_signal (struct multi_context *m, struct multi_instavoid init_management_callback_multi (struct multi_context *m);void uninit_management_callback_multi (struct multi_context *m); +bool validate_peer_info_line (const char *line); +void multi_output_peer_info_env (struct env_set *es,const char * peer_info); +/* * Return true if our output queue is not full */
src/openvpn/ssl.c +22 -13
@@ -1106,6 +1106,8 @@ tls_multi_free (struct tls_multi *multi, bool clear)#ifdef MANAGEMENT_DEF_AUTH man_def_auth_set_client_reason (multi,NULL ); +#endif +#ifdef P2MP_SERVER free (multi->peer_info);#endif
@@ -1994,6 +1996,7 @@ key_method_2_read (struct buffer *buf, struct tls_multi *multi, struct tls_sessistruct gc_arena gc =gc_new ();char *options; +struct user_pass *up;/* allocate temporary objects */ ALLOC_ARRAY_CLEAR_GC (options, char,TLS_OPTIONS_LEN , &gc);
@@ -2029,15 +2032,25 @@ key_method_2_read (struct buffer *buf, struct tls_multi *multi, struct tls_sessi ks->authenticated = false; +/* always extract username + password fields from buf, even if not +* authenticating for it, because otherwise we can't get at the +* peer_info data which follows behind +*/ + ALLOC_OBJ_CLEAR_GC (up, struct user_pass, &gc); + username_status =read_string (buf, up->username,USER_PASS_LEN ); + password_status =read_string (buf, up->password,USER_PASS_LEN ); + +#ifdef P2MP_SERVER +/* get peer info from control channel */ +free (multi->peer_info); + multi->peer_info =read_string_alloc (buf); +if ( multi->peer_info ) +multi_output_peer_info_env (session->opt->es, multi->peer_info); +#endif +if (verify_user_pass_enabled (session)) {/* Perform username/password authentication */ -struct user_pass *up; - - ALLOC_OBJ_CLEAR_GC (up, struct user_pass, &gc); - username_status =read_string (buf, up->username,USER_PASS_LEN ); - password_status =read_string (buf, up->password,USER_PASS_LEN ); -if (!username_status || !password_status) {CLEAR (*up);
@@ -2048,14 +2061,7 @@ key_method_2_read (struct buffer *buf, struct tls_multi *multi, struct tls_sessi } } -#ifdef MANAGEMENT_DEF_AUTH -/* get peer info from control channel */ -free (multi->peer_info); - multi->peer_info =read_string_alloc (buf); -#endif -verify_user_pass (up, multi, session); -CLEAR (*up); }else {
@@ -2069,6 +2075,9 @@ key_method_2_read (struct buffer *buf, struct tls_multi *multi, struct tls_sessi ks->authenticated = true; } +/* clear username and password from memory */ +CLEAR (*up); +/* Perform final authentication checks */ if (ks->authenticated) {
src/openvpn/ssl_common.h +5 -3
@@ -476,14 +476,16 @@ struct tls_multi*/ char *client_reason; +/* Time of last call to tls_authentication_status */ +time_t tas_last; +#endif + +#ifdef P2MP_SERVER /* * A multi-line string of general-purpose info received from peer * over control channel. */ char *peer_info; - -/* Time of last call to tls_authentication_status */ -time_t tas_last;#endif /*
Signature · 1 line
1.7.8.6
PATCH v3 1/1 Make push-peer-info visible in "normal" per-instance environment.
Without this patch, peer-info pushed by clients in the TLS handshake is only visible on the management interface, and only if --management-client-auth is enabled.
With this patch, received records are sanitized and put into the normal "multi instance" environment, where it can be evaluated by --client-connect or --auth-user-pass-verify scripts and plugins, etc. Only records matching a fairly strict "name=value" format are accepted, and only names starting with IV_ or UV_ are exported, to avoid clients sending funny stuff and playing havoc with script/plugin environments on the server. In the "value" part, spaces, non-printable characters and shell metacharacters are replaced by '_'.
The change is somewhat invasive as reception of the peer_info string was only done when username+password are expected from the client, but the data is always there (if the client sends no username/password, it will send 0-length strings, so always extracting 3 strings is safe). Also, the sanitation function validate_peer_info_line() and the opts->peer_info field were only compiled in #ifdef MANGEMENT_DEF_AUTH...
Patch v3: do not call the old man_output_peer_info_env() anymore, unless a management env-filter has been set (= ensure IV_ and UV_ stuff is sent at most *once*, and exactly the way OpenVPN AS expects it). Add substituting of "bad" characters in the environment values.
--- src/openvpn/manage.c | 30 ++-------------------------- src/openvpn/multi.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ src/openvpn/multi.h | 3 +++ src/openvpn/ssl.c | 35 ++++++++++++++++++++------------ src/openvpn/ssl_common.h | 8 +++++--- 5 files changed, 84 insertions(+), 44 deletions(-)
src/openvpn/manage.c +2 -28
@@ -2462,33 +2462,6 @@ management_notify_generic (struct management *man, const char *str)#ifdef MANAGEMENT_DEF_AUTH -static bool -validate_peer_info_line (const char *line) -{ -uint8_t c; -int state =0 ; -while ((c=*line++)) - { -switch (state) - { -case 0 : -case 1 : -if (c =='=' && state ==1 ) - state =2 ; -else if (isalnum (c) || c =='_' ) - state =1 ; -else -return false; -case 2 : -if (isprint (c)) - ; -else -return false; - } - } -return (state ==2 ); -} -static void man_output_peer_info_env (struct management *man,struct man_def_auth_context *mdac) {
@@ -2527,7 +2500,8 @@ management_notify_client_needing_auth (struct management *management, mode ="REAUTH" ;msg (M_CLIENT ,">CLIENT:%s,%lu,%u" , mode, mdac->cid, mda_key_id);man_output_extra_env (management,"CLIENT" ); -man_output_peer_info_env (management, mdac); +if (management->connection.env_filter_level>0 ) +man_output_peer_info_env (management, mdac);man_output_env (es, true, management->connection.env_filter_level,"CLIENT" ); mdac->flags |=DAF_INITIAL_AUTH ; }
src/openvpn/multi.c +52 -0
58 lines not on this page · raw message
src/openvpn/multi.h +3 -0
@@ -312,6 +312,9 @@ void multi_close_instance_on_signal (struct multi_context *m, struct multi_instavoid init_management_callback_multi (struct multi_context *m);void uninit_management_callback_multi (struct multi_context *m); +bool validate_peer_info_line (char *line); +void multi_output_peer_info_env (struct env_set *es,const char * peer_info); +/* * Return true if our output queue is not full */
src/openvpn/ssl.c +22 -13
@@ -1106,6 +1106,8 @@ tls_multi_free (struct tls_multi *multi, bool clear)#ifdef MANAGEMENT_DEF_AUTH man_def_auth_set_client_reason (multi,NULL ); +#endif +#ifdef P2MP_SERVER free (multi->peer_info);#endif
@@ -1996,6 +1998,7 @@ key_method_2_read (struct buffer *buf, struct tls_multi *multi, struct tls_sessistruct gc_arena gc =gc_new ();char *options; +struct user_pass *up;/* allocate temporary objects */ ALLOC_ARRAY_CLEAR_GC (options, char,TLS_OPTIONS_LEN , &gc);
@@ -2031,15 +2034,25 @@ key_method_2_read (struct buffer *buf, struct tls_multi *multi, struct tls_sessi ks->authenticated = false; +/* always extract username + password fields from buf, even if not +* authenticating for it, because otherwise we can't get at the +* peer_info data which follows behind +*/ + ALLOC_OBJ_CLEAR_GC (up, struct user_pass, &gc); + username_status =read_string (buf, up->username,USER_PASS_LEN ); + password_status =read_string (buf, up->password,USER_PASS_LEN ); + +#ifdef P2MP_SERVER +/* get peer info from control channel */ +free (multi->peer_info); + multi->peer_info =read_string_alloc (buf); +if ( multi->peer_info ) +multi_output_peer_info_env (session->opt->es, multi->peer_info); +#endif +if (verify_user_pass_enabled (session)) {/* Perform username/password authentication */ -struct user_pass *up; - - ALLOC_OBJ_CLEAR_GC (up, struct user_pass, &gc); - username_status =read_string (buf, up->username,USER_PASS_LEN ); - password_status =read_string (buf, up->password,USER_PASS_LEN ); -if (!username_status || !password_status) {CLEAR (*up);
@@ -2050,14 +2063,7 @@ key_method_2_read (struct buffer *buf, struct tls_multi *multi, struct tls_sessi } } -#ifdef MANAGEMENT_DEF_AUTH -/* get peer info from control channel */ -free (multi->peer_info); - multi->peer_info =read_string_alloc (buf); -#endif -verify_user_pass (up, multi, session); -CLEAR (*up); }else {
@@ -2071,6 +2077,9 @@ key_method_2_read (struct buffer *buf, struct tls_multi *multi, struct tls_sessi ks->authenticated = true; } +/* clear username and password from memory */ +CLEAR (*up); +/* Perform final authentication checks */ if (ks->authenticated) {
src/openvpn/ssl_common.h +5 -3
@@ -476,14 +476,16 @@ struct tls_multi*/ char *client_reason; +/* Time of last call to tls_authentication_status */ +time_t tas_last; +#endif + +#ifdef P2MP_SERVER /* * A multi-line string of general-purpose info received from peer * over control channel. */ char *peer_info; - -/* Time of last call to tls_authentication_status */ -time_t tas_last;#endif /*
Signature · 1 line
1.8.1.5
Am 05.05.13 14:36, schrieb Gert Doering:
Quoted 20 lines
Without this patch, peer-info pushed by clients in the TLS handshake is only visible on the management interface, and only if --management-client-auth is enabled.
With this patch, received records are sanitized and put into the normal "multi instance" environment, where it can be evaluated by --client-connect or --auth-user-pass-verify scripts and plugins, etc. Only records matching a fairly strict "name=value" format are accepted, and only names starting with
IV_orUV_are exported, to avoid clients sending funny stuff and playing havoc with script/plugin environments on the server. In the "value" part, spaces, non-printable characters and shell metacharacters are replaced by '_'.The change is somewhat invasive as reception of the
peer_infostring was only done when username+password are expected from the client, but the data is always there (if the client sends no username/password, it will send 0-length strings, so always extracting 3 strings is safe). Also, the sanitation functionvalidate_peer_info_line()and theopts->peer_infofield were only compiled in #ifdefMANGEMENT_DEF_AUTH...
Quoted 6 lines
Patch v3: do not call the old
man_output_peer_info_env()anymore, unless a management env-filter has been set (= ensureIV_andUV_stuff is sent at most *once*, and exactly the way OpenVPN AS expects it). Add substituting of "bad" characters in the environment values.
ACK
[Openvpn-devel] [PATCH applied] Re: Make push-peer-info visible in normal per-instance environment.
In reply to Gert DoeringYour patch has been applied to the master branch.
commit a8be73799be163909a3b212656dedf03494f0792
Author: Gert Doering Date: Sun May 5 14:36:13 2013 +0200
Make push-peer-info visible in normal per-instance environment.
Signed-off-by: Gert Doering <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/7582--
kind regards,
Gert Doering