From patchwork Wed Mar 17 02:03:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 1618 X-Patchwork-Delegate: gert@greenie.muc.de Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director12.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id gFKJNWn+UWCYZwAAIUCqbw (envelope-from ) for ; Wed, 17 Mar 2021 09:04:41 -0400 Received: from proxy12.mail.ord1d.rsapps.net ([172.30.191.6]) by director12.mail.ord1d.rsapps.net with LMTP id MOVQNWn+UWCkBQAAIasKDg (envelope-from ) for ; Wed, 17 Mar 2021 09:04:41 -0400 Received: from smtp9.gate.ord1d ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy12.mail.ord1d.rsapps.net with LMTPS id YLAZNWn+UWBoYQAA7PHxkg (envelope-from ) for ; Wed, 17 Mar 2021 09:04:41 -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: smtp9.gate.ord1d.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: 555119be-8721-11eb-b2c6-525400bd3b1f-1-1 Received: from [216.105.38.7] ([216.105.38.7:47480] helo=lists.sourceforge.net) by smtp9.gate.ord1d.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 3F/BA-05275-86EF1506; Wed, 17 Mar 2021 09:04:40 -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.90_1) (envelope-from ) id 1lMVpp-0005Ne-47; Wed, 17 Mar 2021 13:03:37 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMVpi-0005Mr-WE for openvpn-devel@lists.sourceforge.net; Wed, 17 Mar 2021 13:03:31 +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=9oE7HZtkk3H3VNL8Q4CxvDC1pfFWjk1OdMVzYn1MQTI=; b=mhf8VRb26+9m27PGNo2zgzgci0 Mhj36XJoqsfKgh0k0GYo2ZvMrnS7Z1ogVwgdljwfdtBy82aHj+AQ65ZCC/FRHCu5MhELJVnR60tg1 ASbpkKb+Fl9r2Tx3254IflnJK94KO6VLE9omjNLDX1oAeAYH5eC1Iyo8jfD9tMN0TCBE=; 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=9oE7HZtkk3H3VNL8Q4CxvDC1pfFWjk1OdMVzYn1MQTI=; b=hKhhqUizw1w83N3hQxQXFMA0b4 +eIXjHZIOTD80CVmSF8YYexdZscHjdVbywMvqGx2TcTMm+hVBT9pXq+JSJ7OnQr0FM5r5G3wL1H4F qzegcLZNKIyw2c3KSbhGZ4TLjKaVLzbqS/+VulCK4AJS/LYI7CNItpvVdUz5NU8G+EPo=; Received: from mail.blinkt.de ([192.26.174.232]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) id 1lMVpd-0004O0-95 for openvpn-devel@lists.sourceforge.net; Wed, 17 Mar 2021 13:03:30 +0000 Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c]) by mail.blinkt.de with smtp (Exim 4.94 (FreeBSD)) (envelope-from ) id 1lMVpQ-000FwF-P5 for openvpn-devel@lists.sourceforge.net; Wed, 17 Mar 2021 14:03:12 +0100 Received: (nullmailer pid 8634 invoked by uid 10006); Wed, 17 Mar 2021 13:03:12 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Wed, 17 Mar 2021 14:03:11 +0100 Message-Id: <20210317130312.8585-1-arne@rfc2549.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210310154754.GH976@greenie.muc.de> References: <20210310154754.GH976@greenie.muc.de> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: rfc2549.org] 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: 1lMVpd-0004O0-95 Subject: [Openvpn-devel] [PATCH v5 1/2] Move auth deferred related members into its own struct 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 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 Acked-by: Gert Doering --- 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(-) diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 893e5753..b6c553be 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -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) { diff --git a/src/openvpn/ssl_common.h b/src/openvpn/ssl_common.h index 2e3c98db..0773376e 100644 --- a/src/openvpn/ssl_common.h +++ b/src/openvpn/ssl_common.h @@ -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_state unsigned 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 */ diff --git a/src/openvpn/ssl_verify.c b/src/openvpn/ssl_verify.c index 4b120f7b..c9983d66 100644 --- a/src/openvpn/ssl_verify.c +++ b/src/openvpn/ssl_verify.c @@ -870,13 +870,13 @@ man_def_auth_test(const struct key_state *ks) * and key_state structure */ static void -key_state_rm_auth_pending_file(struct key_state *ks) +key_state_rm_auth_pending_file(struct auth_deferred_status *ads) { - if (ks && ks->auth_pending_file) + if (ads && ads->auth_pending_file) { - platform_unlink(ks->auth_pending_file); - free(ks->auth_pending_file); - ks->auth_pending_file = NULL; + platform_unlink(ads->auth_pending_file); + free(ads->auth_pending_file); + ads->auth_pending_file = NULL; } } @@ -921,13 +921,13 @@ check_auth_pending_method(const char *peer_info, const char *method) * @returns false The file had an invlaid format or another error occured */ static bool -key_state_check_auth_pending_file(struct key_state *ks, +key_state_check_auth_pending_file(struct auth_deferred_status *ads, struct tls_multi *multi) { bool ret = true; - if (ks && ks->auth_pending_file) + if (ads->auth_pending_file) { - struct buffer_list *lines = buffer_list_file(ks->auth_pending_file, + struct buffer_list *lines = buffer_list_file(ads->auth_pending_file, 1024); if (lines && lines->head) { @@ -977,7 +977,7 @@ key_state_check_auth_pending_file(struct key_state *ks, buffer_list_free(lines); } - key_state_rm_auth_pending_file(ks); + key_state_rm_auth_pending_file(ads); return ret; } @@ -987,15 +987,15 @@ key_state_check_auth_pending_file(struct key_state *ks, * and key_state structure */ void -key_state_rm_auth_control_files(struct key_state *ks) +key_state_rm_auth_control_files(struct auth_deferred_status *ads) { - if (ks && ks->auth_control_file) + if (ads->auth_control_file) { - platform_unlink(ks->auth_control_file); - free(ks->auth_control_file); - ks->auth_control_file = NULL; + platform_unlink(ads->auth_control_file); + free(ads->auth_control_file); + ads->auth_control_file = NULL; } - key_state_rm_auth_pending_file(ks); + key_state_rm_auth_pending_file(ads); } /** @@ -1005,20 +1005,21 @@ key_state_rm_auth_control_files(struct key_state *ks) * @return true if file creation was successful */ static bool -key_state_gen_auth_control_files(struct key_state *ks, const struct tls_options *opt) +key_state_gen_auth_control_files(struct auth_deferred_status *ads, + const struct tls_options *opt) { struct gc_arena gc = gc_new(); - key_state_rm_auth_control_files(ks); + 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); if (acf && apf) { - ks->auth_control_file = string_alloc(acf, NULL); - ks->auth_pending_file = string_alloc(apf, NULL); - setenv_str(opt->es, "auth_control_file", ks->auth_control_file); - setenv_str(opt->es, "auth_pending_file", ks->auth_pending_file); + ads->auth_control_file = string_alloc(acf, NULL); + ads->auth_pending_file = string_alloc(apf, NULL); + setenv_str(opt->es, "auth_control_file", ads->auth_control_file); + setenv_str(opt->es, "auth_pending_file", ads->auth_pending_file); } gc_free(&gc); @@ -1026,14 +1027,14 @@ key_state_gen_auth_control_files(struct key_state *ks, const struct tls_options } static unsigned int -key_state_test_auth_control_file(struct key_state *ks) +key_state_test_auth_control_file(struct auth_deferred_status *ads) { - if (ks && ks->auth_control_file) + if (ads->auth_control_file) { - unsigned int ret = ks->auth_control_status; + unsigned int ret = ads->auth_control_status; if (ret == ACF_UNDEFINED) { - FILE *fp = fopen(ks->auth_control_file, "r"); + FILE *fp = fopen(ads->auth_control_file, "r"); if (fp) { const int c = fgetc(fp); @@ -1046,7 +1047,7 @@ key_state_test_auth_control_file(struct key_state *ks) ret = ACF_FAILED; } fclose(fp); - ks->auth_control_status = ret; + ads->auth_control_status = ret; } } return ret; @@ -1088,7 +1089,7 @@ tls_authentication_status(struct tls_multi *multi, const int latency) { unsigned int s1 = ACF_DISABLED; unsigned int s2 = ACF_DISABLED; - s1 = key_state_test_auth_control_file(ks); + s1 = key_state_test_auth_control_file(&ks->plugin_auth); #ifdef ENABLE_MANAGEMENT s2 = man_def_auth_test(ks); #endif @@ -1267,7 +1268,7 @@ verify_user_pass_plugin(struct tls_session *session, struct tls_multi *multi, setenv_str(session->opt->es, "password", up->password); /* generate filename for deferred auth control file */ - if (!key_state_gen_auth_control_files(ks, session->opt)) + if (!key_state_gen_auth_control_files(&ks->plugin_auth, session->opt)) { msg(D_TLS_ERRORS, "TLS Auth Error (%s): " "could not create deferred auth control file", __func__); @@ -1281,16 +1282,16 @@ verify_user_pass_plugin(struct tls_session *session, struct tls_multi *multi, { /* Check if the plugin has written the pending auth control * file and send the pending auth to the client */ - if(!key_state_check_auth_pending_file(ks, multi)) + if(!key_state_check_auth_pending_file(&ks->plugin_auth, multi)) { retval = OPENVPN_PLUGIN_FUNC_ERROR; - key_state_rm_auth_control_files(ks); + key_state_rm_auth_control_files(&ks->plugin_auth); } } else { /* purge auth control filename (and file itself) for non-deferred returns */ - key_state_rm_auth_control_files(ks); + key_state_rm_auth_control_files(&ks->plugin_auth); } setenv_del(session->opt->es, "password"); diff --git a/src/openvpn/ssl_verify.h b/src/openvpn/ssl_verify.h index 0221e81f..874d2dcb 100644 --- a/src/openvpn/ssl_verify.h +++ b/src/openvpn/ssl_verify.h @@ -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. From patchwork Wed Mar 17 02:03:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 1617 X-Patchwork-Delegate: gert@greenie.muc.de Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director10.mail.ord1d.rsapps.net ([172.27.255.50]) by backend30.mail.ord1d.rsapps.net with LMTP id eFlILGn+UWDzaAAAIUCqbw (envelope-from ) for ; Wed, 17 Mar 2021 09:04:41 -0400 Received: from proxy3.mail.iad3a.rsapps.net ([172.27.255.50]) by director10.mail.ord1d.rsapps.net with LMTP id CKbkK2n+UWATEwAApN4f7A (envelope-from ) for ; Wed, 17 Mar 2021 09:04:41 -0400 Received: from smtp12.gate.iad3a ([172.27.255.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy3.mail.iad3a.rsapps.net with LMTPS id IGWkJmn+UWBHbgAAYaqY3Q (envelope-from ) for ; Wed, 17 Mar 2021 09:04:41 -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: smtp12.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: 55594b66-8721-11eb-97cd-525400068c1c-1-1 Received: from [216.105.38.7] ([216.105.38.7:41720] helo=lists.sourceforge.net) by smtp12.gate.iad3a.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id D9/C9-09933-86EF1506; Wed, 17 Mar 2021 09:04:41 -0400 Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.92.3) (envelope-from ) id 1lMVpl-0002QP-1c; Wed, 17 Mar 2021 13:03:33 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) (envelope-from ) id 1lMVpi-0002QG-VZ for openvpn-devel@lists.sourceforge.net; Wed, 17 Mar 2021 13:03:31 +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=o64159PWUkDxwcTjKcFDUzhJtPJWJKwrxiRcTdMHgnA=; b=XlG3mO0JXAAzNeiugbf+GAPcbb xdmN+kMEQ0B1qL7qHumgfRiB23IYFQMcKiD2L0MoD7tyJ6r4/g4CB99q7gK0MGozc2ay/b8YLYTi8 uvTNwSdhw3rBpbuyoPxBlFXMdGCtT8DmFyrTuSKF0Q/0WTJHXj8d+jv+7E6oZ00qSRmY=; 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=o64159PWUkDxwcTjKcFDUzhJtPJWJKwrxiRcTdMHgnA=; b=K81croH7JKYjJ2K9intw9e2PKO obfot2E9T5v/fVlJlriL42Iy8lVnEwsJj/M7mfFdRWxToZAV2mL/Nb2GRL/9oWlhRbR+76MJt4ha5 QLZ8rU4YSltI/l/6y8loDqf10R4WVjjdFduDA+0wGym9fgCcX8eGiJbXUzSZMEPV4rls=; 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.92.2) id 1lMVpb-00AXmg-N3 for openvpn-devel@lists.sourceforge.net; Wed, 17 Mar 2021 13:03:30 +0000 Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c]) by mail.blinkt.de with smtp (Exim 4.94 (FreeBSD)) (envelope-from ) id 1lMVpQ-000FwI-S1 for openvpn-devel@lists.sourceforge.net; Wed, 17 Mar 2021 14:03:12 +0100 Received: (nullmailer pid 8637 invoked by uid 10006); Wed, 17 Mar 2021 13:03:12 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Wed, 17 Mar 2021 14:03:12 +0100 Message-Id: <20210317130312.8585-2-arne@rfc2549.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210317130312.8585-1-arne@rfc2549.org> References: <20210310154754.GH976@greenie.muc.de> <20210317130312.8585-1-arne@rfc2549.org> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: totpauth.py] 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: 1lMVpb-00AXmg-N3 Subject: [Openvpn-devel] [PATCH v5 2/2] Implement deferred auth for scripts 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 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 Signed-off-by: Arne Schwabe --- 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(-) diff --git a/Changes.rst b/Changes.rst index d6be1050..ddfacdbe 100644 --- a/Changes.rst +++ b/Changes.rst @@ -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 ========================== diff --git a/doc/man-sections/script-options.rst b/doc/man-sections/script-options.rst index 03b3dd77..22990f4f 100644 --- a/doc/man-sections/script-options.rst +++ b/doc/man-sections/script-options.rst @@ -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. diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index b6c553be..08b95bc3 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -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) { diff --git a/src/openvpn/ssl_common.h b/src/openvpn/ssl_common.h index 0773376e..6c6e5073 100644 --- a/src/openvpn/ssl_common.h +++ b/src/openvpn/ssl_common.h @@ -222,6 +222,7 @@ struct key_state time_t acf_last_mod; struct auth_deferred_status plugin_auth; + struct auth_deferred_status script_auth; }; /** Control channel wrapping (--tls-auth/--tls-crypt) context */ diff --git a/src/openvpn/ssl_verify.c b/src/openvpn/ssl_verify.c index c9983d66..c32bc927 100644 --- a/src/openvpn/ssl_verify.c +++ b/src/openvpn/ssl_verify.c @@ -1087,20 +1087,25 @@ tls_authentication_status(struct tls_multi *multi, const int latency) } else { - unsigned int s1 = ACF_DISABLED; - unsigned int s2 = ACF_DISABLED; - s1 = key_state_test_auth_control_file(&ks->plugin_auth); + unsigned int auth_plugin = ACF_DISABLED; + unsigned int auth_script = ACF_DISABLED; + unsigned int auth_man = ACF_DISABLED; + auth_plugin = key_state_test_auth_control_file(&ks->plugin_auth); + auth_script = key_state_test_auth_control_file(&ks->script_auth); #ifdef ENABLE_MANAGEMENT - s2 = man_def_auth_test(ks); + auth_man = man_def_auth_test(ks); #endif - ASSERT(s1 < 4 && s2 < 4); + ASSERT(auth_plugin < 4 && auth_script < 4 && auth_man < 4); - if (s1 == ACF_FAILED || s2 == ACF_FAILED) + if (auth_plugin == ACF_FAILED || auth_script == ACF_FAILED + || auth_man == ACF_FAILED) { ks->authenticated = KS_AUTH_FALSE; failed_auth = true; } - else if (s1 == ACF_UNDEFINED || s2 == ACF_UNDEFINED) + else if (auth_plugin == ACF_UNDEFINED + || auth_script == ACF_UNDEFINED + || auth_man == ACF_UNDEFINED) { if (now < ks->auth_deferred_expire) { @@ -1109,7 +1114,7 @@ tls_authentication_status(struct tls_multi *multi, const int latency) } else { - /* s1 and s2 are either ACF_DISABLED or ACF_SUCCEDED */ + /* auth_plugin and auth_man are either ACF_DISABLED or ACF_SUCCEDED */ success = true; ks->authenticated = KS_AUTH_TRUE; } @@ -1189,14 +1194,15 @@ tls_authenticate_key(struct tls_multi *multi, const unsigned int mda_key_id, con /* * Verify the user name and password using a script */ -static bool +static int verify_user_pass_script(struct tls_session *session, struct tls_multi *multi, const struct user_pass *up) { struct gc_arena gc = gc_new(); struct argv argv = argv_new(); const char *tmp_file = ""; - bool ret = false; + int retval = OPENVPN_PLUGIN_FUNC_ERROR; + struct key_state *ks = &session->key[KS_PRIMARY]; /* primary key */ /* Set environmental variables prior to calling script */ setenv_str(session->opt->es, "script_type", "user-pass-verify"); @@ -1224,25 +1230,58 @@ verify_user_pass_script(struct tls_session *session, struct tls_multi *multi, /* pass temp file name to script */ argv_printf_cat(&argv, "%s", tmp_file); } - else - { - msg(D_TLS_ERRORS, "TLS Auth Error: could not create write " - "username/password to temp file"); - } } else { + setenv_str(session->opt->es, "username", up->username); setenv_str(session->opt->es, "password", up->password); } + /* generate filename for deferred auth control file */ + if (!key_state_gen_auth_control_files(&ks->script_auth, session->opt)) + { + msg(D_TLS_ERRORS, "TLS Auth Error (%s): " + "could not create deferred auth control file", __func__); + return OPENVPN_PLUGIN_FUNC_ERROR; + } + /* call command */ - ret = openvpn_run_script(&argv, session->opt->es, 0, - "--auth-user-pass-verify"); + int script_ret = openvpn_run_script(&argv, session->opt->es, S_EXITCODE, + "--auth-user-pass-verify"); + switch (script_ret) + { + case 0: + retval = OPENVPN_PLUGIN_FUNC_SUCCESS; + break; + case 2: + retval = OPENVPN_PLUGIN_FUNC_DEFERRED; + break; + default: + retval = OPENVPN_PLUGIN_FUNC_ERROR; + break; + } + if (retval == OPENVPN_PLUGIN_FUNC_DEFERRED) + { + /* Check if we the plugin has written the pending auth control + * file and send the pending auth to the client */ + if(!key_state_check_auth_pending_file(&ks->script_auth, + multi)) + { + retval = OPENVPN_PLUGIN_FUNC_ERROR; + key_state_rm_auth_control_files(&ks->script_auth); + } + } + else + { + /* purge auth control filename (and file itself) for non-deferred returns */ + key_state_rm_auth_control_files(&ks->script_auth); + } if (!session->opt->auth_user_pass_verify_script_via_file) { setenv_del(session->opt->es, "password"); } + done: if (tmp_file && strlen(tmp_file) > 0) { @@ -1251,7 +1290,7 @@ done: argv_free(&argv); gc_free(&gc); - return ret; + return retval; } /* @@ -1372,8 +1411,6 @@ void verify_user_pass(struct user_pass *up, struct tls_multi *multi, struct tls_session *session) { - int s1 = OPENVPN_PLUGIN_FUNC_SUCCESS; - bool s2 = true; struct key_state *ks = &session->key[KS_PRIMARY]; /* primary key */ #ifdef ENABLE_MANAGEMENT @@ -1433,30 +1470,32 @@ verify_user_pass(struct user_pass *up, struct tls_multi *multi, } } + int plugin_status = OPENVPN_PLUGIN_FUNC_SUCCESS; + int script_status = OPENVPN_PLUGIN_FUNC_SUCCESS; /* Set the environment variables used by all auth variants */ if (!set_verify_user_pass_env(up, multi, session)) { skip_auth = true; - s1 = OPENVPN_PLUGIN_FUNC_ERROR; + plugin_status = OPENVPN_PLUGIN_FUNC_ERROR; } /* call plugin(s) and/or script */ if (!skip_auth) { #ifdef ENABLE_MANAGEMENT - if (man_def_auth==KMDA_DEF) + if (man_def_auth == KMDA_DEF) { man_def_auth = verify_user_pass_management(session, multi, up); } #endif if (plugin_defined(session->opt->plugins, OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY)) { - s1 = verify_user_pass_plugin(session, multi, up); + plugin_status = verify_user_pass_plugin(session, multi, up); } if (session->opt->auth_user_pass_verify_script) { - s2 = verify_user_pass_script(session, multi, up); + script_status = verify_user_pass_script(session, multi, up); } } @@ -1467,19 +1506,25 @@ verify_user_pass(struct user_pass *up, struct tls_multi *multi, msg(D_TLS_ERRORS, "TLS Auth Error: --username-as-common name specified and username is longer than the maximum permitted Common Name length of %d characters", TLS_USERNAME_LEN); - s1 = OPENVPN_PLUGIN_FUNC_ERROR; + plugin_status = OPENVPN_PLUGIN_FUNC_ERROR; + script_status = OPENVPN_PLUGIN_FUNC_ERROR; } /* auth succeeded? */ - if ((s1 == OPENVPN_PLUGIN_FUNC_SUCCESS - || s1 == OPENVPN_PLUGIN_FUNC_DEFERRED - ) && s2 + bool plugin_ok = plugin_status == OPENVPN_PLUGIN_FUNC_SUCCESS + || plugin_status == OPENVPN_PLUGIN_FUNC_DEFERRED; + + bool script_ok = script_status == OPENVPN_PLUGIN_FUNC_SUCCESS + || script_status == OPENVPN_PLUGIN_FUNC_DEFERRED; + + if (script_ok && plugin_ok && tls_lock_username(multi, up->username) #ifdef ENABLE_MANAGEMENT && man_def_auth != KMDA_ERROR #endif - && tls_lock_username(multi, up->username)) + ) { ks->authenticated = KS_AUTH_TRUE; - if (s1 == OPENVPN_PLUGIN_FUNC_DEFERRED) + if (plugin_status == OPENVPN_PLUGIN_FUNC_DEFERRED + || script_status == OPENVPN_PLUGIN_FUNC_DEFERRED) { ks->authenticated = KS_AUTH_DEFERRED; }