From: "plaisthos (Code Review)" Date: Tue, 21 Jan 2025 09:50:15 +0000 In-Reply-To: References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <7a8ef3d6073361abb91a6e81f9b30de19919de53-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="jx3ukjdrVFM="; 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: flichtenheld Cc: openvpn-devel --jx3ukjdrVFM= 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/+/872?usp=3Demail to look at the new patch set (#3). Change subject: Implement override-username ...................................................................... Implement override-username This is intended to allow using auth-gen-token in scenarios where the client 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. Change-Id: Ia4095518d5e4447992a2974e0d7a159d79ba6b6f Signed-off-by: Arne Schwabe --- M Changes.rst M doc/man-sections/server-options.rst M src/openvpn/auth_token.c 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 11 files changed, 158 insertions(+), 10 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/72/872/3 diff --git a/Changes.rst b/Changes.rst index 16ae6fc..8543113 100644 --- a/Changes.rst +++ b/Changes.rst @@ -36,6 +36,10 @@ add an allowed cipher without having to spell out the default ciphers. +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. + 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..a76de67 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 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 + 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 has to be taken both the initial username of the client and= the + overridden username are correctly handled when using ``--override-usern= ame`` + 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/auth_token.c b/src/openvpn/auth_token.c index 3cf55e8..f51c42e 100644 --- a/src/openvpn/auth_token.c +++ b/src/openvpn/auth_token.c @@ -330,6 +330,7 @@ timestamp_initial =3D ntohll(timestamp_initial); hmac_ctx_t *ctx =3D multi->opt.auth_token_key.hmac; + if (check_hmac_token(ctx, b64decoded, up->username)) { ret |=3D AUTH_TOKEN_HMAC_OK; diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index f426b46..3e0cbe1 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" @@ -2663,6 +2665,48 @@ NULL, }; +/** + * Overrides the locked username with the username of --override-username + * @param mi the multi instance that should be modified. + */ +static void +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_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); + 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); + } +} /* * Called as soon as the SSL/TLS connection is authenticated. * @@ -2766,6 +2810,11 @@ (*cur_handler_index)++; } + if (mi->context.options.override_username) + { + override_locked_username(mi); + } + /* 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 3ef4d78..93b8417 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -440,6 +440,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" @@ -7847,6 +7849,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 55f12dd..274f282 100644 --- a/src/openvpn/options.h +++ b/src/openvpn/options.h @@ -492,6 +492,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 a7cd3bf..5ccd7d8 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; + 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 e4a7b57..e548299 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -1260,6 +1260,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 e092472..2efeb6a 100644 --- a/src/openvpn/ssl_common.h +++ b/src/openvpn/ssl_common.h @@ -625,7 +625,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 e7d7ed6..e78c8e7 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) @@ -141,6 +135,7 @@ const char *cn =3D multi->session[TM_ACTIVE].common_name; if (cn && !multi->locked_cn) { + free(multi->locked_cn); multi->locked_cn =3D string_alloc(cn, NULL); } } @@ -153,7 +148,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, @@ -1613,6 +1611,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 0) + { + strncpy(up->username, multi->locked_username, sizeof(up->username)= ); + msg(D_MULTI_LOW, "TLS: Replacing client provided username '%s' wit= h " + "username from override-user '%s'", up->username, + multi->locked_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: 3 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: flichtenheld Gerrit-MessageType: newpatchset --jx3ukjdrVFM= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld.

plaisthos uploaded patch set #3 to this change.

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

Implement override-username

This is intended to allow using au= th-gen-token in scenarios where the
client use certificates and multi-fa= ctor authentication.

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

The scenario that this feature is probably most useful
whe= n --management-client-auth is in use as in this mode the OpenVPN
server = can accept clients without username/password but still use
--auth-gen-to= ken with username and password to accept auth-token as
alternative authe= ntication.

Change-Id: Ia4095518d5e4447992a2974e0d7a159d79ba6b6f
S= igned-off-by: Arne Schwabe <arne@...1227...>
---
M Changes.rst<= br>M doc/man-sections/server-options.rst
M src/openvpn/auth_token.c
M= src/openvpn/multi.c
M src/openvpn/options.c
M src/openvpn/options.h<= br>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
11 files c= hanged, 158 insertions(+), 10 deletions(-)

git pull ssh://gerrit.=
openvpn.net:29418/openvpn refs/changes/72/872/3
diff --git a/Change=
s.rst b/Changes.rst
index 16ae6fc..8543113 100644--- a/Changes.rst
+++ b/Changes.rst
= @@ -36,6 +36,10 @@
add an allowed cipher without havin= g to spell out the default ciphers.


+Allow overriding userna= me with ``--override-username``
+ This is intended to allow using auth-gen-token in scenarios= where the
+ clien= ts use certificates and multi-factor authentication.
+
Deprecated features
-------------------
``secret`` support has b= een removed by default.
diff --git a/doc/man-sections/serve= r-options.rst b/doc/man-sections/server-options.rst
index 3= fe9862..a76de67 100644
--- a/doc/man-sections/server-option= s.rst
+++ b/doc/man-sections/server-options.rst
<= span>@@ -89,6 +89,12 @@

will lead to authentication bypa= ss (as does returning success on a wrong
password from a= script).

+ **Note:** the username for ``--auth-gen-token`` can be overridden= by
+ ``--override-u= ser``. In this case the client will be pushed also the
+ ``--auth-token-user`` option and and a= n auth token that is valid for
+ that username instead of the original username that the client=
+ authenticated wit= h.
+
= --auth-gen-token-secret file
Specifies a file that hold= s 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
+ Sets the username of a connection to the speci= fied username. This username
+ will also be used by ``--auth-gen-token``. However, the overrid= den
+ username comes= only into effect *after* the ``--client-config-dir`` has been
+ read and the ``--auth-user-pas= s-verify`` and ``--client-connect`` scripts

+ have been run.
+
+ Also ``username-as-common-name`` will use the client provided username<= /span>
+ as common-name. It= is recommended to avoid the use of the
+ ``--override-username`` option if the option ``--user= name-as-common-name``
+ is being used.
+<= /span>
+ The changed userna= me will be picked up by the status output and also by
+ the ``--auth-gen-token`` option. It wil= l also be pushed to the client
+ using ``--auth-token-user``.
+
+ overridden = username are correctly handled when using ``--override-username``+ and the related options to= avoid authentication/authorisation
+ bypasses.
+
+ This opti= on 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 provi= ding a username in
+ = these scenarios.
+
--port-share args
Share OpenVPN TCP with= another service

diff --git a/src/openvpn= /auth_token.c b/src/openvpn/auth_token.c
index 3cf55e8..f51= c42e 100644
--- a/src/openvpn/auth_token.c
= +++ b/src/openvpn/auth_token.c
@@ -330,6 +330,7 @@ timestamp_initial =3D ntohll(timestamp_initial);

hmac_ctx_t *ctx =3D multi->opt.auth_token_key.= hmac;
+
if (check_hmac_token(ctx, b64decoded, up->username))

<= span> {
ret |=3D AUTH_TOKEN_HMAC_OK;diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c
index f426b46..3e0cbe1 100644
--- a/src/openvpn/multi.c<= /span>
+++ b/src/openvpn/multi.c
@@ -42,7 +42,9 @@=
#include "ssl_verify.h"
#inclu= de "ssl_ncp.h"
#include "vlan.h"
+#include "auth_token= .h"
#include <inttypes.h>
+#include <string.h>

#include "memdbg.h"
<= br>@@ -2663,6 +2665,48 @@
NULL,
= };

+/**
+ * Overrides t= he locked username with the username of --override-username
+ * @param mi the multi instance tha= t should be modified.

+ */
+static void
+override_locked_userna= me(struct multi_instance *mi)
+{
+ stru= ct tls_multi *multi =3D mi->context.c2.tls_multi;
+ struct options *options =3D &mi-&= gt;context.options;
+= struct tls_session *session =3D &multi->session[TM_ACTIVE];
+
+ if (!multi->locked_original_userna= me
+ &&= ; strcmp(multi->locked_username, options->override_username) !=3D 0)<= /span>
+ {
+ multi->locked_original_= username =3D multi->locked_username;

+ multi->locked_username =3D strdup(options-&g= t;override_username);
+
+ /* Overri= de also the common name if username should be set as common
+ * name */

+ if ((session->opt->ssl= _flags & SSLF_USERNAME_AS_COMMON_NAME))
+ {
+ set_common_name(session, multi->locked_usernam= e);
+ tls_= lock_common_name(multi);
+ }
+
+ /* Regenerate th= e auth-token if enabled */
+ if (multi->auth_token_initial)
+ {
+ struct user_pass up;
+ CLEAR(up);
+ strncpynt(up.username, mul= ti->locked_username,
+ sizeof(up.username));
+
+ generate_auth_token(&up, multi);
+ }
+
+ msg(D_MULTI_LOW, "MULTI: Note, override-username chan= ges username "
+= "from '%s' to '%s'",
+ multi->locked_origina= l_username,
+ = multi->locked_username);
+ }
+}<= /span>
/*
* Called as soon as the SSL/TLS conne= ction is authenticated.
*
@@ -2766,6 +281= 0,11 @@
(*cur_handler_index)++;
= }

+ {
+ override_locked_username(mi);
+ }
+
/* Check if we have forbiddin= g options in the current mode */
if (dco_enabled(&= mi->context.options)
&& !dco_check_opti= on(D_MULTI_ERRORS, &mi->context.options))
diff --git= a/src/openvpn/options.c b/src/openvpn/options.c
index 3ef4= d78..93b8417 100644
--- a/src/openvpn/options.c
<= span>+++ b/src/openvpn/options.c

@@ -440,6 +440,8 @@=
" Only valid in a client-specific conf= ig file.\n"
"--disable : Client is dis= abled.\n"
" Only valid in a= client-specific config file.\n"
+ "--override-username: Overrides the client-speci= fic username to be used.\n"
+ " Only valid in a client-specific co= nfig file.\n"
"--verify-client-cert [none|op= tional|require] : perform no, optional or\n"
&quo= t; mandatory client certificate verification.\n"
" Default is to require the client t= o supply a certificate.\n"
@@ -7847,6 +7849,23 @@
VERIFY_PERMISSION(OPT_P_INSTANCE);
= options->disable =3D true;
}
+ else if (streq(p[0], "overr= ide-username") && p[1] && !p[2])
+ {
+ VERIFY_PERMISSION(OPT_P_INSTANCE);
+ if (strlen(p[1]) > TL= S_USERNAME_LEN)

+ = {
+ ms= g(msglevel, "override-username exceeds the maximum length of %d "=
+ &qu= ot;characters", TLS_USERNAME_LEN);
+
= + /* disable the connection since ignoring the request to=
+ * set another= username might cause serious problems */
+ options->disable =3D true;
<= span style=3D"color: hsl(120, 100%, 40%);">+ }

+ 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 55f12dd..274f282 100644

--- a/src/openvpn/options.= h
+++ b/src/openvpn/options.h
@@ -492,6 +49= 2,7 @@
const char *client_config_dir;
= bool ccd_exclusive;
bool disable;
+ const char *override_username;<= /span>
int n_bcast_buf;
int tcp_queue_li= mit;
struct iroute *iroutes;
diff --gi= t a/src/openvpn/push.c b/src/openvpn/push.c
index a7cd3bf..= 5ccd7d8 100644
--- a/src/openvpn/push.c
+++= b/src/openvpn/push.c
@@ -595,9 +595,19 @@
= */
if (tls_multi->auth_token)
{
- push_o= ption_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;
+ = (int)strlen(tls_multi->locked_username),
= + = &base64user);
+ if (ret < USER_PASS_LEN && ret > 0)+ {
+ push_option_fmt(gc, push_li= st, M_USAGE, "auth-token-user %s",
+ base64user);+ }
+ free(base64user);
}
}

diff --git a= /src/openvpn/ssl.c b/src/openvpn/ssl.c
index e4a7b57..e5482= 99 100644
--- a/src/openvpn/ssl.c
+++ b/src= /openvpn/ssl.c
@@ -1260,6 +1260,7 @@
f= ree(multi->peer_info);
free(multi->locked_cn);
free(multi->locked_username);
+ free(multi->locked_original_userna= me);

cert_hash_free(multi->locked= _cert_hash_set);

diff --git a/src/openvpn= /ssl_common.h b/src/openvpn/ssl_common.h
index e092472..2ef= eb6a 100644
--- a/src/openvpn/ssl_common.h
= +++ b/src/openvpn/ssl_common.h
@@ -625,7 +625,16 @@<= br> * Our locked common name, username, and cert hashes (cannot = change during the life of this tls_multi object)
*/
char *locked_cn;
+
+ = /** The locked username is the username we assume the client is using.

+ * Normally the us= ername used for initial authentication unless
+ * overridden by --override-username */

char *locked_username;
+
+= /** The username that client initially used before being overridden

+ * by --override-us= er */
+ char *lock= ed_original_username;
+
struct cert_hash_set *locked_cert_hash_set;<= br>
/** Time of last when we updated the cached= state of
diff --git a/src/openvpn/ssl_verify.c b/src/openv= pn/ssl_verify.c
index e7d7ed6..e78c8e7 100644
--- a/src/openvpn/ssl_verify.c
+++ b/src/openvpn/ssl_ver= ify.c
@@ -48,9 +48,6 @@
#include "pus= h.h"
#include "ssl_util.h"
=
-/** Maximum length o= f common name */
-#defi= ne 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
+v= oid
set_common_name(struct tls_session *session, const cha= r *common_name)
{
if (session->com= mon_name)
@@ -141,6 +135,7 @@
const ch= ar *cn =3D multi->session[TM_ACTIVE].common_name;
i= f (cn && !multi->locked_cn)
{
+ free(multi->locked_cn)= ;
multi->locked_cn =3D string_alloc(cn, NULL);<= /span>
}
}
@@ -153,7 +148,10= @@
{
if (multi->locked_username)<= /span>
{
= - 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(us= ername, multi->locked_username) !=3D 0
+ && (!multi->locked_original_u= sername || strcmp(username, multi->locked_original_username) !=3D 0))
{
msg(D_TLS_ERRORS, &qu= ot;TLS Auth Error: username attempted to change from '%s' to '%= s' -- tunnel disabled",
multi->= ;locked_username,
@@ -1613,6 +1611,17 @@
= */
bool skip_auth =3D false;

+ /* Replace username= early if override-username is in effect but only
+ * if client is sending the original user= name */
+ if (mult= i->locked_original_username
+ && strncmp(up->username, multi->locked_ori= ginal_username, sizeof(up->username)) !=3D 0)
+ {
+ strncpy(up->username, multi->locked_username, = sizeof(up->username));
+ msg(D_MULTI_LOW, "TLS: Replacing client provided usernam= e '%s' with "
+ "username from override-user '%s&#= 39;", up->username,
+ multi->locked_username);
+ }
+
/*
*= If server is configured with --auth-gen-token and the client sends<= br> * something that looks like an authentication token, this
diff --git a/src/openvpn/ssl_verify.h b/src/openvpn/ssl_verif= y.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 lengt= h of common name */
+= #define TLS_USERNAME_LEN 64
+
/** Structure containing the hash for a single ce= rtificate */
struct cert_hash {
unsig= ned char sha256_hash[256/8];
@@ -146,6 +149,16 @@ */
const char *tls_common_name(const struct tls_m= ulti *multi, const bool null);

+
+/**
+ * Set= s the common name field for the given tunnel
+ *
+ * @param multi The tunnel to set the common name for

+ * @param common_name T= he name to set the common name to
+ */
+vo= id
+set_common_name(s= truct tls_session *session, const char *common_name);
+
/**
*= Returns the username field for the given tunnel
*=

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

=
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia4095518d5e4447992a2974e0d7= a159d79ba6b6f
Gerrit-Change-Number: 872
Gerrit-PatchSet: 3
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
--jx3ukjdrVFM=--