From: "cron2 (Code Review)" Date: Tue, 11 Mar 2025 21:54:12 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., heiko@...515..., openvpn-devel@lists.sourceforge.net, frank@...2641..., lstipakov@...277..., a@...2181... Message-ID: <437fd20db71b17426989d34e06b9e9edd80b66fc-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="IOa3J9X6RF4="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Implement override-username List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: d12fk , stipa , flichtenheld , openvpn-devel --IOa3J9X6RF4= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/87= 2?usp=3Demail ) Change subject: Implement override-username ...................................................................... Implement override-username This allow the server to set and override the username that is assumed for the client for interaction with the client after the authentication. This is especially intended to allow the of use auth-gen-token in scenarios where the clients use certificates and multi-factor authentication. It allows a client to successfully roam to a different server and have a correct username and auth-token that can be accepted by that server as fully authenticated user without requiring MFA again. The scenario that this feature is probably most useful when --management-client-auth is in use as in this mode the OpenVPN server can accept clients without username/password but still use --auth-gen-token with username and password to accept auth-token as alternative authentication. A client without a username will also not use the pushed auth-token. So setting/pushing an auth-token-user will ensure that the client has a username. Github: OpenVPN/openvpn#299 Change-Id: Ia4095518d5e4447992a2974e0d7a159d79ba6b6f Signed-off-by: Arne Schwabe Acked-by: Gert Doering Message-Id: <20250311155904.4446-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg31= 091.html Signed-off-by: Gert Doering --- M Changes.rst M doc/man-sections/server-options.rst M src/openvpn/multi.c M src/openvpn/options.c M src/openvpn/options.h M src/openvpn/push.c M src/openvpn/ssl.c M src/openvpn/ssl_common.h M src/openvpn/ssl_verify.c M src/openvpn/ssl_verify.h 10 files changed, 173 insertions(+), 10 deletions(-) diff --git a/Changes.rst b/Changes.rst index bcc64fc..a4f5e57 100644 --- a/Changes.rst +++ b/Changes.rst @@ -49,6 +49,12 @@ - IV constructed with XOR instead of concatenation to not have (parts)= of the real IV on the wire +Allow overriding username with ``--override-username`` + This is intended to allow using auth-gen-token in scenarios where the + clients use certificates and multi-factor authentication. This will + also generate a 'push "auth-token-user newusername"' directives in + push replies. + Deprecated features ------------------- ``secret`` support has been removed by default. diff --git a/doc/man-sections/server-options.rst b/doc/man-sections/server-= options.rst index 3fe9862..e93b04d 100644 --- a/doc/man-sections/server-options.rst +++ b/doc/man-sections/server-options.rst @@ -89,6 +89,12 @@ will lead to authentication bypass (as does returning success on a wrong password from a script). + **Note:** the username for ``--auth-gen-token`` can be overridden by + ``--override-user``. In this case the client will be pushed also the + ``--auth-token-user`` option and an auth token that is valid for that + username instead of the original username that the client authenticated + with. + --auth-gen-token-secret file Specifies a file that holds a secret for the HMAC used in ``--auth-gen-token`` If ``file`` is not present OpenVPN will generate a @@ -412,6 +418,32 @@ This option requires that ``--disable-occ`` NOT be used. +--override-username username + Sets the username of a connection to the specified username. This usern= ame + will also be used by ``--auth-gen-token``. However, the overridden + username comes only into effect *after* the ``--client-config-dir`` has = been + read and the ``--auth-user-pass-verify`` and ``--client-connect`` scripts + have been run. + + Also ``--username-as-common-name`` will use the client provided username + as common-name. It is recommended to avoid the use of the + ``--override-username`` option if the option ``--username-as-common-name= `` + is being used. + + The changed username will be picked up by the status output and also by + the ``--auth-gen-token`` option. It will also be pushed to the client + using ``--auth-token-user``. + + Special care should be taken that both the initial username of the client + and the overridden username are handled correctly when using + ``--override-username`` and the related options to avoid + authentication/authorisation bypasses. + + This option is mainly intended for use cases that use certificates and + multi factor authentication and therefore do not provide a username that + can be used for ``--auth-gen-token`` to allow providing a username in + these scenarios. + --port-share args Share OpenVPN TCP with another service diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 0292e8d..a673ec1 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -42,7 +42,9 @@ #include "ssl_verify.h" #include "ssl_ncp.h" #include "vlan.h" +#include "auth_token.h" #include +#include #include "memdbg.h" @@ -2680,6 +2682,60 @@ NULL, }; +/** + * Overrides the locked username with the username of --override-username + * @param mi the multi instance that should be modified. + */ +static bool +override_locked_username(struct multi_instance *mi) +{ + struct tls_multi *multi =3D mi->context.c2.tls_multi; + struct options *options =3D &mi->context.options; + struct tls_session *session =3D &multi->session[TM_ACTIVE]; + + if (!multi->locked_username) + { + msg(D_MULTI_ERRORS, "MULTI: Ignoring override-username as no " + "user/password method is enabled. Enable " + "--management-client-auth, --auth-user-pass-verify, or a " + "plugin with user/password verify capability."); + return false; + } + + if (!multi->locked_original_username + && strcmp(multi->locked_username, options->override_username) !=3D= 0) + { + multi->locked_original_username =3D multi->locked_username; + multi->locked_username =3D strdup(options->override_username); + + /* Override also the common name if username should be set as comm= on + * name */ + if ((session->opt->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME)) + { + set_common_name(session, multi->locked_username); + free(multi->locked_cn); + multi->locked_cn =3D NULL; + tls_lock_common_name(multi); + } + + /* Regenerate the auth-token if enabled */ + if (multi->auth_token_initial) + { + struct user_pass up; + CLEAR(up); + strncpynt(up.username, multi->locked_username, + sizeof(up.username)); + + generate_auth_token(&up, multi); + } + + msg(D_MULTI_LOW, "MULTI: Note, override-username changes username " + "from '%s' to '%s'", + multi->locked_original_username, + multi->locked_username); + } + return true; +} /* * Called as soon as the SSL/TLS connection is authenticated. * @@ -2783,6 +2839,14 @@ (*cur_handler_index)++; } + if (mi->context.options.override_username) + { + if (!override_locked_username(mi)) + { + cc_succeeded =3D false; + } + } + /* Check if we have forbidding options in the current mode */ if (dco_enabled(&mi->context.options) && !dco_check_option(D_MULTI_ERRORS, &mi->context.options)) diff --git a/src/openvpn/options.c b/src/openvpn/options.c index df3ebad..704e65a 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -452,6 +452,8 @@ " Only valid in a client-specific config file.\n" "--disable : Client is disabled.\n" " Only valid in a client-specific config file.\n" + "--override-username: Overrides the client-specific username to be use= d.\n" + " Only valid in a client-specific config file.\n" "--verify-client-cert [none|optional|require] : perform no, optional o= r\n" " mandatory client certificate verification.\n" " Default is to require the client to supply a certif= icate.\n" @@ -8000,6 +8002,23 @@ VERIFY_PERMISSION(OPT_P_INSTANCE); options->disable =3D true; } + else if (streq(p[0], "override-username") && p[1] && !p[2]) + { + VERIFY_PERMISSION(OPT_P_INSTANCE); + if (strlen(p[1]) > TLS_USERNAME_LEN) + { + msg(msglevel, "override-username exceeds the maximum length of= %d " + "characters", TLS_USERNAME_LEN); + + /* disable the connection since ignoring the request to + * set another username might cause serious problems */ + options->disable =3D true; + } + else + { + options->override_username =3D p[1]; + } + } else if (streq(p[0], "tcp-nodelay") && !p[1]) { VERIFY_PERMISSION(OPT_P_GENERAL); diff --git a/src/openvpn/options.h b/src/openvpn/options.h index 161899a..fa617c8 100644 --- a/src/openvpn/options.h +++ b/src/openvpn/options.h @@ -505,6 +505,7 @@ const char *client_config_dir; bool ccd_exclusive; bool disable; + const char *override_username; int n_bcast_buf; int tcp_queue_limit; struct iroute *iroutes; diff --git a/src/openvpn/push.c b/src/openvpn/push.c index 914f520..c97ce28 100644 --- a/src/openvpn/push.c +++ b/src/openvpn/push.c @@ -595,9 +595,19 @@ */ if (tls_multi->auth_token) { - push_option_fmt(gc, push_list, M_USAGE, - "auth-token %s", + push_option_fmt(gc, push_list, M_USAGE, "auth-token %s", tls_multi->auth_token); + + char *base64user =3D NULL; + int ret =3D openvpn_base64_encode(tls_multi->locked_username, + (int)strlen(tls_multi->locked_user= name), + &base64user); + if (ret < USER_PASS_LEN && ret > 0) + { + push_option_fmt(gc, push_list, M_USAGE, "auth-token-user %s", + base64user); + } + free(base64user); } } diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 48f2a49..99b5c07 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -1262,6 +1262,7 @@ free(multi->peer_info); free(multi->locked_cn); free(multi->locked_username); + free(multi->locked_original_username); cert_hash_free(multi->locked_cert_hash_set); diff --git a/src/openvpn/ssl_common.h b/src/openvpn/ssl_common.h index 6916ad4..68a6ce6 100644 --- a/src/openvpn/ssl_common.h +++ b/src/openvpn/ssl_common.h @@ -627,7 +627,16 @@ * Our locked common name, username, and cert hashes (cannot change du= ring the life of this tls_multi object) */ char *locked_cn; + + /** The locked username is the username we assume the client is using. + * Normally the username used for initial authentication unless + * overridden by --override-username */ char *locked_username; + + /** The username that client initially used before being overridden + * by --override-user */ + char *locked_original_username; + struct cert_hash_set *locked_cert_hash_set; /** Time of last when we updated the cached state of diff --git a/src/openvpn/ssl_verify.c b/src/openvpn/ssl_verify.c index 1ac94fc..5f8f1d3 100644 --- a/src/openvpn/ssl_verify.c +++ b/src/openvpn/ssl_verify.c @@ -48,9 +48,6 @@ #include "push.h" #include "ssl_util.h" -/** Maximum length of common name */ -#define TLS_USERNAME_LEN 64 - static void string_mod_remap_name(char *str) { @@ -85,10 +82,7 @@ } } -/* - * Set the given session's common_name - */ -static void +void set_common_name(struct tls_session *session, const char *common_name) { if (session->common_name) @@ -153,7 +147,10 @@ { if (multi->locked_username) { - if (strcmp(username, multi->locked_username) !=3D 0) + /* If the username has been overridden, we accept both the original + * username and the changed username */ + if (strcmp(username, multi->locked_username) !=3D 0 + && (!multi->locked_original_username || strcmp(username, mult= i->locked_original_username) !=3D 0)) { msg(D_TLS_ERRORS, "TLS Auth Error: username attempted to chang= e from '%s' to '%s' -- tunnel disabled", multi->locked_username, @@ -1604,6 +1601,17 @@ */ bool skip_auth =3D false; + /* Replace username early if override-username is in effect but only + * if client is sending the original username */ + if (multi->locked_original_username + && strncmp(up->username, multi->locked_original_username, sizeof(u= p->username)) =3D=3D 0) + { + msg(D_MULTI_LOW, "TLS: Replacing client provided username '%s' wit= h " + "username from override-user '%s'", up->username, + multi->locked_username); + strncpy(up->username, multi->locked_username, sizeof(up->username)= ); + } + /* * If server is configured with --auth-gen-token and the client sends * something that looks like an authentication token, this diff --git a/src/openvpn/ssl_verify.h b/src/openvpn/ssl_verify.h index cd2ec24..eba3832 100644 --- a/src/openvpn/ssl_verify.h +++ b/src/openvpn/ssl_verify.h @@ -51,6 +51,9 @@ /** Maximum certificate depth we will allow */ #define MAX_CERT_DEPTH 16 +/** Maximum length of common name */ +#define TLS_USERNAME_LEN 64 + /** Structure containing the hash for a single certificate */ struct cert_hash { unsigned char sha256_hash[256/8]; @@ -146,6 +149,16 @@ */ const char *tls_common_name(const struct tls_multi *multi, const bool null= ); + +/** + * Sets the common name field for the given tunnel + * + * @param multi The tunnel to set the common name for + * @param common_name The name to set the common name to + */ +void +set_common_name(struct tls_session *session, const char *common_name); + /** * Returns the username field for the given tunnel * -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/872?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: Ia4095518d5e4447992a2974e0d7a159d79ba6b6f Gerrit-Change-Number: 872 Gerrit-PatchSet: 10 Gerrit-Owner: plaisthos Gerrit-Reviewer: cron2 Gerrit-Reviewer: d12fk Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-CC: ordex Gerrit-CC: stipa Gerrit-MessageType: merged --IOa3J9X6RF4= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 submitted this change.

View Change

Implement override-username

This allow = the server to set and override the username that is assumed
for the clie= nt for interaction with the client after the authentication.

This is= especially intended to allow the of use auth-gen-token in
scenarios whe= re the clients use certificates and multi-factor
authentication.

= It allows a client to successfully roam to a different server and have
a= correct username and auth-token that can be accepted by that server as
= fully authenticated user without requiring MFA again.

The scenario t= hat this feature is probably most useful
when --management-client-auth i= s in use as in this mode the OpenVPN
server can accept clients without u= sername/password but still use
--auth-gen-token with username and passwo= rd to accept auth-token as
alternative authentication. A client without = a username will also not
use the pushed auth-token. So setting/pushing a= n auth-token-user
will ensure that the client has a username.

Git= hub: OpenVPN/openvpn#299

Change-Id: Ia4095518d5e4447992a2974e0d7a159= d79ba6b6f
Signed-off-by: Arne Schwabe <arne@...1227...>
Acked-b= y: Gert Doering <gert@...1296...>
Message-Id: <20250311155904.4= 446-1-gert@...1296...>
URL: https://www.mail-archive.com/openvpn-deve= l@lists.sourceforge.net/msg31091.html
Signed-off-by: Gert Doering <ge= rt@...1296...>
---
M Changes.rst
M doc/man-sections/server-opti= ons.rst
M src/openvpn/multi.c
M src/openvpn/options.c
M src/openvp= n/options.h
M src/openvpn/push.c
M src/openvpn/ssl.c
M src/openvpn= /ssl_common.h
M src/openvpn/ssl_verify.c
M src/openvpn/ssl_verify.h10 files changed, 173 insertions(+), 10 deletions(-)

diff --git a/Changes.rst b/Changes.rst
index bcc64fc..a4= f5e57 100644
--- a/Changes.rst
+++ b/Change= s.rst
@@ -49,6 +49,12 @@
- IV construc= ted with XOR instead of concatenation to not have (parts) of
the real IV on the wire

+Allow overriding username with ``--override-= username``
+ This = is intended to allow using auth-gen-token in scenarios where the
= + clients use certificates a= nd multi-factor authentication. This will
+ also generate a 'push "auth-token-user = newusername"' directives in
+ push replies.
+
Deprecated features
-----= --------------
``secret`` support has been removed by defa= ult.
diff --git a/doc/man-sections/server-options.rst b/doc= /man-sections/server-options.rst
index 3fe9862..e93b04d 100= 644
--- a/doc/man-sections/server-options.rst
+++ b/doc/man-sections/server-options.rst
@@ -89,6 +89,1= 2 @@
will lead to authentication bypass (as does returni= ng success on a wrong
password from a script).
+ **Note:**= the username for ``--auth-gen-token`` can be overridden by
+ ``--override-user``. In this case= the client will be pushed also the
+ ``--auth-token-user`` option and an auth token that is va= lid for that
+ usern= ame instead of the original username that the client authenticated+ with.
+
--auth-gen-token-secre= t file
Specifies a file that holds a secret for the HMAC= used in
``--auth-gen-token`` If ``file`` is not present= OpenVPN will generate a
@@ -412,6 +418,32 @@

This option requires that ``--disable-occ`` NOT be = used.

+--override-username username
+ Sets the username of a connection to the specified username.= This username
+ wi= ll also be used by ``--auth-gen-token``. However, the overridden
= + username comes only into eff= ect *after* the ``--client-config-dir`` has been
+ read and the ``--auth-user-pass-verify`` and= ``--client-connect`` scripts
+ have been run.
+
+ Also ``--u= sername-as-common-name`` will use the client provided username
+ as common-name. It is recommen= ded to avoid the use of the
+ ``--override-username`` option if the option ``--username-as-comm= on-name``
+ is being= used.
+
+ The changed username will be p= icked up by the status output and also by
+ the ``--auth-gen-token`` option. It will also be pu= shed to the client
+ = using ``--auth-token-user``.
+
+ Special= care should be taken that both the initial username of the client+ and the overridden usernam= e are handled correctly when using
+ ``--override-username`` and the related options to avoid
+ authentication/auth= orisation bypasses.
+=
+ This option is ma= inly intended for use cases that use certificates and
+ multi factor authentication and therefo= re do not provide a username that
+ can be used for ``--auth-gen-token`` to allow providing a u= sername in
+ these s= cenarios.
+ --port-share args
Share OpenVPN TCP with another= service

diff --git a/src/openvpn/multi.c= b/src/openvpn/multi.c
index 0292e8d..a673ec1 100644=
--- a/src/openvpn/multi.c
+++ b/src/openvpn/multi= .c
@@ -42,7 +42,9 @@
#include "ssl_ve= rify.h"
#include "ssl_ncp.h"
#include "vlan.h"

+#include "auth_token.h"
#include <= inttypes.h>
+#incl= ude <string.h>

#include "memd= bg.h"

@@ -2680,6 +2682,60 @@<= br> NULL,
};

+/**
+ * Overrides the locked username with the username of= --override-username
= + * @param mi the multi instance that should be modified.
+ */
+static bool
+override_locked_username(struct multi_instance *mi)+{
+ struct tls_multi *multi =3D mi->context.= c2.tls_multi;
+ st= ruct options *options =3D &mi->context.options;
+ struct tls_session *session =3D &= ;multi->session[TM_ACTIVE];
+
+ if (= !multi->locked_username)
+ {
+ = msg(D_MULTI_ERRORS, "MULTI: Ignoring override-username as no "<= /span>
+ "us= er/password method is enabled. Enable "
+ "--management-client-auth, --auth= -user-pass-verify, or a "
+ "plugin with user/password verify capability.&q= uot;);
+ retur= n false;
+ }

+
+ if (!multi->locked_original_username<= /span>
+ && s= trcmp(multi->locked_username, options->override_username) !=3D 0)

+ {
+ multi->locked_original_use= rname =3D multi->locked_username;
+ multi->locked_username =3D strdup(options->o= verride_username);
+<= /span>
+ /* Override = also the common name if username should be set as common
+ * name */
+ if ((session->opt->ssl_fl= ags & SSLF_USERNAME_AS_COMMON_NAME))
+ {
+ set_common_name(session, multi->locked_username);=
+ free(mu= lti->locked_cn);
+= multi->locked_cn =3D NULL;
+ tls_lock_common_name(multi);
+ }

+
+ /* Regenerate the auth-token if enabled */+ if (multi->auth_to= ken_initial)
+ = {
+ struc= t user_pass up;
+ = CLEAR(up);
+ = strncpynt(up.username, multi->locked_username,
+ sizeof(up.us= ername));
++ generate_auth_tok= en(&up, multi);
+= }
++ msg(D_MULTI_LOW, &quo= t;MULTI: Note, override-username changes username "
+ "from '%s' to= '%s'",
= + multi->locked_original_username,
+ multi->locked_username);=
+ }
+ return true;
+}
/*
*= Called as soon as the SSL/TLS connection is authenticated.
*
@@ -2783,6 +2839,14 @@
(*cur_= handler_index)++;
}

+ if (mi->context.options.overr= ide_username)
+ {<= /span>
+ if (!overrid= e_locked_username(mi))
+ = cc_succeeded =3D false;
+ }
+ = }
+
/* Check if we have forbidding options in the current mode */
=
if (dco_enabled(&mi->context.options)
&& !dco_check_option(D_MULTI_ERRORS, &mi->context.= options))
diff --git a/src/openvpn/options.c b/src/openvpn/= options.c
index df3ebad..704e65a 100644
---= a/src/openvpn/options.c
+++ b/src/openvpn/options.c=
@@ -452,6 +452,8 @@
" = Only valid in a client-specific config file.\n"
&= quot;--disable : Client is disabled.\n"
&qu= ot; Only valid in a client-specific config file.\n"
+ "--override-= username: Overrides the client-specific username to be used.\n"=
+ " = Only valid in a client-specific config file.\n"
= "--verify-client-cert [none|optional|require] : perform no, optional = or\n"
" mandatory client ce= rtificate verification.\n"
" = Default is to require the client to supply a certificate.\n"<= br>@@ -8000,6 +8002,23 @@
VERIFY_PERMISSION(= OPT_P_INSTANCE);
options->disable =3D true;

}
+= else if (streq(p[0], "override-username") && p[1] &am= p;& !p[2])
+ {=
+ VERIFY_PERM= ISSION(OPT_P_INSTANCE);
+ if (strlen(p[1]) > TLS_USERNAME_LEN)
+ {
+ msg(msglevel, "override-username e= xceeds the maximum length of %d "
+ "characters", TLS_USERNAME_LEN= );
+
+ /* disable the connectio= n since ignoring the request to
+ * set another username might cause serious problem= s */
+ opt= ions->disable =3D true;
+ }
+ = else
+ {<= /span>
+ options-= >override_username =3D p[1];
+ }
+ }
else if (streq(p[0], "tcp-nodelay") = && !p[1])
{
VERIFY_PE= RMISSION(OPT_P_GENERAL);
diff --git a/src/openvpn/options.h= b/src/openvpn/options.h
index 161899a..fa617c8 100644
--- a/src/openvpn/options.h
+++ b/src/openvpn/o= ptions.h
@@ -505,6 +505,7 @@
const cha= r *client_config_dir;
bool ccd_exclusive;
bool disable;

- push_option_fmt(gc, push_list, M_USAGE,
- &= quot;auth-token %s",
+ push_option_fmt(gc, push_list, M_USAGE, "auth-token %s&q= uot;,
tls_multi->auth_token);
+
+ char *base64user =3D NULL;
+ int ret =3D openv= pn_base64_encode(tls_multi->locked_username,
+ (int)st= rlen(tls_multi->locked_username),
+ &base64user);<= /span>
+ if (ret <= USER_PASS_LEN && ret > 0)
+ {
+ push_option_fmt(gc, push_list, M_USAGE, "auth-toke= n-user %s",
+ = base64user);
+ }
+ free(base64user);
}
}=

diff --git a/src/openvpn/ssl.c b/src/ope= nvpn/ssl.c
index 48f2a49..99b5c07 100644
--= - a/src/openvpn/ssl.c
+++ b/src/openvpn/ssl.c
@@ -1262,6 +1262,7 @@

free(multi->peer_info);
free(multi->locked_cn);
free(mul= ti->locked_username);
+ free(multi->locked_original_username);
=
cert_hash_free(multi->locked_cert_hash_set);

diff --git a/src/openvpn/ssl_common.h b/src/openvpn/s= sl_common.h
index 6916ad4..68a6ce6 100644
-= -- a/src/openvpn/ssl_common.h
+++ b/src/openvpn/ssl_common.= h
@@ -627,7 +627,16 @@
* Our locked c= ommon name, username, and cert hashes (cannot change during the life of thi= s tls_multi object)
*/
char *loc= ked_cn;
+
<= span style=3D"color: hsl(120, 100%, 40%);">+ /** The locked username is = the username we assume the client is using.

+ * Normally the username used for initial authe= ntication unless
+ = * overridden by --override-username */
char *locked_= username;
++ /** The username that cli= ent initially used before being overridden
+ * by --override-user */
+ char *locked_original_username;
+
str= uct cert_hash_set *locked_cert_hash_set;

= /** Time of last when we updated the cached state of
d= iff --git a/src/openvpn/ssl_verify.c b/src/openvpn/ssl_verify.c
<= span>index 1ac94fc..5f8f1d3 100644

--- a/src/openvpn/ssl_ve= rify.c
+++ b/src/openvpn/ssl_verify.c
@@ -4= 8,9 +48,6 @@
#include "push.h"
= #include "ssl_util.h"

-/** Maximum length of common name */
= -#define TLS_USERNAME_LEN 64
-
static v= oid
string_mod_remap_name(char *str)
{
@@ -85,10 +82,7 @@
}
}<= /span>

-/*
- * Set the given sessio= n's common_name
- *= /
-static void+void
set_co= mmon_name(struct tls_session *session, const char *common_name)
<= span> {

if (session->common_name)
@= @ -153,7 +147,10 @@
{
if (multi->l= ocked_username)
{
- if (strcmp(username, multi->locked_username) != =3D 0)
+ /* If= the username has been overridden, we accept both the original
+ * username and the chan= ged username */

+ = if (strcmp(username, multi->locked_username) !=3D 0
+ && (!multi->= locked_original_username || strcmp(username, multi->locked_original_user= name) !=3D 0))
{
msg(= D_TLS_ERRORS, "TLS Auth Error: username attempted to change from '= %s' to '%s' -- tunnel disabled",
= multi->locked_username,
@@ -1604,6 +1601,17 @@
*/
bool skip_auth =3D false;

+ /*= Replace username early if override-username is in effect but only+ * if client is sending = the original username */
+ if (multi->locked_original_username
+ && strncmp(up->username, mul= ti->locked_original_username, sizeof(up->username)) =3D=3D 0)<= br>+ {
+ msg(D_MULTI_LOW, "TLS: Repla= cing client provided username '%s' with "
+ "username from override= -user '%s'", up->username,
+ multi->locked_username);
+ strncpy(up->username,= multi->locked_username, sizeof(up->username));

+ }
+
/*
* If ser= ver is configured with --auth-gen-token and the client sends
* something that looks like an authentication token, this
diff --git a/src/openvpn/ssl_verify.h b/src/openvpn/ssl_verify.h
index cd2ec24..eba3832 100644
--- a/src/openvp= n/ssl_verify.h
+++ b/src/openvpn/ssl_verify.h
@@ -51,6 +51,9 @@

/** Maximum certificate depth we will= allow */
#define MAX_CERT_DEPTH 16

+/** Maximum length of co= mmon name */
+#define= TLS_USERNAME_LEN 64
= +
/** Structure containing the hash for a single certifica= te */
struct cert_hash {
unsigned cha= r sha256_hash[256/8];
@@ -146,6 +149,16 @@
= */
const char *tls_common_name(const struct tls_multi *m= ulti, const bool null);

+
+ * Sets the c= ommon name field for the given tunnel
+ *
= + * @param multi The tunnel to set the common name for
+ * @param common_name The name= to set the common name to

+ */
+void
+set_common_name(struct t= ls_session *session, const char *common_name);
+
/**
* Return= s the username field for the given tunnel
*

To view, visit change 872. To unsubscribe, or for help wr= iting mail filters, visit se= ttings.

<= div itemscope itemprop=3D"action" itemtype=3D"http://schema.org/ViewAction"= >
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia4095518d5e4447992a2974e0d7= a159d79ba6b6f
Gerrit-Change-Number: 872
Gerrit-PatchSet: 10
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: d12fk <heiko@...515...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-CC: ordex <a@...2181...>
Gerrit-CC: stipa <lstipakov@...277...> <= /div>
Gerrit-MessageType: merged
--IOa3J9X6RF4=--