Implement exit notifcation via control channel and temporary AUTH_FAIL
cover Implement exit notifcation via control channel and temporary AUTH_FAIL
This patchset consts of three patches and one small clean up patches. The first patch deals with exit notification via control channel instead of using OCC data message if both peers support it.
This is need to avoid implementing OCC exit messages in DCO implementation. In p2p mode this is also implemented keeps the behaviour that an OCC_EXIT triggers a SIGTERM on receiving side. This is questionable but should be addressed in a different patch after a discussion.
The second patch implements a way for OpenVPN server to temporarily reject a user or send them directly to the next server.
To allow testing and using this feature without needing to use the management interface and client-deny, the third patch adds support for providing a AUTH_FAIL message from plugins and scripts.
Finally, here is my own script that I use for testing the custom AUTH_FAIL and auth-pending messages. It will change its behaviour depending on the username:
https://gist.github.com/schwabe/2d412ae9236888b398063317ed6a9be4
Arne Schwabe (4):
Implement exit notification via control channel Cleanup receive_auth_failed and simplify method Implement AUTH_FAIL,TEMP message support
Allow scripts and plugins to set a custom AUTH_FAILED message
doc/man-sections/client-options.rst | 7 +- doc/man-sections/script-options.rst | 30 +++++++ src/openvpn/Makefile.am | 1 + src/openvpn/crypto.h | 5 ++ src/openvpn/forward.c | 4 + src/openvpn/init.c | 9 +- src/openvpn/multi.c | 5 ++ src/openvpn/openvpn.vcxproj | 2 + src/openvpn/openvpn.vcxproj.filters | 3 + src/openvpn/options.c | 14 +++ src/openvpn/options.h | 9 +- src/openvpn/options_util.c | 104 ++++++++++++++++++++++ src/openvpn/options_util.h | 33 +++++++ src/openvpn/push.c | 124 +++++++++++++++++---------- src/openvpn/push.h | 2 + src/openvpn/sig.c | 27 +++++- src/openvpn/ssl.c | 16 +++- src/openvpn/ssl.h | 6 ++ src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_ncp.c | 5 ++ src/openvpn/ssl_verify.c | 74 +++++++++++++++- tests/unit_tests/openvpn/Makefile.am | 1 + tests/unit_tests/openvpn/test_misc.c | 49 +++++++++++ 23 files changed, 474 insertions(+), 57 deletions(-) create mode 100644 src/openvpn/options_util.c create mode 100644 src/openvpn/options_util.h
Signature · 1 line
2.32.0 (Apple Git-132)
PATCH 1/4 Implement exit notification via control channel
Current exit notification relies on data channel messages with specific prefix. Adding these to new data channel modules (DCO) adds uncessary complexity for the data for messages that from their idea belong to the control channel anyway.
This patch adds announcing support for control channel and sending/receving it. We use the simple EXIT message for this.
--- doc/man-sections/client-options.rst | 7 ++++++- src/openvpn/crypto.h | 5 +++++ src/openvpn/forward.c | 4 ++++ src/openvpn/multi.c | 5 +++++ src/openvpn/options.c | 14 ++++++++++++++ src/openvpn/push.c | 19 +++++++++++++++++++ src/openvpn/push.h | 2 ++ src/openvpn/sig.c | 27 +++++++++++++++++++++++++-- src/openvpn/ssl.c | 3 +++ src/openvpn/ssl.h | 3 +++ src/openvpn/ssl_ncp.c | 5 +++++ 11 files changed, 91 insertions(+), 3 deletions(-)
doc/man-sections/client-options.rst +6 -1
@@ -220,9 +220,14 @@ configuration. immediately close its client instance object rather than waiting for a timeout. + If both server and client support sending this message using the control + channel, the message will be sent as control-channel message. Otherwise + the message is sent as data-channel message, which will be ignored by + data-channel offloaded peers. + The **n** parameter (default :code:`1` if not present) controls the maximum number of attempts that the client will try to resend the exit - notification message. + notification message if messages are sent in data-channel mode. In UDP server mode, send :code:`RESTART` control channel command to connected clients. The ``n`` parameter (default :code:`1` if not present)
src/openvpn/crypto.h +5 -0
@@ -264,6 +264,11 @@ struct crypto_options/**< Bit-flag indicating that we do not allow clients that do * not support resending the wrapped client key (WKc) with the * third packet of the three-way handshake */ +#define CO_USE_CC_EXIT_NOTIFY (1<<6) +/**< Bit-flag indicating that explicit exit notifies should be +* send via the control channel instead of using an OCC message +*/ +unsigned int flags;/**< Bit-flags determining behavior of * security operation functions. */ };
src/openvpn/forward.c +4 -0
@@ -241,6 +241,10 @@ check_incoming_control_channel(struct context *c) {receive_auth_pending (c, &buf); } + else if (buf_string_match_head_str(&buf, "EXIT")) + { +receive_exit_message (c, &buf); + } else {msg (D_PUSH_ERRORS ,"WARNING: Received unknown control message: %s" ,BSTR (&buf));
src/openvpn/multi.c +5 -0
@@ -1777,6 +1777,11 @@ multi_client_set_protocol_options(struct context *c) }#endif +if (proto &IV_PROTO_CC_EXIT_NOTIFY ) + { + o->data_channel_crypto_flags |=CO_USE_CC_EXIT_NOTIFY ; + } +/* Select cipher if client supports Negotiable Crypto Parameters */ /* if we have already created our key, we cannot *change* our own
src/openvpn/options.c +14 -0
@@ -8338,6 +8338,20 @@ add_option(struct options *options,msg (msglevel,"Unknown key-derivation method %s" , p[1 ]); } } +else if (streq (p[0 ],"protocol-flags" ) && p[1 ]) + { +for (size_t j =1 ; j <MAX_PARMS && p[j] !=NULL ; j++) + { +if (streq (p[j],"cc-exit" )) + { + options->data_channel_crypto_flags |=CO_USE_CC_EXIT_NOTIFY ; + } +else + { +msg (msglevel,"Unknown protocol-flags flag: %s" , p[j]); + } + } + }else if (streq (p[0 ],"prng" ) && p[1 ] && !p[3 ]) {msg (M_WARN ,"NOTICE: --prng option ignored (SSL library PRNG is used)" );
src/openvpn/push.c +19 -0
@@ -176,6 +176,21 @@ server_pushed_signal(struct context *c, const struct buffer *buffer, const bool } } +void +receive_exit_message (struct context *c,const struct buffer *buffer) +{ +dmsg (D_STREAM_ERRORS ,"Exit message received by peer" ); + c->sig->signal_received =SIGTERM ; + c->sig->signal_text ="remote-exit" ; +#ifdef ENABLE_MANAGEMENT +if (management) + { +management_notify (management,"info" , c->sig->signal_text,"EXIT" ); + } +#endif +} + +void server_pushed_info (struct context *c,const struct buffer *buffer,const int adv)
@@ -604,6 +619,10 @@ prepare_push_reply(struct context *c, struct gc_arena *gc, {push_option_fmt (gc, push_list,M_USAGE ,"key-derivation tls-ekm" ); } +if (o->data_channel_crypto_flags &CO_USE_CC_EXIT_NOTIFY ) + { +push_option_fmt (gc, push_list,M_USAGE ,"protocol-flags cc-exit" ); + }return true; }
src/openvpn/push.h +2 -0
@@ -48,6 +48,8 @@ void receive_auth_failed(struct context *c, const struct buffer *buffer);void server_pushed_signal (struct context *c,const struct buffer *buffer,const bool restart,const int adv); +void receive_exit_message (struct context *c,const struct buffer *buffer); +void server_pushed_info (struct context *c,const struct buffer *buffer,const int adv);
src/openvpn/sig.c +25 -2
@@ -321,20 +321,43 @@ print_status(const struct context *c, struct status_output *so)gc_free (&gc); } + +/* Small helper function to determine if we should be sending exit notifcation +* via control channel */ +static inline bool +cc_exit_notify_enabled (struct context *c) +{ +/* Check if we have TLS active at all */ +if (!c->c2.tls_multi) + { +return false; + } + +const struct key_state *ks =get_primary_key (c->c2.tls_multi); +return (ks->crypto_options.flags &CO_USE_CC_EXIT_NOTIFY ); +} +/* * Handle the triggering and time-wait of explicit * exit notification. */ -static void process_explicit_exit_notification_init (struct context *c) {msg (M_INFO ,"SIGTERM received, sending exit notification to peer" );event_timeout_init (&c->c2.explicit_exit_notification_interval,1 ,0 );reset_coarse_timers (c); +signal_reset (c->sig);halt_non_edge_triggered_signals (); c->c2.explicit_exit_notification_time_wait = now; + +/* Check if we are in TLS mode and should sent the notify via data +* channel */ +if (cc_exit_notify_enabled (c)) + { +send_control_channel_string (c,"EXIT" ,D_PUSH ); + } }void
@@ -351,7 +374,7 @@ process_explicit_exit_notification_timer_wakeup(struct context *c) c->sig->signal_received =SIGTERM ; c->sig->signal_text ="exit-with-notification" ; } -else +else if (!cc_exit_notify_enabled (c)) { c->c2.occ_op =OCC_EXIT ; }
src/openvpn/ssl.c +3 -0
@@ -1940,6 +1940,9 @@ push_peer_info(struct buffer *buf, struct tls_session *session)/* support for P_DATA_V2 */ int iv_proto =IV_PROTO_DATA_V2 ; +/* support for exit notify via control channel */ + iv_proto |=IV_PROTO_CC_EXIT_NOTIFY ; +/* support for receiving push_reply before sending * push request, also signal that the client wants * to get push-reply messages without without requiring a round
src/openvpn/ssl.h +3 -0
@@ -93,6 +93,9 @@* result. */ #define IV_PROTO_NCP_P2P (1<<5) +/** Support for explicit exit notify via control channel */ +#define IV_PROTO_CC_EXIT_NOTIFY (1<<7) +/* Default field in X509 to be username */ #define X509_USERNAME_FIELD_DEFAULT "CN"
src/openvpn/ssl_ncp.c +5 -0
@@ -419,6 +419,11 @@ p2p_ncp_set_options(struct tls_multi *multi, struct tls_session *session) multi->peer_id =0x76706e ;/* 'v' 'p' 'n' */ } +if (iv_proto_peer &IV_PROTO_CC_EXIT_NOTIFY ) + { + session->opt->crypto_flags |=CO_USE_CC_EXIT_NOTIFY ; + } +#if defined(HAVE_EXPORT_KEYING_MATERIAL )if (iv_proto_peer &IV_PROTO_TLS_KEY_EXPORT ) {
Signature · 1 line
2.32.0 (Apple Git-132)
Re: [Openvpn-devel] [PATCH 1/4] Implement exit notification via control channel
Quoted 3 lines
Arne Schwabe <[email protected]...> hat am 18.05.2022 11:32 geschrieben:
Current exit notification relies on data channel messages with specific prefix. Adding these to new data channel modules (DCO) adds uncessary
"unnecessary"
Quoted 5 lines
complexity for the data for messages that from their idea belong to the control channel anyway.
This patch adds announcing support for control channel and sending/receving it. We use the simple EXIT message for this.
[...]
Quoted 25 lines
doc/man-sections/client-options.rst +6
-1@@ -220,9 +220,14 @@ configuration. immediately close its client instance object rather than waiting for a timeout. + If both server and client support sending this message using the control + channel, the message will be sent as control-channel message. Otherwise + the message is sent as data-channel message, which will be ignored by + data-channel offloaded peers. + The **n** parameter (default :code:`1` if not present) controls the maximum number of attempts that the client will try to resend the exit - notification message. + notification message if messages are sent in data-channel mode. In UDP server mode, send :code:`RESTART` control channel command to connected clients. The ``n`` parameter (default :code:`1` if not present)src/openvpn/crypto.h +0
-0
src/openvpn/crypto.h struct crypto_options · line 269
Quoted 6 lines
src/openvpn/crypto.h +3
-0@@ -264,6 +264,11 @@ struct crypto_options/**< Bit-flag indicating that we do not allow clients that do * not support resending the wrapped client key (WKc) with the * third packet of the three-way handshake */ +#define CO_USE_CC_EXIT_NOTIFY (1<<6) +/**< Bit-flag indicating that explicit exit notifies should be +* send via the control channel instead of using an OCC message
"sent"
Quoted 5 lines
src/openvpn/crypto.h +2
-0+*/ +unsigned int flags;/**< Bit-flags determining behavior of * security operation functions. */ };
[...]
src/openvpn/options.c add_option(struct options *options, · line 8341
Quoted 9 lines
src/openvpn/options.c +1
-0@@ -8338,6 +8338,20 @@ add_option(struct options *options,msg (msglevel,"Unknown key-derivation method %s" , p[1 ]); } } +else if (streq (p[0 ],"protocol-flags" ) && p[1 ])
I find it a bit irritating that this patch doesn't add any documentation for this new option. But we have other undocumented options, so I assume this is considered fine for options the user is not supposed to set manually?
Quoted 21 lines
src/openvpn/options.c +13
-0+ { +for (size_t j =1 ; j <MAX_PARMS && p[j] !=NULL ; j++) + { +if (streq (p[j],"cc-exit" )) + { + options->data_channel_crypto_flags |=CO_USE_CC_EXIT_NOTIFY ; + } +else + { +msg (msglevel,"Unknown protocol-flags flag: %s" , p[j]); + } + } + } else if (streq(p[0], "prng") && p[1] && !p[3]) {msg (M_WARN ,"NOTICE: --prng option ignored (SSL library PRNG is used)" );src/openvpn/push.c +0
-0
src/openvpn/push.c server_pushed_signal(struct context *c, const struct buffer *buffer, const bool · line 180
Quoted 5 lines
src/openvpn/push.c +2
-0@@ -176,6 +176,21 @@ server_pushed_signal(struct context *c, const struct buffer *buffer, const bool } } +void +receive_exit_message (struct context *c,const struct buffer *buffer)
buffer is not used, so we can probably remove it?
Quoted 16 lines
src/openvpn/push.c +13
-0+{ +dmsg (D_STREAM_ERRORS ,"Exit message received by peer" ); + c->sig->signal_received =SIGTERM ; + c->sig->signal_text ="remote-exit" ; +#ifdef ENABLE_MANAGEMENT +if (management) + { +management_notify (management,"info" , c->sig->signal_text,"EXIT" ); + } +#endif +} + +void server_pushed_info (struct context *c,const struct buffer *buffer,const int adv)
[...]
src/openvpn/sig.c print_status(const struct context *c, struct status_output *so) · line 325
Quoted 10 lines
src/openvpn/sig.c +2
-0@@ -321,20 +321,43 @@ print_status(const struct context *c, struct status_output *so)gc_free (&gc); } + +/* Small helper function to determine if we should be sending exit notifcation
"should send" (not an error, just a simplification), "notification"
Quoted 21 lines
src/openvpn/sig.c +14
-1+* via control channel */ +static inline bool +cc_exit_notify_enabled (struct context *c) +{ +/* Check if we have TLS active at all */ +if (!c->c2.tls_multi) + { +return false; + } + +const struct key_state *ks =get_primary_key (c->c2.tls_multi); +return (ks->crypto_options.flags &CO_USE_CC_EXIT_NOTIFY ); +} +/* * Handle the triggering and time-wait of explicit * exit notification. */ -static void process_explicit_exit_notification_init (struct context *c)
src/openvpn/sig.c print_status(const struct context *c, struct status_output *so) · line 355
Quoted 10 lines
src/openvpn/sig.c +3
-0{msg (M_INFO ,"SIGTERM received, sending exit notification to peer" );event_timeout_init (&c->c2.explicit_exit_notification_interval,1 ,0 );reset_coarse_timers (c); +signal_reset (c->sig);halt_non_edge_triggered_signals (); c->c2.explicit_exit_notification_time_wait = now; + +/* Check if we are in TLS mode and should sent the notify via data
"should send", "control"
src/openvpn/sig.c print_status(const struct context *c, struct status_output *so) · line 363
Quoted 8 lines
src/openvpn/sig.c +5
-0+* channel */ +if (cc_exit_notify_enabled (c)) + { +send_control_channel_string (c,"EXIT" ,D_PUSH ); + } }void
[...]
Regards,
--
Frank Lichtenheld
PATCH 2/4 Cleanup receive_auth_failed and simplify method
In reply to Arne SchwabeThis simplifies the buffer handling in the method and adds a quick return instead of wrapping the whole method in a if (pull) block
--- src/openvpn/push.c | 96 ++++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 45 deletions(-)
src/openvpn/push.c +51 -45
@@ -53,63 +53,69 @@ receive_auth_failed(struct context *c, const struct buffer *buffer)msg (M_VERB0 ,"AUTH: Received control message: %s" ,BSTR (buffer)); c->options.no_advance = true; -if (c->options.pull) +if (!c->options.pull) { -/* Before checking how to react on AUTH_FAILED, first check if the -* failed auth might be the result of an expired auth-token. -* Note that a server restart will trigger a generic AUTH_FAILED -* instead an AUTH_FAILED,SESSION so handle all AUTH_FAILED message -* identical for this scenario */ -if (ssl_clean_auth_token ()) - { - c->sig->signal_received =SIGUSR1 ;/* SOFT-SIGUSR1 -- Auth failure error */ - c->sig->signal_text ="auth-failure (auth-token)" ; - } -else +return ; + } + +struct buffer buf = *buffer; + +/* If the AUTH_FAIL message ends with a , it is an extended message that +* contains further flags */ +bool authfail_extended =buf_string_compare_advance (&buf,"AUTH_FAILED," ); + +/* Before checking how to react on AUTH_FAILED, first check if the +* failed auth might be the result of an expired auth-token. +* Note that a server restart will trigger a generic AUTH_FAILED +* instead an AUTH_FAILED,SESSION so handle all AUTH_FAILED message +* identical for this scenario */ +if (ssl_clean_auth_token ()) + { + c->sig->signal_received =SIGUSR1 ;/* SOFT-SIGUSR1 -- Auth failure error */ + c->sig->signal_text ="auth-failure (auth-token)" ; + } +else + { +switch (auth_retry_get ()) { -switch (auth_retry_get ()) - { -case AR_NONE : - c->sig->signal_received =SIGTERM ;/* SOFT-SIGTERM -- Auth failure error */ -break ; +case AR_NONE : + c->sig->signal_received =SIGTERM ;/* SOFT-SIGTERM -- Auth failure error */ +break ; -case AR_INTERACT : -ssl_purge_auth (false); +case AR_INTERACT : +ssl_purge_auth (false); -case AR_NOINTERACT : - c->sig->signal_received =SIGUSR1 ;/* SOFT-SIGUSR1 -- Auth failure error */ -break ; +case AR_NOINTERACT : + c->sig->signal_received =SIGUSR1 ;/* SOFT-SIGUSR1 -- Auth failure error */ +break ; -default : -ASSERT (0 ); - } - c->sig->signal_text ="auth-failure" ; +default : +ASSERT (0 ); } + c->sig->signal_text ="auth-failure" ; + }#ifdef ENABLE_MANAGEMENT -if (management) +if (management) + { +const char *reason =NULL ; +if (authfail_extended &&BLEN (&buf)) { -const char *reason =NULL ; -struct buffer buf = *buffer; -if (buf_string_compare_advance (&buf,"AUTH_FAILED," ) &&BLEN (&buf)) - { - reason =BSTR (&buf); - } -management_auth_failure (management,UP_TYPE_AUTH , reason); + reason =BSTR (&buf); } +management_auth_failure (management,UP_TYPE_AUTH , reason); + }#endif -/* -* Save the dynamic-challenge text even when management is defined -*/ - { +/* +* Save the dynamic-challenge text even when management is defined +*/ + {#ifdef ENABLE_MANAGEMENT -struct buffer buf = *buffer; -if (buf_string_match_head_str (&buf,"AUTH_FAILED,CRV1:" ) &&BLEN (&buf)) - { -buf_advance (&buf,12 );/* Length of "AUTH_FAILED," substring */ -ssl_put_auth_challenge (BSTR (&buf)); - } -#endif +if (authfail_extended + &&buf_string_match_head_str (&buf,"CRV1:" ) &&BLEN (&buf)) + { +ssl_put_auth_challenge (BSTR (&buf)); } +#endif } }
Signature · 1 line
2.32.0 (Apple Git-132)
Re: [Openvpn-devel] [PATCH 2/4] Cleanup receive_auth_failed and simplify method
Patch looks reasonable when looking at it with -w.
But I have some suggestions to further simplify the function. See below.
Quoted 11 lines
Arne Schwabe <[email protected]...> hat am 18.05.2022 11:32 geschrieben:
This simplifies the buffer handling in the method and adds a quick return instead of wrapping the whole method in a if (pull) block--- src/openvpn/push.c | 96 ++++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 45 deletions(-)src/openvpn/push.c +0
-0
[...]
Quoted 17 lines
#ifdef
ENABLE_MANAGEMENTsrc/openvpn/push.c +6
-8-if (management) +if (management) + { +const char *reason =NULL ; +if (authfail_extended &&BLEN (&buf)) { -const char *reason =NULL ; -struct buffer buf = *buffer; -if (buf_string_compare_advance (&buf,"AUTH_FAILED," ) &&BLEN (&buf)) - { - reason =BSTR (&buf); - } -management_auth_failure (management,UP_TYPE_AUTH , reason); + reason =BSTR (&buf); } +management_auth_failure (management,UP_TYPE_AUTH , reason);
src/openvpn/push.c
Quoted 10 lines
src/openvpn/push.c +5
-4+ }#endif -/* -* Save the dynamic-challenge text even when management is defined -*/ - { +/* +* Save the dynamic-challenge text even when management is defined +*/ + {
This additional block has no meaning now that you don't define a variable anymore.
Quoted 1 line
#ifdef
ENABLE_MANAGEMENT
This ifdef can be merged with the previous ifdef to further simplify the function.
Quoted 5 lines
src/openvpn/push.c +0
-5-struct buffer buf = *buffer; -if (buf_string_match_head_str (&buf,"AUTH_FAILED,CRV1:" ) &&BLEN (&buf)) - { -buf_advance (&buf,12 );/* Length of "AUTH_FAILED," substring */ -ssl_put_auth_challenge (BSTR (&buf));
src/openvpn/push.c
Quoted 10 lines
src/openvpn/push.c +5
-2- } -#endif +if (authfail_extended + &&buf_string_match_head_str (&buf,"CRV1:" ) &&BLEN (&buf)) + { +ssl_put_auth_challenge (BSTR (&buf)); } +#endif } }
So something like this on top of this patch:
src/openvpn/push.c +4 -8
@@ -104,19 +104,15 @@ receive_auth_failed(struct context *c, const struct buffer *buffer) }management_auth_failure (management,UP_TYPE_AUTH , reason); } -#endif /* * Save the dynamic-challenge text even when management is defined */ +if (authfail_extended + &&buf_string_match_head_str (&buf,"CRV1:" ) &&BLEN (&buf)) { -#ifdef ENABLE_MANAGEMENT -if (authfail_extended - &&buf_string_match_head_str (&buf,"CRV1:" ) &&BLEN (&buf)) - { -ssl_put_auth_challenge (BSTR (&buf)); - } -#endif +ssl_put_auth_challenge (BSTR (&buf)); } +#endif }/*
[email protected]...:~/openvpn/community/openvpn (master *)$ git --no-pager diff
src/openvpn/push.c +4 -8
@@ -104,19 +104,15 @@ receive_auth_failed(struct context *c, const struct buffer *buffer) }management_auth_failure (management,UP_TYPE_AUTH , reason); } -#endif /* * Save the dynamic-challenge text even when management is defined */ +if (authfail_extended + &&buf_string_match_head_str (&buf,"CRV1:" ) &&BLEN (&buf)) { -#ifdef ENABLE_MANAGEMENT -if (authfail_extended - &&buf_string_match_head_str (&buf,"CRV1:" ) &&BLEN (&buf)) - { -ssl_put_auth_challenge (BSTR (&buf)); - } -#endif +ssl_put_auth_challenge (BSTR (&buf)); } +#endif }/*
Regards,
--
Frank Lichtenheld
Re: [Openvpn-devel] [PATCH 2/4] Cleanup receive_auth_failed and simplify method
Quoted 2 lines
Frank Lichtenheld <[email protected]...> hat am 18.05.2022 12:40 geschrieben:
[...]
Quoted 1 line
So something like this on top of this patch:
Somehow managed to double paste the patch. They seem to be identical, so simply ignore either one ;)
Quoted 47 lines
src/openvpn/push.c +4
-8@@ -104,19 +104,15 @@ receive_auth_failed(struct context *c, const struct buffer *buffer) }management_auth_failure (management,UP_TYPE_AUTH , reason); } -#endif /* * Save the dynamic-challenge text even when management is defined */ +if (authfail_extended + &&buf_string_match_head_str (&buf,"CRV1:" ) &&BLEN (&buf)) { -#ifdef ENABLE_MANAGEMENT -if (authfail_extended - &&buf_string_match_head_str (&buf,"CRV1:" ) &&BLEN (&buf)) - { -ssl_put_auth_challenge (BSTR (&buf)); - } -#endif +ssl_put_auth_challenge (BSTR (&buf)); } +#endif }/* [email protected]...:~/openvpn/community/openvpn (master *)$ git --no-pager diff
src/openvpn/push.c +2
-4@@ -104,19 +104,15 @@ receive_auth_failed(struct context *c, const struct buffer *buffer) }management_auth_failure (management,UP_TYPE_AUTH , reason); } -#endif /* * Save the dynamic-challenge text even when management is defined */ +if (authfail_extended + &&buf_string_match_head_str (&buf,"CRV1:" ) &&BLEN (&buf)) { -#ifdef ENABLE_MANAGEMENT -if (authfail_extended - &&buf_string_match_head_str (&buf,"CRV1:" ) &&BLEN (&buf))
src/openvpn/push.c receive_auth_failed(struct context *c, const struct buffer *buffer) · line 118
Quoted 10 lines
src/openvpn/push.c +2
-4- { -ssl_put_auth_challenge (BSTR (&buf)); - } -#endif + ssl_put_auth_challenge(BSTR(&buf)); } +#endif }/*
--
Frank Lichtenheld
PATCH 3/4 Implement AUTH_FAIL, TEMP message support
In reply to Arne SchwabeThis allows a server to indicate a temporary problem on the server and allows the server to indicate how to proceed (i.e. move to the next server, retry the same server, wait a certain time,...)
This adds options_utils.c/h to be able to unit test the new function.
--- doc/man-sections/script-options.rst | 30 ++++++++ src/openvpn/Makefile.am | 1 + src/openvpn/init.c | 9 ++- src/openvpn/openvpn.vcxproj | 2 + src/openvpn/openvpn.vcxproj.filters | 3 + src/openvpn/options.h | 9 ++- src/openvpn/options_util.c | 104 +++++++++++++++++++++++++++ src/openvpn/options_util.h | 33 +++++++++ src/openvpn/push.c | 11 ++- src/openvpn/ssl.c | 13 ++-- src/openvpn/ssl.h | 3 + tests/unit_tests/openvpn/Makefile.am | 1 + tests/unit_tests/openvpn/test_misc.c | 49 +++++++++++++ 13 files changed, 260 insertions(+), 8 deletions(-) create mode 100644 src/openvpn/options_util.c create mode 100644 src/openvpn/options_util.h
doc/man-sections/script-options.rst +30 -0
@@ -97,6 +97,36 @@ SCRIPT HOOKS the authentication, a :code:`1` or :code:`0` must be written to the file specified by the :code:`auth_control_file`. + If the file specified by :code:`auth_failed_reason` exists and has non-empty + content, the content of this file will be used as AUTH_FAILED message. To + avoid race condition, this file should be written before + :code:`auth_control_file`. + + This auth fail reason can be something simple like "User has permanently + disabled" but there are also some special auth failed messages. + + The ``TEMP`` message indicates that the authentication + temporarily failed and that the client should continue to retry to connect. + The server can optionally give a user readable message and hint the client a + behavior how to proceed. The keywords of the ``AUTH_FAILED,TEMP`` message + are comma separated keys/values. Currently defined are: + + - ``backoff s`` - instructs the client to wait at least s seconds before the + next connection attempt. If the client has already a higher + delay before reconnecting, the delay will not be + shortened. + - ``advance addr`` - Instructs the client to reconnect to the (IP) + address of the current server. + - ``advance remote`` - Instructs the client to skip the remaining IP + addresses of the current server and instead connect to + the next server specified in the configuration file + - ``advance no`` - Instructs the client to retry connecting to the same server + again. + + For example, the message ``TEMP[backoff 42,advance no]: No free IP addresses`` + to indicates that the VPN connection can currently not succeed and instructs + the client to retry in 42 seconds again. + When deferred authentication is in use, the script can also request pending authentication by writing to the file specified by the :code:`auth_pending_file`. The first line must be the timeout in
src/openvpn/Makefile.am +1 -0
@@ -95,6 +95,7 @@ openvpn_SOURCES = \ pkcs11_mbedtls.c \ openvpn.c openvpn.h \ options.c options.h \ + options_util.c options_util.h \ otime.c otime.h \ packet_id.c packet_id.h \ perf.c perf.h \
src/openvpn/init.c +8 -1
@@ -483,13 +483,15 @@ next_connection_entry(struct context *c)/* Check if there is another resolved address to try for * the current connection */ if (c->c1.link_socket_addr.current_remote - && c->c1.link_socket_addr.current_remote->ai_next) + && c->c1.link_socket_addr.current_remote->ai_next + && !c->options.advance_next_remote) { c->c1.link_socket_addr.current_remote = c->c1.link_socket_addr.current_remote->ai_next; }else { + c->options.advance_next_remote = false;/* FIXME (schwabe) fix the persist-remote-ip option for real, * this is broken probably ever since connection lists and multiple * remote existed
@@ -2357,6 +2359,11 @@ socket_restart_pause(struct context *c)/* sec is less than 2^16; we can left shift it by up to 15 bits without overflow */ sec =max_int (sec,1 ) <<min_int (backoff,15 ); } +if (c->options.server_backoff_time) + { + sec =max_int (sec, c->options.server_backoff_time); + c->options.server_backoff_time =0 ; + }if (sec > c->options.ce.connect_retry_seconds_max) {
src/openvpn/openvpn.vcxproj +2 -0
@@ -306,6 +306,7 @@ <ClCompile Include="occ.c" /> <ClCompile Include="openvpn.c" /> <ClCompile Include="options.c" /> + <ClCompile Include="options_util.c" /> <ClCompile Include="otime.c" /> <ClCompile Include="packet_id.c" /> <ClCompile Include="perf.c" />
@@ -395,6 +396,7 @@ <ClInclude Include="occ.h" /> <ClInclude Include="openvpn.h" /> <ClInclude Include="options.h" /> + <ClInclude Include="options_util.h" /> <ClInclude Include="otime.h" /> <ClInclude Include="packet_id.h" /> <ClInclude Include="perf.h" />
src/openvpn/openvpn.vcxproj.filters +3 -0
@@ -395,6 +395,9 @@ <ClInclude Include="options.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="options_util.h"> + <Filter>Header Files</Filter> + </ClInclude> <ClInclude Include="otime.h"> <Filter>Header Files</Filter> </ClInclude>
src/openvpn/options.h +8 -1
@@ -272,10 +272,17 @@ struct optionsstruct connection_list *connection_list;struct remote_list *remote_list; -/* Do not advanced the connection or remote addr list*/ +/* Do not advance the connection or remote addr list*/ bool no_advance; +/* Advance directly to the next remote, skipping remaining addresses of the +* current remote */ +bool advance_next_remote;/* Counts the number of unsuccessful connection attempts */ unsigned int unsuccessful_attempts; +/* the server can suggest a backoff time to the client, it +* will still be capped by the max timeout between connections +* (300s by default) */ +int server_backoff_time;#if ENABLE_MANAGEMENT struct http_proxy_options *http_proxy_override;
src/openvpn/options_util.c new file +104 -0
105 lines not on this page · raw message
src/openvpn/options_util.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* OpenVPN -- An application to securely tunnel IP networks +* over a single TCP/UDP port, with support for SSL/TLS-based +* session authentication and key exchange, +* packet encryption, packet authentication, and +* packet compression. +* +* Copyright (C) 2002-2022 OpenVPN Inc <[email protected]...> +* Copyright (C) 2010-2021 Fox Crypto B.V. <[email protected]...> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef OPTIONS_UTIL_H_ +#define OPTIONS_UTIL_H_ + +#include "options.h" + +const char * +parse_auth_failed_temp (struct options *o,const struct buffer *buf); + +#endif
src/openvpn/push.c +9 -2
@@ -38,6 +38,7 @@#include "memdbg.h" #include "ssl_util.h" +#include "options_util.h" static char push_reply_cmd[] ="PUSH_REPLY" ;
@@ -51,7 +52,6 @@ void receive_auth_failed(struct context *c, const struct buffer *buffer) { msg(M_VERB0, "AUTH: Received control message: %s", BSTR(buffer)); - c->options.no_advance = true;if (!c->options.pull) {
@@ -64,15 +64,22 @@ receive_auth_failed(struct context *c, const struct buffer *buffer)* contains further flags */ bool authfail_extended =buf_string_compare_advance (&buf,"AUTH_FAILED," ); +if (authfail_extended &&buf_string_match_head_str (&buf,"TEMP" )) + { +parse_auth_failed_temp (&c->options, &buf); + c->sig->signal_received =SIGUSR1 ; + c->sig->signal_text ="auth-temp-failure (server temporary reject)" ; + }/* Before checking how to react on AUTH_FAILED, first check if the * failed auth might be the result of an expired auth-token. * Note that a server restart will trigger a generic AUTH_FAILED * instead an AUTH_FAILED,SESSION so handle all AUTH_FAILED message * identical for this scenario */ -if (ssl_clean_auth_token ()) +else if (ssl_clean_auth_token ()) { c->sig->signal_received =SIGUSR1 ;/* SOFT-SIGUSR1 -- Auth failure error */ c->sig->signal_text ="auth-failure (auth-token)" ; + c->options.no_advance = true; }else {
src/openvpn/ssl.c +9 -4
@@ -1943,14 +1943,19 @@ push_peer_info(struct buffer *buf, struct tls_session *session)/* support for exit notify via control channel */ iv_proto |=IV_PROTO_CC_EXIT_NOTIFY ; -/* support for receiving push_reply before sending -* push request, also signal that the client wants -* to get push-reply messages without without requiring a round -* trip for a push request message*/ if (session->opt->pull) { +/* support for receiving push_reply before sending +* push request, also signal that the client wants +* to get push-reply messages without requiring a round +* trip for a push request message*/ iv_proto |=IV_PROTO_REQUEST_PUSH ; + +/* Support keywords in the AUTH_PENDING control message */ iv_proto |=IV_PROTO_AUTH_PENDING_KW ; + +/* support for AUTH_FAIL,TEMP control message */ + iv_proto |=IV_PROTO_AUTH_FAIL_TEMP ; }/* support for Negotiable Crypto Parameters */
src/openvpn/ssl.h +3 -0
@@ -93,6 +93,9 @@* result. */ #define IV_PROTO_NCP_P2P (1<<5) +/** Support for AUTH_FAIL,TEMP messages */ +#define IV_PROTO_AUTH_FAIL_TEMP (1<<6) +/** Support for explicit exit notify via control channel */ #define IV_PROTO_CC_EXIT_NOTIFY (1<<7)
tests/unit_tests/openvpn/Makefile.am +1 -0
@@ -176,5 +176,6 @@ misc_testdriver_LDFLAGS = @TEST_LDFLAGS@ misc_testdriver_SOURCES = test_misc.c mock_msg.c \ mock_get_random.c \ $(openvpn_srcdir)/buffer.c \ + $(openvpn_srcdir)/options_util.c \ $(openvpn_srcdir)/ssl_util.c \ $(openvpn_srcdir)/platform.c
tests/unit_tests/openvpn/test_misc.c +49 -0
63 lines not on this page · raw message
Signature · 1 line
2.32.0 (Apple Git-132)
Re: [Openvpn-devel] [PATCH 3/4] Implement AUTH_FAIL, TEMP message support
Documentation-only review.
Quoted 6 lines
Arne Schwabe <[email protected]...> hat am 18.05.2022 11:32 geschrieben:
This allows a server to indicate a temporary problem on the server and allows the server to indicate how to proceed (i.e. move to the next server, retry the same server, wait a certain time,...)This adds options_utils.c/h to be able to unit test the new function.
[...]
doc/man-sections/script-options.rst SCRIPT HOOKS · line 102
Quoted 11 lines
doc/man-sections/script-options.rst +3
-0@@ -97,6 +97,36 @@ SCRIPT HOOKS the authentication, a :code:`1` or :code:`0` must be written to the file specified by the :code:`auth_control_file`. + If the file specified by :code:`auth_failed_reason` exists and has non-empty + content, the content of this file will be used as AUTH_FAILED message. To + avoid race condition, this file should be written before
either "a race condition" or "race conditions"
doc/man-sections/script-options.rst SCRIPT HOOKS · line 105
Quoted 3 lines
doc/man-sections/script-options.rst +3
-0+ :code:`auth_control_file`. + + This auth fail reason can be something simple like "User has permanently
"has been"
doc/man-sections/script-options.rst SCRIPT HOOKS · line 111
Quoted 6 lines
doc/man-sections/script-options.rst +6
-0+ disabled" but there are also some special auth failed messages. + + The ``TEMP`` message indicates that the authentication + temporarily failed and that the client should continue to retry to connect. + The server can optionally give a user readable message and hint the client a + behavior how to proceed. The keywords of the ``AUTH_FAILED,TEMP`` message
"and a hint to the client on how to proceed" maybe?
doc/man-sections/script-options.rst SCRIPT HOOKS · line 115
Quoted 4 lines
doc/man-sections/script-options.rst +4
-0+ are comma separated keys/values. Currently defined are: + + - ``backoff s`` - instructs the client to wait at least s seconds before the + next connection attempt. If the client has already a higher
"has already" -> "already uses" ?
doc/man-sections/script-options.rst SCRIPT HOOKS · line 118
Quoted 3 lines
doc/man-sections/script-options.rst +3
-0+ delay before reconnecting, the delay will not be + shortened. + - ``advance addr`` - Instructs the client to reconnect to the (IP)
"to the" -> "to a specific"
doc/man-sections/script-options.rst SCRIPT HOOKS · line 122
Quoted 4 lines
doc/man-sections/script-options.rst +4
-0+ address of the current server. + - ``advance remote`` - Instructs the client to skip the remaining IP + addresses of the current server and instead connect to + the next server specified in the configuration file
Missing full stop.
doc/man-sections/script-options.rst SCRIPT HOOKS · line 127
Quoted 5 lines
doc/man-sections/script-options.rst +5
-0+ - ``advance no`` - Instructs the client to retry connecting to the same server + again. + + For example, the message ``TEMP[backoff 42,advance no]: No free IP addresses`` + to indicates that the VPN connection can currently not succeed and instructs
Remove "to"
doc/man-sections/script-options.rst SCRIPT HOOKS · line 132
Quoted 5 lines
doc/man-sections/script-options.rst +2
-0+ the client to retry in 42 seconds again. + When deferred authentication is in use, the script can also request pending authentication by writing to the file specified by the :code:`auth_pending_file`. The first line must be the timeout in
Regards,
--
Frank Lichtenheld
Re: [Openvpn-devel] [PATCH 3/4] Implement AUTH_FAIL, TEMP message support
Found one mistake in my previous review:
Quoted 3 lines
Frank Lichtenheld <[email protected]...> hat am 18.05.2022 13:12 geschrieben:
Documentation-only review.Quoted 1 line
Arne Schwabe <[email protected]...> hat am 18.05.2022 11:32 geschrieben:
[...]
Quoted 5 lines
doc/man-sections/script-options.rst SCRIPT HOOKS · line 115
Quoted 4 lines
doc/man-sections/script-options.rst +4
-0+ are comma separated keys/values. Currently defined are: + + - ``backoff s`` - instructs the client to wait at least s seconds before the + next connection attempt. If the client has already a higher
Quoted 7 lines
"has already" -> "already uses" ?
doc/man-sections/script-options.rst SCRIPT HOOKS · line 118
Quoted 3 lines
doc/man-sections/script-options.rst +3
-0+ delay before reconnecting, the delay will not be + shortened. + - ``advance addr`` - Instructs the client to reconnect to the (IP)"to the" -> "to a specific"
After reading the code I see that I was mistaken. I thought that you would specify an actually address here. But it is literaly the string "addr". So the correct fix seems to be "to the" -> "to the next".
I wonder whether there would be some good way to make clear that "s" above is a placeholder but "addr" is a literal string. "backoff <s>" maybe? Not sure.
Quoted 7 lines
doc/man-sections/script-options.rst SCRIPT HOOKS · line 122
Quoted 4 lines
doc/man-sections/script-options.rst +4
-0+ address of the current server. + - ``advance remote`` - Instructs the client to skip the remaining IP + addresses of the current server and instead connect to + the next server specified in the configuration fileMissing full stop.
Quoted 13 lines
doc/man-sections/script-options.rst SCRIPT HOOKS · line 127
Quoted 5 lines
doc/man-sections/script-options.rst +5
-0+ - ``advance no`` - Instructs the client to retry connecting to the same server + again. + + For example, the message ``TEMP[backoff 42,advance no]: No free IP addresses`` + to indicates that the VPN connection can currently not succeed and instructsRemove "to"
Quoted 5 lines
doc/man-sections/script-options.rst +2
-0+ the client to retry in 42 seconds again. + When deferred authentication is in use, the script can also request pending authentication by writing to the file specified by the :code:`auth_pending_file`. The first line must be the timeout in
--
Frank Lichtenheld
PATCH 4/4 Allow scripts and plugins to set a custom AUTH_FAILED message
In reply to Arne SchwabeThis is currently only possible when using the management interface and the client-deny functionality.
--- src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_verify.c | 74 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 73 insertions(+), 2 deletions(-)
src/openvpn/ssl_common.h +1 -0
@@ -155,6 +155,7 @@ struct auth_deferred_status {char *auth_control_file;char *auth_pending_file; +char *auth_failed_reason_file;unsigned int auth_control_status; };
src/openvpn/ssl_verify.c +72 -2
131 lines not on this page · raw message
Signature · 1 line
2.32.0 (Apple Git-132)