From patchwork Wed May 17 11:02:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 3222 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7300:7b9a:b0:c3:1364:a2a2 with SMTP id j26csp1094154dyk; Wed, 17 May 2023 04:03:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4r9p+81qt28r0jr7UTOT38JssU5/6eohe0fV/oOx7LG6fnpe9dshft4AXlp4AbykirIzhe X-Received: by 2002:a92:d188:0:b0:335:e716:93fc with SMTP id z8-20020a92d188000000b00335e71693fcmr1757308ilz.6.1684321393901; Wed, 17 May 2023 04:03:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684321393; cv=none; d=google.com; s=arc-20160816; b=bd5U0ZtrjO/cyGYFGU3D4l4W0Q8L5R0WrS0yHcQmvC2NjUlYf/YV7cv3alx60/eV7j O07z0+594tCakFmh90Lf7sKdmBA6z8FSb79GWO8wLo1UYA/WJNCLxoxSTZjLYZb2JorZ c/4njdbTfbeJQ2tAC+f7nLOHzHS5oFN2prdUcWPU/XRzhETbjUo5USL92hdXvLh5kztS A+1Px1YLlnsBeR8yaljk91q3XEAfvXWRW5pL6NpcfWVa4owyQSJXKb5ZwUCCExtVUXWb ncPCjQ/C0s4z94QzRkrkVsYmV05fXA1irOGig074Dbk+uRUy3EsAgUkQwDbQT8ETwcOL SJzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:message-id:date:to:from:dkim-signature:dkim-signature; bh=NvKHJSupsZ46IQVeau3c8E09xfXT6LfBK6ADRq8Rzq8=; b=WDZqRFvbwfQR9bXbFtj/6FNEaRNKxstKev+MqUNvdsDPzGqCNinfGbdqf+8ieliLwa AwRfYw86gUxqpUjM56n6PBqZ147RNRGYG+L0cYIEOidi5GngYsZEXm+oJRVOUz9HIO7o ADsnajflKCShg07gH8Bk3IkGY+NFovQ1oVLdKh4ReP1utyPMudrFzWlMlqzPp4sjEn/K k50jSvy6acYeamytBJEJRL57TIJOuoeap6CPYq+mNFk0/RzFZyYS6ZG3C0FIRZsjBtOQ J3VrxJGP2mtaRMPn7+odhQLX+9RpQVvAkAZDHmaTWvb+y15oZffqvk8r3k8iESdtlhEf EHjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=dnJRK5VW; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=iz4y3HWW; 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 Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id x2-20020a92b002000000b0032b7232dacesi15839467ilh.45.2023.05.17.04.03.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 May 2023 04:03:13 -0700 (PDT) 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=dnJRK5VW; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=iz4y3HWW; 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 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.95) (envelope-from ) id 1pzEvZ-0002Ja-1Y; Wed, 17 May 2023 11:02:41 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pzEvW-0002JI-Fo for openvpn-devel@lists.sourceforge.net; Wed, 17 May 2023 11:02:39 +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: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:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=zDH4TdHpNCyQJ5xuC08xUyUr4laGuALCQonDH6n+TuA=; b=dnJRK5VWIdDRqeN2U8ZCxLmnS7 h7brg7zhG+q9DSRlAipEWnnCA/xGLcn5G43P7uaYIDdhGIjkd9OnjlOGjSEzmebVfR/2aY/lUsoYS MomGeAYFjB3KXuDaEMaVvSI1Bc/QBwU3dHVoP+4dHYFM2gKtURdC8Y30q6RHpX6rwLts=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version: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:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=zDH4TdHpNCyQJ5xuC08xUyUr4laGuALCQonDH6n+TuA=; b=i z4y3HWWHJeP2tRZVUzPOsXwWVgh3Bvc7wVLPAqgD1UTJqsWsMgB1dSYshQi7Wia+2T2RvYFnmK/H+ zVDbYPGJ+DcdJz1l2dCeYYDtTooT6epXO9hCh20SxpnO+YMIFRNSgvSiMlqiiInrJPWizQipLyhmq o8z0J9OU18YElaNk=; Received: from mail.blinkt.de ([192.26.174.232]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pzEvV-00Ayus-Ia for openvpn-devel@lists.sourceforge.net; Wed, 17 May 2023 11:02:39 +0000 Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c]) by mail.blinkt.de with smtp (Exim 4.95 (FreeBSD)) (envelope-from ) id 1pzEvO-0003qF-4r for openvpn-devel@lists.sourceforge.net; Wed, 17 May 2023 13:02:30 +0200 Received: (nullmailer pid 2234312 invoked by uid 10006); Wed, 17 May 2023 11:02:30 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Wed, 17 May 2023 13:02:29 +0200 Message-Id: <20230517110230.2234266-1-arne@rfc2549.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Score: 0.3 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-1.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: This function allows us to map from a management key id to a key structure and also allows this function to be reused. Signed-off-by: Arne Schwabe --- src/openvpn/ssl_common.h | 20 ++++++++++++++++++++ src/openvpn/ssl_verify.c | 17 +++++++ 2 files changed, 27 insertions(+), 10 deletions(-) Content analysis details: (0.3 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different X-Headers-End: 1pzEvV-00Ayus-Ia Subject: [Openvpn-devel] [PATCH 1/2] Introduce get_key_by_management_key_id helper 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?1766138989755727710?= X-GMAIL-MSGID: =?utf-8?q?1766138989755727710?= This function allows us to map from a management key id to a key structure and also allows this function to be reused. Signed-off-by: Arne Schwabe --- src/openvpn/ssl_common.h | 20 ++++++++++++++++++++ src/openvpn/ssl_verify.c | 17 +++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/openvpn/ssl_common.h b/src/openvpn/ssl_common.h index 27b029479..ebfd25432 100644 --- a/src/openvpn/ssl_common.h +++ b/src/openvpn/ssl_common.h @@ -722,4 +722,24 @@ get_primary_key(const struct tls_multi *multi) return &multi->session[TM_ACTIVE].key[KS_PRIMARY]; } +#ifdef ENABLE_MANAGEMENT +/** + * Gets the \c key_state object that belong to the management key id or + * return NULL if not found. + */ +static inline struct key_state * +get_key_by_management_key_id(struct tls_multi *multi, unsigned int mda_key_id) +{ + for (int i = 0; i < KEY_SCAN_SIZE; ++i) + { + struct key_state *ks = get_key_scan(multi, i); + if (ks->mda_key_id == mda_key_id) + { + return ks; + } + } + return NULL; +} +#endif + #endif /* SSL_COMMON_H_ */ diff --git a/src/openvpn/ssl_verify.c b/src/openvpn/ssl_verify.c index 1b589f1a6..4c78c2b2c 100644 --- a/src/openvpn/ssl_verify.c +++ b/src/openvpn/ssl_verify.c @@ -1268,22 +1268,19 @@ tls_authentication_status(struct tls_multi *multi) bool tls_authenticate_key(struct tls_multi *multi, const unsigned int mda_key_id, const bool auth, const char *client_reason) { - bool ret = false; + struct key_state *ks = NULL; if (multi) { - int i; + auth_set_client_reason(multi, client_reason); - for (i = 0; i < KEY_SCAN_SIZE; ++i) + ks = get_key_by_management_key_id(multi, mda_key_id); + + if (ks) { - struct key_state *ks = get_key_scan(multi, i); - if (ks->mda_key_id == mda_key_id) - { - ks->mda_status = auth ? ACF_SUCCEEDED : ACF_FAILED; - ret = true; - } + ks->mda_status = auth ? ACF_SUCCEEDED : ACF_FAILED; } } - return ret; + return (bool) ks; } #endif /* ifdef ENABLE_MANAGEMENT */