From patchwork Wed Aug 24 04:08:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 2721 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director7.mail.ord1d.rsapps.net ([172.28.255.1]) by backend30.mail.ord1d.rsapps.net with LMTP id wAThGDwxBmN0OgAAIUCqbw (envelope-from ) for ; Wed, 24 Aug 2022 10:10:04 -0400 Received: from proxy5.mail.ord1c.rsapps.net ([172.28.255.1]) by director7.mail.ord1d.rsapps.net with LMTP id kPC7GDwxBmNiHAAAovjBpQ (envelope-from ) for ; Wed, 24 Aug 2022 10:10:04 -0400 Received: from smtp21.gate.ord1c ([172.28.255.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy5.mail.ord1c.rsapps.net with LMTPS id SGVsGDwxBmNgKgAAPBRIyg (envelope-from ) for ; Wed, 24 Aug 2022 10:10:04 -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: smtp21.gate.ord1c.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: 72b43d46-23b6-11ed-93b6-a0369f0d8808-1-1 Received: from [216.105.38.7] ([216.105.38.7:39990] helo=lists.sourceforge.net) by smtp21.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id A3/81-05315-B3136036; Wed, 24 Aug 2022 10:10:04 -0400 Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1oQr46-0002Gd-RK; Wed, 24 Aug 2022 14:09:06 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1oQr44-0002GW-Pv for openvpn-devel@lists.sourceforge.net; Wed, 24 Aug 2022 14:09:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: 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=Y0fkLVWV5r8w8/FLdlDvLgxurjOPckm3zwqNOlT9GnM=; b=lQRoZlQYI+1aqwXAqlb5QhDGj2 22BBAs00/3XAkyo3+JUhppQJrQIrODPb7Fpq32HimaDN3cBi8wVEF45jLKhjetyE937ygprHMEdjH 6tElUB0shjxTttvwN3oQ02AxaJqKB3Ck/Dww6vOVpNQqYEmYU0Fwdlx7eqOS9Ygq2RI0=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: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=Y0fkLVWV5r8w8/FLdlDvLgxurjOPckm3zwqNOlT9GnM=; b=jMDaPtqGYjXWsK2MOa3BMzc5as WoZolxRl9IaGy6gEPJOEHMgqN7FylV+RbH9kVFqXX5hD0mqs7uARD7tIb6VXosN+yPzFHDMF7lAWR 65T2zV8yNihmRpSYxbXlBFUXRLaTBMB29Ul62ZKrHkQDkDy6JIKa0aiBb0Q4ZHzPAZjM=; Received: from mail.blinkt.de ([192.26.174.232]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1oQr3v-0005Q0-Gv for openvpn-devel@lists.sourceforge.net; Wed, 24 Aug 2022 14:09:04 +0000 Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c]) by mail.blinkt.de with smtp (Exim 4.95 (FreeBSD)) (envelope-from ) id 1oQr3o-00056B-UX for openvpn-devel@lists.sourceforge.net; Wed, 24 Aug 2022 16:08:48 +0200 Received: (nullmailer pid 88059 invoked by uid 10006); Wed, 24 Aug 2022 14:08:48 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Wed, 24 Aug 2022 16:08:48 +0200 Message-Id: <20220824140848.88013-1-arne@rfc2549.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220520213250.3126372-1-arne@rfc2549.org> References: <20220520213250.3126372-1-arne@rfc2549.org> MIME-Version: 1.0 X-Spam-Report: Spam detection software, running on the system "util-spamd-1.v13.lw.sourceforge.com", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This is currently only possible when using the management interface and the client-deny functionality. Patch v3: add missing gc_free Signed-off-by: Arne Schwabe --- src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_verify.c | 74 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 73 insertions(+), 2 deletions( [...] Content analysis details: (0.3 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-Headers-End: 1oQr3v-0005Q0-Gv Subject: [Openvpn-devel] [PATCH v3 4/4] Allow scripts and plugins to set a custom AUTH_FAILED message 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: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox This is currently only possible when using the management interface and the client-deny functionality. Patch v3: add missing gc_free Signed-off-by: Arne Schwabe Acked-by: Heiko Hund --- src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_verify.c | 74 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/src/openvpn/ssl_common.h b/src/openvpn/ssl_common.h index bf3ac67a5..f1cade2ef 100644 --- a/src/openvpn/ssl_common.h +++ b/src/openvpn/ssl_common.h @@ -155,6 +155,7 @@ struct auth_deferred_status { char *auth_control_file; char *auth_pending_file; + char *auth_failed_reason_file; unsigned int auth_control_status; }; diff --git a/src/openvpn/ssl_verify.c b/src/openvpn/ssl_verify.c index b4608517f..76cb9f19b 100644 --- a/src/openvpn/ssl_verify.c +++ b/src/openvpn/ssl_verify.c @@ -989,6 +989,12 @@ key_state_rm_auth_control_files(struct auth_deferred_status *ads) free(ads->auth_control_file); ads->auth_control_file = NULL; } + if (ads->auth_failed_reason_file) + { + platform_unlink(ads->auth_failed_reason_file); + free(ads->auth_failed_reason_file); + ads->auth_failed_reason_file = NULL; + } key_state_rm_auth_pending_file(ads); } @@ -1007,19 +1013,47 @@ key_state_gen_auth_control_files(struct auth_deferred_status *ads, key_state_rm_auth_control_files(ads); const char *acf = platform_create_temp_file(opt->tmp_dir, "acf", &gc); const char *apf = platform_create_temp_file(opt->tmp_dir, "apf", &gc); + const char *afr = platform_create_temp_file(opt->tmp_dir, "afr", &gc); if (acf && apf) { ads->auth_control_file = string_alloc(acf, NULL); ads->auth_pending_file = string_alloc(apf, NULL); + ads->auth_failed_reason_file = string_alloc(afr, NULL); + setenv_str(opt->es, "auth_control_file", ads->auth_control_file); setenv_str(opt->es, "auth_pending_file", ads->auth_pending_file); + setenv_str(opt->es, "auth_failed_reason_file", ads->auth_failed_reason_file); } gc_free(&gc); return (acf && apf); } +/** + * Checks if the auth failed reason file has any content and if yes it will + * be returned as string allocated in gc to the caller. + */ +static char * +key_state_check_auth_failed_message_file(const struct auth_deferred_status *ads, + struct tls_multi *multi, + struct gc_arena *gc) +{ + char *ret = NULL; + if (ads->auth_failed_reason_file) + { + struct buffer reason = buffer_read_from_file(ads->auth_failed_reason_file, gc); + + if (BLEN(&reason)) + { + ret = BSTR(&reason); + } + + } + return ret; +} + + /** * Checks the auth control status from a file. The function will try * to read and update the cached status if the status is still pending @@ -1184,12 +1218,27 @@ tls_authentication_status(struct tls_multi *multi) #endif if (failed_auth) { + struct gc_arena gc = gc_new(); + const struct key_state *ks = get_primary_key(multi); + const char *plugin_message = key_state_check_auth_failed_message_file(&ks->plugin_auth, multi, &gc); + const char *script_message = key_state_check_auth_failed_message_file(&ks->script_auth, multi, &gc); + + if (plugin_message) + { + auth_set_client_reason(multi, plugin_message); + } + if (script_message) + { + auth_set_client_reason(multi, script_message); + } + /* We have at least one session that failed authentication. There * might be still another session with valid keys. * Although our protocol allows keeping the VPN session alive * with the other session (and we actually did that in earlier * version, this behaviour is really strange from a user (admin) * experience */ + gc_free(&gc); return TLS_AUTHENTICATION_FAILED; } else if (success) @@ -1248,6 +1297,21 @@ tls_authenticate_key(struct tls_multi *multi, const unsigned int mda_key_id, con * this is the place to start. *************************************************************************** */ +/** + * Check if the script/plugin left a message in the auth failed message + * file and relay it to the user */ +static void +check_for_client_reason(struct tls_multi *multi, + struct auth_deferred_status *status) +{ + struct gc_arena gc = gc_new(); + const char *msg = key_state_check_auth_failed_message_file(status, multi, &gc); + if (msg) + { + auth_set_client_reason(multi, msg); + } + gc_free(&gc); +} /* * Verify the user name and password using a script */ @@ -1316,6 +1380,7 @@ verify_user_pass_script(struct tls_session *session, struct tls_multi *multi, break; default: + check_for_client_reason(multi, &ks->script_auth); retval = OPENVPN_PLUGIN_FUNC_ERROR; break; } @@ -1450,10 +1515,15 @@ verify_user_pass_plugin(struct tls_session *session, struct tls_multi *multi, if (!key_state_check_auth_pending_file(&ks->plugin_auth, multi)) { retval = OPENVPN_PLUGIN_FUNC_ERROR; - key_state_rm_auth_control_files(&ks->plugin_auth); } } - else + + if (retval == OPENVPN_PLUGIN_FUNC_ERROR) + { + check_for_client_reason(multi, &ks->plugin_auth); + } + + if (retval != OPENVPN_PLUGIN_FUNC_DEFERRED) { /* purge auth control filename (and file itself) for non-deferred returns */ key_state_rm_auth_control_files(&ks->plugin_auth);