Skip to contentSkip to conversation

Ensure the current common_name is in the environment for scripts

PATCH In review [email protected]... 2 participants 4 messages Oct 23, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Ensure the current common_name is in the environment for scripts

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

When username-as-common-name is in effect, the common_name is "CN" from the certificate for auth-user-pass-verify. It gets changed to "username" after successful authentication. This changed value gets into the env when client-connect script is called.

However, "common_name" goes through the cycle of being "CN", then "username" during every reauth (renegotiation). As the client-connect script is not called during reneg, the changed value never gets back into the env. The end result is that the disconnect script gets "common_name=<CN>" instead of the username. Unless no reneg steps have happened before disconnect. (For a more detailed analysis see
https://community.openvpn.net/openvpn/ticket/1434#comment:12)

Fix by adding common_name to env whenever it changes.

Trac: #1434
Very likely applies to #160 as well, but that's too old and some of the relevant code path has evolved since then.

---
 src/openvpn/ssl_verify.c | 2 ++
 1 file changed, 2 insertions(+)
src/openvpn/ssl_verify.c +2 -0
index b745b3c7..8dbbf5f5 100644
@@ -101,6 +101,8 @@ set_common_name(struct tls_session *session, const char *common_name)
         /* FIXME: Last alloc will never be freed */
         session->common_name = string_alloc(common_name, NULL);
     }
+    /* update common name in env */
+    setenv_str(session->opt->es, "common_name", common_name);
 }
 
 /*
Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/1 Ensure the current common_name is in the environment for scripts

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

When username-as-common-name is in effect, the common_name is "CN" from the certificate for auth-user-pass-verify. It gets changed to "username" after successful authentication. This changed value gets into the env when client-connect script is called.

However, "common_name" goes through the cycle of being "CN", then "username" during every reauth (renegotiation). As the client-connect script is not called during reneg, the changed value never gets back into the env. The end result is that the disconnect script gets "common_name=<CN>" instead of the username. Unless no reneg steps have happened before disconnect. (For a more detailed analysis see
https://community.openvpn.net/openvpn/ticket/1434#comment:12)

Fix by adding common_name to env whenever it changes.

Trac: #1434
Very likely applies to #160 as well, but that's too old and some of the relevant code path has evolved since then.

Same as for 2.6 except for the context change due to PF.

---
 src/openvpn/ssl_verify.c | 2 ++
 1 file changed, 2 insertions(+)
src/openvpn/ssl_verify.c +2 -0
index 4f3b61d6..0ccd43d0 100644
@@ -116,6 +116,8 @@ set_common_name(struct tls_session *session, const char *common_name)
         }
 #endif
     }
+    /* update common name in env */
+    setenv_str(session->opt->es, "common_name", common_name);
 }
 
 /*
Signature · 1 line
2.30.2
Acked-by on v1 1/1
#2 lore raw

Thanks, again :-)

Your patch has been applied to the release/2.5 and release/2.4 branches.

commit a2412bf4a6bb6ac7a6f26128d00fe81b0fa4a18e (release/2.5) commit 644bcb87e76f0c56ec5b6cb205771a00fc28e598 (release/2.4)

Author: Selva Nair
Date:   Fri Oct 22 20:07:06 2021 -0400
     Ensure the current common_name is in the environment for scripts

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

--
kind regards,

Gert Doering

Acked-by on v1 1/1
#3 lore raw
In reply to [email protected]...

Thanks for finding a better theory how to fix this :-) - and then finding the single-line "so obvious" place to fix this, without caring about all our convolutions in changing common_name.

(And thanks to Richard for getting so upset with this bug that he found nice and reliable ways to test bug and fix)

Your patch has been applied to the master branch.

commit fa5ab2438ad2d8a12eaf43e2cdd8b4294299c175

Author: Selva Nair
Date:   Fri Oct 22 20:07:05 2021 -0400
     Ensure the current common_name is in the environment for scripts

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

--
kind regards,

Gert Doering