[Openvpn-devel,v2] auth_token: Wipe the server secret key after loading it

Message ID 20261102090635.24906-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v2] auth_token: Wipe the server secret key after loading it |

Commit Message

Gert Doering Nov. 2, 2026, 9:06 a.m. UTC
  From: Hansaem Wi <hansaemw@gmail.com>

auth_token_init_secret() reads the auth-token server key into a 2048
byte buffer, copies it into a struct key on the stack, converts that
into a struct key_parameters on the stack and frees the buffer with
free_buf(), so all three copies of the key stay in memory.
tls_crypt_v2_init_server_key() already wipes its struct key after
init_key_ctx(); do the same here for the struct key and the struct
key_parameters, and clear the buffer before freeing it.

Found by scanning freed heap blocks for the key from test_auth_token.

Assisted-by: Claude Code:claude-opus-5-5
Change-Id: Ib5eb24b156acb5a99c614050fb1bd64fe46d8b52
Signed-off-by: Hansaem Wi <hansaemw@gmail.com>
Acked-by: Steffan Karger <steffan@karger.me>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2076
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2076
This mail reflects revision 2 of this Change.

Acked-by according to Gerrit (reflected above):
Steffan Karger <steffan@karger.me>
  

Patch

diff --git a/src/openvpn/auth_token.c b/src/openvpn/auth_token.c
index 969f37f..84558af 100644
--- a/src/openvpn/auth_token.c
+++ b/src/openvpn/auth_token.c
@@ -172,6 +172,9 @@ 
     key_parameters_from_key(&key_params, &key);
     init_key_ctx(key_ctx, &key_params, &kt, false, "auth-token secret");
 
+    secure_memzero(&key, sizeof(key));
+    secure_memzero(&key_params, sizeof(key_params));
+    buf_clear(&server_secret_key);
     free_buf(&server_secret_key);
 }