From: "plaisthos (Code Review)" Date: Mon, 24 Mar 2025 12:59:52 +0000 In-Reply-To: References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <3f027f52ee5d3414a8db91cd03886b81b56c5635-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="lU8uNhVTGlg="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Use USER_PASS_LEN instead of TLS_USERNAME_LEN for override-username List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: openvpn-devel --lU8uNhVTGlg= 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/+/913?usp=3Demail to look at the new patch set (#2). Change subject: Use USER_PASS_LEN instead of TLS_USERNAME_LEN for override-= username ...................................................................... Use USER_PASS_LEN instead of TLS_USERNAME_LEN for override-username Currently override-username is artificially restricted to the length of TLS common-name for the corner case of using username-as-common-name, which we explicitly do not recommend. Do away with that limitation and only error out on longer usernames when username-as-common-name is actually in effect. Change-Id: I1c2c050dd160746a0f8d9c234abe1e258bc8e48d Signed-off-by: Arne Schwabe --- M src/openvpn/multi.c M src/openvpn/options.c M src/openvpn/ssl_verify.c M src/openvpn/ssl_verify.h 4 files changed, 42 insertions(+), 7 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/13/913/2 diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index a673ec1..a2d3fd1 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -2705,6 +2705,12 @@ if (!multi->locked_original_username && strcmp(multi->locked_username, options->override_username) !=3D= 0) { + /* Check if the username length is acceptable */ + if (!ssl_verify_username_length(session, options->override_usernam= e)) + { + return false; + } + multi->locked_original_username =3D multi->locked_username; multi->locked_username =3D strdup(options->override_username); =20 diff --git a/src/openvpn/options.c b/src/openvpn/options.c index ab56609..f89fc7d 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -7875,10 +7875,10 @@ else if (streq(p[0], "override-username") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_INSTANCE); - if (strlen(p[1]) > TLS_USERNAME_LEN) + if (strlen(p[1]) > USER_PASS_LEN) { msg(msglevel, "override-username exceeds the maximum length of= %d " - "characters", TLS_USERNAME_LEN); + "characters", USER_PASS_LEN); /* disable the connection since ignoring the request to * set another username might cause serious problems */ diff --git a/src/openvpn/ssl_verify.c b/src/openvpn/ssl_verify.c index 5f8f1d3..0defcbf 100644 --- a/src/openvpn/ssl_verify.c +++ b/src/openvpn/ssl_verify.c @@ -1568,6 +1568,24 @@ } } +bool +ssl_verify_username_length(struct tls_session *session, const char *userna= me) +{ + if ((session->opt->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME) + && strlen(username) > TLS_USERNAME_LEN) + { + msg(D_TLS_ERRORS, + "TLS Auth Error: --username-as-common name specified and " + "username is longer than the maximum permitted Common Name " + "length of %d characters", TLS_USERNAME_LEN); + return false; + } + else + { + return true; + } +} + /** * Main username/password verification entry point * @@ -1689,15 +1707,12 @@ } /* check sizing of username if it will become our common name */ - if ((session->opt->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME) - && strlen(up->username)>TLS_USERNAME_LEN) + if (ssl_verify_username_length(session, up->username)) { - msg(D_TLS_ERRORS, - "TLS Auth Error: --username-as-common name specified and usern= ame is longer than the maximum permitted Common Name length of %d character= s", - TLS_USERNAME_LEN); plugin_status =3D OPENVPN_PLUGIN_FUNC_ERROR; script_status =3D OPENVPN_PLUGIN_FUNC_ERROR; } + /* auth succeeded? */ bool plugin_ok =3D plugin_status =3D=3D OPENVPN_PLUGIN_FUNC_SUCCESS || plugin_status =3D=3D OPENVPN_PLUGIN_FUNC_DEFERRED; diff --git a/src/openvpn/ssl_verify.h b/src/openvpn/ssl_verify.h index eba3832..7a4d44a 100644 --- a/src/openvpn/ssl_verify.h +++ b/src/openvpn/ssl_verify.h @@ -192,6 +192,20 @@ struct tls_session *session); +/** + * Checks if the username length is valid to use. This checks when + * username-as-common-name is active if the username is shorter than + * the maximum TLS common name length (64). + * + * It will also display an error message if the name is too long + * + * @param session current TLS session + * @param username username to check + * @return true if name is under limit or username-as-common-= name + * is not active + */ +bool ssl_verify_username_length(struct tls_session *session, + const char *username); /** * Runs the --client-crresponse script if one is defined. -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/913?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: I1c2c050dd160746a0f8d9c234abe1e258bc8e48d Gerrit-Change-Number: 913 Gerrit-PatchSet: 2 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: flichtenheld Gerrit-MessageType: newpatchset --lU8uNhVTGlg= 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/+/913?usp=3Demail">View Chang= e

Use USER_PASS_LEN instead of TLS_USERNAME_LEN for override-username
Currently override-username is artificially restricted to the length = of
TLS common-name for the corner case of using username-as-common-name,= which
we explicitly do not recommend.

Do away with that limitati= on and only error out on longer usernames when
username-as-common-name i= s actually in effect.

Change-Id: I1c2c050dd160746a0f8d9c234abe1e258b= c8e48d
Signed-off-by: Arne Schwabe <arne@...1227...>
---
M s= rc/openvpn/multi.c
M src/openvpn/options.c
M src/openvpn/ssl_verify.c=
M src/openvpn/ssl_verify.h
4 files changed, 42 insertions(+), 7 dele= tions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/cha=
nges/13/913/2
diff --git a/src/openvpn/multi.c b/src/openvpn/multi.=
c
index a673ec1..a2d3fd1 100644
--- a/src/o= penvpn/multi.c
+++ b/src/openvpn/multi.c
@@= -2705,6 +2705,12 @@
if (!multi->locked_original_us= ername
&& strcmp(multi->locked_username= , options->override_username) !=3D 0)
{
<= span style=3D"color: hsl(120, 100%, 40%);">+ /* Check if the usernam= e length is acceptable */
+ if (!ssl_verify_username_length(session, options->override= _username))
+ = {
+ return= false;
+ }
+
= multi->locked_original_username =3D multi->locked_username;
multi->locked_username =3D strdup(options->overri= de_username);

diff --git a/src/openvpn/op= tions.c b/src/openvpn/options.c
index ab56609..f89fc7d 1006= 44
--- a/src/openvpn/options.c
+++ b/src/op= envpn/options.c
@@ -7875,10 +7875,10 @@
= else if (streq(p[0], "override-username") && p[1] &= & !p[2])
{
VERIFY_PERMISS= ION(OPT_P_INSTANCE);
- = if (strlen(p[1]) > TLS_USERNAME_LEN)
+ if (strlen(p[1]) > USER_PASS_LEN)
{
msg(msglevel, "ov= erride-username exceeds the maximum length of %d "
- "characters", T= LS_USERNAME_LEN);
+ = "characters", USER_PASS_LEN);

/* disable the connection since ignoring the requ= est to
* set another username might cause ser= ious problems */
diff --git a/src/openvpn/ssl_verify.c b/sr= c/openvpn/ssl_verify.c
index 5f8f1d3..0defcbf 100644=
--- a/src/openvpn/ssl_verify.c
+++ b/src/openvpn/= ssl_verify.c
@@ -1568,6 +1568,24 @@
}<= /span>
}

+bool
+ssl_verify_username_length(struct tls_session *session, const char *usern= ame)
+{
+ if ((session->opt->ssl_= flags & SSLF_USERNAME_AS_COMMON_NAME)

+ && strlen(username) > TLS_USERNAME= _LEN)
+ {+ msg(D_TLS_ERRORS,
+ "TLS = Auth Error: --username-as-common name specified and "
+ "username is longer= than the maximum permitted Common Name "
+ "length of %d characters",= TLS_USERNAME_LEN);
+= return false;
+ }
+ else
+ {
+ return true;
+ }
+}
+
/**
* Main username/password ver= ification entry point
*
@@ -1689,15 +1707= ,12 @@
}

/* che= ck sizing of username if it will become our common name */
- if ((session->opt->ssl_flags= & SSLF_USERNAME_AS_COMMON_NAME)
- && strlen(up->username)>TLS_USERNAME_L= EN)
+ if (ssl_veri= fy_username_length(session, up->username))
{=
- msg(D_TLS_ERRORS,
- "TLS Au= th Error: --username-as-common name specified and username is longer than t= he maximum permitted Common Name length of %d characters",
<= span style=3D"color: hsl(0, 100%, 40%);">- TLS_USERNAME_LEN);
plugin_status =3D OPENVPN_PLUGIN_FUNC_ERROR;<= br> script_status =3D OPENVPN_PLUGIN_FUNC_ERROR;
}

+ /* auth succeeded? */
bool plugin_ok =3D = plugin_status =3D=3D OPENVPN_PLUGIN_FUNC_SUCCESS
= || plugin_status =3D=3D OPENVPN_PLUGIN_FUNC_DEFERRED;diff --git a/src/openvpn/ssl_verify.h b/src/openvpn/ssl_verify.h
index eba3832..7a4d44a 100644
--- a/src/openvp= n/ssl_verify.h
+++ b/src/openvpn/ssl_verify.h
@@ -192,6 +192,20 @@

struct tls_s= ession *session);


+/**
+ * Checks if the username length is valid to use. This c= hecks when
+ * userna= me-as-common-name is active if the username is shorter than
+ * the maximum TLS common name leng= th (64).

+ *+ * It will also display an e= rror message if the name is too long
+ *
+= * @param session current TLS session
+ * @param username username to check+ * @return true = if name is under limit or username-as-common-name
+ * is not active<= br>+ */
+bool ssl_verify_username_length(struct tl= s_session *session,
+= const char *username);

/**
* Runs the --client-crresponse script = if one is defined.

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

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1c2c050dd160746a0f8d9c234ab= e1e258bc8e48d
Gerrit-Change-Number: 913
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
--lU8uNhVTGlg=--