| Message ID | 20210810061644.20353-1-maximilian.fillinger@foxcrypto.com |
|---|---|
| State | Accepted |
| Headers |
Return-Path: <openvpn-devel-bounces@lists.sourceforge.net> Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director10.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net with LMTP id uDtdBPgdEmGgdAAAIUCqbw (envelope-from <openvpn-devel-bounces@lists.sourceforge.net>) for <patchwork@openvpn.net>; Tue, 10 Aug 2021 02:34:32 -0400 Received: from proxy12.mail.iad3b.rsapps.net ([172.31.255.6]) by director10.mail.ord1d.rsapps.net with LMTP id YEnuA/gdEmGbCgAApN4f7A (envelope-from <openvpn-devel-bounces@lists.sourceforge.net>) for <patchwork@openvpn.net>; Tue, 10 Aug 2021 02:34:32 -0400 Received: from smtp17.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 LMTPS id iN6LOvcdEmEOCwAAEsW3lA (envelope-from <openvpn-devel-bounces@lists.sourceforge.net>) for <patchwork@openvpn.net>; Tue, 10 Aug 2021 02:34:31 -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: smtp17.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 (key not found in DNS) header.d=foxcrypto.com; dmarc=fail (p=none; dis=none) header.from=foxcrypto.com X-Suspicious-Flag: YES X-Classification-ID: 04c36924-f9a5-11eb-acc4-52540094e46f-1-1 Received: from [216.105.38.7] ([216.105.38.7:41868] helo=lists.sourceforge.net) by smtp17.gate.iad3b.rsapps.net (envelope-from <openvpn-devel-bounces@lists.sourceforge.net>) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id E1/58-22984-7FD12116; Tue, 10 Aug 2021 02:34:31 -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 <openvpn-devel-bounces@lists.sourceforge.net>) id 1mDLKF-0004eU-H9; Tue, 10 Aug 2021 06:33: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 <maximilian.fillinger@foxcrypto.com>) id 1mDLKE-0004eH-CS for openvpn-devel@lists.sourceforge.net; Tue, 10 Aug 2021 06:33:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:MIME-Version:Message-ID:Date:Subject: CC:To:From:Sender:Reply-To: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=erxaI9cBqhBnrdwzln5KJeyeyoORLonb3lYFIhZxQYM=; b=d5D8IZDIRAJ9ee12s2/4DLxIXz WPC8XQUi19hAeqRtCieIlsr+5l1F69oRc4quUgFpBRnHFmKXY3YQ6m3w7U5GYajC2l1Ke9K+/OllF Z6nBJNGLYwM06P+cMElfUq2Vk5gbKMrXtf2Z2c6Y5YL+FFPcUB37MV6x1WAQdYy7BNhw=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From:Sender: Reply-To: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=erxaI9cBqhBnrdwzln5KJeyeyoORLonb3lYFIhZxQYM=; b=I bFAOmcmZavjrMkeoqXUIMPLaSvE96sUshSsxNta6xPDx4QETF1Uq6JceLkhfa4gGq34DZnUHadhx1 3FKHi0q329vdNVL0feV7MsyUUF8fBt2B8ztwTyzzvQt5pSdK6G9j77LcIhArEnoCxJO8hrVh2b8DL du/rkCfrLaTq0jh8=; Received: from nl-dft-mx-01.fox-it.com ([178.250.144.135]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) id 1mDLK5-0000Iu-Cr for openvpn-devel@lists.sourceforge.net; Tue, 10 Aug 2021 06:33:22 +0000 From: Max Fillinger <maximilian.fillinger@foxcrypto.com> To: <openvpn-devel@lists.sourceforge.net> Date: Tue, 10 Aug 2021 08:16:44 +0200 Message-ID: <20210810061644.20353-1-maximilian.fillinger@foxcrypto.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-ClientProxiedBy: FOXDFT1EX01.FOX.local (10.0.0.129) To FOXDFT1EX01.FOX.local (10.0.0.129) X-FE-Policy-ID: 13:3:2:SYSTEM DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; d=foxcrypto.com; s=NL-DFT-MX-01; c=relaxed/relaxed; h=from:to:cc:subject:date:message-id:mime-version:content-type; bh=erxaI9cBqhBnrdwzln5KJeyeyoORLonb3lYFIhZxQYM=; b=FY/yHyYCeSgSUrBA/Q73KDP8wPw5lHy9MVN7fErldA3DSPLl4+8RweQZ+KLrI5CMuNij+sA3IILL 5NZmH6dnHlcZ5O++ePumt0n6qm6yzcyczm9VP4Fi/CYdp7SjGSZid49gxhFQ1zFcDuEGlKGVs25h HJT1KLfrOvg6WxnACsnca7ZDfrIppuqSfVIqmYC8tjlmQheRsRFiSGu5a4FGETGHL+pM3h+ixYty rJvAAbiyMknLImIlAAknMlIAX5kre5aAyd6Gll0vhnTwcVJhWgnsWzdVND3eNh/xt9tpAlG9mVaA eD1RRT1Jikd2PQ3FU6pkoixMK22m/WkL5zspfg== X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.1 DKIM_INVALID DKIM or DK signature exists, but is not valid X-Headers-End: 1mDLK5-0000Iu-Cr Subject: [Openvpn-devel] [PATCH] Replace deprecated mbedtls DRBG update function X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: <openvpn-devel.lists.sourceforge.net> List-Unsubscribe: <https://lists.sourceforge.net/lists/options/openvpn-devel>, <mailto:openvpn-devel-request@lists.sourceforge.net?subject=unsubscribe> List-Archive: <http://sourceforge.net/mailarchive/forum.php?forum_name=openvpn-devel> List-Post: <mailto:openvpn-devel@lists.sourceforge.net> List-Help: <mailto:openvpn-devel-request@lists.sourceforge.net?subject=help> List-Subscribe: <https://lists.sourceforge.net/lists/listinfo/openvpn-devel>, <mailto:openvpn-devel-request@lists.sourceforge.net?subject=subscribe> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox |
| Series |
[Openvpn-devel] Replace deprecated mbedtls DRBG update function
|
|
Commit Message
Maximilian Fillinger
Aug. 9, 2021, 8:16 p.m. UTC
The function mbedtls_ctr_drbg_update is deprecated as of mbedtls 2.16
and is superseded by mbedtls_ctr_drbg_update_ret, which returns an error
code. This commit replaces the call to the deprecated function with the
new one and logs a warning in case of an error.
For older versions of mbedtls, we add a compatibility function that runs
mbedtls_ctr_drbg_update and returns 0.
Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
---
src/openvpn/ssl_mbedtls.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
Comments
Am 10.08.21 um 08:16 schrieb Max Fillinger:
> +#if MBEDTLS_VERSION_NUMBER < 0x02100000
Is that really 2.16? Looking at the API doc
(https://tls.mbed.org/api/version_8h.html#adb4f54ebb33fd1a25e2c4d4480cf4936)
it sounds like there should be a 16 in that number.
Arne
> From: Arne Schwabe [mailto:arne@rfc2549.org] > Sent: dinsdag 10 augustus 2021 12:12 > To: Maximilian Fillinger <maximilian.fillinger@foxcrypto.com>; openvpn- > devel@lists.sourceforge.net > Subject: Re: [Openvpn-devel] [PATCH] Replace deprecated mbedtls DRBG > update function > > Am 10.08.21 um 08:16 schrieb Max Fillinger: > > +#if MBEDTLS_VERSION_NUMBER < 0x02100000 > > Is that really 2.16? Looking at the API doc > (https://tls.mbed.org/api/version_8h.html#adb4f54ebb33fd1a25e2c4d4480cf4 > 936) > it sounds like there should be a 16 in that number. It's a hexadecimal 16. Version 2.26.0 for example does #define MBEDTLS_VERSION_NUMBER 0x021A0000
Am 10.08.21 um 12:17 schrieb Maximilian Fillinger: >> From: Arne Schwabe [mailto:arne@rfc2549.org] >> Sent: dinsdag 10 augustus 2021 12:12 >> To: Maximilian Fillinger <maximilian.fillinger@foxcrypto.com>; openvpn- >> devel@lists.sourceforge.net >> Subject: Re: [Openvpn-devel] [PATCH] Replace deprecated mbedtls DRBG >> update function >> >> Am 10.08.21 um 08:16 schrieb Max Fillinger: >>> +#if MBEDTLS_VERSION_NUMBER < 0x02100000 >> >> Is that really 2.16? Looking at the API doc >> (https://tls.mbed.org/api/version_8h.html#adb4f54ebb33fd1a25e2c4d4480cf4 >> 936) >> it sounds like there should be a 16 in that number. > > It's a hexadecimal 16. Version 2.26.0 for example does > > #define MBEDTLS_VERSION_NUMBER 0x021A0000 > Oh well that is confusing. Thanks for clearing that up. Arne
Am 10.08.21 um 08:16 schrieb Max Fillinger: > The function mbedtls_ctr_drbg_update is deprecated as of mbedtls 2.16 > and is superseded by mbedtls_ctr_drbg_update_ret, which returns an error > code. This commit replaces the call to the deprecated function with the > new one and logs a warning in case of an error. > > For older versions of mbedtls, we add a compatibility function that runs > mbedtls_ctr_drbg_update and returns 0. > > Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com> > --- Normally we have patch v2 here and also a patch v2 in the subject (use -v 2 when doing git format-patch) but for this small patch it is not a problem. > src/openvpn/ssl_mbedtls.c | 20 +++++++++++++++++++- > 1 file changed, 19 insertions(+), 1 deletion(-) > > diff --git a/src/openvpn/ssl_mbedtls.c b/src/openvpn/ssl_mbedtls.c > index 265ea36f..1853335e 100644 > --- a/src/openvpn/ssl_mbedtls.c > +++ b/src/openvpn/ssl_mbedtls.c > @@ -62,6 +62,21 @@ > #include <mbedtls/oid.h> > #include <mbedtls/pem.h> > > +/** > + * Compatibility: mbedtls_ctr_drbg_update was deprecated in mbedtls 2.16 and > + * replaced with mbedtls_ctr_drbg_update_ret, which returns an error code. > + * For older versions, we call mbedtls_ctr_drbg_update and return 0 (success). > + */ > +#if MBEDTLS_VERSION_NUMBER < 0x02100000 > +static int mbedtls_ctr_drbg_update_ret(mbedtls_ctr_drbg_context *ctx, > + const unsigned char *additional, > + size_t add_len) > +{ > + mbedtls_ctr_drbg_update(ctx, additional, add_len); > + return 0; > +} > +#endif > + > static const mbedtls_x509_crt_profile openvpn_x509_crt_profile_legacy = > { > /* Hashes from SHA-1 and above */ > @@ -950,7 +965,10 @@ tls_ctx_personalise_random(struct tls_root_ctx *ctx) > > if (0 != memcmp(old_sha256_hash, sha256_hash, sizeof(sha256_hash))) > { > - mbedtls_ctr_drbg_update(cd_ctx, sha256_hash, 32); > + if (!mbed_ok(mbedtls_ctr_drbg_update_ret(cd_ctx, sha256_hash, 32))) > + { > + msg(M_WARN, "WARNING: failed to personalise random, could not update CTR_DRBG"); > + } > memcpy(old_sha256_hash, sha256_hash, sizeof(old_sha256_hash)); > } > } > Apart from the fact that we might want to abort (M_FATAL) if this fails instead basically ignoring the error and just log it, the change is fine. Considering the return status was ignored before, this patch is otherwise good. But failing also does not have any really bad impact... So: Acked-By: Arne Schwabe <arne@rfc2549.org>
> Normally we have patch v2 here and also a patch v2 in the subject (use > -v 2 when doing git format-patch) but for this small patch it is not a > problem. I'll keep it in mind for next time! > Apart from the fact that we might want to abort (M_FATAL) if this fails > instead basically ignoring the error and just log it, the change is > fine. Considering the return status was ignored before, this patch is > otherwise good. But failing also does not have any really bad impact... I was thinking about making it fatal, but there's another place where personalizing random can fail that also only gives a warning. So that's what I went with. (I wouldn't be opposed to making them both fatal, though.) Anyway, thanks for the ACK!
On 10/08/2021 14:51, Maximilian Fillinger wrote: >> Normally we have patch v2 here and also a patch v2 in the subject (use >> -v 2 when doing git format-patch) but for this small patch it is not a >> problem. > > I'll keep it in mind for next time! > >> Apart from the fact that we might want to abort (M_FATAL) if this fails >> instead basically ignoring the error and just log it, the change is >> fine. Considering the return status was ignored before, this patch is >> otherwise good. But failing also does not have any really bad impact... > > I was thinking about making it fatal, but there's another place where > personalizing random can fail that also only gives a warning. So that's what > I went with. (I wouldn't be opposed to making them both fatal, though.) > IMHO it's ok to keep WARN for now because, like pointed out, other parts of the code path just warn in case of issues. Just a few line above Max's change there is another failure treated with a WARN only. Therefore I'd stick to WARN unless a complete revamp is performed on the entire codepath. Regards,
Hi, On 10/08/2021 08:16, Max Fillinger wrote: > The function mbedtls_ctr_drbg_update is deprecated as of mbedtls 2.16 > and is superseded by mbedtls_ctr_drbg_update_ret, which returns an error > code. This commit replaces the call to the deprecated function with the > new one and logs a warning in case of an error. > > For older versions of mbedtls, we add a compatibility function that runs > mbedtls_ctr_drbg_update and returns 0. > > Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com> I also gave this patch a go and compiled it against: * mbedTLS 2.26.0 * mbedTLS 2.20.0 * mbedTLS 2.10.0 all good. Patch looks good to me too. Acked-by: Antonio Quartulli <antonio@openvpn.net>
I have only done a cursory look ("it's like v1 with the compat function"),
and done a minimal test compile (Linux, mbedTLS 2.26.0, and FreeBSD,
mbedTLS 2.16.11) + t_client test run. No surprises.
Your patch has been applied to the master branch.
commit b99fa3fd4fc41862354be709edb9877aae3e138c
Author: Max Fillinger
Date: Tue Aug 10 08:16:44 2021 +0200
Replace deprecated mbedtls DRBG update function
Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
Acked-by: Antonio Quartulli <antonio@openvpn.net>
Message-Id: <20210810061644.20353-1-maximilian.fillinger@foxcrypto.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg22711.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
--
kind regards,
Gert Doering
Hi, On Tue, Aug 10, 2021 at 08:16:44AM +0200, Max Fillinger wrote: > The function mbedtls_ctr_drbg_update is deprecated as of mbedtls 2.16 > and is superseded by mbedtls_ctr_drbg_update_ret, which returns an error > code. This commit replaces the call to the deprecated function with the > new one and logs a warning in case of an error. > > For older versions of mbedtls, we add a compatibility function that runs > mbedtls_ctr_drbg_update and returns 0. For the record, this breaks 2.14.*1* - which does have this function, and the static-vs-non-static prototyping causes a compile error. So, followup patch needed. 2.14.0 does not have it, and from what I understand, 2.15.x does not have it either. But maybe we do not care for 2.15 gert
diff --git a/src/openvpn/ssl_mbedtls.c b/src/openvpn/ssl_mbedtls.c index 265ea36f..1853335e 100644 --- a/src/openvpn/ssl_mbedtls.c +++ b/src/openvpn/ssl_mbedtls.c @@ -62,6 +62,21 @@ #include <mbedtls/oid.h> #include <mbedtls/pem.h> +/** + * Compatibility: mbedtls_ctr_drbg_update was deprecated in mbedtls 2.16 and + * replaced with mbedtls_ctr_drbg_update_ret, which returns an error code. + * For older versions, we call mbedtls_ctr_drbg_update and return 0 (success). + */ +#if MBEDTLS_VERSION_NUMBER < 0x02100000 +static int mbedtls_ctr_drbg_update_ret(mbedtls_ctr_drbg_context *ctx, + const unsigned char *additional, + size_t add_len) +{ + mbedtls_ctr_drbg_update(ctx, additional, add_len); + return 0; +} +#endif + static const mbedtls_x509_crt_profile openvpn_x509_crt_profile_legacy = { /* Hashes from SHA-1 and above */ @@ -950,7 +965,10 @@ tls_ctx_personalise_random(struct tls_root_ctx *ctx) if (0 != memcmp(old_sha256_hash, sha256_hash, sizeof(sha256_hash))) { - mbedtls_ctr_drbg_update(cd_ctx, sha256_hash, 32); + if (!mbed_ok(mbedtls_ctr_drbg_update_ret(cd_ctx, sha256_hash, 32))) + { + msg(M_WARN, "WARNING: failed to personalise random, could not update CTR_DRBG"); + } memcpy(old_sha256_hash, sha256_hash, sizeof(old_sha256_hash)); } }