Skip to contentSkip to conversation

Only announce IV_NCP=2 when we are willing to support these ciphers

PATCH Superseded Arne Schwabe 3 participants 27 messages Nov 17, 2019 – Feb 17, 2020 1 message not in the archive

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 Only announce IV_NCP=2 when we are willing to support these ciphers

We currently always announce IV_NCP=2 when we support these ciphers even when we do not accept them. This lead to a server pushing a AES-GCM-128 cipher to clients and the client then rejecting it.

---
 doc/openvpn.8            | 2 ++
 src/openvpn/init.c       | 4 ++++
 src/openvpn/openvpn.h    | 1 +
 src/openvpn/ssl.c        | 4 +++-
 src/openvpn/ssl_common.h | 1 +
 5 files changed, 11 insertions(+), 1 deletion(-)
doc/openvpn.8 +2 -0
index 457c2667..ae24b6c0 100644
@@ -4392,6 +4392,8 @@ NCP server (v2.4+) with "\-\-cipher BF\-CBC" and "\-\-ncp\-ciphers
 AES\-256\-GCM:AES\-256\-CBC" set can either specify "\-\-cipher BF\-CBC" or
 "\-\-cipher AES\-256\-CBC" and both will work.
 
+Note, for using NCP with a OpenVPN 2.4 server this list must include
+the AES\-256\-GCM and AES\-128\-GCM ciphers.
 .\"*********************************************************
 .TP
 .B \-\-ncp\-disable
src/openvpn/init.c +4 -0
index 0bdb0a9c..8f142311 100644
@@ -623,6 +623,7 @@ save_ncp_options(struct context *c)
     c->c1.ciphername = c->options.ciphername;
     c->c1.authname = c->options.authname;
     c->c1.keysize = c->options.keysize;
+    c->c1.ncp_ciphers = c->options.ncp_ciphers;
 }
 
 /* Restores NCP-negotiable options to original values */
@@ -632,6 +633,7 @@ restore_ncp_options(struct context *c)
     c->options.ciphername = c->c1.ciphername;
     c->options.authname = c->c1.authname;
     c->options.keysize = c->c1.keysize;
+    c->options.ncp_ciphers = c->c1.ncp_ciphers;
 }
 
 void
@@ -2827,6 +2829,7 @@ do_init_crypto_tls(struct context *c, const unsigned int flags)
     to.tcp_mode = link_socket_proto_connection_oriented(options->ce.proto);
     to.config_ciphername = c->c1.ciphername;
     to.config_authname = c->c1.authname;
+    to.config_ncp_ciphers = c->c1.ncp_ciphers;
     to.ncp_enabled = options->ncp_enabled;
     to.transition_window = options->transition_window;
     to.handshake_window = options->handshake_window;
@@ -4532,6 +4535,7 @@ inherit_context_child(struct context *dest,
     dest->c1.ciphername = src->c1.ciphername;
     dest->c1.authname = src->c1.authname;
     dest->c1.keysize = src->c1.keysize;
+    dest->c1.ncp_ciphers = src->c1.ncp_ciphers;
 
     /* inherit auth-token */
     dest->c1.ks.auth_token_key = src->c1.ks.auth_token_key;
src/openvpn/openvpn.h +1 -0
index 900db7e1..9e46ad6c 100644
@@ -209,6 +209,7 @@ struct context_1
 
     const char *ciphername;     /**< Data channel cipher from config file */
     const char *authname;       /**< Data channel auth from config file */
+    const char *ncp_ciphers;    /**< NCP Ciphers */
     int keysize;                /**< Data channel keysize from config file */
 #endif
 };
src/openvpn/ssl.c +3 -1
index 4455ebb8..6ca5c79a 100644
@@ -2322,7 +2322,9 @@ push_peer_info(struct buffer *buf, struct tls_session *session)
 
         /* support for Negotiable Crypto Parameters */
         if (session->opt->ncp_enabled
-            && (session->opt->mode == MODE_SERVER || session->opt->pull))
+            && (session->opt->mode == MODE_SERVER || session->opt->pull)
+            && tls_item_in_cipher_list("AES-128-GCM", session->opt->config_ncp_ciphers)
+            && tls_item_in_cipher_list("AES-256-GCM", session->opt->config_ncp_ciphers))
         {
             buf_printf(&out, "IV_NCP=2\n");
         }
src/openvpn/ssl_common.h +1 -0
index 8dd08862..fb82f610 100644
@@ -290,6 +290,7 @@ struct tls_options
 
     const char *config_ciphername;
     const char *config_authname;
+    const char *config_ncp_ciphers;
     bool ncp_enabled;
 
     bool tls_crypt_v2;
Signature · 1 line
2.22.0
#1 lore raw

PATCH 2/4 Implement dynamic NCP negotiation

Our current NCP version is flawed in the way that it can only indicate support for AES-256-GCM and AES-128-GCM. While configuring client and server with different ncp-cipher configuration directive works, the server will blindly push the first cipher of that list to the client if the client sends IV_NCP=2.

This patches introduces IV_CIPHER sent from the client to the server that contains the full list of cipers that the client is willing to support (*). The server will then pick the first ciphr of its own ncp-cipher list that the client indicates support for.

We choose a textual representation of the ciphers instead of a binary sinc a binary would mean that we would need to have a central place to maintain a mapping between binary and the actual cipher name. Also the normal ncp-cipher list is quite short, so this should not be problem. It also provides the freedom to negioate new ciphers from SSL libraries without the need to upgrade OpenVPN/its binary cipher table.

* the client/server will also accpt the cipher specifid in --cipher but eventually we want to get rid of --ciper. So this patch keeps a reasonable backwards compatbility (especially poor man's NCP) but does not encourage to use --cipher for negotiation in documentation or warning messages.

---
 doc/openvpn.8            |  10 +++-
 src/openvpn/init.c       |   1 -
 src/openvpn/options.c    |   1 +
 src/openvpn/push.c       |  32 +++++++----
 src/openvpn/ssl.c        | 111 +++++++++++++++++++++++++++++++++++++--
 src/openvpn/ssl.h        |  34 ++++++++++++
 src/openvpn/ssl_common.h |   1 -
 7 files changed, 172 insertions(+), 18 deletions(-)
doc/openvpn.8 +8 -2
index ae24b6c0..4f0df786 100644
@@ -3111,6 +3111,11 @@ IV_NCP=2 \-\- negotiable ciphers, client supports
 pushed by the server, a value of 2 or greater indicates client
 supports AES\-GCM\-128 and AES\-GCM\-256.
 
+IV_CIPHERS=<ncp\-ciphers> \-\- the client pushes the list of configured
+ciphers with the
+\.B -\-\ncp\-ciphers
+option to the server.
+
 IV_GUI_VER=<gui_id> <version> \-\- the UI version of a UI if one is
 running, for example "de.blinkt.openvpn 0.5.47" for the
 Android app.
@@ -4368,7 +4373,8 @@ is a colon\-separated list of ciphers, and defaults to
 
 For servers, the first cipher from
 .B cipher_list
-will be pushed to clients that support cipher negotiation.
+that is also supported by the client will be pushed to clients
+that support cipher negotiation.
 
 Cipher negotiation is enabled in client\-server mode only.  I.e. if
 .B \-\-mode
@@ -4392,7 +4398,7 @@ NCP server (v2.4+) with "\-\-cipher BF\-CBC" and "\-\-ncp\-ciphers
 AES\-256\-GCM:AES\-256\-CBC" set can either specify "\-\-cipher BF\-CBC" or
 "\-\-cipher AES\-256\-CBC" and both will work.
 
-Note, for using NCP with a OpenVPN 2.4 server this list must include
+Note, for using NCP with a OpenVPN 2.4 peer this list must include
 the AES\-256\-GCM and AES\-128\-GCM ciphers.
 .\"*********************************************************
 .TP
src/openvpn/init.c +0 -1
index 8f142311..5058b300 100644
@@ -2828,7 +2828,6 @@ do_init_crypto_tls(struct context *c, const unsigned int flags)
     to.replay_time = options->replay_time;
     to.tcp_mode = link_socket_proto_connection_oriented(options->ce.proto);
     to.config_ciphername = c->c1.ciphername;
-    to.config_authname = c->c1.authname;
     to.config_ncp_ciphers = c->c1.ncp_ciphers;
     to.ncp_enabled = options->ncp_enabled;
     to.transition_window = options->transition_window;
src/openvpn/options.c +1 -0
index c282b582..9be5a826 100644
@@ -45,6 +45,7 @@
 #include "shaper.h"
 #include "crypto.h"
 #include "ssl.h"
+#include "ssl_ncp.h"
 #include "options.h"
 #include "misc.h"
 #include "socket.h"
src/openvpn/push.c +23 -9
index 368b6920..1f1e1f0d 100644
@@ -429,7 +429,7 @@ prepare_push_reply(struct context *c, struct gc_arena *gc,
     prepare_auth_token_push_reply(tls_multi, gc, push_list);
 
     /* Push cipher if client supports Negotiable Crypto Parameters */
-    if (tls_peer_info_ncp_ver(peer_info) >= 2 && o->ncp_enabled)
+    if (o->ncp_enabled)
     {
         /* if we have already created our key, we cannot *change* our own
          * cipher -> so log the fact and push the "what we have now" cipher
@@ -445,17 +445,31 @@ prepare_push_reply(struct context *c, struct gc_arena *gc,
         }
         else
         {
-            /* Push the first cipher from --ncp-ciphers to the client.
-             * TODO: actual negotiation, instead of server dictatorship. */
-            char *push_cipher = string_alloc(o->ncp_ciphers, &o->gc);
-            o->ciphername = strtok(push_cipher, ":");
+            /*
+             * Push the first cipher from --ncp-ciphers to the client that
+             * the client announces to be supporting.
+             */
+            char *push_cipher = ncp_get_best_cipher(o->ncp_ciphers, o->ciphername,
+                                                    peer_info,
+                                                    tls_multi->remote_ciphername,
+                                                    &o->gc);
+
+            if (push_cipher)
+            {
+                o->ciphername = push_cipher;
+            }
+            else
+            {
+                char *peer_ciphers = tls_peer_ncp_list(peer_info);
+                msg(M_INFO, "PUSH: No common cipher between server and client."
+                    "Expect this connection not to work. "
+                    "Server ncp-ciphers: '%s', client supported ciphers '%s'",
+                    o->ncp_ciphers, peer_ciphers);
+                free(peer_ciphers);
+            }
         }
         push_option_fmt(gc, push_list, M_USAGE, "cipher %s", o->ciphername);
     }
-    else if (o->ncp_enabled)
-    {
-        tls_poor_mans_ncp(o, tls_multi->remote_ciphername);
-    }
 
     return true;
 }
src/openvpn/ssl.c +106 -5

136 lines not on this page · raw message

src/openvpn/ssl.h +34 -0
index a944ca3a..ad3b46d7 100644
@@ -512,6 +512,40 @@ tls_get_peer_info(const struct tls_multi *multi)
  */
 int tls_peer_info_ncp_ver(const char *peer_info);
 
+/**
+ * Iterates through the ciphers in server_list and return the first
+ * cipher that is also supported by the peer according to the IV_NCP
+ * and IV_CIPHER values in peer_info.
+ *
+ * We also accept a cipher that is the remote cipher of the client for
+ * "Poor man's NCP": Use peer cipher if it is an allowed (NCP) cipher.
+ * Allows non-NCP peers to upgrade their cipher individually.
+ *
+ * Make sure to call tls_session_update_crypto_params() after calling this
+ * function.
+ *
+ * @param gc   gc arena that is ONLY used to allocate the returned string
+ *
+ * @returns NULL if no common cipher is available, otherwise the best common
+ * cipher
+ */
+char *
+ncp_get_best_cipher(const char *server_list, const char *server_cipher,
+                    const char *peer_info, const char *remote_cipher,
+                    struct gc_arena *gc);
+
+
+/**
+ * Returns the support cipher list from the peer according to the IV_NCP
+ * and IV_CIPHER values in peer_info.
+ *
+ * @returns Either a string containing the ncp list that needs to be
+ * free()ed after use. If no information is available an empty string
+ * ("") is returned.
+ */
+char *
+tls_peer_ncp_list(const char *peer_info);
+
 /**
  * Check whether the ciphers in the supplied list are supported.
  *
src/openvpn/ssl_common.h +0 -1
index fb82f610..998ea3c4 100644
@@ -289,7 +289,6 @@ struct tls_options
     bool tcp_mode;
 
     const char *config_ciphername;
-    const char *config_authname;
     const char *config_ncp_ciphers;
     bool ncp_enabled;
 
Signature · 1 line
2.22.0
#7 lore raw

PATCH 3/4 Move NCP related function into a seperate file and add unit tests

In reply to Arne Schwabe

This allows unit test the NCP functions. The ssl.c file has too many dependencies to make unit testing of it viable.

---
 src/openvpn/Makefile.am              |   1 +
 src/openvpn/init.c                   |   1 +
 src/openvpn/multi.c                  |   1 +
 src/openvpn/push.c                   |   1 +
 src/openvpn/ssl.c                    | 172 +-------------------
 src/openvpn/ssl.h                    |  65 --------
 src/openvpn/ssl_ncp.c                | 225 +++++++++++++++++++++++++++
 src/openvpn/ssl_ncp.h                | 101 ++++++++++++
 tests/unit_tests/openvpn/Makefile.am |  20 ++-
 tests/unit_tests/openvpn/test_ncp.c  | 182 ++++++++++++++++++++++
 10 files changed, 533 insertions(+), 236 deletions(-)
 create mode 100644 src/openvpn/ssl_ncp.c
 create mode 100644 src/openvpn/ssl_ncp.h
 create mode 100644 tests/unit_tests/openvpn/test_ncp.c
src/openvpn/Makefile.am +1 -0
index a091ffc2..e0357997 100644
@@ -116,6 +116,7 @@ openvpn_SOURCES = \
 	ssl.c ssl.h  ssl_backend.h \
 	ssl_openssl.c ssl_openssl.h \
 	ssl_mbedtls.c ssl_mbedtls.h \
+	ssl_ncp.c ssl_ncp.h \
 	ssl_common.h \
 	ssl_verify.c ssl_verify.h ssl_verify_backend.h \
 	ssl_verify_openssl.c ssl_verify_openssl.h \
src/openvpn/init.c +1 -0
index 5058b300..13d05f65 100644
@@ -49,6 +49,7 @@
 #include "ping.h"
 #include "mstats.h"
 #include "ssl_verify.h"
+#include "ssl_ncp.h"
 #include "tls_crypt.h"
 #include "forward.h"
 #include "auth_token.h"
src/openvpn/multi.c +1 -0
index d594dd25..b82c68c4 100644
@@ -45,6 +45,7 @@
 #include "gremlin.h"
 #include "mstats.h"
 #include "ssl_verify.h"
+#include "ssl_ncp.h"
 #include "vlan.h"
 #include <inttypes.h>
 
src/openvpn/push.c +1 -0
index 1f1e1f0d..38069cb5 100644
@@ -33,6 +33,7 @@
 #include "options.h"
 #include "ssl.h"
 #include "ssl_verify.h"
+#include "ssl_ncp.h"
 #include "manage.h"
 
 #include "memdbg.h"
src/openvpn/ssl.c +2 -170

202 lines not on this page · raw message

src/openvpn/ssl.h +0 -65

77 lines not on this page · raw message

src/openvpn/ssl_ncp.c new file +225 -0

225 lines not on this page · raw message

src/openvpn/ssl_ncp.h new file +101 -0

101 lines not on this page · raw message

tests/unit_tests/openvpn/Makefile.am +19 -1
index 60e84639..789a9455 100644
@@ -6,7 +6,7 @@ if HAVE_LD_WRAP_SUPPORT
 test_binaries += argv_testdriver buffer_testdriver
 endif
 
-test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver
+test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver
 if HAVE_LD_WRAP_SUPPORT
 test_binaries += tls_crypt_testdriver
 endif
@@ -110,3 +110,21 @@ auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \
 	$(openvpn_srcdir)/packet_id.c \
 	$(openvpn_srcdir)/platform.c \
 	$(openvpn_srcdir)/base64.c
+
+
+ncp_testdriver_CFLAGS  = @TEST_CFLAGS@ \
+	-I$(openvpn_includedir) -I$(compat_srcdir) -I$(openvpn_srcdir) \
+	$(OPTIONAL_CRYPTO_CFLAGS)
+ncp_testdriver_LDFLAGS = @TEST_LDFLAGS@ \
+	$(OPTIONAL_CRYPTO_LIBS)
+
+ncp_testdriver_SOURCES = test_ncp.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
+
+
tests/unit_tests/openvpn/test_ncp.c new file +182 -0

182 lines not on this page · raw message

Signature · 1 line
2.22.0
#12 lore raw

PATCH 4/4 Normalise ncp-ciphers option and restrict it to 127 bytes

In reply to Arne Schwabe

In scenarios of mbed TLS vs OpenSSL we already normalise the ciphers that are send via the wire protocol via OCC to not have a mismatch warning between server and client. This is done by translate_cipher_name_from_openvpn. The same applies also to the ncp-ciphers list. Specifying non normalised names in ncp-ciphers will cause negotation not to succeed if ciphers are not in the same form. Therefore we will normalise the ciphers in options_postmutate.

The alternative and a lot less user friendly alternative would be to bail if on of the ciphers in ncp-ciphers is not in its normalised form.

Also restrict the ncp-ciphers list to 127. This is somewhat arbitrary but should prevent too large IV_CIPHER messages and problems sending those. The server will accept also large IV_CIPHER values from clients.

---
 doc/openvpn.8                       |  3 ++
 src/openvpn/options.c               | 14 +++++---
 src/openvpn/ssl_ncp.c               | 55 +++++++++++++++++++++++++----
 src/openvpn/ssl_ncp.h               | 19 ++++++++--
 tests/unit_tests/openvpn/test_ncp.c | 40 ++++++++++++++-------
 5 files changed, 104 insertions(+), 27 deletions(-)
doc/openvpn.8 +3 -0
index 4f0df786..a71b1c14 100644
@@ -4400,6 +4400,9 @@ AES\-256\-GCM:AES\-256\-CBC" set can either specify "\-\-cipher BF\-CBC" or
 
 Note, for using NCP with a OpenVPN 2.4 peer this list must include
 the AES\-256\-GCM and AES\-128\-GCM ciphers.
+
+This list is restricted to be 127 chars long after conversion to OpenVPN
+ciphers.
 .\"*********************************************************
 .TP
 .B \-\-ncp\-disable
src/openvpn/options.c +9 -5
index 9be5a826..fd069c75 100644
@@ -2500,11 +2500,6 @@ options_postprocess_verify_ce(const struct options *options, const struct connec
     }
 #endif /* P2MP_SERVER */
 
-    if (options->ncp_enabled && !tls_check_ncp_cipher_list(options->ncp_ciphers))
-    {
-        msg(M_USAGE, "NCP cipher list contains unsupported ciphers.");
-    }
-
     if (options->keysize)
     {
         msg(M_WARN, "WARNING: --keysize is DEPRECATED and will be removed in OpenVPN 2.6");
@@ -3079,6 +3074,15 @@ options_postprocess_mutate(struct options *o)
 
     options_postprocess_mutate_invariant(o);
 
+    if (o->ncp_enabled)
+    {
+        o->ncp_ciphers = mutate_ncp_cipher_list(o->ncp_ciphers, &o->gc);
+        if (o->ncp_ciphers == NULL)
+        {
+            msg(M_USAGE, "NCP cipher list contains unsupported ciphers or is too long.");
+        }
+    }
+
     if (o->remote_list && !o->connection_list)
     {
         /*
src/openvpn/ssl_ncp.c +48 -7

75 lines not on this page · raw message

src/openvpn/ssl_ncp.h +17 -2
index 82d008d8..62822e89 100644
@@ -87,10 +87,17 @@ tls_peer_ncp_list(const char *peer_info);
  * Check whether the ciphers in the supplied list are supported.
  *
  * @param list          Colon-separated list of ciphers
+ * @parms gc            gc_arena to allocate the returned string
  *
- * @returns true iff all ciphers in list are supported.
+ * @returns             colon separated string of normalised (via
+ *                      translate_cipher_name_from_openvpn) and
+ *                      zero terminated string iff all ciphers
+ *                      in list are supported and the total length
+ *                      is short than MAX_NCP_CIPHERS_LENGTH. NULL
+ *                      otherwise.
  */
-bool tls_check_ncp_cipher_list(const char *list);
+char *
+mutate_ncp_cipher_list(const char *list, struct gc_arena *gc);
 
 /**
  * Return true iff item is present in the colon-separated zero-terminated
@@ -98,4 +105,12 @@ bool tls_check_ncp_cipher_list(const char *list);
  */
 bool tls_item_in_cipher_list(const char *item, const char *list);
 
+/**
+ * The maximum length of a ncp-cipher string that is accepted.
+ *
+ * Since this list needs to be pushed as IV_CIPHERS, we are conservative
+ * about its length.
+ */
+#define MAX_NCP_CIPHERS_LENGTH 127
+
 #endif /* ifndef OPENVPN_SSL_NCP_H */
tests/unit_tests/openvpn/test_ncp.c +27 -13
index e71f4825..7684eed4 100644
@@ -47,10 +47,24 @@ const char *aes_ciphers = "AES-256-GCM:AES-128-GCM";
 static void
 test_check_ncp_ciphers_list(void **state)
 {
-    assert_true(tls_check_ncp_cipher_list(aes_ciphers));
-    assert_true(tls_check_ncp_cipher_list(bf_chacha));
-    assert_false(tls_check_ncp_cipher_list("vollbit"));
-    assert_false(tls_check_ncp_cipher_list("AES-256-GCM:vollbit"));
+    struct gc_arena gc = gc_new();
+
+    assert_string_equal(mutate_ncp_cipher_list(aes_ciphers, &gc), aes_ciphers);
+
+    assert_string_equal(mutate_ncp_cipher_list(bf_chacha, &gc), bf_chacha);
+
+    assert_string_equal(mutate_ncp_cipher_list("BF-cbc:ChaCha20-Poly1305", &gc),
+                        bf_chacha);
+
+
+    assert_ptr_equal(mutate_ncp_cipher_list("vollbit", &gc), NULL);
+    assert_ptr_equal(mutate_ncp_cipher_list("AES-256-GCM:vollbit", &gc), NULL);
+    assert_ptr_equal(mutate_ncp_cipher_list("", &gc), NULL);
+
+    assert_ptr_equal(mutate_ncp_cipher_list(
+                         "ChaCha20-Poly1305:ChaCha20-Poly1305:ChaCha20-Poly1305:"
+                         "ChaCha20-Poly1305:ChaCha20-Poly1305:ChaCha20-Poly1305:"
+                         "ChaCha20-Poly1305", &gc), NULL);
 }
 
 static void
@@ -64,7 +78,7 @@ test_extract_client_ciphers(void **state)
     assert_string_equal(aes_ciphers,peer_list);
     assert_true(tls_peer_supports_ncp(client_peer_info));
     free(peer_list);
-                
+
     client_peer_info = "foo=bar\nIV_foo=y\nIV_NCP=2\nIV_CIPHERS=BF-CBC";
     peer_list = tls_peer_ncp_list(client_peer_info);
     assert_string_equal("BF-CBC", peer_list);
@@ -101,8 +115,8 @@ test_poor_man(void **state)
     struct gc_arena gc = gc_new();
     char *best_cipher;
 
-    const char *serverlist="CHACHA20_POLY1305:AES-128-GCM";
-    
+    const char *serverlist = "CHACHA20_POLY1305:AES-128-GCM";
+
     best_cipher = ncp_get_best_cipher(serverlist, "BF-CBC",
                                       "IV_YOLO=NO\nIV_BAR=7",
                                       "BF-CBC", &gc);
@@ -131,8 +145,8 @@ test_ncp_best(void **state)
     struct gc_arena gc = gc_new();
     char *best_cipher;
 
-    const char *serverlist="CHACHA20_POLY1305:AES-128-GCM:AES-256-GCM";
-    
+    const char *serverlist = "CHACHA20_POLY1305:AES-128-GCM:AES-256-GCM";
+
     best_cipher = ncp_get_best_cipher(serverlist, "BF-CBC",
                                       "IV_YOLO=NO\nIV_NCP=2\nIV_BAR=7",
                                       "BF-CBC", &gc);
@@ -150,7 +164,7 @@ test_ncp_best(void **state)
     best_cipher = ncp_get_best_cipher(serverlist, "BF-CBC",
                                       "IV_CIPHERS=AES-128-GCM",
                                       "AES-256-CBC", &gc);
-    
+
 
     assert_string_equal(best_cipher, "AES-128-GCM");
 
@@ -167,16 +181,16 @@ test_ncp_best(void **state)
 
 
 
-
 const struct CMUnitTest ncp_tests[] = {
     cmocka_unit_test(test_check_ncp_ciphers_list),
-    cmocka_unit_test(test_extract_client_ciphers),    
+    cmocka_unit_test(test_extract_client_ciphers),
     cmocka_unit_test(test_poor_man),
     cmocka_unit_test(test_ncp_best)
 };
 
 
-int main(void)
+int
+main(void)
 {
     return cmocka_run_group_tests(ncp_tests, NULL, NULL);
 }
Signature · 1 line
2.22.0
#19 lore raw

[Openvpn-devel] [PATCH 5/4] Add ncp files to Visual studio print

In reply to Arne Schwabe
---
 src/openvpn/openvpn.vcxproj | 2 ++
 1 file changed, 2 insertions(+)
src/openvpn/openvpn.vcxproj +2 -0
index 7446d97d..b3d35ba2 100644
@@ -191,6 +191,7 @@
     <ClCompile Include="socks.c" />
     <ClCompile Include="ssl.c" />
     <ClCompile Include="ssl_openssl.c" />
+    <ClCompile Include="ssl_ncp.c" />
     <ClCompile Include="ssl_verify.c" />
     <ClCompile Include="ssl_verify_openssl.c" />
     <ClCompile Include="status.c" />
@@ -276,6 +277,7 @@
     <ClInclude Include="ssl.h" />
     <ClInclude Include="ssl_backend.h" />
     <ClInclude Include="ssl_common.h" />
+    <ClInclude Include="ssl_ncp.h" />
     <ClInclude Include="ssl_openssl.h" />
     <ClInclude Include="ssl_verify.h" />
     <ClInclude Include="ssl_verify_backend.h" />
Signature · 1 line
2.22.0
#20 lore raw

[Openvpn-devel] [PATCH 6/4] Add strsep compat function

Some operating system do not have the strsep function. Since this API is more "modern" (4.4BSD) than strtok, add it as compat function.

At least Windows is missing strsep. FreeBSD, Linux, macOS and OpenSolaris should not need the compat function.

---
 configure.ac               |  2 +-
 src/compat/Makefile.am     |  1 +
 src/compat/compat-strsep.c | 61 ++++++++++++++++++++++++++++++++++++++
 src/compat/compat.h        |  4 +++
 src/compat/compat.vcxproj  |  3 +-
 5 files changed, 69 insertions(+), 2 deletions(-)
 create mode 100644 src/compat/compat-strsep.c
configure.ac +1 -1
index 807804e5..a9fd8e77 100644
@@ -655,7 +655,7 @@ AC_CHECK_FUNCS([ \
 	ctime memset vsnprintf strdup \
 	setsid chdir putenv getpeername unlink \
 	chsize ftruncate execve getpeereid umask basename dirname access \
-	epoll_create \
+	epoll_create strsep \
 ])
 
 AC_CHECK_LIB(
src/compat/Makefile.am +1 -0
index b51f661e..2e94e943 100644
@@ -30,4 +30,5 @@ libcompat_la_SOURCES = \
 	compat-inet_ntop.c \
 	compat-inet_pton.c \
 	compat-lz4.c compat-lz4.h \
+	compat-strsep.c \
 	compat-versionhelpers.h
src/compat/compat-strsep.c new file +61 -0

61 lines not on this page · raw message

src/compat/compat.h +4 -0
index d5228989..592881df 100644
@@ -70,4 +70,8 @@ int inet_pton(int af, const char *src, void *dst);
 
 #endif
 
+#ifndef HAVE_STRSEP
+char* strsep(char **stringp, const char *delim);
+#endif
+
 #endif /* COMPAT_H */
src/compat/compat.vcxproj +2 -1
index e388008a..0c4c7b0f 100644
@@ -102,6 +102,7 @@
     <ClCompile Include="compat-inet_pton.c" />
     <ClCompile Include="compat-daemon.c" />
     <ClCompile Include="compat-lz4.c" />
+    <ClCompile Include="compat-strsep.c" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="compat.h" />
@@ -115,4 +116,4 @@
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
Signature · 1 line
2.22.0
#14 lore raw

Re: [Openvpn-devel] [PATCH 4/4] Normalise ncp-ciphers option and restrict it to 127 bytes

In reply to a message not in the archive
Quoted 8 lines

Second thing, more of a comment: 127 feels really low.  'AES-256-GCM' is 11 characters, so 127 / 12 (11 chars and a separator) says you're limiting to about 10 ciphers.  If I do openvpn --show-ciphers there's a LOT of data there.  I'd think, for future-proofing, you'd want to allow for a lot more possibilities.  Just an opinion though.

The main problem is the wire protocol at the moment. The whole packet with IVs has to fit into one control channel packet with 1280 bytes. So I want to be conservative here.

And limiting to 10 ciphers should be more than enough. I don't think any reasonable setup should have that many allowed ciphers. At the moment we have AES-GCM-256 or AES-GCM-128 and ChaCha20-Poly1305. Maybe 2 others. For your VPN setup you probably pick one of those, maybe 2. Then there is still more than enough room for the future expansions.

And if I look at show-ciphers of my OpenSSL 1.1.1 compiled OpenVPN and ignore duplicate/weak ciphers and limit myself to one block size, the list is not very long:

ARIA-256-CBC, ChaCha20-Poly1305, AES-256-GCM, CAMELLIA-256-CBC, SEED-CBC, SM4-CBC.

Arne

#21 lore raw

Re: [Openvpn-devel] [PATCH 5/4] Add ncp files to Visual studio print

In reply to Arne Schwabe

Am 17.11.19 um 22:23 schrieb Arne Schwabe:

Quoted 19 lines
---
 src/openvpn/openvpn.vcxproj | 2 ++
 1 file changed, 2 insertions(+)
src/openvpn/openvpn.vcxproj +1 -0
index 7446d97d..b3d35ba2 100644
@@ -191,6 +191,7 @@
     <ClCompile Include="socks.c" />
     <ClCompile Include="ssl.c" />
     <ClCompile Include="ssl_openssl.c" />
+    <ClCompile Include="ssl_ncp.c" />
     <ClCompile Include="ssl_verify.c" />
     <ClCompile Include="ssl_verify_openssl.c" />
     <ClCompile Include="status.c" />

src/openvpn/openvpn.vcxproj line 283

Quoted 7 lines
src/openvpn/openvpn.vcxproj +1 -0
@@ -276,6 +277,7 @@
     <ClInclude Include="ssl.h" />
     <ClInclude Include="ssl_backend.h" />
     <ClInclude Include="ssl_common.h" />
+    <ClInclude Include="ssl_ncp.h" />
     <ClInclude Include="ssl_openssl.h" />
     <ClInclude Include="ssl_verify.h" />
     <ClInclude Include="ssl_verify_backend.h" />

Note this patch can be merged into the 4/4 patch. I just did not want to resend 4/4 for this tiny patch. Should a V2 of 4/4 be needed, I will include this one into it.

Arne

#23 lore raw
In reply to Arne Schwabe

Hi,

Finally found some time to start looking at this patch set.

Quoted 39 lines · Arne Schwabe

We currently always announce IV_NCP=2 when we support these ciphers even when we do not accept them. This lead to a server pushing a AES-GCM-128 cipher to clients and the client then rejecting it.

---
 doc/openvpn.8            | 2 ++
 src/openvpn/init.c       | 4 ++++
 src/openvpn/openvpn.h    | 1 +
 src/openvpn/ssl.c        | 4 +++-
 src/openvpn/ssl_common.h | 1 +
 5 files changed, 11 insertions(+), 1 deletion(-)
doc/openvpn.8 +2 -0
index 457c2667..ae24b6c0 100644
@@ -4392,6 +4392,8 @@ NCP server (v2.4+) with "\-\-cipher BF\-CBC" and "\-\-ncp\-ciphers
 AES\-256\-GCM:AES\-256\-CBC" set can either specify "\-\-cipher BF\-CBC" or
 "\-\-cipher AES\-256\-CBC" and both will work.
 
+Note, for using NCP with a OpenVPN 2.4 server this list must include
+the AES\-256\-GCM and AES\-128\-GCM ciphers.
 .\"*********************************************************
 .TP
 .B \-\-ncp\-disable
src/openvpn/init.c +1 -0
index 0bdb0a9c..8f142311 100644
@@ -623,6 +623,7 @@ save_ncp_options(struct context *c)
     c->c1.ciphername = c->options.ciphername;
     c->c1.authname = c->options.authname;
     c->c1.keysize = c->options.keysize;
+    c->c1.ncp_ciphers = c->options.ncp_ciphers;
 }
 
 /* Restores NCP-negotiable options to original values */

src/openvpn/init.c restore_ncp_options(struct context *c) · line 637

Quoted 5 lines
src/openvpn/init.c +1 -0
@@ -632,6 +633,7 @@ restore_ncp_options(struct context *c)
     c->options.ciphername = c->c1.ciphername;
     c->options.authname = c->c1.authname;
     c->options.keysize = c->c1.keysize;
+    c->options.ncp_ciphers = c->c1.ncp_ciphers;
 }

options->ncp_ciphers itself is not negotiable, and thus does not need restoring, I would think.

Quoted 50 lines
src/openvpn/init.c +2 -0
 void
@@ -2827,6 +2829,7 @@ do_init_crypto_tls(struct context *c, const unsigned int flags)
     to.tcp_mode = link_socket_proto_connection_oriented(options->ce.proto);
     to.config_ciphername = c->c1.ciphername;
     to.config_authname = c->c1.authname;
+    to.config_ncp_ciphers = c->c1.ncp_ciphers;
     to.ncp_enabled = options->ncp_enabled;
     to.transition_window = options->transition_window;
     to.handshake_window = options->handshake_window;
@@ -4532,6 +4535,7 @@ inherit_context_child(struct context *dest,
     dest->c1.ciphername = src->c1.ciphername;
     dest->c1.authname = src->c1.authname;
     dest->c1.keysize = src->c1.keysize;
+    dest->c1.ncp_ciphers = src->c1.ncp_ciphers;
 
     /* inherit auth-token */
     dest->c1.ks.auth_token_key = src->c1.ks.auth_token_key;
src/openvpn/openvpn.h +1 -0
index 900db7e1..9e46ad6c 100644
@@ -209,6 +209,7 @@ struct context_1
 
     const char *ciphername;     /**< Data channel cipher from config file */
     const char *authname;       /**< Data channel auth from config file */
+    const char *ncp_ciphers;    /**< NCP Ciphers */
     int keysize;                /**< Data channel keysize from config file */
 #endif
 };
src/openvpn/ssl.c +3 -1
index 4455ebb8..6ca5c79a 100644
@@ -2322,7 +2322,9 @@ push_peer_info(struct buffer *buf, struct tls_session *session)
 
         /* support for Negotiable Crypto Parameters */
         if (session->opt->ncp_enabled
-            && (session->opt->mode == MODE_SERVER || session->opt->pull))
+            && (session->opt->mode == MODE_SERVER || session->opt->pull)
+            && tls_item_in_cipher_list("AES-128-GCM", session->opt->config_ncp_ciphers)
+            && tls_item_in_cipher_list("AES-256-GCM", session->opt->config_ncp_ciphers))
         {
             buf_printf(&out, "IV_NCP=2\n");
         }
src/openvpn/ssl_common.h +0 -0
index 8dd08862..fb82f610 100644

src/openvpn/ssl_common.h struct tls_options · line 296

Quoted 7 lines
src/openvpn/ssl_common.h +1 -0
@@ -290,6 +290,7 @@ struct tls_options
 
     const char *config_ciphername;
     const char *config_authname;
+    const char *config_ncp_ciphers;
     bool ncp_enabled;
 
     bool tls_crypt_v2;

Otherwise this makes sense and looks good.

-Steffan

#24 lore raw

PATCH v2 1/4 Only announce IV_NCP=2 when we are willing to support these ciphers

We currently always announce IV_NCP=2 when we support these ciphers even when we do not accept them. This lead to a server pushing a AES-GCM-128 cipher to clients and the client then rejecting it.

Patch V2: Remove unecessary restoring of ncp_ciphers

---
 doc/openvpn.8            | 2 ++
 src/openvpn/init.c       | 3 +++
 src/openvpn/openvpn.h    | 1 +
 src/openvpn/ssl.c        | 4 +++-
 src/openvpn/ssl_common.h | 1 +
 5 files changed, 10 insertions(+), 1 deletion(-)
doc/openvpn.8 +2 -0
index 8feb3b9c..b8f2f042 100644
@@ -4398,6 +4398,8 @@ NCP server (v2.4+) with "\-\-cipher BF\-CBC" and "\-\-ncp\-ciphers
 AES\-256\-GCM:AES\-256\-CBC" set can either specify "\-\-cipher BF\-CBC" or
 "\-\-cipher AES\-256\-CBC" and both will work.
 
+Note, for using NCP with a OpenVPN 2.4 server this list must include
+the AES\-256\-GCM and AES\-128\-GCM ciphers.
 .\"*********************************************************
 .TP
 .B \-\-ncp\-disable
src/openvpn/init.c +3 -0
index 04207b61..d83b42b0 100644
@@ -623,6 +623,7 @@ save_ncp_options(struct context *c)
     c->c1.ciphername = c->options.ciphername;
     c->c1.authname = c->options.authname;
     c->c1.keysize = c->options.keysize;
+    c->c1.ncp_ciphers = c->options.ncp_ciphers;
 }
 
 /* Restores NCP-negotiable options to original values */
@@ -2827,6 +2828,7 @@ do_init_crypto_tls(struct context *c, const unsigned int flags)
     to.tcp_mode = link_socket_proto_connection_oriented(options->ce.proto);
     to.config_ciphername = c->c1.ciphername;
     to.config_authname = c->c1.authname;
+    to.config_ncp_ciphers = c->c1.ncp_ciphers;
     to.ncp_enabled = options->ncp_enabled;
     to.transition_window = options->transition_window;
     to.handshake_window = options->handshake_window;
@@ -4532,6 +4534,7 @@ inherit_context_child(struct context *dest,
     dest->c1.ciphername = src->c1.ciphername;
     dest->c1.authname = src->c1.authname;
     dest->c1.keysize = src->c1.keysize;
+    dest->c1.ncp_ciphers = src->c1.ncp_ciphers;
 
     /* inherit auth-token */
     dest->c1.ks.auth_token_key = src->c1.ks.auth_token_key;
src/openvpn/openvpn.h +1 -0
index 900db7e1..9e46ad6c 100644
@@ -209,6 +209,7 @@ struct context_1
 
     const char *ciphername;     /**< Data channel cipher from config file */
     const char *authname;       /**< Data channel auth from config file */
+    const char *ncp_ciphers;    /**< NCP Ciphers */
     int keysize;                /**< Data channel keysize from config file */
 #endif
 };
src/openvpn/ssl.c +3 -1
index e708fc93..b8351737 100644
@@ -2322,7 +2322,9 @@ push_peer_info(struct buffer *buf, struct tls_session *session)
 
         /* support for Negotiable Crypto Parameters */
         if (session->opt->ncp_enabled
-            && (session->opt->mode == MODE_SERVER || session->opt->pull))
+            && (session->opt->mode == MODE_SERVER || session->opt->pull)
+            && tls_item_in_cipher_list("AES-128-GCM", session->opt->config_ncp_ciphers)
+            && tls_item_in_cipher_list("AES-256-GCM", session->opt->config_ncp_ciphers))
         {
             buf_printf(&out, "IV_NCP=2\n");
         }
src/openvpn/ssl_common.h +1 -0
index 8dd08862..fb82f610 100644
@@ -290,6 +290,7 @@ struct tls_options
 
     const char *config_ciphername;
     const char *config_authname;
+    const char *config_ncp_ciphers;
     bool ncp_enabled;
 
     bool tls_crypt_v2;
Signature · 1 line
2.25.0
#2 lore raw

Re: [Openvpn-devel] [PATCH 2/4] Implement dynamic NCP negotiation

In reply to Arne Schwabe

Hi,

su 17. marrask. 2019 klo 20.13 Arne Schwabe ([email protected]...) kirjoitti:

Quoted 1 line

+#include "ssl_ncp.h"

this file is missing from this patch.

Quoted 1 line

+ const char *token = strsep(&tmp_ciphers, ":");

This breaks on Windows.

Could you send v2 with strsep-compat and removed header (which is introduced in v3) ?

-Lev

#15 lore raw

Re: [Openvpn-devel] [PATCH 4/4] Normalise ncp-ciphers option and restrict it to 127 bytes

In reply to Arne Schwabe

Hi,

su 17. marrask. 2019 klo 20.13 Arne Schwabe ([email protected]...) kirjoitti:

Review

Quoted 3 lines
(quoted diff) +1 -1
-        if (!cipher_kt_get(translate_cipher_name_from_openvpn(token)))
+        /* translate_cipher_name_from_openvpn also normalises the cipher

name,

Review

Quoted 2 lines
(quoted diff) +2 -0
+         * e.g. replacing AeS-128-gCm with AES-128-GCM
+         */

I think this comment is a bit misleading -
translate_cipher_name_from_openvpn()
translates openvpn cipher name (value in --ncp-ciphers) to crypto library cipher name,
for example from "aES-256-GCM" to "idaes_256_GCM" which contradicts the comment.

Maybe we could factor this code out into separate normalize_cipher_name() function, which

- translates (possibly non-normalized) openvpn cipher name into cryptolib
cipher name
- translates crypto cipher name back to openvpn cipher name, this time
normalized

Quoted 3 lines

+ if (!ktc)
{
msg(M_WARN, "Unsupported cipher in --ncp-ciphers: %s",

token);

Review

Quoted 2 lines
(quoted diff) +1 -1
-            unsupported_cipher_found = true;
+            error_found = true;

It seems that mutate_ncp_cipher_list() returns NULL if error_found is true. Maybe we could goto
out of the loop? The label could be added before free() calls.

src/openvpn/ssl_ncp.c tls_peer_supports_ncp(const char *peer_info) · line 130

Quoted 11 lines
src/openvpn/ssl_ncp.c +11 -0
+            if (buf_len(&new_list)> 0)
+            {
+                /* The next if condition ensure there is always space for
+                 * a :
+                 */
+                buf_puts(&new_list, ":");
+            }
+
+            /* Ensure buffer has capacity for cipher name + : + \0 */
+            if (!(buf_forward_capacity(&new_list) >
+                  strlen(ovpn_cipher_name) + 2))

This doesn't handle the case when buffer capacity is just enough to fit the last cipher - for that it is enough to fit cipher name and \0. Could we move

Quoted 1 line
         token = strtok(NULL, ":");

here and do something like

/* for the last cipher, token is NULL, enough to fit cipher and \0 */ strlen(ovpn_cipher_name) + (token ? 2 : 1);

src/openvpn/ssl_ncp.c tls_peer_supports_ncp(const char *peer_info) · line 134

Quoted 4 lines
src/openvpn/ssl_ncp.c +4 -0
+            {
+                msg(M_WARN, "Length of --ncp-ciphers is over the"
+                    "limit of 127 chars");
+                error_found = true;

Same as above, cannot we "goto out"?

We could put out: right before next line.

src/openvpn/ssl_ncp.c tls_peer_supports_ncp(const char *peer_info) · line 156

Quoted 6 lines
     free(tmp_ciphers);
src/openvpn/ssl_ncp.c +2 -1
+    free_buf(&new_list);
 
-    return 0 < strlen(list) && !unsupported_cipher_found;
+    return ret;
 }

-Lev

#3 lore raw

PATCH v2 2/5 Implement dynamic NCP negotiation

In reply to Lev Stipakov

Our current NCP version is flawed in the way that it can only indicate support for AES-256-GCM and AES-128-GCM. While configuring client and server with different ncp-cipher configuration directive works, the server will blindly push the first cipher of that list to the client if the client sends IV_NCP=2.

This patches introduces IV_CIPHER sent from the client to the server that contains the full list of cipers that the client is willing to support (*). The server will then pick the first ciphr of its own ncp-cipher list that the client indicates support for.

We choose a textual representation of the ciphers instead of a binary sinc a binary would mean that we would need to have a central place to maintain a mapping between binary and the actual cipher name. Also the normal ncp-cipher list is quite short, so this should not be problem. It also provides the freedom to negioate new ciphers from SSL libraries without the need to upgrade OpenVPN/its binary cipher table.

* the client/server will also accpt the cipher specifid in --cipher but eventually we want to get rid of --ciper. So this patch keeps a reasonable backwards compatbility (especially poor man's NCP) but does not encourage to use --cipher for negotiation in documentation or warning messages.

Patch V2: Remove #include "ssl_ncp.h" Note to compile on windows the patch
"Add strsep compat function" should be applied first

---
 doc/openvpn.8            |  10 +++-
 src/openvpn/init.c       |   1 -
 src/openvpn/push.c       |  32 +++++++----
 src/openvpn/ssl.c        | 111 +++++++++++++++++++++++++++++++++++++--
 src/openvpn/ssl.h        |  34 ++++++++++++
 src/openvpn/ssl_common.h |   1 -
 6 files changed, 171 insertions(+), 18 deletions(-)
doc/openvpn.8 +8 -2
index b8f2f042..d631ebe7 100644
@@ -3117,6 +3117,11 @@ IV_NCP=2 \-\- negotiable ciphers, client supports
 pushed by the server, a value of 2 or greater indicates client
 supports AES\-GCM\-128 and AES\-GCM\-256.
 
+IV_CIPHERS=<ncp\-ciphers> \-\- the client pushes the list of configured
+ciphers with the
+\.B -\-\ncp\-ciphers
+option to the server.
+
 IV_GUI_VER=<gui_id> <version> \-\- the UI version of a UI if one is
 running, for example "de.blinkt.openvpn 0.5.47" for the
 Android app.
@@ -4374,7 +4379,8 @@ is a colon\-separated list of ciphers, and defaults to
 
 For servers, the first cipher from
 .B cipher_list
-will be pushed to clients that support cipher negotiation.
+that is also supported by the client will be pushed to clients
+that support cipher negotiation.
 
 Cipher negotiation is enabled in client\-server mode only.  I.e. if
 .B \-\-mode
@@ -4398,7 +4404,7 @@ NCP server (v2.4+) with "\-\-cipher BF\-CBC" and "\-\-ncp\-ciphers
 AES\-256\-GCM:AES\-256\-CBC" set can either specify "\-\-cipher BF\-CBC" or
 "\-\-cipher AES\-256\-CBC" and both will work.
 
-Note, for using NCP with a OpenVPN 2.4 server this list must include
+Note, for using NCP with a OpenVPN 2.4 peer this list must include
 the AES\-256\-GCM and AES\-128\-GCM ciphers.
 .\"*********************************************************
 .TP
src/openvpn/init.c +0 -1
index d83b42b0..3488d2ea 100644
@@ -2827,7 +2827,6 @@ do_init_crypto_tls(struct context *c, const unsigned int flags)
     to.replay_time = options->replay_time;
     to.tcp_mode = link_socket_proto_connection_oriented(options->ce.proto);
     to.config_ciphername = c->c1.ciphername;
-    to.config_authname = c->c1.authname;
     to.config_ncp_ciphers = c->c1.ncp_ciphers;
     to.ncp_enabled = options->ncp_enabled;
     to.transition_window = options->transition_window;
src/openvpn/push.c +23 -9
index 368b6920..1f1e1f0d 100644
@@ -429,7 +429,7 @@ prepare_push_reply(struct context *c, struct gc_arena *gc,
     prepare_auth_token_push_reply(tls_multi, gc, push_list);
 
     /* Push cipher if client supports Negotiable Crypto Parameters */
-    if (tls_peer_info_ncp_ver(peer_info) >= 2 && o->ncp_enabled)
+    if (o->ncp_enabled)
     {
         /* if we have already created our key, we cannot *change* our own
          * cipher -> so log the fact and push the "what we have now" cipher
@@ -445,17 +445,31 @@ prepare_push_reply(struct context *c, struct gc_arena *gc,
         }
         else
         {
-            /* Push the first cipher from --ncp-ciphers to the client.
-             * TODO: actual negotiation, instead of server dictatorship. */
-            char *push_cipher = string_alloc(o->ncp_ciphers, &o->gc);
-            o->ciphername = strtok(push_cipher, ":");
+            /*
+             * Push the first cipher from --ncp-ciphers to the client that
+             * the client announces to be supporting.
+             */
+            char *push_cipher = ncp_get_best_cipher(o->ncp_ciphers, o->ciphername,
+                                                    peer_info,
+                                                    tls_multi->remote_ciphername,
+                                                    &o->gc);
+
+            if (push_cipher)
+            {
+                o->ciphername = push_cipher;
+            }
+            else
+            {
+                char *peer_ciphers = tls_peer_ncp_list(peer_info);
+                msg(M_INFO, "PUSH: No common cipher between server and client."
+                    "Expect this connection not to work. "
+                    "Server ncp-ciphers: '%s', client supported ciphers '%s'",
+                    o->ncp_ciphers, peer_ciphers);
+                free(peer_ciphers);
+            }
         }
         push_option_fmt(gc, push_list, M_USAGE, "cipher %s", o->ciphername);
     }
-    else if (o->ncp_enabled)
-    {
-        tls_poor_mans_ncp(o, tls_multi->remote_ciphername);
-    }
 
     return true;
 }
src/openvpn/ssl.c +106 -5

136 lines not on this page · raw message

src/openvpn/ssl.h +34 -0
index a944ca3a..ad3b46d7 100644
@@ -512,6 +512,40 @@ tls_get_peer_info(const struct tls_multi *multi)
  */
 int tls_peer_info_ncp_ver(const char *peer_info);
 
+/**
+ * Iterates through the ciphers in server_list and return the first
+ * cipher that is also supported by the peer according to the IV_NCP
+ * and IV_CIPHER values in peer_info.
+ *
+ * We also accept a cipher that is the remote cipher of the client for
+ * "Poor man's NCP": Use peer cipher if it is an allowed (NCP) cipher.
+ * Allows non-NCP peers to upgrade their cipher individually.
+ *
+ * Make sure to call tls_session_update_crypto_params() after calling this
+ * function.
+ *
+ * @param gc   gc arena that is ONLY used to allocate the returned string
+ *
+ * @returns NULL if no common cipher is available, otherwise the best common
+ * cipher
+ */
+char *
+ncp_get_best_cipher(const char *server_list, const char *server_cipher,
+                    const char *peer_info, const char *remote_cipher,
+                    struct gc_arena *gc);
+
+
+/**
+ * Returns the support cipher list from the peer according to the IV_NCP
+ * and IV_CIPHER values in peer_info.
+ *
+ * @returns Either a string containing the ncp list that needs to be
+ * free()ed after use. If no information is available an empty string
+ * ("") is returned.
+ */
+char *
+tls_peer_ncp_list(const char *peer_info);
+
 /**
  * Check whether the ciphers in the supplied list are supported.
  *
src/openvpn/ssl_common.h +0 -1
index fb82f610..998ea3c4 100644
@@ -289,7 +289,6 @@ struct tls_options
     bool tcp_mode;
 
     const char *config_ciphername;
-    const char *config_authname;
     const char *config_ncp_ciphers;
     bool ncp_enabled;
 
Signature · 1 line
2.25.0
#8 lore raw

PATCH v2 3/5 Move NCP related function into a seperate file and add unit tests

In reply to Arne Schwabe

This allows unit test the NCP functions. The ssl.c file has too many dependencies to make unit testing of it viable.

Patch V2: Removing the include "ssl_ncp.h" from options.c for V2 of
implement dynamic NCP forces a new version of this patch to add the #include in this patch. Merge VS studio file changes for ssl_ncp.[ch] into this patch

---
 src/openvpn/Makefile.am              |   1 +
 src/openvpn/init.c                   |   1 +
 src/openvpn/multi.c                  |   1 +
 src/openvpn/openvpn.vcxproj          |   2 +
 src/openvpn/options.c                |   1 +
 src/openvpn/push.c                   |   1 +
 src/openvpn/ssl.c                    | 172 +-------------------
 src/openvpn/ssl.h                    |  65 --------
 src/openvpn/ssl_ncp.c                | 225 +++++++++++++++++++++++++++
 src/openvpn/ssl_ncp.h                | 101 ++++++++++++
 tests/unit_tests/openvpn/Makefile.am |  18 ++-
 tests/unit_tests/openvpn/test_ncp.c  | 182 ++++++++++++++++++++++
 12 files changed, 534 insertions(+), 236 deletions(-)
 create mode 100644 src/openvpn/ssl_ncp.c
 create mode 100644 src/openvpn/ssl_ncp.h
 create mode 100644 tests/unit_tests/openvpn/test_ncp.c
src/openvpn/Makefile.am +1 -0
index d1bb99c2..2ea47cda 100644
@@ -116,6 +116,7 @@ openvpn_SOURCES = \
 	ssl.c ssl.h  ssl_backend.h \
 	ssl_openssl.c ssl_openssl.h \
 	ssl_mbedtls.c ssl_mbedtls.h \
+	ssl_ncp.c ssl_ncp.h \
 	ssl_common.h \
 	ssl_verify.c ssl_verify.h ssl_verify_backend.h \
 	ssl_verify_openssl.c ssl_verify_openssl.h \
src/openvpn/init.c +1 -0
index 3488d2ea..9aa050ec 100644
@@ -49,6 +49,7 @@
 #include "ping.h"
 #include "mstats.h"
 #include "ssl_verify.h"
+#include "ssl_ncp.h"
 #include "tls_crypt.h"
 #include "forward.h"
 #include "auth_token.h"
src/openvpn/multi.c +1 -0
index d594dd25..b82c68c4 100644
@@ -45,6 +45,7 @@
 #include "gremlin.h"
 #include "mstats.h"
 #include "ssl_verify.h"
+#include "ssl_ncp.h"
 #include "vlan.h"
 #include <inttypes.h>
 
src/openvpn/openvpn.vcxproj +2 -0
index 614d720a..53ac5482 100644
@@ -192,6 +192,7 @@
     <ClCompile Include="socks.c" />
     <ClCompile Include="ssl.c" />
     <ClCompile Include="ssl_openssl.c" />
+    <ClCompile Include="ssl_ncp.c" />
     <ClCompile Include="ssl_verify.c" />
     <ClCompile Include="ssl_verify_openssl.c" />
     <ClCompile Include="status.c" />
@@ -278,6 +279,7 @@
     <ClInclude Include="ssl.h" />
     <ClInclude Include="ssl_backend.h" />
     <ClInclude Include="ssl_common.h" />
+    <ClInclude Include="ssl_ncp.h" />
     <ClInclude Include="ssl_openssl.h" />
     <ClInclude Include="ssl_verify.h" />
     <ClInclude Include="ssl_verify_backend.h" />
src/openvpn/options.c +1 -0
index c459b260..d057975c 100644
@@ -45,6 +45,7 @@
 #include "shaper.h"
 #include "crypto.h"
 #include "ssl.h"
+#include "ssl_ncp.h"
 #include "options.h"
 #include "misc.h"
 #include "socket.h"
src/openvpn/push.c +1 -0
index 1f1e1f0d..38069cb5 100644
@@ -33,6 +33,7 @@
 #include "options.h"
 #include "ssl.h"
 #include "ssl_verify.h"
+#include "ssl_ncp.h"
 #include "manage.h"
 
 #include "memdbg.h"
src/openvpn/ssl.c +2 -170

202 lines not on this page · raw message

src/openvpn/ssl.h +0 -65

77 lines not on this page · raw message

src/openvpn/ssl_ncp.c new file +225 -0

225 lines not on this page · raw message

src/openvpn/ssl_ncp.h new file +101 -0

101 lines not on this page · raw message

tests/unit_tests/openvpn/Makefile.am +17 -1
index 60e84639..f0880a6b 100644
@@ -6,7 +6,7 @@ if HAVE_LD_WRAP_SUPPORT
 test_binaries += argv_testdriver buffer_testdriver
 endif
 
-test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver
+test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver
 if HAVE_LD_WRAP_SUPPORT
 test_binaries += tls_crypt_testdriver
 endif
@@ -110,3 +110,19 @@ auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \
 	$(openvpn_srcdir)/packet_id.c \
 	$(openvpn_srcdir)/platform.c \
 	$(openvpn_srcdir)/base64.c
+
+
+ncp_testdriver_CFLAGS  = @TEST_CFLAGS@ \
+	-I$(openvpn_includedir) -I$(compat_srcdir) -I$(openvpn_srcdir) \
+	$(OPTIONAL_CRYPTO_CFLAGS)
+ncp_testdriver_LDFLAGS = @TEST_LDFLAGS@ \
+	$(OPTIONAL_CRYPTO_LIBS)
+
+ncp_testdriver_SOURCES = test_ncp.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
tests/unit_tests/openvpn/test_ncp.c new file +182 -0

182 lines not on this page · raw message

Signature · 1 line
2.25.0
#16 lore raw

PATCH v2 4/5 Normalise ncp-ciphers option and restrict it to 127 bytes

In reply to Lev Stipakov

In scenarios of mbed TLS vs OpenSSL we already normalise the ciphers that are send via the wire protocol via OCC to not have a mismatch warning between server and client. This is done by translate_cipher_name_from_openvpn. The same applies also to the ncp-ciphers list. Specifying non normalised names in ncp-ciphers will cause negotation not to succeed if ciphers are not in the same form. Therefore we will normalise the ciphers in options_postmutate.

The alternative and a lot less user friendly alternative would be to bail if on of the ciphers in ncp-ciphers is not in its normalised form.

Also restrict the ncp-ciphers list to 127. This is somewhat arbitrary but should prevent too large IV_CIPHER messages and problems sending those. The server will accept also large IV_CIPHER values from clients.

Patch V2: Correct comment about normalising ciphers

---
 doc/openvpn.8                       |  3 ++
 src/openvpn/options.c               | 14 ++++---
 src/openvpn/ssl_ncp.c               | 57 +++++++++++++++++++++++++----
 src/openvpn/ssl_ncp.h               | 19 +++++++++-
 tests/unit_tests/openvpn/test_ncp.c | 43 ++++++++++++++++++----
 5 files changed, 114 insertions(+), 22 deletions(-)
doc/openvpn.8 +3 -0
index d631ebe7..c0ec80f9 100644
@@ -4406,6 +4406,9 @@ AES\-256\-GCM:AES\-256\-CBC" set can either specify "\-\-cipher BF\-CBC" or
 
 Note, for using NCP with a OpenVPN 2.4 peer this list must include
 the AES\-256\-GCM and AES\-128\-GCM ciphers.
+
+This list is restricted to be 127 chars long after conversion to OpenVPN
+ciphers.
 .\"*********************************************************
 .TP
 .B \-\-ncp\-disable
src/openvpn/options.c +9 -5
index d057975c..06291970 100644
@@ -2511,11 +2511,6 @@ options_postprocess_verify_ce(const struct options *options, const struct connec
     }
 #endif /* P2MP_SERVER */
 
-    if (options->ncp_enabled && !tls_check_ncp_cipher_list(options->ncp_ciphers))
-    {
-        msg(M_USAGE, "NCP cipher list contains unsupported ciphers.");
-    }
-
     if (options->keysize)
     {
         msg(M_WARN, "WARNING: --keysize is DEPRECATED and will be removed in OpenVPN 2.6");
@@ -3093,6 +3088,15 @@ options_postprocess_mutate(struct options *o)
 
     options_postprocess_mutate_invariant(o);
 
+    if (o->ncp_enabled)
+    {
+        o->ncp_ciphers = mutate_ncp_cipher_list(o->ncp_ciphers, &o->gc);
+        if (o->ncp_ciphers == NULL)
+        {
+            msg(M_USAGE, "NCP cipher list contains unsupported ciphers or is too long.");
+        }
+    }
+
     if (o->remote_list && !o->connection_list)
     {
         /*
src/openvpn/ssl_ncp.c +50 -7

77 lines not on this page · raw message

src/openvpn/ssl_ncp.h +17 -2
index 82d008d8..62822e89 100644
@@ -87,10 +87,17 @@ tls_peer_ncp_list(const char *peer_info);
  * Check whether the ciphers in the supplied list are supported.
  *
  * @param list          Colon-separated list of ciphers
+ * @parms gc            gc_arena to allocate the returned string
  *
- * @returns true iff all ciphers in list are supported.
+ * @returns             colon separated string of normalised (via
+ *                      translate_cipher_name_from_openvpn) and
+ *                      zero terminated string iff all ciphers
+ *                      in list are supported and the total length
+ *                      is short than MAX_NCP_CIPHERS_LENGTH. NULL
+ *                      otherwise.
  */
-bool tls_check_ncp_cipher_list(const char *list);
+char *
+mutate_ncp_cipher_list(const char *list, struct gc_arena *gc);
 
 /**
  * Return true iff item is present in the colon-separated zero-terminated
@@ -98,4 +105,12 @@ bool tls_check_ncp_cipher_list(const char *list);
  */
 bool tls_item_in_cipher_list(const char *item, const char *list);
 
+/**
+ * The maximum length of a ncp-cipher string that is accepted.
+ *
+ * Since this list needs to be pushed as IV_CIPHERS, we are conservative
+ * about its length.
+ */
+#define MAX_NCP_CIPHERS_LENGTH 127
+
 #endif /* ifndef OPENVPN_SSL_NCP_H */
tests/unit_tests/openvpn/test_ncp.c +35 -8

73 lines not on this page · raw message

Signature · 1 line
2.25.0
#22 lore raw

Re: [Openvpn-devel] [PATCH 5/4] Add ncp files to Visual studio print

In reply to Arne Schwabe

Am 18.11.19 um 09:45 schrieb Arne Schwabe:

Quoted 23 lines

Am 17.11.19 um 22:23 schrieb Arne Schwabe:

Quoted 22 lines
---
 src/openvpn/openvpn.vcxproj | 2 ++
 1 file changed, 2 insertions(+)
src/openvpn/openvpn.vcxproj +2 -0
index 7446d97d..b3d35ba2 100644
@@ -191,6 +191,7 @@
     <ClCompile Include="socks.c" />
     <ClCompile Include="ssl.c" />
     <ClCompile Include="ssl_openssl.c" />
+    <ClCompile Include="ssl_ncp.c" />
     <ClCompile Include="ssl_verify.c" />
     <ClCompile Include="ssl_verify_openssl.c" />
     <ClCompile Include="status.c" />
@@ -276,6 +277,7 @@
     <ClInclude Include="ssl.h" />
     <ClInclude Include="ssl_backend.h" />
     <ClInclude Include="ssl_common.h" />
+    <ClInclude Include="ssl_ncp.h" />
Quoted 8 lines

src/openvpn/openvpn.vcxproj line 283

Quoted 4 lines
src/openvpn/openvpn.vcxproj +0 -0
     <ClInclude Include="ssl_openssl.h" />
     <ClInclude Include="ssl_verify.h" />
     <ClInclude Include="ssl_verify_backend.h" />

Note this patch can be merged into the 4/4 patch. I just did not want to resend 4/4 for this tiny patch. Should a V2 of 4/4 be needed, I will include this one into it.

V2 of 4/5 includes now this patch and this patch is obsolute.

#6 lore raw

Re: [Openvpn-devel] [PATCH 2/4] Implement dynamic NCP negotiation

In reply to Lev Stipakov

Am 13.02.20 um 12:45 schrieb Lev Stipakov:

Quoted 7 lines

Hi,

su 17. marrask. 2019 klo 20.13 Arne Schwabe ([email protected]... <mailto:[email protected]...>) kirjoitti:

Quoted 1 line

+#include "ssl_ncp.h"

Quoted 9 lines

this file is missing from this patch.

Quoted 1 line

+    const char *token = strsep(&tmp_ciphers, ":");

This breaks on Windows.

Could you send v2 with strsep-compat and removed header (which is introduced in v3) ?

Patch 6 takes cares of fixing Windows compatibility.

Arne

#18 lore raw

Re: [Openvpn-devel] [PATCH 4/4] Normalise ncp-ciphers option and restrict it to 127 bytes

In reply to Lev Stipakov

Am 13.02.20 um 13:34 schrieb Lev Stipakov:

Quoted 11 lines

Hi,

su 17. marrask. 2019 klo 20.13 Arne Schwabe ([email protected]... <mailto:[email protected]...>) kirjoitti:

Quoted 3 lines

-        if (!cipher_kt_get(translate_cipher_name_from_openvpn(token)))
+        /* translate_cipher_name_from_openvpn also normalises the

cipher name,

Quoted 2 lines

+         * e.g. replacing AeS-128-gCm with AES-128-GCM
+         */

Quoted 7 lines

I think this comment is a bit misleading - translate_cipher_name_from_openvpn()
translates openvpn cipher name (value in --ncp-ciphers) to crypto library cipher name,
for example from "aES-256-GCM" to "idaes_256_GCM" which contradicts the comment.

Will update the comment.

Quoted 7 lines

Maybe we could factor this code out into separate
normalize_cipher_name() function, which

 - translates (possibly non-normalized) openvpn cipher name into cryptolib cipher name
 - translates crypto cipher name back to openvpn cipher name, this time normalized

Hm, it would be only used here and make error handling more complicated, so I think we should just stick with the two functions.

Quoted 10 lines
Quoted 3 lines

+        if (!ktc)
         {
             msg(M_WARN, "Unsupported cipher in --ncp-ciphers: %s",

token);

Quoted 2 lines

-            unsupported_cipher_found = true;
+            error_found = true;

It seems that mutate_ncp_cipher_list() returns NULL if error_found is true. Maybe we could goto
out of the loop? The label could be added before free() calls.

Yes. But I found that less user friendly. The approach here will give you an error for every unsupported cipher. Otherwise you get only an error for the first unsupported cipher.

Quoted 16 lines
Quoted 11 lines

+            if (buf_len(&new_list)> 0)
+            {
+                /* The next if condition ensure there is always space for
+                 * a :
+                 */
+                buf_puts(&new_list, ":");
+            }
+
+            /* Ensure buffer has capacity for cipher name + : + \0 */
+            if (!(buf_forward_capacity(&new_list) >
+                  strlen(ovpn_cipher_name) + 2))

This doesn't handle the case when buffer capacity is just enough to fit the last cipher - for that it is enough to fit cipher name and \0. Could we move

Quoted 11 lines

  >          token = strtok(NULL, ":");

here and do something like

  /* for the last cipher, token is NULL, enough to fit cipher and \0 */ strlen(ovpn_cipher_name) + (token ? 2 : 1);

Quoted 4 lines

+            {
+                msg(M_WARN, "Length of --ncp-ciphers is over the"
+                    "limit of 127 chars");
+                error_found = true;

I don't think this worth fixing. If you are close or at the 127 char limit then your cipher list is too long anyway. That we might bail out at 126 char is acceptable. I rather prefer the simple code here.

Arne

Acked-by on v2 2/5
#4 lore raw

Re: [Openvpn-devel] [PATCH v2 2/5] Implement dynamic NCP negotiation

In reply to Arne Schwabe

Hi,

to 13. helmik. 2020 klo 15.51 Arne Schwabe ([email protected]...) kirjoitti:

Quoted 2 lines

Our current NCP version is flawed in the way that it can only indicate

support for

Built and tested on Ubuntu 18 and MSVC. Works as advertised.

Out of curiosity - you picked strsep because strtok which we have used so far
relies on evil global state?

#9 lore raw

Re: [Openvpn-devel] [PATCH v2 3/5] Move NCP related function into a seperate file and add unit tests

In reply to Arne Schwabe

Hi,

<skip>

I was planning to send a separate patch, but since you moved this code, maybe you could fix it here.

Review

Quoted 5 lines
(quoted diff) +5 -0
+bool
+tls_item_in_cipher_list(const char *item, const char *list)
+{
+    char *tmp_ciphers = string_alloc(list, NULL);
+    char *tmp_ciphers_orig = tmp_ciphers;

This is redundant. strtok() manipulates string, but doesn't modify pointer, unlike strsep. So it should be safe to to call

Quoted 1 line

free(tmp_ciphers)

instead of

Quoted 1 line

+ free(tmp_ciphers_orig);

Same case as here:
https://sourceforge.net/p/openvpn/mailman/message/35421870/

Also could you apply following diff, which makes sure that ssl_ncp.[ch] are displayed under correct Source/Headers folder in MSVC?

(quoted diff) +0 -0

b/src/openvpn/openvpn.vcxproj.filters
index 41e62d14..80eb52b3 100644

src/openvpn/openvpn.vcxproj.filters +7 -1
@@ -243,6 +243,9 @@
     <ClCompile Include="ring_buffer.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="ssl_ncp.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="base64.h">
@@ -506,10 +509,13 @@
     <ClInclude Include="ring_buffer.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="ssl_ncp.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="openvpn_win32_resources.rc">
       <Filter>Resource Files</Filter>
     </ResourceCompile>
   </ItemGroup>
-</Project>
+</Project>
\ No newline at end of file

Other than that, looks good.

#17 lore raw

Re: [Openvpn-devel] [PATCH v2 4/5] Normalise ncp-ciphers option and restrict it to 127 bytes

In reply to Arne Schwabe

Hi,

Review

Quoted 3 lines
(quoted diff) +2 -0
+
+#idef ENABLE_CRYPTO_OPENSSL

Boom.

#5 lore raw

Re: [Openvpn-devel] [PATCH v2 2/5] Implement dynamic NCP negotiation

In reply to Lev Stipakov

Am 14.02.20 um 13:23 schrieb Lev Stipakov:

Quoted 5 lines

Hi,

to 13. helmik. 2020 klo 15.51 Arne Schwabe ([email protected]... <mailto:[email protected]...>) kirjoitti:

Quoted 1 line
Quoted 8 lines
Quoted 1 line

Our current NCP version is flawed in the way that it can only indicate

support for

Built and tested on Ubuntu 18 and MSVC. Works as advertised.

Out of curiosity - you picked strsep because strtok which we have used so far
relies on evil global state?

Yes, one of the calls in that functions actually calls a function that uses strtok, so then everything blows up.

Arne

#10 lore raw

Re: [Openvpn-devel] [PATCH v2 3/5] Move NCP related function into a seperate file and add unit tests

In reply to Lev Stipakov

Am 14.02.20 um 14:08 schrieb Lev Stipakov:

Quoted 7 lines

Hi,

<skip>

I was planning to send a separate patch, but since you moved this code, maybe you could fix it here.

Quoted 9 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+bool
+tls_item_in_cipher_list(const char *item, const char *list)
+{
+    char *tmp_ciphers = string_alloc(list, NULL);
+    char *tmp_ciphers_orig = tmp_ciphers;

This is redundant. strtok() manipulates string, but doesn't modify pointer, unlike strsep. So it should be safe to to call

This patch is just moving code that it does not touch. The original code is from Steffan. If we fix it, that should go into a different patch I think.

But yes you are correct. But the compiler will optimise that away I think :)

Arne

#11 lore raw

Re: [Openvpn-devel] [PATCH v2 3/5] Move NCP related function into a seperate file and add unit tests

I found this discussion

https://sourceforge.net/p/openvpn/mailman/message/34405489/

and wonder if we should replace strdup with string_alloc("AES-256-GCM").

If the result of strdup is NULL because of OOM, then following is NULL

    char *peer_ncp_list = tls_peer_ncp_list(peer_info);

and it is passed to

    const char *token = strtok(tmp_ciphers, ":");

and then behavior depends on the previous state of strtok.

string_alloc(), on the other hand, calls check_malloc_return(), which prints "out of memory" and exits program.

pe 14. helmik. 2020 klo 16.35 Arne Schwabe ([email protected]...) kirjoitti:

Quoted 27 lines

Am 14.02.20 um 14:08 schrieb Lev Stipakov:

Quoted 7 lines

Hi,

<skip>

I was planning to send a separate patch, but since you moved this code, maybe you could fix it here.

Quoted 9 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+bool
+tls_item_in_cipher_list(const char *item, const char *list)
+{
+    char *tmp_ciphers = string_alloc(list, NULL);
+    char *tmp_ciphers_orig = tmp_ciphers;

This is redundant. strtok() manipulates string, but doesn't modify pointer, unlike strsep. So it should be safe to to call

This patch is just moving code that it does not touch. The original code is from Steffan. If we fix it, that should go into a different patch I think.

But yes you are correct. But the compiler will optimise that away I think :)

Arne

Signature · 1 line
-Lev
#25 lore raw
In reply to Arne Schwabe

Hi,

Since --ncp-ciphers are non-negotiable, why do we need to store it in context_1 at all? Cannot we use the value from struct options?

This can be removed

Quoted 1 line

+ c->c1.ncp_ciphers = c->options.ncp_ciphers;

This

Quoted 1 line

+ to.config_ncp_ciphers = c->c1.ncp_ciphers;

can be changed to

Quoted 1 line

+ to.config_ncp_ciphers = options->ncp_ciphers

Those are not needed:

Quoted 1 line

+ dest->c1.ncp_ciphers = src->c1.ncp_ciphers;

<skip>

Quoted 1 line

+ const char *ncp_ciphers; /**< NCP Ciphers */

-Lev

#26 lore raw

Am 17.02.20 um 10:58 schrieb Lev Stipakov:

Quoted 5 lines

Hi,

Since --ncp-ciphers are non-negotiable, why do we need to store it in context_1 at all? Cannot we use the value from struct options?

The push context do not have access to the options struct. Using options directly would be massive refactoring. I want to avoid that for this small patch.

Arne

#27 lore raw

To clarify - I am not arguing against config_ncp_ciphers in struct tls_options.

The only use of ncp_ciphers in context_1 is this:

   to.config_ncp_ciphers = c->c1.ncp_ciphers;

which can be changed to

  to.config_ncp_ciphers = options->ncp_ciphers;

which allows us to get rid of added "ncp_ciphers" in struct context_1.

-Lev