From patchwork Fri Jun 5 01:25:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 1143 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director11.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net with LMTP id iCJAKd8r2l6aZAAAIUCqbw for ; Fri, 05 Jun 2020 07:26:23 -0400 Received: from proxy7.mail.iad3b.rsapps.net ([172.31.255.6]) by director11.mail.ord1d.rsapps.net with LMTP id mLCpJt8r2l63JwAAvGGmqA ; Fri, 05 Jun 2020 07:26:23 -0400 Received: from smtp18.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy7.mail.iad3b.rsapps.net with LMTP id SNGnIN8r2l4yBQAAQkQ5tQ ; Fri, 05 Jun 2020 07:26:23 -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: smtp18.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: 625bcd1c-a71f-11ea-becf-5254009ad1d4-1-1 Received: from [216.105.38.7] ([216.105.38.7:45214] helo=lists.sourceforge.net) by smtp18.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id BD/0D-26475-EDB2ADE5; Fri, 05 Jun 2020 07:26:23 -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 1jhATb-00063J-Th; Fri, 05 Jun 2020 11:25:31 +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 1jhATY-00062g-Uv for openvpn-devel@lists.sourceforge.net; Fri, 05 Jun 2020 11:25:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=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:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=zcVptuUUCoTh/w0sr0R9ahyqQ2vJ2tpnfiWHfRUIhHE=; b=PCJZDfChiuYlVw6ifGF4btjvWm bYSkP8VUdKHt3cKCh59Bp8hPRkVq8iU9RhYHg/QcqS7AckMnYH68pG51dF1cRknOxNA96Pha2YtU6 ja2rKRli0w/nk5K3AQrXykAI3akKvHrVWUd8NwyFXOowFIxLxvSD/QlaTWLsZjYD4xuo=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=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: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=zcVptuUUCoTh/w0sr0R9ahyqQ2vJ2tpnfiWHfRUIhHE=; b=T5imhYssn180IR1kNcRZTYThME EFK9w3WnEeowpQKxL/EZde4g251r/ukSx+qG2MbntFzcWQirFB90pM8tc8OGc/HO05ljeKmUr3TVi QKtBbVDtzMK5dLlNVcEq8ud+ox/FTD07Xgq2SZv2j2eHtIL9EYm1efhYsWwD0eUevUjg=; Received: from mail.blinkt.de ([192.26.174.232]) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1jhATW-009nec-Tq for openvpn-devel@lists.sourceforge.net; Fri, 05 Jun 2020 11:25:28 +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 1jhATP-0000nX-IE for openvpn-devel@lists.sourceforge.net; Fri, 05 Jun 2020 13:25:19 +0200 Received: (nullmailer pid 22761 invoked by uid 10006); Fri, 05 Jun 2020 11:25:19 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Fri, 5 Jun 2020 13:25:17 +0200 Message-Id: <20200605112519.22714-1-arne@rfc2549.org> X-Mailer: git-send-email 2.17.1 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 X-Headers-End: 1jhATW-009nec-Tq Subject: [Openvpn-devel] [PATCH 1/3] Make cipher_kt_name always return normalised cipher name 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 The mbed TLS variant of the call already returned the normalised name while the OpenSSL variant did not. On top of that, all calls but one to cipher_kt_name were translate_cipher_name_to_openvpn. This commit moves the call of translate_cipher_name_to_openvpn into cipher_kt_name or avoids calling it twice in the case of mbed TLS. The one case that did not translate_cipher_name_to_openvpn is an internal ssl_openssl.c method that should call EVP_CIPHER_name anyway. Also simplify cipher_name_cmp function that is only used by openvpn --show-ciphers with the modified cipher_kt_name function. Signed-off-by: Arne Schwabe Acked-by: Steffan Karger --- src/openvpn/crypto.c | 4 ++-- src/openvpn/crypto_backend.h | 2 ++ src/openvpn/crypto_openssl.c | 13 +++++-------- src/openvpn/options.c | 3 +-- src/openvpn/ssl_ncp.c | 3 +-- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index 2388027c..ba1fc095 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -847,7 +847,7 @@ init_key_ctx(struct key_ctx *ctx, const struct key *key, cipher_ctx_init(ctx->cipher, key->cipher, kt->cipher_length, kt->cipher, enc); - const char *ciphername = translate_cipher_name_to_openvpn(cipher_kt_name(kt->cipher)); + const char *ciphername = cipher_kt_name(kt->cipher); msg(D_HANDSHAKE, "%s: Cipher '%s' initialized with %d bit key", prefix, ciphername, @@ -1810,7 +1810,7 @@ print_cipher(const cipher_kt_t *cipher) " by default" : ""; printf("%s (%d bit key%s, ", - translate_cipher_name_to_openvpn(cipher_kt_name(cipher)), + cipher_kt_name(cipher), cipher_kt_key_size(cipher) * 8, var_key_size); if (cipher_kt_block_size(cipher) == 1) diff --git a/src/openvpn/crypto_backend.h b/src/openvpn/crypto_backend.h index 1d206a8c..d46cb63f 100644 --- a/src/openvpn/crypto_backend.h +++ b/src/openvpn/crypto_backend.h @@ -237,6 +237,8 @@ const cipher_kt_t *cipher_kt_get(const char *ciphername); /** * Retrieve a string describing the cipher (e.g. \c AES-128-CBC). + * The returned name is normalised to the OpenVPN config name in case the + * name differs from the name used by the crypto library. * * @param cipher_kt Static cipher parameters * diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c index a5b2c45a..13ab4859 100644 --- a/src/openvpn/crypto_openssl.c +++ b/src/openvpn/crypto_openssl.c @@ -266,12 +266,7 @@ cipher_name_cmp(const void *a, const void *b) const EVP_CIPHER *const *cipher_a = a; const EVP_CIPHER *const *cipher_b = b; - const char *cipher_name_a = - translate_cipher_name_to_openvpn(EVP_CIPHER_name(*cipher_a)); - const char *cipher_name_b = - translate_cipher_name_to_openvpn(EVP_CIPHER_name(*cipher_b)); - - return strcmp(cipher_name_a, cipher_name_b); + return strcmp(cipher_kt_name(*cipher_a), cipher_kt_name(*cipher_b)); } void @@ -613,7 +608,9 @@ cipher_kt_name(const EVP_CIPHER *cipher_kt) { return "[null-cipher]"; } - return EVP_CIPHER_name(cipher_kt); + + const char *name = EVP_CIPHER_name(cipher_kt); + return translate_cipher_name_to_openvpn(name); } int @@ -644,7 +641,7 @@ cipher_kt_block_size(const EVP_CIPHER *cipher) int block_size = EVP_CIPHER_block_size(cipher); - orig_name = cipher_kt_name(cipher); + orig_name = EVP_CIPHER_name(cipher); if (!orig_name) { goto cleanup; diff --git a/src/openvpn/options.c b/src/openvpn/options.c index d1e68a51..ec912d34 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -3779,8 +3779,7 @@ options_string(const struct options *o, init_key_type(&kt, o->ciphername, o->authname, o->keysize, true, false); - buf_printf(&out, ",cipher %s", - translate_cipher_name_to_openvpn(cipher_kt_name(kt.cipher))); + buf_printf(&out, ",cipher %s", cipher_kt_name(kt.cipher)); buf_printf(&out, ",auth %s", md_kt_name(kt.digest)); buf_printf(&out, ",keysize %d", kt.cipher_length * 8); if (o->shared_secret_file) diff --git a/src/openvpn/ssl_ncp.c b/src/openvpn/ssl_ncp.c index 9ed6ff5f..042b0ce0 100644 --- a/src/openvpn/ssl_ncp.c +++ b/src/openvpn/ssl_ncp.c @@ -116,8 +116,7 @@ mutate_ncp_cipher_list(const char *list, struct gc_arena *gc) } else { - const char *ovpn_cipher_name = - translate_cipher_name_to_openvpn(cipher_kt_name(ktc)); + const char *ovpn_cipher_name = cipher_kt_name(ktc); if (buf_len(&new_list)> 0) { From patchwork Fri Jun 5 01:25:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 1145 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 QGVRNvQr2l4zXgAAIUCqbw for ; Fri, 05 Jun 2020 07:26:44 -0400 Received: from proxy16.mail.iad3b.rsapps.net ([172.31.255.6]) by director12.mail.ord1d.rsapps.net with LMTP id kHgnNPQr2l4caQAAIasKDg ; Fri, 05 Jun 2020 07:26:44 -0400 Received: from smtp39.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy16.mail.iad3b.rsapps.net with LMTP id +BH5LvQr2l7KSAAAPj+4aA ; Fri, 05 Jun 2020 07:26:44 -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: smtp39.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: 6efbeb9c-a71f-11ea-904f-5254002be87c-1-1 Received: from [216.105.38.7] ([216.105.38.7:35340] helo=lists.sourceforge.net) by smtp39.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id C2/51-18496-4FB2ADE5; Fri, 05 Jun 2020 07:26:44 -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.90_1) (envelope-from ) id 1jhATg-0005xY-3h; Fri, 05 Jun 2020 11:25:36 +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.90_1) (envelope-from ) id 1jhATe-0005xR-Ea for openvpn-devel@lists.sourceforge.net; Fri, 05 Jun 2020 11:25:34 +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=NXaEBFSrUyLwPVVcRrCDpEuXJNlzpJ7vOkonEEcZ+c4=; b=lexMWddxkfqFFeVMdJ+02D6ov6 HnODzUaad+dsm7ynkHRH9NC3BzRHEEVX6EtvRKD7w6G8I+HiTw+EuNzIESRq/0nZKR3mENDJN3KpF JafKpjSicnaJFzqPy0tpFH9I0YAfPB5iXs748Uc/+7uF5/sct03Sb3FlePF8bRApjGFc=; 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=NXaEBFSrUyLwPVVcRrCDpEuXJNlzpJ7vOkonEEcZ+c4=; b=UJFqU7bR5rMo06FI5MAOixB3kz ptecmnQONpRzEOPM6B5xs8ooh+MpaMopWcb3p1vqZLkAKwIrsxXeIXU1N+uEjJIh3qYufR89+XkG0 4JmIgwE+VM+TRSzPVKrfS6+68kR81wZKq94KZjeAGIla4BHnSjHaoMSAShgz8FmI+z4c=; Received: from mail.blinkt.de ([192.26.174.232]) by sfi-mx-4.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1jhATd-00CnhX-9U for openvpn-devel@lists.sourceforge.net; Fri, 05 Jun 2020 11:25:34 +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 1jhATP-0000na-K9 for openvpn-devel@lists.sourceforge.net; Fri, 05 Jun 2020 13:25:19 +0200 Received: (nullmailer pid 22764 invoked by uid 10006); Fri, 05 Jun 2020 11:25:19 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Fri, 5 Jun 2020 13:25:18 +0200 Message-Id: <20200605112519.22714-2-arne@rfc2549.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200605112519.22714-1-arne@rfc2549.org> References: <20200605112519.22714-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 X-Headers-End: 1jhATd-00CnhX-9U Subject: [Openvpn-devel] [PATCH 2/3] Make cipher_kt_get also accept OpenVPN config cipher name 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 Basically calls to cipher_kt_get were calling translate_cipher_name_from_openvpn. The only two exception were the (broken) unit test and tls-crypt that uses cipher_kt_get("AES-256-CTR") Signed-off-by: Arne Schwabe Acked-by: Steffan Karger --- src/openvpn/crypto.c | 2 +- src/openvpn/crypto_backend.h | 3 ++- src/openvpn/crypto_mbedtls.c | 1 + src/openvpn/crypto_openssl.c | 1 + src/openvpn/ssl_ncp.c | 8 ++++---- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index ba1fc095..1ce98184 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -763,7 +763,7 @@ init_key_type(struct key_type *kt, const char *ciphername, CLEAR(*kt); if (strcmp(ciphername, "none") != 0) { - kt->cipher = cipher_kt_get(translate_cipher_name_from_openvpn(ciphername)); + kt->cipher = cipher_kt_get(ciphername); if (!kt->cipher) { msg(M_FATAL, "Cipher %s not supported", ciphername); diff --git a/src/openvpn/crypto_backend.h b/src/openvpn/crypto_backend.h index d46cb63f..85cb084a 100644 --- a/src/openvpn/crypto_backend.h +++ b/src/openvpn/crypto_backend.h @@ -227,7 +227,8 @@ void cipher_des_encrypt_ecb(const unsigned char key[DES_KEY_LENGTH], * initialise encryption/decryption. * * @param ciphername Name of the cipher to retrieve parameters for (e.g. - * \c AES-128-CBC). + * \c AES-128-CBC). Will be translated to the library name + * from the openvpn config name if needed. * * @return A statically allocated structure containing parameters * for the given cipher, or NULL if no matching parameters diff --git a/src/openvpn/crypto_mbedtls.c b/src/openvpn/crypto_mbedtls.c index c8dcddc8..bb752557 100644 --- a/src/openvpn/crypto_mbedtls.c +++ b/src/openvpn/crypto_mbedtls.c @@ -465,6 +465,7 @@ cipher_kt_get(const char *ciphername) ASSERT(ciphername); + ciphername = translate_cipher_name_from_openvpn(ciphername); cipher = mbedtls_cipher_info_from_string(ciphername); if (NULL == cipher) diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c index 13ab4859..bbaa5742 100644 --- a/src/openvpn/crypto_openssl.c +++ b/src/openvpn/crypto_openssl.c @@ -580,6 +580,7 @@ cipher_kt_get(const char *ciphername) ASSERT(ciphername); + ciphername = translate_cipher_name_from_openvpn(ciphername); cipher = EVP_get_cipherbyname(ciphername); if (NULL == cipher) diff --git a/src/openvpn/ssl_ncp.c b/src/openvpn/ssl_ncp.c index 042b0ce0..ea1dc960 100644 --- a/src/openvpn/ssl_ncp.c +++ b/src/openvpn/ssl_ncp.c @@ -103,12 +103,12 @@ mutate_ncp_cipher_list(const char *list, struct gc_arena *gc) while (token) { /* - * Going through a roundtrip by using translate_cipher_name_from_openvpn - * and translate_cipher_name_to_openvpn also normalises the cipher name, + * Going through a roundtrip by using cipher_kt_get/cipher_kt_name + * (and translate_cipher_name_from_openvpn/ + * translate_cipher_name_to_openvpn) also normalises the cipher name, * e.g. replacing AeS-128-gCm with AES-128-GCM */ - const char *cipher_name = translate_cipher_name_from_openvpn(token); - const cipher_kt_t *ktc = cipher_kt_get(cipher_name); + const cipher_kt_t *ktc = cipher_kt_get(token); if (!ktc) { msg(M_WARN, "Unsupported cipher in --ncp-ciphers: %s", token); From patchwork Fri Jun 5 01:25:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 1144 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director11.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net with LMTP id ABrvD+Ar2l6aZAAAIUCqbw for ; Fri, 05 Jun 2020 07:26:24 -0400 Received: from proxy12.mail.iad3b.rsapps.net ([172.31.255.6]) by director11.mail.ord1d.rsapps.net with LMTP id 0LO5DeAr2l6/JwAAvGGmqA ; Fri, 05 Jun 2020 07:26:24 -0400 Received: from smtp28.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy12.mail.iad3b.rsapps.net with LMTP id aCTPCOAr2l51NAAAEsW3lA ; Fri, 05 Jun 2020 07:26:24 -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: smtp28.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: 628c6f8a-a71f-11ea-b586-525400c8cd63-1-1 Received: from [216.105.38.7] ([216.105.38.7:43502] helo=lists.sourceforge.net) by smtp28.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 2A/30-18024-FDB2ADE5; Fri, 05 Jun 2020 07:26:23 -0400 Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1jhATa-0007v4-TH; Fri, 05 Jun 2020 11:25:30 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhATY-0007uw-Qa for openvpn-devel@lists.sourceforge.net; Fri, 05 Jun 2020 11:25:28 +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=S6ADbetMOFd+i6JxZX2AmEc5o/b3XRAZyHwGZWIcQ5o=; b=Bo34+ykrq1UrvLabxppj5uhqGH IP5aGTFIy9P7dHGLnJGGrs4OQyQs5VN+FNcB99bTYCuJzMgbn6aQQKampnRrIXw0tKdfd2S3onrjn IB53osi7ujOZLgDEPAHOvlzHdmUR4pTUt3VvEvsj9iYMbFNrF6cCObE981+beycz0LwE=; 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=S6ADbetMOFd+i6JxZX2AmEc5o/b3XRAZyHwGZWIcQ5o=; b=XWyp4kuZ0znJYZeBtEublcGm6R Y2iqtYmGSYjsoh/0sabE7cFdI/qMptqgrjOrjU89aWrUB+2Q4FGWjMiADF03uclmQrHFqh38uL6+j opVY6O2qklDzEmpy7Wazd3veYbUQRSEULk8wHz/mYH94gYC5olxXR4WjPM1Miwx+R8Zk=; Received: from mail.blinkt.de ([192.26.174.232]) by sfi-mx-4.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1jhATW-00Cnh1-VE for openvpn-devel@lists.sourceforge.net; Fri, 05 Jun 2020 11:25:28 +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 1jhATP-0000nf-MO for openvpn-devel@lists.sourceforge.net; Fri, 05 Jun 2020 13:25:19 +0200 Received: (nullmailer pid 22767 invoked by uid 10006); Fri, 05 Jun 2020 11:25:19 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Fri, 5 Jun 2020 13:25:19 +0200 Message-Id: <20200605112519.22714-3-arne@rfc2549.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200605112519.22714-1-arne@rfc2549.org> References: <20200605112519.22714-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 X-Headers-End: 1jhATW-00Cnh1-VE Subject: [Openvpn-devel] [PATCH 3/3] Add unit test for cipher name translations 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 The unit test duplicates some part of the test for the ncp-cipher list but that is not a bad thing. Signed-off-by: Arne Schwabe Acked-by: Gert Doering --- tests/unit_tests/openvpn/test_crypto.c | 68 ++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/tests/unit_tests/openvpn/test_crypto.c b/tests/unit_tests/openvpn/test_crypto.c index fdf814de..ea9b99b2 100644 --- a/tests/unit_tests/openvpn/test_crypto.c +++ b/tests/unit_tests/openvpn/test_crypto.c @@ -69,11 +69,79 @@ crypto_pem_encode_decode_loopback(void **state) gc_free(&gc); } +static void +test_translate_cipher(const char *ciphername, const char *openvpn_name) +{ + const cipher_kt_t *cipher = cipher_kt_get(ciphername); + + /* Empty cipher is fine */ + if (!cipher) + { + return; + } + + const char *kt_name = cipher_kt_name(cipher); + + assert_string_equal(kt_name, openvpn_name); +} + +static void +test_cipher_names(const char *ciphername, const char *openvpn_name) +{ + struct gc_arena gc = gc_new(); + /* Go through some variants, if the cipher library accepts these, they + * should be normalised to the openvpn name */ + char *upper = string_alloc(ciphername, &gc); + char *lower = string_alloc(ciphername, &gc); + char *random_case = string_alloc(ciphername, &gc); + + for (int i = 0; i < strlen(ciphername); i++) + { + upper[i] = toupper(ciphername[i]); + lower[i] = tolower(ciphername[i]); + if (rand() & 0x1) + { + random_case[i] = upper[i]; + } + else + { + random_case[i] = lower[i]; + } + } + + if (!openvpn_name) + { + openvpn_name = upper; + } + + test_translate_cipher(upper, openvpn_name); + test_translate_cipher(lower, openvpn_name); + test_translate_cipher(random_case, openvpn_name); + test_translate_cipher(ciphername, openvpn_name); + + + gc_free(&gc); +} + +static void +crypto_translate_cipher_names(void **state) +{ + /* Test that a number of ciphers to see that they turn out correctly */ + test_cipher_names("BF-CBC", NULL); + test_cipher_names("BLOWFISH-CBC", "BF-CBC"); + test_cipher_names("Chacha20-Poly1305", NULL); + test_cipher_names("AES-128-GCM", NULL); + test_cipher_names("AES-128-CBC", NULL); + test_cipher_names("CAMELLIA-128-CFB128", "CAMELLIA-128-CFB"); + test_cipher_names("id-aes256-GCM", "AES-256-GCM"); +} + int main(void) { const struct CMUnitTest tests[] = { cmocka_unit_test(crypto_pem_encode_decode_loopback), + cmocka_unit_test(crypto_translate_cipher_names), }; #if defined(ENABLE_CRYPTO_OPENSSL)