Skip to contentSkip to conversation

Backport/implement IV_CIPHERS support for OpenVPN 2.4

PATCH In review Arne Schwabe 2 participants 6 messages Aug 30, 2020 – Nov 24, 2020

lore
Share & tools
lore
#0 lore raw

cover Backport/implement IV_CIPHERS support for OpenVPN 2.4

This is basically to improve 2.4 client to OpenVPN 2.5 server compatibility. The commit message of patch 2/2 explains the motivations and details more.

Arne Schwabe (2):
Normalise ncp-ciphers option and restrict it to 127 bytes Also announce IV_CIPHERS as client in OpenVPN 2.4

 doc/openvpn.8            |   2 +
 src/openvpn/init.c       |   1 +
 src/openvpn/options.c    |   9 +++
 src/openvpn/ssl.c        |  74 +++++++++++++++++++++++++
 src/openvpn/ssl.h        |  23 ++++++++
 src/openvpn/ssl_common.h |   1 +
 src/openvpn/ssl_ncp.h    | 116 +++++++++++++++++++++++++++++++++++++++
 7 files changed, 226 insertions(+)
 create mode 100644 src/openvpn/ssl_ncp.h
Signature · 1 line
2.26.2
#1 lore raw

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

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.

Cherry picked from be4531564e2be7c8a0222e6923e3f7580b358cab and adjusted for 2.4 (methods added to ssl.h/ssl.c instead ssl_ncp.c/.h

---
 doc/openvpn.8         |   2 +
 src/openvpn/options.c |   9 ++++
 src/openvpn/ssl.c     |  63 +++++++++++++++++++++++
 src/openvpn/ssl.h     |  23 +++++++++
 src/openvpn/ssl_ncp.h | 116 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 213 insertions(+)
 create mode 100644 src/openvpn/ssl_ncp.h
doc/openvpn.8 +2 -0
index 8038e1f4..77cc361d 100644
@@ -4273,6 +4273,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.
 
+This list is restricted to be 127 chars long after conversion to OpenVPN
+ciphers.
 .\"*********************************************************
 .TP
 .B \-\-ncp\-disable
src/openvpn/options.c +9 -0
index de30fcb0..f69bbb22 100644
@@ -2982,6 +2982,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.c +63 -0

69 lines not on this page · raw message

src/openvpn/ssl.h +23 -0
index 3266f386..703de99b 100644
@@ -527,6 +527,29 @@ bool tls_check_ncp_cipher_list(const char *list);
  */
 bool tls_item_in_cipher_list(const char *item, const char *list);
 
+/**
+ * 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             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.
+ */
+char *
+mutate_ncp_cipher_list(const char *list, struct gc_arena *gc);
+
+/**
+ * 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
 
 /*
  * inline functions
src/openvpn/ssl_ncp.h new file +116 -0

116 lines not on this page · raw message

Signature · 1 line
2.26.2
#3 lore raw

PATCH 2/2 Also announce IV_CIPHERS as client in OpenVPN 2.4

In reply to Arne Schwabe

This improves compatbility to a OpenVPN 2.5 server and allows to negotiate a different cipher than AES-128/256-GCM without abusing the poor man's NCP support with --cipher.

We keep the IV_NCP=2 flag logic as broken as it is since 2.5 server ignore the flag if IV_CIPHERS is set and this might break existing 2.4 setups.

Server support for IV_CIPHERS is not added since it would be quite intrusive and users should rather upgrade to 2.5 on the server if they want the full benefits.

This commit cherry picks a few parts of
868b200c3aef6ee5acfdf679770832018ebc7b70

---
 src/openvpn/init.c       |  1 +
 src/openvpn/ssl.c        | 11 +++++++++++
 src/openvpn/ssl_common.h |  1 +
 3 files changed, 13 insertions(+)
src/openvpn/init.c +1 -0
index e153682e..7ce6dd97 100644
@@ -2734,6 +2734,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 = options->ncp_ciphers;
     to.ncp_enabled = options->ncp_enabled;
     to.transition_window = options->transition_window;
     to.handshake_window = options->handshake_window;
src/openvpn/ssl.c +11 -0
index dd9c52fb..d70dcb46 100644
@@ -2311,7 +2311,18 @@ push_peer_info(struct buffer *buf, struct tls_session *session)
         if (session->opt->ncp_enabled
             && (session->opt->mode == MODE_SERVER || session->opt->pull))
         {
+            /* We keep announcing IV_NCP=2 in OpenVPN 2.4 even though it is
+             * technically wrong to ensure not to break 2.4 setups on a
+             * minor release */
             buf_printf(&out, "IV_NCP=2\n");
+            buf_printf(&out, "IV_CIPHERS=%s", session->opt->config_ncp_ciphers);
+            if (!tls_item_in_cipher_list(session->opt->config_ciphername,
+                                         session->opt->config_ncp_ciphers))
+            {
+                buf_printf(&out, ":%s", session->opt->config_ciphername);
+            }
+            buf_printf(&out, "\n")
+
         }
 
         /* push compression status */
src/openvpn/ssl_common.h +1 -0
index ac25ffa7..378b81fd 100644
@@ -286,6 +286,7 @@ struct tls_options
 
     const char *config_ciphername;
     const char *config_authname;
+    const char *config_ncp_ciphers;
     bool ncp_enabled;
 
     /** TLS handshake wrapping state */
Signature · 1 line
2.26.2
#4 lore raw

Re: [Openvpn-devel] [PATCH 2/2] Also announce IV_CIPHERS as client in OpenVPN 2.4

Quoted 7 lines

+++ b/src/openvpn/ssl.c

src/openvpn/ssl.c +1 -0
@@ -2311,7 +2311,18 @@ push_peer_info(struct buffer *buf, struct tls_session *session)
         if (session->opt->ncp_enabled
             && (session->opt->mode == MODE_SERVER || session->opt->pull))
         {
+            /* We keep announcing IV_NCP=2 in OpenVPN 2.4 even though it is

src/openvpn/ssl.c push_peer_info(struct buffer *buf, struct tls_session *session) · line 2324

Quoted 10 lines
src/openvpn/ssl.c +9 -0
+             * technically wrong to ensure not to break 2.4 setups on a
+             * minor release */
             buf_printf(&out, "IV_NCP=2\n");
+            buf_printf(&out, "IV_CIPHERS=%s", session->opt->config_ncp_ciphers);
+            if (!tls_item_in_cipher_list(session->opt->config_ciphername,
+                                         session->opt->config_ncp_ciphers))
+            {
+                buf_printf(&out, ":%s", session->opt->config_ciphername);
+            }
+            buf_printf(&out, "\n")

This line misses a ';' at the end :(

I forgot this amending. I can resend the patch if needed.

Arne

Acked-by on v1 1/2
#2 lore raw

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

In reply to Arne Schwabe

It's a prerequisite for the (desirable) IV_CIPHERS patch for 2.4. It passes the client side tests (though the code is not exercised very strongly). The code looks different from the "master" patch due to changes to cipher_kt_get() and because it's called "--data-ciphers" there - but these are straightforward. Besides that, it's exactly the same code.

NOTE: the patch includes a copy of ssl_ncp.h, which is not needed *and* not referenced, so I've dropped that part.

Your patch has been applied to the release/2.4 branch.

commit 7e3cd06d514476658709506c5e8e0703008efc5f

Author: Arne Schwabe
Date:   Sun Aug 30 16:07:35 2020 +0200
     Normalise ncp-ciphers option and restrict it to 127 bytes

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

--
kind regards,

Gert Doering

Acked-by on v1 2/2
#5 lore raw

[Openvpn-devel] [PATCH applied] Re: Also announce IV_CIPHERS as client in OpenVPN 2.4

In reply to Arne Schwabe

This is useful functionality for better 2.4 client <=> 2.5/master server NCP interoperability. It is only bringing in the client side, which is fairly nonintrusive.

Tested with my t_client setup (client-side only) and with a few manual calls to excercise the translation code (works). What does not work is case-insensitive cipher name specifications - I thought "Bf-cbC" should work, but 2.6 doesn't do this either (so, no idea where I got that idea from).

Looking at the code, I do wonder why we send IV_NCP=2 and IV_CIPHERS server to client, when we do not have anything on the client side that would care about these bits... but this is nothing this patch introduces.

Your patch has been applied to the release/2.4 branch.

commit f8c3e0aef2f6e03a0a5eafd81644c4079796649d

Author: Arne Schwabe
Date:   Sun Aug 30 16:07:36 2020 +0200
     Also announce IV_CIPHERS as client in OpenVPN 2.4

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

--
kind regards,

Gert Doering