From: "flichtenheld (Code Review)"
Date: Mon, 16 Mar 2026 11:56:47 +0000
In-Reply-To:
References:
Reply-To: frank@...2641..., arne-openvpn@...1227...,
openvpn-devel@lists.sourceforge.net
Message-ID: <6617527354c1e7fb143e697a7ff4b364263cae14-EmailReplacePatchSet-HTML@...2715...>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Content-Type: multipart/alternative; boundary="ZVHDveLkgFk="; 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
--ZVHDveLkgFk=
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is currently required from: flichtenheld.
Hello plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1510?usp=3Demail
to look at the new patch set (#7).
The change is no longer submittable: checks~ChecksSubmitRule is unsatisfied=
now.
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/7
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: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I73dba29719ea685f0427a3c479e7f1f176f09eba
Gerrit-Change-Number: 1510
Gerrit-PatchSet: 7
Gerrit-Owner: flichtenheld
Gerrit-Reviewer: plaisthos
Gerrit-CC: openvpn-devel
Gerrit-Attention: flichtenheld
--ZVHDveLkgFk=
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is cur=
rently required from: flichtenheld.
flichtenheld uploaded patch set #7 to this change.
<=
p>View C=
hange
The change is no longer submittable: checks~ChecksSubmitRul=
e is unsatisfied now.
auth_token: Clean up type handling i=
n verify_auth_token and its UT
First of all remove the testing of re=
negotiation_seconds.
Commit 9a5161704173e31f2510d3f5c29361f76e275d0f mad=
e it
irrelevant for verify_auth_token but still left UTs for it.
But =
AFAICT these UTs only test that renegotiation_seconds
is bigger than aut=
h_token_renewal, so it tests the UT
setup routine...
Also improve=
the code to require less casts under
-Wsign-compare.
Add a comme=
nt that this code is not y38 safe if time_t
is 32bit. Probably nothing w=
e 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: I7=
3dba29719ea685f0427a3c479e7f1f176f09eba
Signed-off-by: Frank Lichtenheld=
<frank@...2641...>
---
M src/openvpn/auth_token.c
M tests/u=
nit_tests/openvpn/test_auth_token.c
2 files changed, 22 insertions(+), 3=
8 deletions(-)
git pull ssh://gerrit.openvpn.net=
:29418/openvpn refs/changes/10/1510/7
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;<=
/span>
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
=
-#pragma GCC diagnostic ignored &=
quot;-Wsign-compare"
-#endif
-
=
unsigned int
verify_auth_token(struct user_pass *up=
, struct tls_multi *multi, struct tls_session *session)
{<=
/span>
@@ -318,7 +313,7 @@
=
const uint8_t *sessid =3D b64decoded;
const uint8_t *t=
stamp_initial =3D sessid + AUTH_TOKEN_SESSION_ID_LEN;
- const uint8_t *tstamp =3D tstamp_initia=
l + sizeof(int64_t);
=
+ const uint8_t *tstamp =3D tstamp_initial + sizeof(uint64_t);
/* tstamp, tstamp_initial might not be aligne=
d to an uint64, use memcpy
* to avoid unaligned acces=
s */
@@ -348,9 +343,11 @@
}
=
/* Accept session tokens only if their timesta=
mp is in the acceptable range
- * for renegotiations */
- bool in_renegotiation_time =3D
- now >=3D timestamp && now &l=
t; timestamp + 2 * session->opt->auth_token_renewal;
+ * for renegotiations.
+ * Cast is required for s=
ystems 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 < token_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_e=
ol =3D (time_t)timestamp_initial + multi->opt.auth_token_lifetime;
+ if (multi->opt.aut=
h_token_lifetime && now > token_eol)
{
ret |=3D AUTH_TOKEN_EXPIRED;
}
@@ -396,10 +394,6 @@
return ret;<=
br> }
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
void
wipe_auth_tok=
en(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/tes=
ts/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 ignor=
ed "-Wsign-compare"
-#endif
-=
static void
auth_token_test_timeout(void **stat=
e)
{
struct test_context *ctx =3D (st=
ruct 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->a=
uth_token_renewal;
+ =
const time_t token_eol =3D initial_time + ctx->session->opt->au=
th_token_lifetime + 1;
+
strcpy(ctx->up.password, ctx->multi.auth_tok=
en);
free(ctx->multi.auth_token_initial);
ctx->multi.auth_token_initial =3D NULL;
@@ -=
188,26 +187,21 @@
assert_int_equal(verify_auth_token(&=
amp;ctx->up, &ctx->multi, ctx->session), AUTH_TOKEN_HMAC_OK);<=
/span>
/* 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);
- /* T=
oken no valid for renegotiate_seconds but still for renewal_time */<=
br>- 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_TOK=
EN_EXPIRED);
--
- now =3D 100000 + 2 * ctx->session->opt-&g=
t;auth_token_renewal - 20;
+ /* Token still valid for renewal_time */
+ now =3D token_renew_window - 20;
assert_int_equal(verify_auth_token(&ctx->up, &c=
tx->multi, ctx->session), AUTH_TOKEN_HMAC_OK);
/* Token past validity, should be rejected */
- now =3D 100000 + 2 * ctx->s=
ession->opt->renegotiate_seconds + 20;
+ now =3D token_renew_window + 20;
assert_int_equal(verify_auth_token(&ctx->up, &ctx->mu=
lti, ctx->session),
AUTH_TOKEN_HMA=
C_OK | AUTH_TOKEN_EXPIRED);
- /* But not when we reached our timeout */
- now =3D 100000 + ctx-&g=
t;session->opt->auth_token_lifetime + 1;
+ /* Token past lifetime, should be rejected *=
/
+ now =3D token_=
eol;
assert_int_equal(verify_auth_token(&ctx->u=
p, &ctx->multi, ctx->session),
=
AUTH_TOKEN_HMAC_OK | AUTH_TOKEN_EXPIRED);
<=
span>@@ -215,8 +209,8 @@
ctx->multi.auth_token_init=
ial =3D NULL;
/* regenerate the toke=
n util it hits the expiry */
- now =3D 100000;
- while (now < 100000 + ctx->session->opt->auth_token_li=
fetime + 1)
+ now =
=3D initial_time;
+ =
while (now < token_eol)
{
=
assert_int_equal(verify_auth_token(&ctx->up, &ctx->multi, c=
tx->session),
AUTH_TOKEN_HMAC_=
OK);
@@ -234,10 +228,6 @@
assert_int_e=
qual(verify_auth_token(&ctx->up, &ctx->multi, ctx->session=
), AUTH_TOKEN_HMAC_OK);
}
-#if defined(__GNUC__) || defined(__c=
lang__)
-#pragma GCC di=
agnostic pop
-#endif
-
static=
void
zerohmac(char *token)
{
<=
span>
To view, visit change 1510. To unsubscribe, or for hel=
p 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: 7
Gerrit-Owner: flichtenheld <frank@...2723...=
.>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...=
.1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...=
ts.sourceforge.net>
Gerrit-Attention: flichtenheld <frank@...2375...=
41...>
=
--ZVHDveLkgFk=--