From patchwork Mon Nov 11 01:59:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "flichtenheld (Code Review)" X-Patchwork-Id: 3926 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:41ba:b0:5d9:9f4c:3bc7 with SMTP id a26csp2277987mad; Sun, 10 Nov 2024 18:00:04 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW5MnTXFtIvr6mH1SOqDtpEdCLQ6F3VPs6BuUbQyKg0Uvf6JzQoHRTFHvXzMN5mEPi4IezSforB6us=@openvpn.net X-Google-Smtp-Source: AGHT+IF/Xp3GlMp18cmAT8uCpNy74ZYstjWtzi/Sn9itNocMuY8RZITlLS0h1CHG7GMqcKBSHHSq X-Received: by 2002:a05:6808:2a03:b0:3e7:a201:db0f with SMTP id 5614622812f47-3e7a201dc40mr1649909b6e.25.1731290404263; Sun, 10 Nov 2024 18:00:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1731290404; cv=none; d=google.com; s=arc-20240605; b=dBGsd7v++LJFaCjEzLMg9daO0SQatJ6YiTO0XXXfpkfeDED6Xch3lai7hWNyMlfPow jXV/PFHx81YfmvVKEvA3pVi9wJDILgZ6QAr00BFRO5Z5LULO28sK2wF+dy+FIglYCkhL nBHNJpaHk1jV7uZ3tZtP7Th+GjSyqAntj5wZvYeCSDa/cMZZPx4GDc7RfRKrSWgqpwfD Y8s414aGlgYEsDV06WLuchSq0St8wZcHZqxBT5VeDUqfMklZu3SkasAZKyH4e+nKhkMb 2EUlw+poLX2muxeNNcOu3si2CHlxpmNPj5XVY1VlyXAyqBWLKfT0TXG0Xuf7FpOFxgZS 7TuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:cc:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:user-agent :mime-version:message-id:references:auto-submitted:to:date:from :dkim-signature:dkim-signature:dkim-signature; bh=B475xMeLpC8OqJEQDY5qXwFIv9TS75DNz+J/J7doE9w=; fh=lm0MLPW7DntlrDqRECIiC9JlE1uPxhepE0URYHIf+eE=; b=MMVu9WiqgPCPuU7JDie8Ats5WfhGyguLSaCDbn5rWo1gYZqYje8LzTlztW8a1nYTrD TL2C+OXQsxo5Hp0tMgCY3Ta8WWzeFodcN+eUAESC+F22aegN7Fwei8V3btfC5f81jD4B EXUHu6ngC669a/C/LEbOWAzXsi2FBAEHcBsCcYUXxfJZAWNj+8YGt4plI+Bez2AuZhhh S5Eg4Eou4lDwQIJc+zoOA9Xq1isrSrmwmOsKSvEffJuTROHdOKt/4wBupJlmLpyNX06H +F9GPIREPpUdtCONK4bP6dxL3iTRvFIO8dE3gfkuU4ElxKxvRZf/heVfDIJ8e65SjW2H dRmg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=bothlyZ5; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=Hsp8XkgK; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=CwuTmbqj; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=openvpn.net; dara=fail header.i=@openvpn.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 5614622812f47-3e78cd59423si241481b6e.228.2024.11.10.18.00.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Nov 2024 18:00:04 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=bothlyZ5; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=Hsp8XkgK; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=CwuTmbqj; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=openvpn.net; dara=fail header.i=@openvpn.net 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.95) (envelope-from ) id 1tAJiY-0003SB-Rn; Mon, 11 Nov 2024 01:59:50 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1tAJiX-0003S5-4R for openvpn-devel@lists.sourceforge.net; Mon, 11 Nov 2024 01:59:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:Content-Transfer-Encoding:MIME-Version :Message-ID:Reply-To:References:Subject:List-Unsubscribe:List-Id:Cc:To:Date: From:Sender:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:List-Help: List-Subscribe:List-Post:List-Owner:List-Archive; bh=+TNBpkGajvJrkIlW7pp3L+cGcuNPnLG0ljNRteK7BvU=; b=bothlyZ5liU3aEWL/xY9kGSdqk hcc6BZtuRMckE/RtoA2gs/VQhWofEqwJ9mCw8KIRDepn1Hpgb8s7YMwO0PxsQbDpXNgpw5yQkTZXe BZPxm7kJXh9/CHejDRTejexLn9Ad903vrxu+JnUcwChAn6A5mLKNELldRM5sj37UNWUs=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Reply-To: References:Subject:List-Unsubscribe:List-Id:Cc:To:Date:From:Sender:Content-ID :Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To: Resent-Cc:Resent-Message-ID:In-Reply-To:List-Help:List-Subscribe:List-Post: List-Owner:List-Archive; bh=+TNBpkGajvJrkIlW7pp3L+cGcuNPnLG0ljNRteK7BvU=; b=H sp8XkgKieooh2NMTiXPTIKckLeqf9FxZFwPq1Bfw9vKnUTXiBZWevqcsdH73htiA8s7btw/X7ZeYG A461BgiWr3wXhkki/5Ek1/Nfqg72rNPdIvlNQlLakMIYnfXxcbU6K0336GH0yobU0StBrd5/9iSvp nCAe2LycN32sCF/A=; Received: from mail-wm1-f46.google.com ([209.85.128.46]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1tAJiV-0001YD-Qw for openvpn-devel@lists.sourceforge.net; Mon, 11 Nov 2024 01:59:49 +0000 Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-43169902057so32062015e9.0 for ; Sun, 10 Nov 2024 17:59:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvpn.net; s=google; t=1731290381; x=1731895181; darn=lists.sourceforge.net; h=user-agent:content-disposition:content-transfer-encoding :mime-version:message-id:reply-to:references:subject :list-unsubscribe:list-id:auto-submitted:cc:to:date:from:from:to:cc :subject:date:message-id:reply-to; bh=+TNBpkGajvJrkIlW7pp3L+cGcuNPnLG0ljNRteK7BvU=; b=CwuTmbqjwTc/LAIlIoBq3NWP4FXDbJ1/QujwS9OEcjlzF3vPAT4CuIzmkOzr1WLQ8A dFmvHIinwS5R6wC2yC70VPtGulzVmcsIMNVI1MxlJeA+fBw1eEMdfXIi6pEtDmPWqRT3 UMeIR70BYGMpuCfRDHgqi3nAYQEFEmbb+r6d58u3EFR/YXh23mHCAMr6vyNni79F0nmE ruKFBLuMqXC7nqLCHKIgLZ9Rd8J9XSQz7E4UHdjNRKfqBiW0LYiNv+10P4arFKjC+3sp EN6Vood+o5Woonnsq8CN+vWpDkYNgGHSuA09c8M3e4r4+DgxvwtLUXJ81O0QTglFwU64 aAsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731290381; x=1731895181; h=user-agent:content-disposition:content-transfer-encoding :mime-version:message-id:reply-to:references:subject :list-unsubscribe:list-id:auto-submitted:cc:to:date:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+TNBpkGajvJrkIlW7pp3L+cGcuNPnLG0ljNRteK7BvU=; b=ZtkDHJ9lo4W5K9vAuupbQQphAmB44wJJxuqstspDlOfg7jkTvj7F5C1oOWpUaTGH/T vvasWZN4LowHhhfSyvN2MbAbk5fChxh8wwChv9FxYQGXDJqeXBFGUyIXreh0TMHmZX3B EXOu2ghgiYxPSVedjmv5oykt9Uv0wy4LXJDW4Q5XbzYLlkNfHgKztajguCk72dQKasuw vOltuSFQrCkD/+vJwV3NqxPaIgqwvVk5jLDI1q2/4LbE+gkj2ZsBnI3gDiW9adBlXvtF kB/uLP51pVkOVD5KuFtI5eSbJnU4qckphBb993AfgNcZ3CkkeiR+2gYLmw0fjEW0IXqn TdQA== X-Gm-Message-State: AOJu0YxeVoIZlbOJUwtdTZb68YTRLRQCKgqMnIEudxy5FcDpoudQwicJ ihfl6qNhkaWPpHqYPNiSKaFl/F2ycMjxH4GPCc21epM2MRDNUelmcV4En5DKtBPrrzF+a2B16Nq c X-Received: by 2002:a05:600c:5124:b0:431:60ec:7a91 with SMTP id 5b1f17b1804b1-432b74fcbecmr87585535e9.2.1731290381015; Sun, 10 Nov 2024 17:59:41 -0800 (PST) Received: from gerrit.openvpn.in (ec2-18-159-0-78.eu-central-1.compute.amazonaws.com. [18.159.0.78]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381eda04136sm11563242f8f.97.2024.11.10.17.59.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Nov 2024 17:59:39 -0800 (PST) From: "plaisthos (Code Review)" X-Google-Original-From: "plaisthos (Code Review)" X-Gerrit-PatchSet: 1 Date: Mon, 11 Nov 2024 01:59:38 +0000 To: flichtenheld Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange X-Gerrit-Change-Id: I210fa255921e7115bd66ba5f3e431562552e3335 X-Gerrit-Change-Number: 794 X-Gerrit-Project: openvpn X-Gerrit-ChangeURL: X-Gerrit-Commit: 55014333fe63c9dc53ed6de21a430d2fa9494d43 References: Message-ID: <086667eab23225deb6e15a4c533c97f3893fa01a-HTML@gerrit.openvpn.net> MIME-Version: 1.0 User-Agent: Gerrit/3.8.2 X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-2.v13.lw.sourceforge.com", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Attention is currently required from: flichtenheld. Hello flichtenheld, I'd like you to do a code review. Please visit Content analysis details: (-0.9 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.128.46 listed in list.dnswl.org] -0.7 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.128.46 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 WEIRD_PORT URI: Uses non-standard port number for HTTP 0.0 HTML_MESSAGE BODY: HTML included in message -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -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_EF Message has a valid DKIM or DK signature from envelope-from domain 0.0 T_KAM_HTML_FONT_INVALID Test for Invalidly Named or Formatted Colors in HTML X-Headers-End: 1tAJiV-0001YD-Qw Subject: [Openvpn-devel] [S] Change in openvpn[master]: Move should_trigger_renegotiation into its own 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: , Reply-To: arne-openvpn@rfc2549.org, openvpn-devel@lists.sourceforge.net, frank@lichtenheld.com Cc: openvpn-devel Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1815389566808160519?= X-GMAIL-MSGID: =?utf-8?q?1815389566808160519?= X-getmail-filter-classifier: gerrit message type newchange Attention is currently required from: flichtenheld. Hello flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/794?usp=email to review the following change. Change subject: Move should_trigger_renegotiation into its own function ...................................................................... Move should_trigger_renegotiation into its own function The if statement has become quite large and unreadable. Reformat it and move it to a separate function. Change-Id: I210fa255921e7115bd66ba5f3e431562552e3335 Signed-off-by: Arne Schwabe --- M src/openvpn/ssl.c 1 file changed, 36 insertions(+), 8 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/94/794/1 diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 93e31f1..c48a85c 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -2962,8 +2962,42 @@ return true; } +/** + * Determines if a renegotiation should be triggerred based on the various + * factors that can trigger one + */ +static bool +should_trigger_renegotiation(const struct tls_session *session, const struct key_state *ks) +{ + /* Time limit */ + if (session->opt->renegotiate_seconds + && now >= ks->established + session->opt->renegotiate_seconds) + { + return true; + } + /* Byte limit */ + if (session->opt->renegotiate_bytes > 0 + && ks->n_bytes >= session->opt->renegotiate_bytes) + { + return true; + } + /* Packet limit */ + if (session->opt->renegotiate_packets + && ks->n_packets >= session->opt->renegotiate_packets) + { + return true; + } + + /* Packet id approach the limit of the packet id */ + if (packet_id_close_to_wrapping(&ks->crypto_options.packet_id.send)) + { + return true; + } + + return false; +} /* * This is the primary routine for processing TLS stuff inside the * the main event loop. When this routine exits @@ -2991,14 +3025,8 @@ /* Should we trigger a soft reset? -- new key, keeps old key for a while */ if (ks->state >= S_GENERATED_KEYS - && ((session->opt->renegotiate_seconds - && now >= ks->established + session->opt->renegotiate_seconds) - || (session->opt->renegotiate_bytes > 0 - && ks->n_bytes >= session->opt->renegotiate_bytes) - || (session->opt->renegotiate_packets - && ks->n_packets >= session->opt->renegotiate_packets) - || (packet_id_close_to_wrapping(&ks->crypto_options.packet_id.send)))) - { + && should_trigger_renegotiation(session, ks)) + { msg(D_TLS_DEBUG_LOW, "TLS: soft reset sec=%d/%d bytes=" counter_format "/%d pkts=" counter_format "/%d", (int) (now - ks->established), session->opt->renegotiate_seconds,