From patchwork Mon Nov 11 07:43:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 3939 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:41ba:b0:5d9:9f4c:3bc7 with SMTP id a26csp2382759mad; Sun, 10 Nov 2024 23:44:20 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUu7aMJFnR3BR/cHXySKZYyUHausOWOvvm7F8QLwA8T07Y0Rd7VypRLCy4ZvxE5j/r+OJXDPFwyWkE=@openvpn.net X-Google-Smtp-Source: AGHT+IGgCg5xqlr1hSLReR6azWFNXQHA3Kzeim9NSu7U3jqvhJ781H2wWraC83WeaAi719RglnNc X-Received: by 2002:a05:6830:65c3:b0:718:7c3:f86a with SMTP id 46e09a7af769-71a1c1f1886mr11035219a34.6.1731311060466; Sun, 10 Nov 2024 23:44:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1731311060; cv=none; d=google.com; s=arc-20240605; b=Lie9ZEDnQBwUBAduXnVdZcigp2R4a0P2PhoTrjifFvPFmK0QsPfpyjErrR1pk90VvL ux898BcgdOKnthc79f/lBQhMrDgXf6wSTJdr5gb15/sTohk/PLI8zS8+czSgZ9z2ZqhS ltZ8KKccl8XxDE/k5hWo7PQL+aoKpHe2AesX3P3VluHRn0IRBRri2ha0r62X10LyUm7/ C5qgPJnI2BeVSdtLvr5OVleGKcoqUwZqHfUpU9IetMMFzCCiMTMoIaS3n/DX6XjBQrYG 8NZL5qCw4CsnJEqRbhNZH1ojG9OmhCALMoE4nqowTyg76xFYPOikd7hgvUiInIswW9kF UOqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature; bh=SHRF/979dfz2PlqZ0NXNpBIaabJQ1bBGDW3x01Odas8=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=g4g+lM5oFYWqNwXCousGLXg75AKxthzPhjQDMkaImeXmQNYu7YDzcaHM0+6f+YeukN xHyj3aS8ELkQcf1muX/AHskQuhK+9/Smh5XMDtldqyuSQ2ZCTIi5TSxlA+aUrnsrCLio FnUX2znCzRSphotdCiR5+1/nTSqZtKEwmHuRs6Go+JYL3b/iUIjWw24s7m3NDX6a8KsE bxA4GA9QxneO8/vO41ZUE+UySF8sbeUvA3a42bVwUkL4I4epevzu3fJ+oWIA5bMtEFR0 JYSDP4GCn5WEsJ/Ojm+fLpL+2P+mSaHzazHvWVzEiP55RCeyKl9AeTDDYaeqaMqCDuZz VNNA==; 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=llwN2itJ; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=mlKBUZnu; 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=muc.de Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 46e09a7af769-71a109ab446si5463712a34.275.2024.11.10.23.44.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Nov 2024 23:44:20 -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=llwN2itJ; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=mlKBUZnu; 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=muc.de Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1tAP5o-0000JI-56; Mon, 11 Nov 2024 07:44:12 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1tAP5m-0000Iy-4U for openvpn-devel@lists.sourceforge.net; Mon, 11 Nov 2024 07:44:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: 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=PmCU61rrOBuH8VCvdKRQ5VRa7tAuULS8gyEvmBhMIqE=; b=llwN2itJ7RZ8SmejTcZvWnbB8z PIWaFlOtWIXUgXnouwc6b4i5vVCWRLXTTgSySvsKrgitJtrexHCcfVICN6eNMBao4RoPi0gCtvgu2 XYCH+1FOSS6Lmv5xJMNlRLwiEftOAFq4uEWj85nlQ9hgIEjPKZrpPKkgT8EU0qH6W8o8=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: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=PmCU61rrOBuH8VCvdKRQ5VRa7tAuULS8gyEvmBhMIqE=; b=mlKBUZnu+Xa9zIA9lIwfxc0TFy 9Lb4JzUhMOKrT9v2CardoK5+1IuhIt0uomnNUfwrlYP6sQ3Eq9s7gGbJqQl0iMiNBad34YjaQFE5N fIa3Up03XSWuczcJUJsjltgbib5CSnHTjVYohV20HUzhilcnPT4pkurDkJiOV8hxRVgQ=; Received: from dhcp-174.greenie.muc.de ([193.149.48.174] helo=blue.greenie.muc.de) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1tAP5k-0007A5-1f for openvpn-devel@lists.sourceforge.net; Mon, 11 Nov 2024 07:44:10 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.17.1.9/8.17.1.9) with ESMTP id 4AB7huiF017940 for ; Mon, 11 Nov 2024 08:43:56 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.17.1.9/8.17.1.9/Submit) id 4AB7hurW017939 for openvpn-devel@lists.sourceforge.net; Mon, 11 Nov 2024 08:43:56 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Mon, 11 Nov 2024 08:43:55 +0100 Message-ID: <20241111074355.17918-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: -0.0 (/) 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: From: Arne Schwabe 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 Acked-by: Gert Doering --- Content analysis details: (-0.0 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record X-Headers-End: 1tAP5k-0007A5-1f Subject: [Openvpn-devel] [PATCH v1] 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: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1815411226107476743?= X-GMAIL-MSGID: =?utf-8?q?1815411226107476743?= From: Arne Schwabe 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 Acked-by: Gert Doering --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/794 This mail reflects revision 1 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering 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,