From: "flichtenheld (Code Review)" Date: Fri, 6 Feb 2026 12:02:53 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: <0bbef77c5bce85dabceff60224461208ee720672-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="Lz/fbVcnvLk="; 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: plaisthos Cc: openvpn-devel --Lz/fbVcnvLk= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: plaisthos. Hello plaisthos, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1510?usp=3Demail to review the following change. 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 --- 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/1 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 82c20c1..30d55f6 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); /* 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: newchange Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I73dba29719ea685f0427a3c479e7f1f176f09eba Gerrit-Change-Number: 1510 Gerrit-PatchSet: 1 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos --Lz/fbVcnvLk= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: plaisthos.

flichtenheld would like plaisthos to review this change.

V= iew Change

auth_token: Clean up type handling in verif=
y_auth_token and its UT

First of all remove the testing of renegotia= tion_seconds.
Commit 9a5161704173e31f2510d3f5c29361f76e275d0f made itirrelevant 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 co= de 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&qu= ot; is borked.
So we trust in the OS here...

Change-Id: I73dba297= 19ea685f0427a3c479e7f1f176f09eba
Signed-off-by: Frank Lichtenheld <fr= ank@...2641...>
---
M src/openvpn/auth_token.c
M tests/unit_tes= ts/openvpn/test_auth_token.c
2 files changed, 22 insertions(+), 38 delet= ions(-)

git pull ssh://gerrit.openvpn.net:29418/=
openvpn refs/changes/10/1510/1
diff --git a/src/openvpn/auth_token.=
c b/src/openvpn/auth_token.c
index eb2b4d5..d8ca125 100644<= /span>
--- a/src/openvpn/auth_token.c
+++ b/src/op= envpn/auth_token.c
@@ -287,11 +287,6 @@
= return memcmp_constant_time(&hmac_output, hmac, 32) =3D=3D 0;<= br> }

-#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, str= uct tls_multi *multi, struct tls_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 + s= izeof(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 */<= /span>
@@ -348,9 +343,11 @@
}

/* Accept session tokens only if their timestamp is= in the acceptable range
- bool in_renegotiation_time =3D
- now >=3D timestamp && now < ti= mestamp + 2 * session->opt->auth_token_renewal;
+ * for renegotiations.
+ * Cast is required for system= s with 32bit time_t, e.g. Windows x86.
+ */
+ const time_t token_reneg_deadline =3D (time_t)timestamp + 2 * se= ssion->opt->auth_token_renewal;
+ bool in_renegotiation_time =3D now >=3D (time_t)ti= mestamp && now < token_reneg_deadline;
<= br> if (!in_renegotiation_time)
{
= @@ -369,7 +366,8 @@
ret |=3D AUTH_TOKEN_EXPI= RED;
}

- 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_t= oken_lifetime && now > token_eol)
{<= br> 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(st= ruct tls_multi *multi)
{
diff --git a/test= s/unit_tests/openvpn/test_auth_token.c b/tests/unit_tests/openvpn/test_auth= _token.c
index 82c20c1..30d55f6 100644
--- = a/tests/unit_tests/openvpn/test_auth_token.c
+++ b/tests/un= it_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);
}

-/* No= te: only on 32bit Windows builds */
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
<= span style=3D"color: hsl(0, 100%, 40%);">-#pragma GCC diagnostic ignored &q= uot;-Wsign-compare"

-
<= span> 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);


+ co= nst time_t token_renew_window =3D
+ initial_time + 2 * ctx->session->opt->auth_t= oken_renewal;
+ co= nst time_t token_eol =3D initial_time + ctx->session->opt->auth_to= ken_lifetime + 1;
+
strcpy(ctx->up.password, ctx->multi.auth_token);<= /span>
free(ctx->multi.auth_token_initial);
ctx->multi.auth_token_initial =3D NULL;

@@ -188,2= 6 +187,21 @@
assert_int_equal(verify_auth_token(&c= tx->up, &ctx->multi, ctx->session), AUTH_TOKEN_HMAC_OK);

/* Token before validity, should be rejec= ted */
- now =3D 100= 000 - 100;
+ now = =3D initial_time - 100;
assert_int_equal(verify_auth_t= oken(&ctx->up, &ctx->multi, ctx->session),
AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXPIRED);

=
- /* Token n= o valid for renegotiate_seconds but still for renewal_time */
- now =3D 100000 + 2 * ctx->se= ssion->opt->renegotiate_seconds - 20;

- assert_int_equal(verify_auth_token(&ctx->u= p, &ctx->multi, ctx->session),
- AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXP= IRED);
-
-
- 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->m= ulti, ctx->session), AUTH_TOKEN_HMAC_OK);

/* Token past validity, should be rejected */
- now =3D 100000 + 2 * ctx->session-&= gt;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 | A= UTH_TOKEN_EXPIRED);

- /* But not when we reached our timeout */
- now =3D 100000 + ctx->sessio= n->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 i= t hits the expiry */
- = now =3D 100000;
- = while (now < 100000 + ctx->session->opt->auth_token_lifetime += 1)
+ now =3D init= ial_time;
+ while = (now < token_eol)
{
assert= _int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->s= ession),
AUTH_TOKEN_HMAC_OK);
@@ -234,10 +228,6 @@
assert_int_equal(ver= ify_auth_token(&ctx->up, &ctx->multi, ctx->session), AUTH_= TOKEN_HMAC_OK);
}

-#if defined(__GNUC__) || defined(__clang__)=
-#pragma GCC diagnosti= c pop
-#endif-
static void
zerohmac(char *token)
{

To view, visit change 1510. To unsubscribe, or for help writi= ng mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I73dba29719ea685f0427a3c479e= 7f1f176f09eba
Gerrit-Change-Number: 1510
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
= --Lz/fbVcnvLk=--