From patchwork Wed Oct 10 03:30:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 538 X-Patchwork-Delegate: a@unstable.cc Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director8.mail.ord1d.rsapps.net ([172.27.255.58]) by backend30.mail.ord1d.rsapps.net with LMTP id 6MQcMVoNvlvJXAAAIUCqbw for ; Wed, 10 Oct 2018 10:31:54 -0400 Received: from proxy20.mail.iad3a.rsapps.net ([172.27.255.58]) by director8.mail.ord1d.rsapps.net with LMTP id wPlJLloNvlv6awAAfY0hYg ; Wed, 10 Oct 2018 10:31:54 -0400 Received: from smtp8.gate.iad3a ([172.27.255.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy20.mail.iad3a.rsapps.net with LMTP id iKl0J1oNvluPbgAAtfLT2w ; Wed, 10 Oct 2018 10:31:54 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp8.gate.iad3a.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dmarc=none (p=nil; dis=none) header.from=rfc2549.org X-Suspicious-Flag: YES X-Classification-ID: 3af6216c-cc99-11e8-9c63-525400b8fe03-1-1 Received: from [216.105.38.7] ([216.105.38.7:15305] helo=lists.sourceforge.net) by smtp8.gate.iad3a.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id A7/A9-19884-95D0EBB5; Wed, 10 Oct 2018 10:31:53 -0400 Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1gAFVv-00027g-HC; Wed, 10 Oct 2018 14:31:03 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1gAFVu-00027E-0i for openvpn-devel@lists.sourceforge.NET; Wed, 10 Oct 2018 14:31:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:To: From:Sender:Reply-To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=uvv0dSsJA7Ued0+V+OzNpFlSKOGT6BUfc3Njhpd0V2A=; b=lcN6hTtjTpSOaM7xTNVOqaeCbV EMP52m1aSF+TTZM8h/rSujCekZZVRlw+jYxmXK2DaA38L/XMSp/RdXiqdCFTW3iU/BgmHe07tH6pe Ffg+p6ijMDVd1Jvddn7tSnncFQj/FngKV71chK92tYxchaz3ZwiRrwkPz02BnWQIu4Dc=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc :MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=uvv0dSsJA7Ued0+V+OzNpFlSKOGT6BUfc3Njhpd0V2A=; b=WcCM3Um/1++FO3OlcW6Zp7OgsE ZoH6eJRMvg0Y7h9F/vCwuWFwIjmVLWOxqOf/BGUzUSX6UR/HtaDLOzOGZPfLYa7awqMVPP7b8KFxe 3TvIeZ+blSFdBifPj0xhjv3uuxyRd2NJScDLJJJF9AV570mxN5f17+cL1L/ip6yIZGkk=; Received: from mail.blinkt.de ([192.26.174.232]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) id 1gAFVs-0053x9-1y for openvpn-devel@lists.sourceforge.NET; Wed, 10 Oct 2018 14:31:01 +0000 Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c]) by mail.blinkt.de with smtp (Exim 4.91 (FreeBSD)) (envelope-from ) id 1gAFVj-000Fuq-Nq for openvpn-devel@lists.sourceforge.net; Wed, 10 Oct 2018 16:30:51 +0200 Received: (nullmailer pid 27208 invoked by uid 10006); Wed, 10 Oct 2018 14:30:51 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Wed, 10 Oct 2018 16:30:51 +0200 Message-Id: <20181010143051.27163-1-arne@rfc2549.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <1520262951-1807-1-git-send-email-arne@rfc2549.org> References: <1520262951-1807-1-git-send-email-arne@rfc2549.org> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different 0.1 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1gAFVs-0053x9-1y Subject: [Openvpn-devel] [PATCH v5] Revert to original password authentication after failed auth-token X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox Auth-tokens can expire. For by reconnecting when the server uses auth-gen-toke. Behaviour of OpenVPN client is to never fallback to the previous authentication method and continue using the auth-token. Depending on auth-retry it either quit or tried endlessly with an expired token. Since auth-gen-token tokens expire on reconnect, a client will not survive a reconnect. This patches changes the behaviour on failed auth when using an auth-token as a soft error (USR1) and clean the auth-token falling back to the original auth method. Patch V2: properly formatted commit message, fix openvpn3 detection Patch V3: remove all server changes, include only minimal non intrusive client changes that only improve error recovery but don't change overall behaviour. Patch V4: forget add push.c to git index, now also included Signed-off-by: Arne Schwabe Acked-by: Antonio Quartulli --- doc/openvpn.8 | 6 ++++++ src/openvpn/misc.c | 16 ++++++++++------ src/openvpn/misc.h | 4 ++-- src/openvpn/push.c | 17 +++++++++++++++-- src/openvpn/ssl.c | 39 +++++++++++++++++++++++++-------------- src/openvpn/ssl.h | 2 ++ 6 files changed, 60 insertions(+), 24 deletions(-) diff --git a/doc/openvpn.8 b/doc/openvpn.8 index e94ab760..39fc4fdf 100644 --- a/doc/openvpn.8 +++ b/doc/openvpn.8 @@ -5347,6 +5347,12 @@ into the file/buffer for dynamic configuration data. This will then make the OpenVPN server to push this value to the client, which replaces the local password with the UNIQUE_TOKEN_VALUE. + +Newer clients (2.4.7+) will fall back to the original password method +after a failed auth. Older clients will keep using the token value +and react acording to +.B \-\-auth-retry +. .\"********************************************************* .TP .B \-\-tls\-verify cmd diff --git a/src/openvpn/misc.c b/src/openvpn/misc.c index d75b7685..75f4ff47 100644 --- a/src/openvpn/misc.c +++ b/src/openvpn/misc.c @@ -469,7 +469,7 @@ purge_user_pass(struct user_pass *up, const bool force) * don't show warning if the pass has been replaced by a token: this is an * artificial "auth-nocache" */ - else if (!warn_shown && (!up->tokenized)) + else if (!warn_shown) { msg(M_WARN, "WARNING: this configuration may cache passwords in memory -- use the auth-nocache option to prevent this"); warn_shown = true; @@ -477,14 +477,18 @@ purge_user_pass(struct user_pass *up, const bool force) } void -set_auth_token(struct user_pass *up, const char *token) +set_auth_token(struct user_pass *up, struct user_pass *tk, const char *token) { - if (token && strlen(token) && up && up->defined && !up->nocache) + + if (token && strlen(token) && up && up->defined) { - CLEAR(up->password); - strncpynt(up->password, token, USER_PASS_LEN); - up->tokenized = true; + strncpynt(tk->password, token, USER_PASS_LEN); + strncpynt(tk->username, up->username, USER_PASS_LEN); + tk->defined = true; } + + /* Cleans user/pass for nocache */ + purge_user_pass(up, false); } /* diff --git a/src/openvpn/misc.h b/src/openvpn/misc.h index a54185f0..00de2b23 100644 --- a/src/openvpn/misc.h +++ b/src/openvpn/misc.h @@ -63,7 +63,6 @@ struct user_pass { bool defined; bool nocache; - bool tokenized; /* true if password has been substituted by a token */ bool wait_for_push; /* true if this object is waiting for a push-reply */ /* max length of username/password */ @@ -145,7 +144,8 @@ void fail_user_pass(const char *prefix, void purge_user_pass(struct user_pass *up, const bool force); -void set_auth_token(struct user_pass *up, const char *token); +void set_auth_token(struct user_pass *up, struct user_pass *tk, + const char *token); /* * Process string received by untrusted peer before diff --git a/src/openvpn/push.c b/src/openvpn/push.c index 72f09962..4798e26d 100644 --- a/src/openvpn/push.c +++ b/src/openvpn/push.c @@ -55,8 +55,20 @@ receive_auth_failed(struct context *c, const struct buffer *buffer) if (c->options.pull) { - switch (auth_retry_get()) + /* Before checking how to react on AUTH_FAILED, first check if the + * failed auth might be the result of an expired auth-token. + * Note that a server restart will trigger a generic AUTH_FAILED + * instead an AUTH_FAILED,SESSION so handle all AUTH_FAILED message + * identical for this scenario */ + if (ssl_clean_auth_token()) { + c->sig->signal_received = SIGUSR1; /* SOFT-SIGUSR1 -- Auth failure error */ + c->sig->signal_text = "auth-failure (auth-token)"; + } + else + { + switch (auth_retry_get()) + { case AR_NONE: c->sig->signal_received = SIGTERM; /* SOFT-SIGTERM -- Auth failure error */ break; @@ -70,8 +82,9 @@ receive_auth_failed(struct context *c, const struct buffer *buffer) default: ASSERT(0); + } + c->sig->signal_text = "auth-failure"; } - c->sig->signal_text = "auth-failure"; #ifdef ENABLE_MANAGEMENT if (management) { diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 58261e66..b52c2ab5 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -398,6 +398,7 @@ pem_password_callback(char *buf, int size, int rwflag, void *u) static bool auth_user_pass_enabled; /* GLOBAL */ static struct user_pass auth_user_pass; /* GLOBAL */ +static struct user_pass auth_token; /* GLOBAL */ #ifdef ENABLE_MANAGEMENT static char *auth_challenge; /* GLOBAL */ @@ -407,7 +408,7 @@ void auth_user_pass_setup(const char *auth_file, const struct static_challenge_info *sci) { auth_user_pass_enabled = true; - if (!auth_user_pass.defined) + if (!auth_user_pass.defined && !auth_token.defined) { #ifdef ENABLE_MANAGEMENT if (auth_challenge) /* dynamic challenge/response */ @@ -445,7 +446,7 @@ ssl_set_auth_nocache(void) { passbuf.nocache = true; auth_user_pass.nocache = true; - /* wait for push-reply, because auth-token may invert nocache */ + /* wait for push-reply, because auth-token may still need the username */ auth_user_pass.wait_for_push = true; } @@ -455,15 +456,18 @@ ssl_set_auth_nocache(void) void ssl_set_auth_token(const char *token) { - if (auth_user_pass.nocache) - { - msg(M_INFO, - "auth-token received, disabling auth-nocache for the " - "authentication token"); - auth_user_pass.nocache = false; - } + set_auth_token(&auth_user_pass, &auth_token, token); +} - set_auth_token(&auth_user_pass, token); +/* + * Cleans an auth token and checks if it was active + */ +bool +ssl_clean_auth_token (void) +{ + bool wasdefined = auth_token.defined; + purge_user_pass(&auth_token, true); + return wasdefined; } /* @@ -2369,19 +2373,26 @@ key_method_2_write(struct buffer *buf, struct tls_session *session) #else auth_user_pass_setup(session->opt->auth_user_pass_file, NULL); #endif - if (!write_string(buf, auth_user_pass.username, -1)) + struct user_pass *up = &auth_user_pass; + + /* + * If we have a valid auth-token, send that instead of real + * username/password + */ + if (auth_token.defined) + up = &auth_token; + + if (!write_string(buf, up->username, -1)) { goto error; } - if (!write_string(buf, auth_user_pass.password, -1)) + else if (!write_string(buf, up->password, -1)) { goto error; } /* if auth-nocache was specified, the auth_user_pass object reaches * a "complete" state only after having received the push-reply * message. - * This is the case because auth-token statement in a push-reply would - * invert its nocache. * * For this reason, skip the purge operation here if no push-reply * message has been received yet. diff --git a/src/openvpn/ssl.h b/src/openvpn/ssl.h index a1bd9bf0..781adb94 100644 --- a/src/openvpn/ssl.h +++ b/src/openvpn/ssl.h @@ -437,6 +437,8 @@ void ssl_set_auth_token(const char *token); */ void ssl_purge_auth_challenge(void); +bool ssl_clean_auth_token(void); + void ssl_put_auth_challenge(const char *cr_str); #endif