From: "MaxF (Code Review)" Date: Wed, 19 Jun 2024 15:06:54 +0000 References: Reply-To: max@...2606..., 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="iJRL4Moard8="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Check that tls-version-min is supported on startup List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --iJRL4Moard8= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/683?usp=3Demail to review the following change. Change subject: Check that tls-version-min is supported on startup ...................................................................... Check that tls-version-min is supported on startup After disabling TLS 1.0 and 1.1 in the mbedtls build, the client would error out during startup if tls-version-min was set to 1.0 or 1.1, but the server would start up and only error out when a client attempts to connect. This commit checks that tls-version-min is supported during startup so that both the client and server error out on startup. Change-Id: Ifc589854816842e46969a76e2845084b3aaa962f Signed-off-by: Max Fillinger --- 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 5 files changed, 31 insertions(+), 6 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/83/683/1 diff --git a/src/openvpn/options.c b/src/openvpn/options.c index f2c7536..f8287f2 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -8933,7 +8933,7 @@ ver =3D tls_version_parse(p[1], p[2]); if (ver =3D=3D TLS_VER_BAD) { - msg(msglevel, "unknown tls-version-min parameter: %s", p[1]); + msg(msglevel, "unknown or unsupported tls-version-min paramete= r: %s", p[1]); goto err; } options->ssl_flags &=3D @@ -8947,7 +8947,7 @@ ver =3D tls_version_parse(p[1], NULL); if (ver =3D=3D TLS_VER_BAD) { - msg(msglevel, "unknown tls-version-max parameter: %s", p[1]); + msg(msglevel, "unknown or unsupported tls-version-max paramete= r: %s", p[1]); goto err; } options->ssl_flags &=3D diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 2054eb4..1d3fdcd 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -405,20 +405,21 @@ int tls_version_parse(const char *vstr, const char *extra) { + const int min_version =3D tls_version_min(); const int max_version =3D tls_version_max(); - if (!strcmp(vstr, "1.0") && TLS_VER_1_0 <=3D max_version) + if (!strcmp(vstr, "1.0") && min_version <=3D TLS_VER_1_0 && TLS_VER_1_= 0 <=3D max_version) { return TLS_VER_1_0; } - else if (!strcmp(vstr, "1.1") && TLS_VER_1_1 <=3D max_version) + else if (!strcmp(vstr, "1.1") && min_version <=3D TLS_VER_1_1 && TLS_V= ER_1_1 <=3D max_version) { return TLS_VER_1_1; } - else if (!strcmp(vstr, "1.2") && TLS_VER_1_2 <=3D max_version) + else if (!strcmp(vstr, "1.2") && min_version <=3D TLS_VER_1_2 && TLS_V= ER_1_2 <=3D max_version) { return TLS_VER_1_2; } - else if (!strcmp(vstr, "1.3") && TLS_VER_1_3 <=3D max_version) + else if (!strcmp(vstr, "1.3") && min_version <=3D TLS_VER_1_3 && TLS_V= ER_1_3 <=3D max_version) { return TLS_VER_1_3; } diff --git a/src/openvpn/ssl_backend.h b/src/openvpn/ssl_backend.h index 285705f..ef1347b 100644 --- a/src/openvpn/ssl_backend.h +++ b/src/openvpn/ssl_backend.h @@ -117,6 +117,14 @@ int tls_version_max(void); /** + * Return the minimum TLS version (as a TLS_VER_x constant) + * supported by current SSL implementation + * + * @return One of the TLS_VER_x constants (but not TLS_VER_BA= D). + */ +int tls_version_min(void); + +/** * Initialise a library-specific TLS context for a server. * * @param ctx TLS context to initialise diff --git a/src/openvpn/ssl_mbedtls.c b/src/openvpn/ssl_mbedtls.c index bb88da9..de7efed 100644 --- a/src/openvpn/ssl_mbedtls.c +++ b/src/openvpn/ssl_mbedtls.c @@ -1049,6 +1049,16 @@ #endif /* defined(MBEDTLS_SSL_PROTO_TLS1_2) */ } +int +tls_version_min(void) +{ +#if defined(MBEDTLS_SSL_PROTO_TLS1_2) + return TLS_VER_1_2; +#else + #error "mbedtls is compiled without support for TLS 1.2." +#endif /* defined(MBEDTLS_SSL_PROTO_TLS1_2) */ +} + /** * Convert an OpenVPN tls-version variable to mbed TLS format * diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c index e8a30a3..352f7fb 100644 --- a/src/openvpn/ssl_openssl.c +++ b/src/openvpn/ssl_openssl.c @@ -231,6 +231,12 @@ #endif } +int +tls_version_min(void) +{ + return TLS_VER_1_0; +} + /** Convert internal version number to openssl version number */ static int openssl_tls_version(int ver) -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/683?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: Ifc589854816842e46969a76e2845084b3aaa962f Gerrit-Change-Number: 683 Gerrit-PatchSet: 1 Gerrit-Owner: MaxF Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --iJRL4Moard8= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

MaxF would like plaisthos and flichtenheld to review th= is change.

Vi= ew Change

Check that tls-version-min is supported on startup

Aft= er disabling TLS 1.0 and 1.1 in the mbedtls build, the client would
erro= r out during startup if tls-version-min was set to 1.0 or 1.1, but
the s= erver would start up and only error out when a client attempts to
connec= t.

This commit checks that tls-version-min is supported during start= up so
that both the client and server error out on startup.

Chang= e-Id: Ifc589854816842e46969a76e2845084b3aaa962f
Signed-off-by: Max Filli= nger <maximilian.fillinger@...2507...>
---
M src/openvpn/option= s.c
M src/openvpn/ssl.c
M src/openvpn/ssl_backend.h
M src/openvpn/= ssl_mbedtls.c
M src/openvpn/ssl_openssl.c
5 files changed, 31 inserti= ons(+), 6 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/op=
envpn refs/changes/83/683/1
diff --git a/src/openvpn/options.c b/sr=
c/openvpn/options.c
index f2c7536..f8287f2 100644--- a/src/openvpn/options.c
+++ b/src/openvpn/option= s.c
@@ -8933,7 +8933,7 @@
ver =3D = tls_version_parse(p[1], p[2]);
if (ver =3D=3D TLS_= VER_BAD)
{
- msg(msglevel, "unknown tls-version-min param= eter: %s", p[1]);
- msg(msglevel, "unknown tls-version-max parameter:= %s", p[1]);
+ = msg(msglevel, "unknown or unsupported tls-version-max parame= ter: %s", p[1]);
goto err;
}
options->ssl_flags &=3D=
diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c
index 2054eb4..1d3fdcd 100644
--- a/src/openvpn/ssl.c
+++ b/src/openvpn/ssl.c
@@ -405,20 +405,21 @@<= /span>
int
tls_version_parse(const char *vstr, c= onst char *extra)
{
+ const int min_version =3D tls_version_min(); const int max_version =3D tls_version_max();
- if (!strcmp(vstr, "1.0") &= amp;& TLS_VER_1_0 <=3D max_version)
+ if (!strcmp(vstr, "1.0") && mi= n_version <=3D TLS_VER_1_0 && TLS_VER_1_0 <=3D max_version)
{
return TLS_VER_1_0; }
- els= e if (!strcmp(vstr, "1.1") && TLS_VER_1_1 <=3D max_ver= sion)
+ else if (!= strcmp(vstr, "1.1") && min_version <=3D TLS_VER_1_1 &a= mp;& TLS_VER_1_1 <=3D max_version)
{
= return TLS_VER_1_1;
}
- else if (!strcmp(vstr, "1.2&qu= ot;) && TLS_VER_1_2 <=3D max_version)
+ else if (!strcmp(vstr, "1.2") &a= mp;& min_version <=3D TLS_VER_1_2 && TLS_VER_1_2 <=3D max= _version)
{
return TLS_VER_1_= 2;
}
- else if (!strcmp(vstr, "1.3") && TLS_VER_1_3 <= =3D max_version)
+ = else if (!strcmp(vstr, "1.3") && min_version <=3D TLS= _VER_1_3 && TLS_VER_1_3 <=3D max_version)
{=
return TLS_VER_1_3;
}=
diff --git a/src/openvpn/ssl_backend.h b/src/openvpn/ssl_backend.= h
index 285705f..ef1347b 100644
--- a/src/o= penvpn/ssl_backend.h
+++ b/src/openvpn/ssl_backend.h=
@@ -117,6 +117,14 @@
int tls_version_max(void);<= /span>

/**
+ * Return the minimum TLS version (as a TLS_VER_x consta= nt)
+ * supported by = current SSL implementation
+ *
+ * @return= One of the TLS_VER_x constants (but not TLS_VER_BAD).<= br>+ */
+int tls_version_min(void);
+

+/**
* Initialise a library-specific= TLS context for a server.
*
* @param c= tx TLS context to initialise
diff --git a/src/ope= nvpn/ssl_mbedtls.c b/src/openvpn/ssl_mbedtls.c
index bb88da= 9..de7efed 100644
--- a/src/openvpn/ssl_mbedtls.c+++ b/src/openvpn/ssl_mbedtls.c
@@ -1049,6 +1049,16 = @@
#endif /* defined(MBEDTLS_SSL_PROTO_TLS1_2) */ }

+int
+tls_ver= sion_min(void)
+{
+#if defined(MBEDTLS_SSL= _PROTO_TLS1_2)
+ r= eturn TLS_VER_1_2;
+#= else
+ #error &quo= t;mbedtls is compiled without support for TLS 1.2."
+#endif /* defined(MBEDTLS_SSL_PROTO_TL= S1_2) */
+}+
/**<= br> * Convert an OpenVPN tls-version variable to mbed TLS format
*
diff --git a/src/openvpn/ssl_openssl.c b/s= rc/openvpn/ssl_openssl.c
index e8a30a3..352f7fb 100644

--- a/src/openvpn/ssl_openssl.c
+++ b/src/openv= pn/ssl_openssl.c
@@ -231,6 +231,12 @@
#end= if
}

+int
+tls_version_min(void)
+{
+ return T= LS_VER_1_0;
+}=
+
/** Conv= ert internal version number to openssl version number */
s= tatic int
openssl_tls_version(int ver)

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

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ifc589854816842e46969a76e284= 5084b3aaa962f
Gerrit-Change-Number: 683
Gerrit-PatchSet: 1
Gerrit-Owner: MaxF <max@...2606...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
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: newchange
--iJRL4Moard8=--