From: "plaisthos (Code Review)" Date: Wed, 23 Apr 2025 11:53:39 +0000 In-Reply-To: References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="OFqhojgX7js="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Make dh none behaviour default if not specified and add dh auto List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: openvpn-devel --OFqhojgX7js= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello flichtenheld, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/945?usp=3Demail to look at the new patch set (#2). The following approvals got outdated and were removed: Code-Review-1 by flichtenheld Change subject: Make dh none behaviour default if not specified and add dh = auto ...................................................................... Make dh none behaviour default if not specified and add dh auto Nowadays ciphers that are using still DH and not ECDH are rarely chosen as best cipher suite. Our man page even indicates that OpenSSL 1.0.1+ supports ECDH cipher suites. So it does not feel useful to force specifying --dh anymore. Custom generated Diffie Hellmann parameters are also discouraged nowadays. The newest OpenSSL FIPS libraries even flat out reject them: FIPS 186-4 type domain parameters no longer allowed in FIPS mode, since the required validation routines were removed from FIPS 186-5 So add --dh auto since is very little extra code to let the TLS library itself pick the parameter. Change-Id: Ica02244c9f0ac9b4690a51f940fda9d900465289 --- M Changes.rst M doc/man-sections/tls-options.rst M src/openvpn/options.c M src/openvpn/ssl.c M src/openvpn/ssl_backend.h M src/openvpn/ssl_mbedtls.c M src/openvpn/ssl_openssl.c 7 files changed, 53 insertions(+), 10 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/45/945/2 diff --git a/Changes.rst b/Changes.rst index a4f5e57..a7ce8f8 100644 --- a/Changes.rst +++ b/Changes.rst @@ -103,6 +103,12 @@ - ``--x509-username-field`` will no longer automatically convert fieldname= s to uppercase. This is deprecated since OpenVPN 2.4, and has now been remove= d. +- ``--dh none`` is now the default if ``--dh`` is specified. Modern TLS + implementations will prefer ECDH and other more modern algorithm anyway. + +- ``--dh auto`` instructs the TLS library - if supported - to use internal + Diffie-Hellmann parameters. + Overview of changes in 2.6 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D diff --git a/doc/man-sections/tls-options.rst b/doc/man-sections/tls-option= s.rst index 0638d09..ad4c9cc 100644 --- a/doc/man-sections/tls-options.rst +++ b/doc/man-sections/tls-options.rst @@ -171,16 +171,22 @@ --dh file - File containing Diffie Hellman parameters in .pem format (required for + File containing Diffie Hellman parameters in .pem format (used by ``--tls-server`` only). Set ``file`` to :code:`none` to disable Diffie Hellman key exchange (and - use ECDH only). Note that this requires peers to be using an SSL library - that supports ECDH TLS cipher suites (e.g. OpenSSL 1.0.1+, or - mbed TLS 2.0+). + use ECDH or newer hybrid key agreement algorithms like X25519MLKEM768). + Note that this requires peers to be using an SSL library that supports + ECDH TLS cipher suites (e.g. OpenSSL 1.0.1+, or mbed TLS 2.0+). Starting + with 2.7.0, this is the same as not specifying ``--dh`` at all. - Use ``openssl dhparam -out dh2048.pem 2048`` to generate 2048-bit DH - parameters. Diffie Hellman parameters may be considered public. + Set ``file`` to :code:`auto` to enable builtin Diffie Hellman + parameters of the TLS library, e.g. the ones defined in RFC 7919. + + Diffie Hellman parameters can be generated using + ``openssl dhparam -out dh2048.pem 2048`` but it is recommended to + use the public well-known parameters or using ``none``. + Diffie Hellman parameters may be considered public. --ecdh-curve name Specify the curve to use for elliptic curve Diffie Hellman. Available diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 96119c4..e67371e 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -3711,9 +3711,12 @@ if (o->tls_server) { - /* Check that DH file is specified, or explicitly disabled */ - notnull(o->dh_file, "DH file (--dh)"); - if (streq(o->dh_file, "none")) + if (streq(o->dh_file, "auto")) + { + /* do not check existence of the "auto" file */ + o->dh_file_inline =3D true; + } + else if (streq(o->dh_file, "none")) { o->dh_file =3D NULL; } diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 23f6423..d591bac 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -535,7 +535,11 @@ { tls_ctx_server_new(new_ctx); - if (options->dh_file) + if (options->dh_file && !strcmp(options->dh_file, "auto")) + { + tls_ctx_use_dh_params_builtin(new_ctx); + } + else if (options->dh_file) { tls_ctx_load_dh_params(new_ctx, options->dh_file, options->dh_file_inline); diff --git a/src/openvpn/ssl_backend.h b/src/openvpn/ssl_backend.h index e25727f..326f78d 100644 --- a/src/openvpn/ssl_backend.h +++ b/src/openvpn/ssl_backend.h @@ -223,6 +223,13 @@ bool dh_file_inline); /** + * Instructs the TLS library to use builtin Diffie Hellman Parameters inst= ead + * of loading specific ones (e.g. the ones from RFC 7919) + * @param ctx + */ +void tls_ctx_use_dh_params_builtin(struct tls_root_ctx *ctx); + +/** * Load Elliptic Curve Parameters, and load them into the library-specific * TLS context. * diff --git a/src/openvpn/ssl_mbedtls.c b/src/openvpn/ssl_mbedtls.c index e15c391..f1fada3 100644 --- a/src/openvpn/ssl_mbedtls.c +++ b/src/openvpn/ssl_mbedtls.c @@ -480,6 +480,13 @@ } void +tls_ctx_use_dh_params_builtin(struct tls_root_ctx *ctx) +{ + msg(M_FATAL, "mbed TLS does not support --dh auto. Use --dh none or " + "manually specify Diffie-Hellmann parameters"); +} + +void tls_ctx_load_ecdh_params(struct tls_root_ctx *ctx, const char *curve_name ) { diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c index f7be50c..f204007 100644 --- a/src/openvpn/ssl_openssl.c +++ b/src/openvpn/ssl_openssl.c @@ -714,6 +714,16 @@ } void +tls_ctx_use_dh_params_builtin(struct tls_root_ctx *ctx) +{ + if (!SSL_CTX_set_dh_auto(ctx->ctx, 1)) + { + crypto_msg(M_FATAL, "SSL_CTX_set_dh_auto"); + } + +} + +void tls_ctx_load_ecdh_params(struct tls_root_ctx *ctx, const char *curve_name) { #if OPENSSL_VERSION_NUMBER >=3D 0x30000000L -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/945?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: Ica02244c9f0ac9b4690a51f940fda9d900465289 Gerrit-Change-Number: 945 Gerrit-PatchSet: 2 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newpatchset --OFqhojgX7js= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

plaisthos uploaded patch set #2 to this change.

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

The following approvals got outdated and were removed: Code-Review-1 by flichtenheld

Make dh none behaviour default if not specifi=
ed and add dh auto

Nowadays ciphers that are using still DH and not = ECDH are rarely chosen
as best cipher suite. Our man page even indicates= that OpenSSL 1.0.1+
supports ECDH cipher suites. So it does not feel us= eful to force
specifying --dh anymore.

Custom generated Diffie He= llmann parameters are also discouraged
nowadays. The newest OpenSSL FIPS= libraries even flat out reject them:

FIPS 186-4 type domain para= meters no longer allowed in FIPS mode,
since the required validation = routines were removed from FIPS 186-5

So add --dh auto since is very= little extra code to let the TLS library
itself pick the parameter.
=
Change-Id: Ica02244c9f0ac9b4690a51f940fda9d900465289
---
M Change= s.rst
M doc/man-sections/tls-options.rst
M src/openvpn/options.c
M= src/openvpn/ssl.c
M src/openvpn/ssl_backend.h
M src/openvpn/ssl_mbed= tls.c
M src/openvpn/ssl_openssl.c
7 files changed, 53 insertions(+), = 10 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn r=
efs/changes/45/945/2
diff --git a/Changes.rst b/Changes.rst<=
br>index a4f5e57..a7ce8f8 100644
--- a/Changes.rst
+++ b/Changes.rst
@@ -103,6 +103,12 @@=
- ``--x509-username-field`` will no longer automatically convert= fieldnames to
uppercase. This is deprecated since OpenV= PN 2.4, and has now been removed.

+- ``--dh none`` is now the default if ``-= -dh`` is specified. Modern TLS
+ implementations will prefer ECDH and other more modern algorit= hm anyway.
++- ``--dh auto`` instructs th= e TLS library - if supported - to use internal
+ Diffie-Hellmann parameters.
+
Overview of changes = in 2.6
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D

diff --git a/= doc/man-sections/tls-options.rst b/doc/man-sections/tls-options.rst<= br>index 0638d09..ad4c9cc 100644
--- a/doc/man-sectio= ns/tls-options.rst
+++ b/doc/man-sections/tls-options.rst
@@ -171,16 +171,22 @@


--dh file
+ File containing D= iffie Hellman parameters in .pem format (used by
``--tls= -server`` only).

Set ``file`` to :code= :`none` to disable Diffie Hellman key exchange (and
- use ECDH only). Note that this requires p= eers to be using an SSL library
- that supports ECDH TLS cipher suites (e.g. OpenSSL 1.0.1+, or
- mbed TLS 2.0+).
+ use ECDH or newer hybri= d key agreement algorithms like X25519MLKEM768).
+ Note that this requires peers to be using an= SSL library that supports
+ ECDH TLS cipher suites (e.g. OpenSSL 1.0.1+, or mbed TLS 2.0+). St= arting
+ with 2.7.0,= this is the same as not specifying ``--dh`` at all.

- Use ``openssl dhparam -o= ut dh2048.pem 2048`` to generate 2048-bit DH
- parameters. Diffie Hellman parameters may be consi= dered public.
+ Set = ``file`` to :code:`auto` to enable builtin Diffie Hellman
+ parameters of the TLS library, e.g.= the ones defined in RFC 7919.
+
+ Diffie= Hellman parameters can be generated using
+ ``openssl dhparam -out dh2048.pem 2048`` but it is= recommended to
+ us= e the public well-known parameters or using ``none``.
+ Diffie Hellman parameters may be consid= ered public.

--ecdh-curve name Specify the curve to use for elliptic curve Diffie Hellman. Avail= able
diff --git a/src/openvpn/options.c b/src/openvpn/optio= ns.c
index 96119c4..e67371e 100644
--- a/sr= c/openvpn/options.c
+++ b/src/openvpn/options.c
<= span>@@ -3711,9 +3711,12 @@


if (o-&g= t;tls_server)
{
- /* Check that DH file is specified, or explicitly di= sabled */
- notn= ull(o->dh_file, "DH file (--dh)");
- if (streq(o->dh_file, "none"= ))
+ if (streq= (o->dh_file, "auto"))
+ {
+ /* do not check existence of the "auto" file */<= /span>
+ o->dh= _file_inline =3D true;
+ = else if (streq(o->dh_file, "none"))
= {
o->dh_file =3D NULL;
= }
diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c
index 23f6423..d591bac 100644
--- a/src/open= vpn/ssl.c
+++ b/src/openvpn/ssl.c
@@ -535,7= +535,11 @@
{
tls_ctx_server_= new(new_ctx);

- if (options->dh_file)
+ if (options->dh_file && !strcmp(o= ptions->dh_file, "auto"))
+ {
+ tls_ctx_use_dh_params_builtin(new_ctx);
+ }

+ else if (options->dh_file)
{
tls_ctx_load_dh_params(n= ew_ctx, options->dh_file,
= options->dh_file_inline);
diff --git a/src/openvpn= /ssl_backend.h b/src/openvpn/ssl_backend.h
index e25727f..3= 26f78d 100644
--- a/src/openvpn/ssl_backend.h
+++ b/src/openvpn/ssl_backend.h

@@ -223,6 +223,13 @@
bool dh_file_inline);
<= span>

/**
+ * Instructs the TLS library to use builtin Diffie Hellman Paramete= rs instead
+ * of loa= ding specific ones (e.g. the ones from RFC 7919)
+ * @param ctx
+ */
+void tls_ctx_use_dh_params_builtin(struct tls_root_ctx *ctx);=
+
+/**
* Load Elliptic Curve P= arameters, and load them into the library-specific
* TLS = context.
*
diff --git a/src/openvpn/ssl_m= bedtls.c b/src/openvpn/ssl_mbedtls.c
index e15c391..f1fada3= 100644
--- a/src/openvpn/ssl_mbedtls.c
+++= b/src/openvpn/ssl_mbedtls.c
@@ -480,6 +480,13 @@ }

void
+tls_ctx_use_dh_params_builtin(struct tls_root= _ctx *ctx)
+{<= br>+ msg(M_FATAL, "mbed= TLS does not support --dh auto. Use --dh none or "
+ "manually specify Diffie-= Hellmann parameters");
+}
++void
tls_ctx= _load_ecdh_params(struct tls_root_ctx *ctx, const char *curve_name )
{
diff= --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c
index f7be50c..f204007 100644

--- a/src/openvpn/ssl_ope= nssl.c
+++ b/src/openvpn/ssl_openssl.c
@@ -= 714,6 +714,16 @@
}

void=
+tls_ctx_use_dh_para= ms_builtin(struct tls_root_ctx *ctx)
+{
+ = if (!SSL_CTX_set_dh_auto(ctx->ctx, 1))
+ {
+ crypto_msg(M_FATAL, "SSL_CTX_set_dh_auto");
+ }
+
+}
+
+void
tls_ctx_load_ecdh_params(struct tls_root_ctx *ctx, const char *curve_n= ame)

{
#if OPENSSL_VERSION_NUMBER >=3D= 0x30000000L

To view, visit change 945. To u= nsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ica02244c9f0ac9b4690a51f940f= da9d900465289
Gerrit-Change-Number: 945
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: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newpatchset
--OFqhojgX7js=--