From patchwork Mon Apr 12 06:45:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maximilian Fillinger X-Patchwork-Id: 1734 X-Patchwork-Delegate: a@unstable.cc Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director10.mail.ord1d.rsapps.net ([172.27.255.8]) by backend30.mail.ord1d.rsapps.net with LMTP id cNizA755dGASIQAAIUCqbw (envelope-from ) for ; Mon, 12 Apr 2021 12:47:58 -0400 Received: from proxy17.mail.iad3a.rsapps.net ([172.27.255.8]) by director10.mail.ord1d.rsapps.net with LMTP id 4CuqA755dGCMIwAApN4f7A (envelope-from ) for ; Mon, 12 Apr 2021 12:47:58 -0400 Received: from smtp49.gate.iad3a ([172.27.255.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy17.mail.iad3a.rsapps.net with LMTPS id UMbuNr15dGA1XQAAR4KW9A (envelope-from ) for ; Mon, 12 Apr 2021 12:47:57 -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: smtp49.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; dkim=fail (key not found in DNS) header.d=foxcrypto.com; dmarc=fail (p=none; dis=none) header.from=foxcrypto.com X-Suspicious-Flag: YES X-Classification-ID: d4e55248-9bae-11eb-bad8-525400fffce0-1-1 Received: from [216.105.38.7] ([216.105.38.7:52560] helo=lists.sourceforge.net) by smtp49.gate.iad3a.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id B0/E6-21271-CB974706; Mon, 12 Apr 2021 12:47:57 -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 1lVziU-0007K9-1U; Mon, 12 Apr 2021 16:47:14 +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 1lVziN-0007Ij-6R for openvpn-devel@lists.sourceforge.net; Mon, 12 Apr 2021 16:47:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:MIME-Version:References:In-Reply-To: Date:Subject:CC:To:From:Sender:Reply-To:Message-ID: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=jBp2o0opDLc7qhkbJ0b2oZBwKoQ+Stbp21cFSzIR1b4=; b=eStoJ504HId/kMqX4xRJFKxFLW IefjUsdyqPD6HtnmQfUTOMJFoj5b9a7qkaTm+vSTMAwgPYBP8UAsH1QisIttzobZFK8BsgrwQfPwO SD0FDQG/UR+EniFXQqjFFxDAr9EsKfu1Cx/LX5qr9mf0wzL8R53+EMvRx63/Oik3RdmY=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:MIME-Version:References:In-Reply-To:Date:Subject:CC:To:From: Sender:Reply-To:Message-ID: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=jBp2o0opDLc7qhkbJ0b2oZBwKoQ+Stbp21cFSzIR1b4=; b=Wcd+cp22KQCeCu/AxH12fNZuQX CQbVdT9+zwT0ao2bx9hhd1a+mNlAyjKspo3YFv/KyPq+5S7CemTomZltw+KBzw6hmiGCFTic+05Et 8o3qby41L0XJBc+wDld7hte+3YDLoFvopCj7L09a1CCtEz/ZjBfyo8ncp8TM33Xnke1s=; Received: from nl-dft-mx-01.fox-it.com ([178.250.144.135]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1lVzi4-00Armm-KB for openvpn-devel@lists.sourceforge.net; Mon, 12 Apr 2021 16:47:07 +0000 From: Max Fillinger To: Date: Mon, 12 Apr 2021 18:45:45 +0200 X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210412164545.11151-1-maximilian.fillinger@foxcrypto.com> References: <20210412164545.11151-1-maximilian.fillinger@foxcrypto.com> MIME-Version: 1.0 X-ClientProxiedBy: FOXDFT1EX01.FOX.local (10.0.0.129) To FOXDFT1EX01.FOX.local (10.0.0.129) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; d=foxcrypto.com; s=NL-DFT-MX-01; c=relaxed/relaxed; h=from:to:cc:subject:date:references:mime-version:content-type; bh=jBp2o0opDLc7qhkbJ0b2oZBwKoQ+Stbp21cFSzIR1b4=; b=AhECuErgxsoTqScy+edtn27ZNCcaMNBLU8VUAZp4kz6fQ/OzxZuUYKD+8JFMEU682gCbrPiopNe7 M8MO9W80Wei+obk3hCVwvjYo5yQVqeB2jYhByte11LfCQ4dBhmVtsi2Q/lzkLO4nC0Fn/EvPUwUV UwH0IcCvA5rGdZ/viyDGPTFjGS9o3SnjTJu7j5M8Zymv2e+mS3zNRMbvSrE94ZJzShrtxfdwtMYe 4Q40rv+UI1pnzaPo5PUn0yNRKLK6InAP8+wGatKwOro0jUqqlSlBcJq04uvP6NhutptgDr3UjJsG s3OaW6DP5MOltY7yxhjN+fQsJHLfv9E1DGOeLw== X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 1.0 MISSING_MID Missing Message-Id: header 0.1 DKIM_INVALID DKIM or DK signature exists, but is not valid X-Headers-End: 1lVzi4-00Armm-KB Subject: [Openvpn-devel] [PATCH v2 2/2] Abort if CRL file can't be stat-ed in init_ssl 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 Message-Id: X-getmail-retrieved-from-mailbox: Inbox Now that the path for the CRL file is handled correctly when using chroot, there's no good reason for the file to be inaccessible during init_ssl(). This commit ensures that the CRL file is accessed successfully at least once, which fixes a bug where the mbedtls version of OpenVPN wouldn't use a reloaded CRL if it initially failed to access the file. In tls_process(), we stick with the previous behavior of logging a warning and keeping the old CRL to ensure that the CRL file can be updated on-the-fly. Signed-off-by: Max Fillinger --- src/openvpn/ssl.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 8782b140..a42b639c 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -539,10 +539,14 @@ tls_version_parse(const char *vstr, const char *extra) * @param crl_file The file name to load the CRL from, or * "[[INLINE]]" in the case of inline files. * @param crl_inline A string containing the CRL + * @param abort_on_err If this is true, OpenVPN exits if it can't stat + * the CRL file. If it is false, it will instead + * log a warning and continue using the previously + * loaded CRL. */ static void tls_ctx_reload_crl(struct tls_root_ctx *ssl_ctx, const char *crl_file, - bool crl_file_inline) + bool crl_file_inline, bool abort_on_err) { /* if something goes wrong with stat(), we'll store 0 as mtime */ platform_stat_t crl_stat = {0}; @@ -559,7 +563,14 @@ tls_ctx_reload_crl(struct tls_root_ctx *ssl_ctx, const char *crl_file, } else if (platform_stat(crl_file, &crl_stat) < 0) { - msg(M_WARN, "WARNING: Failed to stat CRL file, not (re)loading CRL."); + if (abort_on_err) + { + msg(M_FATAL, "ERROR: Failed to stat CRL file during init_ssl, exiting."); + } + else + { + msg(M_WARN, "WARNING: Failed to stat CRL file, not (re)loading CRL."); + } return; } @@ -710,13 +721,13 @@ init_ssl(const struct options *options, struct tls_root_ctx *new_ctx, bool in_ch * chroot directory to crl_file. */ if (options->chroot_dir == NULL || in_chroot || options->crl_file_inline) { - tls_ctx_reload_crl(new_ctx, options->crl_file, options->crl_file_inline); + tls_ctx_reload_crl(new_ctx, options->crl_file, options->crl_file_inline, true); } else { struct gc_arena gc = gc_new(); struct buffer crl_file_buf = prepend_chroot(options->chroot_dir, options->crl_file, &gc); - tls_ctx_reload_crl(new_ctx, BSTR(&crl_file_buf), options->crl_file_inline); + tls_ctx_reload_crl(new_ctx, BSTR(&crl_file_buf), options->crl_file_inline, true); gc_free(&gc); } } @@ -2752,7 +2763,7 @@ tls_process(struct tls_multi *multi, && !(session->opt->ssl_flags & SSLF_CRL_VERIFY_DIR)) { tls_ctx_reload_crl(&session->opt->ssl_ctx, - session->opt->crl_file, session->opt->crl_file_inline); + session->opt->crl_file, session->opt->crl_file_inline, false); } /* New connection, remove any old X509 env variables */