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)