From: "plaisthos (Code Review)" Date: Tue, 21 Nov 2023 19:36:50 +0000 In-Reply-To: References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <79cc7e4d5bffd6bdbe28ca84abf05a756c105473-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="MUeuRL0g8qE="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Implement generating TLS 1.0 PRF using new OpenSSL 3.0 APIs List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: openvpn-devel --MUeuRL0g8qE= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld. Hello flichtenheld,=20 I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/457?usp=3Demail to look at the new patch set (#2). Change subject: Implement generating TLS 1.0 PRF using new OpenSSL 3.0 APIs ...................................................................... Implement generating TLS 1.0 PRF using new OpenSSL 3.0 APIs OpenSSL 3.0 introduced a new API for doing key derivation. So this leaves us now with three different implementation for 1.0.2, 1.1.x and 3.x. This was initially done to maybe still have a working TLS 1.0 PRF when using OpenSSL 3.0, it gives the same error as with the older API but since moving to a new API is always good, we use the new API when using OpenSSL 3.0. We also print the internal OpenSSL error message when the KDF fails. Change-Id: Ic74195a4ed340547c5e862dc2438f95be318c286 Signed-off-by: Arne Schwabe --- M src/openvpn/crypto_openssl.c 1 file changed, 50 insertions(+), 1 deletion(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/57/457/2 diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c index fe1254f..7351a5f 100644 --- a/src/openvpn/crypto_openssl.c +++ b/src/openvpn/crypto_openssl.c @@ -54,6 +54,7 @@ #endif #if OPENSSL_VERSION_NUMBER >=3D 0x30000000L #include +#include #endif #if defined(_WIN32) && defined(OPENSSL_NO_EC) @@ -1373,8 +1374,56 @@ { return CRYPTO_memcmp(a, b, size); } +#if (OPENSSL_VERSION_NUMBER >=3D 0x3000000L) && !defined(LIBRESSL_VERSION_= NUMBER) +bool +ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8_t *secret, + int secret_len, uint8_t *output, int output_len) +{ + bool ret =3D true; + EVP_KDF_CTX *kctx =3D NULL; -#if (OPENSSL_VERSION_NUMBER >=3D 0x10100000L) && !defined(LIBRESSL_VERSION= _NUMBER) + + EVP_KDF *kdf =3D EVP_KDF_fetch(NULL, "TLS1-PRF", NULL); + if (!kdf) + { + goto err; + } + + kctx =3D EVP_KDF_CTX_new(kdf); + + if (!kctx) + { + goto err; + } + + OSSL_PARAM params[4]; + + params[0] =3D OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, + SN_md5_sha1, strlen(SN_md= 5_sha1)); + params[1] =3D OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SECRET, + secret, (size_t) secret_= len); + params[2] =3D OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED, + seed, (size_t) seed_len); + params[3] =3D OSSL_PARAM_construct_end(); + + if (EVP_KDF_derive(kctx, output, output_len, params) <=3D 0) + { + crypto_msg(D_TLS_DEBUG_LOW, "Generating TLS 1.0 PRF using " + "EVP_KDF_derive failed"); + goto err; + } + + goto out; + +err: + ret =3D false; +out: + EVP_KDF_free(kdf); + EVP_KDF_free(kdf); + + return ret; +} +#elif (OPENSSL_VERSION_NUMBER >=3D 0x10100000L) && !defined(LIBRESSL_VERSI= ON_NUMBER) bool ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8_t *secret, int secret_len, uint8_t *output, int output_len) -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/457?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ic74195a4ed340547c5e862dc2438f95be318c286 Gerrit-Change-Number: 457 Gerrit-PatchSet: 2 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: flichtenheld Gerrit-MessageType: newpatchset --MUeuRL0g8qE= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld.

plaisthos uploaded patch set #2 to this change.

<= a href=3D"http://gerrit.openvpn.net/c/openvpn/+/457?usp=3Demail">View Chang= e

Implement generating TLS 1.0 PRF using new OpenSSL 3.0 APIs

Op= enSSL 3.0 introduced a new API for doing key derivation. So this leaves
= us now with three different implementation for 1.0.2, 1.1.x and 3.x.
This was initially done to maybe still have a working TLS 1.0 PRF when
= using OpenSSL 3.0, it gives the same error as with the older API but
sin= ce moving to a new API is always good, we use the new API when using
Ope= nSSL 3.0. We also print the internal OpenSSL error message when
the KDF = fails.

Change-Id: Ic74195a4ed340547c5e862dc2438f95be318c286
Signe= d-off-by: Arne Schwabe <arne@...1227...>
---
M src/openvpn/cryp= to_openssl.c
1 file changed, 50 insertions(+), 1 deletion(-)

g=
it pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/57/457/2
<= pre style=3D"font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c<= /span>
index fe1254f..7351a5f 100644
--- a/src/ope= nvpn/crypto_openssl.c
+++ b/src/openvpn/crypto_openssl.c
@@ -54,6 +54,7 @@
#endif
#i= f OPENSSL_VERSION_NUMBER >=3D 0x30000000L
#include <= openssl/provider.h>
+#if (OPENSSL_VERSION_NUMBER >= =3D 0x3000000L) && !defined(LIBRESSL_VERSION_NUMBER)
+bool

+ssl_tls1_PRF(const uint8_t *seed, int seed_len, c= onst uint8_t *secret,
+ int secret_len, uint8_t *output, int output_len)
<= span style=3D"color: hsl(120, 100%, 40%);">+{
+ bool ret =3D true;
+ EVP_KDF_CTX *kctx =3D NULL;

-#if (OPENSSL_VERSI= ON_NUMBER >=3D 0x10100000L) && !defined(LIBRESSL_VERSION_NUMBER)=
+
+ EVP_KDF *kdf =3D EVP_KDF_fetch(NUL= L, "TLS1-PRF", NULL);
+ if (!kdf)
+ {
+ = goto err;
+ }

+
+ kctx =3D EVP_KDF_CTX_new(kdf);=
+
+ if (!kctx)
+ {
+ goto err;
+ }
+

+ OSSL_PARAM params[4]= ;
+
+ params[0] =3D OSSL_PARAM_construc= t_utf8_string(OSSL_KDF_PARAM_DIGEST,
+ SN_md5_sh= a1, strlen(SN_md5_sha1));
+ params[1] =3D OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SE= CRET,
+ = secret, (size_t) secret_len);+ params[2] =3D OSSL_PARAM_= construct_octet_string(OSSL_KDF_PARAM_SEED,
+ s= eed, (size_t) seed_len);
+ params[3] =3D OSSL_PARAM_construct_end();
+
+ if (EVP_KDF_derive(kctx, output, output_len, params) <= =3D 0)
+ {<= br>+ crypto_msg(D_TLS_DE= BUG_LOW, "Generating TLS 1.0 PRF using "
+ "EVP_KDF_derive fail= ed");
+ g= oto err;
+ }
+
+ goto out;
+
+err:
+ ret = =3D false;
+out:
+ EVP_KDF_free(kdf);
+ EVP_KDF_free(kdf)= ;
+
+ return ret;
+}
+#elif (OPENSSL_VERSION_NUMBER >=3D 0x10100000L) &&am= p; !defined(LIBRESSL_VERSION_NUMBER)
bool
= ssl_tls1_PRF(const uint8_t *seed, int seed_len, const uint8_t *secret,
int secret_len, uint8_t *output, int output_len)=

To view, visit change 457. To unsubscribe, = or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic74195a4ed340547c5e862dc243= 8f95be318c286
Gerrit-Change-Number: 457
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newpatchset
--MUeuRL0g8qE=--