From patchwork Sat Oct 6 20:34:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steffan Karger X-Patchwork-Id: 496 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director8.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net with LMTP id UKuYEUW3uVsYdwAAIUCqbw for ; Sun, 07 Oct 2018 03:35:33 -0400 Received: from proxy8.mail.iad3b.rsapps.net ([172.31.255.6]) by director8.mail.ord1d.rsapps.net with LMTP id KK9lDkW3uVsQKgAAfY0hYg ; Sun, 07 Oct 2018 03:35:33 -0400 Received: from smtp2.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy8.mail.iad3b.rsapps.net with LMTP id aJXXB0W3uVujPwAAoCsc3g ; Sun, 07 Oct 2018 03:35:33 -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: smtp2.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; dkim=fail (signature verification failed) header.d=karger-me.20150623.gappssmtp.com; dmarc=none (p=nil; dis=none) header.from=karger.me X-Suspicious-Flag: YES X-Classification-ID: 92293426-ca03-11e8-b597-5254000fbace-1-1 Received: from [216.105.38.7] ([216.105.38.7:58799] helo=lists.sourceforge.net) by smtp2.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 69/7A-17031-447B9BB5; Sun, 07 Oct 2018 03:35:32 -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 1g93aC-00068v-R4; Sun, 07 Oct 2018 07:34:32 +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 1g93aB-00068o-MX for openvpn-devel@lists.sourceforge.net; Sun, 07 Oct 2018 07:34:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: 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=BIlWc3TLECKXxONVuVmJSPqJzYfWG9g4XPMC/kd1Y+I=; b=BFdwpKm+b2/ZT4z3aghohI4AP2 42vwIppfn9PdPfM+mMlBK6YttIHoC6QHGllhXhGk+Yb3UtU9TJUOqGTs7Jt2GaihltPJ6dfuJLlvR T34dSIgsi4pOigvu4fnSKCKw0/z7jS7KJkBUIZLI7uITcmS4Q63qgajT5IHCm31zeYu4=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: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=BIlWc3TLECKXxONVuVmJSPqJzYfWG9g4XPMC/kd1Y+I=; b=VxcaPKYGuEvPOcaMG/NuP962Dc JKZHWCZZ8Fwxtxp2LASDOm7pxvYKkELC1t0AxYSqAB2TXe70lhW7vNTEBGjqMbDj3HQFLs/2SJaae Gl4S9CL4+1loR5ocFh1suBEZwAKwojO+VeH9oPZ9Wez2ToPa9l2xMUMx3V+We0oXQu9s=; Received: from mail-ed1-f66.google.com ([209.85.208.66]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) id 1g93a6-00DnXb-R7 for openvpn-devel@lists.sourceforge.net; Sun, 07 Oct 2018 07:34:31 +0000 Received: by mail-ed1-f66.google.com with SMTP id v18-v6so13894448edq.12 for ; Sun, 07 Oct 2018 00:34:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=karger-me.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=BIlWc3TLECKXxONVuVmJSPqJzYfWG9g4XPMC/kd1Y+I=; b=pk1Ye29WZtiQ9LzKLNJ0wRhMA/2aH4s5yQY1uSuvKjvTWNH5wJyaIMEPAFk9qrJL4R lusQ9yB6EcBiiutXPNATCvExs19PEL5D1dlv6KR80duxQYC8av1pDTUjjRd2qQlpqHmP vpgYDFVC4T+Sfwo6fz7pG3UVmsyn0BCHsoYMjuwgxsw3AF5etqeLxQ+BQ1OYVTRFZ2Bf hURa0wma0mkgwb0QVL4nJtlz0zx8ayb4V6Rr/K72ZpIPjxKyOCvimTRIKej0TLuCn7GU w11bLyofKHIMOgBYKIajNrf1zzEJYAXywX5IEIQLdHotIDspcGGNa6erIwDPD08P68v1 mpUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=BIlWc3TLECKXxONVuVmJSPqJzYfWG9g4XPMC/kd1Y+I=; b=ERoMP4cA1855+QufklT6e/3X90fpJQGu/mwohRa+Hhuw8A43c1umKs19TNrMay9oDv F59CZX1v16IA+DqjBXwlRcHqVrDdD9XsMZuK9B7ugBmVuhjpUYl+20kk1TIPe7p1QghF Zu8jYyjFKIkiekikiO2Y0kTDE4WirS3X3D1t75y/3K0OdKwmeqcZPGKumbgKU6oNnSBv h5dXjYfLkMiZP55nrEhJ5QF4sTlqdabl5khobiP3i6oq1mo+RNplTZs1KDHTq8J/r8Hb 4TSZS9k+EW4f3F8+91lUQJuDbQkr9jqKILIDHmxT8GpOJOFF27PPRvlBYdGB6N38s78H 6X7g== X-Gm-Message-State: ABuFfoiZqsQYke7lr6+VKYrNXQ+U3JmJgudX3OhA/qjrr774UeJ6uLPM bc9+tbD9DubFLgAXWVpseSWfH4MtmTP/9Q== X-Google-Smtp-Source: ACcGV60NXRLCJawgwaFrpV8QThr0SHSgxs/kOrfUA8V/ykFZcLMHZEJOMbSAL04PyVzJrNkIBEEEPQ== X-Received: by 2002:a50:86ba:: with SMTP id r55-v6mr22614556eda.87.1538897659945; Sun, 07 Oct 2018 00:34:19 -0700 (PDT) Received: from localhost.localdomain ([2001:985:e54:1050::1000]) by smtp.gmail.com with ESMTPSA id l18-v6sm2295460ejc.62.2018.10.07.00.34.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Oct 2018 00:34:19 -0700 (PDT) From: Steffan Karger To: openvpn-devel@lists.sourceforge.net Date: Sun, 7 Oct 2018 09:34:13 +0200 Message-Id: <20181007073413.9778-1-steffan@karger.me> 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.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.208.66 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.208.66 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.0 DKIMWL_WL_MED DKIMwl.org - Whitelisted Medium sender -0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1g93a6-00DnXb-R7 Subject: [Openvpn-devel] [PATCH] Add support for CHACHA20-POLY1305 in the data channel 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 We explicitly only supported GCM as a valid AEAD mode, change that to also allow ChaCha20-Poly1305 as an AEAD cipher. That works nicely with our new (GCM) data channel format, because is has the same 96-bit IV. Note that we need some tricks to not treat the cipher as insecure, because we used to only look at the block size of a cipher to determine if find a cipher insecure. But ChaCha20-Poly1305 is a stream cipher, which essentially has a 'block size' of 1 byte and is reported as such. So, special-case this cipher to be in the list of secure ciphers. Signed-off-by: Steffan Karger --- Changes.rst | 10 ++++++++++ src/openvpn/crypto.c | 2 +- src/openvpn/crypto_backend.h | 5 +++++ src/openvpn/crypto_mbedtls.c | 21 ++++++++++++++++++--- src/openvpn/crypto_openssl.c | 33 ++++++++++++++++++++++++++++----- src/openvpn/ssl.c | 2 +- 6 files changed, 63 insertions(+), 10 deletions(-) diff --git a/Changes.rst b/Changes.rst index a6090cf5..70ce2e10 100644 --- a/Changes.rst +++ b/Changes.rst @@ -1,3 +1,13 @@ +Overview of changes in 2.5 +========================== + +New features +------------ +ChaCha20-Poly1305 cipher support + Added support for using the ChaCha20-Poly1305 cipher in the OpenVPN data + channel. + + Overview of changes in 2.4 ========================== diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index c8d95f3b..6d34acd7 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -841,7 +841,7 @@ init_key_ctx(struct key_ctx *ctx, const struct key *key, dmsg(D_CRYPTO_DEBUG, "%s: CIPHER block_size=%d iv_size=%d", prefix, cipher_kt_block_size(kt->cipher), cipher_kt_iv_size(kt->cipher)); - if (cipher_kt_block_size(kt->cipher) < 128/8) + if (cipher_kt_insecure(kt->cipher)) { msg(M_WARN, "WARNING: INSECURE cipher with block size less than 128" " bit (%d bit). This allows attacks like SWEET32. Mitigate by " diff --git a/src/openvpn/crypto_backend.h b/src/openvpn/crypto_backend.h index f917c8d7..38b2c175 100644 --- a/src/openvpn/crypto_backend.h +++ b/src/openvpn/crypto_backend.h @@ -284,6 +284,11 @@ int cipher_kt_block_size(const cipher_kt_t *cipher_kt); */ int cipher_kt_tag_size(const cipher_kt_t *cipher_kt); +/** + * Returns true if we consider this cipher to be insecure. + */ +bool cipher_kt_insecure(const cipher_kt_t *cipher); + /** * Returns the mode that the cipher runs in. * diff --git a/src/openvpn/crypto_mbedtls.c b/src/openvpn/crypto_mbedtls.c index 82f4e574..a5a096b1 100644 --- a/src/openvpn/crypto_mbedtls.c +++ b/src/openvpn/crypto_mbedtls.c @@ -51,6 +51,7 @@ #include #include #include +#include #include @@ -175,7 +176,7 @@ show_available_ciphers(void) while (*ciphers != 0) { const cipher_kt_t *info = mbedtls_cipher_info_from_type(*ciphers); - if (info && cipher_kt_block_size(info) >= 128/8) + if (info && !cipher_kt_insecure(info)) { print_cipher(info); } @@ -188,7 +189,7 @@ show_available_ciphers(void) while (*ciphers != 0) { const cipher_kt_t *info = mbedtls_cipher_info_from_type(*ciphers); - if (info && cipher_kt_block_size(info) < 128/8) + if (info && cipher_kt_insecure(info)) { print_cipher(info); } @@ -550,6 +551,16 @@ cipher_kt_tag_size(const mbedtls_cipher_info_t *cipher_kt) return 0; } +bool +cipher_kt_insecure(const mbedtls_cipher_info_t *cipher_kt) +{ + return !(cipher_kt_block_size(cipher_kt) >= 128/8 +#if defined(MBEDTLS_CHACHAPOLY_C) && (MBEDTLS_VERSION_NUMBER >= 0x020C0000) + || cipher_kt->type == MBEDTLS_CIPHER_CHACHA20_POLY1305 +#endif + ); +} + int cipher_kt_mode(const mbedtls_cipher_info_t *cipher_kt) { @@ -573,7 +584,11 @@ cipher_kt_mode_ofb_cfb(const cipher_kt_t *cipher) bool cipher_kt_mode_aead(const cipher_kt_t *cipher) { - return cipher && cipher_kt_mode(cipher) == OPENVPN_MODE_GCM; + return cipher && (cipher_kt_mode(cipher) == OPENVPN_MODE_GCM +#if defined(MBEDTLS_CHACHAPOLY_C) && (MBEDTLS_VERSION_NUMBER >= 0x020C0000) + || cipher_kt_mode(cipher) == MBEDTLS_MODE_CHACHAPOLY +#endif + ); } diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c index 9ec2048d..0004be9e 100644 --- a/src/openvpn/crypto_openssl.c +++ b/src/openvpn/crypto_openssl.c @@ -245,6 +245,7 @@ const cipher_name_pair cipher_name_translation_table[] = { { "AES-128-GCM", "id-aes128-GCM" }, { "AES-192-GCM", "id-aes192-GCM" }, { "AES-256-GCM", "id-aes256-GCM" }, + { "CHACHA20-POLY1305", "ChaCha20-Poly1305" }, }; const size_t cipher_name_translation_table_count = sizeof(cipher_name_translation_table) / sizeof(*cipher_name_translation_table); @@ -321,7 +322,7 @@ show_available_ciphers(void) qsort(cipher_list, num_ciphers, sizeof(*cipher_list), cipher_name_cmp); for (i = 0; i < num_ciphers; i++) { - if (cipher_kt_block_size(cipher_list[i]) >= 128/8) + if (!cipher_kt_insecure(cipher_list[i])) { print_cipher(cipher_list[i]); } @@ -330,7 +331,7 @@ show_available_ciphers(void) printf("\nThe following ciphers have a block size of less than 128 bits, \n" "and are therefore deprecated. Do not use unless you have to.\n\n"); for (i = 0; i < num_ciphers; i++) { - if (cipher_kt_block_size(cipher_list[i]) < 128/8) + if (cipher_kt_insecure(cipher_list[i])) { print_cipher(cipher_list[i]); } @@ -686,6 +687,16 @@ cipher_kt_tag_size(const EVP_CIPHER *cipher_kt) } } +bool +cipher_kt_insecure(const EVP_CIPHER *cipher) +{ + return !(cipher_kt_block_size(cipher) >= 128/8 +#ifdef NID_chacha20_poly1305 + || EVP_CIPHER_nid(cipher) == NID_chacha20_poly1305 +#endif + ); +} + int cipher_kt_mode(const EVP_CIPHER *cipher_kt) { @@ -720,10 +731,22 @@ bool cipher_kt_mode_aead(const cipher_kt_t *cipher) { #ifdef HAVE_AEAD_CIPHER_MODES - return cipher && (cipher_kt_mode(cipher) == OPENVPN_MODE_GCM); -#else - return false; + if (cipher) + { + switch (EVP_CIPHER_nid(cipher)) + { + case NID_aes_128_gcm: + case NID_aes_192_gcm: + case NID_aes_256_gcm: +#ifdef NID_chacha20_poly1305 + case NID_chacha20_poly1305: #endif + return true; + } + } +#endif + + return false; } /* diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 4257c33d..315303b0 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -294,7 +294,7 @@ tls_get_cipher_name_pair(const char *cipher_name, size_t len) static void tls_limit_reneg_bytes(const cipher_kt_t *cipher, int *reneg_bytes) { - if (cipher && (cipher_kt_block_size(cipher) < 128/8)) + if (cipher && cipher_kt_insecure(cipher)) { if (*reneg_bytes == -1) /* Not user-specified */ {