From: "cron2 (Code Review)"
Date: Sat, 10 Feb 2024 09:13:08 +0000
In-Reply-To:
References:
Reply-To: gert@...1296..., arne-openvpn@...1227...,
openvpn-devel@lists.sourceforge.net, frank@...2641...
Message-ID: <35178e7fc7e1ea919ae3592781b845ab34926aab-HTML@...2715...>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Content-Type: multipart/alternative; boundary="fLtrOnS1i74="; 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: plaisthos
Cc: flichtenheld , openvpn-devel
--fLtrOnS1i74=
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/45=
7?usp=3Demail )
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 in FIPS but 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.
This also allows us now to compile an OpenSSL build that has been built with
OPENSSL_NO_MD5. Which is not yet common but might be in the future.
Change-Id: Ic74195a4ed340547c5e862dc2438f95be318c286
Signed-off-by: Arne Schwabe
Acked-by: Frank Lichtenheld
Message-Id: <20240209110629.15364-1-frank@...2641...>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg28=
203.html
Signed-off-by: Gert Doering
---
M src/openvpn/crypto_openssl.c
1 file changed, 51 insertions(+), 1 deletion(-)
diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c
index e8ddf14..4fd5e6b 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)
@@ -1329,8 +1330,57 @@
{
return CRYPTO_memcmp(a, b, size);
}
+#if (OPENSSL_VERSION_NUMBER >=3D 0x30000000L) && !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];
+
+ /* The OpenSSL APIs require us to cast the const aways even though the
+ * strings are never changed and only read */
+ 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,
+ (uint8_t *) secret, (siz=
e_t) secret_len);
+ params[2] =3D OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED,
+ (uint8_t *) 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);
+
+ 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: 9
Gerrit-Owner: plaisthos
Gerrit-Reviewer: flichtenheld
Gerrit-CC: openvpn-devel
Gerrit-MessageType: merged
--fLtrOnS1i74=
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
cron2 submitted this change.
View Change
Implement generating TLS 1.0 PRF using new Ope=
nSSL 3.0 APIs
OpenSSL 3.0 introduced a new API for doing key derivat=
ion. 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 worki=
ng TLS 1.0 PRF when
using OpenSSL 3.0 in FIPS but it gives the same erro=
r as with the older API.
But since moving to a new API is always good, w=
e use the new API when using
OpenSSL 3.0. We also print the internal Ope=
nSSL error message when
the KDF fails.
This also allows us now to=
compile an OpenSSL build that has been built with
OPENSSL_NO_MD5. Which=
is not yet common but might be in the future.
Change-Id: Ic74195a4e=
d340547c5e862dc2438f95be318c286
Signed-off-by: Arne Schwabe <arne@...493...=
1227...>
Acked-by: Frank Lichtenheld <frank@...2641...>
Mess=
age-Id: <20240209110629.15364-1-frank@...2641...>
URL: https://www=
.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg28203.html
Sign=
ed-off-by: Gert Doering <gert@...1296...>
---
M src/openvpn/cry=
pto_openssl.c
1 file changed, 51 insertions(+), 1 deletion(-)
diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c=
index e8ddf14..4fd5e6b 100644
--- a/src/op=
envpn/crypto_openssl.c
+++ b/src/openvpn/crypto_openssl.c=
span>
@@ -54,6 +54,7 @@
#endif
#=
if OPENSSL_VERSION_NUMBER >=3D 0x30000000L
#include <=
;openssl/provider.h>
+#include <openssl/core_names.h>
#endif
#if defined(_WIN32) && defined(OPENSSL_NO=
_EC)
@@ -1329,8 +1330,57 @@
{
return CRYPTO_memcmp(a, b, size);
}
+#if (OPENSSL_VERSION_NUMBER >=
=3D 0x30000000L) && !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_VERS=
ION_NUMBER >=3D 0x10100000L) && !defined(LIBRESSL_VERSION_NUMBER=
)
+
+ EVP_KDF *kdf =3D EVP_KDF_fetch(NU=
LL, "TLS1-PRF", NULL);
+ if (!kdf)
+ {
+ =
goto err;
+ }
+
+ kctx =3D EVP_KDF_CTX_new(kdf);=
+
+ if (!kctx)
+ {
+ goto err;
+ }
+
+ OSSL_PARAM params[4]=
;
+
+ /* The OpenSSL APIs require us to=
cast the const aways even though the
+ * strings are never changed and only read */<=
br>+ params[0] =3D OSSL_PARA=
M_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
+ =
SN_md5_sha1, strlen(SN_md5_sha1));
+ params[1] =3D OSSL_PARAM_construct_octet_string(OSSL_KD=
F_PARAM_SECRET,
+ =
(uint8_t *) secret, (size_t) =
secret_len);
+ par=
ams[2] =3D OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED,
+ =
(uint8_t *) seed, (size_t) seed_len);
+ params[3] =3D OSSL_PARAM_constru=
ct_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);
+
+ retur=
n ret;
+}
<=
span style=3D"color: hsl(120, 100%, 40%);">+#elif (OPENSSL_VERSION_NUMBER &=
gt;=3D 0x10100000L) && !defined(LIBRESSL_VERSION_NUMBER)
=
bool
ssl_tls1_PRF(const uint8_t *seed, int seed_len=
, const uint8_t *secret,
int secret_len, uint=
8_t *output, int output_len)
To view, v=
isit chan=
ge 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: 9
Gerrit-Owner: plaisthos <arne-openvpn@...1711...=
27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...=
1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...=
ts.sourceforge.net>
Gerrit-MessageType: merged
--fLtrOnS1i74=--