Skip to contentSkip to conversation

Implement --genkey type keyfile syntax and migrate tls-crypt-v2

PATCH In review Arne Schwabe 4 participants 28 messages Jun 13, 2019 – Oct 1, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v4 2/7 Implement --genkey type keyfile syntax and migrate tls-crypt-v2

This unifies our key generation and also migrates the generation of the tls-crypt-v2 keys. Since tls-crypt-v2 is not included in any released version, we remove the the old syntax without compatibility.

PATCH V4: Introduce warning/error when using --secret with --genkey
Update non code usages to use new --genkey syntax

---
 INSTALL                                |  2 +-
 doc/openvpn.8                          | 81 ++++++++++++++------------
 sample/sample-config-files/server.conf |  2 +-
 sample/sample-keys/gen-sample-keys.sh  |  2 +-
 sample/sample-windows/sample.ovpn      |  2 +-
 src/openvpn/crypto.c                   |  2 +-
 src/openvpn/init.c                     | 71 ++++++++++++++--------
 src/openvpn/options.c                  | 67 +++++++++++++--------
 src/openvpn/options.h                  | 11 +++-
 tests/t_lpback.sh                      |  8 +--
 10 files changed, 151 insertions(+), 97 deletions(-)
INSTALL +1 -1
index 0ba3bba6..b82cda19 100644
@@ -145,7 +145,7 @@ make check (Run all tests below)
 
 Test Crypto:
 
-./openvpn --genkey --secret key
+./openvpn --genkey secret key
 ./openvpn --test-crypto --secret key
 
 Test SSL/TLS negotiations (runs for 2 minutes):
doc/openvpn.8 +44 -37

126 lines not on this page · raw message

sample/sample-config-files/server.conf +1 -1
index 1dd477bd..e7020639 100644
@@ -235,7 +235,7 @@ keepalive 10 120
 # to help block DoS attacks and UDP port flooding.
 #
 # Generate with:
-#   openvpn --genkey --secret ta.key
+#   openvpn --genkey tls-auth ta.key
 #
 # The server and each client must have
 # a copy of this key.
sample/sample-keys/gen-sample-keys.sh +1 -1
index 920513a1..fda4ffe6 100755
@@ -15,7 +15,7 @@ then
 fi
 
 # Generate static key for tls-auth (or static key mode)
-$(dirname ${0})/../../src/openvpn/openvpn --genkey --secret ta.key
+$(dirname ${0})/../../src/openvpn/openvpn --genkey tls-auth ta.key
 
 # Create required directories and files
 mkdir -p sample-ca
sample/sample-windows/sample.ovpn +1 -1
index 5accd573..51e32744 100755
@@ -68,7 +68,7 @@ ifconfig 10.3.0.1 255.255.255.0
 #
 # You can also generate key.txt manually
 # with the following command:
-#   openvpn --genkey --secret key.txt
+#   openvpn --genkey secret key.txt
 #
 # key must match on both ends of the connection,
 # so you should generate it on one machine and
src/openvpn/crypto.c +1 -1
index eb56421b..9a150fa2 100644
@@ -1493,7 +1493,7 @@ must_have_n_keys(const char *filename, const char *option, const struct key2 *ke
 #ifdef ENABLE_SMALL
         msg(M_FATAL, "Key file '%s' used in --%s contains insufficient key material [keys found=%d required=%d]", filename, option, key2->n, n);
 #else
-        msg(M_FATAL, "Key file '%s' used in --%s contains insufficient key material [keys found=%d required=%d] -- try generating a new key file with '" PACKAGE " --genkey --secret [file]', or use the existing key file in bidirectional mode by specifying --%s without a key direction parameter", filename, option, key2->n, n, option);
+        msg(M_FATAL, "Key file '%s' used in --%s contains insufficient key material [keys found=%d required=%d] -- try generating a new key file with '" PACKAGE " --genkey secret [file]', or use the existing key file in bidirectional mode by specifying --%s without a key direction parameter", filename, option, key2->n, n, option);
 #endif
     }
 }
src/openvpn/init.c +47 -24

95 lines not on this page · raw message

src/openvpn/options.c +42 -25

120 lines not on this page · raw message

src/openvpn/options.h +9 -2
index fb2d84a1..63f0f4cb 100644
@@ -177,6 +177,12 @@ struct remote_host_store
     char port[RH_PORT_LEN];
 };
 
+enum genkey_type {
+    GENKEY_SECRET,
+    GENKEY_TLS_CRYPTV2_CLIENT,
+    GENKEY_TLS_CRYPTV2_SERVER,
+};
+
 /* Command line options */
 struct options
 {
@@ -207,6 +213,9 @@ struct options
     bool show_tls_ciphers;
     bool show_curves;
     bool genkey;
+    enum genkey_type genkey_type;
+    const char* genkey_filename;
+    const char* genkey_extra_data;
 
     /* Networking parms */
     int connect_retry_max;
@@ -589,8 +598,6 @@ struct options
     const char *tls_crypt_v2_file;
     const char *tls_crypt_v2_inline;
 
-    const char *tls_crypt_v2_genkey_type;
-    const char *tls_crypt_v2_genkey_file;
     const char *tls_crypt_v2_metadata;
 
     const char *tls_crypt_v2_verify_script;
tests/t_lpback.sh +4 -4
index 3b1e73a8..d8512896 100755
@@ -38,7 +38,7 @@ CIPHERS=$(echo "$CIPHERS" | egrep -v '^(DES-EDE3-CFB1|DES-CFB1|RC5-)' )
 # Also test cipher 'none'
 CIPHERS=${CIPHERS}$(printf "\nnone")
 
-"${top_builddir}/src/openvpn/openvpn" --genkey --secret key.$$
+"${top_builddir}/src/openvpn/openvpn" --genkey secret key.$$
 set +e
 
 e=0
@@ -57,7 +57,7 @@ done
 
 echo -n "Testing tls-crypt-v2 server key generation..."
 "${top_builddir}/src/openvpn/openvpn" \
-    --tls-crypt-v2-genkey server tc-server-key.$$ >log.$$ 2>&1
+    --genkey tls-crypt-v2-server tc-server-key.$$ >log.$$ 2>&1
 if [ $? != 0 ] ; then
     echo "FAILED"
     cat log.$$
@@ -68,7 +68,7 @@ fi
 
 echo -n "Testing tls-crypt-v2 key generation (no metadata)..."
 "${top_builddir}/src/openvpn/openvpn" --tls-crypt-v2 tc-server-key.$$ \
-    --tls-crypt-v2-genkey client tc-client-key.$$ >log.$$ 2>&1
+    --genkey tls-crypt-v2-client tc-client-key.$$ >log.$$ 2>&1
 if [ $? != 0 ] ; then
     echo "FAILED"
     cat log.$$
@@ -86,7 +86,7 @@ while [ $i -lt 732 ]; do
 done
 echo -n "Testing tls-crypt-v2 key generation (max length metadata)..."
 "${top_builddir}/src/openvpn/openvpn" --tls-crypt-v2 tc-server-key.$$ \
-    --tls-crypt-v2-genkey client tc-client-key.$$ "${METADATA}" \
+    --genkey tls-crypt-v2-client tc-client-key.$$ "${METADATA}" \
     >log.$$ 2>&1
 if [ $? != 0 ] ; then
     echo "FAILED"
Signature · 1 line
2.22.0
#1 lore raw

PATCH v4 3/7 Add generate_ephemeral_key that allows a random ephermal key

From: Arne Schwabe <[email protected]...>

This is useful for features that can use enither a persistent or an ephemeral key.

Patch V2: Move the functionality of generating a random key into a
separate function that acts as wrapper for pem_read_key_file
Patch V4: Move wrapper functionality to caller and leave only generate
epehermal key functionality in the new function

---
 src/openvpn/crypto.c | 14 ++++++++++++++
 src/openvpn/crypto.h | 12 +++++++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)
src/openvpn/crypto.c +14 -0
index 9a150fa2..69877d1d 100644
@@ -1892,6 +1892,20 @@ cleanup:
     return;
 }
 
+bool
+generate_ephemeral_key(struct buffer *key, const char *key_name)
+{
+    msg(M_INFO, "Using random %s.", key_name);
+    uint8_t rand[BCAP(key)];
+    if (!rand_bytes(rand, BCAP(key)))
+    {
+        msg(M_WARN, "ERROR: could not generate random key");
+        return false;
+    }
+    buf_write(key, rand, BCAP(key));
+    return true;
+}
+
 bool
 read_pem_key_file(struct buffer *key, const char *pem_name,
                   const char *key_file, const char *key_inline)
src/openvpn/crypto.h +11 -1
index c5947483..72244997 100644
@@ -428,7 +428,17 @@ unsigned int crypto_max_overhead(void);
  * @param pem_name          The name to use in the PEM header/footer.
  */
 void
-write_pem_key_file(const char *filename, const char *pem_name);
+write_pem_key_file(const char *filename, const char *key_name);
+
+/**
+ * Generate ephermal key material  into the key structure or if
+ *
+ * @param key           the key structure that will hold the key material
+ * @param pem_name      the name used for logging
+ * @return              true if key generation was successful
+ */
+bool
+generate_ephemeral_key(struct buffer *key, const char *pem_name);
 
 /**
  * Read key material from a PEM encoded files into the key structure
Signature · 1 line
2.22.0
#4 lore raw

PATCH v4 4/7 Rewrite auth-token-gen to be based on HMAC based tokens

In reply to Arne Schwabe

The previous auth-token implementation had a serious problem, especially when paired with an unpatched OpenVPN client that keeps trying the auth-token (commit e61b401a).

The auth-token-gen implementation forgot the auth-token on reconnect, this lead to reconnect with auth-token never working.

This new implementation implements the auth-token in a stateles variant. By using HMAC to sign the auth-token the server can verify if a token has been authenticated and by checking the embedded timestamp in the token it can also verify that the auth-token is still valid.

Using the new config directive auth-gen-token-secret instead of extending auth-gen-token (--auth-gen-token [lifetime] [secret-key]) was chosen to allow inlinening the secret key.

Patch V2: cleaned up code, use refactored read_pem_key_file function Patch V3: clarify some design decision in the commit message Patch V4: Use ephermal_generate_key

---
 doc/openvpn.8            |  25 ++++
 src/openvpn/Makefile.am  |   1 +
 src/openvpn/auth_token.c | 272 +++++++++++++++++++++++++++++++++++++++
 src/openvpn/auth_token.h | 116 +++++++++++++++++
 src/openvpn/init.c       |  30 ++++-
 src/openvpn/openvpn.h    |   1 +
 src/openvpn/options.c    |  22 +++-
 src/openvpn/options.h    |   4 +
 src/openvpn/push.c       |  70 ++++++++--
 src/openvpn/push.h       |   8 ++
 src/openvpn/ssl.c        |   7 +-
 src/openvpn/ssl_common.h |  36 ++++--
 src/openvpn/ssl_verify.c | 182 ++++++++++++--------------
 13 files changed, 639 insertions(+), 135 deletions(-)
 create mode 100644 src/openvpn/auth_token.c
 create mode 100644 src/openvpn/auth_token.h
doc/openvpn.8 +25 -0
index 25195fd4..cb63e218 100644
@@ -3720,6 +3720,9 @@ the token authentication internally and it will NOT do any
 additional authentications against configured external
 user/password authentication mechanisms.
 
+The tokens implemented by this mechanism include a initial timestamp
+and a renew timestamp and are secured by HMAC.
+
 The
 .B lifetime
 argument defines how long the generated token is valid.  The
@@ -3730,6 +3733,16 @@ 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.
+.\"*********************************************************
+.TP
+.B \-\-auth\-gen\-token\-secret [file]
+Specifies a file that hold a secret for the HMAC used in
+.B \-\-auth\-gen\-token
+If not present OpenVPN will generate a random secret on startup. This file
+should be used if auth-token should valid after restarting a server or if
+client should be able to roam between multiple OpenVPN server with their
+auth\-token.
+
 .\"*********************************************************
 .TP
 .B \-\-opt\-verify
@@ -5769,6 +5782,17 @@ Servers can use
 .B \-\-tls\-crypt\-v2\-verify
 to specify a metadata verification command.
 .\"*********************************************************
+.TP
+.B \-\-genkey auth\-token [keyfile]
+Generate a new secret that can be used
+with
+.B \-\-auth\-gen\-token\-secret
+
+.B Note:
+this file should be kept secret to the server as anyone
+that access to this file will be to generate auth tokens
+that the OpenVPN server will accept as valid.
+.\"*********************************************************
 .SS TUN/TAP persistent tunnel config mode:
 Available with Linux 2.4.7+.  These options comprise a standalone mode
 of OpenVPN which can be used to create and delete persistent tunnels.
@@ -6980,6 +7004,7 @@ X509_1_C=KG
 OpenVPN allows including files in the main configuration for the
 .B \-\-ca, \-\-cert, \-\-dh, \-\-extra\-certs, \-\-key, \-\-pkcs12, \-\-secret,
 .B \-\-crl\-verify, \-\-http\-proxy\-user\-pass, \-\-tls\-auth,
+.B \-\-auth\-gen\-token\-secret
 .B \-\-tls\-crypt,
 and
 .B \-\-tls\-crypt-v2
src/openvpn/Makefile.am +1 -0
index 30caa01f..3754fd95 100644
@@ -39,6 +39,7 @@ sbin_PROGRAMS = openvpn
 
 openvpn_SOURCES = \
 	argv.c argv.h \
+	auth_token.c auth_token.h \
 	base64.c base64.h \
 	basic.h \
 	buffer.c buffer.h \
src/openvpn/auth_token.c new file +272 -0

272 lines not on this page · raw message

src/openvpn/auth_token.h new file +116 -0

116 lines not on this page · raw message

src/openvpn/init.c +29 -1
index 87976290..3fe746ad 100644
@@ -51,6 +51,7 @@
 #include "ssl_verify.h"
 #include "tls_crypt.h"
 #include "forward.h"
+#include "auth_token.h"
 
 #include "memdbg.h"
 
@@ -1118,6 +1119,11 @@ do_genkey(const struct options *options)
                                            options->tls_crypt_v2_inline);
         return true;
     }
+    else if (options->genkey && options->genkey_type == GENKEY_AUTH_TOKEN)
+    {
+        auth_token_write_server_key_file(options->genkey_filename);
+        return true;
+    }
     else
     {
         return false;
@@ -2522,7 +2528,6 @@ init_crypto_pre(struct context *c, const unsigned int flags)
         rand_ctx_enable_prediction_resistance();
     }
 #endif
-
 }
 
 /*
@@ -2646,6 +2651,22 @@ do_init_tls_wrap_key(struct context *c)
 
 }
 
+/*
+ * Initialise the auth-token key context
+ */
+static void
+do_init_auth_token_key(struct context *c)
+{
+    if (!c->options.auth_token_generate)
+    {
+        return;
+    }
+
+    auth_token_init_secret(&c->c1.ks.auth_token_key,
+                           c->options.auth_token_secret_file,
+                           c->options.auth_token_secret_file_inline);
+}
+
 /*
  * Initialize the persistent component of OpenVPN's TLS mode,
  * which is preserved across SIGUSR1 resets.
@@ -2698,6 +2719,9 @@ do_init_crypto_tls_c1(struct context *c)
         /* initialize tls-auth/crypt/crypt-v2 key */
         do_init_tls_wrap_key(c);
 
+        /* initialise auth-token crypto support */
+        do_init_auth_token_key(c);
+
 #if 0 /* was: #if ENABLE_INLINE_FILES --  Note that enabling this code will break restarts */
         if (options->priv_key_file_inline)
         {
@@ -2871,6 +2895,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_key = c->c1.ks.auth_token_key;
 #endif
 
     to.x509_track = options->x509_track;
@@ -4486,6 +4511,9 @@ inherit_context_child(struct context *dest,
     dest->c1.authname = src->c1.authname;
     dest->c1.keysize = src->c1.keysize;
 
+    /* inherit auth-token */
+    dest->c1.ks.auth_token_key = src->c1.ks.auth_token_key;
+
     /* options */
     dest->options = src->options;
     options_detach(&dest->options);
src/openvpn/openvpn.h +1 -0
index fca33f25..7b01de16 100644
@@ -68,6 +68,7 @@ struct key_schedule
     struct key_ctx_bi tls_wrap_key;
     struct key_ctx tls_crypt_v2_server_key;
     struct buffer tls_crypt_v2_wkc;             /**< Wrapped client key */
+    struct key_ctx auth_token_key;
 };
 
 /*
src/openvpn/options.c +21 -1
index a37b7146..b9e39157 100644
@@ -1289,6 +1289,7 @@ show_p2mp_parms(const struct options *o)
     SHOW_BOOL(auth_user_pass_verify_script_via_file);
     SHOW_BOOL(auth_token_generate);
     SHOW_INT(auth_token_lifetime);
+    SHOW_STR(auth_token_secret_file);
 #if PORT_SHARE
     SHOW_STR(port_share_host);
     SHOW_STR(port_share_port);
@@ -2336,7 +2337,11 @@ options_postprocess_verify_ce(const struct options *options, const struct connec
         {
             msg(M_USAGE, "--mode server requires --key-method 2");
         }
-
+        if (options->auth_token_generate && !options->renegotiate_seconds)
+        {
+            msg(M_USAGE, "--auth-gen-token needs a non-infinite "
+                "--renegotiate_seconds setting");
+        }
         {
             const bool ccnr = (options->auth_user_pass_verify_script
                                || PLUGIN_OPTION_LIST(options)
@@ -6771,6 +6776,17 @@ add_option(struct options *options,
         options->auth_token_generate = true;
         options->auth_token_lifetime = p[1] ? positive_atoi(p[1]) : 0;
     }
+    else if (streq(p[0], "auth-gen-token-secret") && p[1] && (!p[2]
+                                                              || (p[2] && streq(p[1], INLINE_FILE_TAG))))
+    {
+        VERIFY_PERMISSION(OPT_P_GENERAL);
+        options->auth_token_secret_file = p[1];
+
+        if (streq(p[1], INLINE_FILE_TAG) && p[2])
+        {
+            options->auth_token_secret_file_inline = p[2];
+        }
+    }
     else if (streq(p[0], "client-connect") && p[1])
     {
         VERIFY_PERMISSION(OPT_P_SCRIPT);
@@ -7546,6 +7562,10 @@ add_option(struct options *options,
                     options->genkey_extra_data = p[3];
                 }
             }
+            else if (streq(p[1], "auth-token"))
+            {
+                options->genkey_type = GENKEY_AUTH_TOKEN;
+            }
             else
             {
                 msg(msglevel, "unknown --genkey type: %s", p[1]);
src/openvpn/options.h +4 -0
index 63f0f4cb..d885f4d9 100644
@@ -181,6 +181,7 @@ enum genkey_type {
     GENKEY_SECRET,
     GENKEY_TLS_CRYPTV2_CLIENT,
     GENKEY_TLS_CRYPTV2_SERVER,
+    GENKEY_AUTH_TOKEN
 };
 
 /* Command line options */
@@ -469,6 +470,9 @@ struct options
     bool auth_user_pass_verify_script_via_file;
     bool auth_token_generate;
     unsigned int auth_token_lifetime;
+    const char *auth_token_secret_file;
+    const char *auth_token_secret_file_inline;
+
 #if PORT_SHARE
     char *port_share_host;
     char *port_share_port;
src/openvpn/push.c +59 -11

106 lines not on this page · raw message

src/openvpn/push.h +8 -0
index 5f6181e7..070782dd 100644
@@ -69,6 +69,14 @@ void send_auth_failed(struct context *c, const char *client_reason);
 
 void send_restart(struct context *c, const char *kill_msg);
 
+/**
+ * Sends a push reply message only containin the auth-token to update
+ * the auth-token on the client
+ *
+ * @param multi  - The tls_multi structure belonging to the instance to push to
+ */
+void send_push_reply_auth_token(struct tls_multi *multi);
+
 #endif
 #endif /* if P2MP */
 #endif /* ifndef PUSH_H */
src/openvpn/ssl.c +2 -5
index 640808f9..73c07595 100644
@@ -59,6 +59,7 @@
 #include "ssl.h"
 #include "ssl_verify.h"
 #include "ssl_backend.h"
+#include "auth_token.h"
 
 #include "memdbg.h"
 
@@ -1368,11 +1369,7 @@ tls_multi_free(struct tls_multi *multi, bool clear)
 
     cert_hash_free(multi->locked_cert_hash_set);
 
-    if (multi->auth_token)
-    {
-        secure_memzero(multi->auth_token, AUTH_TOKEN_SIZE);
-        free(multi->auth_token);
-    }
+    wipe_auth_token(multi);
 
     free(multi->remote_ciphername);
 
src/openvpn/ssl_common.h +22 -14
index 0312c1f8..5e19ab56 100644
@@ -298,7 +298,6 @@ struct tls_options
     /** TLS handshake wrapping state */
     struct tls_wrap_ctx tls_wrap;
 
-    /* frame parameters for TLS control channel */
     struct frame frame;
 
     /* used for username/password authentication */
@@ -306,10 +305,16 @@ struct tls_options
     bool auth_user_pass_verify_script_via_file;
     const char *tmp_dir;
     const char *auth_user_pass_file;
-    bool auth_token_generate;   /**< Generate auth-tokens on successful user/pass auth,
-                                 *   set via options->auth_token_generate. */
+
+#ifdef P2MP_SERVER
+    bool auth_token_generate;   /**< Generate auth-tokens on successful
+                                 * user/pass auth,seet via
+                                 * options->auth_token_generate. */
     unsigned int auth_token_lifetime;
 
+    struct key_ctx auth_token_key;
+#endif
+
     /* use the client-config-dir as a positive authenticator */
     const char *client_config_dir_exclusive;
 
@@ -369,10 +374,6 @@ struct tls_options
 /** @} name Index of key_state objects within a tls_session structure */
 /** @} addtogroup control_processor */
 
-#define AUTH_TOKEN_SIZE 32      /**< Size of server side generated auth tokens.
-                                 *   32 bytes == 256 bits
-                                 */
-
 /**
  * Security parameter state of a single session within a VPN tunnel.
  * @ingroup control_processor
@@ -540,7 +541,21 @@ struct tls_multi
      * over control channel.
      */
     char *peer_info;
+    char *auth_token;    /**< If server sends a generated auth-token,
+                          *   this is the token to use for future
+                          *   user/pass authentications in this session.
+                          */
+    char *auth_token_initial;
+    /**< The first auth-token we sent to a client, for clients that do
+     * not update their auth-token (older OpenVPN3 core versions)
+     */
+#define  AUTH_TOKEN_HMAC_OK              (1<<0)
+    /**< Auth-token sent from client has valid hmac */
+#define  AUTH_TOKEN_EXPIRED              (1<<1)
+    /**< Auth-token sent from client has expired */
 #endif
+    int auth_token_state_flags;
+    /**< The state of the auth-token sent from the client last time */
 
     /* For P_DATA_V2 */
     uint32_t peer_id;
@@ -548,13 +563,6 @@ struct tls_multi
 
     char *remote_ciphername;    /**< cipher specified in peer's config file */
 
-    char *auth_token;    /**< If server sends a generated auth-token,
-                          *   this is the token to use for future
-                          *   user/pass authentications in this session.
-                          */
-    time_t auth_token_tstamp; /**< timestamp of the generated token */
-    bool auth_token_sent; /**< If server uses --auth-gen-token and
-                           *   token has been sent to client */
     /*
      * Our session objects.
      */
src/openvpn/ssl_verify.c +79 -103

240 lines not on this page · raw message

Signature · 1 line
2.22.0
#12 lore raw

PATCH v4 5/7 Implement a permanent session id in auth-token

In reply to 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

---
 doc/openvpn.8            |  37 +++++++++-
 src/openvpn/auth_token.c | 145 ++++++++++++++++++++++++++++++++++++---
 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 |  12 +++-
 src/openvpn/ssl_verify.c |  67 ++++++++++++------
 9 files changed, 260 insertions(+), 39 deletions(-)
doc/openvpn.8 +36 -1
index cb63e218..7ec287df 100644
@@ -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 +134 -11

224 lines not on this page · raw message

src/openvpn/auth_token.h +14 -1
index 600ac29f..c10afde9 100644
@@ -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
index 3fe746ad..5df0db15 100644
@@ -2895,6 +2895,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
index 2d86dad4..1d97c2b6 100644
@@ -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
index b9e39157..d2a37f11 100644
@@ -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
index d885f4d9..8f722497 100644
@@ -469,7 +469,9 @@ struct options
     const 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 +10 -2
index 5e19ab56..047aa59b 100644
@@ -310,6 +310,7 @@ struct tls_options
     bool 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
@@ -553,9 +553,17 @@ struct tls_multi
     /**< Auth-token sent from client has valid hmac */
 #define  AUTH_TOKEN_EXPIRED              (1<<1)
     /**< Auth-token sent from client has expired */
-#endif
+#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 */
+#endif
 
     /* For P_DATA_V2 */
     uint32_t peer_id;
src/openvpn/ssl_verify.c +46 -21

140 lines not on this page · raw message

Signature · 1 line
2.22.0
#15 lore raw

PATCH v4 6/7 Sent indication that a session is expired to clients

In reply to Arne Schwabe

From: Arne Schwabe <[email protected]...>

This allows OpenVPN 3 core to fall back to the original authentication method.

This commit changes man_def_auth_set_client_reason to auth_set_client_reason since it now used in more contexts.

Also remove a FIXME about client_reason not being freed, as it is freed in tls_multi_free with auth_set_client_reason(multi, NULL);

Patch V4: Rebase on master

---
 src/openvpn/auth_token.c |  3 +++
 src/openvpn/ssl.c        |  6 ++----
 src/openvpn/ssl_common.h | 10 +++++-----
 src/openvpn/ssl_verify.c |  8 ++++----
 src/openvpn/ssl_verify.h | 15 ++++++++++-----
 5 files changed, 24 insertions(+), 18 deletions(-)
src/openvpn/auth_token.c +3 -0
index 8387a7c8..6c287236 100644
@@ -15,6 +15,7 @@
 #include "push.h"
 #include "integer.h"
 #include "ssl.h"
+#include "ssl_verify.h"
 
 const char *auth_token_pem_name = "OpenVPN auth-token server key";
 
@@ -368,6 +369,8 @@ verify_auth_token(struct user_pass *up, struct tls_multi *multi,
 
     if (ret & AUTH_TOKEN_EXPIRED)
     {
+        /* Tell client that the session token is expired */
+        auth_set_client_reason(multi, "SESSION: token expired");
         msg(M_INFO, "--auth-token-gen: auth-token from client expired");
     }
     return ret;
src/openvpn/ssl.c +2 -4
index 73c07595..b993df9f 100644
@@ -1349,11 +1349,9 @@ tls_multi_free(struct tls_multi *multi, bool clear)
 
     ASSERT(multi);
 
-#ifdef MANAGEMENT_DEF_AUTH
-    man_def_auth_set_client_reason(multi, NULL);
-
-#endif
 #if P2MP_SERVER
+    auth_set_client_reason(multi, NULL);
+
     free(multi->peer_info);
 #endif
 
src/openvpn/ssl_common.h +5 -5
index 047aa59b..aad6af2f 100644
@@ -526,16 +526,16 @@ struct tls_multi
     struct cert_hash_set *locked_cert_hash_set;
 
 #ifdef ENABLE_DEF_AUTH
-    /*
-     * An error message to send to client on AUTH_FAILED
-     */
-    char *client_reason;
-
     /* Time of last call to tls_authentication_status */
     time_t tas_last;
 #endif
 
 #if P2MP_SERVER
+    /*
+     * An error message to send to client on AUTH_FAILED
+     */
+    char *client_reason;
+
     /*
      * A multi-line string of general-purpose info received from peer
      * over control channel.
src/openvpn/ssl_verify.c +4 -4
index 6535ad8d..f61c621b 100644
@@ -803,9 +803,8 @@ cleanup:
 #define ACF_FAILED    3
 #endif
 
-#ifdef MANAGEMENT_DEF_AUTH
 void
-man_def_auth_set_client_reason(struct tls_multi *multi, const char *client_reason)
+auth_set_client_reason(struct tls_multi* multi, const char* client_reason)
 {
     if (multi->client_reason)
     {
@@ -814,11 +813,12 @@ man_def_auth_set_client_reason(struct tls_multi *multi, const char *client_reaso
     }
     if (client_reason && strlen(client_reason))
     {
-        /* FIXME: Last alloc will never be freed */
         multi->client_reason = string_alloc(client_reason, NULL);
     }
 }
 
+#ifdef MANAGEMENT_DEF_AUTH
+
 static inline unsigned int
 man_def_auth_test(const struct key_state *ks)
 {
@@ -1022,7 +1022,7 @@ tls_authenticate_key(struct tls_multi *multi, const unsigned int mda_key_id, con
     if (multi)
     {
         int i;
-        man_def_auth_set_client_reason(multi, client_reason);
+        auth_set_client_reason(multi, client_reason);
         for (i = 0; i < KEY_SCAN_SIZE; ++i)
         {
             struct key_state *ks = multi->key_scan[i];
src/openvpn/ssl_verify.h +10 -5
index 64f27efb..c54b89a6 100644
@@ -224,18 +224,23 @@ struct x509_track
 #ifdef MANAGEMENT_DEF_AUTH
 bool tls_authenticate_key(struct tls_multi *multi, const unsigned int mda_key_id, const bool auth, const char *client_reason);
 
-void man_def_auth_set_client_reason(struct tls_multi *multi, const char *client_reason);
+#endif
 
+#ifdef P2MP_SERVER
+/**
+ * Sets the reason why authentication of a client failed. This be will send to the client
+ * when the AUTH_FAILED message is sent
+ * An example would be "SESSION: Token expired"
+ * @param multi             The multi tls struct
+ * @param client_reason     The string to send to the client as part of AUTH_FAILED
+ */
+void auth_set_client_reason(struct tls_multi* multi, const char* client_reason);
 #endif
 
 static inline const char *
 tls_client_reason(struct tls_multi *multi)
 {
-#ifdef ENABLE_DEF_AUTH
     return multi->client_reason;
-#else
-    return NULL;
-#endif
 }
 
 /** Remove any X509_ env variables from env_set es */
Signature · 1 line
2.22.0
#23 lore raw

PATCH v4 7/7 Implement unit tests for auth-gen-token

In reply to Arne Schwabe

From: Arne Schwabe <[email protected]...>

Patch V2: adapt unit tests to other V2 patches
Patch V4: Resolve rebase conflicts

---
 tests/unit_tests/openvpn/Makefile.am       |  20 +-
 tests/unit_tests/openvpn/test_auth_token.c | 375 +++++++++++++++++++++
 2 files changed, 394 insertions(+), 1 deletion(-)
 create mode 100644 tests/unit_tests/openvpn/test_auth_token.c
tests/unit_tests/openvpn/Makefile.am +19 -1
index c6da91a8..e941f488 100644
@@ -6,7 +6,7 @@ if HAVE_LD_WRAP_SUPPORT
 test_binaries += argv_testdriver buffer_testdriver
 endif
 
-test_binaries += crypto_testdriver packet_id_testdriver
+test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver
 if HAVE_LD_WRAP_SUPPORT
 test_binaries += tls_crypt_testdriver
 endif
@@ -92,3 +92,21 @@ networking_testdriver_SOURCES = test_networking.c mock_msg.c \
 	$(openvpn_srcdir)/otime.c \
 	$(openvpn_srcdir)/packet_id.c \
 	$(openvpn_srcdir)/platform.c
+
+auth_token_testdriver_CFLAGS  = @TEST_CFLAGS@ \
+	-I$(openvpn_includedir) -I$(compat_srcdir) -I$(openvpn_srcdir) \
+	$(OPTIONAL_CRYPTO_CFLAGS)
+auth_token_testdriver_LDFLAGS = @TEST_LDFLAGS@ \
+	$(OPTIONAL_CRYPTO_LIBS)
+
+auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \
+	$(openvpn_srcdir)/buffer.c \
+	$(openvpn_srcdir)/crypto.c \
+	$(openvpn_srcdir)/crypto_mbedtls.c \
+	$(openvpn_srcdir)/crypto_openssl.c \
+	$(openvpn_srcdir)/otime.c \
+	$(openvpn_srcdir)/packet_id.c \
+	$(openvpn_srcdir)/platform.c
+	$(openvpn_srcdir)/platform.c \
+	$(openvpn_srcdir)/base64.c
+
tests/unit_tests/openvpn/test_auth_token.c new file +375 -0

375 lines not on this page · raw message

Signature · 1 line
2.22.0
Acked-by on v4 3/7
#2 lore raw

Re: [Openvpn-devel] [PATCH v4 3/7] Add generate_ephemeral_key that allows a random ephermal key

In reply to Arne Schwabe
Quoted 5 lines · Arne Schwabe

From: Arne Schwabe <[email protected]...>

This is useful for features that can use enither a persistent or an ephemeral key.

Quoted 8 lines

Patch V2: Move the functionality of generating a random key into a
separate function that acts as wrapper for pem_read_key_file
Patch V4: Move wrapper functionality to caller and leave only generate
epehermal key functionality in the new function

---
 src/openvpn/crypto.c | 14 ++++++++++++++
 src/openvpn/crypto.h | 12 +++++++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)

This looks good ... but one nit-pick, but can be fixed during commit:

src/openvpn/crypto.h unsigned int crypto_max_overhead(void);

Quoted 5 lines
src/openvpn/crypto.h +0 -0
index c5947483..72244997 100644
@@ -428,7 +428,17 @@ unsigned int crypto_max_overhead(void);

[....]> +/**

src/openvpn/crypto.h unsigned int crypto_max_overhead(void); · line 434

Quoted 1 line
src/openvpn/crypto.h +1 -0
+ * Generate ephermal key material  into the key structure or if
                                                             ^^^^^

This comment don't need those two last words, but that can be fixed during commit time.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
Acked-by on v4 2/7
#25 lore raw
In reply to Arne Schwabe
Quoted 6 lines · Arne Schwabe

This unifies our key generation and also migrates the generation of the tls-crypt-v2 keys. Since tls-crypt-v2 is not included in any released version, we remove the the old syntax without compatibility.

PATCH V4: Introduce warning/error when using --secret with --genkey
Update non code usages to use new --genkey syntax

Quoted 13 lines
---
 INSTALL                                |  2 +-
 doc/openvpn.8                          | 81 ++++++++++++++------------
 sample/sample-config-files/server.conf |  2 +-
 sample/sample-keys/gen-sample-keys.sh  |  2 +-
 sample/sample-windows/sample.ovpn      |  2 +-
 src/openvpn/crypto.c                   |  2 +-
 src/openvpn/init.c                     | 71 ++++++++++++++--------
 src/openvpn/options.c                  | 67 +++++++++++++--------
 src/openvpn/options.h                  | 11 +++-
 tests/t_lpback.sh                      |  8 +--
 10 files changed, 151 insertions(+), 97 deletions(-)

Looks good now, 'make check' passes and behaviour is more consistent.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#5 lore raw

Re: [Openvpn-devel] [PATCH v4 4/7] Rewrite auth-token-gen to be based on HMAC based tokens

In reply to Arne Schwabe
Quoted 28 lines · Arne Schwabe

The previous auth-token implementation had a serious problem, especially when paired with an unpatched OpenVPN client that keeps trying the auth-token (commit e61b401a).

The auth-token-gen implementation forgot the auth-token on reconnect, this lead to reconnect with auth-token never working.

This new implementation implements the auth-token in a stateles variant. By using HMAC to sign the auth-token the server can verify if a token has been authenticated and by checking the embedded timestamp in the token it can also verify that the auth-token is still valid.

Using the new config directive auth-gen-token-secret instead of extending auth-gen-token (--auth-gen-token [lifetime] [secret-key]) was chosen to allow inlinening the secret key.

Patch V2: cleaned up code, use refactored read_pem_key_file function Patch V3: clarify some design decision in the commit message Patch V4: Use ephermal_generate_key

---
 doc/openvpn.8            |  25 ++++
 src/openvpn/Makefile.am  |   1 +
 src/openvpn/auth_token.c | 272 +++++++++++++++++++++++++++++++++++++++
 src/openvpn/auth_token.h | 116 +++++++++++++++++
 src/openvpn/init.c       |  30 ++++-
 src/openvpn/openvpn.h    |   1 +
 src/openvpn/options.c    |  22 +++-
 src/openvpn/options.h    |   4 +
Quoted 9 lines
 src/openvpn/push.c       |  70 ++++++++--
 src/openvpn/push.h       |   8 ++
 src/openvpn/ssl.c        |   7 +-
 src/openvpn/ssl_common.h |  36 ++++--
 src/openvpn/ssl_verify.c | 182 ++++++++++++--------------
 13 files changed, 639 insertions(+), 135 deletions(-)
 create mode 100644 src/openvpn/auth_token.c
 create mode 100644 src/openvpn/auth_token.h

Not as heavy tested as in last round, but changes has been applied as indicated. Thank you! Unfortunately, some compiler warnings are appearing:

------------------------------------------------------------
auth_token.c: In function ‘generate_auth_token’:
auth_token.c:115:9: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

         initial_timestamp = *((uint64_t *)(old_tstamp_decode));
         ^

auth_token.c: In function ‘verify_auth_token’:
auth_token.c:233:9: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 3 has type ‘uint64_t’ [-Wformat=]
msg(M_WARN, "Initial timestamp (%lld) in token from client earlier than "
^
auth_token.c:233:9: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 4 has type ‘uint64_t’ [-Wformat=]
------------------------------------------------------------

The first one (dereferencing type-punned pointer) seems to only show up with gcc-4.8.5 and 6.3.1. Below are warnings reported by both gcc-7.3.1 and 8.3.1, which are also a bit more verbose, with a few additional twists.

------------------------------------------------------------
auth_token.c: In function ‘verify_auth_token’:
auth_token.c:233:21: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 3 has type ‘uint64_t’ {aka ‘long unsigned int’} [-Wformat=]
msg(M_WARN, "Initial timestamp (%lld) in token from client earlier than "
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
auth_token.c:235:13:

             timestamp_initial, timestamp);
             ~~~~~~~~~~~~~~~~~
error.h:151:67: note: in definition of macro ‘msg’
 #define msg(flags, ...) do { if (msg_test(flags)) {x_msg((flags), __VA_ARGS__);} EXIT_FATAL(flags); } while (false)
                                                                   ^~~~~~~~~~~
auth_token.c:233:44: note: format string is defined here
         msg(M_WARN, "Initial timestamp (%lld) in token from client earlier than "
                                         ~~~^
                                         %ld
In file included from buffer.h:28,
                 from auth_token.c:10:

auth_token.c:233:21: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 4 has type ‘uint64_t’ {aka ‘long unsigned int’} [-Wformat=]
msg(M_WARN, "Initial timestamp (%lld) in token from client earlier than "
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
auth_token.c:235:32:

             timestamp_initial, timestamp);
                                ~~~~~~~~~
error.h:151:67: note: in definition of macro ‘msg’
 #define msg(flags, ...) do { if (msg_test(flags)) {x_msg((flags), __VA_ARGS__);} EXIT_FATAL(flags); } while (false)
                                                                   ^~~~~~~~~~~
auth_token.c:234:36: note: format string is defined here
             "current timestamp (%lld). Broken/unsynchronised clock?",
                                 ~~~^
                                 %ld

------------------------------------------------------------

Other than these issues, things looks good and would normally get an ACK.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
Acked-by on v4 6/7
#16 lore raw

Re: [Openvpn-devel] [PATCH v4 6/7] Sent indication that a session is expired to clients

In reply to Arne Schwabe
Quoted 11 lines · Arne Schwabe

From: Arne Schwabe <[email protected]...>

This allows OpenVPN 3 core to fall back to the original authentication method.

This commit changes man_def_auth_set_client_reason to auth_set_client_reason since it now used in more contexts.

Also remove a FIXME about client_reason not being freed, as it is freed in tls_multi_free with auth_set_client_reason(multi, NULL);

Quoted 9 lines

Patch V4: Rebase on master

---
 src/openvpn/auth_token.c |  3 +++
 src/openvpn/ssl.c        |  6 ++----
 src/openvpn/ssl_common.h | 10 +++++-----
 src/openvpn/ssl_verify.c |  8 ++++----
 src/openvpn/ssl_verify.h | 15 ++++++++++-----
 5 files changed, 24 insertions(+), 18 deletions(-)

There's a typo in the subject line (Sent -> Send), otherwise this is fine and works as expected.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#24 lore raw

Re: [Openvpn-devel] [PATCH v4 7/7] Implement unit tests for auth-gen-token

In reply to Arne Schwabe
Quoted 10 lines · Arne Schwabe

From: Arne Schwabe <[email protected]...>

Patch V2: adapt unit tests to other V2 patches
Patch V4: Resolve rebase conflicts

---
 tests/unit_tests/openvpn/Makefile.am       |  20 +-
 tests/unit_tests/openvpn/test_auth_token.c | 375 +++++++++++++++++++++
 2 files changed, 394 insertions(+), 1 deletion(-)
 create mode 100644 tests/unit_tests/openvpn/test_auth_token.c

Looks reasonable. But needs to be rebased on top of latest git master; I suspect this is due to sitnl patches arriving in master. I had to "force" this into submission, so I might have missed a few things - as I do get these errors:

-------------------------------------------------------------
.../openvpn/tests/unit_tests/openvpn/../../../src/openvpn/auth_token.c:201: undefined reference to openvpn_base64_decode' .../openvpn/tests/unit_tests/openvpn/../../../src/openvpn/auth_token.c:205: undefined reference to openvpn_base64_decode' .../openvpn/tests/unit_tests/openvpn/../../../src/openvpn/auth_token.c:254: undefined reference to openvpn_base64_encode' auth_token_testdriver-test_auth_token.o: In function verify_auth_token':
.../OpenVPN/openvpn/tests/unit_tests/openvpn/../../../src/openvpn/auth_token.c:299: undefined reference to `openvpn_base64_decode'
-------------------------------------------------------------

In addition comes the warnings I've already reported in a prior patch.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#26 lore raw
In reply to Arne Schwabe

Unimportant non escaped dashes openvpn.8 & one typo

Quoted 89 lines · Arne Schwabe

This unifies our key generation and also migrates the generation of the tls-crypt-v2 keys. Since tls-crypt-v2 is not included in any released version, we remove the the old syntax without compatibility.

PATCH V4: Introduce warning/error when using --secret with --genkey
Update non code usages to use new --genkey syntax

---
  INSTALL                                |  2 +-
  doc/openvpn.8                          | 81 ++++++++++++++------------
  sample/sample-config-files/server.conf |  2 +-
  sample/sample-keys/gen-sample-keys.sh  |  2 +-
  sample/sample-windows/sample.ovpn      |  2 +-
  src/openvpn/crypto.c                   |  2 +-
  src/openvpn/init.c                     | 71 ++++++++++++++--------
  src/openvpn/options.c                  | 67 +++++++++++++--------
  src/openvpn/options.h                  | 11 +++-
  tests/t_lpback.sh                      |  8 +--
  10 files changed, 151 insertions(+), 97 deletions(-)
doc/openvpn.8 +3 -34
index ce440447..25195fd4 100644
@@ -5242,7 +5242,7 @@ Use client\-specific tls\-crypt keys.
  For clients,
  .B keyfile
  is a client\-specific tls\-crypt key.  Such a key can be generated using the
-.B \-\-tls\-crypt\-v2\-genkey
+.B \-\-genkey tls\-crypt\-v2\-client
  option.
 
  For servers,
@@ -5250,7 +5250,7 @@ For servers,
  is used to unwrap client\-specific keys supplied by the client during connection
  setup.  This key must be the same as the key used to generate the
  client\-specific key (see
-.B \-\-tls\-crypt\-v2\-genkey\fR).
+.B \-\-genkey tls\-crypt\-v2\-client\fR).
 
  On servers, this option can be used together with the
  .B \-\-tls\-auth
@@ -5260,36 +5260,6 @@ option.  In that case, the server will detect whether the client is using
  client\-specific keys, and automatically select the right mode.
  .\"*********************************************************
  .TP
-.B \-\-tls\-crypt\-v2\-genkey client|server keyfile [metadata]
-
-If the first parameter equals "server", generate a \-\-tls\-crypt\-v2 server
-key and store the key in
-.B keyfile\fR.
-
-
-If the first parameter equals "client", generate a \-\-tls\-crypt\-v2 client
-key, and store the key in
-.B keyfile\fR.
-
-If supplied, include the supplied
-.B metadata
-in the wrapped client key.  This metadata must be supplied in base64\-encoded
-form.  The metadata must be at most 735 bytes long (980 bytes in base64).
-
-If no metadata is supplied, OpenVPN will use a 64\-bit unix timestamp
-representing the current time in UTC, encoded in network order, as metadata for
-the generated key.
-
-A tls\-crypt\-v2 client key is wrapped using a server key.  To generate a
-client key, the user must therefore supply the server key using the
-.B \-\-tls\-crypt\-v2
-option.
-
-Servers can use
-.B \-\-tls\-crypt\-v2\-verify
-to specify a metadata verification command.
-.\"*********************************************************
-.TP
  .B \-\-tls\-crypt\-v2\-verify cmd
 
  Run command
@@ -5741,13 +5711,18 @@ Show all available elliptic curves to use with the
  .B \-\-ecdh\-curve
  option.
  .\"*********************************************************
-.SS Generate a random key:
-Used only for non\-TLS static key encryption mode.
+.SS Generating key material:
  .\"*********************************************************
  .TP

doc/openvpn.8 Show all available elliptic curves to use with the · line 5724

Quoted 10 lines
doc/openvpn.8 +7 -2
-.B \-\-genkey file
+.B \-\-genkey keytype keyfile
  (Standalone)
-Generate a random key to be used as a shared secret, for use with the
+Generate a key to be used of the type keytype. if keyfile is left out or empty
+the key will be output on stdout. See the following sections for the different keytypes.
+
+.\"*********************************************************
+.TP
+.B \-\-genkey secret|tls-crypt|tls-auth keyfile

^^

doc/openvpn.8 or · line 5733

Quoted 9 lines
doc/openvpn.8 +2 -0
+Generate a shared secret, for use with the
  .B \-\-secret
  ,
  .B \-\-tls-auth
@@ -5755,6 +5730,8 @@ or
  .B \-\-tls-crypt
  options.  Stores the key in
  .B file\fR.
+All three variants (secret, tls-crypt, and tls-auth) generate the same type of

^^

doc/openvpn.8 or · line 5734

Quoted 1 line
doc/openvpn.8 +1 -0
+key. The aliases are added for convience.

typo: convience -> convenience

doc/openvpn.8 If using this for · line 5743

Quoted 9 lines
doc/openvpn.8 +2 -0
  If using this for
  .B \-\-secret
@@ -5762,6 +5739,36 @@ If using this for
  such as
  .BR scp (1)\fR.
  .\"*********************************************************
+.TP
+.B \-\-genkey tls\-crypt\-v2-server keyfile

^^

doc/openvpn.8 If using this for · line 5749

Quoted 6 lines
doc/openvpn.8 +6 -0
+
+Generate a \-\-tls\-crypt\-v2 server key and store the key in
+.B keyfile\fR.
+
+.TP
+.B \-\-genkey tls\-crypt\-v2-client keyfile [metadata]

^^

Quoted 33 lines
doc/openvpn.8 +22 -1
+
+Generate a \-\-tls\-crypt\-v2 client key, and store the key in > +.B keyfile\fR.
+
+If supplied, include the supplied
+.B metadata
+in the wrapped client key.  This metadata must be supplied in base64\-encoded
+form.  The metadata must be at most 735 bytes long (980 bytes in base64).
+
+If no metadata is supplied, OpenVPN will use a 64\-bit unix timestamp
+representing the current time in UTC, encoded in network order, as metadata for
+the generated key.
+
+A tls\-crypt\-v2 client key is wrapped using a server key.  To generate a
+client key, the user must therefore supply the server key using the
+.B \-\-tls\-crypt\-v2
+option.
+
+Servers can use
+.B \-\-tls\-crypt\-v2\-verify
+to specify a metadata verification command.
+.\"*********************************************************
  .SS TUN/TAP persistent tunnel config mode:
  Available with Linux 2.4.7+.  These options comprise a standalone mode
  of OpenVPN which can be used to create and delete persistent tunnels.
@@ -7185,7 +7192,7 @@ First build a static key on bob.
  .IP
  .B openvpn \-\-genkey \-\-secret key
  .LP
-This command will build a random key file called
+This command will build a key file called
  .B key
  (in ascii format).
  Now copy
#27 lore raw
In reply to Arne Schwabe

Your patch has been applied to the master branch.

Have only done a cursory review + "make check" since David did the thorough review already. One small code wart...

+ if (options->mlock && (options->genkey))

(asymmetric brackets) ... we can fix that when we pass here next time...

I have adjusted openvpn.8 according to tincantech's comments about dashes and the typo.

commit 0d80b562e48a243c36dba9f1f66c3da6e3b3eb98

Author: Arne Schwabe
Date:   Thu Jun 13 15:48:29 2019 +0200
     Implement --genkey type keyfile syntax and migrate tls-crypt-v2

     Acked-by: David Sommerseth <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg18524.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#3 lore raw

[Openvpn-devel] [PATCH applied] Re: Add generate_ephemeral_key that allows a random ephermal key

In reply to Arne Schwabe

Your patch has been applied to the master branch.

I have adjusted the comment as David suggested. Not much to test yet, as the new code is not used yet.

commit fb4e8abca908d90faa98f20125e49a2590bccaa3

Author: Arne Schwabe
Date:   Thu Jun 13 15:48:30 2019 +0200
     Add generate_ephemeral_key that allows a random ephermal key

     Acked-by: David Sommerseth <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg18527.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#6 lore raw

PATCH v6 4/7 Rewrite auth-token-gen to be based on HMAC based tokens

In reply to David Sommerseth

The previous auth-token implementation had a serious problem, especially when paired with an unpatched OpenVPN client that keeps trying the auth-token (commit e61b401a).

The auth-token-gen implementation forgot the auth-token on reconnect, this lead to reconnect with auth-token never working.

This new implementation implements the auth-token in a stateles variant. By using HMAC to sign the auth-token the server can verify if a token has been authenticated and by checking the embedded timestamp in the token it can also verify that the auth-token is still valid.

Using the new config directive auth-gen-token-secret instead of extending auth-gen-token (--auth-gen-token [lifetime] [secret-key]) was chosen to allow inlinening the secret key.

Patch V2: cleaned up code, use refactored read_pem_key_file function Patch V3: clarify some design decision in the commit message Patch V4: Use ephermal_generate_key
Patch V5: Use C99 PRIu64 instead of %lld int printf like statement,
fix strict aliasing

---
 doc/openvpn.8            |  25 ++++
 src/openvpn/Makefile.am  |   1 +
 src/openvpn/auth_token.c | 273 +++++++++++++++++++++++++++++++++++++++
 src/openvpn/auth_token.h | 116 +++++++++++++++++
 src/openvpn/init.c       |  30 ++++-
 src/openvpn/openvpn.h    |   1 +
 src/openvpn/options.c    |  22 +++-
 src/openvpn/options.h    |   4 +
 src/openvpn/push.c       |  70 ++++++++--
 src/openvpn/push.h       |   8 ++
 src/openvpn/ssl.c        |   7 +-
 src/openvpn/ssl_common.h |  36 ++++--
 src/openvpn/ssl_verify.c | 182 +++++++++++---------------
 13 files changed, 640 insertions(+), 135 deletions(-)
 create mode 100644 src/openvpn/auth_token.c
 create mode 100644 src/openvpn/auth_token.h
doc/openvpn.8 +25 -0
index 4185ffed..a50d67d4 100644
@@ -3720,6 +3720,9 @@ the token authentication internally and it will NOT do any
 additional authentications against configured external
 user/password authentication mechanisms.
 
+The tokens implemented by this mechanism include a initial timestamp
+and a renew timestamp and are secured by HMAC.
+
 The
 .B lifetime
 argument defines how long the generated token is valid.  The
@@ -3730,6 +3733,16 @@ 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.
+.\"*********************************************************
+.TP
+.B \-\-auth\-gen\-token\-secret [file]
+Specifies a file that hold a secret for the HMAC used in
+.B \-\-auth\-gen\-token
+If not present OpenVPN will generate a random secret on startup. This file
+should be used if auth-token should valid after restarting a server or if
+client should be able to roam between multiple OpenVPN server with their
+auth\-token.
+
 .\"*********************************************************
 .TP
 .B \-\-opt\-verify
@@ -5775,6 +5788,17 @@ Servers can use
 .B \-\-tls\-crypt\-v2\-verify
 to specify a metadata verification command.
 .\"*********************************************************
+.TP
+.B \-\-genkey auth\-token [keyfile]
+Generate a new secret that can be used
+with
+.B \-\-auth\-gen\-token\-secret
+
+.B Note:
+this file should be kept secret to the server as anyone
+that access to this file will be to generate auth tokens
+that the OpenVPN server will accept as valid.
+.\"*********************************************************
 .SS TUN/TAP persistent tunnel config mode:
 Available with Linux 2.4.7+.  These options comprise a standalone mode
 of OpenVPN which can be used to create and delete persistent tunnels.
@@ -6986,6 +7010,7 @@ X509_1_C=KG
 OpenVPN allows including files in the main configuration for the
 .B \-\-ca, \-\-cert, \-\-dh, \-\-extra\-certs, \-\-key, \-\-pkcs12, \-\-secret,
 .B \-\-crl\-verify, \-\-http\-proxy\-user\-pass, \-\-tls\-auth,
+.B \-\-auth\-gen\-token\-secret
 .B \-\-tls\-crypt,
 and
 .B \-\-tls\-crypt-v2
src/openvpn/Makefile.am +1 -0
index 30caa01f..3754fd95 100644
@@ -39,6 +39,7 @@ sbin_PROGRAMS = openvpn
 
 openvpn_SOURCES = \
 	argv.c argv.h \
+	auth_token.c auth_token.h \
 	base64.c base64.h \
 	basic.h \
 	buffer.c buffer.h \
src/openvpn/auth_token.c new file +273 -0

273 lines not on this page · raw message

src/openvpn/auth_token.h new file +116 -0

116 lines not on this page · raw message

src/openvpn/init.c +29 -1
index b5a034dc..2efd0828 100644
@@ -51,6 +51,7 @@
 #include "ssl_verify.h"
 #include "tls_crypt.h"
 #include "forward.h"
+#include "auth_token.h"
 
 #include "memdbg.h"
 
@@ -1118,6 +1119,11 @@ do_genkey(const struct options *options)
                                            options->tls_crypt_v2_inline);
         return true;
     }
+    else if (options->genkey && options->genkey_type == GENKEY_AUTH_TOKEN)
+    {
+        auth_token_write_server_key_file(options->genkey_filename);
+        return true;
+    }
     else
     {
         return false;
@@ -2534,7 +2540,6 @@ init_crypto_pre(struct context *c, const unsigned int flags)
         rand_ctx_enable_prediction_resistance();
     }
 #endif
-
 }
 
 /*
@@ -2658,6 +2663,22 @@ do_init_tls_wrap_key(struct context *c)
 
 }
 
+/*
+ * Initialise the auth-token key context
+ */
+static void
+do_init_auth_token_key(struct context *c)
+{
+    if (!c->options.auth_token_generate)
+    {
+        return;
+    }
+
+    auth_token_init_secret(&c->c1.ks.auth_token_key,
+                           c->options.auth_token_secret_file,
+                           c->options.auth_token_secret_file_inline);
+}
+
 /*
  * Initialize the persistent component of OpenVPN's TLS mode,
  * which is preserved across SIGUSR1 resets.
@@ -2710,6 +2731,9 @@ do_init_crypto_tls_c1(struct context *c)
         /* initialize tls-auth/crypt/crypt-v2 key */
         do_init_tls_wrap_key(c);
 
+        /* initialise auth-token crypto support */
+        do_init_auth_token_key(c);
+
 #if 0 /* was: #if ENABLE_INLINE_FILES --  Note that enabling this code will break restarts */
         if (options->priv_key_file_inline)
         {
@@ -2883,6 +2907,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_key = c->c1.ks.auth_token_key;
 #endif
 
     to.x509_track = options->x509_track;
@@ -4499,6 +4524,9 @@ inherit_context_child(struct context *dest,
     dest->c1.authname = src->c1.authname;
     dest->c1.keysize = src->c1.keysize;
 
+    /* inherit auth-token */
+    dest->c1.ks.auth_token_key = src->c1.ks.auth_token_key;
+
     /* options */
     dest->options = src->options;
     options_detach(&dest->options);
src/openvpn/openvpn.h +1 -0
index 29d21f0a..900db7e1 100644
@@ -68,6 +68,7 @@ struct key_schedule
     struct key_ctx_bi tls_wrap_key;
     struct key_ctx tls_crypt_v2_server_key;
     struct buffer tls_crypt_v2_wkc;             /**< Wrapped client key */
+    struct key_ctx auth_token_key;
 };
 
 /*
src/openvpn/options.c +21 -1
index 2d3865a6..fbba93c9 100644
@@ -1289,6 +1289,7 @@ show_p2mp_parms(const struct options *o)
     SHOW_BOOL(auth_user_pass_verify_script_via_file);
     SHOW_BOOL(auth_token_generate);
     SHOW_INT(auth_token_lifetime);
+    SHOW_STR(auth_token_secret_file);
 #if PORT_SHARE
     SHOW_STR(port_share_host);
     SHOW_STR(port_share_port);
@@ -2336,7 +2337,11 @@ options_postprocess_verify_ce(const struct options *options, const struct connec
         {
             msg(M_USAGE, "--mode server requires --key-method 2");
         }
-
+        if (options->auth_token_generate && !options->renegotiate_seconds)
+        {
+            msg(M_USAGE, "--auth-gen-token needs a non-infinite "
+                "--renegotiate_seconds setting");
+        }
         {
             const bool ccnr = (options->auth_user_pass_verify_script
                                || PLUGIN_OPTION_LIST(options)
@@ -6771,6 +6776,17 @@ add_option(struct options *options,
         options->auth_token_generate = true;
         options->auth_token_lifetime = p[1] ? positive_atoi(p[1]) : 0;
     }
+    else if (streq(p[0], "auth-gen-token-secret") && p[1] && (!p[2]
+                                                              || (p[2] && streq(p[1], INLINE_FILE_TAG))))
+    {
+        VERIFY_PERMISSION(OPT_P_GENERAL);
+        options->auth_token_secret_file = p[1];
+
+        if (streq(p[1], INLINE_FILE_TAG) && p[2])
+        {
+            options->auth_token_secret_file_inline = p[2];
+        }
+    }
     else if (streq(p[0], "client-connect") && p[1])
     {
         VERIFY_PERMISSION(OPT_P_SCRIPT);
@@ -7546,6 +7562,10 @@ add_option(struct options *options,
                     options->genkey_extra_data = p[3];
                 }
             }
+            else if (streq(p[1], "auth-token"))
+            {
+                options->genkey_type = GENKEY_AUTH_TOKEN;
+            }
             else
             {
                 msg(msglevel, "unknown --genkey type: %s", p[1]);
src/openvpn/options.h +4 -0
index 63f0f4cb..d885f4d9 100644
@@ -181,6 +181,7 @@ enum genkey_type {
     GENKEY_SECRET,
     GENKEY_TLS_CRYPTV2_CLIENT,
     GENKEY_TLS_CRYPTV2_SERVER,
+    GENKEY_AUTH_TOKEN
 };
 
 /* Command line options */
@@ -469,6 +470,9 @@ struct options
     bool auth_user_pass_verify_script_via_file;
     bool auth_token_generate;
     unsigned int auth_token_lifetime;
+    const char *auth_token_secret_file;
+    const char *auth_token_secret_file_inline;
+
 #if PORT_SHARE
     char *port_share_host;
     char *port_share_port;
src/openvpn/push.c +59 -11

106 lines not on this page · raw message

src/openvpn/push.h +8 -0
index 5f6181e7..070782dd 100644
@@ -69,6 +69,14 @@ void send_auth_failed(struct context *c, const char *client_reason);
 
 void send_restart(struct context *c, const char *kill_msg);
 
+/**
+ * Sends a push reply message only containin the auth-token to update
+ * the auth-token on the client
+ *
+ * @param multi  - The tls_multi structure belonging to the instance to push to
+ */
+void send_push_reply_auth_token(struct tls_multi *multi);
+
 #endif
 #endif /* if P2MP */
 #endif /* ifndef PUSH_H */
src/openvpn/ssl.c +2 -5
index abc3c53b..0d79f91e 100644
@@ -59,6 +59,7 @@
 #include "ssl.h"
 #include "ssl_verify.h"
 #include "ssl_backend.h"
+#include "auth_token.h"
 
 #include "memdbg.h"
 
@@ -1368,11 +1369,7 @@ tls_multi_free(struct tls_multi *multi, bool clear)
 
     cert_hash_free(multi->locked_cert_hash_set);
 
-    if (multi->auth_token)
-    {
-        secure_memzero(multi->auth_token, AUTH_TOKEN_SIZE);
-        free(multi->auth_token);
-    }
+    wipe_auth_token(multi);
 
     free(multi->remote_ciphername);
 
src/openvpn/ssl_common.h +22 -14
index 0312c1f8..5e19ab56 100644
@@ -298,7 +298,6 @@ struct tls_options
     /** TLS handshake wrapping state */
     struct tls_wrap_ctx tls_wrap;
 
-    /* frame parameters for TLS control channel */
     struct frame frame;
 
     /* used for username/password authentication */
@@ -306,10 +305,16 @@ struct tls_options
     bool auth_user_pass_verify_script_via_file;
     const char *tmp_dir;
     const char *auth_user_pass_file;
-    bool auth_token_generate;   /**< Generate auth-tokens on successful user/pass auth,
-                                 *   set via options->auth_token_generate. */
+
+#ifdef P2MP_SERVER
+    bool auth_token_generate;   /**< Generate auth-tokens on successful
+                                 * user/pass auth,seet via
+                                 * options->auth_token_generate. */
     unsigned int auth_token_lifetime;
 
+    struct key_ctx auth_token_key;
+#endif
+
     /* use the client-config-dir as a positive authenticator */
     const char *client_config_dir_exclusive;
 
@@ -369,10 +374,6 @@ struct tls_options
 /** @} name Index of key_state objects within a tls_session structure */
 /** @} addtogroup control_processor */
 
-#define AUTH_TOKEN_SIZE 32      /**< Size of server side generated auth tokens.
-                                 *   32 bytes == 256 bits
-                                 */
-
 /**
  * Security parameter state of a single session within a VPN tunnel.
  * @ingroup control_processor
@@ -540,7 +541,21 @@ struct tls_multi
      * over control channel.
      */
     char *peer_info;
+    char *auth_token;    /**< If server sends a generated auth-token,
+                          *   this is the token to use for future
+                          *   user/pass authentications in this session.
+                          */
+    char *auth_token_initial;
+    /**< The first auth-token we sent to a client, for clients that do
+     * not update their auth-token (older OpenVPN3 core versions)
+     */
+#define  AUTH_TOKEN_HMAC_OK              (1<<0)
+    /**< Auth-token sent from client has valid hmac */
+#define  AUTH_TOKEN_EXPIRED              (1<<1)
+    /**< Auth-token sent from client has expired */
 #endif
+    int auth_token_state_flags;
+    /**< The state of the auth-token sent from the client last time */
 
     /* For P_DATA_V2 */
     uint32_t peer_id;
@@ -548,13 +563,6 @@ struct tls_multi
 
     char *remote_ciphername;    /**< cipher specified in peer's config file */
 
-    char *auth_token;    /**< If server sends a generated auth-token,
-                          *   this is the token to use for future
-                          *   user/pass authentications in this session.
-                          */
-    time_t auth_token_tstamp; /**< timestamp of the generated token */
-    bool auth_token_sent; /**< If server uses --auth-gen-token and
-                           *   token has been sent to client */
     /*
      * Our session objects.
      */
src/openvpn/ssl_verify.c +79 -103

240 lines not on this page · raw message

Signature · 1 line
2.22.0
#13 lore raw

PATCH v6 5/7 Implement a permanent session id in auth-token

In reply to 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: Fix tls_lock_username rejecting clients with empty username
when explicitly accepting them with external-auth

---
 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 |  12 ++-
 src/openvpn/ssl_verify.c |  67 +++++++++++------
 9 files changed, 270 insertions(+), 40 deletions(-)
doc/openvpn.8 +36 -1
index a50d67d4..19c386a0 100644
@@ -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
index 600ac29f..c10afde9 100644
@@ -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
index 2efd0828..f395fe01 100644
@@ -2907,6 +2907,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
index 2d86dad4..1d97c2b6 100644
@@ -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
index fbba93c9..752f5f2c 100644
@@ -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
index d885f4d9..8f722497 100644
@@ -469,7 +469,9 @@ struct options
     const 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 +10 -2
index 5e19ab56..047aa59b 100644
@@ -310,6 +310,7 @@ struct tls_options
     bool 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
@@ -553,9 +553,17 @@ struct tls_multi
     /**< Auth-token sent from client has valid hmac */
 #define  AUTH_TOKEN_EXPIRED              (1<<1)
     /**< Auth-token sent from client has expired */
-#endif
+#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 */
+#endif
 
     /* For P_DATA_V2 */
     uint32_t peer_id;
src/openvpn/ssl_verify.c +46 -21

140 lines not on this page · raw message

Signature · 1 line
2.22.0
#17 lore raw

PATCH v6 6/7 Send indication that a session is expired to clients

In reply to David Sommerseth

From: Arne Schwabe <[email protected]...>

This allows OpenVPN 3 core to fall back to the original authentication method.

This commit changes man_def_auth_set_client_reason to auth_set_client_reason since it now used in more contexts.

Also remove a FIXME about client_reason not being freed, as it is freed in tls_multi_free with auth_set_client_reason(multi, NULL);

Patch V4: Rebase on master

---
 src/openvpn/auth_token.c |  3 +++
 src/openvpn/ssl.c        |  6 ++----
 src/openvpn/ssl_common.h | 10 +++++-----
 src/openvpn/ssl_verify.c |  8 ++++----
 src/openvpn/ssl_verify.h | 15 ++++++++++-----
 5 files changed, 24 insertions(+), 18 deletions(-)
src/openvpn/auth_token.c +3 -0
index 5568a144..1edc8069 100644
@@ -15,6 +15,7 @@
 #include "push.h"
 #include "integer.h"
 #include "ssl.h"
+#include "ssl_verify.h"
 #include <inttypes.h>
 
 const char *auth_token_pem_name = "OpenVPN auth-token server key";
@@ -378,6 +379,8 @@ verify_auth_token(struct user_pass *up, struct tls_multi *multi,
 
     if (ret & AUTH_TOKEN_EXPIRED)
     {
+        /* Tell client that the session token is expired */
+        auth_set_client_reason(multi, "SESSION: token expired");
         msg(M_INFO, "--auth-token-gen: auth-token from client expired");
     }
     return ret;
src/openvpn/ssl.c +2 -4
index 0d79f91e..4455ebb8 100644
@@ -1349,11 +1349,9 @@ tls_multi_free(struct tls_multi *multi, bool clear)
 
     ASSERT(multi);
 
-#ifdef MANAGEMENT_DEF_AUTH
-    man_def_auth_set_client_reason(multi, NULL);
-
-#endif
 #if P2MP_SERVER
+    auth_set_client_reason(multi, NULL);
+
     free(multi->peer_info);
 #endif
 
src/openvpn/ssl_common.h +5 -5
index 047aa59b..aad6af2f 100644
@@ -526,16 +526,16 @@ struct tls_multi
     struct cert_hash_set *locked_cert_hash_set;
 
 #ifdef ENABLE_DEF_AUTH
-    /*
-     * An error message to send to client on AUTH_FAILED
-     */
-    char *client_reason;
-
     /* Time of last call to tls_authentication_status */
     time_t tas_last;
 #endif
 
 #if P2MP_SERVER
+    /*
+     * An error message to send to client on AUTH_FAILED
+     */
+    char *client_reason;
+
     /*
      * A multi-line string of general-purpose info received from peer
      * over control channel.
src/openvpn/ssl_verify.c +4 -4
index 6535ad8d..f61c621b 100644
@@ -803,9 +803,8 @@ cleanup:
 #define ACF_FAILED    3
 #endif
 
-#ifdef MANAGEMENT_DEF_AUTH
 void
-man_def_auth_set_client_reason(struct tls_multi *multi, const char *client_reason)
+auth_set_client_reason(struct tls_multi* multi, const char* client_reason)
 {
     if (multi->client_reason)
     {
@@ -814,11 +813,12 @@ man_def_auth_set_client_reason(struct tls_multi *multi, const char *client_reaso
     }
     if (client_reason && strlen(client_reason))
     {
-        /* FIXME: Last alloc will never be freed */
         multi->client_reason = string_alloc(client_reason, NULL);
     }
 }
 
+#ifdef MANAGEMENT_DEF_AUTH
+
 static inline unsigned int
 man_def_auth_test(const struct key_state *ks)
 {
@@ -1022,7 +1022,7 @@ tls_authenticate_key(struct tls_multi *multi, const unsigned int mda_key_id, con
     if (multi)
     {
         int i;
-        man_def_auth_set_client_reason(multi, client_reason);
+        auth_set_client_reason(multi, client_reason);
         for (i = 0; i < KEY_SCAN_SIZE; ++i)
         {
             struct key_state *ks = multi->key_scan[i];
src/openvpn/ssl_verify.h +10 -5
index 64f27efb..c54b89a6 100644
@@ -224,18 +224,23 @@ struct x509_track
 #ifdef MANAGEMENT_DEF_AUTH
 bool tls_authenticate_key(struct tls_multi *multi, const unsigned int mda_key_id, const bool auth, const char *client_reason);
 
-void man_def_auth_set_client_reason(struct tls_multi *multi, const char *client_reason);
+#endif
 
+#ifdef P2MP_SERVER
+/**
+ * Sets the reason why authentication of a client failed. This be will send to the client
+ * when the AUTH_FAILED message is sent
+ * An example would be "SESSION: Token expired"
+ * @param multi             The multi tls struct
+ * @param client_reason     The string to send to the client as part of AUTH_FAILED
+ */
+void auth_set_client_reason(struct tls_multi* multi, const char* client_reason);
 #endif
 
 static inline const char *
 tls_client_reason(struct tls_multi *multi)
 {
-#ifdef ENABLE_DEF_AUTH
     return multi->client_reason;
-#else
-    return NULL;
-#endif
 }
 
 /** Remove any X509_ env variables from env_set es */
Signature · 1 line
2.22.0
Acked-by on v6 4/7
#7 lore raw

Re: [Openvpn-devel] [PATCH v6 4/7] Rewrite auth-token-gen to be based on HMAC based tokens

In reply to Arne Schwabe
Quoted 30 lines · Arne Schwabe

The previous auth-token implementation had a serious problem, especially when paired with an unpatched OpenVPN client that keeps trying the auth-token (commit e61b401a).

The auth-token-gen implementation forgot the auth-token on reconnect, this lead to reconnect with auth-token never working.

This new implementation implements the auth-token in a stateles variant. By using HMAC to sign the auth-token the server can verify if a token has been authenticated and by checking the embedded timestamp in the token it can also verify that the auth-token is still valid.

Using the new config directive auth-gen-token-secret instead of extending auth-gen-token (--auth-gen-token [lifetime] [secret-key]) was chosen to allow inlinening the secret key.

Patch V2: cleaned up code, use refactored read_pem_key_file function Patch V3: clarify some design decision in the commit message Patch V4: Use ephermal_generate_key
Patch V5: Use C99 PRIu64 instead of %lld int printf like statement,
fix strict aliasing

---
 doc/openvpn.8            |  25 ++++
 src/openvpn/Makefile.am  |   1 +
 src/openvpn/auth_token.c | 273 +++++++++++++++++++++++++++++++++++++++
 src/openvpn/auth_token.h | 116 +++++++++++++++++
 src/openvpn/init.c       |  30 ++++-
 src/openvpn/openvpn.h    |   1 +
 src/openvpn/options.c    |  22 +++-
 src/openvpn/options.h    |   4 +
Quoted 9 lines
 src/openvpn/push.c       |  70 ++++++++--
 src/openvpn/push.h       |   8 ++
 src/openvpn/ssl.c        |   7 +-
 src/openvpn/ssl_common.h |  36 ++++--
 src/openvpn/ssl_verify.c | 182 +++++++++++---------------
 13 files changed, 640 insertions(+), 135 deletions(-)
 create mode 100644 src/openvpn/auth_token.c
 create mode 100644 src/openvpn/auth_token.h

Hi,

Thanks a lot. This now only leaves the following warning when using gcc-4.8.5 and gcc-6.3.1 (both on RHEL 7.7)

------------------------------------------------------------
auth_token.c: In function ‘generate_auth_token’:
auth_token.c:115:9: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

         initial_timestamp = *((uint64_t *)(old_tstamp_decode));
         ^

------------------------------------------------------------

This warning is not present when compiling with gcc-7.3.1, gcc-8.3.1, clang-3.4.2 nor clang-5.0.1. So I'm blaming buggy/confused older GCC compilers for this one.

Since I've tested and reviewed the rest in earlier rounds and the change from previous version i sjust changing %lld to PRIu64, I'm giving
this my ...

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#14 lore raw

Re: [Openvpn-devel] [PATCH v6 5/7] Implement a permanent session id in auth-token

In reply to Arne Schwabe
Quoted 29 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: Fix tls_lock_username rejecting clients with empty username
when explicitly accepting them with external-auth

---
 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 |  12 ++-
 src/openvpn/ssl_verify.c |  67 +++++++++++------
 9 files changed, 270 insertions(+), 40 deletions(-)

[...snip...]

Quoted 22 lines
src/openvpn/auth_token.c +6 -2
@@ -97,6 +180,8 @@ generate_auth_token(const struct user_pass *up, struct tls_multi *multi)
     hmac_ctx_t *ctx = multi->opt.auth_token_key.hmac;
     ASSERT(hmac_ctx_size(ctx) == 256/8);
 
+    uint8_t sessid[AUTH_TOKEN_SESSION_ID_LEN];
+
     if (multi->auth_token)
     {
         /* Just enough space to fit 8 bytes+ 1 extra to decode a non padded
@@ -109,27 +194,65 @@ generate_auth_token(const struct user_pass *up, struct tls_multi *multi)
          * reuse the same session id and timestamp and null terminate it at
          * for base64 decode it only decodes the session id part of it
          */
-        char *old_tsamp_initial = multi->auth_token + strlen(SESSION_ID_PREFIX);
+        char *old_sessid = multi->auth_token + strlen(SESSION_ID_PREFIX);
+        char *old_tsamp_initial = old_sessid + AUTH_TOKEN_SESSION_ID_LEN*8/6;
 
         old_tsamp_initial[12] = '\0';
         ASSERT(openvpn_base64_decode(old_tsamp_initial, old_tstamp_decode, 9) == 9);
-        initial_timestamp = *((uint64_t *)(old_tstamp_decode));
+
+        /*

src/openvpn/auth_token.c generate_auth_token(const struct user_pass *up, struct tls_multi *multi) · line 213

Quoted 10 lines
src/openvpn/auth_token.c +10 -0
+         * 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';
+        ASSERT(openvpn_base64_decode(old_sessid, sessid, AUTH_TOKEN_SESSION_ID_LEN)==AUTH_TOKEN_SESSION_ID_LEN);
+

The gcc-4.8 strict aliasing fix works, so that is good.

Could you explain (or comment) the rationale for the ASSERT() calls here?

If the decoded token is only managed by the server side, then this shouldn't really fail. But unless I'm misunderstanding what happens in verify_user_pass() [ssl_verify.c:1376], we put the "password" (token) from the client into multi->auth_token. With the ASSERT() calls here, this could be abused to trigger a DoS attack, by sending an invalid token value. Or am I missing something?

And there is a superfluous additional extra new line, which should not be needed.

[...snip...]

src/openvpn/auth_token.h

Quoted 4 lines
src/openvpn/auth_token.h +0 -0
index 600ac29f..c10afde9 100644

[...snip...]

This file includes the following comment for verify_auth_token(), which I believe is wrong now:

* Also calls generate_auth_token to update the auth-token to extend
* its validity

I don't see verify_auth_token() being close to call generate_auth_token(). Or did I overlook something?

[...snip...]

Quoted 4 lines
src/openvpn/options.h +0 -0
index d885f4d9..8f722497 100644

[...snip...]

src/openvpn/options.h struct tls_multi · line 562

Quoted 12 lines
src/openvpn/options.h +7 -1
@@ -553,9 +553,17 @@ struct tls_multi
     /**< Auth-token sent from client has valid hmac */
 #define  AUTH_TOKEN_EXPIRED              (1<<1)
     /**< Auth-token sent from client has expired */
-#endif
+#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.

The last OpenVPN 3 paragraph is hard to understand. Did you mean this?

* OpenVPN 3 clients sometimes empty or replaces the username with a
* username hint from their config.

[...snip...]

Quoted 4 lines
src/openvpn/ssl_verify.c +0 -0
index b392b0ac..6535ad8d 100644

[...snip...]

Quoted 11 lines
src/openvpn/ssl_verify.c +2 -1
@@ -1134,7 +1138,8 @@ done:
  * Verify the username and password using a plugin
  */
 static int
-verify_user_pass_plugin(struct tls_session *session, const struct user_pass *up)
+verify_user_pass_plugin(struct tls_session *session, struct tls_multi *multi,
+                        const struct user_pass *up)
 {
     int retval = OPENVPN_PLUGIN_FUNC_ERROR;
 #ifdef PLUGIN_DEF_AUTH

src/openvpn/ssl_verify.c verify_user_pass_plugin(struct tls_session *session, const struct user_pass *up) · line 1166

Quoted 8 lines
src/openvpn/ssl_verify.c +2 -0
@@ -1154,6 +1159,8 @@ verify_user_pass_plugin(struct tls_session *session, const struct user_pass *up)
         /* setenv client real IP address */
         setenv_untrusted(session);
 
+        /* add auth-token environment */
+        add_session_token_env(session, multi, up);
 #ifdef PLUGIN_DEF_AUTH
         /* generate filename for deferred auth control file */
         if (!key_state_gen_auth_control_file(ks, session->opt))

When looking through the code here; I wonder how this all will work with deferred authentication and plug-ins. Have you tested this? (I will run some additional checks, also covering this use case)

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#8 lore raw

Re: [Openvpn-devel] [PATCH v6 4/7] Rewrite auth-token-gen to be based on HMAC based tokens

In reply to David Sommerseth

Hi,

Quoted 4 lines · David Sommerseth
Quoted 3 lines · Arne Schwabe

The previous auth-token implementation had a serious problem, especially when paired with an unpatched OpenVPN client that keeps trying the auth-token (commit e61b401a).

[..]

Quoted 5 lines

Since I've tested and reviewed the rest in earlier rounds and the change from previous version i sjust changing %lld to PRIu64, I'm giving
this my ...

While I'm all happy to see this ACK (and I trust David to have done a full review on the code changes), there is a slight problem with this - it breaks "--disable-server" builds:

cc -DHAVE_CONFIG_H -I. -I../../../openvpn/src/openvpn -I../.. -I../../include -I../../../openvpn/include -I../../../openvpn/src/compat -I/usr/local/include -I/usr/local/include -DPLUGIN_LIBDIR=\"/usr/local/lib/openvpn/plugins\" -Wall -Wno-unused-parameter -Wno-unused-function -g -O2 -std=c99 -MT auth_token.o -MD -MP -MF .deps/auth_token.Tpo -c -o auth_token.o ../../../openvpn/src/openvpn/auth_token.c
../../../openvpn/src/openvpn/auth_token.c:100:16: error: no member named 'auth_token' in

      'struct tls_multi'
    if (multi->auth_token)
        ~~~~~  ^
../../../openvpn/src/openvpn/auth_token.c:112:42: error: no member named 'auth_token' in
      'struct tls_multi'
        char *old_tsamp_initial = multi->auth_token + strlen(SESSION_ID_PREFIX);
                                  ~~~~~  ^
../../../openvpn/src/openvpn/auth_token.c:119:21: error: no member named 'auth_token' in
      'struct tls_multi'
        free(multi->auth_token);
             ~~~~~  ^

... so, can I have a v7 of this, plus an ACK...?

Sorry for being a spoilsport here.

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
Acked-by on v6 6/7
#18 lore raw

Re: [Openvpn-devel] [PATCH v6 6/7] Send indication that a session is expired to clients

In reply to Arne Schwabe
Quoted 11 lines · Arne Schwabe

From: Arne Schwabe <[email protected]...>

This allows OpenVPN 3 core to fall back to the original authentication method.

This commit changes man_def_auth_set_client_reason to auth_set_client_reason since it now used in more contexts.

Also remove a FIXME about client_reason not being freed, as it is freed in tls_multi_free with auth_set_client_reason(multi, NULL);

Quoted 9 lines

Patch V4: Rebase on master

---
 src/openvpn/auth_token.c |  3 +++
 src/openvpn/ssl.c        |  6 ++----
 src/openvpn/ssl_common.h | 10 +++++-----
 src/openvpn/ssl_verify.c |  8 ++++----
 src/openvpn/ssl_verify.h | 15 ++++++++++-----
 5 files changed, 24 insertions(+), 18 deletions(-)

This looks reasonable and the code does what it says. On my quick testing, I managed to trigger this to be sent to the client:

AUTH: Received control message: AUTH_FAILED,SESSION: token expired

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#9 lore raw

PATCH v7 4/7 Rewrite auth-token-gen to be based on HMAC based tokens

In reply to Gert Doering

The previous auth-token implementation had a serious problem, especially when paired with an unpatched OpenVPN client that keeps trying the auth-token (commit e61b401a).

The auth-token-gen implementation forgot the auth-token on reconnect, this lead to reconnect with auth-token never working.

This new implementation implements the auth-token in a stateles variant. By using HMAC to sign the auth-token the server can verify if a token has been authenticated and by checking the embedded timestamp in the token it can also verify that the auth-token is still valid.

Using the new config directive auth-gen-token-secret instead of extending auth-gen-token (--auth-gen-token [lifetime] [secret-key]) was chosen to allow inlinening the secret key.

Patch V2: cleaned up code, use refactored read_pem_key_file function Patch V3: clarify some design decision in the commit message Patch V4: Use ephermal_generate_key
Patch V5: Use C99 PRIu64 instead of %lld int printf like statement,
fix strict aliasing
Patch V6: Rebase on master
Patch V7: fix compiling with --disable-server

---
 doc/openvpn.8            |  25 ++++
 src/openvpn/Makefile.am  |   1 +
 src/openvpn/auth_token.c | 273 +++++++++++++++++++++++++++++++++++++++
 src/openvpn/auth_token.h | 116 +++++++++++++++++
 src/openvpn/init.c       |  34 ++++-
 src/openvpn/openvpn.h    |   1 +
 src/openvpn/options.c    |  22 +++-
 src/openvpn/options.h    |   4 +
 src/openvpn/push.c       |  70 ++++++++--
 src/openvpn/push.h       |   8 ++
 src/openvpn/ssl.c        |   7 +-
 src/openvpn/ssl_common.h |  36 ++++--
 src/openvpn/ssl_verify.c | 184 ++++++++++++--------------
 13 files changed, 646 insertions(+), 135 deletions(-)
 create mode 100644 src/openvpn/auth_token.c
 create mode 100644 src/openvpn/auth_token.h
doc/openvpn.8 +25 -0
index 4185ffed..a50d67d4 100644
@@ -3720,6 +3720,9 @@ the token authentication internally and it will NOT do any
 additional authentications against configured external
 user/password authentication mechanisms.
 
+The tokens implemented by this mechanism include a initial timestamp
+and a renew timestamp and are secured by HMAC.
+
 The
 .B lifetime
 argument defines how long the generated token is valid.  The
@@ -3730,6 +3733,16 @@ 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.
+.\"*********************************************************
+.TP
+.B \-\-auth\-gen\-token\-secret [file]
+Specifies a file that hold a secret for the HMAC used in
+.B \-\-auth\-gen\-token
+If not present OpenVPN will generate a random secret on startup. This file
+should be used if auth-token should valid after restarting a server or if
+client should be able to roam between multiple OpenVPN server with their
+auth\-token.
+
 .\"*********************************************************
 .TP
 .B \-\-opt\-verify
@@ -5775,6 +5788,17 @@ Servers can use
 .B \-\-tls\-crypt\-v2\-verify
 to specify a metadata verification command.
 .\"*********************************************************
+.TP
+.B \-\-genkey auth\-token [keyfile]
+Generate a new secret that can be used
+with
+.B \-\-auth\-gen\-token\-secret
+
+.B Note:
+this file should be kept secret to the server as anyone
+that access to this file will be to generate auth tokens
+that the OpenVPN server will accept as valid.
+.\"*********************************************************
 .SS TUN/TAP persistent tunnel config mode:
 Available with Linux 2.4.7+.  These options comprise a standalone mode
 of OpenVPN which can be used to create and delete persistent tunnels.
@@ -6986,6 +7010,7 @@ X509_1_C=KG
 OpenVPN allows including files in the main configuration for the
 .B \-\-ca, \-\-cert, \-\-dh, \-\-extra\-certs, \-\-key, \-\-pkcs12, \-\-secret,
 .B \-\-crl\-verify, \-\-http\-proxy\-user\-pass, \-\-tls\-auth,
+.B \-\-auth\-gen\-token\-secret
 .B \-\-tls\-crypt,
 and
 .B \-\-tls\-crypt-v2
src/openvpn/Makefile.am +1 -0
index 30caa01f..3754fd95 100644
@@ -39,6 +39,7 @@ sbin_PROGRAMS = openvpn
 
 openvpn_SOURCES = \
 	argv.c argv.h \
+	auth_token.c auth_token.h \
 	base64.c base64.h \
 	basic.h \
 	buffer.c buffer.h \
src/openvpn/auth_token.c new file +273 -0

273 lines not on this page · raw message

src/openvpn/auth_token.h new file +116 -0

116 lines not on this page · raw message

src/openvpn/init.c +33 -1
index b5a034dc..7ebdddeb 100644
@@ -51,6 +51,7 @@
 #include "ssl_verify.h"
 #include "tls_crypt.h"
 #include "forward.h"
+#include "auth_token.h"
 
 #include "memdbg.h"
 
@@ -1118,6 +1119,11 @@ do_genkey(const struct options *options)
                                            options->tls_crypt_v2_inline);
         return true;
     }
+    else if (options->genkey && options->genkey_type == GENKEY_AUTH_TOKEN)
+    {
+        auth_token_write_server_key_file(options->genkey_filename);
+        return true;
+    }
     else
     {
         return false;
@@ -2534,7 +2540,6 @@ init_crypto_pre(struct context *c, const unsigned int flags)
         rand_ctx_enable_prediction_resistance();
     }
 #endif
-
 }
 
 /*
@@ -2658,6 +2663,24 @@ do_init_tls_wrap_key(struct context *c)
 
 }
 
+#if P2MP_SERVER
+/*
+ * Initialise the auth-token key context
+ */
+static void
+do_init_auth_token_key(struct context *c)
+{
+    if (!c->options.auth_token_generate)
+    {
+        return;
+    }
+
+    auth_token_init_secret(&c->c1.ks.auth_token_key,
+                           c->options.auth_token_secret_file,
+                           c->options.auth_token_secret_file_inline);
+}
+#endif
+
 /*
  * Initialize the persistent component of OpenVPN's TLS mode,
  * which is preserved across SIGUSR1 resets.
@@ -2710,6 +2733,11 @@ do_init_crypto_tls_c1(struct context *c)
         /* initialize tls-auth/crypt/crypt-v2 key */
         do_init_tls_wrap_key(c);
 
+#if P2MP_SERVER
+        /* initialise auth-token crypto support */
+        do_init_auth_token_key(c);
+#endif
+
 #if 0 /* was: #if ENABLE_INLINE_FILES --  Note that enabling this code will break restarts */
         if (options->priv_key_file_inline)
         {
@@ -2883,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_key = c->c1.ks.auth_token_key;
 #endif
 
     to.x509_track = options->x509_track;
@@ -4499,6 +4528,9 @@ inherit_context_child(struct context *dest,
     dest->c1.authname = src->c1.authname;
     dest->c1.keysize = src->c1.keysize;
 
+    /* inherit auth-token */
+    dest->c1.ks.auth_token_key = src->c1.ks.auth_token_key;
+
     /* options */
     dest->options = src->options;
     options_detach(&dest->options);
src/openvpn/openvpn.h +1 -0
index 29d21f0a..900db7e1 100644
@@ -68,6 +68,7 @@ struct key_schedule
     struct key_ctx_bi tls_wrap_key;
     struct key_ctx tls_crypt_v2_server_key;
     struct buffer tls_crypt_v2_wkc;             /**< Wrapped client key */
+    struct key_ctx auth_token_key;
 };
 
 /*
src/openvpn/options.c +21 -1
index 2d3865a6..fbba93c9 100644
@@ -1289,6 +1289,7 @@ show_p2mp_parms(const struct options *o)
     SHOW_BOOL(auth_user_pass_verify_script_via_file);
     SHOW_BOOL(auth_token_generate);
     SHOW_INT(auth_token_lifetime);
+    SHOW_STR(auth_token_secret_file);
 #if PORT_SHARE
     SHOW_STR(port_share_host);
     SHOW_STR(port_share_port);
@@ -2336,7 +2337,11 @@ options_postprocess_verify_ce(const struct options *options, const struct connec
         {
             msg(M_USAGE, "--mode server requires --key-method 2");
         }
-
+        if (options->auth_token_generate && !options->renegotiate_seconds)
+        {
+            msg(M_USAGE, "--auth-gen-token needs a non-infinite "
+                "--renegotiate_seconds setting");
+        }
         {
             const bool ccnr = (options->auth_user_pass_verify_script
                                || PLUGIN_OPTION_LIST(options)
@@ -6771,6 +6776,17 @@ add_option(struct options *options,
         options->auth_token_generate = true;
         options->auth_token_lifetime = p[1] ? positive_atoi(p[1]) : 0;
     }
+    else if (streq(p[0], "auth-gen-token-secret") && p[1] && (!p[2]
+                                                              || (p[2] && streq(p[1], INLINE_FILE_TAG))))
+    {
+        VERIFY_PERMISSION(OPT_P_GENERAL);
+        options->auth_token_secret_file = p[1];
+
+        if (streq(p[1], INLINE_FILE_TAG) && p[2])
+        {
+            options->auth_token_secret_file_inline = p[2];
+        }
+    }
     else if (streq(p[0], "client-connect") && p[1])
     {
         VERIFY_PERMISSION(OPT_P_SCRIPT);
@@ -7546,6 +7562,10 @@ add_option(struct options *options,
                     options->genkey_extra_data = p[3];
                 }
             }
+            else if (streq(p[1], "auth-token"))
+            {
+                options->genkey_type = GENKEY_AUTH_TOKEN;
+            }
             else
             {
                 msg(msglevel, "unknown --genkey type: %s", p[1]);
src/openvpn/options.h +4 -0
index 63f0f4cb..d885f4d9 100644
@@ -181,6 +181,7 @@ enum genkey_type {
     GENKEY_SECRET,
     GENKEY_TLS_CRYPTV2_CLIENT,
     GENKEY_TLS_CRYPTV2_SERVER,
+    GENKEY_AUTH_TOKEN
 };
 
 /* Command line options */
@@ -469,6 +470,9 @@ struct options
     bool auth_user_pass_verify_script_via_file;
     bool auth_token_generate;
     unsigned int auth_token_lifetime;
+    const char *auth_token_secret_file;
+    const char *auth_token_secret_file_inline;
+
 #if PORT_SHARE
     char *port_share_host;
     char *port_share_port;
src/openvpn/push.c +59 -11

106 lines not on this page · raw message

src/openvpn/push.h +8 -0
index 5f6181e7..070782dd 100644
@@ -69,6 +69,14 @@ void send_auth_failed(struct context *c, const char *client_reason);
 
 void send_restart(struct context *c, const char *kill_msg);
 
+/**
+ * Sends a push reply message only containin the auth-token to update
+ * the auth-token on the client
+ *
+ * @param multi  - The tls_multi structure belonging to the instance to push to
+ */
+void send_push_reply_auth_token(struct tls_multi *multi);
+
 #endif
 #endif /* if P2MP */
 #endif /* ifndef PUSH_H */
src/openvpn/ssl.c +2 -5
index abc3c53b..0d79f91e 100644
@@ -59,6 +59,7 @@
 #include "ssl.h"
 #include "ssl_verify.h"
 #include "ssl_backend.h"
+#include "auth_token.h"
 
 #include "memdbg.h"
 
@@ -1368,11 +1369,7 @@ tls_multi_free(struct tls_multi *multi, bool clear)
 
     cert_hash_free(multi->locked_cert_hash_set);
 
-    if (multi->auth_token)
-    {
-        secure_memzero(multi->auth_token, AUTH_TOKEN_SIZE);
-        free(multi->auth_token);
-    }
+    wipe_auth_token(multi);
 
     free(multi->remote_ciphername);
 
src/openvpn/ssl_common.h +22 -14
index 0312c1f8..2c90caa0 100644
@@ -298,7 +298,6 @@ struct tls_options
     /** TLS handshake wrapping state */
     struct tls_wrap_ctx tls_wrap;
 
-    /* frame parameters for TLS control channel */
     struct frame frame;
 
     /* used for username/password authentication */
@@ -306,10 +305,16 @@ struct tls_options
     bool auth_user_pass_verify_script_via_file;
     const char *tmp_dir;
     const char *auth_user_pass_file;
-    bool auth_token_generate;   /**< Generate auth-tokens on successful user/pass auth,
-                                 *   set via options->auth_token_generate. */
+
+#ifdef P2MP_SERVER
+    bool auth_token_generate;   /**< Generate auth-tokens on successful
+                                 * user/pass auth,seet via
+                                 * options->auth_token_generate. */
     unsigned int auth_token_lifetime;
 
+    struct key_ctx auth_token_key;
+#endif
+
     /* use the client-config-dir as a positive authenticator */
     const char *client_config_dir_exclusive;
 
@@ -369,10 +374,6 @@ struct tls_options
 /** @} name Index of key_state objects within a tls_session structure */
 /** @} addtogroup control_processor */
 
-#define AUTH_TOKEN_SIZE 32      /**< Size of server side generated auth tokens.
-                                 *   32 bytes == 256 bits
-                                 */
-
 /**
  * Security parameter state of a single session within a VPN tunnel.
  * @ingroup control_processor
@@ -541,6 +542,20 @@ struct tls_multi
      */
     char *peer_info;
 #endif
+    char *auth_token;    /**< If server sends a generated auth-token,
+                          *   this is the token to use for future
+                          *   user/pass authentications in this session.
+                          */
+    char *auth_token_initial;
+    /**< The first auth-token we sent to a client, for clients that do
+     * not update their auth-token (older OpenVPN3 core versions)
+     */
+#define  AUTH_TOKEN_HMAC_OK              (1<<0)
+    /**< Auth-token sent from client has valid hmac */
+#define  AUTH_TOKEN_EXPIRED              (1<<1)
+    /**< Auth-token sent from client has expired */
+    int auth_token_state_flags;
+    /**< The state of the auth-token sent from the client last time */
 
     /* For P_DATA_V2 */
     uint32_t peer_id;
@@ -548,13 +563,6 @@ struct tls_multi
 
     char *remote_ciphername;    /**< cipher specified in peer's config file */
 
-    char *auth_token;    /**< If server sends a generated auth-token,
-                          *   this is the token to use for future
-                          *   user/pass authentications in this session.
-                          */
-    time_t auth_token_tstamp; /**< timestamp of the generated token */
-    bool auth_token_sent; /**< If server uses --auth-gen-token and
-                           *   token has been sent to client */
     /*
      * Our session objects.
      */
src/openvpn/ssl_verify.c +81 -103

242 lines not on this page · raw message

Signature · 1 line
2.22.0
#19 lore raw

PATCH v7 6/7 Sent indication that a session is expired to clients

In reply to David Sommerseth

From: Arne Schwabe <[email protected]...>

This allows OpenVPN 3 core to fall back to the original authentication method.

This commit changes man_def_auth_set_client_reason to auth_set_client_reason since it now used in more contexts.

Also remove a FIXME about client_reason not being freed, as it is freed in tls_multi_free with auth_set_client_reason(multi, NULL);

Patch V4: Rebase on master
Patch V7: Rebase on master

---
 src/openvpn/auth_token.c |  3 +++
 src/openvpn/ssl.c        |  6 ++----
 src/openvpn/ssl_common.h | 10 +++++-----
 src/openvpn/ssl_verify.c |  8 ++++----
 src/openvpn/ssl_verify.h | 15 ++++++++++-----
 5 files changed, 24 insertions(+), 18 deletions(-)
src/openvpn/auth_token.c +3 -0
index 5568a144..1edc8069 100644
@@ -15,6 +15,7 @@
 #include "push.h"
 #include "integer.h"
 #include "ssl.h"
+#include "ssl_verify.h"
 #include <inttypes.h>
 
 const char *auth_token_pem_name = "OpenVPN auth-token server key";
@@ -378,6 +379,8 @@ verify_auth_token(struct user_pass *up, struct tls_multi *multi,
 
     if (ret & AUTH_TOKEN_EXPIRED)
     {
+        /* Tell client that the session token is expired */
+        auth_set_client_reason(multi, "SESSION: token expired");
         msg(M_INFO, "--auth-token-gen: auth-token from client expired");
     }
     return ret;
src/openvpn/ssl.c +2 -4
index 0d79f91e..4455ebb8 100644
@@ -1349,11 +1349,9 @@ tls_multi_free(struct tls_multi *multi, bool clear)
 
     ASSERT(multi);
 
-#ifdef MANAGEMENT_DEF_AUTH
-    man_def_auth_set_client_reason(multi, NULL);
-
-#endif
 #if P2MP_SERVER
+    auth_set_client_reason(multi, NULL);
+
     free(multi->peer_info);
 #endif
 
src/openvpn/ssl_common.h +5 -5
index 4f4fd599..406601bc 100644
@@ -526,16 +526,16 @@ struct tls_multi
     struct cert_hash_set *locked_cert_hash_set;
 
 #ifdef ENABLE_DEF_AUTH
-    /*
-     * An error message to send to client on AUTH_FAILED
-     */
-    char *client_reason;
-
     /* Time of last call to tls_authentication_status */
     time_t tas_last;
 #endif
 
 #if P2MP_SERVER
+    /*
+     * An error message to send to client on AUTH_FAILED
+     */
+    char *client_reason;
+
     /*
      * A multi-line string of general-purpose info received from peer
      * over control channel.
src/openvpn/ssl_verify.c +4 -4
index 5e98fe8a..65188d23 100644
@@ -803,9 +803,8 @@ cleanup:
 #define ACF_FAILED    3
 #endif
 
-#ifdef MANAGEMENT_DEF_AUTH
 void
-man_def_auth_set_client_reason(struct tls_multi *multi, const char *client_reason)
+auth_set_client_reason(struct tls_multi* multi, const char* client_reason)
 {
     if (multi->client_reason)
     {
@@ -814,11 +813,12 @@ man_def_auth_set_client_reason(struct tls_multi *multi, const char *client_reaso
     }
     if (client_reason && strlen(client_reason))
     {
-        /* FIXME: Last alloc will never be freed */
         multi->client_reason = string_alloc(client_reason, NULL);
     }
 }
 
+#ifdef MANAGEMENT_DEF_AUTH
+
 static inline unsigned int
 man_def_auth_test(const struct key_state *ks)
 {
@@ -1022,7 +1022,7 @@ tls_authenticate_key(struct tls_multi *multi, const unsigned int mda_key_id, con
     if (multi)
     {
         int i;
-        man_def_auth_set_client_reason(multi, client_reason);
+        auth_set_client_reason(multi, client_reason);
         for (i = 0; i < KEY_SCAN_SIZE; ++i)
         {
             struct key_state *ks = multi->key_scan[i];
src/openvpn/ssl_verify.h +10 -5
index 64f27efb..c54b89a6 100644
@@ -224,18 +224,23 @@ struct x509_track
 #ifdef MANAGEMENT_DEF_AUTH
 bool tls_authenticate_key(struct tls_multi *multi, const unsigned int mda_key_id, const bool auth, const char *client_reason);
 
-void man_def_auth_set_client_reason(struct tls_multi *multi, const char *client_reason);
+#endif
 
+#ifdef P2MP_SERVER
+/**
+ * Sets the reason why authentication of a client failed. This be will send to the client
+ * when the AUTH_FAILED message is sent
+ * An example would be "SESSION: Token expired"
+ * @param multi             The multi tls struct
+ * @param client_reason     The string to send to the client as part of AUTH_FAILED
+ */
+void auth_set_client_reason(struct tls_multi* multi, const char* client_reason);
 #endif
 
 static inline const char *
 tls_client_reason(struct tls_multi *multi)
 {
-#ifdef ENABLE_DEF_AUTH
     return multi->client_reason;
-#else
-    return NULL;
-#endif
 }
 
 /** Remove any X509_ env variables from env_set es */
Signature · 1 line
2.22.0
Acked-by on v7 6/7
#20 lore raw

Re: [Openvpn-devel] [PATCH v7 6/7] Sent indication that a session is expired to clients

Quoted 13 lines · Arne Schwabe

From: Arne Schwabe <[email protected]...>

This allows OpenVPN 3 core to fall back to the original authentication method.

This commit changes man_def_auth_set_client_reason to auth_set_client_reason since it now used in more contexts.

Also remove a FIXME about client_reason not being freed, as it is freed in tls_multi_free with auth_set_client_reason(multi, NULL);

Patch V4: Rebase on master
Patch V7: Rebase on master

Quoted 7 lines
---
 src/openvpn/auth_token.c |  3 +++
 src/openvpn/ssl.c        |  6 ++----
 src/openvpn/ssl_common.h | 10 +++++-----
 src/openvpn/ssl_verify.c |  8 ++++----
 src/openvpn/ssl_verify.h | 15 ++++++++++-----
 5 files changed, 24 insertions(+), 18 deletions(-)

This is identical to the previous version, just reference points for the changes are changed - exactly what I'd expect with a rebase.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
Acked-by on v7 4/7
#10 lore raw

Re: [Openvpn-devel] [PATCH v7 4/7] Rewrite auth-token-gen to be based on HMAC based tokens

In reply to Arne Schwabe
Quoted 32 lines · Arne Schwabe

The previous auth-token implementation had a serious problem, especially when paired with an unpatched OpenVPN client that keeps trying the auth-token (commit e61b401a).

The auth-token-gen implementation forgot the auth-token on reconnect, this lead to reconnect with auth-token never working.

This new implementation implements the auth-token in a stateles variant. By using HMAC to sign the auth-token the server can verify if a token has been authenticated and by checking the embedded timestamp in the token it can also verify that the auth-token is still valid.

Using the new config directive auth-gen-token-secret instead of extending auth-gen-token (--auth-gen-token [lifetime] [secret-key]) was chosen to allow inlinening the secret key.

Patch V2: cleaned up code, use refactored read_pem_key_file function Patch V3: clarify some design decision in the commit message Patch V4: Use ephermal_generate_key
Patch V5: Use C99 PRIu64 instead of %lld int printf like statement,
fix strict aliasing
Patch V6: Rebase on master
Patch V7: fix compiling with --disable-server

---
 doc/openvpn.8            |  25 ++++
 src/openvpn/Makefile.am  |   1 +
 src/openvpn/auth_token.c | 273 +++++++++++++++++++++++++++++++++++++++
 src/openvpn/auth_token.h | 116 +++++++++++++++++
 src/openvpn/init.c       |  34 ++++-
 src/openvpn/openvpn.h    |   1 +
 src/openvpn/options.c    |  22 +++-
 src/openvpn/options.h    |   4 +
Quoted 8 lines
 src/openvpn/push.c       |  70 ++++++++--
 src/openvpn/push.h       |   8 ++
 src/openvpn/ssl.c        |   7 +-
 src/openvpn/ssl_common.h |  36 ++++--
 src/openvpn/ssl_verify.c | 184 ++++++++++++--------------
 13 files changed, 646 insertions(+), 135 deletions(-)
 create mode 100644 src/openvpn/auth_token.c
 create mode 100644 src/openvpn/auth_token.h

This looks good. The changes was a bit bigger than expected, but it this (and the rest of the patches) passes compiling on our buildbot rig - including --disable-server.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#11 lore raw

[Openvpn-devel] [PATCH applied] Re: Rewrite auth-token-gen to be based on HMAC based tokens

In reply to Arne Schwabe

Your patch has been applied to the master branch.

I have lightly tested client-side builds and t_client runs (and I'm aware that half our buildbot cloud is down, but I do not expect any system- dependent breakages - compiler flags, possibly, but nothing like "on OpenBSD, <x> will not work").

There's a few typos in the comments, so a native english speaker might want to have a look (and I'd welcome a followup patch) - I've decided to merge it "as it is" for now, though. Get this series done.

commit 1b9a88a2c38a6a29f8ccbec4fd529d7b363bfc06

Author: Arne Schwabe
Date:   Tue Sep 17 14:10:04 2019 +0200
     Rewrite auth-token-gen to be based on HMAC based tokens

     Acked-by: David Sommerseth <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg18818.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#21 lore raw

[Openvpn-devel] [PATCH applied] Re: Sent indication that a session is expired to clients

In reply to Arne Schwabe

Your patch has been applied to the master branch.

This breaks --disable-server (again), but since David sent a patch to remedy this, I'm merging it nonetheless. I'll merge David's patch right away and push both together to avoid needless buildbot fails.

The patch itself looks like a very nice approach to the problem with "how can we communicate authentication fail reasons to the client?" issue that had a few (fairly intrusiv) patch sets flying around... someone needs to go through the open patches and see what has become obsolete.

commit fba0e8b8964d5a1f24182ff4c48b18923b5d7ba8

Author: Arne Schwabe
Date:   Tue Sep 17 14:11:15 2019 +0200
     Sent indication that a session is expired to clients

     Acked-by: David Sommerseth <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg18820.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#22 lore raw

Re: [Openvpn-devel] [PATCH applied] Re: Sent indication that a session is expired to clients

Quoted 5 lines · Gert Doering

The patch itself looks like a very nice approach to the problem with "how can we communicate authentication fail reasons to the client?" issue that had a few (fairly intrusiv) patch sets flying around... someone needs to go through the open patches and see what has become obsolete.

This patch should obsolete the older patches resolving the same issue.

It's a simpler approach, storing the reason in a session context object which is then picked up when sending AUTH_FAILED. I had one more intrusive change, which changed the internal APIs fairly much, an approach not even I didn't really liked that much. I don't think there were any other proposals on the mailing list.

I don't know what the various GUIs does, but they should also now be able to pick up these rejections via the management interface as well; even on 2.4.x clients connecting to a server with this patch.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc