Implement a permanent session id in auth-token
A message that is not in the archive (sent off-list or not yet received): [email protected]...
PATCH v7 5/7 Implement a permanent session id in auth-token
From: Arne Schwabe <[email protected]...>
This allows an external authentication method
(e.g. management interface) to track the connection and distinguish a reconnection from multiple connections.
Addtionally this now also checks to workaround a problem with OpenVPN 3 core that sometimes uses a username hint from the config instead of using an empty username if the token would be valid with an empty username. Accepting such token can be only done explicitly when the external-auth keyword to auth-gen-token is present.
Patch V2: Add Empty variants to work around behaviour in openvpn 3 Patch V3: document the behaviour of external-auth better in the man page,
rename 'auth' parameter to 'external-auth'
Patch V4: Rebase on current master
Patch V6: Fix tls_lock_username rejecting clients with empty username
when explicitly accepting them with external-auth
Patch V7: Fix compiling with disable-server
--- doc/openvpn.8 | 37 +++++++++- src/openvpn/auth_token.c | 156 ++++++++++++++++++++++++++++++++++++--- src/openvpn/auth_token.h | 15 +++- src/openvpn/init.c | 1 + src/openvpn/manage.c | 4 +- src/openvpn/options.c | 14 +++- src/openvpn/options.h | 4 +- src/openvpn/ssl_common.h | 10 ++- src/openvpn/ssl_verify.c | 70 ++++++++++++------ 9 files changed, 270 insertions(+), 41 deletions(-)
doc/openvpn.8 +36 -1
@@ -3710,7 +3710,7 @@ For a sample script that performs PAM authentication, see in the OpenVPN source distribution. .\"********************************************************* .TP -.B \-\-auth\-gen\-token [lifetime] +.B \-\-auth\-gen\-token [lifetime] [auth] After successful user/password authentication, the OpenVPN server will with this option generate a temporary authentication token and push that to client. On the following
@@ -3733,6 +3733,41 @@ This feature is useful for environments which is configured to use One Time Passwords (OTP) as part of the user/password authentications and that authentication mechanism does not implement any auth\-token support. + +When the external-auth keyword is present the normal authentication +method will always be called even if auth-token succeeds. Normally other +authentications method are skipped if auth-token verification suceeds or +fails. + +This option postpones this decision to the external authentication methods +and check the validity of the account and do other checks. + +In this mode the environment will have a session_id variable +that hold the session id from auth-gen-token. Also a environment +variable session_state is present. This variable tells whether the +auth-token has succeeded or not. It can have the following values: + + - Initial: No token from client. + - Authenticated: Token is valid and not expired + - Expired: Token is valid but has expired + - Invalid Token is invalid (failed HMAC or wrong length) + - AuthenticatedEmptyUser/ExpiredEmptyUser + The token is not valid with the username send from the client + but would be valid (or expired) if we assume an empty username was used + instead. These two cases are a workaround for behaviour in OpenVPN3. If + this workaround is not needed these two cases should be handled in the + same way as Invalid. + +.B Warning: +Use this feature only if you want your authentication method called on +every verification. Since the external authentication is called it needs +to also indicate a success or failure of the authentication. It is strongly +recommended to return an authentication failure in the case of the +Invalid/Expired auth-token with the external-auth option unless the client +could authenticate in another acceptable way (e.g. client certificate), +otherwise returning success will lead to authentication bypass (as does +returning success on a wrong password from a script). + .\"********************************************************* .TP .B \-\-auth\-gen\-token\-secret [file]
src/openvpn/auth_token.c +144 -12
234 lines not on this page · raw message
src/openvpn/auth_token.h +14 -1
@@ -34,7 +34,8 @@* * Format of the auth-token (before base64 encode) * -* uint64 timestamp (4 bytes)|uint64 timestamp (4 bytes)|sha256-hmac(32 bytes) +* session id(12 bytes)|uint64 timestamp (4 bytes)| +* uint64 timestamp (4 bytes)|sha256-hmac(32 bytes) * * The first timestamp is the time the token was initially created and is used to * determine the maximum renewable time of the token. We always include this even
@@ -44,6 +45,10 @@* to determine if this token has been renewed in the acceptable time range * (2 * renogiation timeout) * +* The session is a random string of 12 byte (or 16 in base64) that is not used by +* OpenVPN itself but kept intact so that external logging/managment can track the +* session multiple reconnects/servers +* * The hmac is calculated over the username contactinated with the * raw auth-token bytes to include authentication of the username in the token *
@@ -82,6 +87,14 @@ auth_token_init_secret(struct key_ctx *key_ctx, const char *key_file,void auth_token_write_server_key_file (const char *filename); +/** +* Put the session id, and auth token status into the environment +* if auth-token is enabled +* +*/ +void add_session_token_env (struct tls_session *session,struct tls_multi *multi, +const struct user_pass *up); +/** * Wipes the authentication token out of the memory, frees and cleans up * related buffers and flags
src/openvpn/init.c +1 -0
@@ -2911,6 +2911,7 @@ do_init_crypto_tls(struct context *c, const unsigned int flags) to.auth_user_pass_file = options->auth_user_pass_file; to.auth_token_generate = options->auth_token_generate; to.auth_token_lifetime = options->auth_token_lifetime; + to.auth_token_call_auth = options->auth_token_call_auth; to.auth_token_key = c->c1.ks.auth_token_key;#endif
src/openvpn/manage.c +3 -1
@@ -2736,7 +2736,9 @@ env_filter_match(const char *env_str, const int env_filter_level)"ifconfig_pool_netmask=" ,"time_duration=" ,"bytes_sent=" , - "bytes_received=" +"bytes_received=" , +"session_id=" , + "session_state=" };if (env_filter_level ==0 )
src/openvpn/options.c +13 -1
@@ -6770,11 +6770,23 @@ add_option(struct options *options, &options->auth_user_pass_verify_script, p[1], "auth-user-pass-verify", true); } -else if (streq (p[0 ],"auth-gen-token" )) +else if (streq (p[0 ],"auth-gen-token" ) && !p[3 ]) {VERIFY_PERMISSION (OPT_P_GENERAL ); options->auth_token_generate = true; options->auth_token_lifetime = p[1 ] ?positive_atoi (p[1 ]) :0 ; +if (p[2 ]) + { +if (streq (p[2 ],"external-auth" )) + { + options->auth_token_call_auth = true; + } +else + { +msg (msglevel,"Invalid argument to auth-gen-token: %s" , p[2 ]); + } + } + }else if (streq (p[0 ],"auth-gen-token-secret" ) && p[1 ] && (!p[2 ] || (p[2 ] &&streq (p[1 ],INLINE_FILE_TAG ))))
src/openvpn/options.h +3 -1
@@ -469,7 +469,9 @@ struct optionsconst char *auth_user_pass_verify_script;bool auth_user_pass_verify_script_via_file;bool auth_token_generate; -unsigned int auth_token_lifetime; +bool auth_token_gen_secret_file; +bool auth_token_call_auth; +int auth_token_lifetime;const char *auth_token_secret_file;const char *auth_token_secret_file_inline;
src/openvpn/ssl_common.h +9 -1
@@ -310,6 +310,7 @@ struct tls_optionsbool auth_token_generate;/**< Generate auth-tokens on successful * user/pass auth,seet via * options->auth_token_generate. */ +bool auth_token_call_auth;/**< always call normal authentication */ unsigned int auth_token_lifetime;struct key_ctx auth_token_key;
@@ -470,7 +471,6 @@ struct tls_session*/ #define KEY_SCAN_SIZE 3 -/** * Security parameter state for a single VPN tunnel. * @ingroup control_processor
@@ -554,6 +554,14 @@ struct tls_multi/**< Auth-token sent from client has valid hmac */ #define AUTH_TOKEN_EXPIRED (1<<1)/**< Auth-token sent from client has expired */ +#define AUTH_TOKEN_VALID_EMPTYUSER (1<<2) +/**< +* Auth-token is only valid for an empty username +* and not the username actually supplied from the client +* +* OpenVPN 3 clients sometimes the empty username with a +* username hint from their config. +*/ int auth_token_state_flags;/**< The state of the auth-token sent from the client last time */
src/openvpn/ssl_verify.c +47 -23
155 lines not on this page · raw message
Signature · 1 line
2.22.0
Quoted 19 lines · Arne Schwabe
From: Arne Schwabe <[email protected]...>
This allows an external authentication method
(e.g. management interface) to track the connection and distinguish a reconnection from multiple connections.Addtionally this now also checks to workaround a problem with OpenVPN 3 core that sometimes uses a username hint from the config instead of using an empty username if the token would be valid with an empty username. Accepting such token can be only done explicitly when the external-auth keyword to auth-gen-token is present.
Patch V2: Add Empty variants to work around behaviour in openvpn 3 Patch V3: document the behaviour of external-auth better in the man page,
rename 'auth' parameter to 'external-auth'
Patch V4: Rebase on current master
Patch V6: Fixtls_lock_usernamerejecting clients with empty username
when explicitly accepting them with external-auth
Patch V7: Fix compiling with disable-server
Quoted 11 lines
--- doc/openvpn.8 | 37 +++++++++- src/openvpn/auth_token.c | 156 ++++++++++++++++++++++++++++++++++++--- src/openvpn/auth_token.h | 15 +++- src/openvpn/init.c | 1 + src/openvpn/manage.c | 4 +- src/openvpn/options.c | 14 +++- src/openvpn/options.h | 4 +- src/openvpn/ssl_common.h | 10 ++- src/openvpn/ssl_verify.c | 70 ++++++++++++------ 9 files changed, 270 insertions(+), 41 deletions(-)
This patch works ... but there are some comments which got ignored from the previous patch review. I will send a patch for this, as this is mostly documentation errors, not code errors.
So, I'll approve this now; these patches needs to be completed now.
Signature · 4 lines
kind regards, David Sommerseth OpenVPN Inc
Your patch has been applied to the master branch.
Again, lightly tested with client side test runs.
There is a typo in the man page change:
-.B \-\-auth\-gen\-token [lifetime]
+.B \-\-auth\-gen\-token [lifetime] [auth]
this flag is called "external-auth" (the *text* correctly says so, and options.c agrees). I have fixed this on the fly.
Not exactly sure why we need a workaround for an OpenVPN3 bug in 2.5, though... when 2.5 comes close to release, there should no longer be any buggy OpenVPN3 client around that mishandles username sending? So maybe we want to take that part *out* again...?
commit c8723aa7bebb0ddb088819590d5a9bea6ea0d669
Author: Arne Schwabe Date: Tue Sep 17 14:10:39 2019 +0200
Implement a permanent session id in auth-token
Acked-by: David Sommerseth <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg18819.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Quoted 5 lines · Gert Doering
Not exactly sure why we need a workaround for an OpenVPN3 bug in 2.5, though... when 2.5 comes close to release, there should no longer be any buggy OpenVPN3 client around that mishandles username sending? So maybe we want to take that part *out* again...?
I don't know the history around this behavioural change in OpenVPN 3, but it's the OpenVPN 3 Core library (used by OpenVPN Connect, openvpn3-linux, etc clients) which has this behaviour. But I have a feeling this is also related to how Access Server expects things to be in specific situations.
Signature · 4 lines
kind regards, David Sommerseth OpenVPN Inc