Skip to contentSkip to conversation

Fix auth-token usage with management-def-auth

PATCH In review [email protected]... 4 participants 5 messages Jul 4, 2022 – Aug 19, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix auth-token usage with management-def-auth

From: Selva Nair <[email protected]...>

When auth-token verify succeeds during a reauth, other auth methods (plugin, script, management) are skipped unless external-auth is in effect (skip_auth gets set to true).

However, in this case, the status of management-def-auth (ks->mda_satus) stays at its default value of ACF_PENDING and will never change. This causes TLS keys to go out of sync and an eventual client disconnect.

Further, a message saying username/password authentication is "deferred" gets logged which is misleading.
For example:

test/127.0.0.1:35874 TLS: Username/auth-token authentication
succeeded for username 'test'

followed by

test/127.0.0.1:35874 TLS: Username/Password authentication
deferred for username 'test' [CN SET]

Fix by setting ks->mda_status to ACF_DISABLED, and do not set ks->authenticated = KS_AUTH_DEFERRED when skip_auth is true.

Also log a warning message when token is marked as expired on missing the reneg window.

Reported by: Connor Edwards <[email protected]...>

---
 src/openvpn/auth_token.c | 8 +++++---
 src/openvpn/ssl_verify.c | 9 ++++++++-
 2 files changed, 13 insertions(+), 4 deletions(-)
src/openvpn/auth_token.c +5 -3
index 096edc75..b5f9f6dd 100644
@@ -346,20 +346,22 @@ verify_auth_token(struct user_pass *up, struct tls_multi *multi,
         return 0;
     }
 
-    /* Accept session tokens that not expired are in the acceptable range
-     * for renogiations */
+    /* Accept session tokens only if their timestamp is in the acceptable range
+     * for renegotiations */
     bool in_renegotiation_time = now >= timestamp
                                  && now < timestamp + 2 * session->opt->renegotiate_seconds;
 
     if (!in_renegotiation_time)
     {
+        msg(M_WARN, "Timestamp (%" PRIu64 ") of auth-token is out of the renegotiation window",
+            timestamp);
         ret |= AUTH_TOKEN_EXPIRED;
     }
 
     /* Sanity check the initial timestamp */
     if (timestamp < timestamp_initial)
     {
-        msg(M_WARN, "Initial timestamp (%" PRIu64 " in token from client earlier than "
+        msg(M_WARN, "Initial timestamp (%" PRIu64 ") in token from client earlier than "
             "current timestamp %" PRIu64 ". Broken/unsynchronised clock?",
             timestamp_initial, timestamp);
         ret |= AUTH_TOKEN_EXPIRED;
src/openvpn/ssl_verify.c +8 -1
index c01841fa..45eaf8ed 100644
@@ -1599,7 +1599,14 @@ verify_user_pass(struct user_pass *up, struct tls_multi *multi,
 #ifdef ENABLE_MANAGEMENT
         if (man_def_auth != KMDA_UNDEF)
         {
-            ks->authenticated = KS_AUTH_DEFERRED;
+            if (skip_auth)
+            {
+                ks->mda_status = ACF_DISABLED;
+            }
+            else
+            {
+                ks->authenticated = KS_AUTH_DEFERRED;
+            }
         }
 #endif
         if ((session->opt->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME))
Signature · 1 line
2.30.2
#1 lore raw

Looks good. Shortly after my last email about the issue I found this bit of code and also came to the conclusion it was faulty.

Thanks for the patch Selva.

Signature · 9 lines
*This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed. 
If you are not the named addressee you must not disseminate, distribute or 
copy this e-mail. Please notify us on [email protected]... 
<mailto:[email protected]...> immediately if you have received this e-mail 
by mistake and delete this e-mail from your system. If you are not the 
intended recipient you are notified that disclosing, copying, distributing 
or taking any action in reliance on the contents of this information is 
strictly prohibited.*
Acked-by on v1 1/1
#2 lore raw
In reply to [email protected]...

Am 04.07.22 um 04:58 schrieb [email protected]...:

Quoted 8 lines

From: Selva Nair <[email protected]...>

When auth-token verify succeeds during a reauth, other auth methods (plugin, script, management) are skipped unless external-auth is in effect (skip_auth gets set to true).

However, in this case, the status of management-def-auth (ks->mda_satus) stays at its default value of ACF_PENDING

ks->mda_status

Quoted 15 lines

and will never change. This causes TLS keys to go out of sync and an eventual client disconnect.

Further, a message saying username/password authentication is "deferred" gets logged which is misleading.
For example:

test/127.0.0.1:35874 TLS: Username/auth-token authentication
succeeded for username 'test'

followed by

test/127.0.0.1:35874 TLS: Username/Password authentication
deferred for username 'test' [CN SET]

Quoted 8 lines

Fix by setting ks->mda_status to ACF_DISABLED, and do not set ks->authenticated = KS_AUTH_DEFERRED when skip_auth is true.

Also log a warning message when token is marked as expired on missing the reneg window.

Reported by: Connor Edwards <[email protected]...>

Note that you need have management enabled for this bug to trigger. If you go through all the effort to talk to management like this, you probably want to use external-auth anyway.

Basically currently AS is the only management+server mode application that active developer use, bugs like this tend to slip.

Arne

author
#3 lore raw

Hi

Quoted 33 lines · Arne Schwabe

Am 04.07.22 um 04:58 schrieb [email protected]...:

Quoted 8 lines

From: Selva Nair <[email protected]...>

When auth-token verify succeeds during a reauth, other auth methods (plugin, script, management) are skipped unless external-auth is in effect (skip_auth gets set to true).

However, in this case, the status of management-def-auth (ks->mda_satus) stays at its default value of ACF_PENDING

ks->mda_status

Quoted 21 lines

and will never change. This causes TLS keys to go out of sync and an eventual client disconnect.

Further, a message saying username/password authentication is "deferred" gets logged which is misleading.
For example:

test/127.0.0.1:35874 TLS: Username/auth-token authentication
succeeded for username 'test'

followed by

test/127.0.0.1:35874 TLS: Username/Password authentication
deferred for username 'test' [CN SET]

Fix by setting ks->mda_status to ACF_DISABLED, and do not set ks->authenticated = KS_AUTH_DEFERRED when skip_auth is true.

Also log a warning message when token is marked as expired on missing the reneg window.

Quoted 9 lines
Quoted 2 lines

Reported by: Connor Edwards <[email protected]...>

Note that you need have management enabled for this bug to trigger. If you go through all the effort to talk to management like this, you probably want to use external-auth anyway.

I agree. This kind of fiddling with flags like mda_status is not clean and easy to break again. I use management-def-auth but do not use auth-gen-token -- instead the management script keeps track of reauth, lifetime of 2FA etc. If I were to "modernize" that setup I would use auth-gen-token with external-auth as well.

That said, for 2.5, an easy fix like this is good enough?

Selva

#4 lore raw
In reply to [email protected]...

Sorry for leaving this ACKed-but-unmerged since July. It got heaped-over by DCO patches...

Anyway. I have no current test rig where I could recreate and test this, but if Arne as resident management interface expert is happy with this, this is fine for me. (The comment / message updates are easy to review and make sense).

I have test compiled it :-) - and lightly tested, knowing that the interesting code path is not excercised. Just to be sure.

Cherrypicking to 2.5 caused a funny conflict, as the variable is called "in_renog_time" there, and got renamed to "in_renegotiation_time" somewhere later... but solved easily enough.

Your patch has been applied to the master and release/2.5 branch.

commit ddbe6a6fc26586d09f5a9105f13124c479b4d993 (master) commit 5b178f591c882a6600414104a77a9240f7a29331 (release/2.5)

Author: Selva Nair
Date:   Sun Jul 3 22:58:40 2022 -0400
     Fix auth-token usage with management-def-auth

     Signed-off-by: Selva Nair <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg24627.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering