mirror of
https://github.com/OpenVPN/openvpn.git
synced 2024-09-19 19:42:30 +02:00
generate_auth_token: simplify code
The previous code went through some hoops to avoid compiler warnings. But there is a much easier way by just telling it exactly what you want to do. Also fix typo in variable name while I'm here. Change-Id: Icc86334b26ba1fcc20f4cd03644018d1d16796e3 Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com> Acked-by: Arne Schwabe <arne-openvpn@rfc2549.org> Message-Id: <20240910170005.5586-1-gert@greenie.muc.de> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg29178.html Signed-off-by: Gert Doering <gert@greenie.muc.de>
This commit is contained in:
parent
53449cb61f
commit
3c77d32891
@ -182,24 +182,18 @@ generate_auth_token(const struct user_pass *up, struct tls_multi *multi)
|
|||||||
char *initial_token_copy = string_alloc(multi->auth_token_initial, &gc);
|
char *initial_token_copy = string_alloc(multi->auth_token_initial, &gc);
|
||||||
|
|
||||||
char *old_sessid = initial_token_copy + strlen(SESSION_ID_PREFIX);
|
char *old_sessid = initial_token_copy + strlen(SESSION_ID_PREFIX);
|
||||||
char *old_tsamp_initial = old_sessid + AUTH_TOKEN_SESSION_ID_LEN*8/6;
|
char *old_tstamp_initial = old_sessid + AUTH_TOKEN_SESSION_ID_LEN*8/6;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We null terminate the old token just after the session ID to let
|
* We null terminate the old token just after the session ID to let
|
||||||
* our base64 decode function only decode the session ID
|
* our base64 decode function only decode the session ID
|
||||||
*/
|
*/
|
||||||
old_tsamp_initial[12] = '\0';
|
old_tstamp_initial[12] = '\0';
|
||||||
ASSERT(openvpn_base64_decode(old_tsamp_initial, old_tstamp_decode, 9) == 9);
|
ASSERT(openvpn_base64_decode(old_tstamp_initial, old_tstamp_decode, 9) == 9);
|
||||||
|
|
||||||
/*
|
memcpy(&initial_timestamp, &old_tstamp_decode, sizeof(initial_timestamp));
|
||||||
* Avoid old gcc (4.8.x) complaining about strict aliasing
|
|
||||||
* by using a temporary variable instead of doing it in one
|
|
||||||
* line
|
|
||||||
*/
|
|
||||||
uint64_t *tstamp_ptr = (uint64_t *) old_tstamp_decode;
|
|
||||||
initial_timestamp = *tstamp_ptr;
|
|
||||||
|
|
||||||
old_tsamp_initial[0] = '\0';
|
old_tstamp_initial[0] = '\0';
|
||||||
ASSERT(openvpn_base64_decode(old_sessid, sessid, AUTH_TOKEN_SESSION_ID_LEN) == AUTH_TOKEN_SESSION_ID_LEN);
|
ASSERT(openvpn_base64_decode(old_sessid, sessid, AUTH_TOKEN_SESSION_ID_LEN) == AUTH_TOKEN_SESSION_ID_LEN);
|
||||||
}
|
}
|
||||||
else if (!rand_bytes(sessid, AUTH_TOKEN_SESSION_ID_LEN))
|
else if (!rand_bytes(sessid, AUTH_TOKEN_SESSION_ID_LEN))
|
||||||
|
Loading…
Reference in New Issue
Block a user