|
From: Kirthik A. <kir...@gm...> - 2026-11-24 07:47:05
|
When a UDP server using --explicit-exit-notify restarts (SIGUSR1/SIGHUP) or exits, it sends a bare RESTART to connected clients. OpenVPN 3 clients treat this as a request to discard their auth-token, so users relying on SSO have to authenticate again, even when the server can still validate their token using --auth-gen-token-secret. When --auth-gen-token is enabled, send RESTART,[P]: instead to ask clients to keep their auth-token across the restart. OpenVPN 3 only recognises this exact prefix. The next-server case ([N]) is left unchanged because OpenVPN 3 does not support it. If the token is no longer valid after the restart, the client receives AUTH_FAILED and falls back to normal authentication. GitHub: closes OpenVPN/openvpn#1099 Signed-off-by: Kirthik Aditya <kir...@gm...> --- Discussion: https://github.com/OpenVPN/openvpn/issues/1099 Branch: https://github.com/spryzz3n/openvpn/tree/restart-preserve-auth-token Tested with OpenVPN 2.x client on localhost; not yet with OpenVPN Connect. Changes.md | 8 ++++++++ doc/man-sections/client-options.rst | 6 ++++++ src/openvpn/multi.c | 15 +++++++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Changes.md b/Changes.md index 89a72fe4..54c6385c 100644 --- a/Changes.md +++ b/Changes.md @@ -2,6 +2,14 @@ ## User-visible Changes +* **`explicit-exit-notify` preserves auth-tokens on server restart** + + When a UDP server with `--explicit-exit-notify 1` and `--auth-gen-token` + restarts or exits, it now sends `RESTART,[P]:` instead of a bare `RESTART`. + This lets OpenVPN 3 based clients (e.g. OpenVPN Connect) reconnect with + their auth-token instead of asking the user to authenticate again. + OpenVPN 2.x clients now also keep their cached username/password. + * **Parsing Distinguished Names in certificates** (OpenSSL backend:) OpenVPN now rejects certificates that have a null-byte diff --git a/doc/man-sections/client-options.rst b/doc/man-sections/client-options.rst index 16309f90..c8596c41 100644 --- a/doc/man-sections/client-options.rst +++ b/doc/man-sections/client-options.rst @@ -285,6 +285,12 @@ configuration. reconnect to the same server, with ``n`` = :code:`2` client will advance to the next server. + If ``--auth-gen-token`` is also used and ``n`` = :code:`1`, the server + sends :code:`RESTART,[P]:` instead, asking clients to keep their cached + credentials and auth-token. Clients can then reconnect with the token + without user interaction, provided the token is still valid after the + restart (see ``--auth-gen-token-secret``). + OpenVPN will not send any exit notifications unless this option is enabled. diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 900b5a3b..c6dc932b 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -3926,14 +3926,25 @@ is_exit_restart(int sig) static void multi_push_restart_schedule_exit(struct multi_context *m, bool next_server) { + /* Preserve auth-token on restart for OpenVPN 3 clients. + * Keep the next-server case unchanged for compatibility. */ + const char *restart_msg = "RESTART"; + if (next_server) + { + restart_msg = "RESTART,[N]"; + } + else if (m->top.options.auth_token_generate) + { + restart_msg = "RESTART,[P]:"; + } + /* tell all clients to restart */ for (uint32_t i = 0; i <= m->max_peerid; i++) { struct multi_instance *mi = m->instances[i]; if (mi && !mi->halt && proto_is_dgram(mi->context.c2.link_sockets[0]->info.proto)) { - send_control_channel_string(&mi->context, next_server ? "RESTART,[N]" : "RESTART", - D_PUSH); + send_control_channel_string(&mi->context, restart_msg, D_PUSH); multi_schedule_context_wakeup(m, mi); } } -- 2.43.0 |