From patchwork Thu Sep 20 03:12:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lev Stipakov X-Patchwork-Id: 467 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director11.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id 0DjuEpudo1sbSwAAIUCqbw for ; Thu, 20 Sep 2018 09:16:11 -0400 Received: from proxy12.mail.ord1d.rsapps.net ([172.30.191.6]) by director11.mail.ord1d.rsapps.net with LMTP id gD0gE5udo1sKXQAAvGGmqA ; Thu, 20 Sep 2018 09:16:11 -0400 Received: from smtp22.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 LMTP id 2Fp5Epudo1tiRgAA7PHxkg ; Thu, 20 Sep 2018 09:16:11 -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: smtp22.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; dkim=fail (signature verification failed) header.d=gmail.com; dmarc=fail (p=none; dis=none) header.from=gmail.com X-Suspicious-Flag: YES X-Classification-ID: 575abe34-bcd7-11e8-a488-5254001a15c2-1-1 Received: from [216.105.38.7] ([216.105.38.7:43692] helo=lists.sourceforge.net) by smtp22.gate.ord1d.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id D2/68-13550-A9D93AB5; Thu, 20 Sep 2018 09:16:11 -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 1g2ynN-00012s-1h; Thu, 20 Sep 2018 13:15:01 +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 1g2ynM-00012l-9W for openvpn-devel@lists.sourceforge.net; Thu, 20 Sep 2018 13:15:00 +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=0MY3nIbMIrRzX+fzT5FgFq+XAglfwQStfJjAT4DA1WE=; b=kiYTjXeSI/gfzuGDENMxj4E4n1 cs/KiE+q/JUHCC3lNUksdKQtIhkAgCmiqofA3E4Y6rdyiQfq5E+37ts1hTFKektaS2j96ZXjyRKIQ hBiNHzCvqK3frCO0MYeops1w2uKwPUh3dEjuqIhkdFogni4Y0dZ7pPdwxR3wMr2yrQR8=; 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=0MY3nIbMIrRzX+fzT5FgFq+XAglfwQStfJjAT4DA1WE=; b=AYu76tnTOjhLUUxM7JDisjMYIt 9QMEd1lvCCgX9rHCrEQfZunMrlzSUpdO7zLco1P+5RZrHIBBMXu4keN6QLV0s2ECjueX+FrpUqvC5 miq/lGSa6RykiPRpQNdkGkj7RrpyaHHyeA5Z3PiRTKvxtrMrZpmFRUKYp25o50pQNE6g=; Received: from mail-ed1-f51.google.com ([209.85.208.51]) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) id 1g2ynK-0036y3-Ld for openvpn-devel@lists.sourceforge.net; Thu, 20 Sep 2018 13:15:00 +0000 Received: by mail-ed1-f51.google.com with SMTP id j62-v6so7794388edd.7 for ; Thu, 20 Sep 2018 06:14:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=0MY3nIbMIrRzX+fzT5FgFq+XAglfwQStfJjAT4DA1WE=; b=Pxddc/W8/qIOOIHY1vUwYC0+CRQvdzpkFaDmv/hVyHcOc/1HWo+1hBTxlHqjjA01PU JlrsLraJrzB62BpBhowP6fdfZAHUnc9GNOGfBFk5iR+teXLK4XqP3td5RBLduAXO6xnL i/5iRDVwUVsDEKOUYAOgkyZykqNC1Sgx2e+u4ZRcK4tm+sy1xmVpziLFhfULjrttBstZ i3wuEejmJU5pRhqszLsjcdn3Vkpj8EhoUY3hdGMEt+0Yt40sXa0VQiM9/ysLPj6YmszO 5L+uObYsye5/hURROYnJzIsG1BTCn+Iln1jN8cYFkL9dgYjW+kUE1CirITClvRqwdl28 RHyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=0MY3nIbMIrRzX+fzT5FgFq+XAglfwQStfJjAT4DA1WE=; b=K9NpSLbbYN/qwCDr+lTgnf/qctZtR94cZYWABys2z3SeH2MiWBYWZBq4Ec5UKyuNrF sRb1lLRnkL6x/8GSkbWvaE/BMsFdP+/6LVRh4lqClctJpqp/jkgUjupjj4NATZf4y2J7 fr/n2spC3xlDUaWqSENNjPpl7UB4AOU2DUMHfCiDymp8ZGcUVMIDdgOciK8zkZQwZlXL 8RGb43nBNsDKbekesLDLU0oDmGEa768+m9cWr4EX8bF5SbqMGO9xCMrFehQRf7Yj8xe6 6smQ5YrpNUdsyGCfR01LlurWbDke+2jGRC+9dlGrcpYoeIKPv9Ch06v8IPB0bupISQAa Y8Iw== X-Gm-Message-State: APzg51AyfFhxn7PsM09TEd7pHl5YP9dq0sO96HshHRwBrtgd4axYQOmK yjqvjZ1TuTx6A9OpxwkQ6VaqWfb07GY= X-Google-Smtp-Source: ANB0VdaFodfq2i8UFwDMnz8eoBJ2dWK/YJF6+EGqRdrFc7vWshr4zjZttedvlwOBZFb07UocbQuT4Q== X-Received: by 2002:a50:9174:: with SMTP id f49-v6mr4424833eda.279.1537449291752; Thu, 20 Sep 2018 06:14:51 -0700 (PDT) Received: from stipakov.fi (stipakov.fi. [128.199.52.117]) by smtp.gmail.com with ESMTPSA id m42-v6sm771194edd.46.2018.09.20.06.14.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Sep 2018 06:14:51 -0700 (PDT) From: Lev Stipakov To: openvpn-devel@lists.sourceforge.net Date: Thu, 20 Sep 2018 16:12:34 +0300 Message-Id: <1537449154-26879-1-git-send-email-lstipakov@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: 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 [209.85.208.51 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (lstipakov[at]gmail.com) -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.208.51 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1g2ynK-0036y3-Ld Subject: [Openvpn-devel] [PATCH v2] Refactor NCP-negotiable options handling 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 From: Lev Stipakov NCP negotiation can alter options. On reconnect client sends possibly altered options while server expects original values. This leads to warnings in log and, if server uses --opt-verify, breaks reconnect. Fix by decouple setting/unsetting NCP options from the state of TLS context. At startup (and once per sighup) we load original values to c->c1, which persists over sigusr1 (restart). When tearing tunnel down we restore (possibly altered) options back to original values. Trac: #1105 Signed-off-by: Lev Stipakov Acked-by: Steffan Karger --- v2: refined commit message src/openvpn/init.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/src/openvpn/init.c b/src/openvpn/init.c index f432106..9353527 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -612,6 +612,33 @@ uninit_proxy(struct context *c) uninit_proxy_dowork(c); } +/* + * Assign NCP-negotiable options to context->c1 + * from context->options (initially config values). + * They persist over sigusr1 restart. + */ +static void +do_set_ncp_options(struct context *c) +{ + c->c1.ciphername = c->options.ciphername; + c->c1.authname = c->options.authname; + c->c1.keysize = c->options.keysize; +} + +/* + * Restore NCP-negotiable options from c->c1 to + * c->options. The latter ones can be altered by + * pushed options and therefore need to be restored + * to original values on sigusr1 restart. + */ +static void +do_unset_ncp_options(struct context *c) +{ + c->options.ciphername = c->c1.ciphername; + c->options.authname = c->c1.authname; + c->options.keysize = c->c1.keysize; +} + void context_init_1(struct context *c) { @@ -621,6 +648,8 @@ context_init_1(struct context *c) init_connection_list(c); + do_set_ncp_options(c); + #if defined(ENABLE_PKCS11) if (c->first_time) { @@ -2593,10 +2622,6 @@ do_init_crypto_tls_c1(struct context *c) /* initialize tls-auth/crypt key */ do_init_tls_wrap_key(c); - c->c1.ciphername = options->ciphername; - c->c1.authname = options->authname; - c->c1.keysize = options->keysize; - #if 0 /* was: #if ENABLE_INLINE_FILES -- Note that enabling this code will break restarts */ if (options->priv_key_file_inline) { @@ -2609,11 +2634,6 @@ do_init_crypto_tls_c1(struct context *c) { msg(D_INIT_MEDIUM, "Re-using SSL/TLS context"); - /* Restore pre-NCP cipher options */ - c->options.ciphername = c->c1.ciphername; - c->options.authname = c->c1.authname; - c->options.keysize = c->c1.keysize; - /* * tls-auth/crypt key can be configured per connection block, therefore * we must reload it as it may have changed @@ -4293,6 +4313,8 @@ close_instance(struct context *c) /* free key schedules */ do_close_free_key_schedule(c, (c->mode == CM_P2P || c->mode == CM_TOP)); + do_unset_ncp_options(c); + /* close TCP/UDP connection */ do_close_link_socket(c);