From patchwork Wed Apr 14 23:12:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maximilian Fillinger X-Patchwork-Id: 1738 X-Patchwork-Delegate: a@unstable.cc Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director12.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net with LMTP id CBl1N/IDeGBfJQAAIUCqbw (envelope-from ) for ; Thu, 15 Apr 2021 05:14:26 -0400 Received: from proxy5.mail.iad3b.rsapps.net ([172.31.255.6]) by director12.mail.ord1d.rsapps.net with LMTP id sJNcN/IDeGBmPQAAIasKDg (envelope-from ) for ; Thu, 15 Apr 2021 05:14:26 -0400 Received: from smtp5.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy5.mail.iad3b.rsapps.net with LMTPS id WEejMPIDeGA/OwAA13hMnw (envelope-from ) for ; Thu, 15 Apr 2021 05:14:26 -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: smtp5.gate.iad3b.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: f963e5a8-9dca-11eb-b487-525400155d63-1-1 Received: from [216.105.38.7] ([216.105.38.7:54510] helo=lists.sourceforge.net) by smtp5.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 0B/21-24958-2F308706; Thu, 15 Apr 2021 05:14:26 -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 1lWy49-0006NQ-LV; Thu, 15 Apr 2021 09:13:37 +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 1lWy48-0006Mu-CK for openvpn-devel@lists.sourceforge.net; Thu, 15 Apr 2021 09:13:36 +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: Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: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=Xgo0HuXv4tu5mV3uD6sFkwvz8mBzkv4FpuZoMblkXiU=; b=VvxzFOBz2pst8i6ApSW7SA4MYY /3mxsPZeDiekezyWWrG1yVqRLVpaD//yTv5kBiAVEMCJDFlWi+zVTNshBhFrs551uIbmpXD+4l3jP /pd4Lr1xSg7R0dUEBELZygU/IiHRa1euSXAr8zQvtruso4eDcimu1l/yKiIKBFb7sV8c=; 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:Message-ID:Date:Subject: CC:To:From:Sender:Reply-To: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=Xgo0HuXv4tu5mV3uD6sFkwvz8mBzkv4FpuZoMblkXiU=; b=lOoTWvURbgjLWh3oTI4B+VFknb lxfyFinpFPxHYwcu5dichN5COxvUGK+kX6vhSVY65HdP1sJQZoCUT923IDtCR+3P46VlVIsT5FsV8 /yF8XrUND99K+79ju5USNniYUKHGMoxQtvO6GH98FCZn/7ytwUk5Gy5ckk8DJR/YoXSQ=; 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 1lWy3v-008c5Q-T0 for openvpn-devel@lists.sourceforge.net; Thu, 15 Apr 2021 09:13:36 +0000 From: Max Fillinger To: Date: Thu, 15 Apr 2021 11:12:48 +0200 Message-ID: <20210415091248.18149-1-maximilian.fillinger@foxcrypto.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: 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:message-id:references:mime-version:content-type; bh=Xgo0HuXv4tu5mV3uD6sFkwvz8mBzkv4FpuZoMblkXiU=; b=426HFUO9hXKoyAkZrnQoGOG4YNBEAnYGhS4SIuFvkuHzpsrlEisCZRet76YLyDrKxTygyqcx8en+ 6Tq3y0dSbGLCx5cl5H/yWczm8Pftka2kXLklycuAuxOhmIDtX36MOSpfmfkP4fbErSdmR+jNS9m2 Q6QANIvd3R5Y8bA/ai8Z5EBZhe0YZgEuLIuCBmlQAvk8bzQDJ9dyk+X9n9ajDWvHWvDAVwrA7jMn /cdc9ouxJ1qo7e6WkCLMiRdnjW5sy+6yow/9RvrzQ2WUtx24wS7GF7u6+gmaOD83EEq1DSbHcqkk osSGuPWoPrsLokIffj1RUiJU34/gQk+662E00w== 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: foxcrypto.com] -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 0.1 DKIM_INVALID DKIM or DK signature exists, but is not valid X-Headers-End: 1lWy3v-008c5Q-T0 Subject: [Openvpn-devel] [PATCH v3 1/2] In init_ssl, open the correct CRL path pre-chroot 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: , Cc: a@unstable.cc Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox When using the chroot option, the init_ssl function can be called before entering the chroot or, when OpenVPN receives a SIGHUP, afterwards. This commit ensures that OpenVPN tries to open the correct path for the CRL file in either situation. This commit does not address key and certificate files. For these, the --persist-key option should be used. Signed-off-by: Max Fillinger Acked-by: Antonio Quartulli --- src/openvpn/init.c | 2 +- src/openvpn/misc.c | 11 +++++++++++ src/openvpn/misc.h | 6 ++++++ src/openvpn/options.c | 8 +------- src/openvpn/ssl.c | 21 +++++++++++++++++++-- src/openvpn/ssl.h | 2 +- 6 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/openvpn/init.c b/src/openvpn/init.c index 28d183aa..f18e054a 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -2702,7 +2702,7 @@ do_init_crypto_tls_c1(struct context *c) * Initialize the OpenSSL library's global * SSL context. */ - init_ssl(options, &(c->c1.ks.ssl_ctx)); + init_ssl(options, &(c->c1.ks.ssl_ctx), c->c0 && c->c0->uid_gid_chroot_set); if (!tls_ctx_initialised(&c->c1.ks.ssl_ctx)) { switch (auth_retry_get()) diff --git a/src/openvpn/misc.c b/src/openvpn/misc.c index feaefb3b..650daa0c 100644 --- a/src/openvpn/misc.c +++ b/src/openvpn/misc.c @@ -767,3 +767,14 @@ get_num_elements(const char *string, char delimiter) return element_count; } + +struct buffer +prepend_dir(const char *dir, const char *path, struct gc_arena *gc) +{ + size_t len = strlen(dir) + strlen(PATH_SEPARATOR_STR) + strlen(path) + 1; + struct buffer combined_path = alloc_buf_gc(len, gc); + buf_printf(&combined_path, "%s%s%s", dir, PATH_SEPARATOR_STR, path); + ASSERT(combined_path.len > 0); + + return combined_path; +} diff --git a/src/openvpn/misc.h b/src/openvpn/misc.h index 9b018eb5..d9005353 100644 --- a/src/openvpn/misc.h +++ b/src/openvpn/misc.h @@ -190,4 +190,10 @@ void output_peer_info_env(struct env_set *es, const char *peer_info); int get_num_elements(const char *string, char delimiter); +/** + * Prepend a directory to a path. + */ +struct buffer +prepend_dir(const char *dir, const char *path, struct gc_arena *gc); + #endif /* ifndef MISC_H */ diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 9e61b1e0..9ce12a2b 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -3317,14 +3317,8 @@ check_file_access_chroot(const char *chroot, const int type, const char *file, c { struct gc_arena gc = gc_new(); struct buffer chroot_file; - int len = 0; - - /* Build up a new full path including chroot directory */ - len = strlen(chroot) + strlen(PATH_SEPARATOR_STR) + strlen(file) + 1; - chroot_file = alloc_buf_gc(len, &gc); - buf_printf(&chroot_file, "%s%s%s", chroot, PATH_SEPARATOR_STR, file); - ASSERT(chroot_file.len > 0); + chroot_file = prepend_dir(chroot, file, &gc); ret = check_file_access(type, BSTR(&chroot_file), mode, opt); gc_free(&gc); } diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index d8662d00..1e0e6170 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -584,7 +584,7 @@ tls_ctx_reload_crl(struct tls_root_ctx *ssl_ctx, const char *crl_file, * All files are in PEM format. */ void -init_ssl(const struct options *options, struct tls_root_ctx *new_ctx) +init_ssl(const struct options *options, struct tls_root_ctx *new_ctx, bool in_chroot) { ASSERT(NULL != new_ctx); @@ -702,7 +702,24 @@ init_ssl(const struct options *options, struct tls_root_ctx *new_ctx) /* Read CRL */ if (options->crl_file && !(options->ssl_flags & SSLF_CRL_VERIFY_DIR)) { - tls_ctx_reload_crl(new_ctx, options->crl_file, options->crl_file_inline); + /* If we're running with the chroot option, we may run init_ssl() before + * and after chroot-ing. We can use the crl_file path as-is if we're + * not going to chroot, or if we already are inside the chroot. + * + * If we're going to chroot later, we need to prefix the path of the + * chroot directory to crl_file. + */ + if (!options->chroot_dir || in_chroot || options->crl_file_inline) + { + tls_ctx_reload_crl(new_ctx, options->crl_file, options->crl_file_inline); + } + else + { + struct gc_arena gc = gc_new(); + struct buffer crl_file_buf = prepend_dir(options->chroot_dir, options->crl_file, &gc); + tls_ctx_reload_crl(new_ctx, BSTR(&crl_file_buf), options->crl_file_inline); + gc_free(&gc); + } } /* Once keys and cert are loaded, load ECDH parameters */ diff --git a/src/openvpn/ssl.h b/src/openvpn/ssl.h index 300a70d3..45ebe720 100644 --- a/src/openvpn/ssl.h +++ b/src/openvpn/ssl.h @@ -159,7 +159,7 @@ void free_ssl_lib(void); * Build master SSL context object that serves for the whole of OpenVPN * instantiation */ -void init_ssl(const struct options *options, struct tls_root_ctx *ctx); +void init_ssl(const struct options *options, struct tls_root_ctx *ctx, bool in_chroot); /** @addtogroup control_processor * @{ */