Skip to contentSkip to conversation

Fix session id and initial timestamp not begin preserved

PATCH Superseded Arne Schwabe 4 participants 11 messages Mar 26, 2020 – May 19, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 Fix session id and initial timestamp not begin preserved

In the initial state of checking whether an auth-token has been validated, the check check if multi->auth_token is already set and only then sets the value. This defeats the purpose and lead to always a new auth-token with new session id and lifetime being generated when the server restarts or the client reconnect to another server.

---
 src/openvpn/ssl_verify.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/ssl_verify.c +1 -1
index da0966c5..226daf3d 100644
@@ -1381,7 +1381,7 @@ verify_user_pass(struct user_pass *up, struct tls_multi *multi,
              * to store the auth-token in multi->auth_token, so
              * the initial timestamp and session id can be extracted from it
              */
-            if (multi->auth_token && (multi->auth_token_state_flags & AUTH_TOKEN_HMAC_OK)
+            if ((multi->auth_token_state_flags & AUTH_TOKEN_HMAC_OK)
                 && !(multi->auth_token_state_flags & AUTH_TOKEN_EXPIRED))
             {
                 multi->auth_token = strdup(up->password);
Signature · 1 line
2.26.0
#1 lore raw

PATCH 2/3 Fix session id in env missing first byte

sizeof for a constant string return the size including the null byte. For copying the session id this meant that we do not copy the first byte. This made the session id reported to the external authenticator one byte shorter than it was indented to be.

---
 src/openvpn/auth_token.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/auth_token.c +1 -1
index 6275299d..585679dc 100644
@@ -121,7 +121,7 @@ add_session_token_env(struct tls_session *session, struct tls_multi *multi,
      */
 
     char session_id[AUTH_TOKEN_SESSION_ID_LEN*2] = {0};
-    memcpy(session_id, session_id_source + sizeof(SESSION_ID_PREFIX),
+    memcpy(session_id, session_id_source + strlen(SESSION_ID_PREFIX),
            AUTH_TOKEN_SESSION_ID_LEN*8/6);
 
     setenv_str(session->opt->es, "session_id", session_id);
Signature · 1 line
2.26.0
#3 lore raw

PATCH 3/3 Document reneweal mechanic of auth-token in manual

In reply to Arne Schwabe

Our man page was missing the information that the life time of the auth-token also depends on the reneg-sec

---
 doc/openvpn.8 | 6 ++++++
 1 file changed, 6 insertions(+)
doc/openvpn.8 +6 -0
index 864f94e8..f890e7a2 100644
@@ -3741,6 +3741,12 @@ argument defines how long the generated token is valid.  The
 lifetime is defined in seconds.  If lifetime is not set
 or it is set to 0, the token will never expire.
 
+The token will expire either after the lifetime of the token or after
+not being renewed for 2 *
+.B reneg\-sec
+seconds. Clients are being send renewed tokens on every
+TLS renogiation to keep the client's token updated.
+
 This feature is useful for environments which is configured
 to use One Time Passwords (OTP) as part of the user/password
 authentications and that authentication mechanism does not
Signature · 1 line
2.26.0
#4 lore raw

Re: [Openvpn-devel] [PATCH 3/3] [auth-token] Document reneweal mechanic of auth-token in manual

doc/openvpn.8 argument defines how long the generated token is valid. The · line 3747

Quoted 12 lines · Arne Schwabe
doc/openvpn.8 +4 -0
index 864f94e8..f890e7a2 100644
@@ -3741,6 +3741,12 @@ argument defines how long the generated token is valid.  The
 lifetime is defined in seconds.  If lifetime is not set
 or it is set to 0, the token will never expire.
 
+The token will expire either after the lifetime of the token or after
+not being renewed for 2 *
+.B reneg\-sec
+seconds. Clients are being send renewed tokens on every

s/send/sent/

(Would something like "Clients should normally be sent" or "During normal operation, clients will be sent" be a clearer explanation of the topic?)

Nathan

----------------------------------------------------------------------------
Nathan Stratton Treadway - [email protected]... - Mid-Atlantic region
Ray Ontko & Co. - Software consulting services - http://www.ontko.com/
GPG Key: http://www.ontko.com/~nathanst/gpg_key.txt ID: 1023D/ECFB6239
Key fingerprint = 6AD8 485E 20B9 5C71 231C 0C32 15F3 ADCD ECFB 6239

Acked-by on v1 2/3
#2 lore raw

[Openvpn-devel] [PATCH applied] Re: Fix session id in env missing first byte

In reply to Arne Schwabe

Your patch has been applied to the master branch.

Haven't actually tested this in any server setup - but "this is your code, if you say this is the way it needs to be, it is, the explanation makes sense and the code change matches". An all other occurences use strlen() as well... So,

commit 42fe3e8175822a4cf2c85cc4ce3fdffd41d74455

Author: Arne Schwabe
Date:   Thu Mar 26 18:23:31 2020 +0100
     Fix session id in env missing first byte

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

--
kind regards,

Gert Doering

Acked-by on v1 3/3
#5 lore raw

[Openvpn-devel] [PATCH applied] Re: Document reneweal mechanic of auth-token in manual

In reply to Arne Schwabe

Documentation is good.

I have followed the advice from Nathan Stratton Treadway and looked a bit into the wording, and added some text that I feel explains the process and reasoning better (based on how you explained it to me). I hope it's ok.

Your patch has been applied to the master branch.

commit b0c94aff299fcec607d6a0194c4cdea8a33dd353

Author: Arne Schwabe
Date:   Thu Mar 26 18:23:32 2020 +0100
     Document reneweal mechanic of auth-token in manual

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

--
kind regards,

Gert Doering

#6 lore raw

PATCH v2 1/3 Fix session id and initial timestamp not begin preserved

In reply to Arne Schwabe

In the initial state of checking whether an auth-token has been validated, the check check if multi->auth_token is already set and only then sets the value. This defeats the purpose and lead to always a new auth-token with new session id and lifetime being generated when the server restarts or the client reconnect to another server.

Patch V2: Only set multi->auth_token when NULL to avoid leaking
memory. Improve comments and documentation of auth-token.

---
 src/openvpn/auth_token.h | 17 +++++++++++------
 src/openvpn/ssl_verify.c |  9 ++++++---
 2 files changed, 17 insertions(+), 9 deletions(-)
src/openvpn/auth_token.h +11 -6
index 6f34b760..d5694898 100644
@@ -34,8 +34,8 @@
  *
  * Format of the auth-token (before base64 encode)
  *
- * session id(12 bytes)|uint64 timestamp (4 bytes)|
- * uint64 timestamp (4 bytes)|sha256-hmac(32 bytes)
+ * session id(12 bytes)|uint64 timestamp (8 bytes)|
+ * uint64 timestamp (8 bytes)|sha256-hmac(32 bytes)
  *
  * The first timestamp is the time the token was initially created and is used to
  * determine the maximum renewable time of the token. We always include this even
@@ -45,14 +45,19 @@
  * to determine if this token has been renewed in the acceptable time range
  * (2 * renogiation timeout)
  *
- * The session is a random string of 12 byte (or 16 in base64) that is not used by
- * OpenVPN itself but kept intact so that external logging/managment can track the
- * session multiple reconnects/servers
+ * The session id is a random string of 12 byte (or 16 in base64) that is not
+ * used by OpenVPN itself but kept intact so that external logging/managment
+ * can track the session multiple reconnects/servers. It is delibrately chosen
+ * be a multiple of 3 bytes to have a base64 encoding without padding.
  *
  * The hmac is calculated over the username contactinated with the
  * raw auth-token bytes to include authentication of the username in the token
  *
- * we prepend the session id with SESS_ID_ before sending it to the client
+ * We encode the auth-token with base64 and then it with SESS_ID_ before
+ * sending it to the client.
+ *
+ * This function will free() an existing multi->auth_token and keep the existing
+ * initial timestamp and session id contained in that token.
  */
 void
 generate_auth_token(const struct user_pass *up, struct tls_multi *multi);
src/openvpn/ssl_verify.c +6 -3
index e66d81e1..ddaef6d7 100644
@@ -1380,15 +1380,15 @@ verify_user_pass(struct user_pass *up, struct tls_multi *multi,
              * to store the auth-token in multi->auth_token, so
              * the initial timestamp and session id can be extracted from it
              */
-            if (multi->auth_token && (multi->auth_token_state_flags & AUTH_TOKEN_HMAC_OK)
+            if (!multi->auth_token && (multi->auth_token_state_flags & AUTH_TOKEN_HMAC_OK)
                 && !(multi->auth_token_state_flags & AUTH_TOKEN_EXPIRED))
             {
                 multi->auth_token = strdup(up->password);
             }
 
             /*
-             * Server is configured with --auth-gen-token but no token has yet
-             * been generated for this client.  Generate one and save it.
+             * Server is configured with --auth-gen-token. Generate or renew
+             * the token.
              */
             generate_auth_token(up, multi);
         }
@@ -1396,6 +1396,9 @@ verify_user_pass(struct user_pass *up, struct tls_multi *multi,
          * Auth token already sent to client, update auth-token on client.
          * The initial auth-token is sent as part of the push message, for this
          * update we need to schedule an extra push message.
+         *
+         * Otherwise the auth-token get pushed out as part of the "normal"
+         * push-reply
          */
         if (multi->auth_token_initial)
         {
Signature · 1 line
2.26.0
Acked-by on v2 1/3
#7 lore raw

[Openvpn-devel] [PATCH applied] Re: Fix session id and initial timestamp not being preserved

Discussed with Arne, change makes sense, old code did not do what it tried to. Plus documentation enhancements, always welcome.

I haven't tested this in any "real" aspect (server-side), just basic compile/client tests (which unsurprisingly didn't turn up anything).

Your patch has been applied to the master branch.

I have reworded / rewrapped the comments slightly, and also rewrapped the patched if() statement onto 3 lines, to keep to the line length limit. No code space, just whitespace and comments.

commit 15d0331e5731c7559cfe95e6bb62dc3f3654b08e

Author: Arne Schwabe
Date:   Tue May 12 14:43:44 2020 +0200
     Fix session id and initial timestamp not begin preserved

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

--
kind regards,

Gert Doering

#8 lore raw

PATCH 1/1 Refuse server mode on Android

In reply to Arne Schwabe

After the commit 042429d3 "build: Remove --disable-server from ./configure" Android needs another way to ensure that OpenVPN is not run in server mode.

---
 src/openvpn/options.c | 3 +++
 1 file changed, 3 insertions(+)
src/openvpn/options.c +3 -0
index 2da8cf6d..bfba62ad 100644
@@ -2254,6 +2254,9 @@ options_postprocess_verify_ce(const struct options *options, const struct connec
      */
     if (options->mode == MODE_SERVER)
     {
+#ifdef TARGET_ANDROID
+        msg(M_FATAL, "--mode server not supported on Android");
+#endif
         if (!(dev == DEV_TYPE_TUN || dev == DEV_TYPE_TAP))
         {
             msg(M_USAGE, "--mode server only works with --dev tun or --dev tap");
Signature · 1 line
2.26.0
Acked-by on v1 1/1
#9 lore raw

Re: [Openvpn-devel] [PATCH] Refuse server mode on Android

Quoted 14 lines · Arne Schwabe

After the commit 042429d3 "build: Remove --disable-server from ./configure" Android needs another way to ensure that OpenVPN is not run in server mode.

---
 src/openvpn/options.c | 3 +++
 1 file changed, 3 insertions(+)
src/openvpn/options.c +0 -0
index 2da8cf6d..bfba62ad 100644

src/openvpn/options.c options_postprocess_verify_ce(const struct options *options, const struct connec · line 2262

Quoted 9 lines
src/openvpn/options.c +3 -0
@@ -2254,6 +2254,9 @@ options_postprocess_verify_ce(const struct options *options, const struct connec
      */
     if (options->mode == MODE_SERVER)
     {
+#ifdef TARGET_ANDROID
+        msg(M_FATAL, "--mode server not supported on Android");
+#endif
         if (!(dev == DEV_TYPE_TUN || dev == DEV_TYPE_TAP))
         {
             msg(M_USAGE, "--mode server only works with --dev tun or --dev tap");

Not tested this, but this change is pretty clear and explicit. I also can't imagine now a better way to tackle this, even though I'm not too happy about adding more #ifdef.

If someone really needs TARGET_ANDROID with server support, lets wait for them to appear so we can clearly define the use-case and design a better solution for a known scenario.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#10 lore raw

[Openvpn-devel] [PATCH applied] Re: Refuse server mode on Android

In reply to Arne Schwabe

Your patch has been applied to the master branch.

(I would have ACKed this, but David was faster... "#ifdef ANDROID, if not excessive, is mostly Arne's decision anyway")

commit cc76e177606ba336bbcb63ebc5e4d85b4116057f

Author: Arne Schwabe
Date:   Mon May 18 17:54:27 2020 +0200
     Refuse server mode on Android

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

--
kind regards,

Gert Doering