From: "cron2 (Code Review)" Date: Thu, 26 Mar 2026 16:49:56 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <96aeaedb118e796af4eb455e85ca4226125957af-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="dEb+ve/0oE0="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: auth_token: Clean up type handling in verify_auth_token and its UT List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld , plaisthos Cc: openvpn-devel --dEb+ve/0oE0= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#9) to the change originally created by= flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1510?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by plaisthos Change subject: auth_token: Clean up type handling in verify_auth_token and= its UT ...................................................................... auth_token: Clean up type handling in verify_auth_token and its UT First of all remove the testing of renegotiation_seconds. Commit 9a5161704173e31f2510d3f5c29361f76e275d0f made it irrelevant for verify_auth_token but still left UTs for it. But AFAICT these UTs only test that renegotiation_seconds is bigger than auth_token_renewal, so it tests the UT setup routine... Also improve the code to require less casts under -Wsign-compare. Add a comment that this code is not y38 safe if time_t is 32bit. Probably nothing we want to do from our side since in that case everything that uses "now" is borked. So we trust in the OS here... Change-Id: I73dba29719ea685f0427a3c479e7f1f176f09eba Signed-off-by: Frank Lichtenheld Acked-by: Arne Schwabe Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1510 Message-Id: <20260312173144.15602-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg36= 079.html Signed-off-by: Gert Doering --- M src/openvpn/auth_token.c M tests/unit_tests/openvpn/test_auth_token.c 2 files changed, 22 insertions(+), 38 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/10/1510/9 diff --git a/src/openvpn/auth_token.c b/src/openvpn/auth_token.c index eb2b4d5..d8ca125 100644 --- a/src/openvpn/auth_token.c +++ b/src/openvpn/auth_token.c @@ -287,11 +287,6 @@ return memcmp_constant_time(&hmac_output, hmac, 32) =3D=3D 0; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wsign-compare" -#endif - unsigned int verify_auth_token(struct user_pass *up, struct tls_multi *multi, struct tl= s_session *session) { @@ -318,7 +313,7 @@ const uint8_t *sessid =3D b64decoded; const uint8_t *tstamp_initial =3D sessid + AUTH_TOKEN_SESSION_ID_LEN; - const uint8_t *tstamp =3D tstamp_initial + sizeof(int64_t); + const uint8_t *tstamp =3D tstamp_initial + sizeof(uint64_t); /* tstamp, tstamp_initial might not be aligned to an uint64, use memcpy * to avoid unaligned access */ @@ -348,9 +343,11 @@ } /* Accept session tokens only if their timestamp is in the acceptable = range - * for renegotiations */ - bool in_renegotiation_time =3D - now >=3D timestamp && now < timestamp + 2 * session->opt->auth_tok= en_renewal; + * for renegotiations. + * Cast is required for systems with 32bit time_t, e.g. Windows x86. + */ + const time_t token_reneg_deadline =3D (time_t)timestamp + 2 * session-= >opt->auth_token_renewal; + bool in_renegotiation_time =3D now >=3D (time_t)timestamp && now < tok= en_reneg_deadline; if (!in_renegotiation_time) { @@ -369,7 +366,8 @@ ret |=3D AUTH_TOKEN_EXPIRED; } - if (multi->opt.auth_token_lifetime && now > timestamp_initial + multi-= >opt.auth_token_lifetime) + const time_t token_eol =3D (time_t)timestamp_initial + multi->opt.auth= _token_lifetime; + if (multi->opt.auth_token_lifetime && now > token_eol) { ret |=3D AUTH_TOKEN_EXPIRED; } @@ -396,10 +394,6 @@ return ret; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - void wipe_auth_token(struct tls_multi *multi) { diff --git a/tests/unit_tests/openvpn/test_auth_token.c b/tests/unit_tests/= openvpn/test_auth_token.c index d28bd8a..c7ba5fd 100644 --- a/tests/unit_tests/openvpn/test_auth_token.c +++ b/tests/unit_tests/openvpn/test_auth_token.c @@ -166,20 +166,19 @@ assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), AUTH_TOKEN_HMAC_OK); } -/* Note: only on 32bit Windows builds */ -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wsign-compare" -#endif - static void auth_token_test_timeout(void **state) { struct test_context *ctx =3D (struct test_context *)*state; - now =3D 100000; + const time_t initial_time =3D 100000; + now =3D initial_time; generate_auth_token(&ctx->up, &ctx->multi); + const time_t token_renew_window =3D + initial_time + 2 * ctx->session->opt->auth_token_renewal; + const time_t token_eol =3D initial_time + ctx->session->opt->auth_toke= n_lifetime + 1; + strcpy(ctx->up.password, ctx->multi.auth_token); free(ctx->multi.auth_token_initial); ctx->multi.auth_token_initial =3D NULL; @@ -188,26 +187,21 @@ assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), AUTH_TOKEN_HMAC_OK); /* Token before validity, should be rejected */ - now =3D 100000 - 100; + now =3D initial_time - 100; assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXPIRED); - /* Token no valid for renegotiate_seconds but still for renewal_time */ - now =3D 100000 + 2 * ctx->session->opt->renegotiate_seconds - 20; - assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), - AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXPIRED); - - - now =3D 100000 + 2 * ctx->session->opt->auth_token_renewal - 20; + /* Token still valid for renewal_time */ + now =3D token_renew_window - 20; assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), AUTH_TOKEN_HMAC_OK); =20 /* Token past validity, should be rejected */ - now =3D 100000 + 2 * ctx->session->opt->renegotiate_seconds + 20; + now =3D token_renew_window + 20; assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXPIRED); - /* But not when we reached our timeout */ - now =3D 100000 + ctx->session->opt->auth_token_lifetime + 1; + /* Token past lifetime, should be rejected */ + now =3D token_eol; assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXPIRED); @@ -215,8 +209,8 @@ ctx->multi.auth_token_initial =3D NULL; /* regenerate the token util it hits the expiry */ - now =3D 100000; - while (now < 100000 + ctx->session->opt->auth_token_lifetime + 1) + now =3D initial_time; + while (now < token_eol) { assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->ses= sion), AUTH_TOKEN_HMAC_OK); @@ -234,10 +228,6 @@ assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->session= ), AUTH_TOKEN_HMAC_OK); } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - static void zerohmac(char *token) { -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1510?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I73dba29719ea685f0427a3c479e7f1f176f09eba Gerrit-Change-Number: 1510 Gerrit-PatchSet: 9 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel --dEb+ve/0oE0= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 upl= oaded patch set #9 to the change originally created by flichtenhel= d.

View Change

The following approvals got outdated and were remove= d: Code-Review+2 by plaisthos

auth_token: Clean up type handl=
ing in verify_auth_token and its UT

First of all remove the testing = of renegotiation_seconds.
Commit 9a5161704173e31f2510d3f5c29361f76e275d0= f made it
irrelevant for verify_auth_token but still left UTs for it.But AFAICT these UTs only test that renegotiation_seconds
is bigger tha= n auth_token_renewal, so it tests the UT
setup routine...

Also im= prove the code to require less casts under
-Wsign-compare.

Add a = comment that this code is not y38 safe if time_t
is 32bit. Probably noth= ing we want to do from our side
since in that case everything that uses = "now" is borked.
So we trust in the OS here...

Change-I= d: I73dba29719ea685f0427a3c479e7f1f176f09eba
Signed-off-by: Frank Lichte= nheld <frank@...2641...>
Acked-by: Arne Schwabe <arne-openvpn@...220...= ..1227...>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1510Message-Id: <20260312173144.15602-1-gert@...1296...>
URL: https:/= /www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg36079.html
= Signed-off-by: Gert Doering <gert@...1296...>
---
M src/openvpn= /auth_token.c
M tests/unit_tests/openvpn/test_auth_token.c
2 files ch= anged, 22 insertions(+), 38 deletions(-)

git pul=
l ssh://gerrit.openvpn.net:29418/openvpn refs/changes/10/1510/9
dif=
f --git a/src/openvpn/auth_token.c b/src/openvpn/auth_token.c
index eb2b4d5..d8ca125 100644
--- a/src/openvpn/auth_tok= en.c
+++ b/src/openvpn/auth_token.c
@@ -287= ,11 +287,6 @@
return memcmp_constant_time(&hmac_ou= tput, hmac, 32) =3D=3D 0;
}

-#if defined(__GNUC__) || defined(_= _clang__)
-#pragma GCC = diagnostic push
-#pragm= a GCC diagnostic ignored "-Wsign-compare"
-#endif
-
unsigned int
verify_aut= h_token(struct user_pass *up, struct tls_multi *multi, struct tls_session *= session)
{
@@ -318,7 +313,7 @@
<= span>
const uint8_t *sessid =3D b64decoded; const uint8_t *tstamp_initial =3D sessid + AUTH_TOKEN_SESSION_I= D_LEN;
- const uint8= _t *tstamp =3D tstamp_initial + sizeof(int64_t);
+ const uint8_t *tstamp =3D tstamp_initial += sizeof(uint64_t);

/* tstamp, tstamp= _initial might not be aligned to an uint64, use memcpy
= * to avoid unaligned access */
@@ -348,9 +343,11 @@
}

/* Accept session = tokens only if their timestamp is in the acceptable range
- * for renegotiations */
= - bool in_renegotiation_time = =3D
- now >= =3D timestamp && now < timestamp + 2 * session->opt->auth_= token_renewal;
+ = * for renegotiations.
+ * Cast is required for systems with 32bit time_t, e.g. Windows x86.<= /span>
+ */
+ const time_t token_reneg_dea= dline =3D (time_t)timestamp + 2 * session->opt->auth_token_renewal;
+ bool in_renegotia= tion_time =3D now >=3D (time_t)timestamp && now < token_reneg= _deadline;

if (!in_renegotiation_tim= e)
{
@@ -369,7 +366,8 @@
ret |=3D AUTH_TOKEN_EXPIRED;

}
<= span>

- if (multi-&= gt;opt.auth_token_lifetime && now > timestamp_initial + multi-&g= t;opt.auth_token_lifetime)
+ const time_t token_eol =3D (time_t)timestamp_initial + multi->= ;opt.auth_token_lifetime;
+ if (multi->opt.auth_token_lifetime && now > token_e= ol)
{
ret |=3D AUTH_TOKEN_EXP= IRED;
}
@@ -396,10 +394,6 @@ return ret;
}

-#if defined(__GNUC__) || defined(__c= lang__)
-#pragma GCC di= agnostic pop
-#endif

-
void
wipe_auth_token(struct tls_multi *multi)
{=
diff --git a/tests/unit_tests/openvpn/test_auth_token.c b/= tests/unit_tests/openvpn/test_auth_token.c
index d28bd8a..c= 7ba5fd 100644
--- a/tests/unit_tests/openvpn/test_auth_toke= n.c
+++ b/tests/unit_tests/openvpn/test_auth_token.c=
@@ -166,20 +166,19 @@
assert_int_equal(verif= y_auth_token(&ctx->up, &ctx->multi, ctx->session), AUTH_TO= KEN_HMAC_OK);
}

-/* Note: only on 32bit Windows builds */
-#if defined(__GNUC__) || de= fined(__clang__)
-#prag= ma GCC diagnostic push
= -#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
static void
auth_t= oken_test_timeout(void **state)
{
str= uct test_context *ctx =3D (struct test_context *)*state;
<= /span>
- now =3D 100000;
+ const time_t initi= al_time =3D 100000;
+= now =3D initial_time;
generate_auth_token(&ctx= ->up, &ctx->multi);

+ const time_t token_renew_window =3D<= br>+ initial_time + 2 * = ctx->session->opt->auth_token_renewal;
+ const time_t token_eol =3D initial_time + c= tx->session->opt->auth_token_lifetime + 1;
+
strcpy(ctx->up.p= assword, ctx->multi.auth_token);
free(ctx->multi= .auth_token_initial);
ctx->multi.auth_token_initial= =3D NULL;
@@ -188,26 +187,21 @@
asser= t_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->= session), AUTH_TOKEN_HMAC_OK);

/* To= ken before validity, should be rejected */
- now =3D 100000 - 100;
+ now =3D initial_time - 100;
= assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi= , ctx->session),
AUTH_TOKEN_HMAC_O= K | AUTH_TOKEN_EXPIRED);

- /* Token no valid for renegotiate_seconds but stil= l for renewal_time */
-= now =3D 100000 + 2 * ctx->session->opt->renegotiate_seconds - = 20;
- assert_int_equ= al(verify_auth_token(&ctx->up, &ctx->multi, ctx->session),=
- = AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXPIRED);
-
-<= /span>
- now =3D 100000 + 2= * ctx->session->opt->auth_token_renewal - 20;
+ /* Token still valid for renewal_ti= me */
+ now =3D to= ken_renew_window - 20;
assert_int_equal(verify_auth_to= ken(&ctx->up, &ctx->multi, ctx->session), AUTH_TOKEN_HMAC_= OK);

/* Token past validity, should = be rejected */
- now= =3D 100000 + 2 * ctx->session->opt->renegotiate_seconds + 20;

+ now =3D token_renew= _window + 20;
assert_int_equal(verify_auth_token(&= ctx->up, &ctx->multi, ctx->session),
= AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXPIRED);

- /* But not when we r= eached our timeout */
-= now =3D 100000 + ctx->session->opt->auth_token_lifetime + 1;
+ /* Token past lif= etime, should be rejected */
+ now =3D token_eol;
assert_int_equal(verif= y_auth_token(&ctx->up, &ctx->multi, ctx->session),<= br> AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXPIRED);

@@ -215,8 +209,8 @@
ct= x->multi.auth_token_initial =3D NULL;

= /* regenerate the token util it hits the expiry */
- now =3D 100000;
- while (now < 100000 + ctx->sessio= n->opt->auth_token_lifetime + 1)
+ now =3D initial_time;
+ while (now < token_eol)
= {
assert_int_equal(verify_auth_token(&ctx-&g= t;up, &ctx->multi, ctx->session),
= AUTH_TOKEN_HMAC_OK);
@@ -234,10 +228,6 @@=
assert_int_equal(verify_auth_token(&ctx->up, &ctx= ->multi, ctx->session), AUTH_TOKEN_HMAC_OK);
}

-#if defin= ed(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
change 1510= . To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I73dba29719ea685f0427a3c479e= 7f1f176f09eba
Gerrit-Change-Number: 1510
Gerrit-PatchSet: 9
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --dEb+ve/0oE0=--