From: "plaisthos (Code Review)" Date: Thu, 4 Jan 2024 12:45:44 +0000 In-Reply-To: References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., gert@...1296... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="sdaeP1D0DsY="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Check PRF availability on initialisation and add --force-tls-key-mate... List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: cron2 , flichtenheld Cc: openvpn-devel --sdaeP1D0DsY= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello cron2, flichtenheld, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/460?usp=3Demail to look at the new patch set (#9). Change subject: Check PRF availability on initialisation and add --force-tl= s-key-material-export ...................................................................... Check PRF availability on initialisation and add --force-tls-key-material-e= xport We now warn a user if the TLS 1.0 PRF is not supported by the cryptographic library of the system. Also add the option --force-tls-key-material-export that automatically rejects clients that do not support TLS Keying Material Export and automatically enable it when TLS 1.0 PRF support is not availabl= e. Change-Id: I04f8c7c413e7cb62c726262feee6ca89c7e86c70 Signed-off-by: Arne Schwabe --- M doc/man-sections/protocol-options.rst M src/openvpn/crypto.c M src/openvpn/crypto.h M src/openvpn/multi.c M src/openvpn/options.c M src/openvpn/options.h 6 files changed, 84 insertions(+), 0 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/60/460/9 diff --git a/doc/man-sections/protocol-options.rst b/doc/man-sections/proto= col-options.rst index 948c0c8..8b061d2 100644 --- a/doc/man-sections/protocol-options.rst +++ b/doc/man-sections/protocol-options.rst @@ -242,3 +242,11 @@ a key renegotiation begins (default :code:`3600` seconds). This feature allows for a graceful transition from old to new key, and removes the key renegotiation sequence from the critical path of tunnel data forwarding. + +--force-tls-key-material-export + This option is only available in --mode server and forces to use + Keying Material Exporters (RFC 5705) for clients. This can be used to + simulate an environment where the cryptographic library does not support + the older method to generate data channel keys anymore. This option is + intended to be a test option and might be removed in a future OpenVPN + version without notice. diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index e4452d7..2fca131 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -27,6 +27,7 @@ #endif #include "syshead.h" +#include #include "crypto.h" #include "error.h" @@ -1789,3 +1790,22 @@ gc_free(&gc); return ret; } + +bool +check_tls_prf_working(void) +{ + /* Modern TLS libraries might no longer support the TLS 1.0 PRF with + * MD5+SHA1. This allows us to establish connections only + * with other 2.6.0+ OpenVPN peers. + * Do a simple dummy test here to see if it works. */ + const char *seed =3D "tls1-prf-test"; + const char *secret =3D "tls1-prf-test-secret"; + uint8_t out[8]; + uint8_t expected_out[] =3D { 'q', 'D', '\xfe', '%', '@', 's', 'u', '\x= 95' }; + + int ret =3D ssl_tls1_PRF((uint8_t *)seed, (int) strlen(seed), + (uint8_t *)secret, (int) strlen(secret), + out, sizeof(out)); + + return (ret && memcmp(out, expected_out, sizeof(out)) =3D=3D 0); +} diff --git a/src/openvpn/crypto.h b/src/openvpn/crypto.h index 9255d38..4201524 100644 --- a/src/openvpn/crypto.h +++ b/src/openvpn/crypto.h @@ -593,4 +593,12 @@ return kt; } +/** + * Checks if the current TLS library supports the TLS 1.0 PRF with MD5+SHA1 + * that OpenVPN uses when TLS Keying Material Export is not available. + * + * @return true if supported, false otherwise. + */ +bool check_tls_prf_working(void); + #endif /* CRYPTO_H */ diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 8b490ed..f4f0b8a 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -1830,6 +1830,16 @@ { o->imported_protocol_flags |=3D CO_USE_TLS_KEY_MATERIAL_EXPORT; } + else if (o->force_key_material_export) + { + msg(M_INFO, "PUSH: client does not support TLS Keying Material " + "Exporters but --force-tls-key-material-export is enabled."); + auth_set_client_reason(tls_multi, "Client incompatible with this " + "server. Keying Material Exporters (RFC 570= 5) " + "support missing. Upgrade to a client that " + "supports this feature (OpenVPN 2.6.0+)."); + return false; + } if (proto & IV_PROTO_DYN_TLS_CRYPT) { o->imported_protocol_flags |=3D CO_USE_DYNAMIC_TLS_CRYPT; diff --git a/src/openvpn/options.c b/src/openvpn/options.c index e498114..1b28a19 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -1561,6 +1561,7 @@ SHOW_STR(auth_user_pass_verify_script); SHOW_BOOL(auth_user_pass_verify_script_via_file); SHOW_BOOL(auth_token_generate); + SHOW_BOOL(force_key_material_export); SHOW_INT(auth_token_lifetime); SHOW_STR_INLINE(auth_token_secret_file); #if PORT_SHARE @@ -2802,6 +2803,11 @@ { msg(M_USAGE, "--vlan-tagging requires --mode server"); } + + if (options->force_key_material_export) + { + msg(M_USAGE, "--force-tls-key-material-export requires --mode = server"); + } } /* @@ -3634,6 +3640,30 @@ } static void +options_process_mutate_prf(struct options *o) +{ + if (!check_tls_prf_working()) + { + msg(D_TLS_ERRORS, "Warning: TLS 1.0 PRF with MD5+SHA1 PRF is not " + "supported by the TLS library. Your system does not support th= is " + "calculation anymore or your security policy (e.g. FIPS 140-2)= " + "forbids it. Connections will only work with peers running " + "OpenVPN 2.6.0 or higher)"); +#ifndef HAVE_EXPORT_KEYING_MATERIAL + msg(M_FATAL, "Keying Material Exporters (RFC 5705) not available e= ither. " + "No way to generate data channel keys left."); +#endif + if (o->mode =3D=3D MODE_SERVER) + { + msg(M_WARN, "Automatically enabling option " + "--force-tls-key-material-export"); + o->force_key_material_export =3D true; + } + + } +} + +static void options_postprocess_mutate(struct options *o, struct env_set *es) { int i; @@ -3647,6 +3677,7 @@ options_postprocess_setdefault_ncpciphers(o); options_set_backwards_compatible_options(o); + options_process_mutate_prf(o); options_postprocess_cipher(o); o->ncp_ciphers =3D mutate_ncp_cipher_list(o->ncp_ciphers, &o->gc); @@ -8642,6 +8673,11 @@ } } } + else if (streq(p[0], "force-tls-key-material-export")) + { + VERIFY_PERMISSION(OPT_P_GENERAL); + options->force_key_material_export =3D true; + } else if (streq(p[0], "prng") && p[1] && !p[3]) { msg(M_WARN, "NOTICE: --prng option ignored (SSL library PRNG is us= ed)"); diff --git a/src/openvpn/options.h b/src/openvpn/options.h index c4514e1..cbfff18 100644 --- a/src/openvpn/options.h +++ b/src/openvpn/options.h @@ -687,6 +687,8 @@ const char *keying_material_exporter_label; int keying_material_exporter_length; #endif + /* force using TLS key material export for data channel key generation= */ + bool force_key_material_export; bool vlan_tagging; enum vlan_acceptable_frames vlan_accept; -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/460?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: I04f8c7c413e7cb62c726262feee6ca89c7e86c70 Gerrit-Change-Number: 460 Gerrit-PatchSet: 9 Gerrit-Owner: plaisthos Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newpatchset --sdaeP1D0DsY= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

plaisthos uploaded patch set #9 to this change.

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

Check PRF availability on initialisation and add --force-tls-key-mate=
rial-export

We now warn a user if the TLS 1.0 PRF is not supported b= y the cryptographic
library of the system. Also add the option --force-t= ls-key-material-export
that automatically rejects clients that do not su= pport TLS Keying Material
Export and automatically enable it when TLS 1.= 0 PRF support is not available.

Change-Id: I04f8c7c413e7cb62c726262f= eee6ca89c7e86c70
Signed-off-by: Arne Schwabe <arne@...1227...>
= ---
M doc/man-sections/protocol-options.rst
M src/openvpn/crypto.cM src/openvpn/crypto.h
M src/openvpn/multi.c
M src/openvpn/options.c=
M src/openvpn/options.h
6 files changed, 84 insertions(+), 0 deletio= ns(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/change=
s/60/460/9
diff --git a/doc/man-sections/protocol-options.rst b/doc=
/man-sections/protocol-options.rst
index 948c0c8..8b061d2 1= 00644
--- a/doc/man-sections/protocol-options.rst+++ b/doc/man-sections/protocol-options.rst
@@ -242,= 3 +242,11 @@
a key renegotiation begins (default :code:`= 3600` seconds). This feature
allows for a graceful trans= ition from old to new key, and removes the key
renegotia= tion sequence from the critical path of tunnel data forwarding.
<= span style=3D"color: hsl(120, 100%, 40%);">+
+--force-tls-key-material-export
+ This option is only available in --m= ode server and forces to use
+ Keying Material Exporters (RFC 5705) for clients. This can be us= ed to
+ simulate an = environment where the cryptographic library does not support
+ the older method to generate dat= a channel keys anymore. This option is
+ intended to be a test option and might be removed in a= future OpenVPN
+ ve= rsion without notice.
diff --git a/src/openvpn/crypto.c b/s= rc/openvpn/crypto.c
index e4452d7..2fca131 100644--- a/src/openvpn/crypto.c
+++ b/src/openvpn/crypto.= c
@@ -27,6 +27,7 @@
#endif

#include "syshead.h"
+#include <string.h>
<= /span>
#include "crypto.h"
#include &q= uot;error.h"
@@ -1789,3 +1790,22 @@
= gc_free(&gc);
return ret;
}
+
+bool
+check_tls_prf_working(void)
+{
+ /* Modern TLS libraries might no longer support the TLS 1.0 PR= F with
+ * MD5+SH= A1. This allows us to establish connections only
+ * with other 2.6.0+ OpenVPN peers.=
+ * Do a simple dummy t= est here to see if it works. */
+ const char *seed =3D "tls1-prf-test";
<= span style=3D"color: hsl(120, 100%, 40%);">+ const char *secret =3D &quo= t;tls1-prf-test-secret";

+ uint8_t out[8];
+ uint8_t expected_out[] =3D { 'q', 'D', '\= xfe', '%', '@', 's', 'u', '\x95'= ; };
+
+ int ret =3D ssl_tls1_PRF((uint= 8_t *)seed, (int) strlen(seed),

+ (uint8_t *)secret, (int) strlen(secr= et),
+ = out, sizeof(out));
+
+ retu= rn (ret && memcmp(out, expected_out, sizeof(out)) =3D=3D 0);=
+}
diff --g= it a/src/openvpn/crypto.h b/src/openvpn/crypto.h
index 9255= d38..4201524 100644
--- a/src/openvpn/crypto.h
+++ b/src/openvpn/crypto.h
@@ -593,4 +593,12 @@<= br> return kt;
}

+/**
+ * Checks if the current TLS library supports the= TLS 1.0 PRF with MD5+SHA1
+ * that OpenVPN uses when TLS Keying Material Export is not availabl= e.
+ *
+ * @return true if supported, fal= se otherwise.
+ */

+bool check_tls_prf_wor= king(void);
+<= br> #endif /* CRYPTO_H */
diff --git a/src/openvpn/mu= lti.c b/src/openvpn/multi.c
index 8b490ed..f4f0b8a 100644
--- a/src/openvpn/multi.c
+++ b/src/openvpn/= multi.c
@@ -1830,6 +1830,16 @@
{

o->imported_protocol_flags |=3D CO_USE_TLS_KEY_MATER= IAL_EXPORT;
}
+ else if (o->force_key_material_export)
+ {
+ msg(M_INFO, "PUSH: client does not = support TLS Keying Material "
+ "Exporters but --force-tls-key-material-exp= ort is enabled.");
+ auth_set_client_reason(tls_multi, "Client incompatible wit= h this "
+ = "server. Keying Material Exporters (RFC 5705)= "
+ = "support missing. Upgrade to a client that "
+ = "supports this feature (OpenVPN 2.6.0+).");
<= span style=3D"color: hsl(120, 100%, 40%);">+ return false;
+ }
if= (proto & IV_PROTO_DYN_TLS_CRYPT)
{
o->imported_protocol_flags |=3D CO_USE_DYNAMIC_TLS_CRYPT;
diff --git a/src/openvpn/options.c b/src/openvpn/options.c
index e498114..1b28a19 100644
--- a/src/openvp= n/options.c
+++ b/src/openvpn/options.c
@@ = -1561,6 +1561,7 @@
SHOW_STR(auth_user_pass_verify_scri= pt);
SHOW_BOOL(auth_user_pass_verify_script_via_file);=
SHOW_BOOL(auth_token_generate);
+ SHOW_BOOL(force_key_material_export);=
SHOW_INT(auth_token_lifetime);
S= HOW_STR_INLINE(auth_token_secret_file);
#if PORT_SHARE
@@ -2802,6 +2803,11 @@
{
msg(M_USAGE, "--vlan-tagging requires --mode server&q= uot;);

}
+
+ = if (options->force_key_material_export)
+ {
+ msg(M_USAGE, "--force-tls-key-material-exp= ort requires --mode server");
+ }
}
/*
@@ -3634,6 +3640,30 @@
}

static void
+options_process_mutate_prf(struct options *o)

+{
+ if (!check_tls_prf_working())<= br>+ {
+ msg(D_TLS_ERRORS, "Warning: = TLS 1.0 PRF with MD5+SHA1 PRF is not "
+ "supported by the TLS library. You= r system does not support this "
+ "calculation anymore or your security po= licy (e.g. FIPS 140-2) "
+ "forbids it. Connections will only work with pee= rs running "
+ = "OpenVPN 2.6.0 or higher)");
+#ifndef HAVE_EXPORT_KEYING_MATERIAL
= + msg(M_FATAL, "Key= ing Material Exporters (RFC 5705) not available either. "
+ "No way to gene= rate data channel keys left.");
+#endif
+ if (o->mode =3D=3D MODE_SERVER)
+ {
+ msg(M_WARN, "Automatically enabling optio= n "
+ = "--force-tls-key-material-export");
+ o->force_key_material_export = =3D true;
+ }<= /span>
+
+ }
+}
+
+static void
options_postprocess_mutate(struct options *o, struct env_set = *es)
{
int i;
@@ -364= 7,6 +3677,7 @@

options_postprocess_s= etdefault_ncpciphers(o);
options_set_backwards_compati= ble_options(o);
+ = options_process_mutate_prf(o);

optio= ns_postprocess_cipher(o);
o->ncp_ciphers =3D mutate= _ncp_cipher_list(o->ncp_ciphers, &o->gc);
@@ -864= 2,6 +8673,11 @@
}
}
}
+ else if (streq(p[0], "force-tls-key-material-export"))

+ {
+ VERIFY_PERMISSION(OPT_P_GENERA= L);
+ options-= >force_key_material_export =3D true;
+ }
else if (streq(p[0], "p= rng") && p[1] && !p[3])
{<= br> msg(M_WARN, "NOTICE: --prng option ignored (SSL libr= ary PRNG is used)");
diff --git a/src/openvpn/options.= h b/src/openvpn/options.h
index c4514e1..cbfff18 100644
--- a/src/openvpn/options.h
+++ b/src/openvpn/= options.h
@@ -687,6 +687,8 @@
const ch= ar *keying_material_exporter_label;
int keying_materia= l_exporter_length;
#endif
+ /* force using TLS key material export for data = channel key generation */
+ bool force_key_material_export;

bool vlan_tagging;

enum vlan_acceptable_frames v= lan_accept;

To view, visit change 460. To un= subscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I04f8c7c413e7cb62c726262feee= 6ca89c7e86c70
Gerrit-Change-Number: 460
Gerrit-PatchSet: 9
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: cron2 <gert@...1296...>=
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
--sdaeP1D0DsY=--