From patchwork Mon May 22 10:11:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 3235 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7300:7b9a:b0:c3:1364:a2a2 with SMTP id j26csp1476688dyk; Mon, 22 May 2023 03:12:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ45UL1vetKY5XGMdA8LoW4gaAoHHFRRzHsEg2z4jeu1tGxT5fKkP/C+81p/1fh26Ge18Ioa X-Received: by 2002:a6b:5c10:0:b0:769:a626:6e13 with SMTP id z16-20020a6b5c10000000b00769a6266e13mr5934816ioh.19.1684750323956; Mon, 22 May 2023 03:12:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684750323; cv=none; d=google.com; s=arc-20160816; b=vthAe8Rqku5IqzZ5xRy9RQ5l10UI9XXtWVoN3RqXDlvWCPlOTU7nyC2Ob0Djz5Ecut tHyDXMYIMH688ejJ2nw28NcRZDcSK9KjIsB2rIGcJRt/tdxzgCYPkRavnMhfqgdIEITy vvQhDnfIYwXs3J7VaAU9sBWDdfH5w33xQtfvNqHBIq63TR4D0CFshsaqns281hRtOLpk Kroff1SWRSgmidIc/l1yjmeqmVTDZa0NvHWylVODyOacsbrsYfx4GDoHD+qUSIq/QSEv lI61zMqNXmW5d7ijNoMBYfA7AOnmh50oGJ2h2PsDw/sKjuUqO3oIGYkKzzpQFDWuJGal NpVQ== 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:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature; bh=BN/uKZO8heOybx1BVKpsYXEhV4/Tcg8vL1MbfDFhdKQ=; b=oQcmvuvbPGfRN185lqV6vRkCYmWpEG/HFLaFriRDKOcQGcYGu8NV46sZktNwcJxqbc y3e+tqYYErYSldP8bHW6uaIGGY4W8aT3mX869OV0Hp2RoRmj119LCHTpXLis/uo4VGab 24TYo9nQw5o2wmXmrQH01t5h0rwdlwwJQJCz8XVyox3WryalYdJrJ/JfY/nhwTmeYubk TiqeNyi/7dtyS+hE9gITAJExIfrTI32ZaG8pTwxl1X+AdLQL3mkjuE35nAwIoUQwBZ9W 7Wh4DJ/PA1SuPnvlGY5ncuysgsNY0Znx/Tdkj7amnkss1IiL2Xva1xLCcEwO5qiN8a+v NdFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=R1jHPS7a; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=eSXGJGSQ; 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 z18-20020a056602005200b007637e2cbae4si3043548ioz.125.2023.05.22.03.12.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 May 2023 03:12:03 -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=R1jHPS7a; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=eSXGJGSQ; 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 1q12W1-0002w2-K7; Mon, 22 May 2023 10:11:46 +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 1q12W0-0002vS-IW for openvpn-devel@lists.sourceforge.net; Mon, 22 May 2023 10:11:45 +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=CoyQm650HLw8uC7/JprV6DSA6HEKAwJWmLhNp15gWQ8=; b=R1jHPS7atphcFL+2cvnWyt/xcw tMeT4FWsIP7c5tMX5G82E19JU/foCC8XK5vMaqSozAEyS1m4USDMzingDuVHExOyBq475OJhq+EI4 ep9BlAEuHYZkiHYAngr99rIVBe6V/02KSsbxboqD7gsGNIHvqlKaiGpOvwbq9k7MVApU=; 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=CoyQm650HLw8uC7/JprV6DSA6HEKAwJWmLhNp15gWQ8=; b=eSXGJGSQZHo/np8XskzWyxMOQ2 r2Y63qJabfvJ0hYJT3ABk81uY4TiuQzu0+/zniQ4tIu0X7lJ5lh/SszVimai4z5Pu2Rm61pdrAPK8 dBFOHC75jH6mRg5sYECCgDQeKOj/92fbOETRcQuQKR0R46ydX8mdYErTStClc8tQbJTc=; 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 1q12W0-00FdhK-Je for openvpn-devel@lists.sourceforge.net; Mon, 22 May 2023 10:11:45 +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 1q12Vu-000MwG-5V for openvpn-devel@lists.sourceforge.net; Mon, 22 May 2023 12:11:38 +0200 Received: (nullmailer pid 2842424 invoked by uid 10006); Mon, 22 May 2023 10:11:38 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Mon, 22 May 2023 12:11:37 +0200 Message-Id: <20230522101138.2842378-1-arne@rfc2549.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230517110230.2234266-1-arne@rfc2549.org> References: <20230517110230.2234266-1-arne@rfc2549.org> MIME-Version: 1.0 X-Spam-Score: 0.2 (/) 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: This function allows us to map from a management key id to a key structure and also allows this function to be reused. Patch v2: add message when key is not found. Signed-off-by: Arne Schwabe --- src/openvpn/ssl_common.h | 20 ++++++++++++++++++++ src/openvpn/ssl_verify.c | 23 +++++++++++++ 2 files changed, 33 insertions(+), 10 deleti [...] Content analysis details: (0.2 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Headers-End: 1q12W0-00FdhK-Je Subject: [Openvpn-devel] [PATCH v2 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?1766588755536019746?= This function allows us to map from a management key id to a key structure and also allows this function to be reused. Patch v2: add message when key is not found. Signed-off-by: Arne Schwabe --- src/openvpn/ssl_common.h | 20 ++++++++++++++++++++ src/openvpn/ssl_verify.c | 23 +++++++++++++---------- 2 files changed, 33 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..d4d291098 100644 --- a/src/openvpn/ssl_verify.c +++ b/src/openvpn/ssl_verify.c @@ -1268,22 +1268,25 @@ 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; } + else + { + msg(D_TLS_DEBUG_LOW, "%s: no key state found for management key id " + "%d", __func__, mda_key_id); + } + } - return ret; + return (bool) ks; } #endif /* ifdef ENABLE_MANAGEMENT */