From patchwork Tue Mar 31 23:21:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 1063 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director12.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net with LMTP id 6OttGJZrhF6iVwAAIUCqbw for ; Wed, 01 Apr 2020 06:23:18 -0400 Received: from proxy19.mail.iad3b.rsapps.net ([172.31.255.6]) by director12.mail.ord1d.rsapps.net with LMTP id 4D24FZZrhF6VVQAAIasKDg ; Wed, 01 Apr 2020 06:23:18 -0400 Received: from smtp35.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy19.mail.iad3b.rsapps.net with LMTP id sIg/D5ZrhF7PcwAAIG4riQ ; Wed, 01 Apr 2020 06:23:18 -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: smtp35.gate.iad3b.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: cd3a8aba-7402-11ea-b69d-525400503131-1-1 Received: from [216.105.38.7] ([216.105.38.7:35448] helo=lists.sourceforge.net) by smtp35.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 3E/9D-22416-59B648E5; Wed, 01 Apr 2020 06:23:17 -0400 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.90_1) (envelope-from ) id 1jJaVr-0006B7-32; Wed, 01 Apr 2020 10:22:23 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jJaVp-0006Ag-KG for openvpn-devel@lists.sourceforge.net; Wed, 01 Apr 2020 10:22:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:To: From:Sender:Reply-To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: 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=ANfuXk0DxNcKG/qholHcTXDLGEjYwiXswi24+aicNps=; b=IN17znKxYPJhXwqF2HLapmVSZT VP94EjI3DuyoavDxCbJjppH2q9CWxdPvHQTNdAZaUTOF0RR6i2zX54C4PROunUSe4VCtT8QDeDy1q gxU+tHNmmUUUfLRZbdLHC30hHvlwpxlSxbUHkCmBlEUYbsFSVgwjbW6ot0anJO7+UcCA=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc :MIME-Version:Content-Type:Content-Transfer-Encoding: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=ANfuXk0DxNcKG/qholHcTXDLGEjYwiXswi24+aicNps=; b=Xn9vV4v4bX9qUUAQ1KQbHCOv9A dP3y94nzAjIrq/u6rMIKZ4fLoMwmzA7GKJliWVYiu5/25CcB8WR3oufZFm05xRQXi9Wf47zwIubQR fbfq15jY4fPZNJFZIsQhhr8jSj65rwzYvpAlTe/eAkUh7Ldx038EEzrhztfVsubD/dTw=; Received: from mail.blinkt.de ([192.26.174.232]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1jJaVi-00FLz0-Mf for openvpn-devel@lists.sourceforge.net; Wed, 01 Apr 2020 10:22:21 +0000 Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c]) by mail.blinkt.de with smtp (Exim 4.92.3 (FreeBSD)) (envelope-from ) id 1jJaVT-000HuX-HZ for openvpn-devel@lists.sourceforge.net; Wed, 01 Apr 2020 12:21:59 +0200 Received: (nullmailer pid 29202 invoked by uid 10006); Wed, 01 Apr 2020 10:21:59 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Wed, 1 Apr 2020 12:21:58 +0200 Message-Id: <20200401102159.29157-1-arne@rfc2549.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200328040858.16505-1-arne@rfc2549.org> References: <20200328040858.16505-1-arne@rfc2549.org> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 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 0.5 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1jJaVi-00FLz0-Mf Subject: [Openvpn-devel] [PATCH 2/3] Refactor counting number of element in a : delimited list into 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: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox --- src/openvpn/misc.c | 18 ++++++++++++++++++ src/openvpn/misc.h | 13 +++++++++++++ src/openvpn/ssl_mbedtls.c | 15 ++------------- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/openvpn/misc.c b/src/openvpn/misc.c index 1931149b..b375451f 100644 --- a/src/openvpn/misc.c +++ b/src/openvpn/misc.c @@ -735,4 +735,22 @@ output_peer_info_env(struct env_set *es, const char *peer_info) } } +int get_num_elements(const char* string, char delimiter) +{ + int string_len = strlen(string); + + ASSERT(0 != string_len); + + int element_count = 1; + /* Get number of ciphers */ + for (int i = 0; i < string_len; i++) + { + if (string[i] == delimiter) + { + element_count++; + } + } + + return element_count; +} #endif /* P2MP_SERVER */ diff --git a/src/openvpn/misc.h b/src/openvpn/misc.h index 991b7df2..0655b7fe 100644 --- a/src/openvpn/misc.h +++ b/src/openvpn/misc.h @@ -175,4 +175,17 @@ void output_peer_info_env(struct env_set *es, const char *peer_info); #endif /* P2MP_SERVER */ +/** + * Counts the number of delimiter in a string and returns + * their number +1. This is typically used to find out the + * number elements in a cipher string or similar that is separated by : like + * + * X25519:secp256r1:X448:secp512r1:secp384r1:brainpoolP384r1 + * + * @param string the string to work on + * @param delimiter the delimiter to count, typically ':' + * @return number of delimiter found + 1 + */ +int +get_num_elements(const char* string, char delimiter); #endif /* ifndef MISC_H */ diff --git a/src/openvpn/ssl_mbedtls.c b/src/openvpn/ssl_mbedtls.c index 0f0b035b..0e17e734 100644 --- a/src/openvpn/ssl_mbedtls.c +++ b/src/openvpn/ssl_mbedtls.c @@ -289,33 +289,22 @@ void tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers) { char *tmp_ciphers, *tmp_ciphers_orig, *token; - int i, cipher_count; - int ciphers_len; if (NULL == ciphers) { return; /* Nothing to do */ - } - ciphers_len = strlen(ciphers); ASSERT(NULL != ctx); - ASSERT(0 != ciphers_len); /* Get number of ciphers */ - for (i = 0, cipher_count = 1; i < ciphers_len; i++) - { - if (ciphers[i] == ':') - { - cipher_count++; - } - } + int cipher_count = get_num_elements(ciphers, ':'); /* Allocate an array for them */ ALLOC_ARRAY_CLEAR(ctx->allowed_ciphers, int, cipher_count+1) /* Parse allowed ciphers, getting IDs */ - i = 0; + int i = 0; tmp_ciphers_orig = tmp_ciphers = string_alloc(ciphers, NULL); token = strtok(tmp_ciphers, ":");