From: "cron2 (Code Review)" Date: Thu, 26 Mar 2026 16:49:57 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <96aeaedb118e796af4eb455e85ca4226125957af-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="ob8A+Fae02A="; 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 Cc: plaisthos , openvpn-devel --ob8A+Fae02A= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/15= 10?usp=3Demail ) 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(-) 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); /* 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: merged 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 --ob8A+Fae02A= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 sub= mitted this change.

View Change

auth_token: Clean up type handling in verify_aut=
h_token and its UT

First of all remove the testing of renegotiation_= seconds.
Commit 9a5161704173e31f2510d3f5c29361f76e275d0f made it
irre= levant for verify_auth_token but still left UTs for it.
But AFAICT these= UTs only test that renegotiation_seconds
is bigger than auth_token_rene= wal, 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" i= s borked.
So we trust in the OS here...

Change-Id: I73dba29719ea6= 85f0427a3c479e7f1f176f09eba
Signed-off-by: Frank Lichtenheld <frank@...220...= ..2641...>
Acked-by: Arne Schwabe <arne-openvpn@...1227...>
= 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/msg36079.html
Signed-off-by: Ge= rt Doering <gert@...1296...>
---
M src/openvpn/auth_token.c
= M tests/unit_tests/openvpn/test_auth_token.c
2 files changed, 22 inserti= ons(+), 38 deletions(-)

diff --git a/src/openvpn/auth_token.c b/src/openvpn/auth_token.c<=
br>index eb2b4d5..d8ca125 100644
--- a/src/openvpn/au= th_token.c
+++ b/src/openvpn/auth_token.c
@= @ -287,11 +287,6 @@
return memcmp_constant_time(&h= mac_output, hmac, 32) =3D=3D 0;
}
=
-#if defined(__GNUC__) || def= ined(__clang__)
-#pragm= a GCC diagnostic push
-= #pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
unsigned int
verify= _auth_token(struct user_pass *up, struct tls_multi *multi, struct tls_sessi= on *session)
{
@@ -318,7 +313,7 @@<= br>
const uint8_t *sessid =3D b64decoded;
const uint8_t *tstamp_initial =3D sessid + AUTH_TOKEN_SESSI= ON_ID_LEN;
- const u= int8_t *tstamp =3D tstamp_initial + sizeof(int64_t);
+ const uint8_t *tstamp =3D tstamp_init= ial + sizeof(uint64_t);

/* tstamp, t= stamp_initial might not be aligned to an uint64, use memcpy
* to avoid unaligned access */

@@ -348,9 +343,11 @@<= /span>
}

/* Accept ses= sion tokens only if their timestamp is in the acceptable range
- * for renegotiations */
- bool in_renegotiation_t= ime =3D
- now &g= t;=3D timestamp && now < timestamp + 2 * session->opt->aut= h_token_renewal;
+ = * for renegotiations.
+ * Cast is required for systems with 32bit time_t, e.g. Windows x86= .
+ */
= + const time_t token_reneg_d= eadline =3D (time_t)timestamp + 2 * session->opt->auth_token_renewal;=
+ bool in_renegot= iation_time =3D now >=3D (time_t)timestamp && now < token_ren= eg_deadline;

if (!in_renegotiation_t= ime)
{
@@ -369,7 +366,8 @@
<= span> 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-&= gt;opt.auth_token_lifetime;
+ if (multi->opt.auth_token_lifetime && now > token= _eol)
{
ret |=3D AUTH_TOKEN_E= XPIRED;
}
@@ -396,10 +394,6 @@<= br> return ret;
}

-#if defined(__GNUC__) || defined(_= _clang__)
-#pragma GCC = diagnostic pop
-#endif<= /span>
-
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_to= ken.c
+++ b/tests/unit_tests/openvpn/test_auth_token.c
@@ -166,20 +166,19 @@
assert_int_equal(ver= ify_auth_token(&ctx->up, &ctx->multi, ctx->session), AUTH_= TOKEN_HMAC_OK);
}

-/* Note: only on 32bit Windows builds */

-#if defined(__GNUC__) ||= defined(__clang__)
-#p= ragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
static void
aut= h_token_test_timeout(void **state)
{
= struct test_context *ctx =3D (struct test_context *)*state;

- now =3D 100000;=
+ const time_t in= itial_time =3D 100000;
+ 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_token_lifetime + 1;
+
strcpy(ctx->up.= password, ctx->multi.auth_token);
free(ctx->mult= i.auth_token_initial);
ctx->multi.auth_token_initia= l =3D NULL;
@@ -188,26 +187,21 @@
asse= rt_int_equal(verify_auth_token(&ctx->up, &ctx->multi, ctx->= ;session), AUTH_TOKEN_HMAC_OK);

/* T= oken before validity, should be rejected */
- now =3D 100000 - 100;
+ now =3D initial_time - 100;
assert_int_equal(verify_auth_token(&ctx->up, &ctx->mult= i, ctx->session),

AUTH_TOKEN_HMAC_= OK | AUTH_TOKEN_EXPIRED);

- /* Token no valid for renegotiate_seconds but sti= ll for renewal_time */
= - now =3D 100000 + 2 * ctx->session->opt->renegotiate_seconds -= 20;
- assert_int_eq= ual(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_t= ime */
+ now =3D t= oken_renew_window - 20;
assert_int_equal(verify_auth_t= oken(&ctx->up, &ctx->multi, ctx->session), AUTH_TOKEN_HMAC= _OK);

/* Token past validity, should= be rejected */
- no= w =3D 100000 + 2 * ctx->session->opt->renegotiate_seconds + 20;
+ now =3D token_rene= w_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;<= /span>
+ /* Token past li= fetime, should be rejected */
+ now =3D token_eol;
assert_int_equal(veri= fy_auth_token(&ctx->up, &ctx->multi, ctx->session),=
AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXPIRED);

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

/* regenerate the token util it hits the expiry */

- now =3D 100000;
- while (now < 100000 + ctx->sessi= on->opt->auth_token_lifetime + 1)
+ now =3D initial_time;
+ while (now < token_eol)
= {
assert_int_equal(verify_auth_token(&ctx-&= gt;up, &ctx->multi, ctx->session),
= AUTH_TOKEN_HMAC_OK);
@@ -234,10 +228,6 @@

assert_int_equal(verify_auth_token(&ctx->up, &ct= x->multi, ctx->session), AUTH_TOKEN_HMAC_OK);
}

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

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

Gerrit-MessageType: merged
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>
= --ob8A+Fae02A=--