From patchwork Mon Jun 4 17:29:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 342 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director10.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net (Dovecot) with LMTP id U+DmBuMDFlvySgAAIUCqbw for ; Mon, 04 Jun 2018 23:30:43 -0400 Received: from proxy20.mail.iad3b.rsapps.net ([172.31.255.6]) by director10.mail.ord1d.rsapps.net (Dovecot) with LMTP id qgrKAOMDFlv2TwAApN4f7A ; Mon, 04 Jun 2018 23:30:43 -0400 Received: from smtp39.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy20.mail.iad3b.rsapps.net with LMTP id sHGvOOIDFluTCQAAcDxLoQ ; Mon, 04 Jun 2018 23:30:42 -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: smtp39.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; dmarc=none (p=nil; dis=none) header.from=unstable.cc X-Suspicious-Flag: YES X-Classification-ID: d2fdf2b0-6870-11e8-b29e-5254002be87c-1-1 Received: from [216.105.38.7] ([216.105.38.7:27811] helo=lists.sourceforge.net) by smtp39.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id BC/5D-30380-2E3061B5; Mon, 04 Jun 2018 23:30:42 -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 1fQ2fJ-0000N4-Ih; Tue, 05 Jun 2018 03:29:45 +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 1fQ2fI-0000My-SX for openvpn-devel@lists.sourceforge.net; Tue, 05 Jun 2018 03:29:44 +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:Cc: To:From:Sender:Reply-To: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=P18FwWlxsVYqRcqnkRBWrVGtT9jHbjkWNP1zp+zBkTM=; b=dnaz9Sc2zcmjE7bxmzmxMF76KZ dALmrg4MHxmjGfqX/dvW2VC+jp7G8Myn7Lxql8W1QDMOvhZg9/U+CfTFALG3Yv9RzNAHmmVq7Amd2 AKA+AwOEuSAo0VZyu9vkNhsrQ1+GgdoM8nOgYh3iuF5adJekaSMEqlwOp1V9uYOD5XbI=; 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:Cc:To:From:Sender:Reply-To :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=P18FwWlxsVYqRcqnkRBWrVGtT9jHbjkWNP1zp+zBkTM=; b=Izd7FxWhFd1RXhW3VM3eSiSLka LM2A05oJIDzYGH5ERTRCCGnaZUj683RsfbPLXYypIZfgeZyOv3rII7FPEeuz8mdV/I0RjTTK1hN5V iDnaR0hcjeeiWNBYbLnGrlHujQFaDz/ETLlYkTnEC7lQ+cs+D/8Ga6ZHcamg3/cf+NZs=; Received: from s2.neomailbox.net ([5.148.176.60]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) id 1fQ2fG-00543i-Lo for openvpn-devel@lists.sourceforge.net; Tue, 05 Jun 2018 03:29:44 +0000 From: Antonio Quartulli To: openvpn-devel@lists.sourceforge.net Date: Tue, 5 Jun 2018 11:29:02 +0800 Message-Id: <20180605032902.26440-3-a@unstable.cc> In-Reply-To: <20180605032902.26440-1-a@unstable.cc> References: <20180605032902.26440-1-a@unstable.cc> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [5.148.176.60 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1fQ2fG-00543i-Lo Subject: [Openvpn-devel] [PATCH v2 3/3] make tls-crypt a per-connection-block option 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: Antonio Quartulli MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox Similarly to tls-auth, different remotes may use different tls-crypt keys. Allow the user to define a different key in each connection block. If no tls-crypt option is specified in a given connection block, the global one, if any, is used. If persist-key is specified, tls-crypt keys are pre-loaded during startup (same as they were embeeded in the config file) so that later there is no need to access the key files. Trac: #720 Cc: Steffan Karger Signed-off-by: Antonio Quartulli --- v2: - convert tls-crypt keyfile to inline key if persist-key was specified doc/openvpn.8 | 1 + src/openvpn/init.c | 8 +++---- src/openvpn/options.c | 56 +++++++++++++++++++++++++++++++++++-------- src/openvpn/options.h | 4 ++++ 4 files changed, 55 insertions(+), 14 deletions(-) diff --git a/doc/openvpn.8 b/doc/openvpn.8 index 8006ba29..ac7307af 100644 --- a/doc/openvpn.8 +++ b/doc/openvpn.8 @@ -374,6 +374,7 @@ block: .B rport, .B socks\-proxy, .B tls\-auth, +.B tls\-crypt, .B tun\-mtu and .B tun\-mtu\-extra. diff --git a/src/openvpn/init.c b/src/openvpn/init.c index 22a74e36..99b5b12a 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -2529,11 +2529,11 @@ do_init_tls_wrap_key(struct context *c) } /* TLS handshake encryption+authentication (--tls-crypt) */ - if (options->tls_crypt_file) + if (options->ce.tls_crypt_file) { tls_crypt_init_key(&c->c1.ks.tls_wrap_key, - options->tls_crypt_file, - options->tls_crypt_inline, options->tls_server); + options->ce.tls_crypt_file, + options->ce.tls_crypt_inline, options->tls_server); } } @@ -2814,7 +2814,7 @@ do_init_crypto_tls(struct context *c, const unsigned int flags) } /* TLS handshake encryption (--tls-crypt) */ - if (options->tls_crypt_file) + if (options->ce.tls_crypt_file) { to.tls_wrap.mode = TLS_WRAP_CRYPT; to.tls_wrap.opt.key_ctx_bi = c->c1.ks.tls_wrap_key; diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 7357f189..09f094d1 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -1510,6 +1510,7 @@ show_connection_entry(const struct connection_entry *o) SHOW_STR(tls_auth_file); SHOW_PARM(key_direction, keydirection2ascii(o->key_direction, false, true), "%s"); + SHOW_STR(tls_crypt_file); } @@ -1790,8 +1791,6 @@ show_settings(const struct options *o) SHOW_BOOL(push_peer_info); SHOW_BOOL(tls_exit); - SHOW_STR(tls_crypt_file); - #ifdef ENABLE_PKCS11 { int i; @@ -2726,7 +2725,7 @@ options_postprocess_verify_ce(const struct options *options, const struct connec notnull(options->priv_key_file, "private key file (--key) or PKCS#12 file (--pkcs12)"); } } - if (options->tls_auth_file && options->tls_crypt_file) + if (ce->tls_auth_file && ce->tls_crypt_file) { msg(M_USAGE, "--tls-auth and --tls-crypt are mutually exclusive"); } @@ -2875,7 +2874,7 @@ options_postprocess_mutate_ce(struct options *o, struct connection_entry *ce) /* * Set per-connection block tls-auth fields if no other method was defined */ - if (!ce->tls_auth_file) + if (!ce->tls_auth_file && !ce->tls_crypt_file) { ce->tls_auth_file = o->tls_auth_file; ce->tls_auth_file_inline = o->tls_auth_file_inline; @@ -2889,6 +2888,29 @@ options_postprocess_mutate_ce(struct options *o, struct connection_entry *ce) ce->tls_auth_file = INLINE_FILE_TAG; ce->tls_auth_file_inline = (char *)in.data; } + + /* + * Set per-connection block tls-crypt fields if no other method was defined + */ + if (!ce->tls_crypt_file && !ce->tls_auth_file) + { + ce->tls_crypt_file = o->tls_crypt_file; + ce->tls_crypt_inline = o->tls_crypt_inline; + } + + /* pre-cache tls-auth key file if persist-key was specified */ + if (ce->tls_crypt_file && !ce->tls_crypt_inline && o->persist_key) + { + struct buffer in = keyfile_to_buffer(ce->tls_crypt_file, 2048, &o->gc); + ce->tls_crypt_file = INLINE_FILE_TAG; + ce->tls_crypt_inline = (char *)in.data; + } + + /* + * NOTE: after the two blocks above, only one among tls-crypt and tls-auth + * will be set, because it is not allowed by the config parser to have both + * globally assigned. + */ } #ifdef _WIN32 @@ -3312,10 +3334,12 @@ options_postprocess_filechecks(struct options *options) errs |= check_file_access(CHKACC_FILE|CHKACC_INLINE|CHKACC_PRIVATE, ce->tls_auth_file, R_OK, "--tls-auth"); + + errs |= check_file_access(CHKACC_FILE|CHKACC_INLINE|CHKACC_PRIVATE, + ce->tls_crypt_file, R_OK, "--tls-crypt"); + } - errs |= check_file_access(CHKACC_FILE|CHKACC_INLINE|CHKACC_PRIVATE, - options->tls_crypt_file, R_OK, "--tls-crypt"); errs |= check_file_access(CHKACC_FILE|CHKACC_INLINE|CHKACC_PRIVATE, options->shared_secret_file, R_OK, "--secret"); @@ -8071,12 +8095,24 @@ add_option(struct options *options, } else if (streq(p[0], "tls-crypt") && p[1] && !p[3]) { - VERIFY_PERMISSION(OPT_P_GENERAL); - if (streq(p[1], INLINE_FILE_TAG) && p[2]) + VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); + if (permission_mask & OPT_P_GENERAL) + { + if (streq(p[1], INLINE_FILE_TAG) && p[2]) + { + options->tls_crypt_inline = p[2]; + } + options->tls_crypt_file = p[1]; + } + else if (permission_mask & OPT_P_CONNECTION) { - options->tls_crypt_inline = p[2]; + if (streq(p[1], INLINE_FILE_TAG) && p[2]) + { + options->ce.tls_crypt_inline = p[2]; + } + options->ce.tls_crypt_file = p[1]; + } - options->tls_crypt_file = p[1]; } else if (streq(p[0], "key-method") && p[1] && !p[2]) { diff --git a/src/openvpn/options.h b/src/openvpn/options.h index 77c963d2..2c0902a9 100644 --- a/src/openvpn/options.h +++ b/src/openvpn/options.h @@ -135,6 +135,10 @@ struct connection_entry const char *tls_auth_file; const char *tls_auth_file_inline; int key_direction; + + /* Shared secret used for TLS control channel authenticated encryption */ + const char *tls_crypt_file; + const char *tls_crypt_inline; }; struct remote_entry