From patchwork Thu Apr 22 05:17:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 1764 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director8.mail.ord1d.rsapps.net ([172.27.255.9]) by backend30.mail.ord1d.rsapps.net with LMTP id yE9DNs+TgWDCEwAAIUCqbw (envelope-from ) for ; Thu, 22 Apr 2021 11:18:39 -0400 Received: from proxy10.mail.iad3a.rsapps.net ([172.27.255.9]) by director8.mail.ord1d.rsapps.net with LMTP id KK4HNs+TgWApSQAAfY0hYg (envelope-from ) for ; Thu, 22 Apr 2021 11:18:39 -0400 Received: from smtp10.gate.iad3a ([172.27.255.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy10.mail.iad3a.rsapps.net with LMTPS id 2NbmLc+TgWBiLQAAnQ/bqA (envelope-from ) for ; Thu, 22 Apr 2021 11:18:39 -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: smtp10.gate.iad3a.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; dmarc=none (p=nil; dis=none) header.from=rfc2549.org X-Suspicious-Flag: YES X-Classification-ID: 0386ddac-a37e-11eb-a6ce-525400a8203f-1-1 Received: from [216.105.38.7] ([216.105.38.7:47128] helo=lists.sourceforge.net) by smtp10.gate.iad3a.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 32/70-01866-FC391806; Thu, 22 Apr 2021 11:18:39 -0400 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.92.3) (envelope-from ) id 1lZb5O-0005v4-1y; Thu, 22 Apr 2021 15:17:46 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) (envelope-from ) id 1lZb5L-0005uW-58 for openvpn-devel@lists.sourceforge.net; Thu, 22 Apr 2021 15:17:43 +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=pALeFcfN+fgedo50ZRYgwXFYvUew+dmQCLZieEa6RIY=; b=ZVgcjNr5HIbrGffsTg7uxsp7Wv xYWRx3OOF9aDzZiYk8pC1xPKQh/b8iXJlymHB/vYKLn6kCBuZRTOGIumhoVyvCIQU35Ka/iAmnWD3 zZ2qGWhs5YS0EeKN1p/Y2/uRVmDrvrT0iQMi4lGoL47hacYmLOk+LFb2PiUdfW94gaII=; 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=pALeFcfN+fgedo50ZRYgwXFYvUew+dmQCLZieEa6RIY=; b=OMoRa+CTlLyWABBUCC43oZ3idz xHAogZ0pdJ8zMGjw5aRAUfT1pXQniyULs8typTH+TH2NGc6mEe2ukXjpn+fLF2Z7cTEeLbgp3foiL XPM84QktKB7BPAQ6K6U+hCvKjGf0KMG7HNp7CziuuxgVv1GYu1rQYvW2MJ0nG/xCUP4U=; Received: from mail.blinkt.de ([192.26.174.232]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) id 1lZb5E-0007cS-Eu for openvpn-devel@lists.sourceforge.net; Thu, 22 Apr 2021 15:17:43 +0000 Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c]) by mail.blinkt.de with smtp (Exim 4.94 (FreeBSD)) (envelope-from ) id 1lZb52-000B5O-9G for openvpn-devel@lists.sourceforge.net; Thu, 22 Apr 2021 17:17:24 +0200 Received: (nullmailer pid 2132622 invoked by uid 10006); Thu, 22 Apr 2021 15:17:24 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Thu, 22 Apr 2021 17:17:19 +0200 Message-Id: <20210422151724.2132573-2-arne@rfc2549.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210422151724.2132573-1-arne@rfc2549.org> References: <20210422151724.2132573-1-arne@rfc2549.org> MIME-Version: 1.0 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: rfc2549.org] 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different 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 X-Headers-End: 1lZb5E-0007cS-Eu Subject: [Openvpn-devel] [PATCH 2/7] Use functions to access key_state instead direct member access 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 This uses get_key_scan and get_primary key instead the directly accessing the members of the struct to improve readiability of the code. Signed-off-by: Arne Schwabe Acked-by: Antonio Quartulli --- src/openvpn/multi.c | 3 +-- src/openvpn/push.c | 9 ++++----- src/openvpn/ssl.c | 11 +++-------- src/openvpn/ssl.h | 2 +- src/openvpn/ssl_common.h | 9 +++++++++ 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index d51316de2..666456da9 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -1800,8 +1800,7 @@ multi_client_set_protocol_options(struct context *c) * cipher -> so log the fact and push the "what we have now" cipher * (so the client is always told what we expect it to use) */ - const struct tls_session *session = &tls_multi->session[TM_ACTIVE]; - if (session->key[KS_PRIMARY].crypto_options.key_ctx_bi.initialized) + if (get_primary_key(tls_multi)->crypto_options.key_ctx_bi.initialized) { msg(M_INFO, "PUSH: client wants to negotiate cipher (NCP), but " "server has already generated data channel keys, " diff --git a/src/openvpn/push.c b/src/openvpn/push.c index bba555fa1..fcafc5003 100644 --- a/src/openvpn/push.c +++ b/src/openvpn/push.c @@ -222,7 +222,7 @@ receive_cr_response(struct context *c, const struct buffer *buffer) struct tls_session *session = &c->c2.tls_multi->session[TM_ACTIVE]; struct man_def_auth_context *mda = session->opt->mda_context; struct env_set *es = session->opt->es; - int key_id = session->key[KS_PRIMARY].key_id; + int key_id = get_primary_key(c->c2.tls_multi)->key_id; management_notify_client_cr_response(key_id, mda, es, m); @@ -304,7 +304,7 @@ receive_auth_pending(struct context *c, const struct buffer *buffer) "to %us", c->options.handshake_window, min_uint(max_timeout, server_timeout)); - struct key_state *ks = &c->c2.tls_multi->session[TM_ACTIVE].key[KS_PRIMARY]; + const struct key_state *ks = get_primary_key(c->c2.tls_multi); c->c2.push_request_timeout = ks->established + min_uint(max_timeout, server_timeout); } @@ -369,7 +369,7 @@ bool send_auth_pending_messages(struct tls_multi *tls_multi, const char *extra, unsigned int timeout) { - struct key_state *ks = &tls_multi->session[TM_ACTIVE].key[KS_PRIMARY]; + struct key_state *ks = get_key_scan(tls_multi, 0); static const char info_pre[] = "INFO_PRE,"; @@ -476,8 +476,7 @@ cleanup: bool send_push_request(struct context *c) { - struct tls_session *session = &c->c2.tls_multi->session[TM_ACTIVE]; - struct key_state *ks = &session->key[KS_PRIMARY]; + const struct key_state *ks = get_primary_key(c->c2.tls_multi); /* We timeout here under two conditions: * a) we reached the hard limit of push_request_timeout diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 3bc84e02c..7d66cf565 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -3448,7 +3448,7 @@ tls_pre_decrypt(struct tls_multi *multi, if (i == TM_SIZE && is_hard_reset_method2(op)) { struct tls_session *session = &multi->session[TM_ACTIVE]; - struct key_state *ks = &session->key[KS_PRIMARY]; + const struct key_state *ks = get_primary_key(multi); /* * If we have no session currently in progress, the initial packet will @@ -3933,7 +3933,6 @@ tls_send_payload(struct tls_multi *multi, const uint8_t *data, int size) { - struct tls_session *session; struct key_state *ks; bool ret = false; @@ -3941,8 +3940,7 @@ tls_send_payload(struct tls_multi *multi, ASSERT(multi); - session = &multi->session[TM_ACTIVE]; - ks = &session->key[KS_PRIMARY]; + ks = get_key_scan(multi, 0); if (ks->state >= S_ACTIVE) { @@ -3971,16 +3969,13 @@ bool tls_rec_payload(struct tls_multi *multi, struct buffer *buf) { - struct tls_session *session; - struct key_state *ks; bool ret = false; tls_clear_error(); ASSERT(multi); - session = &multi->session[TM_ACTIVE]; - ks = &session->key[KS_PRIMARY]; + struct key_state *ks = get_key_scan(multi, 0); if (ks->state >= S_ACTIVE && BLEN(&ks->plaintext_read_buf)) { diff --git a/src/openvpn/ssl.h b/src/openvpn/ssl.h index 135c60732..2791143f6 100644 --- a/src/openvpn/ssl.h +++ b/src/openvpn/ssl.h @@ -547,7 +547,7 @@ tls_test_payload_len(const struct tls_multi *multi) { if (multi) { - const struct key_state *ks = &multi->session[TM_ACTIVE].key[KS_PRIMARY]; + const struct key_state *ks = get_primary_key(multi); if (ks->state >= S_ACTIVE) { return BLEN(&ks->plaintext_read_buf); diff --git a/src/openvpn/ssl_common.h b/src/openvpn/ssl_common.h index 514cdd964..9c923f2a6 100644 --- a/src/openvpn/ssl_common.h +++ b/src/openvpn/ssl_common.h @@ -631,4 +631,13 @@ get_key_scan(struct tls_multi *multi, int index) } } +/** gets an item of \c key_state objects in the + * order they should be scanned by data + * channel modules. */ +static inline const struct key_state * +get_primary_key(const struct tls_multi *multi) +{ + return &multi->session[TM_ACTIVE].key[KS_PRIMARY]; +} + #endif /* SSL_COMMON_H_ */