Pending authentication improvements
v2 cover Pending authentication improvements
This patchset brings a number of improvements:
- Allow a tiemout that is different from the default 60s for pending authentication. 60s is a bit tight, especially when being redirected to a complicated web login process.
- Make the server side auth-pending support no longer dependent on management interface but also allow scripts and plugins to utilise it.
- Introduce deffered authentication support for scripts. Deferred authentication is a necessary requirement for pending authentication.
The branch is also available here: https://github.com/schwabe/openvpn/tree/schwabe/auth_pending
The v2 patches ae modified from the v1 if they contain a Patch v2 note in the commit message, otherwise they are just rebased and resent with the patchset.
Arne Schwabe (11):
Change pull request timeout use a timeout rather than a number Implement client side handling of AUTH_PENDING message Implement server side of AUTH_PENDING with extending timeout Introduce management client state for AUTH_PENDING notifications Change parameter of send_auth_pending_messages from context to
tls_multi
Add S_EXITCODE flag for openvpn_run_script to report exit code Refactor extract_var_peer_info into standalone function and add
ssl_util.c
Allow pending auth to be send from a auth plugin Implement deferred auth for scripts
Implement --client-crresponse script options and plugin interface Add example script demonstrating TOTP via auth-pending
Changes.rst | 21 ++ doc/man-sections/generic-options.rst | 3 +- doc/man-sections/script-options.rst | 45 +++- doc/man-sections/server-options.rst | 4 + doc/man-sections/tls-options.rst | 3 + doc/management-notes.txt | 39 +++- include/openvpn-plugin.h.in | 15 +- sample/sample-scripts/totpauth.py | 107 +++++++++ src/openvpn/Makefile.am | 1 + src/openvpn/forward.c | 27 ++- src/openvpn/forward.h | 9 + src/openvpn/init.c | 1 + src/openvpn/integer.h | 25 +++ src/openvpn/manage.c | 26 ++- src/openvpn/manage.h | 5 +- src/openvpn/multi.c | 29 +-- src/openvpn/openvpn.h | 2 +- src/openvpn/openvpn.vcxproj | 2 + src/openvpn/openvpn.vcxproj.filters | 6 + src/openvpn/options.c | 15 ++ src/openvpn/options.h | 1 + src/openvpn/platform.c | 34 +++ src/openvpn/platform.h | 5 +- src/openvpn/push.c | 153 ++++++++++++- src/openvpn/push.h | 23 +- src/openvpn/run_command.c | 25 ++- src/openvpn/run_command.h | 15 +- src/openvpn/ssl.c | 10 +- src/openvpn/ssl.h | 3 + src/openvpn/ssl_common.h | 4 + src/openvpn/ssl_ncp.c | 20 +- src/openvpn/ssl_util.c | 59 +++++ src/openvpn/ssl_util.h | 49 +++++ src/openvpn/ssl_verify.c | 311 ++++++++++++++++++++++++--- src/openvpn/ssl_verify.h | 25 ++- tests/unit_tests/openvpn/Makefile.am | 3 +- 36 files changed, 988 insertions(+), 137 deletions(-) create mode 100755 sample/sample-scripts/totpauth.py create mode 100644 src/openvpn/ssl_util.c create mode 100644 src/openvpn/ssl_util.h
Signature · 1 line
2.30.0
PATCH v2 1/11 Change pull request timeout use a timeout rather than a number
This commit changes the count n_sent_push_requests to time_t based push_request_timeout. This is more in line to our other timeouts which are also time based instead of number retries based.
This does not change the behaviour but it prepares allowing to extend the pull request timeout during a pending authentication. As a user visible change we print the the time we waited for a timeout instead
Also update the man page to actually document that hand-window controls this timeout.
Patch V2: grammar fix in manual page
--- doc/man-sections/tls-options.rst | 3 +++ src/openvpn/forward.c | 1 + src/openvpn/openvpn.h | 2 +- src/openvpn/push.c | 9 ++++++--- 4 files changed, 11 insertions(+), 4 deletions(-)
doc/man-sections/tls-options.rst +3 -0
@@ -200,6 +200,9 @@ certificates and keys: https://github.com/OpenVPN/easy-rsa will still use our expiring key for up to ``--tran-window`` seconds to maintain continuity of transmission of tunnel data. + The ``--hand-window`` parameter also controls the amount of time that + the OpenVPN client repeats the pull request until it times out. + --key file Local peer's private key in .pem format. Use the private key which was generated when you built your peer's certificate (see ``--cert file``
src/openvpn/forward.c +1 -0
@@ -299,6 +299,7 @@ check_connection_established(struct context *c) }#endif /* fire up push request right away (already 1s delayed) */ + c->c2.push_request_timeout = now + c->options.handshake_window;event_timeout_init (&c->c2.push_request_interval,0 , now);reset_coarse_timers (c); }
src/openvpn/openvpn.h +1 -1
@@ -462,7 +462,7 @@ struct context_2enum client_connect_status context_auth;struct event_timeout push_request_interval; -int n_sent_push_requests; +time_t push_request_timeout;bool did_pre_pull_restore;/* hash of pulled options, so we can compare when options change */
src/openvpn/push.c +6 -3
@@ -369,14 +369,17 @@ cleanup:bool send_push_request (struct context *c) { -const int max_push_requests = c->options.handshake_window /PUSH_REQUEST_INTERVAL ; -if (++c->c2.n_sent_push_requests <= max_push_requests) +struct tls_session *session = &c->c2.tls_multi->session[TM_ACTIVE ]; +struct key_state *ks = &session->key[KS_PRIMARY ]; + +if (c->c2.push_request_timeout > now) {return send_control_channel_string (c,"PUSH_REQUEST" ,D_PUSH ); }else { -msg (D_STREAM_ERRORS ,"No reply from server after sending %d push requests" , max_push_requests); +msg (D_STREAM_ERRORS ,"No reply from server to push requests in %ds" , + (int )(now - ks->established)); c->sig->signal_received =SIGUSR1 ;/* SOFT-SIGUSR1 -- server-pushed connection reset */ c->sig->signal_text ="no-push-reply" ;return false;
Signature · 1 line
2.30.0
PATCH v2 2/11 Implement client side handling of AUTH_PENDING message
In reply to Arne SchwabeThis allows a client to extend the timeout of pull-request response while waiting for the user to complete a pending authentication. A timeout of 60s for a normal authentication might still works for a simple 2FA (but still challenging). With a sophisticated (or overly complicated) web based authentication 60s are quite short.
To avoid not detecting network problem in this phase, we use the constant sending of PUSH_REQUEST/AUTH_PENDING as keepalive signal and still timeout the session after the handshake window time.
patch v2: typo fixes, invert if for sscanf
--- doc/man-sections/server-options.rst | 4 ++ doc/management-notes.txt | 39 +++++++++++++---- src/openvpn/forward.c | 11 ++++- src/openvpn/integer.h | 25 +++++++++++ src/openvpn/push.c | 68 ++++++++++++++++++++++++++++- src/openvpn/push.h | 9 ++++ src/openvpn/ssl.c | 3 ++ src/openvpn/ssl.h | 3 ++ src/openvpn/ssl_common.h | 1 + 9 files changed, 152 insertions(+), 11 deletions(-)
doc/man-sections/server-options.rst +4 -0
@@ -473,6 +473,10 @@ fast hardware. SSL/TLS authentication must be used in this mode. - bit 1: The peer supports peer-id floating mechanism - bit 2: The client expects a push-reply and the server may send this reply without waiting for a push-request first. + - bit 3: The client is capable of doing key derivation using + RFC5705 key material exporter. + - bit 4: The client is capable of accepting additional arguments + to the `AUTH_PENDING` message. :code:`IV_NCP=2` Negotiable ciphers, client supports ``--cipher`` pushed by
doc/management-notes.txt +30 -9
@@ -610,14 +610,30 @@ to signal a pending authenticating to the client. A pending auth means that the connecting requires extra authentication like a one time password or doing a single sign one via web. - client-pending-auth {CID} {EXTRA} - -The server will send AUTH_PENDING and INFO_PRE,{EXTRA} to the client. -The client is expected to inform the user that authentication is pending and -display the extra information. For the format of EXTRA see below -For the OpenVPN server this is stateless operation and needs to be -followed by a client-deny/client-auth[-nt] command (that is the result of the -out of band authentication). + client-pending-auth {CID} {EXTRA} {TIMEOUT} + +The server will send AUTH_PENDING and INFO_PRE,{EXTRA} to the client. If the +client supports accepting keywords to AUTH_PENDING (announced via IV_PROTO), +TIMEOUT parameter will be also be announced to the client to allow it to modify +its own timeout. The client is expected to inform the user that authentication +is pending and display the extra information and also show the user the +remaining time to complete the auth if applicable. + +Receiving an AUTH_PENDING message will make the client change its timeout to +the timeout proposed by the server, even if the timeout is shorter. +If the client does not receive a packet from the server for hand-window the +connection times out regardless of the timeout. This ensures that the connection +still times out relatively quickly in case of network problems. The client will +continously send PULL_REQUEST messages to the server until the timeout is reached. +This message also triggers an ACK message from the server that resets the +hand-window based timeout. + +Both client and server limit the maximum timeout to the smaller value of half the +--tls-reneg minimum time and --hand-window time (defaults to 60s). + +For the format of EXTRA see below. For the OpenVPN server this is a stateless +operation and needs to be followed by a client-deny/client-auth[-nt] command +(that is the result of the out of band authentication). Before issuing a client-pending-auth to a client instead of a client-auth/client-deny, the server should check the IV_SSO
@@ -630,7 +646,7 @@ set setenv IV_SSO openurl,crtext The variable name IV_SSO is historic as AUTH_PENDING was first used -to signal single sign on support. To keep compatiblity with existing +to signal single sign on support. To keep compatibility with existing implementations the name IV_SSO is kept in lieu of a better name. openurl
@@ -646,6 +662,11 @@ The space in a control message is limited, so this url should be kept short to avoid issues. If a loger url is required a URL that redirects to the longer URL should be sent instead. +A complete documentation how URLs should be handled on the client is available +in the openvpn3 repository: + +https://github.com/OpenVPN/openvpn3/blob/master/doc/webauth.md + url_proxy ======== To avoid issues with OpenVPN connection persist-tun and not able
src/openvpn/forward.c +10 -1
@@ -240,6 +240,10 @@ check_incoming_control_channel(struct context *c) {receive_cr_response (c, &buf); } + else if (buf_string_match_head_str(&buf, "AUTH_PENDING")) + { +receive_auth_pending (c, &buf); + } else {msg (D_PUSH_ERRORS ,"WARNING: Received unknown control message: %s" ,BSTR (&buf));
@@ -299,7 +303,12 @@ check_connection_established(struct context *c) }#endif /* fire up push request right away (already 1s delayed) */ - c->c2.push_request_timeout = now + c->options.handshake_window; +/* We might receive a AUTH_PENDING request before we armed this +* timer. In that case we don't change the value */ +if (c->c2.push_request_timeout < now) + { + c->c2.push_request_timeout = now + c->options.handshake_window; + }event_timeout_init (&c->c2.push_request_interval,0 , now);reset_coarse_timers (c); }
src/openvpn/integer.h +25 -0
@@ -39,6 +39,31 @@/* * min/max functions */ +static inline unsigned int +max_uint (unsigned int x,unsigned int y) +{ +if (x > y) + { +return x; + } +else + { +return y; + } +} + +static inline unsigned int +min_uint (unsigned int x,unsigned int y) +{ +if (x < y) + { +return x; + } +else + { +return y; + } +}static inline int max_int (int x,int y)
src/openvpn/push.c +67 -1
80 lines not on this page · raw message
src/openvpn/push.h +9 -0
@@ -89,5 +89,14 @@ void send_restart(struct context *c, const char *kill_msg);*/ void send_push_reply_auth_token (struct tls_multi *multi); +/** +* Parses an AUTH_PENDING message and if in pull mode extends the timeout +* +* @param c The context struct +* @param buffer Buffer containing the control message with AUTH_PENDING +*/ +void +receive_auth_pending (struct context *c,const struct buffer *buffer); +#endif /* if P2MP */ #endif /* ifndef PUSH_H */
src/openvpn/ssl.c +3 -0
@@ -2268,6 +2268,7 @@ push_peer_info(struct buffer *buf, struct tls_session *session)if (session->opt->pull) { iv_proto |=IV_PROTO_REQUEST_PUSH ; + iv_proto |=IV_PROTO_AUTH_PENDING_KW ; }/* support for Negotiable Crypto Parameters */
@@ -3733,6 +3734,8 @@ tls_pre_decrypt(struct tls_multi *multi, } } } +/* Remember that we received a valid control channel packet */ + ks->peer_last_packet = now; done: buf->len =0 ;
src/openvpn/ssl.h +3 -0
@@ -119,6 +119,9 @@/** Supports key derivation via TLS key material exporter [RFC5705] */ #define IV_PROTO_TLS_KEY_EXPORT (1<<3) +/** Supports signaling keywords with AUTH_PENDING, e.g. timeout=xy */ +#define IV_PROTO_AUTH_PENDING_KW (1<<4) +/* Default field in X509 to be username */ #define X509_USERNAME_FIELD_DEFAULT "CN"
src/openvpn/ssl_common.h +1 -0
@@ -178,6 +178,7 @@ struct key_statetime_t established;/* when our state went S_ACTIVE */ time_t must_negotiate;/* key negotiation times out if not finished before this time */ time_t must_die;/* this object is destroyed at this time */ +time_t peer_last_packet;/* Last time we received a packet in this control session */ int initial_opcode;/* our initial P_ opcode */ struct session_id session_id_remote;/* peer's random session ID */
Signature · 1 line
2.30.0
PATCH v2 3/11 Implement server side of AUTH_PENDING with extending timeout
In reply to Arne SchwabePatch V2: eliminate parse_kid function, fix style
--- src/openvpn/manage.c | 23 +++++++++-------- src/openvpn/manage.h | 3 ++- src/openvpn/multi.c | 27 +++----------------- src/openvpn/push.c | 55 +++++++++++++++++++++++++++++++++++++--- src/openvpn/push.h | 10 ++++++++ src/openvpn/ssl.c | 1 + src/openvpn/ssl_common.h | 1 + 7 files changed, 81 insertions(+), 39 deletions(-)
src/openvpn/manage.c +13 -10
@@ -972,15 +972,15 @@ parse_cid(const char *str, unsigned long *cid) }static bool -parse_kid (const char *str,unsigned int *kid) +parse_uint (const char *str,const char * what,unsigned int *uint) { -if (sscanf (str,"%u" , kid) ==1 ) +if (sscanf (str,"%u" , uint) ==1 ) {return true; }else { -msg (M_CLIENT ,"ERROR: cannot parse KID" ); +msg (M_CLIENT ,"ERROR: cannot parse %s" , what);return false; } }
@@ -995,15 +995,18 @@ parse_kid(const char *str, unsigned int *kid)* the information of the additional steps */ static void -man_client_pending_auth (struct management *man,const char *cid_str,const char *extra) +man_client_pending_auth (struct management *man,const char *cid_str, +const char *extra,const char *timeout_str) {unsigned long cid =0 ; -if (parse_cid (cid_str, &cid)) +unsigned int timeout =0 ; +if (parse_cid (cid_str, &cid) + &&parse_uint (timeout_str,"TIMEOUT" , &timeout)) {if (man->persist.callback.client_pending_auth) {bool ret = (*man->persist.callback.client_pending_auth) - (man->persist.callback.arg, cid, extra); + (man->persist.callback.arg, cid, extra, timeout);if (ret) {
@@ -1029,7 +1032,7 @@ man_client_auth(struct management *man, const char *cid_str, const char *kid_str mc->in_extra_cid =0 ; mc->in_extra_kid =0 ;if (parse_cid (cid_str, &mc->in_extra_cid) - &&parse_kid (kid_str, &mc->in_extra_kid)) + &&parse_uint (kid_str,"KID" , &mc->in_extra_kid)) { mc->in_extra_cmd =IEC_CLIENT_AUTH ;in_extra_reset (mc,IER_NEW );
@@ -1045,7 +1048,7 @@ man_client_deny(struct management *man, const char *cid_str, const char *kid_str {unsigned long cid =0 ;unsigned int kid =0 ; -if (parse_cid (cid_str, &cid) &&parse_kid (kid_str, &kid)) +if (parse_cid (cid_str, &cid) &&parse_uint (kid_str,"KID" , &kid)) {if (man->persist.callback.client_auth) {
@@ -1560,9 +1563,9 @@ man_dispatch_command(struct management *man, struct status_output *so, const cha }else if (streq (p[0 ],"client-pending-auth" )) { -if (man_need (man, p,2 ,0 )) +if (man_need (man, p,3 ,0 )) { -man_client_pending_auth (man, p[1 ], p[2 ]); +man_client_pending_auth (man, p[1 ], p[2 ], p[3 ]); } }#ifdef MANAGEMENT_PF
src/openvpn/manage.h +2 -1
@@ -173,7 +173,8 @@ struct management_callback struct buffer_list *cc_config); /* ownership transferred */bool (*client_pending_auth) (void *arg,const unsigned long cid, -const char *url); +const char *extra, +unsigned int timeout);char *(*get_peer_info) (void *arg,const unsigned long cid);#ifdef MANAGEMENT_PF bool (*client_pf)(void *arg,
src/openvpn/multi.c +3 -24
@@ -1768,28 +1768,6 @@ multi_client_connect_setenv(struct multi_context *m,gc_free (&gc); } -/** -* Extracts the IV_PROTO variable and returns its value or 0 -* if it cannot be extracted. -* -*/ -static unsigned int -extract_iv_proto (const char *peer_info) -{ - -const char *optstr = peer_info ?strstr (peer_info,"IV_PROTO=" ) :NULL ; -if (optstr) - { -int proto =0 ; -int r =sscanf (optstr,"IV_PROTO=%d" , &proto); -if (r ==1 && proto >0 ) - { -return proto; - } - } -return 0 ; -} -/** * Calculates the options that depend on the client capabilities * based on local options and available peer info
@@ -3918,14 +3896,15 @@ management_kill_by_cid(void *arg, const unsigned long cid, const char *kill_msg)static bool management_client_pending_auth (void *arg,const unsigned long cid, -const char *extra) +const char *extra, +unsigned int timeout) {struct multi_context *m = (struct multi_context *) arg;struct multi_instance *mi =lookup_by_cid (m, cid);if (mi) {/* sends INFO_PRE and AUTH_PENDING messages to client */ -bool ret =send_auth_pending_messages (&mi->context, extra); +bool ret =send_auth_pending_messages (&mi->context, extra, timeout);multi_schedule_context_wakeup (m, mi);return ret; }
src/openvpn/push.c +51 -4
81 lines not on this page · raw message
src/openvpn/push.h +10 -0
@@ -89,6 +89,16 @@ void send_restart(struct context *c, const char *kill_msg);*/ void send_push_reply_auth_token (struct tls_multi *multi); + +/** +* Extracts the IV_PROTO variable and returns its value or 0 +* if it cannot be extracted. +* +* @param peer_info peer info string to search for IV_PROTO +*/ +unsigned int +extract_iv_proto (const char *peer_info); +/** * Parses an AUTH_PENDING message and if in pull mode extends the timeout *
src/openvpn/ssl.c +1 -0
@@ -2771,6 +2771,7 @@ tls_process(struct tls_multi *multi, buf =reliable_get_buf_output_sequenced (ks->send_reliable);if (buf) { + ks->initial = now; ks->must_negotiate = now + session->opt->handshake_window; ks->auth_deferred_expire = now +auth_deferred_expire_window (session->opt);
src/openvpn/ssl_common.h +1 -0
@@ -175,6 +175,7 @@ struct key_statestruct key_state_ssl ks_ssl;/* contains SSL object and BIOs for the control channel */ +time_t initial;/* when we created this session */ time_t established;/* when our state went S_ACTIVE */ time_t must_negotiate;/* key negotiation times out if not finished before this time */ time_t must_die;/* this object is destroyed at this time */
Signature · 1 line
2.30.0
PATCH v2 4/11 Introduce management client state for AUTH_PENDING notifications
In reply to Arne SchwabeThis allows a UI client to display the correct state. Technically the client is still waiting for PUSH_REPLY but for every practical concern this is a different state as we are waiting for the pending authentication to finish.
--- src/openvpn/manage.c | 3 +++ src/openvpn/manage.h | 2 ++ src/openvpn/push.c | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+)
src/openvpn/manage.c +3 -0
@@ -169,6 +169,9 @@ man_state_name(const int state)case OPENVPN_STATE_TCP_CONNECT :return "TCP_CONNECT" ; +case OPENVPN_STATE_AUTH_PENDING : +return "AUTH_PENDING" ; +default :return "?" ; }
src/openvpn/manage.h +2 -0
@@ -493,6 +493,8 @@ management_enable_def_auth(const struct management *man)#define OPENVPN_STATE_GET_CONFIG 9/* Downloading configuration from server */ #define OPENVPN_STATE_RESOLVE 10/* DNS lookup */ #define OPENVPN_STATE_TCP_CONNECT 11/* Connecting to TCP server */ +#define OPENVPN_STATE_AUTH_PENDING 12/* Waiting in auth-pending mode +* techhnically variant of GET_CONFIG */ #define OPENVPN_STATE_CLIENT_BASE 7/* Base index of client-only states */
src/openvpn/push.c +18 -0
@@ -248,12 +248,30 @@ parse_auth_pending_keywords(const struct buffer *buffer,if (!buf_advance (&buf,strlen ("AUTH_PENDING" )) || !(buf_read_u8 (&buf) ==',' ) || !BLEN (&buf)) { +#ifdef ENABLE_MANAGEMENT +if (management) + { +management_set_state (management,OPENVPN_STATE_AUTH_PENDING , +"" ,NULL ,NULL ,NULL ,NULL ); + } +#endif +return ; }/* parse the keywords in the same way that push options are parsed */ char line[OPTION_LINE_SIZE ]; +#ifdef ENABLE_MANAGEMENT +/* Need to do the management notification with the keywords before +* buf_parse is called, as it will insert \0 bytes into the buffer */ +if (management) + { +management_set_state (management,OPENVPN_STATE_AUTH_PENDING , +BSTR (&buf),NULL ,NULL ,NULL ,NULL ); + } +#endif +while (buf_parse (&buf,',' , line,sizeof (line))) {if (sscanf (line,"timeout %u" , server_timeout) !=1 )
Signature · 1 line
2.30.0
PATCH v2 5/11 Change parameter of send_auth_pending_messages from context to tls_multi
In reply to Arne SchwabeThis prepares send_auth_pending_messages to be used a in context that does not have context c available but also does not need to schedule an immediate sending of the message (auth plugin/script)
Patch V2: Adjust the comment of reschedule_multi_process to actually fit a
function.
--- src/openvpn/forward.c | 17 +++++++++-------- src/openvpn/forward.h | 9 +++++++++ src/openvpn/multi.c | 4 +++- src/openvpn/push.c | 9 ++++----- src/openvpn/push.h | 4 +++- 5 files changed, 28 insertions(+), 15 deletions(-)
src/openvpn/forward.c +9 -8
@@ -342,6 +342,14 @@ send_control_channel_string_dowork(struct tls_multi *multi,return stat; } +void reschedule_multi_process (struct context *c) +{ + +interval_action (&c->c2.tmp_int); +context_immediate_reschedule (c);/* ZERO-TIMEOUT */ +} + +bool send_control_channel_string (struct context *c,const char *str,int msglevel) {
@@ -349,15 +357,8 @@ send_control_channel_string(struct context *c, const char *str, int msglevel) {bool ret =send_control_channel_string_dowork (c->c2.tls_multi, str, msglevel); -/* -* Reschedule tls_multi_process. -* NOTE: in multi-client mode, usually the below two statements are -* insufficient to reschedule the client instance object unless -* multi_schedule_context_wakeup(m, mi) is also called. -*/ +reschedule_multi_process (c); -interval_action (&c->c2.tmp_int); -context_immediate_reschedule (c);/* ZERO-TIMEOUT */ return ret; }return true;
src/openvpn/forward.h +9 -0
@@ -317,6 +317,15 @@ bool send_control_channel_string_dowork(struct tls_multi *multi, const char *str, int msglevel); + +/** +* Reschedule tls_multi_process. +* NOTE: in multi-client mode, usually calling the function is +* insufficient to reschedule the client instance object unless +* multi_schedule_context_wakeup(m, mi) is also called. +*/ +void reschedule_multi_process (struct context *c); +#define PIPV4_PASSTOS (1<<0)#define PIP_MSSFIX (1<<1)/* v4 and v6 */ #define PIP_OUTGOING (1<<2)
src/openvpn/multi.c +3 -1
@@ -3904,7 +3904,9 @@ management_client_pending_auth(void *arg,if (mi) {/* sends INFO_PRE and AUTH_PENDING messages to client */ -bool ret =send_auth_pending_messages (&mi->context, extra, timeout); +bool ret =send_auth_pending_messages (mi->context.c2.tls_multi, extra, + timeout); +reschedule_multi_process (&mi->context);multi_schedule_context_wakeup (m, mi);return ret; }
src/openvpn/push.c +4 -5
@@ -363,14 +363,13 @@ send_auth_failed(struct context *c, const char *client_reason)bool -send_auth_pending_messages (struct context *c,const char *extra, +send_auth_pending_messages (struct tls_multi *tls_multi,const char *extra,unsigned int timeout) {struct key_state *ks = &tls_multi->session[TM_ACTIVE ].key[KS_PRIMARY ];static const char info_pre[] ="INFO_PRE," ; -struct tls_multi *tls_multi = c->c2.tls_multi;const char *const peer_info = tls_multi->peer_info;unsigned int proto =extract_iv_proto (peer_info);
@@ -384,7 +383,7 @@ send_auth_pending_messages(struct context *c, const char *extra,struct gc_arena gc =gc_new ();if ((proto &IV_PROTO_AUTH_PENDING_KW ) ==0 ) { -send_control_channel_string (c,"AUTH_PENDING" ,D_PUSH ); +send_control_channel_string_dowork (tls_multi,"AUTH_PENDING" ,D_PUSH ); }else {
@@ -395,7 +394,7 @@ send_auth_pending_messages(struct context *c, const char *extra,struct buffer buf =alloc_buf_gc (len, &gc);buf_printf (&buf, auth_pre);buf_printf (&buf,"%u" , timeout); -send_control_channel_string (c,BSTR (&buf),D_PUSH ); +send_control_channel_string_dowork (tls_multi,BSTR (&buf),D_PUSH ); }size_t len =strlen (extra) +1 +sizeof (info_pre);
@@ -408,7 +407,7 @@ send_auth_pending_messages(struct context *c, const char *extra,struct buffer buf =alloc_buf_gc (len, &gc);buf_printf (&buf, info_pre);buf_printf (&buf,"%s" , extra); -send_control_channel_string (c,BSTR (&buf),D_PUSH ); +send_control_channel_string_dowork (tls_multi,BSTR (&buf),D_PUSH ); ks->auth_deferred_expire = now + timeout;
src/openvpn/push.h +3 -1
@@ -77,7 +77,9 @@ void send_auth_failed(struct context *c, const char *client_reason);* doc/management-notes.txt under client-pending-auth for * more details on message format */ -bool send_auth_pending_messages (struct context *c,const char *extra); +bool +send_auth_pending_messages (struct tls_multi *tls_multi,const char *extra, +unsigned int timeout);void send_restart (struct context *c,const char *kill_msg);
Signature · 1 line
2.30.0
PATCH v2 6/11 Add S_EXITCODE flag for openvpn_run_script to report exit code
In reply to Arne SchwabeThis allows to use script that have more than just fail/sucess but also deferred as status
Patch v2: minor style fixes, improve doxygen comments
--- src/openvpn/platform.c | 34 ++++++++++++++++++++++++++++++++++ src/openvpn/platform.h | 5 ++++- src/openvpn/run_command.c | 25 ++++++++++++++++--------- src/openvpn/run_command.h | 15 +++++++++++---- 4 files changed, 65 insertions(+), 14 deletions(-)
src/openvpn/platform.c +34 -0
@@ -240,6 +240,40 @@ platform_system_ok(int stat)#endif } +#ifdef _WIN32 +int +platform_ret_code (int stat) +{ +if (stat >=0 && stat <255 ) + { +return stat; + } +else + { +return -1 ; + } +} +#else +int +platform_ret_code (int stat) +{ +if (!WIFEXITED (stat) || stat ==-1 ) + { +return -1 ; + } + +int status =WEXITSTATUS (stat); +if (status >=0 && status <255 ) + { +return status; + } +else + { +return -1 ; + } +} +#endif +int platform_access (const char *path,int mode) {
src/openvpn/platform.h +4 -1
@@ -119,9 +119,12 @@ void platform_mlockall(bool print_msg); /* Disable paging */int platform_chdir (const char *dir); -/* interpret the status code returned by execve() */ +/** interpret the status code returned by execve() */ bool platform_system_ok (int stat); +/** Return an exit code if valid and between 0 and 255, -1 otherwise */ +int platform_ret_code (int stat); +int platform_access (const char *path,int mode);void platform_sleep_milliseconds (unsigned int n);
src/openvpn/run_command.c +16 -9
@@ -191,27 +191,34 @@ openvpn_execve(const struct argv *a, const struct env_set *es, const unsigned in/* * Wrapper around openvpn_execve */ -bool +int openvpn_execve_check (const struct argv *a,const struct env_set *es,const unsigned int flags,const char *error_message) {struct gc_arena gc =gc_new ();const int stat =openvpn_execve (a, es, flags);int ret = false; -if (platform_system_ok (stat)) +if (flags &S_EXITCODE ) + { + ret =platform_ret_code (stat); +if (ret !=-1 ) { + goto done; + } + } +else if (platform_system_ok (stat)) { ret = true; + goto done; } -else +if (error_message) { -if (error_message) - { -msg (((flags &S_FATAL ) ?M_FATAL :M_WARN ),"%s: %s" , - error_message, -system_error_message (stat, &gc)); - } +msg (((flags &S_FATAL ) ?M_FATAL :M_WARN ),"%s: %s" , + error_message, +system_error_message (stat, &gc)); } +done:gc_free (&gc); +return ret; }
src/openvpn/run_command.h +11 -4
@@ -42,18 +42,25 @@ int script_security(void);void script_security_set (int level);/* openvpn_execve flags */ -#define S_SCRIPT (1<<0) -#define S_FATAL (1<<1) +#define S_SCRIPT (1<<0) +#define S_FATAL (1<<1) +/** Instead of returning 1/0 for success/fail, +* return exit code when between 0 and 255 and -1 otherwise */ +#define S_EXITCODE (1<<2)/* wrapper around the execve() call */ int openvpn_popen (const struct argv *a,const struct env_set *es);bool openvpn_execve_allowed (const unsigned int flags); -bool openvpn_execve_check (const struct argv *a,const struct env_set *es, +int openvpn_execve_check (const struct argv *a,const struct env_set *es,const unsigned int flags,const char *error_message); -static inline bool +/** +* Will run a script and return the exit code of the script if between +* 0 and 255, -1 otherwise +*/ +static inline int openvpn_run_script (const struct argv *a,const struct env_set *es,const unsigned int flags,const char *hook) {
Signature · 1 line
2.30.0
PATCH v2 7/11 Refactor extract_var_peer_info into standalone function and add ssl_util.c
In reply to Arne SchwabeOur "natural" place for this function would be ssl.c but ssl.c has a lot of dependencies on all kinds of other compilation units so including ssl.c into unit tests is near impossible currently. Instead create a new file ssl_util.c that holds small utility functions like this one.
Patch v2: add newline add the end of sll_util.h and ssl_util.c
--- src/openvpn/Makefile.am | 1 + src/openvpn/openvpn.vcxproj | 2 + src/openvpn/openvpn.vcxproj.filters | 6 +++ src/openvpn/ssl.c | 2 +- src/openvpn/ssl_ncp.c | 20 ++-------- src/openvpn/ssl_util.c | 59 ++++++++++++++++++++++++++++ src/openvpn/ssl_util.h | 49 +++++++++++++++++++++++ src/openvpn/ssl_verify.c | 1 + tests/unit_tests/openvpn/Makefile.am | 3 +- 9 files changed, 125 insertions(+), 18 deletions(-) create mode 100644 src/openvpn/ssl_util.c create mode 100644 src/openvpn/ssl_util.h
src/openvpn/Makefile.am +1 -0
@@ -119,6 +119,7 @@ openvpn_SOURCES = \ ssl_openssl.c ssl_openssl.h \ ssl_mbedtls.c ssl_mbedtls.h \ ssl_ncp.c ssl_ncp.h \ + ssl_util.c ssl_util.h \ ssl_common.h \ ssl_verify.c ssl_verify.h ssl_verify_backend.h \ ssl_verify_openssl.c ssl_verify_openssl.h \
src/openvpn/openvpn.vcxproj +2 -0
@@ -212,6 +212,7 @@ <ClCompile Include="ssl.c" /> <ClCompile Include="ssl_openssl.c" /> <ClCompile Include="ssl_ncp.c" /> + <ClCompile Include="ssl_util.c" /> <ClCompile Include="ssl_verify.c" /> <ClCompile Include="ssl_verify_openssl.c" /> <ClCompile Include="status.c" />
@@ -300,6 +301,7 @@ <ClInclude Include="ssl_common.h" /> <ClInclude Include="ssl_ncp.h" /> <ClInclude Include="ssl_openssl.h" /> + <ClInclude Include="ssl_util.h" /> <ClInclude Include="ssl_verify.h" /> <ClInclude Include="ssl_verify_backend.h" /> <ClInclude Include="ssl_verify_openssl.h" />
src/openvpn/openvpn.vcxproj.filters +6 -0
@@ -243,6 +243,9 @@ <ClCompile Include="ssl_ncp.c"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="ssl_util.c"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="base64.h">
@@ -509,6 +512,9 @@ <ClInclude Include="ssl_ncp.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="ssl_util.h"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ResourceCompile Include="openvpn_win32_resources.rc">
src/openvpn/ssl.c +1 -1
@@ -4201,4 +4201,4 @@ voidssl_clean_user_pass (void) {purge_user_pass (&auth_user_pass, false); -} +}
src/openvpn/ssl_ncp.c +4 -16
@@ -48,6 +48,7 @@#include "common.h" #include "ssl_ncp.h" +#include "ssl_util.h" #include "openvpn.h" /**
@@ -195,23 +196,10 @@ const char * tls_peer_ncp_list(const char *peer_info, struct gc_arena *gc) {/* Check if the peer sends the IV_CIPHERS list */ -const char *ncp_ciphers_start; -if (peer_info && (ncp_ciphers_start =strstr (peer_info,"IV_CIPHERS=" ))) +const char *iv_ciphers =extract_var_peer_info (peer_info,"IV_CIPHERS=" , gc); +if (iv_ciphers) { - ncp_ciphers_start +=strlen ("IV_CIPHERS=" ); -const char *ncp_ciphers_end =strstr (ncp_ciphers_start,"\n" ); -if (!ncp_ciphers_end) - { -/* IV_CIPHERS is at end of the peer_info list and no '\n' -* follows */ - ncp_ciphers_end = ncp_ciphers_start +strlen (ncp_ciphers_start); - } - -char *ncp_ciphers_peer =string_alloc (ncp_ciphers_start, gc); -/* NULL terminate the copy at the right position */ - ncp_ciphers_peer[ncp_ciphers_end - ncp_ciphers_start] ='\0' ; -return ncp_ciphers_peer; - +return iv_ciphers; }else if (tls_peer_info_ncp_ver (peer_info)>=2 ) {
src/openvpn/ssl_util.c new file +59 -0
59 lines not on this page · raw message
src/openvpn/ssl_util.h new file +49 -0
49 lines not on this page · raw message
src/openvpn/ssl_verify.c +1 -0
@@ -46,6 +46,7 @@#endif #include "auth_token.h" #include "push.h" +#include "ssl_util.h" /** Maximum length of common name */ #define TLS_USERNAME_LEN 64
tests/unit_tests/openvpn/Makefile.am +2 -1
@@ -125,4 +125,5 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(openvpn_srcdir)/crypto_openssl.c \ $(openvpn_srcdir)/otime.c \ $(openvpn_srcdir)/packet_id.c \ - $(openvpn_srcdir)/platform.c + $(openvpn_srcdir)/platform.c \ + $(openvpn_srcdir)/ssl_util.c
Signature · 1 line
2.30.0
PATCH v2 8/11 Allow pending auth to be send from a auth plugin
In reply to Arne SchwabePatch v2: removed change that slipped into this patch and belongs
into the next
--- doc/man-sections/generic-options.rst | 3 +- include/openvpn-plugin.h.in | 8 ++ src/openvpn/ssl.c | 2 +- src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_verify.c | 161 +++++++++++++++++++++++++-- src/openvpn/ssl_verify.h | 2 +- 6 files changed, 162 insertions(+), 15 deletions(-)
doc/man-sections/generic-options.rst +2 -1
@@ -409,7 +409,8 @@ which mode OpenVPN is configured as. * :code:`OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY` plug-in hooks returns success/failure via :code:`auth_control_file` when using deferred auth - method + method and pending authentification via :code:`pending_auth_file`. + * :code:`OPENVPN_PLUGIN_ENABLE_PF` plugin hook to pass filtering rules via ``pf_file``
include/openvpn-plugin.h.in +8 -0
@@ -567,6 +567,14 @@ OPENVPN_PLUGIN_DEF openvpn_plugin_handle_t OPENVPN_PLUGIN_FUNC(openvpn_plugin_op * auth_control_file/client_connect_deferred_file * in the environmental variable list (envp). * + * Additionally the auth_pending_file can be written, which causes the openvpn + * server to send a pending auth request to the client. See doc/management.txt + * for more details on this authentication mechanism. The format of the + * auth_pending_file is + * line 1: timeout in seconds + * line 2: Pending auth method the client needs to support (e.g. openurl) + * line 3: EXTRA (e.g. OPEN_URL:http://www.example.com) + * * In addition the OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER and * OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2 are called when OpenVPN tries to * get the deferred result. For a V2 call implementing this function is
src/openvpn/ssl.c +1 -1
@@ -993,7 +993,7 @@ key_state_free(struct key_state *ks, bool clear)packet_id_free (&ks->crypto_options.packet_id);#ifdef PLUGIN_DEF_AUTH -key_state_rm_auth_control_file (ks); +key_state_rm_auth_control_files (ks);#endif if (clear)
src/openvpn/ssl_common.h +1 -0
@@ -215,6 +215,7 @@ struct key_stateunsigned int auth_control_status;time_t acf_last_mod;char *auth_control_file; +char *auth_pending_file; };/** Control channel wrapping (--tls-auth/--tls-crypt) context */
src/openvpn/ssl_verify.c +149 -12
209 lines not on this page · raw message
src/openvpn/ssl_verify.h +1 -1
@@ -117,7 +117,7 @@ tls_authentication_status(struct tls_multi *multi, const int latency);* * @param ks The key state the remove the file for */ -void key_state_rm_auth_control_file (struct key_state *ks); +void key_state_rm_auth_control_files (struct key_state *ks);/** * Frees the given set of certificate hashes.
Signature · 1 line
2.30.0
PATCH v2 9/11 Implement deferred auth for scripts
In reply to Arne SchwabeThis patch also refactors the if condition that checks the result of the authentication since that has become quite unreadable. It renames s1/s2 and extracts some parts of the condition into individual variables to make the condition better understandle
Patch V2: add refactoring of the if condition
--- Changes.rst | 12 ++++ doc/man-sections/script-options.rst | 14 ++++- src/openvpn/ssl.c | 2 - src/openvpn/ssl_verify.c | 86 +++++++++++++++++++++-------- 4 files changed, 89 insertions(+), 25 deletions(-)
Changes.rst +12 -0
@@ -9,6 +9,18 @@ Keying Material Exporters (RFC 5705) based key generation the RFC5705 based key material generation to the current custom OpenVPN PRF. This feature requires OpenSSL or mbed TLS 2.18+. +Deferred auth support for scripts + The ``--auth-user-pass-verify`` script supports now deferred authentication. + +Pending auth support for plugins and scripts + Both auth plugin and script can now signal pending authentication to + the client when using deferred authentication. The new ``client-crresponse`` + script option and ``OPENVPN_PLUGIN_CLIENT_CRRESPONSE`` plugin function can + be used to parse a client response to a ``CR_TEXT`` two factor challenge. + + See ``sample/sample-scripts/totpauth.py`` for an example. + + Overview of changes in 2.5 ==========================
doc/man-sections/script-options.rst +13 -1
@@ -90,7 +90,19 @@ SCRIPT HOOKS The script should examine the username and password, returning a success exit code (:code:`0`) if the client's authentication request is to be - accepted, or a failure code (:code:`1`) to reject the client. + accepted, a failure code (:code:`1`) to reject the client, or a that + the authentication is deferred (:code:`2`). If the authentication is + deferred, the script must fork/start a background or another non-blocking + operation to continue the authentication in the background. When finshing + the authentication, a :code:`1` or :code:`0` must be written to the + file specified by the :code:`auth_control_file`. + + 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 + seconds and the second line the EXTRA as documented in the + ``client-pending-auth`` section of `doc/management.txt`. + This directive is designed to enable a plugin-style interface for extending OpenVPN's authentication capabilities.
src/openvpn/ssl.c +0 -2
@@ -992,9 +992,7 @@ key_state_free(struct key_state *ks, bool clear)packet_id_free (&ks->crypto_options.packet_id); -#ifdef PLUGIN_DEF_AUTH key_state_rm_auth_control_files (ks); -#endif if (clear) {
src/openvpn/ssl_verify.c +64 -22
167 lines not on this page · raw message
Signature · 1 line
2.30.0
PATCH v2 10/11 Implement --client-crresponse script options and plugin interface
In reply to Arne SchwabeThis is allows scripts and pluginsto parse/react to a CR_RESPONSE message
Patch V2: doc fixes, do not put script under ENABLE_PLUGIN
--- doc/man-sections/script-options.rst | 28 ++++++++++++- include/openvpn-plugin.h.in | 7 +++- src/openvpn/init.c | 1 + src/openvpn/options.c | 15 +++++++ src/openvpn/options.h | 1 + src/openvpn/push.c | 4 ++ src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_verify.c | 65 ++++++++++++++++++++++++++++- src/openvpn/ssl_verify.h | 23 ++++++++++ 9 files changed, 141 insertions(+), 4 deletions(-)
doc/man-sections/script-options.rst +26 -2
@@ -52,6 +52,11 @@ Script Order of Execution Executed in ``--mode server`` mode on new client connections, when the client is still untrusted. +#. ``--client-crresponse`` + + Execute in ``--mode server`` whenever a client sends a + :code:`CR_RESPONSE` message + SCRIPT HOOKS ------------
@@ -72,7 +77,7 @@ SCRIPT HOOKS double-quoted and/or escaped using a backslash, and should be separated by one or more spaces. - If ``method`` is set to :code:`via-env`, OpenVPN will call ``script`` + If ``method`` is set to :code:`via-env`, OpenVPN will call ``cmd`` with the environmental variables :code:`username` and :code:`password` set to the username/password strings provided by the client. *Beware* that this method is insecure on some platforms which make the environment
@@ -80,7 +85,7 @@ SCRIPT HOOKS If ``method`` is set to :code:`via-file`, OpenVPN will write the username and password to the first two lines of a temporary file. The filename - will be passed as an argument to ``script``, and the file will be + will be passed as an argument to ``cmd``, and the file will be automatically deleted by OpenVPN after the script returns. The location of the temporary file is controlled by the ``--tmp-dir`` option, and will default to the current directory if unspecified. For security,
@@ -123,6 +128,25 @@ SCRIPT HOOKS For a sample script that performs PAM authentication, see :code:`sample-scripts/auth-pam.pl` in the OpenVPN source distribution. +--client-crresponse + Executed when the client sends a text based challenge response. + + Valid syntax: + :: + + client-crresponse cmd + + OpenVPN will write the response of the client into a temporary file. + The filename will be passed as an argument to ``cmd``, and the file will be + automatically deleted by OpenVPN after the script returns. + + The response is passed as is from the client. The script needs to check + itself if the input is valid, e.g. if the input is valid base64 encoding. + + The script can either directly write the result of the verification to + :code:`auth_control_file or further defer it. See ``--auth-user-pass-verify`` + for details. + --client-connect cmd Run command ``cmd`` on client connection.
include/openvpn-plugin.h.in +6 -1
@@ -84,6 +84,10 @@ extern "C" { * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_CLIENT_CONNECT_V2 * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_LEARN_ADDRESS * + * The OPENVPN_PLUGIN_CLIENT_CRRESPONSE function is called when the client sends + * the CR_RESPONSE message, this is *typically* after OPENVPN_PLUGIN_TLS_FINAL + * but may also occur much later. + * * [Client session ensues] * * For each "TLS soft reset", according to reneg-sec option (or similar):
@@ -131,7 +135,8 @@ extern "C" { #define OPENVPN_PLUGIN_ROUTE_PREDOWN 12 #define OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER 13 #define OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2 14 -#define OPENVPN_PLUGIN_N 15 +#define OPENVPN_PLUGIN_CLIENT_CRRESPONSE 15 +#define OPENVPN_PLUGIN_N 16 /* * Build a mask out of a set of plug-in types.
src/openvpn/init.c +1 -0
@@ -2948,6 +2948,7 @@ do_init_crypto_tls(struct context *c, const unsigned int flags) to.auth_user_pass_verify_script = options->auth_user_pass_verify_script; to.auth_user_pass_verify_script_via_file = options->auth_user_pass_verify_script_via_file; + to.client_crresponse_script = options->client_crresponse_script; to.tmp_dir = options->tmp_dir;if (options->ccd_exclusive) {
src/openvpn/options.c +15 -0
@@ -1284,6 +1284,7 @@ show_p2mp_parms(const struct options *o)SHOW_STR (client_connect_script);SHOW_STR (learn_address_script);SHOW_STR (client_disconnect_script); +SHOW_STR (client_crresponse_script);SHOW_STR (client_config_dir);SHOW_BOOL (ccd_exclusive);SHOW_STR (tmp_dir);
@@ -2465,6 +2466,10 @@ options_postprocess_verify_ce(const struct options *options, {msg (M_USAGE ,"--client-connect requires --mode server" ); } +if (options->client_crresponse_script) + { +msg (M_USAGE ,"--client-crresponse requires --mode server" ); + }if (options->client_disconnect_script) {msg (M_USAGE ,"--client-disconnect requires --mode server" );
@@ -7094,6 +7099,16 @@ add_option(struct options *options,set_user_script (options, &options->client_connect_script, p[1 ],"client-connect" , true); } +else if (streq (p[0 ],"client-crresponse" ) && p[1 ]) + { +VERIFY_PERMISSION (OPT_P_SCRIPT ); +if (!no_more_than_n_args (msglevel, p,2 ,NM_QUOTE_HINT )) + { + goto err; + } +set_user_script (options, &options->client_crresponse_script, + p[1 ],"client-crresponse" , true); + }else if (streq (p[0 ],"client-disconnect" ) && p[1 ]) {VERIFY_PERMISSION (OPT_P_SCRIPT );
src/openvpn/options.h +1 -0
@@ -440,6 +440,7 @@ struct optionsconst char *client_connect_script;const char *client_disconnect_script;const char *learn_address_script; +const char *client_crresponse_script;const char *client_config_dir;bool ccd_exclusive;bool disable;
src/openvpn/push.c +4 -0
@@ -228,6 +228,10 @@ receive_cr_response(struct context *c, const struct buffer *buffer)management_notify_client_cr_response (key_id, mda, es, m);#endif +#if ENABLE_PLUGIN +verify_crresponse_plugin (c->c2.tls_multi, m); +#endif +verify_crresponse_script (c->c2.tls_multi, m);msg (D_PUSH ,"CR response was sent by client ('%s')" , m); }
src/openvpn/ssl_common.h +1 -0
@@ -316,6 +316,7 @@ struct tls_options/* used for username/password authentication */ const char *auth_user_pass_verify_script; +const char *client_crresponse_script;bool auth_user_pass_verify_script_via_file;const char *tmp_dir;const char *auth_user_pass_file;
src/openvpn/ssl_verify.c +64 -1
77 lines not on this page · raw message
src/openvpn/ssl_verify.h +23 -0
@@ -209,6 +209,29 @@ tls_common_name_hash(const struct tls_multi *multi, const char **cn, uint32_t *cvoid verify_user_pass (struct user_pass *up,struct tls_multi *multi,struct tls_session *session); + + +/** +* Runs the --client-crresponse script if one is defined. +* +* As with the management interface the script is stateless in the sense that +* it does not directly participate in the authentication but rather should set +* the files for the deferred auth like the management commands. +* +*/ +void +verify_crresponse_script (struct tls_multi *multi,const char *cr_response); + +/** +* Call the plugin OPENVPN_PLUGIN_CLIENT_CRRESPONSE. +* +* As with the management interface calling the plugin is stateless in the sense +* that it does not directly participate in the authentication but rather +* should set the files for the deferred auth like the management commands. +*/ +void +verify_crresponse_plugin (struct tls_multi *multi,const char *cr_response); +/** * Perform final authentication checks, including locking of the cn, the allowed * certificate hashes, and whether a client config entry exists in the
Signature · 1 line
2.30.0
PATCH v2 11/11 Add example script demonstrating TOTP via auth-pending
In reply to Arne Schwabe--- Changes.rst | 9 +++ doc/man-sections/script-options.rst | 3 + sample/sample-scripts/totpauth.py | 107 ++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100755 sample/sample-scripts/totpauth.py
Changes.rst +9 -0
@@ -19,6 +19,15 @@ Pending auth support for plugins and scripts be used to parse a client response to a ``CR_TEXT`` two factor challenge. See ``sample/sample-scripts/totpauth.py`` for an example. +<<<<<<< HEAD +======= + +Deprecated features +------------------- +``inetd`` has been removed + This was a very limited and not-well-tested way to run OpenVPN, on TCP + and TAP mode only. +>>>>>>> 239e8cfd (Add example script demonstrating TOTP via auth-pending) Overview of changes in 2.5
doc/man-sections/script-options.rst +3 -0
@@ -147,6 +147,9 @@ SCRIPT HOOKS :code:`auth_control_file or further defer it. See ``--auth-user-pass-verify`` for details. + For a sample script that implement TOTP (RFC 6238) based two-factor + authentication, see :code:`sample-scripts/totp.py`. + --client-connect cmd Run command ``cmd`` on client connection.
sample/sample-scripts/totpauth.py new file +107 -0
107 lines not on this page · raw message
Signature · 1 line
2.30.0
Re: [Openvpn-devel] [PATCH v2 01/11] Change pull request timeout use a timeout rather than a number
In reply to Arne SchwabeCompared with V1 and spelling is now fixed. Compiled with MSVC, code looks fine.
Re: [Openvpn-devel] [PATCH v2 02/11] Implement client side handling of AUTH_PENDING message
In reply to Arne SchwabeCompared with V1 - all concerns are addressed. Compiled with MSVC.
Re: [Openvpn-devel] [PATCH v2 03/11] Implement server side of AUTH_PENDING with extending timeout
In reply to Arne SchwabeHi,
Looks fine, except
Quoted 7 lines
src/openvpn/push.c +1
-1-send_control_channel_string (c,"AUTH_PENDING" ,D_PUSH ); +struct key_state *ks = &tls_multi->session[TM_ACTIVE ].key[KS_PRIMARY ];C:\Users\lev\Projects\openvpn\src\openvpn\push.c(350,1): error C2220: the following warning is treated as an error C:\Users\lev\Projects\openvpn\src\openvpn\push.c(350,1): warning C4029: declared formal parameter list different from definition C:\Users\lev\Projects\openvpn\src\openvpn\push.c(351,38): error C2065: '
tls_multi': undeclared identifier C:\Users\lev\Projects\openvpn\src\openvpn\push.c(351,40): error C2223: left of '->session' must point to struct/union
-Lev
Re: [Openvpn-devel] [PATCH v2 04/11] Introduce management client state for AUTH_PENDING notifications
In reply to Arne SchwabeSince I already acked v1, I checked that v2 is no different to v1.
I got a compilation error because 03/11 is broken, but it is unrelated to this patch.
Re: [Openvpn-devel] [PATCH v2 05/11] Change parameter of send_auth_pending_messages from context to tls_multi
In reply to Arne SchwabeHi,
The patch is fine and the comment has been fixed. It also fixes compilation errors
introduced in 03/11. However I think we need to fix it back in 03/11, not here.
-Lev
Re: [Openvpn-devel] [PATCH v2 06/11] Add S_EXITCODE flag for openvpn_run_script to report exit code
In reply to Arne SchwabeHi,
V1 has been acked and this has minor style/comment fixes. No other changes compared to V1.
Compiled with MSVC.
Re: [Openvpn-devel] [PATCH v2 07/11] Refactor extract_var_peer_info into standalone function and add ssl_util.c
In reply to Arne SchwabeHi,
Quoted 1 line
Patch v2: add newline add the end of
sll_util.handssl_util.c
sll -> ssl
Compared to v1, only changes are added newlines.
Compiled with MSVC.
Re: [Openvpn-devel] [PATCH v2 08/11] Allow pending auth to be send from a auth plugin
In reply to Arne SchwabeQuoted 4 lines · Arne Schwabe
Patch v2: removed change that slipped into this patch and belongs
into the nextSigned-off-by Arne Schwabe <[email protected]...>
Quoted 9 lines
--- doc/man-sections/generic-options.rst | 3 +- include/openvpn-plugin.h.in | 8 ++ src/openvpn/ssl.c | 2 +- src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_verify.c | 161 +++++++++++++++++++++++++-- src/openvpn/ssl_verify.h | 2 +- 6 files changed, 162 insertions(+), 15 deletions(-)
Glared at the code, run some simple tests and it looks good. I ended up patching sample/sample-plugins/defer/simple.c to do an openurl call. This worked fine.
I'll send a patch updating the sample-plugin after this patchset has been reviewed.
Signature · 4 lines
kind regards, David Sommerseth OpenVPN Inc
Re: [Openvpn-devel] [PATCH v2 09/11] Implement deferred auth for scripts
In reply to Arne SchwabeQuoted 23 lines · Arne Schwabe
This patch also refactors the if condition that checks the result of the authentication since that has become quite unreadable. It renames s1/s2 and extracts some parts of the condition into individual variables to make the condition better understandle
Patch V2: add refactoring of the if condition
Signed-off-by Arne Schwabe <[email protected]...>--- Changes.rst | 12 ++++ doc/man-sections/script-options.rst | 14 ++++- src/openvpn/ssl.c | 2 - src/openvpn/ssl_verify.c | 86 +++++++++++++++++++++-------- 4 files changed, 89 insertions(+), 25 deletions(-)Changes.rst +0
-0@@ -9,6 +9,18 @@ Keying Material Exporters (RFC 5705) based key generation the RFC5705 based key material generation to the current custom OpenVPN PRF. This feature requires OpenSSL or mbed TLS 2.18+.
Changes.rst Keying Material Exporters (RFC 5705) based key generation · line 21
Quoted 10 lines
Changes.rst +10
-0+Deferred auth support for scripts + The ``--auth-user-pass-verify`` script supports now deferred authentication. + +Pending auth support for plugins and scripts + Both auth plugin and script can now signal pending authentication to + the client when using deferred authentication. The new ``client-crresponse`` + script option and ``OPENVPN_PLUGIN_CLIENT_CRRESPONSE`` plugin function can + be used to parse a client response to a ``CR_TEXT`` two factor challenge. + + See ``sample/sample-scripts/totpauth.py`` for an example.
This sample script is not yet added; but I don't think it matter much at this stage and in this file.
Quoted 16 lines
Changes.rst +2
-0+ + Overview of changes in 2.5 ==========================doc/man-sections/script-options.rst +2
-1@@ -90,7 +90,19 @@ SCRIPT HOOKS The script should examine the username and password, returning a success exit code (:code:`0`) if the client's authentication request is to be - accepted, or a failure code (:code:`1`) to reject the client. + accepted, a failure code (:code:`1`) to reject the client, or a that + the authentication is deferred (:code:`2`). If the authentication is
doc/man-sections/script-options.rst SCRIPT HOOKS · line 104
Quoted 10 lines
doc/man-sections/script-options.rst +10
-0+ deferred, the script must fork/start a background or another non-blocking + operation to continue the authentication in the background. When finshing + the authentication, a :code:`1` or :code:`0` must be written to the + file specified by the :code:`auth_control_file`. + + 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 + seconds and the second line the EXTRA as documented in the + ``client-pending-auth`` section of `doc/management.txt`.
Doesn't the auth_pending_file need to be 3 lines?
--------
$timeout
$method
$extra
-------
This is what the plug-in is required to write to the file, which the write_auth_pending() Python function in the totp example in patch 11/11 also does.
Quoted 4 lines
src/openvpn/ssl_verify.c +0
-0
[...snip...]
src/openvpn/ssl_verify.c verify_user_pass_script(struct tls_session *session, struct tls_multi *multi,
Quoted 1 line
src/openvpn/ssl_verify.c +0
-0@@ -1223,25 +1223,61 @@ verify_user_pass_script(struct tls_session *session, struct tls_multi *multi,
[...snip...]+#ifdef ENABLE_DEF_AUTH
+ if (retval == OPENVPN_PLUGIN_FUNC_DEFERRED)
+ {
Didn't you kill ENABLE_DEF_AUTH in commit 99d217b20064e7fef9 ? I had to remove this #ifdef to be able to test it with the totpauth.py script in patch 11/11 (with patch 10/11 applied as well).
Otherwise looking good and works when removing this #ifdef. But needs a bit more polish.
Signature · 4 lines
kind regards, David Sommerseth OpenVPN Inc
Re: [Openvpn-devel] [PATCH v2 10/11] Implement --client-crresponse script options and plugin interface
In reply to Arne SchwabeQuoted 6 lines · Arne Schwabe
This is allows scripts and pluginsto parse/react to a
CR_RESPONSEmessagePatch V2: doc fixes, do not put script under
ENABLE_PLUGINSigned-off-by Arne Schwabe <[email protected]...>
Quoted 11 lines
--- doc/man-sections/script-options.rst | 28 ++++++++++++- include/openvpn-plugin.h.in | 7 +++- src/openvpn/init.c | 1 + src/openvpn/options.c | 15 +++++++ src/openvpn/options.h | 1 + src/openvpn/push.c | 4 ++ src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_verify.c | 65 ++++++++++++++++++++++++++++- src/openvpn/ssl_verify.h | 23 ++++++++++ 9 files changed, 141 insertions(+), 4 deletions(-)
Tested using the totpauth.py script in patch 11/11. Worked fine (after some tweaking, see review response to patch 9 and 11 for details). Code looks reasonable, so this is good enough for me.
Signature · 4 lines
kind regards, David Sommerseth OpenVPN Inc
Re: [Openvpn-devel] [PATCH v2 11/11] Add example script demonstrating TOTP via auth-pending
In reply to Arne SchwabeQuoted 15 lines · Arne Schwabe
Signed-off-by Arne Schwabe <[email protected]...>--- Changes.rst | 9 +++ doc/man-sections/script-options.rst | 3 + sample/sample-scripts/totpauth.py | 107 ++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+)create mode 100755
sample/sample-scripts/totpauth.pyChanges.rst +0
-0@@ -19,6 +19,15 @@ Pending auth support for plugins and scripts be used to parse a client response to a ``CR_TEXT`` two factor challenge.
Changes.rst Pending auth support for plugins and scripts · line 30
Quoted 10 lines
Changes.rst +9
-0See ``sample/sample-scripts/totpauth.py`` for an example. +<<<<<<< HEAD +======= + +Deprecated features +------------------- +``inetd`` has been removed + This was a very limited and not-well-tested way to run OpenVPN, on TCP + and TAP mode only. +>>>>>>> 239e8cfd (Add example script demonstrating TOTP via auth-pending)
Ehm .... ;-)
[...snip....]
Quoted 6 lines
sample/sample-scripts/totpauth.py new file +0
-0@@ -0,0 +1,107 @@
[...snip...]
sample/sample-scripts/totpauth.py
Quoted 2 lines
sample/sample-scripts/totpauth.py new file +2
-0+ +import pprint
This shouldn't be needed.
Quoted 8 lines
sample/sample-scripts/totpauth.py new file +8
-0+ +# Example script demonstrating how to use the auth-pending API in +# OpenVPN. This script is provided under MIT license to allow easy +# modification for other purposes. +# +# To use this script add the following lines in the openvpn config + +# client-crresponse /path/to/totpauth.py
sample/sample-scripts/totpauth.py line 46
Quoted 10 lines
sample/sample-scripts/totpauth.py new file +10
-0+# auth-user-pass-verify /path/to/totpauth.py via-file +# auth-user-pass-optional +# auth-gen-token + +# Note that this script does NOT verify username/password +# It is only meant for querying additional 2FA when certificates are +# used to authenticate + +secrets = {"styx": "OS6JDNRK2BNUPQVX", + "apate": "IXWEMP7SK2QWSHTG"}
Perhaps replace one of these user names with 'Test-Client', which is what our client.crt contains.
This does actually work reasonably well, BUT ... there are some things which could be improved in the documentation here.
Currently, both OpenVPN 2 and OpenVPN 3 Linux (which I tested) does not support crtext based auth out-of-the-box. But it's possible to workaround that with OpenVPN 2.x. (I've tested v2.5.0 and git master). I used this config:
client
remote 127.0.0.1
dev tun
ca sample/sample-keys/ca.crt
key sample/sample-keys/client.key
cert sample/sample-keys/client.crt
nobind
explicit-exit-notify 3
management ./mngmt.sock unix
management-hold
management-query-passwords
setenv IV_SSO crtext
Then I used 'nc -U mngmt.sock' to connect to the management interface and issued the 'hold release' command and the 'cr-response' command with a base64 encoded TOTP value. I did update the toptpauth.py script to use 'Test-Client' instead of one of the predefined user names.
So while this does work fine, it's not a straight forward way to test it out. And it requires client hackery (even though I bet this is not an issue using your Android app ;-)).
I don't think we need to update with more scripts or stuff like that, just mentioning more clearly that the client must support 'crtext' and it is possible with OpenVPN 2.x enabling the management interface and setting the IV_SSO env variable properly.
Otherwise, this generally looks good - but we should improve docs a bit more and fix those minor issues while at it.
Signature · 4 lines
kind regards, David Sommerseth OpenVPN Inc
[Openvpn-devel] [PATCH applied] Re: Change pull request timeout use a timeout rather than a number
In reply to Arne SchwabeYour patch has been applied to the master branch.
Only very lightly tested.
Observation: it introduces "*session" and "*ks" to send_push_request() which might be needed by later patches on, but are not used by code in this patch yet.
commit 413580b6a41d7eefb35438701fc79a63e0344ced
Author: Arne Schwabe Date: Mon Jan 25 13:56:18 2021 +0100
Change pull request timeout use a timeout rather than a number
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Lev Stipakov <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg21490.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v3 1/1 Implement server side of AUTH_PENDING with extending timeout
In reply to Lev StipakovPatch V2: eliminate parse_kid function, fix style Patch V3: adding missing parameter in function, this was added
by a later patch in the original series
--- src/openvpn/manage.c | 23 +++++++++-------- src/openvpn/manage.h | 3 ++- src/openvpn/multi.c | 27 +++----------------- src/openvpn/push.c | 55 +++++++++++++++++++++++++++++++++++++--- src/openvpn/push.h | 14 +++++++++- src/openvpn/ssl.c | 1 + src/openvpn/ssl_common.h | 1 + 7 files changed, 84 insertions(+), 40 deletions(-)
src/openvpn/manage.c +13 -10
@@ -972,15 +972,15 @@ parse_cid(const char *str, unsigned long *cid) }static bool -parse_kid (const char *str,unsigned int *kid) +parse_uint (const char *str,const char * what,unsigned int *uint) { -if (sscanf (str,"%u" , kid) ==1 ) +if (sscanf (str,"%u" , uint) ==1 ) {return true; }else { -msg (M_CLIENT ,"ERROR: cannot parse KID" ); +msg (M_CLIENT ,"ERROR: cannot parse %s" , what);return false; } }
@@ -995,15 +995,18 @@ parse_kid(const char *str, unsigned int *kid)* the information of the additional steps */ static void -man_client_pending_auth (struct management *man,const char *cid_str,const char *extra) +man_client_pending_auth (struct management *man,const char *cid_str, +const char *extra,const char *timeout_str) {unsigned long cid =0 ; -if (parse_cid (cid_str, &cid)) +unsigned int timeout =0 ; +if (parse_cid (cid_str, &cid) + &&parse_uint (timeout_str,"TIMEOUT" , &timeout)) {if (man->persist.callback.client_pending_auth) {bool ret = (*man->persist.callback.client_pending_auth) - (man->persist.callback.arg, cid, extra); + (man->persist.callback.arg, cid, extra, timeout);if (ret) {
@@ -1029,7 +1032,7 @@ man_client_auth(struct management *man, const char *cid_str, const char *kid_str mc->in_extra_cid =0 ; mc->in_extra_kid =0 ;if (parse_cid (cid_str, &mc->in_extra_cid) - &&parse_kid (kid_str, &mc->in_extra_kid)) + &&parse_uint (kid_str,"KID" , &mc->in_extra_kid)) { mc->in_extra_cmd =IEC_CLIENT_AUTH ;in_extra_reset (mc,IER_NEW );
@@ -1045,7 +1048,7 @@ man_client_deny(struct management *man, const char *cid_str, const char *kid_str {unsigned long cid =0 ;unsigned int kid =0 ; -if (parse_cid (cid_str, &cid) &&parse_kid (kid_str, &kid)) +if (parse_cid (cid_str, &cid) &&parse_uint (kid_str,"KID" , &kid)) {if (man->persist.callback.client_auth) {
@@ -1560,9 +1563,9 @@ man_dispatch_command(struct management *man, struct status_output *so, const cha }else if (streq (p[0 ],"client-pending-auth" )) { -if (man_need (man, p,2 ,0 )) +if (man_need (man, p,3 ,0 )) { -man_client_pending_auth (man, p[1 ], p[2 ]); +man_client_pending_auth (man, p[1 ], p[2 ], p[3 ]); } }#ifdef MANAGEMENT_PF
src/openvpn/manage.h +2 -1
@@ -173,7 +173,8 @@ struct management_callback struct buffer_list *cc_config); /* ownership transferred */bool (*client_pending_auth) (void *arg,const unsigned long cid, -const char *url); +const char *extra, +unsigned int timeout);char *(*get_peer_info) (void *arg,const unsigned long cid);#ifdef MANAGEMENT_PF bool (*client_pf)(void *arg,
src/openvpn/multi.c +3 -24
@@ -1768,28 +1768,6 @@ multi_client_connect_setenv(struct multi_context *m,gc_free (&gc); } -/** -* Extracts the IV_PROTO variable and returns its value or 0 -* if it cannot be extracted. -* -*/ -static unsigned int -extract_iv_proto (const char *peer_info) -{ - -const char *optstr = peer_info ?strstr (peer_info,"IV_PROTO=" ) :NULL ; -if (optstr) - { -int proto =0 ; -int r =sscanf (optstr,"IV_PROTO=%d" , &proto); -if (r ==1 && proto >0 ) - { -return proto; - } - } -return 0 ; -} -/** * Calculates the options that depend on the client capabilities * based on local options and available peer info
@@ -3918,14 +3896,15 @@ management_kill_by_cid(void *arg, const unsigned long cid, const char *kill_msg)static bool management_client_pending_auth (void *arg,const unsigned long cid, -const char *extra) +const char *extra, +unsigned int timeout) {struct multi_context *m = (struct multi_context *) arg;struct multi_instance *mi =lookup_by_cid (m, cid);if (mi) {/* sends INFO_PRE and AUTH_PENDING messages to client */ -bool ret =send_auth_pending_messages (&mi->context, extra); +bool ret =send_auth_pending_messages (&mi->context, extra, timeout);multi_schedule_context_wakeup (m, mi);return ret; }
src/openvpn/push.c +51 -4
81 lines not on this page · raw message
src/openvpn/push.h +13 -1
@@ -77,7 +77,9 @@ void send_auth_failed(struct context *c, const char *client_reason);* doc/management-notes.txt under client-pending-auth for * more details on message format */ -bool send_auth_pending_messages (struct context *c,const char *extra); +bool +send_auth_pending_messages (struct tls_multi *tls_multi,const char *extra, +unsigned int timeout);void send_restart (struct context *c,const char *kill_msg);
@@ -89,6 +91,16 @@ void send_restart(struct context *c, const char *kill_msg);*/ void send_push_reply_auth_token (struct tls_multi *multi); + +/** +* Extracts the IV_PROTO variable and returns its value or 0 +* if it cannot be extracted. +* +* @param peer_info peer info string to search for IV_PROTO +*/ +unsigned int +extract_iv_proto (const char *peer_info); +/** * Parses an AUTH_PENDING message and if in pull mode extends the timeout *
src/openvpn/ssl.c +1 -0
@@ -2771,6 +2771,7 @@ tls_process(struct tls_multi *multi, buf =reliable_get_buf_output_sequenced (ks->send_reliable);if (buf) { + ks->initial = now; ks->must_negotiate = now + session->opt->handshake_window; ks->auth_deferred_expire = now +auth_deferred_expire_window (session->opt);
src/openvpn/ssl_common.h +1 -0
@@ -175,6 +175,7 @@ struct key_statestruct key_state_ssl ks_ssl;/* contains SSL object and BIOs for the control channel */ +time_t initial;/* when we created this session */ time_t established;/* when our state went S_ACTIVE */ time_t must_negotiate;/* key negotiation times out if not finished before this time */ time_t must_die;/* this object is destroyed at this time */
Signature · 1 line
2.30.0
PATCH v3 1/1 Change parameter of send_auth_pending_messages from context to tls_multi
In reply to Lev StipakovThis prepares send_auth_pending_messages to be used a in context that does not have context c available but also does not need to schedule an immediate sending of the message (auth plugin/script)
Patch V2: Adjust the comment of reschedule_multi_process to actually fit a
function.
Patch V3: Rebase needed because v3 of 3/11
--- src/openvpn/forward.c | 17 +++++++++-------- src/openvpn/forward.h | 9 +++++++++ src/openvpn/multi.c | 4 +++- src/openvpn/push.c | 9 ++++----- 4 files changed, 25 insertions(+), 14 deletions(-)
src/openvpn/forward.c +9 -8
@@ -342,6 +342,14 @@ send_control_channel_string_dowork(struct tls_multi *multi,return stat; } +void reschedule_multi_process (struct context *c) +{ + +interval_action (&c->c2.tmp_int); +context_immediate_reschedule (c);/* ZERO-TIMEOUT */ +} + +bool send_control_channel_string (struct context *c,const char *str,int msglevel) {
@@ -349,15 +357,8 @@ send_control_channel_string(struct context *c, const char *str, int msglevel) {bool ret =send_control_channel_string_dowork (c->c2.tls_multi, str, msglevel); -/* -* Reschedule tls_multi_process. -* NOTE: in multi-client mode, usually the below two statements are -* insufficient to reschedule the client instance object unless -* multi_schedule_context_wakeup(m, mi) is also called. -*/ +reschedule_multi_process (c); -interval_action (&c->c2.tmp_int); -context_immediate_reschedule (c);/* ZERO-TIMEOUT */ return ret; }return true;
src/openvpn/forward.h +9 -0
@@ -317,6 +317,15 @@ bool send_control_channel_string_dowork(struct tls_multi *multi, const char *str, int msglevel); + +/** +* Reschedule tls_multi_process. +* NOTE: in multi-client mode, usually calling the function is +* insufficient to reschedule the client instance object unless +* multi_schedule_context_wakeup(m, mi) is also called. +*/ +void reschedule_multi_process (struct context *c); +#define PIPV4_PASSTOS (1<<0)#define PIP_MSSFIX (1<<1)/* v4 and v6 */ #define PIP_OUTGOING (1<<2)
src/openvpn/multi.c +3 -1
@@ -3904,7 +3904,9 @@ management_client_pending_auth(void *arg,if (mi) {/* sends INFO_PRE and AUTH_PENDING messages to client */ -bool ret =send_auth_pending_messages (&mi->context, extra, timeout); +bool ret =send_auth_pending_messages (mi->context.c2.tls_multi, extra, + timeout); +reschedule_multi_process (&mi->context);multi_schedule_context_wakeup (m, mi);return ret; }
src/openvpn/push.c +4 -5
@@ -363,10 +363,9 @@ send_auth_failed(struct context *c, const char *client_reason)bool -send_auth_pending_messages (struct context *c,const char *extra, +send_auth_pending_messages (struct tls_multi *tls_multi,const char *extra,unsigned int timeout) { -struct tls_multi *tls_multi = c->c2.tls_multi;struct key_state *ks = &tls_multi->session[TM_ACTIVE ].key[KS_PRIMARY ];static const char info_pre[] ="INFO_PRE," ;
@@ -384,7 +383,7 @@ send_auth_pending_messages(struct context *c, const char *extra,struct gc_arena gc =gc_new ();if ((proto &IV_PROTO_AUTH_PENDING_KW ) ==0 ) { -send_control_channel_string (c,"AUTH_PENDING" ,D_PUSH ); +send_control_channel_string_dowork (tls_multi,"AUTH_PENDING" ,D_PUSH ); }else {
@@ -395,7 +394,7 @@ send_auth_pending_messages(struct context *c, const char *extra,struct buffer buf =alloc_buf_gc (len, &gc);buf_printf (&buf, auth_pre);buf_printf (&buf,"%u" , timeout); -send_control_channel_string (c,BSTR (&buf),D_PUSH ); +send_control_channel_string_dowork (tls_multi,BSTR (&buf),D_PUSH ); }size_t len =strlen (extra) +1 +sizeof (info_pre);
@@ -408,7 +407,7 @@ send_auth_pending_messages(struct context *c, const char *extra,struct buffer buf =alloc_buf_gc (len, &gc);buf_printf (&buf, info_pre);buf_printf (&buf,"%s" , extra); -send_control_channel_string (c,BSTR (&buf),D_PUSH ); +send_control_channel_string_dowork (tls_multi,BSTR (&buf),D_PUSH ); ks->auth_deferred_expire = now + timeout;
Signature · 1 line
2.30.0
Re: [Openvpn-devel] [PATCH v3] Implement server side of AUTH_PENDING with extending timeout
In reply to Arne SchwabeAlmost there.
Here we still need context, not tls_multi.
Quoted 8 lines
src/openvpn/push.h +3
-1-bool send_auth_pending_messages (struct context *c,const char *extra); +bool +send_auth_pending_messages (struct tls_multi *tls_multi,const char *extra, +unsigned int timeout);C:\Users\lev\Projects\openvpn\src\openvpn\multi.c(3907,59): error C2220: the following warning is treated as an error C:\Users\lev\Projects\openvpn\src\openvpn\multi.c(3907,59): warning C4133: 'function': incompatible types - from 'context *' to '
tls_multi*'
[Openvpn-devel] [PATCH applied] Re: Implement client side handling of AUTH_PENDING message
In reply to Arne SchwabeYour patch has been applied to the master branch.
I'm not sure I understand the code, though. It receives the new timeout from the server (that is easy), but then caps it by "hand_window", which is never increased - so the maximum timeout stays at "60", unless increased manually on the client. Where am I misreading this? Or is this a prerequisite for this functionality?
c->c2.push_request_timeout = ks->established + min_uint(max_timeout, server_timeout);
(or am I totally misunderstanding push_request_timeout, and this has nothing to do with hand-window, except "it's using this as a default value", but only for triggering re-sends, not for "final give up"?)
However, for my standard test cases, this does not break anything, and the code looks reasonable. So in it goes :)
commit 3f8fb2b2c1d664f421d36181846da89c4330c6cc
Author: Arne Schwabe Date: Mon Jan 25 13:56:19 2021 +0100
Implement client side handling of AUTH_PENDING message
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Lev Stipakov <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg21491.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [PATCH applied] Re: Introduce management client state for AUTH_PENDING notifications
In reply to Arne SchwabeYour patch has been applied to the master branch.
As this is not depending on 03/11, I've applied it out of sequence.
One typo fixed ("techhnically"). Test run on the client, unsurprisingly no breakage - I have nothing that excercises the new code yet, but it still looks very reasonable :-)
commit b29f7dffc073ebd2a3b04eac5f7aee2edcf5da49
Author: Arne Schwabe Date: Mon Jan 25 13:56:21 2021 +0100
Introduce management client state for AUTH_PENDING notifications
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Lev Stipakov <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg21498.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [PATCH applied] Re: Add S_EXITCODE flag for openvpn_run_script to report exit code
In reply to Arne SchwabeYour patch has been applied to the master branch.
Again, out of sequence, as this does not depend on 03/11 or 05/11.
Lightly tested and stared at the code a bit. Added a line break before a "{"...
commit 04876274b5059f4c27b1f481fd92ff5e8ab15f1c
Author: Arne Schwabe Date: Mon Jan 25 13:56:23 2021 +0100
Add S_EXITCODE flag for openvpn_run_script to report exit code
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Lev Stipakov <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg21487.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH v2 07/11] Refactor extract_var_peer_info into standalone function and add ssl_util.c
In reply to Arne SchwabeHi,
Quoted 6 lines · Arne Schwabe
Our "natural" place for this function would be
ssl.cbutssl.chas a lot of dependencies on all kinds of other compilation units so includingssl.cinto unit tests is near impossible currently. Instead create a new filessl_util.cthat holds small utility functions like this one.Patch v2: add newline add the end of
sll_util.handssl_util.c
Even if it already got an ACK, I find the function could benefit from a v3... "if we refactor, go all the way"
- change to early-return
if (!peer_info || ((var_start = strstr(peer_info, var)) == NULL))
{
return NULL;
}- possibly split the assignment-and-compare if() into easier to read
const char *var_start = strstr(peer_info, var);
if (!var_start)
{
return NULL;
}- half the function has been converted to "var" and "var_start", and the rest still talks "char *ncp_ciphers_peer"... wat? - maybe that should be "char *value" (and "var" should be "key"?) or something.
- the v2 hunk has a newline-at-end-of-file mishap in ssl.c
src/openvpn/ssl.c void · line 4204
Quoted 10 lines
index
14c8116f..f59b409f100644src/openvpn/ssl.c +1
-1@@ -4201,4 +4201,4 @@ voidssl_clean_user_pass (void) {purge_user_pass (&auth_user_pass, false); -} +}
(this is a new "no newline"), while v2 fixes the other one).
On the plus side, I tested "make distcheck" on linux, and all the Makefile bits and pieces are proper (we tend to break that for new C files...)
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...Re: [Openvpn-devel] [PATCH applied] Re: Implement client side handling of AUTH_PENDING message
In reply to Gert DoeringAm 14.02.21 um 16:19 schrieb Gert Doering:
Quoted 5 lines
Your patch has been applied to the master branch.
I'm not sure I understand the code, though. It receives the new timeout from the server (that is easy), but then caps it by "
hand_window", which is never increased - so the maximum timeout stays at "60", unless increased
hm max_timeout is maximum of handshake_window and renegotiate_seconds/2, so max(60,1800) in a default configuration.
Quoted 4 lines
manually on the client. Where am I misreading this? Or is this a prerequisite for this functionality?
c->c2.push_request_timeout = ks->established + min_uint(max_timeout, server_timeout);
And here we normally take a minimum of 1800 and whatever the server pushed.
Quoted 3 lines
(or am I totally misunderstanding
push_request_timeout, and this has nothing to do with hand-window, except "it's using this as a default value", but only for triggering re-sends, not for "final give up"?)
This patch also splits two timeouts that before just happend to be identical into two distinct timeouts. One time is the one that says how TLS (re)negotiation is allowed to be (handshake_window) and the other one is the pull timeout. The if condition in push.c shows their relationship:
if (c->c2.push_request_timeout > now
&& (now - ks->peer_last_packet) < c->options.handshake_window)Basically give the user "max_timeout" time to answer the 2FA challenge but only if the server has been alive in the last handshake_window seconds.
Quoted 2 lines
However, for my standard test cases, this does not break anything, and the code looks reasonable. So in it goes :)
PATCH v3 1/1 Refactor extract_var_peer_info into standalone function and add ssl_util.c
In reply to Gert DoeringOur "natural" place for this function would be ssl.c but ssl.c has a lot of dependencies on all kinds of other compilation units so including ssl.c into unit tests is near impossible currently. Instead create a new file ssl_util.c that holds small utility functions like this one.
Patch v2: add newline add the end of sll_util.h and ssl_util.c
Patch v3: Refactor/clean up the function even more as suggested by Gert.
--- src/openvpn/Makefile.am | 1 + src/openvpn/openvpn.vcxproj | 2 + src/openvpn/openvpn.vcxproj.filters | 6 +++ src/openvpn/ssl.c | 2 +- src/openvpn/ssl_ncp.c | 20 ++------- src/openvpn/ssl_util.c | 61 ++++++++++++++++++++++++++++ src/openvpn/ssl_util.h | 49 ++++++++++++++++++++++ src/openvpn/ssl_verify.c | 1 + tests/unit_tests/openvpn/Makefile.am | 3 +- 9 files changed, 127 insertions(+), 18 deletions(-) create mode 100644 src/openvpn/ssl_util.c create mode 100644 src/openvpn/ssl_util.h
src/openvpn/Makefile.am +1 -0
@@ -119,6 +119,7 @@ openvpn_SOURCES = \ ssl_openssl.c ssl_openssl.h \ ssl_mbedtls.c ssl_mbedtls.h \ ssl_ncp.c ssl_ncp.h \ + ssl_util.c ssl_util.h \ ssl_common.h \ ssl_verify.c ssl_verify.h ssl_verify_backend.h \ ssl_verify_openssl.c ssl_verify_openssl.h \
src/openvpn/openvpn.vcxproj +2 -0
@@ -212,6 +212,7 @@ <ClCompile Include="ssl.c" /> <ClCompile Include="ssl_openssl.c" /> <ClCompile Include="ssl_ncp.c" /> + <ClCompile Include="ssl_util.c" /> <ClCompile Include="ssl_verify.c" /> <ClCompile Include="ssl_verify_openssl.c" /> <ClCompile Include="status.c" />
@@ -300,6 +301,7 @@ <ClInclude Include="ssl_common.h" /> <ClInclude Include="ssl_ncp.h" /> <ClInclude Include="ssl_openssl.h" /> + <ClInclude Include="ssl_util.h" /> <ClInclude Include="ssl_verify.h" /> <ClInclude Include="ssl_verify_backend.h" /> <ClInclude Include="ssl_verify_openssl.h" />
src/openvpn/openvpn.vcxproj.filters +6 -0
@@ -243,6 +243,9 @@ <ClCompile Include="ssl_ncp.c"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="ssl_util.c"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="base64.h">
@@ -509,6 +512,9 @@ <ClInclude Include="ssl_ncp.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="ssl_util.h"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ResourceCompile Include="openvpn_win32_resources.rc">
src/openvpn/ssl.c +1 -1
@@ -4089,4 +4089,4 @@ voidssl_clean_user_pass (void) {purge_user_pass (&auth_user_pass, false); -} +}
src/openvpn/ssl_ncp.c +4 -16
@@ -48,6 +48,7 @@#include "common.h" #include "ssl_ncp.h" +#include "ssl_util.h" #include "openvpn.h" /**
@@ -195,23 +196,10 @@ const char * tls_peer_ncp_list(const char *peer_info, struct gc_arena *gc) {/* Check if the peer sends the IV_CIPHERS list */ -const char *ncp_ciphers_start; -if (peer_info && (ncp_ciphers_start =strstr (peer_info,"IV_CIPHERS=" ))) +const char *iv_ciphers =extract_var_peer_info (peer_info,"IV_CIPHERS=" , gc); +if (iv_ciphers) { - ncp_ciphers_start +=strlen ("IV_CIPHERS=" ); -const char *ncp_ciphers_end =strstr (ncp_ciphers_start,"\n" ); -if (!ncp_ciphers_end) - { -/* IV_CIPHERS is at end of the peer_info list and no '\n' -* follows */ - ncp_ciphers_end = ncp_ciphers_start +strlen (ncp_ciphers_start); - } - -char *ncp_ciphers_peer =string_alloc (ncp_ciphers_start, gc); -/* NULL terminate the copy at the right position */ - ncp_ciphers_peer[ncp_ciphers_end - ncp_ciphers_start] ='\0' ; -return ncp_ciphers_peer; - +return iv_ciphers; }else if (tls_peer_info_ncp_ver (peer_info)>=2 ) {
src/openvpn/ssl_util.c new file +61 -0
61 lines not on this page · raw message
src/openvpn/ssl_util.h new file +49 -0
49 lines not on this page · raw message
src/openvpn/ssl_verify.c +1 -0
@@ -46,6 +46,7 @@#endif #include "auth_token.h" #include "push.h" +#include "ssl_util.h" /** Maximum length of common name */ #define TLS_USERNAME_LEN 64
tests/unit_tests/openvpn/Makefile.am +2 -1
@@ -125,4 +125,5 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(openvpn_srcdir)/crypto_openssl.c \ $(openvpn_srcdir)/otime.c \ $(openvpn_srcdir)/packet_id.c \ - $(openvpn_srcdir)/platform.c + $(openvpn_srcdir)/platform.c \ + $(openvpn_srcdir)/ssl_util.c
Signature · 1 line
2.30.1
PATCH v3 1/1 Implement deferred auth for scripts
In reply to David SommersethThis patch also refactors the if condition that checks the result of the authentication since that has become quite unreadable. It renames s1/s2 and extracts some parts of the condition into individual variables to make the condition better understandle
Patch V2: add refactoring of the if condition
--- Changes.rst | 12 +++++ doc/man-sections/script-options.rst | 14 ++++- src/openvpn/ssl.c | 2 - src/openvpn/ssl_verify.c | 84 +++++++++++++++++++++-------- 4 files changed, 87 insertions(+), 25 deletions(-)
Changes.rst +12 -0
@@ -15,6 +15,17 @@ Compatibility with OpenSSL in FIPS mode requirements/recommendation of FIPS 140-2. This just allows OpenVPN to be run on a system that be configured OpenSSL in FIPS mode. +Deferred auth support for scripts + The ``--auth-user-pass-verify`` script supports now deferred authentication. + +Pending auth support for plugins and scripts + Both auth plugin and script can now signal pending authentication to + the client when using deferred authentication. The new ``client-crresponse`` + script option and ``OPENVPN_PLUGIN_CLIENT_CRRESPONSE`` plugin function can + be used to parse a client response to a ``CR_TEXT`` two factor challenge. + + See ``sample/sample-scripts/totpauth.py`` for an example. + Deprecated features ------------------- ``inetd`` has been removed
@@ -22,6 +33,7 @@ Deprecated features and TAP mode only. + Overview of changes in 2.5 ==========================
doc/man-sections/script-options.rst +13 -1
@@ -90,7 +90,19 @@ SCRIPT HOOKS The script should examine the username and password, returning a success exit code (:code:`0`) if the client's authentication request is to be - accepted, or a failure code (:code:`1`) to reject the client. + accepted, a failure code (:code:`1`) to reject the client, or a that + the authentication is deferred (:code:`2`). If the authentication is + deferred, the script must fork/start a background or another non-blocking + operation to continue the authentication in the background. When finshing + the authentication, a :code:`1` or :code:`0` must be written to the + file specified by the :code:`auth_control_file`. + + 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 + seconds and the second line the EXTRA as documented in the + ``client-pending-auth`` section of `doc/management.txt`. + This directive is designed to enable a plugin-style interface for extending OpenVPN's authentication capabilities.
src/openvpn/ssl.c +0 -2
@@ -992,9 +992,7 @@ key_state_free(struct key_state *ks, bool clear)packet_id_free (&ks->crypto_options.packet_id); -#ifdef PLUGIN_DEF_AUTH key_state_rm_auth_control_files (ks); -#endif if (clear) {
src/openvpn/ssl_verify.c +62 -22
165 lines not on this page · raw message
Signature · 1 line
2.30.1
PATCH v3 1/1 Implement server side of AUTH_PENDING with extending timeout
In reply to Lev StipakovPatch V2: eliminate parse_kid function, fix style Patch V3: adding missing parameter in function, this was added
by a later patch in the original series
--- src/openvpn/manage.c | 23 +++++++++-------- src/openvpn/manage.h | 3 ++- src/openvpn/multi.c | 27 +++----------------- src/openvpn/push.c | 55 +++++++++++++++++++++++++++++++++++++--- src/openvpn/push.h | 14 +++++++++- src/openvpn/ssl.c | 1 + src/openvpn/ssl_common.h | 1 + 7 files changed, 84 insertions(+), 40 deletions(-)
src/openvpn/manage.c +13 -10
@@ -975,15 +975,15 @@ parse_cid(const char *str, unsigned long *cid) }static bool -parse_kid (const char *str,unsigned int *kid) +parse_uint (const char *str,const char * what,unsigned int *uint) { -if (sscanf (str,"%u" , kid) ==1 ) +if (sscanf (str,"%u" , uint) ==1 ) {return true; }else { -msg (M_CLIENT ,"ERROR: cannot parse KID" ); +msg (M_CLIENT ,"ERROR: cannot parse %s" , what);return false; } }
@@ -998,15 +998,18 @@ parse_kid(const char *str, unsigned int *kid)* the information of the additional steps */ static void -man_client_pending_auth (struct management *man,const char *cid_str,const char *extra) +man_client_pending_auth (struct management *man,const char *cid_str, +const char *extra,const char *timeout_str) {unsigned long cid =0 ; -if (parse_cid (cid_str, &cid)) +unsigned int timeout =0 ; +if (parse_cid (cid_str, &cid) + &&parse_uint (timeout_str,"TIMEOUT" , &timeout)) {if (man->persist.callback.client_pending_auth) {bool ret = (*man->persist.callback.client_pending_auth) - (man->persist.callback.arg, cid, extra); + (man->persist.callback.arg, cid, extra, timeout);if (ret) {
@@ -1032,7 +1035,7 @@ man_client_auth(struct management *man, const char *cid_str, const char *kid_str mc->in_extra_cid =0 ; mc->in_extra_kid =0 ;if (parse_cid (cid_str, &mc->in_extra_cid) - &&parse_kid (kid_str, &mc->in_extra_kid)) + &&parse_uint (kid_str,"KID" , &mc->in_extra_kid)) { mc->in_extra_cmd =IEC_CLIENT_AUTH ;in_extra_reset (mc,IER_NEW );
@@ -1048,7 +1051,7 @@ man_client_deny(struct management *man, const char *cid_str, const char *kid_str {unsigned long cid =0 ;unsigned int kid =0 ; -if (parse_cid (cid_str, &cid) &&parse_kid (kid_str, &kid)) +if (parse_cid (cid_str, &cid) &&parse_uint (kid_str,"KID" , &kid)) {if (man->persist.callback.client_auth) {
@@ -1563,9 +1566,9 @@ man_dispatch_command(struct management *man, struct status_output *so, const cha }else if (streq (p[0 ],"client-pending-auth" )) { -if (man_need (man, p,2 ,0 )) +if (man_need (man, p,3 ,0 )) { -man_client_pending_auth (man, p[1 ], p[2 ]); +man_client_pending_auth (man, p[1 ], p[2 ], p[3 ]); } }#ifdef MANAGEMENT_PF
src/openvpn/manage.h +2 -1
@@ -173,7 +173,8 @@ struct management_callback struct buffer_list *cc_config); /* ownership transferred */bool (*client_pending_auth) (void *arg,const unsigned long cid, -const char *url); +const char *extra, +unsigned int timeout);char *(*get_peer_info) (void *arg,const unsigned long cid);#ifdef MANAGEMENT_PF bool (*client_pf)(void *arg,
src/openvpn/multi.c +3 -24
@@ -1768,28 +1768,6 @@ multi_client_connect_setenv(struct multi_context *m,gc_free (&gc); } -/** -* Extracts the IV_PROTO variable and returns its value or 0 -* if it cannot be extracted. -* -*/ -static unsigned int -extract_iv_proto (const char *peer_info) -{ - -const char *optstr = peer_info ?strstr (peer_info,"IV_PROTO=" ) :NULL ; -if (optstr) - { -int proto =0 ; -int r =sscanf (optstr,"IV_PROTO=%d" , &proto); -if (r ==1 && proto >0 ) - { -return proto; - } - } -return 0 ; -} -/** * Calculates the options that depend on the client capabilities * based on local options and available peer info
@@ -3918,14 +3896,15 @@ management_kill_by_cid(void *arg, const unsigned long cid, const char *kill_msg)static bool management_client_pending_auth (void *arg,const unsigned long cid, -const char *extra) +const char *extra, +unsigned int timeout) {struct multi_context *m = (struct multi_context *) arg;struct multi_instance *mi =lookup_by_cid (m, cid);if (mi) {/* sends INFO_PRE and AUTH_PENDING messages to client */ -bool ret =send_auth_pending_messages (&mi->context, extra); +bool ret =send_auth_pending_messages (&mi->context, extra, timeout);multi_schedule_context_wakeup (m, mi);return ret; }
src/openvpn/push.c +51 -4
81 lines not on this page · raw message
src/openvpn/push.h +13 -1
@@ -77,7 +77,9 @@ void send_auth_failed(struct context *c, const char *client_reason);* doc/management-notes.txt under client-pending-auth for * more details on message format */ -bool send_auth_pending_messages (struct context *c,const char *extra); +bool +send_auth_pending_messages (struct context *c,const char *extra, +unsigned int timeout);void send_restart (struct context *c,const char *kill_msg);
@@ -89,6 +91,16 @@ void send_restart(struct context *c, const char *kill_msg);*/ void send_push_reply_auth_token (struct tls_multi *multi); + +/** +* Extracts the IV_PROTO variable and returns its value or 0 +* if it cannot be extracted. +* +* @param peer_info peer info string to search for IV_PROTO +*/ +unsigned int +extract_iv_proto (const char *peer_info); +/** * Parses an AUTH_PENDING message and if in pull mode extends the timeout *
src/openvpn/ssl.c +1 -0
@@ -2659,6 +2659,7 @@ tls_process(struct tls_multi *multi, buf =reliable_get_buf_output_sequenced (ks->send_reliable);if (buf) { + ks->initial = now; ks->must_negotiate = now + session->opt->handshake_window; ks->auth_deferred_expire = now +auth_deferred_expire_window (session->opt);
src/openvpn/ssl_common.h +1 -0
@@ -175,6 +175,7 @@ struct key_statestruct key_state_ssl ks_ssl;/* contains SSL object and BIOs for the control channel */ +time_t initial;/* when we created this session */ time_t established;/* when our state went S_ACTIVE */ time_t must_negotiate;/* key negotiation times out if not finished before this time */ time_t must_die;/* this object is destroyed at this time */
Signature · 1 line
2.30.1
Re: [Openvpn-devel] [PATCH v3] Implement deferred auth for scripts
In reply to Arne SchwabeQuoted 7 lines · Arne Schwabe
This patch also refactors the if condition that checks the result of the authentication since that has become quite unreadable. It renames s1/s2 and extracts some parts of the condition into individual variables to make the condition better understandle
Patch V2: add refactoring of the if condition
Quoted 7 lines
Signed-off-by Arne Schwabe <[email protected]...>--- Changes.rst | 12 +++++ doc/man-sections/script-options.rst | 14 ++++- src/openvpn/ssl.c | 2 - src/openvpn/ssl_verify.c | 84 +++++++++++++++++++++-------- 4 files changed, 87 insertions(+), 25 deletions(-)
I've just looked at the code/diff this time. One good and one ugly.
The good one: The C code looks fine, and is good to go. ENABLE_DEF_AUTH is goe, which was my only complaint.
The ugly one: Documentation is still incorrect. From the diff:
+··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 +··seconds·and·the·second·line·the·EXTRA·as·documented·in·the +··``client-pending-auth``·section·of·doc/management.txt.
This does not match what the TOTP auth-pending demo code does:
+def·write_auth_pending(timeout,·method,·extra):
+····with·open(os.environ['auth_pending_file'],·'w')·as·auth_pending:
+········auth_pending.write("%d\n%s\n%s"·%·(timeout,·method,·extra))
The documentation does not mention the "method" part.
There are also a few nitpicks in the patch 11/11 which I did not see on the ML so far.
<https://www.mail-archive.com/[email protected]/msg21528.html>
Message-Id: <[email protected]...>
Signature · 4 lines
kind regards, David Sommerseth OpenVPN Inc
PATCH v3 1/1 Add example script demonstrating TOTP via auth-pending
In reply to Arne SchwabePatch v3: Some minor cleanups in the script (rename CNs, add more comments)
--- doc/man-sections/script-options.rst | 3 + sample/sample-scripts/totpauth.py | 111 ++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100755 sample/sample-scripts/totpauth.py
doc/man-sections/script-options.rst +3 -0
@@ -147,6 +147,9 @@ SCRIPT HOOKS :code:`auth_control_file or further defer it. See ``--auth-user-pass-verify`` for details. + For a sample script that implement TOTP (RFC 6238) based two-factor + authentication, see :code:`sample-scripts/totp.py`. + --client-connect cmd Run command ``cmd`` on client connection.
sample/sample-scripts/totpauth.py new file +111 -0
111 lines not on this page · raw message
Signature · 1 line
2.30.1
PATCH v4 1/1 Implement deferred auth for scripts
In reply to Arne SchwabeThis patch also refactors the if condition that checks the result of the authentication since that has become quite unreadable. It renames s1/s2 and extracts some parts of the condition into individual variables to make the condition better understandle
Patch v2: add refactoring of the if condition
Patch v4: fix documentation not mentioning method as 2nd line
--- Changes.rst | 12 +++++ doc/man-sections/script-options.rst | 14 ++++- src/openvpn/ssl.c | 2 - src/openvpn/ssl_verify.c | 84 +++++++++++++++++++++-------- 4 files changed, 87 insertions(+), 25 deletions(-)
Changes.rst +12 -0
@@ -15,6 +15,17 @@ Compatibility with OpenSSL in FIPS mode requirements/recommendation of FIPS 140-2. This just allows OpenVPN to be run on a system that be configured OpenSSL in FIPS mode. +Deferred auth support for scripts + The ``--auth-user-pass-verify`` script supports now deferred authentication. + +Pending auth support for plugins and scripts + Both auth plugin and script can now signal pending authentication to + the client when using deferred authentication. The new ``client-crresponse`` + script option and ``OPENVPN_PLUGIN_CLIENT_CRRESPONSE`` plugin function can + be used to parse a client response to a ``CR_TEXT`` two factor challenge. + + See ``sample/sample-scripts/totpauth.py`` for an example. + Deprecated features ------------------- ``inetd`` has been removed
@@ -22,6 +33,7 @@ Deprecated features and TAP mode only. + Overview of changes in 2.5 ==========================
doc/man-sections/script-options.rst +13 -1
@@ -90,7 +90,19 @@ SCRIPT HOOKS The script should examine the username and password, returning a success exit code (:code:`0`) if the client's authentication request is to be - accepted, or a failure code (:code:`1`) to reject the client. + accepted, a failure code (:code:`1`) to reject the client, or a that + the authentication is deferred (:code:`2`). If the authentication is + deferred, the script must fork/start a background or another non-blocking + operation to continue the authentication in the background. When finshing + the authentication, a :code:`1` or :code:`0` must be written to the + file specified by the :code:`auth_control_file`. + + 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 + seconds, the required method on the second line (e.g. crtext) and + third line must be the EXTRA as documented in the + ``client-pending-auth`` section of `doc/management.txt`. This directive is designed to enable a plugin-style interface for extending OpenVPN's authentication capabilities.
src/openvpn/ssl.c +0 -2
@@ -992,9 +992,7 @@ key_state_free(struct key_state *ks, bool clear)packet_id_free (&ks->crypto_options.packet_id); -#ifdef PLUGIN_DEF_AUTH key_state_rm_auth_control_files (ks); -#endif if (clear) {
src/openvpn/ssl_verify.c +62 -22
165 lines not on this page · raw message
Signature · 1 line
2.30.1
Re: [Openvpn-devel] [PATCH v4] Implement deferred auth for scripts
Changes.rst
Quoted 18 lines · Arne Schwabe
This patch also refactors the if condition that checks the result of the authentication since that has become quite unreadable. It renames s1/s2 and extracts some parts of the condition into individual variables to make the condition better understandle
Patch v2: add refactoring of the if condition
Patch v4: fix documentation not mentioning method as 2nd lineSigned-off-by Arne Schwabe <[email protected]...>--- Changes.rst | 12 +++++ doc/man-sections/script-options.rst | 14 ++++- src/openvpn/ssl.c | 2 - src/openvpn/ssl_verify.c | 84 +++++++++++++++++++++-------- 4 files changed, 87 insertions(+), 25 deletions(-)Changes.rst +0
-0
Signature · 4 lines
kind regards, David Sommerseth OpenVPN Inc
Re: [Openvpn-devel] [PATCH v3] Add example script demonstrating TOTP via auth-pending
In reply to Arne Schwabedoc/man-sections/script-options.rst
Quoted 13 lines · Arne Schwabe
Signed-off-by Arne Schwabe <[email protected]...>Patch v3: Some minor cleanups in the script (rename CNs, add more comments)
Signed-off-by Arne Schwabe <[email protected]...>--- doc/man-sections/script-options.rst | 3 + sample/sample-scripts/totpauth.py | 111 ++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+)create mode 100755
sample/sample-scripts/totpauth.pydoc/man-sections/script-options.rst +0
-0
Signature · 4 lines
kind regards, David Sommerseth OpenVPN Inc
Re: [Openvpn-devel] [PATCH v3] Implement server side of AUTH_PENDING with extending timeout
In reply to Arne Schwabeke 3. maalisk. 2021 klo 14.39 Arne Schwabe ([email protected]...) kirjoitti:
Quoted 308 lines
Patch V2: eliminate
parse_kidfunction, fix style Patch V3: adding missing parameter in function, this was added
by a later patch in the original seriesSigned-off-by Arne Schwabe <[email protected]...>--- src/openvpn/manage.c | 23 +++++++++-------- src/openvpn/manage.h | 3 ++- src/openvpn/multi.c | 27 +++----------------- src/openvpn/push.c | 55 +++++++++++++++++++++++++++++++++++++--- src/openvpn/push.h | 14 +++++++++- src/openvpn/ssl.c | 1 + src/openvpn/ssl_common.h | 1 + 7 files changed, 84 insertions(+), 40 deletions(-)src/openvpn/manage.c +13
-10@@ -975,15 +975,15 @@ parse_cid(const char *str, unsigned long *cid) }static bool -parse_kid (const char *str,unsigned int *kid) +parse_uint (const char *str,const char * what,unsigned int *uint) { -if (sscanf (str,"%u" , kid) ==1 ) +if (sscanf (str,"%u" , uint) ==1 ) {return true; }else { -msg (M_CLIENT ,"ERROR: cannot parse KID" ); +msg (M_CLIENT ,"ERROR: cannot parse %s" , what);return false; } }@@ -998,15 +998,18 @@ parse_kid(const char *str, unsigned int *kid)* the information of the additional steps */ static void -man_client_pending_auth (struct management *man,const char *cid_str,const char *extra) +man_client_pending_auth (struct management *man,const char *cid_str, +const char *extra,const char *timeout_str) {unsigned long cid =0 ; -if (parse_cid (cid_str, &cid)) +unsigned int timeout =0 ; +if (parse_cid (cid_str, &cid) + &&parse_uint (timeout_str,"TIMEOUT" , &timeout)) {if (man->persist.callback.client_pending_auth) {bool ret = (*man->persist.callback.client_pending_auth) - (man->persist.callback.arg, cid, extra); + (man->persist.callback.arg, cid, extra, timeout);if (ret) {@@ -1032,7 +1035,7 @@ man_client_auth(struct management *man, const char *cid_str, const char *kid_str mc->in_extra_cid =0 ; mc->in_extra_kid =0 ;if (parse_cid (cid_str, &mc->in_extra_cid) - &&parse_kid (kid_str, &mc->in_extra_kid)) + &&parse_uint (kid_str,"KID" , &mc->in_extra_kid)) { mc->in_extra_cmd =IEC_CLIENT_AUTH ;in_extra_reset (mc,IER_NEW );@@ -1048,7 +1051,7 @@ man_client_deny(struct management *man, const char *cid_str, const char *kid_str {unsigned long cid =0 ;unsigned int kid =0 ; -if (parse_cid (cid_str, &cid) &&parse_kid (kid_str, &kid)) +if (parse_cid (cid_str, &cid) &&parse_uint (kid_str,"KID" , &kid)) {if (man->persist.callback.client_auth) {@@ -1563,9 +1566,9 @@ man_dispatch_command(struct management *man, struct status_output *so, const cha }else if (streq (p[0 ],"client-pending-auth" )) { -if (man_need (man, p,2 ,0 )) +if (man_need (man, p,3 ,0 )) { -man_client_pending_auth (man, p[1 ], p[2 ]); +man_client_pending_auth (man, p[1 ], p[2 ], p[3 ]); } }#ifdef MANAGEMENT_PF src/openvpn/manage.h +2
-1@@ -173,7 +173,8 @@ struct management_callback struct buffer_list *cc_config); /* ownership transferred */bool (*client_pending_auth) (void *arg,const unsigned long cid, -const char *url); +const char *extra, +unsigned int timeout);char *(*get_peer_info) (void *arg,const unsigned long cid);#ifdef MANAGEMENT_PF bool (*client_pf)(void *arg,src/openvpn/multi.c +3
-24@@ -1768,28 +1768,6 @@ multi_client_connect_setenv(struct multi_context *m,gc_free (&gc); } -/** -* Extracts the IV_PROTO variable and returns its value or 0 -* if it cannot be extracted. -* -*/ -static unsigned int -extract_iv_proto (const char *peer_info) -{ - -const char *optstr = peer_info ?strstr (peer_info,"IV_PROTO=" ) :NULL ; -if (optstr) - { -int proto =0 ; -int r =sscanf (optstr,"IV_PROTO=%d" , &proto); -if (r ==1 && proto >0 ) - { -return proto; - } - } -return 0 ; -} -/** * Calculates the options that depend on the client capabilities * based on local options and available peer info @@ -3918,14 +3896,15 @@ management_kill_by_cid(void *arg, const unsigned long cid, const char *kill_msg)static bool management_client_pending_auth (void *arg,const unsigned long cid, -const char *extra) +const char *extra, +unsigned int timeout) {struct multi_context *m = (struct multi_context *) arg;struct multi_instance *mi =lookup_by_cid (m, cid);if (mi) {/* sends INFO_PRE and AUTH_PENDING messages to client */ -bool ret =send_auth_pending_messages (&mi->context, extra); +bool ret =send_auth_pending_messages (&mi->context, extra, timeout);multi_schedule_context_wakeup (m, mi);return ret; }src/openvpn/push.c +51
-4@@ -361,26 +361,57 @@ send_auth_failed(struct context *c, const char *client_reason)gc_free (&gc); } +bool -send_auth_pending_messages (struct context *c,const char *extra) +send_auth_pending_messages (struct context *c,const char *extra, +unsigned int timeout) { -send_control_channel_string (c,"AUTH_PENDING" ,D_PUSH ); +struct tls_multi *tls_multi = c->c2.tls_multi; +struct key_state *ks = &tls_multi->session[TM_ACTIVE ].key[KS_PRIMARY ];static const char info_pre[] ="INFO_PRE," ; +const char *const peer_info = tls_multi->peer_info; +unsigned int proto =extract_iv_proto (peer_info); + -size_t len =strlen (extra)+1 +sizeof (info_pre); +/* Calculate the maximum timeout and subtract the time we already waited */ +unsigned int max_timeout =max_uint (tls_multi->opt.renegotiate_seconds/2 , + tls_multi->opt.handshake_window); + max_timeout = max_timeout - (now - ks->initial); + timeout =min_uint (max_timeout, timeout); + +struct gc_arena gc =gc_new (); +if ((proto &IV_PROTO_AUTH_PENDING_KW ) ==0 ) + { +send_control_channel_string (c,"AUTH_PENDING" ,D_PUSH ); + } +else + { +static const char auth_pre[] ="AUTH_PENDING,timeout " ; +// Assume a worst case of 8 byte uint64 in decimal which +// needs 20 bytes +size_t len =20 +1 +sizeof (auth_pre); +struct buffer buf =alloc_buf_gc (len, &gc); +buf_printf (&buf, auth_pre); +buf_printf (&buf,"%u" , timeout); +send_control_channel_string (c,BSTR (&buf),D_PUSH ); + } + +size_t len =strlen (extra) +1 +sizeof (info_pre);if (len >PUSH_BUNDLE_SIZE ) { +gc_free (&gc);return false; } -struct gc_arena gc =gc_new ();struct buffer buf =alloc_buf_gc (len, &gc);buf_printf (&buf, info_pre);buf_printf (&buf,"%s" , extra);send_control_channel_string (c,BSTR (&buf),D_PUSH ); + ks->auth_deferred_expire = now + timeout; +gc_free (&gc);return true; }@@ -1028,4 +1059,20 @@ remove_iroutes_from_push_route_list(struct options *o) } } +unsigned int +extract_iv_proto (const char *peer_info) +{ +const char *optstr = peer_info ?strstr (peer_info,"IV_PROTO=" ) :NULL ; +if (optstr) + { +int proto =0 ; +int r =sscanf (optstr,"IV_PROTO=%d" , &proto); +if (r ==1 && proto >0 ) + { +return proto; + } + } +return 0 ; +} +#endif /* if P2MP */ src/openvpn/push.h +13
-1@@ -77,7 +77,9 @@ void send_auth_failed(struct context *c, const char *client_reason);* doc/management-notes.txt under client-pending-auth for * more details on message format */ -bool send_auth_pending_messages (struct context *c,const char *extra); +bool +send_auth_pending_messages (struct context *c,const char *extra, +unsigned int timeout);void send_restart (struct context *c,const char *kill_msg);@@ -89,6 +91,16 @@ void send_restart(struct context *c, const char *kill_msg);*/ void send_push_reply_auth_token (struct tls_multi *multi); + +/** +* Extracts the IV_PROTO variable and returns its value or 0 +* if it cannot be extracted. +* +* @param peer_info peer info string to search for IV_PROTO +*/ +unsigned int +extract_iv_proto (const char *peer_info); +/** * Parses an AUTH_PENDING message and if in pull mode extends the timeout * src/openvpn/ssl.c +1
-0@@ -2659,6 +2659,7 @@ tls_process(struct tls_multi *multi, buf =reliable_get_buf_output_sequenced (ks->send_reliable);if (buf) { + ks->initial = now; ks->must_negotiate = now + session->opt->handshake_window; ks->auth_deferred_expire = now +auth_deferred_expire_window (session->opt);src/openvpn/ssl_common.h +1
-1@@ -175,6 +175,7 @@ struct key_statestruct key_state_ssl ks_ssl;/* contains SSL object and BIOs for the control channel */ +time_t initial;/* when we created this session */ time_t established;/* when our state went S_ACTIVE */ time_t must_negotiate;/* key negotiation times out if not finished before this time */ time_t must_die;/* this object is destroyed at this time */ --2.30.1
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Signature · 1 line
-Lev
[Openvpn-devel] [PATCH applied] Re: Implement server side of AUTH_PENDING with extending timeout
In reply to Arne SchwabeI won't claim to understand what this stuff is doing in the grand scheme of things (as far as I can see, all it does is "it introduces a timeout variable all over the place, which then gets sent to the client") but the changes look safe enough :-)
I have subjected this to client-side and server side torturing - which, admittedly, does not excercise the mangement interface at all, and does not have a test for "delayed auth" either. So it's not testing the new code at all, just "nothing else breaks". And this, I can confirm (mbedTLS 2.25 client crashes :-) ).
Your patch has been applied to the master branch.
commit 53229047a259b2edb9034802a33fe27636675ff9
Author: Arne Schwabe Date: Wed Mar 3 13:38:18 2021 +0100
Implement server side of AUTH_PENDING with extending timeout
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Lev Stipakov <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg21596.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH v3] Change parameter of send_auth_pending_messages from context to tls_multi
In reply to Arne SchwabeHi,
Quoted 7 lines · Arne Schwabe
This prepares
send_auth_pending_messagesto be used a in context that does not have context c available but also does not need to schedule an immediate sending of the message (auth plugin/script)Patch V2: Adjust the comment of
reschedule_multi_processto actually fit a
function.
Patch V3: Rebase needed because v3 of 3/11
The change itself is good, and basically just moving around things a bit (different calling convention, so no more "c" available, thus calling "send_control_channel_string_dowork()" instead of the other function, *thus* needing to call interval_action() in the caller, which is easier if folded into reschedule_multi_process(). So, ACK on the intention.
Alas, the v3 patch does not compile :-( - so "Changes Requested".
../../../openvpn/src/openvpn/push.c:366:1: error: conflicting types for 'send_auth_pending_messages'
366 | send_auth_pending_messages(struct tls_multi *tls_multi, const char *extra,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../../../openvpn/src/openvpn/push.c:32:
../../../openvpn/src/openvpn/push.h:81:1: note: previous declaration of 'send_auth_pending_messages' was here
81 | send_auth_pending_messages(struct context *c, const char *extra,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~changing of the prototype in push.h is missing.
That said, the patch also introduces two extra blank lines, which I would have fixed on-the fly - but if you re-send anyway with push.h fixed, please fix that, too :-)
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...[Openvpn-devel] [PATCH applied] Re: Refactor extract_var_peer_info into standalone function and add ssl_util.c
In reply to Arne SchwabeThanks for taking my suggestions to v2 into account (though the ssl.c newline-at-end-of-file mishap is still there in v3 :-) - ignoring that hunk).
Stared-at-code, while this looks very different, it's still doing the same things (and in the same funny way, using strstr() to search for a single character...). Tested client-side and server side, does not break anything.
Adding my ACK on v3 to Lev's ACK on v2 - multiack!
Your patch has been applied to the master branch.
commit 88664aba69a8aab0e600200c445024fbaf7bab80
Author: Arne Schwabe Date: Fri Feb 26 12:10:12 2021 +0100
Refactor extract_var_peer_info into standalone function and add ssl_util.c
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Lev Stipakov <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg21585.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v4 1/1 Change parameter of send_auth_pending_messages from context to tls_multi
In reply to Arne SchwabeThis prepares send_auth_pending_messages to be used a in context that does not have context c available but also does not need to schedule an immediate sending of the message (auth plugin/script)
Patch V2: Adjust the comment of reschedule_multi_process to actually fit a
function.
Patch V3: Rebase needed because v3 of 3/11
Patch V4: Send with push.h prototype
--- src/openvpn/forward.c | 17 +++++++++-------- src/openvpn/forward.h | 9 +++++++++ src/openvpn/multi.c | 4 +++- src/openvpn/push.c | 9 ++++----- src/openvpn/push.h | 2 +- 5 files changed, 26 insertions(+), 15 deletions(-)
src/openvpn/forward.c +9 -8
@@ -342,6 +342,14 @@ send_control_channel_string_dowork(struct tls_multi *multi,return stat; } +void reschedule_multi_process (struct context *c) +{ + +interval_action (&c->c2.tmp_int); +context_immediate_reschedule (c);/* ZERO-TIMEOUT */ +} + +bool send_control_channel_string (struct context *c,const char *str,int msglevel) {
@@ -349,15 +357,8 @@ send_control_channel_string(struct context *c, const char *str, int msglevel) {bool ret =send_control_channel_string_dowork (c->c2.tls_multi, str, msglevel); -/* -* Reschedule tls_multi_process. -* NOTE: in multi-client mode, usually the below two statements are -* insufficient to reschedule the client instance object unless -* multi_schedule_context_wakeup(m, mi) is also called. -*/ +reschedule_multi_process (c); -interval_action (&c->c2.tmp_int); -context_immediate_reschedule (c);/* ZERO-TIMEOUT */ return ret; }return true;
src/openvpn/forward.h +9 -0
@@ -317,6 +317,15 @@ bool send_control_channel_string_dowork(struct tls_multi *multi, const char *str, int msglevel); + +/** +* Reschedule tls_multi_process. +* NOTE: in multi-client mode, usually calling the function is +* insufficient to reschedule the client instance object unless +* multi_schedule_context_wakeup(m, mi) is also called. +*/ +void reschedule_multi_process (struct context *c); +#define PIPV4_PASSTOS (1<<0)#define PIP_MSSFIX (1<<1)/* v4 and v6 */ #define PIP_OUTGOING (1<<2)
src/openvpn/multi.c +3 -1
@@ -3904,7 +3904,9 @@ management_client_pending_auth(void *arg,if (mi) {/* sends INFO_PRE and AUTH_PENDING messages to client */ -bool ret =send_auth_pending_messages (&mi->context, extra, timeout); +bool ret =send_auth_pending_messages (mi->context.c2.tls_multi, extra, + timeout); +reschedule_multi_process (&mi->context);multi_schedule_context_wakeup (m, mi);return ret; }
src/openvpn/push.c +4 -5
@@ -363,10 +363,9 @@ send_auth_failed(struct context *c, const char *client_reason)bool -send_auth_pending_messages (struct context *c,const char *extra, +send_auth_pending_messages (struct tls_multi *tls_multi,const char *extra,unsigned int timeout) { -struct tls_multi *tls_multi = c->c2.tls_multi;struct key_state *ks = &tls_multi->session[TM_ACTIVE ].key[KS_PRIMARY ];static const char info_pre[] ="INFO_PRE," ;
@@ -384,7 +383,7 @@ send_auth_pending_messages(struct context *c, const char *extra,struct gc_arena gc =gc_new ();if ((proto &IV_PROTO_AUTH_PENDING_KW ) ==0 ) { -send_control_channel_string (c,"AUTH_PENDING" ,D_PUSH ); +send_control_channel_string_dowork (tls_multi,"AUTH_PENDING" ,D_PUSH ); }else {
@@ -395,7 +394,7 @@ send_auth_pending_messages(struct context *c, const char *extra,struct buffer buf =alloc_buf_gc (len, &gc);buf_printf (&buf, auth_pre);buf_printf (&buf,"%u" , timeout); -send_control_channel_string (c,BSTR (&buf),D_PUSH ); +send_control_channel_string_dowork (tls_multi,BSTR (&buf),D_PUSH ); }size_t len =strlen (extra) +1 +sizeof (info_pre);
@@ -408,7 +407,7 @@ send_auth_pending_messages(struct context *c, const char *extra,struct buffer buf =alloc_buf_gc (len, &gc);buf_printf (&buf, info_pre);buf_printf (&buf,"%s" , extra); -send_control_channel_string (c,BSTR (&buf),D_PUSH ); +send_control_channel_string_dowork (tls_multi,BSTR (&buf),D_PUSH ); ks->auth_deferred_expire = now + timeout;
src/openvpn/push.h +1 -1
@@ -78,7 +78,7 @@ void send_auth_failed(struct context *c, const char *client_reason);* more details on message format */ bool -send_auth_pending_messages (struct context *c,const char *extra, +send_auth_pending_messages (struct tls_multi *tls_multi,const char *extra,unsigned int timeout);void send_restart (struct context *c,const char *kill_msg);
Signature · 1 line
2.30.1
[Openvpn-devel] [PATCH applied] Re: Change parameter of send_auth_pending_messages from context to tls_multi
Reviewed (did that for v3), only change in v4 is the push.h prototype fix. Taking Lev's ACK from v1 or v2 in as well.
Stared-at-code, tested client-and-server, all good!
Your patch has been applied to the master branch.
commit d8ed59320e619eb5c9e5ba2acbac1a4fecae36b1
Author: Arne Schwabe Date: Wed Mar 10 11:28:23 2021 +0100
Change parameter of send_auth_pending_messages from context to tls_multi
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Lev Stipakov <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/search?l=mid&[email protected]...
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [PATCH applied] Re: Allow pending auth to be send from a auth plugin
In reply to Arne SchwabeStared at the code a bit, tortured it on the server test rig (which excercises delayed-auth plugin and delayed-client-connect-*anything*, so breaking something plugin-related "big time" should have been caught). I have not tested the delayed-auth plugin feature yet.
A few observations, staring at key_state_check_auth_pending_file():
- it would benefit from early-return... 3 levels deep for most of the function...
- if "timeout" cannot be parsed, the function does an early-return, but does not call "key_state_rm_auth_pending_file(ks);" - this looks somewhat intentional ("we keep trying until we can parse the timeout value")...?
- "char* pending_method = BSTR(iv_buf);" is a bit confusingly named - especially as "iv_buf" is not continaing the client-side IV_SSO value set, but the plugin-requested method. So maybe iv_buf could be renamed to "pending_method_buf" or so?
These are all not reasons to reject the patch, but if you feel like "ah, today is openvpn source cleanup day", this would be a candidate :-)
I have taken the liberty to fix the comment in verify_user_pass_plugin().
Your patch has been applied to the master branch.
commit fdb4f27685f38621b72467e3038c2116f0e809c4
Author: Arne Schwabe Date: Mon Jan 25 13:56:25 2021 +0100
Allow pending auth to be send from a auth plugin
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: David Sommerseth <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg21489.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH v4] Implement deferred auth for scripts
In reply to Arne SchwabeHi,
Quoted 7 lines · Arne Schwabe
This patch also refactors the if condition that checks the result of the authentication since that has become quite unreadable. It renames s1/s2 and extracts some parts of the condition into individual variables to make the condition better understandle
Patch v2: add refactoring of the if condition
Patch v4: fix documentation not mentioning method as 2nd line
Not sure yet what is happening, but this breaks deferred auth in plugins
- as in "they always succeed".
I have some test cases using plugin-auth-pam which delays for about 15 seconds (querying a nonexisting radius server) and then checks a local auth+password file. One of the cases should succeed "but be delayed", one of the cases must fail "but delayed fail", because I send a username that does not exists.
With this patch applied, authentication *succeeds* very fast in both cases, even with wrong password.
The log file with this patch has:
2021-03-10 16:40:43 us=610286 2001:608:0:814::f000:21 VERIFY OK: depth=0, C=DE, ST=Bavaria, L=Munich, O=OpenVPN community project, OU=Server Testing, CN=cron2-freebsd-tc-amd64, [email protected]... 2021-03-10 16:40:43 us=612104 PLUGIN AUTH-PAM: do deferred auth '/tmp/openvpn_acf_2f305c6e47c6552f3e29e210b1c0baf.tmp' 2021-03-10 16:40:43 us=612428 PLUGIN AUTH-PAM: deferred authentication 2021-03-10 16:40:43 us=612823 PLUGIN AUTH-PAM: BACKGROUND: deferred auth for 'fbsd-tc-masterFoo', pid=21053 2021-03-10 16:40:43 us=612951 PLUGIN AUTH-PAM: cannot open '/tmp/openvpn_acf_2f305c6e47c6552f3e29e210b1c0baf.tmp' for writing: No such file or directory (errno=2) 2021-03-10 16:40:43 us=617812 2001:608:0:814::f000:21 TLS: Username/Password authentication deferred for username 'fbsd-tc-masterFoo' 2021-03-10 16:40:43 us=618636 2001:608:0:814::f000:21 Control Channel: TLSv1.3, cipher TLSv1.3 TLS_AES_256_GCM_SHA384, 2048 bit RSA 2021-03-10 16:40:43 us=618674 2001:608:0:814::f000:21 [cron2-freebsd-tc-amd64] Peer Connection Initiated with [AF_INET6]2001:608:0:814::f000:21:40868 2021-03-10 16:40:43 us=618705 cron2-freebsd-tc-amd64/2001:608:0:814::f000:21 MULTI_sva: pool returned IPv4=194.97.145.74, IPv6=2001:608:3:814::1000 2021-03-10 16:40:43 us=625942 cron2-freebsd-tc-amd64/2001:608:0:814::f000:21 OPTIONS IMPORT: reading client specific options from: /tmp/openvpn_cc_1cdbffdecac750624e0d4deb89a7ad1d.tmp ... 2021-03-10 16:40:43 us=626454 cron2-freebsd-tc-amd64/2001:608:0:814::f000:21 SENT CONTROL [cron2-freebsd-tc-amd64]: 'PUSH_REPLY,route 10.204.0.0 255.255.0.0,route-ipv6 fd00:abcd:204::/48,tun-ipv6,route-gateway 194.97.145.73,topology subnet,ping 10,ping-restart 30,compress lz4,ifconfig-ipv6 2001:608:3:814::1000/64 2001:608:3:814::1,ifconfig 194.97.145.74 255.255.255.248,peer-id 0,auth-tokenSESS_ID,cipher AES-256-GCM,key-derivation tls-ekm' (status=1)
Actually, there is a script involved as well - the server config has
# ASYNC (20s delay ueber pam_radius)
setenv deferred_auth_pam 1
plugin /.../openvpn-plugin-auth-pam.so "openvpn-global Login: USERNAME Password: PASSWORD"
# nebenbei auch noch das shell-interface validieren script-security 3 auth-user-pass-verify /.../auth-user-pass-verify.sh via-env
if I remove the call to "auth-user-pass-verify", the plugin failure is correctly detected and signalled again. It also waits proper 15 seconds again...
2021-03-10 16:44:31 us=527310 PLUGIN AUTH-PAM: BACKGROUND: deferred auth for 'fbsd-tc-masterFoo', pid=21861 2021-03-10 16:44:46 us=546819 PLUGIN AUTH-PAM: BACKGROUND: user 'fbsd-tc-masterFoo' failed to authenticate: User not known to the underlying authentication module 2021-03-10 16:44:47 us=992782 2001:608:0:814::f000:21 SENT CONTROL [cron2-freebsd-tc-amd64]: 'AUTH_FAILED' (status=1)
... and no error messages about the auth_control_file missing.
So, it seems the cleanup of this nasty bit of logic has actually broken it :-( (or introduced new and interesting corner cases)
I'll see if I can find sufficient brains to dig into this and see what is happening.
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...PATCH v5 1/2 Move auth deferred related members into its own struct
This structures the code a bit nicer and also prepares for deferred scripts that needs their own set of files.
--- src/openvpn/ssl.c | 4 +-- src/openvpn/ssl_common.h | 12 ++++++-- src/openvpn/ssl_verify.c | 63 ++++++++++++++++++++-------------------- src/openvpn/ssl_verify.h | 7 +++-- 4 files changed, 46 insertions(+), 40 deletions(-)
src/openvpn/ssl.c +1 -3
@@ -992,9 +992,7 @@ key_state_free(struct key_state *ks, bool clear)packet_id_free (&ks->crypto_options.packet_id); -#ifdef PLUGIN_DEF_AUTH -key_state_rm_auth_control_files (ks); -#endif +key_state_rm_auth_control_files (&ks->plugin_auth);if (clear) {
src/openvpn/ssl_common.h +9 -3
@@ -145,6 +145,13 @@ enum ks_auth_state {*/ }; +struct auth_deferred_status +{ +char *auth_control_file; +char *auth_pending_file; +unsigned int auth_control_status; +}; +/** * Security parameter state of one TLS and data channel %key session. * @ingroup control_processor
@@ -212,10 +219,9 @@ struct key_stateunsigned int mda_key_id;unsigned int mda_status;#endif -unsigned int auth_control_status;time_t acf_last_mod; -char *auth_control_file; -char *auth_pending_file; + +struct auth_deferred_status plugin_auth; };/** Control channel wrapping (--tls-auth/--tls-crypt) context */
src/openvpn/ssl_verify.c +32 -31
151 lines not on this page · raw message
src/openvpn/ssl_verify.h +4 -3
@@ -113,11 +113,12 @@ tls_authentication_status(struct tls_multi *multi, const int latency);#define TLS_AUTHENTICATED (multi, ks) ((ks)->state >= (S_GOT_KEY - (multi)->opt.server))/** -* Remove the given key state's auth control file, if it exists. +* Remove the given key state's auth deferred status auth control file, +* if it exists. * -* @param ks The key state the remove the file for +* @param ads The key state the remove the file for */ -void key_state_rm_auth_control_files (struct key_state *ks); +void key_state_rm_auth_control_files (struct auth_deferred_status *ads);/** * Frees the given set of certificate hashes.
Signature · 1 line
2.30.1
PATCH v5 2/2 Implement deferred auth for scripts
This patch also refactors the if condition that checks the result of the authentication since that has become quite unreadable. It renames s1/s2 and extracts some parts of the condition into individual variables to make the condition better understandle
Patch v2: add refactoring of the if condition
Patch v4: fix documentation not mentioning method as 2nd line Patch v5: fix deferred auth used by both plugin and script not working
--- Changes.rst | 11 +++ doc/man-sections/script-options.rst | 14 +++- src/openvpn/ssl.c | 1 + src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_verify.c | 105 ++++++++++++++++++++-------- 5 files changed, 101 insertions(+), 31 deletions(-)
Changes.rst +11 -0
@@ -19,6 +19,16 @@ Compatibility with OpenSSL in FIPS mode and if less than 100MB RAM are available, use setrlimit() to upgrade the limit. See Trac #1390. Not available on OpenSolaris. +Deferred auth support for scripts + The ``--auth-user-pass-verify`` script supports now deferred authentication. + +Pending auth support for plugins and scripts + Both auth plugin and script can now signal pending authentication to + the client when using deferred authentication. The new ``client-crresponse`` + script option and ``OPENVPN_PLUGIN_CLIENT_CRRESPONSE`` plugin function can + be used to parse a client response to a ``CR_TEXT`` two factor challenge. + + See ``sample/sample-scripts/totpauth.py`` for an example. Deprecated features -------------------
@@ -27,6 +37,7 @@ Deprecated features and TAP mode only. + Overview of changes in 2.5 ==========================
doc/man-sections/script-options.rst +13 -1
@@ -90,7 +90,19 @@ SCRIPT HOOKS The script should examine the username and password, returning a success exit code (:code:`0`) if the client's authentication request is to be - accepted, or a failure code (:code:`1`) to reject the client. + accepted, a failure code (:code:`1`) to reject the client, or a that + the authentication is deferred (:code:`2`). If the authentication is + deferred, the script must fork/start a background or another non-blocking + operation to continue the authentication in the background. When finshing + the authentication, a :code:`1` or :code:`0` must be written to the + file specified by the :code:`auth_control_file`. + + 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 + seconds, the required method on the second line (e.g. crtext) and + third line must be the EXTRA as documented in the + ``client-pending-auth`` section of `doc/management.txt`. This directive is designed to enable a plugin-style interface for extending OpenVPN's authentication capabilities.
src/openvpn/ssl.c +1 -0
@@ -993,6 +993,7 @@ key_state_free(struct key_state *ks, bool clear)packet_id_free (&ks->crypto_options.packet_id);key_state_rm_auth_control_files (&ks->plugin_auth); +key_state_rm_auth_control_files (&ks->script_auth);if (clear) {
src/openvpn/ssl_common.h +1 -0
@@ -222,6 +222,7 @@ struct key_statetime_t acf_last_mod;struct auth_deferred_status plugin_auth; +struct auth_deferred_status script_auth; };/** Control channel wrapping (--tls-auth/--tls-crypt) context */
src/openvpn/ssl_verify.c +75 -30
205 lines not on this page · raw message
Signature · 1 line
2.30.1
Re: [Openvpn-devel] [PATCH v5 1/2] Move auth deferred related members into its own struct
In reply to Arne SchwabeHi,
Quoted 4 lines · Arne Schwabe
This structures the code a bit nicer and also prepares for deferred scripts that needs their own set of files.
Signed-off-by Arne Schwabe <[email protected]...>
For me this is an ACK, but unfortunately I have no test rig for deferred auth and therefore I cannot really test these code paths.
This said, after staring at the code, I can confirm this is just a restyling of some struct members and nothing else.
A basic client-server test passes as expected.
Regards,
Signature · 1 line
Antonio Quartulli
[Openvpn-devel] [PATCH applied] Re: Move auth deferred related members into its own struct
In reply to Arne SchwabeAs Antonio has already stated, this really only moves 3 structure elements into their own substructure, and all functions working on these elements are now passed a pointer to the substructure (so the next patch can then use two substructures to have individual files for "plugin" and "script" deferred auth).
I'm slightly worried about the "setenv" bits (using the same name in all cases) but if the flow of events is linear enough ("create files, start plugin, create other sets of files, start script") this should not be a problem.
I have fixed the conflict caused by commit 997b006a26 on the fly (trivial).
Tested on the server test rig that found the "now auth fails" problem with the v4 patch. All green so far :-)
Your patch has been applied to the master branch.
commit c5fec838e749e4a1806a42c1f593f195c2d60b3b
Author: Arne Schwabe Date: Wed Mar 17 14:03:11 2021 +0100
Move auth deferred related members into its own struct
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg21671.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH v5 2/2] Implement deferred auth for scripts
In reply to Arne SchwabeHi,
Quoted 10 lines · Arne Schwabe
This patch also refactors the if condition that checks the result of the authentication since that has become quite unreadable. It renames s1/s2 and extracts some parts of the condition into individual variables to make the condition better understandle
Patch v2: add refactoring of the if condition
Patch v4: fix documentation not mentioning method as 2nd line Patch v5: fix deferred auth used by both plugin and script not workingSigned-off-by Arne Schwabe <[email protected]...>
Looking at the --enable-async-push fix-patch, it seems that this one also needs to add an inotify watch for ks->script_auth.auth_control_file, no?
Haven't tested the rest yet. First glance looks good, but without "dual-inotify" this looks incomplete.
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...Re: [Openvpn-devel] [PATCH v2 10/11] Implement --client-crresponse script options and plugin interface
In reply to Arne SchwabeHi,
Quoted 4 lines · Arne Schwabe
This is allows scripts and pluginsto parse/react to a
CR_RESPONSEmessagePatch V2: doc fixes, do not put script under
ENABLE_PLUGIN
This one was left out to try for too long (sorry), and is no more applying in a fairly big way...
error: patch failed: include/openvpn-plugin.h.in:84
error: include/openvpn-plugin.h.in: patch does not apply
error: patch failed: src/openvpn/init.c:2948
error: src/openvpn/init.c: patch does not apply
error: patch failed: src/openvpn/options.c:1284
error: src/openvpn/options.c: patch does not apply
error: patch failed: src/openvpn/options.h:440
error: src/openvpn/options.h: patch does not apply
error: patch failed: src/openvpn/push.c:228
error: src/openvpn/push.c: patch does not apply
error: patch failed: src/openvpn/ssl_common.h:316
error: src/openvpn/ssl_common.h: patch does not apply
error: patch failed: src/openvpn/ssl_verify.c:1232
error: src/openvpn/ssl_verify.c: patch does not apply
error: patch failed: src/openvpn/ssl_verify.h:209
error: src/openvpn/ssl_verify.h: patch does not apply
I assume you have a rebased version in your tree... can you resend this one, please?
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...PATCH v3 1/1 Implement --client-crresponse script options and plugin interface
In reply to Arne SchwabeThis is allows scripts and pluginsto parse/react to a CR_RESPONSE message
Patch V2: doc fixes, do not put script under ENABLE_PLUGIN Patch V3: rebase
--- doc/man-sections/script-options.rst | 28 ++++++++++++- include/openvpn-plugin.h.in | 7 +++- src/openvpn/init.c | 1 + src/openvpn/options.c | 15 +++++++ src/openvpn/options.h | 1 + src/openvpn/plugin.c | 5 ++- src/openvpn/push.c | 4 ++ src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_verify.c | 65 +++++++++++++++++++++++++++++ src/openvpn/ssl_verify.h | 23 ++++++++++ 10 files changed, 146 insertions(+), 4 deletions(-)
doc/man-sections/script-options.rst +26 -2
@@ -52,6 +52,11 @@ Script Order of Execution Executed in ``--mode server`` mode on new client connections, when the client is still untrusted. +#. ``--client-crresponse`` + + Execute in ``--mode server`` whenever a client sends a + :code:`CR_RESPONSE` message + SCRIPT HOOKS ------------
@@ -72,7 +77,7 @@ SCRIPT HOOKS double-quoted and/or escaped using a backslash, and should be separated by one or more spaces. - If ``method`` is set to :code:`via-env`, OpenVPN will call ``script`` + If ``method`` is set to :code:`via-env`, OpenVPN will call ``cmd`` with the environmental variables :code:`username` and :code:`password` set to the username/password strings provided by the client. *Beware* that this method is insecure on some platforms which make the environment
@@ -80,7 +85,7 @@ SCRIPT HOOKS If ``method`` is set to :code:`via-file`, OpenVPN will write the username and password to the first two lines of a temporary file. The filename - will be passed as an argument to ``script``, and the file will be + will be passed as an argument to ``cmd``, and the file will be automatically deleted by OpenVPN after the script returns. The location of the temporary file is controlled by the ``--tmp-dir`` option, and will default to the current directory if unspecified. For security,
@@ -123,6 +128,25 @@ SCRIPT HOOKS For a sample script that performs PAM authentication, see :code:`sample-scripts/auth-pam.pl` in the OpenVPN source distribution. +--client-crresponse + Executed when the client sends a text based challenge response. + + Valid syntax: + :: + + client-crresponse cmd + + OpenVPN will write the response of the client into a temporary file. + The filename will be passed as an argument to ``cmd``, and the file will be + automatically deleted by OpenVPN after the script returns. + + The response is passed as is from the client. The script needs to check + itself if the input is valid, e.g. if the input is valid base64 encoding. + + The script can either directly write the result of the verification to + :code:`auth_control_file or further defer it. See ``--auth-user-pass-verify`` + for details. + --client-connect cmd Run command ``cmd`` on client connection.
include/openvpn-plugin.h.in +6 -1
@@ -84,6 +84,10 @@ extern "C" { * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_CLIENT_CONNECT_V2 * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_LEARN_ADDRESS * + * The OPENVPN_PLUGIN_CLIENT_CRRESPONSE function is called when the client sends + * the CR_RESPONSE message, this is *typically* after OPENVPN_PLUGIN_TLS_FINAL + * but may also occur much later. + * * [Client session ensues] * * For each "TLS soft reset", according to reneg-sec option (or similar):
@@ -131,7 +135,8 @@ extern "C" { #define OPENVPN_PLUGIN_ROUTE_PREDOWN 12 #define OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER 13 #define OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2 14 -#define OPENVPN_PLUGIN_N 15 +#define OPENVPN_PLUGIN_CLIENT_CRRESPONSE 15 +#define OPENVPN_PLUGIN_N 16 /* * Build a mask out of a set of plug-in types.
src/openvpn/init.c +1 -0
@@ -2916,6 +2916,7 @@ do_init_crypto_tls(struct context *c, const unsigned int flags) to.auth_user_pass_verify_script = options->auth_user_pass_verify_script; to.auth_user_pass_verify_script_via_file = options->auth_user_pass_verify_script_via_file; + to.client_crresponse_script = options->client_crresponse_script; to.tmp_dir = options->tmp_dir;if (options->ccd_exclusive) {
src/openvpn/options.c +15 -0
@@ -1327,6 +1327,7 @@ show_p2mp_parms(const struct options *o)SHOW_STR (client_connect_script);SHOW_STR (learn_address_script);SHOW_STR (client_disconnect_script); +SHOW_STR (client_crresponse_script);SHOW_STR (client_config_dir);SHOW_BOOL (ccd_exclusive);SHOW_STR (tmp_dir);
@@ -2470,6 +2471,10 @@ options_postprocess_verify_ce(const struct options *options, {msg (M_USAGE ,"--client-connect requires --mode server" ); } +if (options->client_crresponse_script) + { +msg (M_USAGE ,"--client-crresponse requires --mode server" ); + }if (options->client_disconnect_script) {msg (M_USAGE ,"--client-disconnect requires --mode server" );
@@ -7082,6 +7087,16 @@ add_option(struct options *options,set_user_script (options, &options->client_connect_script, p[1 ],"client-connect" , true); } +else if (streq (p[0 ],"client-crresponse" ) && p[1 ]) + { +VERIFY_PERMISSION (OPT_P_SCRIPT ); +if (!no_more_than_n_args (msglevel, p,2 ,NM_QUOTE_HINT )) + { + goto err; + } +set_user_script (options, &options->client_crresponse_script, + p[1 ],"client-crresponse" , true); + }else if (streq (p[0 ],"client-disconnect" ) && p[1 ]) {VERIFY_PERMISSION (OPT_P_SCRIPT );
src/openvpn/options.h +1 -0
@@ -449,6 +449,7 @@ struct optionsconst char *client_connect_script;const char *client_disconnect_script;const char *learn_address_script; +const char *client_crresponse_script;const char *client_config_dir;bool ccd_exclusive;bool disable;
src/openvpn/plugin.c +4 -1
@@ -102,7 +102,7 @@ plugin_type_name(const int type)return "PLUGIN_CLIENT_CONNECT" ;case OPENVPN_PLUGIN_CLIENT_CONNECT_V2 : -return "PLUGIN_CLIENT_CONNECT" ; +return "PLUGIN_CLIENT_CONNECT_V2" ;case OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER :return "PLUGIN_CLIENT_CONNECT_DEFER" ;
@@ -125,6 +125,9 @@ plugin_type_name(const int type)case OPENVPN_PLUGIN_ROUTE_PREDOWN :return "PLUGIN_ROUTE_PREDOWN" ; +case OPENVPN_PLUGIN_CLIENT_CRRESPONSE : +return "PLUGIN_CRRESPONSE" ; +default :return "PLUGIN_???" ; }
src/openvpn/push.c +4 -0
@@ -227,6 +227,10 @@ receive_cr_response(struct context *c, const struct buffer *buffer)management_notify_client_cr_response (key_id, mda, es, m);#endif +#if ENABLE_PLUGIN +verify_crresponse_plugin (c->c2.tls_multi, m); +#endif +verify_crresponse_script (c->c2.tls_multi, m);msg (D_PUSH ,"CR response was sent by client ('%s')" , m); }
src/openvpn/ssl_common.h +1 -0
@@ -330,6 +330,7 @@ struct tls_options/* used for username/password authentication */ const char *auth_user_pass_verify_script; +const char *client_crresponse_script;bool auth_user_pass_verify_script_via_file;const char *tmp_dir;const char *auth_user_pass_file;
src/openvpn/ssl_verify.c +65 -0
71 lines not on this page · raw message
src/openvpn/ssl_verify.h +23 -0
@@ -206,6 +206,29 @@ tls_common_name_hash(const struct tls_multi *multi, const char **cn, uint32_t *cvoid verify_user_pass (struct user_pass *up,struct tls_multi *multi,struct tls_session *session); + + +/** +* Runs the --client-crresponse script if one is defined. +* +* As with the management interface the script is stateless in the sense that +* it does not directly participate in the authentication but rather should set +* the files for the deferred auth like the management commands. +* +*/ +void +verify_crresponse_script (struct tls_multi *multi,const char *cr_response); + +/** +* Call the plugin OPENVPN_PLUGIN_CLIENT_CRRESPONSE. +* +* As with the management interface calling the plugin is stateless in the sense +* that it does not directly participate in the authentication but rather +* should set the files for the deferred auth like the management commands. +*/ +void +verify_crresponse_plugin (struct tls_multi *multi,const char *cr_response); +/** * Perform final authentication checks, including locking of the cn, the allowed * certificate hashes, and whether a client config entry exists in the
Signature · 1 line
2.31.1
Re: [Openvpn-devel] [PATCH v3] Implement --client-crresponse script options and plugin interface
Hi,
Quoted 6 lines · Arne Schwabe
This is allows scripts and pluginsto parse/react to a
CR_RESPONSEmessagePatch V2: doc fixes, do not put script under
ENABLE_PLUGINPatch V3: rebaseSigned-off-by Arne Schwabe <[email protected]...>
I have a high level question about this patch.
At the moment there is no trace of CR_RESPONSE or request in the OpenVPN2 code.
To the best of my knowledge that's because this protocol is entirely handled outside of OpenVPN using INFO_PRE and custom control messages.
With this patch we are aiming at moving a piece of this "external" logic inside OpenVPN.
Question 1:
What is the benefit of moving the CR response handling inside OpenVPN, if there is no code to generate the request? Maybe there are advantages that are just assumed?
Question 2:
If we implement handling CR-RESPONSE, do we want to implement such handling in the future with every custom control message that may be sent by the management interface?
Question 3:
IMHO, this is a very good case where OpenVPN can be transparent and let the upper layer deal with it (i.e. via mgmt interface), why changing that?
Best Regards,
Signature · 1 line
Antonio Quartulli
Re: [Openvpn-devel] [PATCH v3] Implement --client-crresponse script options and plugin interface
Hi,
Quoted 29 lines · Antonio Quartulli
Hi,
Quoted 6 lines · Arne Schwabe
This is allows scripts and pluginsto parse/react to a
CR_RESPONSEmessagePatch V2: doc fixes, do not put script under
ENABLE_PLUGINPatch V3: rebaseSigned-off-by Arne Schwabe <[email protected]...>I have a high level question about this patch.
At the moment there is no trace of
CR_RESPONSEor request in the OpenVPN2 code.To the best of my knowledge that's because this protocol is entirely handled outside of OpenVPN using
INFO_PREand custom control messages.With this patch we are aiming at moving a piece of this "external" logic inside OpenVPN.
Question 1:
What is the benefit of moving the CR response handling inside OpenVPN, if there is no code to generate the request? Maybe there are advantages that are just assumed?
Question 2:
Quoted 8 lines
If we implement handling CR-RESPONSE, do we want to implement such handling in the future with every custom control message that may be sent by the management interface?
Question 3:
IMHO, this is a very good case where OpenVPN can be transparent and let the upper layer deal with it (i.e. via mgmt interface), why changing that?
I have to take this back.
OpenVPN already has some logic to parse the CR_RESPONSE and react to it accordingly.
Therefore my comments above are wrong.
Please ignore my earlier message.
Best Regards,
Signature · 1 line
Antonio Quartulli
Re: [Openvpn-devel] [PATCH v3] Implement --client-crresponse script options and plugin interface
In reply to Arne SchwabeHi,
Quoted 36 lines · Arne Schwabe
This is allows scripts and pluginsto parse/react to a
CR_RESPONSEmessagePatch V2: doc fixes, do not put script under
ENABLE_PLUGINPatch V3: rebaseSigned-off-by Arne Schwabe <[email protected]...>--- doc/man-sections/script-options.rst | 28 ++++++++++++- include/openvpn-plugin.h.in | 7 +++- src/openvpn/init.c | 1 + src/openvpn/options.c | 15 +++++++ src/openvpn/options.h | 1 + src/openvpn/plugin.c | 5 ++- src/openvpn/push.c | 4 ++ src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_verify.c | 65 +++++++++++++++++++++++++++++ src/openvpn/ssl_verify.h | 23 ++++++++++ 10 files changed, 146 insertions(+), 4 deletions(-)doc/man-sections/script-options.rst +5
-0@@ -52,6 +52,11 @@ Script Order of Execution Executed in ``--mode server`` mode on new client connections, when the client is still untrusted. +#. ``--client-crresponse`` + + Execute in ``--mode server`` whenever a client sends a + :code:`CR_RESPONSE` message + SCRIPT HOOKS ------------
doc/man-sections/script-options.rst SCRIPT HOOKS · line 80
Quoted 5 lines
doc/man-sections/script-options.rst +1
-1@@ -72,7 +77,7 @@ SCRIPT HOOKS double-quoted and/or escaped using a backslash, and should be separated by one or more spaces. - If ``method`` is set to :code:`via-env`, OpenVPN will call ``script`` + If ``method`` is set to :code:`via-env`, OpenVPN will call ``cmd``
this fix seems unrelated
doc/man-sections/script-options.rst SCRIPT HOOKS · line 88
Quoted 9 lines
doc/man-sections/script-options.rst +1
-1with the environmental variables :code:`username` and :code:`password` set to the username/password strings provided by the client. *Beware* that this method is insecure on some platforms which make the environment@@ -80,7 +85,7 @@ SCRIPT HOOKS If ``method`` is set to :code:`via-file`, OpenVPN will write the username and password to the first two lines of a temporary file. The filename - will be passed as an argument to ``script``, and the file will be + will be passed as an argument to ``cmd``, and the file will be
this fix seems unrelated
Quoted 123 lines
doc/man-sections/script-options.rst +19
-0automatically deleted by OpenVPN after the script returns. The location of the temporary file is controlled by the ``--tmp-dir`` option, and will default to the current directory if unspecified. For security,@@ -123,6 +128,25 @@ SCRIPT HOOKS For a sample script that performs PAM authentication, see :code:`sample-scripts/auth-pam.pl` in the OpenVPN source distribution. +--client-crresponse + Executed when the client sends a text based challenge response. + + Valid syntax: + :: + + client-crresponse cmd + + OpenVPN will write the response of the client into a temporary file. + The filename will be passed as an argument to ``cmd``, and the file will be + automatically deleted by OpenVPN after the script returns. + + The response is passed as is from the client. The script needs to check + itself if the input is valid, e.g. if the input is valid base64 encoding. + + The script can either directly write the result of the verification to + :code:`auth_control_file or further defer it. See ``--auth-user-pass-verify`` + for details. + --client-connect cmd Run command ``cmd`` on client connection.include/openvpn-plugin.h.in +6
-1@@ -84,6 +84,10 @@ extern "C" { * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_CLIENT_CONNECT_V2 * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_LEARN_ADDRESS * + * The OPENVPN_PLUGIN_CLIENT_CRRESPONSE function is called when the client sends + * the CR_RESPONSE message, this is *typically* after OPENVPN_PLUGIN_TLS_FINAL + * but may also occur much later. + * * [Client session ensues] * * For each "TLS soft reset", according to reneg-sec option (or similar):@@ -131,7 +135,8 @@ extern "C" { #define OPENVPN_PLUGIN_ROUTE_PREDOWN 12 #define OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER 13 #define OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2 14 -#define OPENVPN_PLUGIN_N 15 +#define OPENVPN_PLUGIN_CLIENT_CRRESPONSE 15 +#define OPENVPN_PLUGIN_N 16 /* * Build a mask out of a set of plug-in types.src/openvpn/init.c +1
-0@@ -2916,6 +2916,7 @@ do_init_crypto_tls(struct context *c, const unsigned int flags) to.auth_user_pass_verify_script = options->auth_user_pass_verify_script; to.auth_user_pass_verify_script_via_file = options->auth_user_pass_verify_script_via_file; + to.client_crresponse_script = options->client_crresponse_script; to.tmp_dir = options->tmp_dir;if (options->ccd_exclusive) {src/openvpn/options.c +15
-0@@ -1327,6 +1327,7 @@ show_p2mp_parms(const struct options *o)SHOW_STR (client_connect_script);SHOW_STR (learn_address_script);SHOW_STR (client_disconnect_script); +SHOW_STR (client_crresponse_script);SHOW_STR (client_config_dir);SHOW_BOOL (ccd_exclusive);SHOW_STR (tmp_dir);@@ -2470,6 +2471,10 @@ options_postprocess_verify_ce(const struct options *options, {msg (M_USAGE ,"--client-connect requires --mode server" ); } +if (options->client_crresponse_script) + { +msg (M_USAGE ,"--client-crresponse requires --mode server" ); + }if (options->client_disconnect_script) {msg (M_USAGE ,"--client-disconnect requires --mode server" );@@ -7082,6 +7087,16 @@ add_option(struct options *options,set_user_script (options, &options->client_connect_script, p[1 ],"client-connect" , true); } +else if (streq (p[0 ],"client-crresponse" ) && p[1 ]) + { +VERIFY_PERMISSION (OPT_P_SCRIPT ); +if (!no_more_than_n_args (msglevel, p,2 ,NM_QUOTE_HINT )) + { + goto err; + } +set_user_script (options, &options->client_crresponse_script, + p[1 ],"client-crresponse" , true); + }else if (streq (p[0 ],"client-disconnect" ) && p[1 ]) {VERIFY_PERMISSION (OPT_P_SCRIPT );src/openvpn/options.h +1
-0@@ -449,6 +449,7 @@ struct optionsconst char *client_connect_script;const char *client_disconnect_script;const char *learn_address_script; +const char *client_crresponse_script;const char *client_config_dir;bool ccd_exclusive;bool disable;src/openvpn/plugin.c +0
-0
src/openvpn/plugin.c plugin_type_name(const int type) · line 105
Quoted 5 lines
src/openvpn/plugin.c +1
-1@@ -102,7 +102,7 @@ plugin_type_name(const int type)return "PLUGIN_CLIENT_CONNECT" ;case OPENVPN_PLUGIN_CLIENT_CONNECT_V2 : -return "PLUGIN_CLIENT_CONNECT" ; +return "PLUGIN_CLIENT_CONNECT_V2" ;
This seems unrelated, isn't it?
Quoted 141 lines
src/openvpn/plugin.c +3
-0case OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER :return "PLUGIN_CLIENT_CONNECT_DEFER" ;@@ -125,6 +125,9 @@ plugin_type_name(const int type)case OPENVPN_PLUGIN_ROUTE_PREDOWN :return "PLUGIN_ROUTE_PREDOWN" ; +case OPENVPN_PLUGIN_CLIENT_CRRESPONSE : +return "PLUGIN_CRRESPONSE" ; +default :return "PLUGIN_???" ; }src/openvpn/push.c +4
-0@@ -227,6 +227,10 @@ receive_cr_response(struct context *c, const struct buffer *buffer)management_notify_client_cr_response (key_id, mda, es, m);#endif +#if ENABLE_PLUGIN +verify_crresponse_plugin (c->c2.tls_multi, m); +#endif +verify_crresponse_script (c->c2.tls_multi, m);msg (D_PUSH ,"CR response was sent by client ('%s')" , m); }src/openvpn/ssl_common.h +1
-0@@ -330,6 +330,7 @@ struct tls_options/* used for username/password authentication */ const char *auth_user_pass_verify_script; +const char *client_crresponse_script;bool auth_user_pass_verify_script_via_file;const char *tmp_dir;const char *auth_user_pass_file;src/openvpn/ssl_verify.c +65
-0@@ -1337,6 +1337,71 @@ done:return retval; } +#ifdef ENABLE_PLUGIN +void +verify_crresponse_plugin (struct tls_multi *multi,const char *cr_response) +{ +struct tls_session *session = &multi->session[TM_ACTIVE ]; +setenv_str (session->opt->es,"crresponse" , cr_response); + +plugin_call (session->opt->plugins,OPENVPN_PLUGIN_CLIENT_CRRESPONSE ,NULL , +NULL , session->opt->es); + +setenv_del (session->opt->es,"crresponse" ); +} +#endif + +void +verify_crresponse_script (struct tls_multi *multi,const char *cr_response) +{ + +struct tls_session *session = &multi->session[TM_ACTIVE ]; + +if (!session->opt->client_crresponse_script) + { +return ; + } +struct argv argv =argv_new (); +struct gc_arena gc =gc_new (); + +setenv_str (session->opt->es,"script_type" ,"client-crresponse" ); + +/* Since cr response might be sensitive, like a stupid way to query +* a password via 2FA, we pass it via file instead environment */ +const char *tmp_file =platform_create_temp_file (session->opt->tmp_dir,"cr" , &gc); +if (tmp_file) + { +struct status_output *so =status_open (tmp_file,0 ,-1 ,NULL , +STATUS_OUTPUT_WRITE ); +status_printf (so,"%s" , cr_response); +if (!status_close (so)) + { +msg (D_TLS_ERRORS ,"TLS CR Response Error: could not write cr" +"responsed to file: %s" , + tmp_file); +tls_deauthenticate (multi); + goto done; + } + } +else + { +msg (D_TLS_ERRORS ,"TLS Auth Error: could not create write " +"username/password to temp file" ); + } + +argv_parse_cmd (&argv, session->opt->client_crresponse_script); +argv_printf_cat (&argv,"%s" , tmp_file); + + +if (!openvpn_run_script (&argv, session->opt->es,0 ,"--client-crresponse" )) + { +tls_deauthenticate (multi); + } +done: +argv_free (&argv); +gc_free (&gc); +} +/* * Verify the username and password using a plugin */ src/openvpn/ssl_verify.h +16
-0@@ -206,6 +206,29 @@ tls_common_name_hash(const struct tls_multi *multi, const char **cn, uint32_t *cvoid verify_user_pass (struct user_pass *up,struct tls_multi *multi,struct tls_session *session); + + +/** +* Runs the --client-crresponse script if one is defined. +* +* As with the management interface the script is stateless in the sense that +* it does not directly participate in the authentication but rather should set +* the files for the deferred auth like the management commands. +* +*/ +void +verify_crresponse_script (struct tls_multi *multi,const char *cr_response); + +/** +* Call the plugin OPENVPN_PLUGIN_CLIENT_CRRESPONSE. +*
src/openvpn/ssl_verify.h tls_common_name_hash(const struct tls_multi *multi, const char **cn, uint32_t *c · line 234
Quoted 10 lines
src/openvpn/ssl_verify.h +7
-0+* As with the management interface calling the plugin is stateless in the sense +* that it does not directly participate in the authentication but rather +* should set the files for the deferred auth like the management commands. +*/ +void +verify_crresponse_plugin (struct tls_multi *multi,const char *cr_response); +/** * Perform final authentication checks, including locking of the cn, the allowed * certificate hashes, and whether a client config entry exists in the
The code looks reasonable and I Can't spot anything wrong, other than what I noted above.
On v2 David already conducted tests and ACK'd this patch, therefore I'd just consider his reply still valid, since this is just a rebase.
Best Regards,
Signature · 1 line
Antonio Quartulli
Re: [Openvpn-devel] [PATCH v3] Implement --client-crresponse script options and plugin interface
In reply to Arne SchwabeQuoted 1 line · On Dienstag, 18. Mai 2021 14:26:35 CEST Arne Schwabe wrote:
This is allows scripts and pluginsto parse/react to a
CR_RESPONSEmessage
This commit message needs a makeover, I think.
doc/man-sections/script-options.rst SCRIPT HOOKS · line 80
Quoted 2 lines
doc/man-sections/script-options.rst +1
-1- If ``method`` is set to :code:`via-env`, OpenVPN will call ``script`` + If ``method`` is set to :code:`via-env`, OpenVPN will call ``cmd``
These drive-by fixes Antonio spotted make sense and are not intrusive enough that I care.
Quoted 1 line
+verify_crresponse_script(struct
tls_multi*multi, const char*cr_response)
[...]
Quoted 11 lines
+ const char
*tmp_file= platform_create_temp_file(session->opt->tmp_dir,
"cr", &gc);src/openvpn/ssl_verify.c +9
-0+if (tmp_file) + { +struct status_output *so =status_open (tmp_file,0 ,-1 ,NULL , +STATUS_OUTPUT_WRITE ); +status_printf (so,"%s" , cr_response); +if (!status_close (so)) + { + msg(D_TLS_ERRORS, "TLS CR Response Error: could not write cr" + "responsed to file: %s",
src/openvpn/ssl_verify.c done: · line 1390
Quoted 10 lines
src/openvpn/ssl_verify.c +10
-0+ tmp_file); +tls_deauthenticate (multi); + goto done; + } + } +else + { +msg (D_TLS_ERRORS ,"TLS Auth Error: could not create write " +"username/password to temp file" ); + }
This else branch should be the same as the "if (!status_close(so))" one above I think, as you don't want to call the script without a valid tempfile. Besides that the error message is copy/paste wrong anyway. So, maybe introduce a bool and do the error handling in one place, might help future copy/pastes as well.
Re: [Openvpn-devel] [PATCH v3] Add example script demonstrating TOTP via auth-pending
In reply to Arne Schwabedoc/man-sections/script-options.rst SCRIPT HOOKS · line 151
Quoted 2 lines · On Donnerstag, 4. März 2021 12:40:18 CEST Arne Schwabe wrote:
doc/man-sections/script-options.rst +2
-0+ For a sample script that implement TOTP (RFC 6238) based two-factor + authentication, see :code:`sample-scripts/totp.py`.
This filename doesn't match with below.
Quoted 2 lines
(quoted diff) +0
-0
b/sample/sample-scripts/totpauth.pynew file mode 100755
Have not looked at the Python code much, but David already did. More of a Perl guy anyway. ;-)
PATCH v4 1/1 Implement --client-crresponse script options and plugin interface
In reply to Arne SchwabeThis is allows scripts and pluginsto parse/react to a CR_RESPONSE message
Patch V2: doc fixes, do not put script under ENABLE_PLUGIN Patch V3: rebase
Patch V4: fix else branch of the verify_crresponse_script function
--- doc/man-sections/script-options.rst | 28 +++++++++++- include/openvpn-plugin.h.in | 7 ++- src/openvpn/init.c | 1 + src/openvpn/options.c | 15 +++++++ src/openvpn/options.h | 1 + src/openvpn/plugin.c | 5 ++- src/openvpn/push.c | 4 ++ src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_verify.c | 67 +++++++++++++++++++++++++++++ src/openvpn/ssl_verify.h | 23 ++++++++++ 10 files changed, 148 insertions(+), 4 deletions(-)
doc/man-sections/script-options.rst +26 -2
@@ -52,6 +52,11 @@ Script Order of Execution Executed in ``--mode server`` mode on new client connections, when the client is still untrusted. +#. ``--client-crresponse`` + + Execute in ``--mode server`` whenever a client sends a + :code:`CR_RESPONSE` message + SCRIPT HOOKS ------------
@@ -72,7 +77,7 @@ SCRIPT HOOKS double-quoted and/or escaped using a backslash, and should be separated by one or more spaces. - If ``method`` is set to :code:`via-env`, OpenVPN will call ``script`` + If ``method`` is set to :code:`via-env`, OpenVPN will call ``cmd`` with the environmental variables :code:`username` and :code:`password` set to the username/password strings provided by the client. *Beware* that this method is insecure on some platforms which make the environment
@@ -80,7 +85,7 @@ SCRIPT HOOKS If ``method`` is set to :code:`via-file`, OpenVPN will write the username and password to the first two lines of a temporary file. The filename - will be passed as an argument to ``script``, and the file will be + will be passed as an argument to ``cmd``, and the file will be automatically deleted by OpenVPN after the script returns. The location of the temporary file is controlled by the ``--tmp-dir`` option, and will default to the current directory if unspecified. For security,
@@ -123,6 +128,25 @@ SCRIPT HOOKS For a sample script that performs PAM authentication, see :code:`sample-scripts/auth-pam.pl` in the OpenVPN source distribution. +--client-crresponse + Executed when the client sends a text based challenge response. + + Valid syntax: + :: + + client-crresponse cmd + + OpenVPN will write the response of the client into a temporary file. + The filename will be passed as an argument to ``cmd``, and the file will be + automatically deleted by OpenVPN after the script returns. + + The response is passed as is from the client. The script needs to check + itself if the input is valid, e.g. if the input is valid base64 encoding. + + The script can either directly write the result of the verification to + :code:`auth_control_file or further defer it. See ``--auth-user-pass-verify`` + for details. + --client-connect cmd Run command ``cmd`` on client connection.
include/openvpn-plugin.h.in +6 -1
@@ -83,6 +83,10 @@ extern "C" { * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_CLIENT_CONNECT_V2 * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_LEARN_ADDRESS * + * The OPENVPN_PLUGIN_CLIENT_CRRESPONSE function is called when the client sends + * the CR_RESPONSE message, this is *typically* after OPENVPN_PLUGIN_TLS_FINAL + * but may also occur much later. + * * [Client session ensues] * * For each "TLS soft reset", according to reneg-sec option (or similar):
@@ -128,7 +132,8 @@ extern "C" { #define OPENVPN_PLUGIN_ROUTE_PREDOWN 12 #define OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER 13 #define OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2 14 -#define OPENVPN_PLUGIN_N 15 +#define OPENVPN_PLUGIN_CLIENT_CRRESPONSE 15 +#define OPENVPN_PLUGIN_N 16 /* * Build a mask out of a set of plug-in types.
src/openvpn/init.c +1 -0
@@ -3029,6 +3029,7 @@ do_init_crypto_tls(struct context *c, const unsigned int flags) to.auth_user_pass_verify_script = options->auth_user_pass_verify_script; to.auth_user_pass_verify_script_via_file = options->auth_user_pass_verify_script_via_file; + to.client_crresponse_script = options->client_crresponse_script; to.tmp_dir = options->tmp_dir;if (options->ccd_exclusive) {
src/openvpn/options.c +15 -0
@@ -1525,6 +1525,7 @@ show_p2mp_parms(const struct options *o)SHOW_STR (client_connect_script);SHOW_STR (learn_address_script);SHOW_STR (client_disconnect_script); +SHOW_STR (client_crresponse_script);SHOW_STR (client_config_dir);SHOW_BOOL (ccd_exclusive);SHOW_STR (tmp_dir);
@@ -2684,6 +2685,10 @@ options_postprocess_verify_ce(const struct options *options, {msg (M_USAGE ,"--client-connect requires --mode server" ); } +if (options->client_crresponse_script) + { +msg (M_USAGE ,"--client-crresponse requires --mode server" ); + }if (options->client_disconnect_script) {msg (M_USAGE ,"--client-disconnect requires --mode server" );
@@ -7441,6 +7446,16 @@ add_option(struct options *options,set_user_script (options, &options->client_connect_script, p[1 ],"client-connect" , true); } +else if (streq (p[0 ],"client-crresponse" ) && p[1 ]) + { +VERIFY_PERMISSION (OPT_P_SCRIPT ); +if (!no_more_than_n_args (msglevel, p,2 ,NM_QUOTE_HINT )) + { + goto err; + } +set_user_script (options, &options->client_crresponse_script, + p[1 ],"client-crresponse" , true); + }else if (streq (p[0 ],"client-disconnect" ) && p[1 ]) {VERIFY_PERMISSION (OPT_P_SCRIPT );
src/openvpn/options.h +1 -0
@@ -473,6 +473,7 @@ struct optionsconst char *client_connect_script;const char *client_disconnect_script;const char *learn_address_script; +const char *client_crresponse_script;const char *client_config_dir;bool ccd_exclusive;bool disable;
src/openvpn/plugin.c +4 -1
@@ -102,7 +102,7 @@ plugin_type_name(const int type)return "PLUGIN_CLIENT_CONNECT" ;case OPENVPN_PLUGIN_CLIENT_CONNECT_V2 : -return "PLUGIN_CLIENT_CONNECT" ; +return "PLUGIN_CLIENT_CONNECT_V2" ;case OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER :return "PLUGIN_CLIENT_CONNECT_DEFER" ;
@@ -122,6 +122,9 @@ plugin_type_name(const int type)case OPENVPN_PLUGIN_ROUTE_PREDOWN :return "PLUGIN_ROUTE_PREDOWN" ; +case OPENVPN_PLUGIN_CLIENT_CRRESPONSE : +return "PLUGIN_CRRESPONSE" ; +default :return "PLUGIN_???" ; }
src/openvpn/push.c +4 -0
@@ -229,6 +229,10 @@ receive_cr_response(struct context *c, const struct buffer *buffer)management_notify_client_cr_response (key_id, mda, es, m);#endif +#if ENABLE_PLUGIN +verify_crresponse_plugin (c->c2.tls_multi, m); +#endif +verify_crresponse_script (c->c2.tls_multi, m);msg (D_PUSH ,"CR response was sent by client ('%s')" , m); }
src/openvpn/ssl_common.h +1 -0
@@ -362,6 +362,7 @@ struct tls_options/* used for username/password authentication */ const char *auth_user_pass_verify_script; +const char *client_crresponse_script;bool auth_user_pass_verify_script_via_file;const char *tmp_dir;const char *auth_user_pass_file;
src/openvpn/ssl_verify.c +67 -0
73 lines not on this page · raw message
src/openvpn/ssl_verify.h +23 -0
@@ -177,6 +177,29 @@ bool cert_hash_compare(const struct cert_hash_set *chs1, const struct cert_hash_void verify_user_pass (struct user_pass *up,struct tls_multi *multi,struct tls_session *session); + + +/** +* Runs the --client-crresponse script if one is defined. +* +* As with the management interface the script is stateless in the sense that +* it does not directly participate in the authentication but rather should set +* the files for the deferred auth like the management commands. +* +*/ +void +verify_crresponse_script (struct tls_multi *multi,const char *cr_response); + +/** +* Call the plugin OPENVPN_PLUGIN_CLIENT_CRRESPONSE. +* +* As with the management interface calling the plugin is stateless in the sense +* that it does not directly participate in the authentication but rather +* should set the files for the deferred auth like the management commands. +*/ +void +verify_crresponse_plugin (struct tls_multi *multi,const char *cr_response); +/** * Perform final authentication checks, including locking of the cn, the allowed * certificate hashes, and whether a client config entry exists in the
Signature · 1 line
2.32.1 (Apple Git-133)
Re: [Openvpn-devel] [PATCH v4] Implement --client-crresponse script options and plugin interface
Quoted 2 lines · On Freitag, 19. August 2022 11:51:32 CEST Arne Schwabe wrote:
(quoted diff) +2
-0+verify_crresponse_script(struct tls_multi *multi, const char *cr_response) +{
[...]
src/openvpn/ssl_verify.c done: · line 1404
Quoted 13 lines
src/openvpn/ssl_verify.c +13
-0+if (!status_close (so)) + { +msg (D_TLS_ERRORS ,"TLS CR Response Error: could not write cr" +"responsed to file: %s" , + tmp_file); +tls_deauthenticate (multi); + goto done; + } + } +else + { +msg (D_TLS_ERRORS ,"TLS Auth Error: could not write " +"username/password to cr response temp file" );
The message is still wrong. Which proves my point about unifying it.
PATCH v5 1/1 Implement --client-crresponse script options and plugin interface
In reply to Arne SchwabeThis is allows scripts and pluginsto parse/react to a CR_RESPONSE message
Patch V2: doc fixes, do not put script under ENABLE_PLUGIN Patch V3: rebase
Patch V4: fix else branch of the verify_crresponse_script function Patch V5: unify message when unable to create/write crresponse file
--- doc/man-sections/script-options.rst | 28 +++++++++++- include/openvpn-plugin.h.in | 7 ++- src/openvpn/init.c | 1 + src/openvpn/options.c | 15 +++++++ src/openvpn/options.h | 1 + src/openvpn/plugin.c | 5 ++- src/openvpn/push.c | 4 ++ src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_verify.c | 67 +++++++++++++++++++++++++++++ src/openvpn/ssl_verify.h | 23 ++++++++++ 10 files changed, 148 insertions(+), 4 deletions(-)
doc/man-sections/script-options.rst +26 -2
@@ -52,6 +52,11 @@ Script Order of Execution Executed in ``--mode server`` mode on new client connections, when the client is still untrusted. +#. ``--client-crresponse`` + + Execute in ``--mode server`` whenever a client sends a + :code:`CR_RESPONSE` message + SCRIPT HOOKS ------------
@@ -72,7 +77,7 @@ SCRIPT HOOKS double-quoted and/or escaped using a backslash, and should be separated by one or more spaces. - If ``method`` is set to :code:`via-env`, OpenVPN will call ``script`` + If ``method`` is set to :code:`via-env`, OpenVPN will call ``cmd`` with the environmental variables :code:`username` and :code:`password` set to the username/password strings provided by the client. *Beware* that this method is insecure on some platforms which make the environment
@@ -80,7 +85,7 @@ SCRIPT HOOKS If ``method`` is set to :code:`via-file`, OpenVPN will write the username and password to the first two lines of a temporary file. The filename - will be passed as an argument to ``script``, and the file will be + will be passed as an argument to ``cmd``, and the file will be automatically deleted by OpenVPN after the script returns. The location of the temporary file is controlled by the ``--tmp-dir`` option, and will default to the current directory if unspecified. For security,
@@ -123,6 +128,25 @@ SCRIPT HOOKS For a sample script that performs PAM authentication, see :code:`sample-scripts/auth-pam.pl` in the OpenVPN source distribution. +--client-crresponse + Executed when the client sends a text based challenge response. + + Valid syntax: + :: + + client-crresponse cmd + + OpenVPN will write the response of the client into a temporary file. + The filename will be passed as an argument to ``cmd``, and the file will be + automatically deleted by OpenVPN after the script returns. + + The response is passed as is from the client. The script needs to check + itself if the input is valid, e.g. if the input is valid base64 encoding. + + The script can either directly write the result of the verification to + :code:`auth_control_file or further defer it. See ``--auth-user-pass-verify`` + for details. + --client-connect cmd Run command ``cmd`` on client connection.
include/openvpn-plugin.h.in +6 -1
@@ -83,6 +83,10 @@ extern "C" { * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_CLIENT_CONNECT_V2 * FUNC: openvpn_plugin_func_v1 OPENVPN_PLUGIN_LEARN_ADDRESS * + * The OPENVPN_PLUGIN_CLIENT_CRRESPONSE function is called when the client sends + * the CR_RESPONSE message, this is *typically* after OPENVPN_PLUGIN_TLS_FINAL + * but may also occur much later. + * * [Client session ensues] * * For each "TLS soft reset", according to reneg-sec option (or similar):
@@ -128,7 +132,8 @@ extern "C" { #define OPENVPN_PLUGIN_ROUTE_PREDOWN 12 #define OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER 13 #define OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER_V2 14 -#define OPENVPN_PLUGIN_N 15 +#define OPENVPN_PLUGIN_CLIENT_CRRESPONSE 15 +#define OPENVPN_PLUGIN_N 16 /* * Build a mask out of a set of plug-in types.
src/openvpn/init.c +1 -0
@@ -3033,6 +3033,7 @@ do_init_crypto_tls(struct context *c, const unsigned int flags) to.auth_user_pass_verify_script = options->auth_user_pass_verify_script; to.auth_user_pass_verify_script_via_file = options->auth_user_pass_verify_script_via_file; + to.client_crresponse_script = options->client_crresponse_script; to.tmp_dir = options->tmp_dir;if (options->ccd_exclusive) {
src/openvpn/options.c +15 -0
@@ -1525,6 +1525,7 @@ show_p2mp_parms(const struct options *o)SHOW_STR (client_connect_script);SHOW_STR (learn_address_script);SHOW_STR (client_disconnect_script); +SHOW_STR (client_crresponse_script);SHOW_STR (client_config_dir);SHOW_BOOL (ccd_exclusive);SHOW_STR (tmp_dir);
@@ -2684,6 +2685,10 @@ options_postprocess_verify_ce(const struct options *options, {msg (M_USAGE ,"--client-connect requires --mode server" ); } +if (options->client_crresponse_script) + { +msg (M_USAGE ,"--client-crresponse requires --mode server" ); + }if (options->client_disconnect_script) {msg (M_USAGE ,"--client-disconnect requires --mode server" );
@@ -7447,6 +7452,16 @@ add_option(struct options *options,set_user_script (options, &options->client_connect_script, p[1 ],"client-connect" , true); } +else if (streq (p[0 ],"client-crresponse" ) && p[1 ]) + { +VERIFY_PERMISSION (OPT_P_SCRIPT ); +if (!no_more_than_n_args (msglevel, p,2 ,NM_QUOTE_HINT )) + { + goto err; + } +set_user_script (options, &options->client_crresponse_script, + p[1 ],"client-crresponse" , true); + }else if (streq (p[0 ],"client-disconnect" ) && p[1 ]) {VERIFY_PERMISSION (OPT_P_SCRIPT );
src/openvpn/options.h +1 -0
@@ -473,6 +473,7 @@ struct optionsconst char *client_connect_script;const char *client_disconnect_script;const char *learn_address_script; +const char *client_crresponse_script;const char *client_config_dir;bool ccd_exclusive;bool disable;
src/openvpn/plugin.c +4 -1
@@ -102,7 +102,7 @@ plugin_type_name(const int type)return "PLUGIN_CLIENT_CONNECT" ;case OPENVPN_PLUGIN_CLIENT_CONNECT_V2 : -return "PLUGIN_CLIENT_CONNECT" ; +return "PLUGIN_CLIENT_CONNECT_V2" ;case OPENVPN_PLUGIN_CLIENT_CONNECT_DEFER :return "PLUGIN_CLIENT_CONNECT_DEFER" ;
@@ -122,6 +122,9 @@ plugin_type_name(const int type)case OPENVPN_PLUGIN_ROUTE_PREDOWN :return "PLUGIN_ROUTE_PREDOWN" ; +case OPENVPN_PLUGIN_CLIENT_CRRESPONSE : +return "PLUGIN_CRRESPONSE" ; +default :return "PLUGIN_???" ; }
src/openvpn/push.c +4 -0
@@ -229,6 +229,10 @@ receive_cr_response(struct context *c, const struct buffer *buffer)management_notify_client_cr_response (key_id, mda, es, m);#endif +#if ENABLE_PLUGIN +verify_crresponse_plugin (c->c2.tls_multi, m); +#endif +verify_crresponse_script (c->c2.tls_multi, m);msg (D_PUSH ,"CR response was sent by client ('%s')" , m); }
src/openvpn/ssl_common.h +1 -0
@@ -362,6 +362,7 @@ struct tls_options/* used for username/password authentication */ const char *auth_user_pass_verify_script; +const char *client_crresponse_script;bool auth_user_pass_verify_script_via_file;const char *tmp_dir;const char *auth_user_pass_file;
src/openvpn/ssl_verify.c +67 -0
73 lines not on this page · raw message
src/openvpn/ssl_verify.h +23 -0
@@ -177,6 +177,29 @@ bool cert_hash_compare(const struct cert_hash_set *chs1, const struct cert_hash_void verify_user_pass (struct user_pass *up,struct tls_multi *multi,struct tls_session *session); + + +/** +* Runs the --client-crresponse script if one is defined. +* +* As with the management interface the script is stateless in the sense that +* it does not directly participate in the authentication but rather should set +* the files for the deferred auth like the management commands. +* +*/ +void +verify_crresponse_script (struct tls_multi *multi,const char *cr_response); + +/** +* Call the plugin OPENVPN_PLUGIN_CLIENT_CRRESPONSE. +* +* As with the management interface calling the plugin is stateless in the sense +* that it does not directly participate in the authentication but rather +* should set the files for the deferred auth like the management commands. +*/ +void +verify_crresponse_plugin (struct tls_multi *multi,const char *cr_response); +/** * Perform final authentication checks, including locking of the cn, the allowed * certificate hashes, and whether a client config entry exists in the
Signature · 1 line
2.32.1 (Apple Git-133)
Re: [Openvpn-devel] [PATCH v5] Implement --client-crresponse script options and plugin interface
Quoted 8 lines · On Mittwoch, 24. August 2022 13:09:30 CEST Arne Schwabe wrote:
This is allows scripts and pluginsto parse/react to a
CR_RESPONSEmessagePatch V2: doc fixes, do not put script under
ENABLE_PLUGINPatch V3: rebase
Patch V4: fix else branch of theverify_crresponse_scriptfunction Patch V5: unify message when unable to create/write crresponse fileSigned-off-by Arne Schwabe <[email protected]...>
[Openvpn-devel] [PATCH applied] Re: Implement --client-crresponse script options and plugin interface
In reply to Arne SchwabeI have tested this on the server test bed, to ensure it does not "drive by" break anything else (doesn't look like it, but testing is better). Doesn't :-) - I have not actually tested the CRRESPONSE script functionality.
I have slightly changed the commit message, to fix grammar/typo.
Looking at the discussions around the error message and the resulting code (why not exit early on "if (!tmp_file)"?) I wonder why we do not have a more generic "create a tmp_file, fill it with $string, do proper error messages, return true/false" function for this... and what this "status_open()" stuff is about, for wrting a plain text file.
But this is for a separate cleanup/refactoring patch.
On the patch itself, since this does not introduce new asynchronous authentication, just extra hooks that are done (or not) and can succeed synchronously (or not), the changes should be fine. Heiko and David already reviewed this.
Next: 11/11 v4 + ACK, please :-)
Your patch has been applied to the master branch.
commit 23eec2d29435a51771dcd4f85d71f33465a174ff
Author: Arne Schwabe Date: Wed Aug 24 13:09:30 2022 +0200
Implement --client-crresponse script options and plugin interface
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Heiko Hund <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg25089.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [PATCH applied] Re: Add example script demonstrating TOTP via auth-pending
In reply to Arne SchwabeI have not tested this, no proper testbed, no client support. But it's not changing OpenVPN code, just adding a script, and David has ACKed it.
I *have* changed the reference to match the script name, as instructed :-)
Your patch has been applied to the master branch.
commit 20ce5e3173cf1b086e1241619e8d949f0a6d0687
Author: Arne Schwabe Date: Thu Mar 4 12:40:18 2021 +0100
Add example script demonstrating TOTP via auth-pending
Signed-off-by: Arne Schwabe <[email protected]...>
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: David Sommerseth <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg21603.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering