From patchwork Thu May 20 05:11:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 1827 X-Patchwork-Delegate: a@unstable.cc Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director7.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id kLngAnN8pmAQbwAAIUCqbw (envelope-from ) for ; Thu, 20 May 2021 11:12:51 -0400 Received: from proxy11.mail.ord1d.rsapps.net ([172.30.191.6]) by director7.mail.ord1d.rsapps.net with LMTP id QHygAnN8pmDuNgAAovjBpQ (envelope-from ) for ; Thu, 20 May 2021 11:12:51 -0400 Received: from smtp34.gate.ord1c ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy11.mail.ord1d.rsapps.net with LMTPS id 6HboJmZ8pmAGYQAAgKDEHA (envelope-from ) for ; Thu, 20 May 2021 11:12:38 -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: smtp34.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: d7634790-b97d-11eb-88b7-545200247500-1-1 Received: from [216.105.38.7] ([216.105.38.7:43284] helo=lists.sourceforge.net) by smtp34.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 2D/04-06762-27C76A06; Thu, 20 May 2021 11:12:50 -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 1ljkLF-00045q-71; Thu, 20 May 2021 15:12:05 +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 1ljkLD-00045I-PO for openvpn-devel@lists.sourceforge.net; Thu, 20 May 2021 15:12:03 +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=GQoD5PxNfXGsBjvmTUCXkbDH/EU5Xmbm6g5t3kD3iC0=; b=SXLi8MQI93uI8ZkNMWpprpxqiF 8o+dGM/IG9v6399owemqRTtrjIfwbSBXMONuqyLn0UXr7A1eIKMxx/7JFoftznWCnh/bvF62x7ztE kXs5a0K1gUqBFDYtwFPqKmCW3aP8mhjHpCbR3z8ZI1yB7OGF2B3UVKDupi7aAG0WVHgE=; 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=GQoD5PxNfXGsBjvmTUCXkbDH/EU5Xmbm6g5t3kD3iC0=; b=JiGpe61wC1zdaDREvkCJFSKPg7 OF7j82d+UkrKEPzE1pi4W2Y9v9ckti4XFig9mPjc/l6gY/LOPMOMDnYo1Euy7HDvvPan3Q5FVzDr2 rvuu+hIAeQ53CKDf6b5Cs1LH3vBPzHZm8IKDk1wbnHfUSh3/+oMAO1aZ+eOgCnSLPXA8=; 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 1ljkL5-00GeSm-Ma for openvpn-devel@lists.sourceforge.net; Thu, 20 May 2021 15:12:04 +0000 Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c]) by mail.blinkt.de with smtp (Exim 4.94.2 (FreeBSD)) (envelope-from ) id 1ljkKy-000C2Q-Gx for openvpn-devel@lists.sourceforge.net; Thu, 20 May 2021 17:11:48 +0200 Received: (nullmailer pid 2565638 invoked by uid 10006); Thu, 20 May 2021 15:11:48 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Thu, 20 May 2021 17:11:44 +0200 Message-Id: <20210520151148.2565578-5-arne@rfc2549.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210520151148.2565578-1-arne@rfc2549.org> References: <20210520151148.2565578-1-arne@rfc2549.org> MIME-Version: 1.0 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: 1ljkL5-00GeSm-Ma Subject: [Openvpn-devel] [PATCH v2 5/9] Extracting key_state deferred auth status update into function 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 extract the update of a deferred key status into into own function. Patch v2: Do not ignore auth_deferred_expire. Minor format changes. Signed-off-by: Arne Schwabe Acked-by: Antonio Quartulli --- src/openvpn/ssl_verify.c | 96 ++++++++++++++++++++++++++-------------- 1 file changed, 62 insertions(+), 34 deletions(-) diff --git a/src/openvpn/ssl_verify.c b/src/openvpn/ssl_verify.c index 7992a6eb9..455a5cd1b 100644 --- a/src/openvpn/ssl_verify.c +++ b/src/openvpn/ssl_verify.c @@ -1073,6 +1073,60 @@ key_state_test_auth_control_file(struct auth_deferred_status *ads, bool cached) return ACF_DISABLED; } +/** + * This method takes a key_state and if updates the state + * of the key if it is deferred. + * @param cached If auth control files should be tried to be opened or th + * cached results should be used + * @param ks The key_state to update + */ +static void +update_key_auth_status(bool cached, struct key_state *ks) +{ + if (ks->authenticated == KS_AUTH_FALSE) + { + return; + } + else + { + enum auth_deferred_result auth_plugin = ACF_DISABLED; + enum auth_deferred_result auth_script = ACF_DISABLED; + enum auth_deferred_result auth_man = ACF_DISABLED; + auth_plugin = key_state_test_auth_control_file(&ks->plugin_auth, cached); + auth_script = key_state_test_auth_control_file(&ks->script_auth, cached); +#ifdef ENABLE_MANAGEMENT + auth_man = man_def_auth_test(ks); +#endif + ASSERT(auth_plugin < 4 && auth_script < 4 && auth_man < 4); + + if (auth_plugin == ACF_FAILED || auth_script == ACF_FAILED + || auth_man == ACF_FAILED) + { + ks->authenticated = KS_AUTH_FALSE; + return; + } + else if (auth_plugin == ACF_PENDING || auth_script == ACF_PENDING + || auth_man == ACF_PENDING) + { + if (now > ks->auth_deferred_expire) + { + /* Window to authenticate the key has expired, mark + * the key as unauthenticated */ + ks->authenticated = KS_AUTH_FALSE; + } + } + else + { + /* all auth states (auth_plugin, auth_script, auth_man) + * are either ACF_DISABLED or ACF_SUCCEDED now, which + * translates to "not checked" or "auth succeeded" + */ + ks->authenticated = KS_AUTH_TRUE; + } + } +} + + /** * The minimum times to have passed to update the cache. Older versions * of OpenVPN had code path that did not do any caching, so we start @@ -1115,46 +1169,20 @@ tls_authentication_status(struct tls_multi *multi) if (TLS_AUTHENTICATED(multi, ks)) { active++; + update_key_auth_status(cached, ks); + if (ks->authenticated == KS_AUTH_FALSE) { failed_auth = true; } - else + else if (ks->authenticated == KS_AUTH_DEFERRED) { - enum auth_deferred_result auth_plugin = ACF_DISABLED; - enum auth_deferred_result auth_script = ACF_DISABLED; - enum auth_deferred_result auth_man = ACF_DISABLED; - auth_plugin = key_state_test_auth_control_file(&ks->plugin_auth, cached); - auth_script = key_state_test_auth_control_file(&ks->script_auth, cached); -#ifdef ENABLE_MANAGEMENT - auth_man = man_def_auth_test(ks); -#endif - ASSERT(auth_plugin < 4 && auth_script < 4 && auth_man < 4); - if (auth_plugin == ACF_FAILED || auth_script == ACF_FAILED - || auth_man == ACF_FAILED) - { - ks->authenticated = KS_AUTH_FALSE; - failed_auth = true; - } - else if (auth_plugin == ACF_PENDING - || auth_script == ACF_PENDING - || auth_man == ACF_PENDING) - { - if (now < ks->auth_deferred_expire) - { - deferred = true; - } - } - else - { - /* all auth states (auth_plugin, auth_script, auth_man) - * are either ACF_DISABLED or ACF_SUCCEDED now, which - * translates to "not checked" or "auth succeeded" - */ - success = true; - ks->authenticated = KS_AUTH_TRUE; - } + deferred = true; + } + else if (ks->authenticated == KS_AUTH_TRUE) + { + success = true; } } }