[Openvpn-devel] Allow 'none' cipher being specified in --data-ciphers

Message ID 20200930131317.1299-2-arne@rfc2549.org
State Superseded
Headers show
Series
  • [Openvpn-devel] Allow 'none' cipher being specified in --data-ciphers
Related show

Commit Message

Arne Schwabe Sept. 30, 2020, 1:13 p.m.
Although we want to get rid of none as cipher, we still have not
deprecated it. In order to use it currently you need
--ncp-disable together with --cipher none to use the none cipher.

In our current situation allowing none to be specified in data-ciphers
is the lesser evil.

This commit also fixes that we use '[null-cipher]' instead 'none' when
setting remote_cipher

Patch V2: Also work correctly if remote_cipher is NULL.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
---
 src/openvpn/ssl.c                   |  8 ++++++++
 src/openvpn/ssl_ncp.c               | 16 +++++++++++++++-
 tests/unit_tests/openvpn/test_ncp.c | 10 ++++++++--
 3 files changed, 31 insertions(+), 3 deletions(-)

Comments

Gert Doering Oct. 4, 2020, 1:14 p.m. | #1
Hi,

On Wed, Sep 30, 2020 at 03:13:06PM +0200, Arne Schwabe wrote:
> Although we want to get rid of none as cipher, we still have not
> deprecated it. In order to use it currently you need
> --ncp-disable together with --cipher none to use the none cipher.
> 
> In our current situation allowing none to be specified in data-ciphers
> is the lesser evil.
> 
> This commit also fixes that we use '[null-cipher]' instead 'none' when
> setting remote_cipher
> 
> Patch V2: Also work correctly if remote_cipher is NULL.

I was about to ACK-and-merge it, but it fails the "ping IPv4 with 3000 bytes"
test, triggering

2020-10-04 15:10:58 us=638418 cron2-freebsd-tc-amd64/2001:608:0:814::f000:21 TCP/UDP packet too large on write to [AF_INET6]2001:608:0:814::f000:21:50629 (tried=1529,max=1526)

on the server side.

"Wat?"

(I could speculate that this was always broken for --cipher none, but
since you've made me add two new testcases for it, I want this to actually
work...)

gert
Gert Doering Oct. 4, 2020, 3:35 p.m. | #2
Hi,

On Sun, Oct 04, 2020 at 03:14:57PM +0200, Gert Doering wrote:
> "Wat?"

Also, the unit test fails for me (on Linux):

[ RUN      ] test_poor_man
[  ERROR   ] --- Test failed with exception: Segmentation fault(11)

gert

Patch

diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c
index 3fcaa25f..69bede27 100644
--- a/src/openvpn/ssl.c
+++ b/src/openvpn/ssl.c
@@ -2518,6 +2518,14 @@  key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_sessio
     multi->remote_ciphername =
         options_string_extract_option(options, "cipher", NULL);
 
+    /* In OCC we send '[null-cipher]' instead 'none' */
+    if (multi->remote_ciphername
+        && strcmp(multi->remote_ciphername, "[null-cipher]") == 0)
+    {
+        free(multi->remote_ciphername);
+        multi->remote_ciphername = string_alloc("none", NULL);
+    }
+
     if (tls_session_user_pass_enabled(session))
     {
         /* Perform username/password authentication */
diff --git a/src/openvpn/ssl_ncp.c b/src/openvpn/ssl_ncp.c
index 55496395..c8229044 100644
--- a/src/openvpn/ssl_ncp.c
+++ b/src/openvpn/ssl_ncp.c
@@ -110,7 +110,15 @@  mutate_ncp_cipher_list(const char *list, struct gc_arena *gc)
          * e.g. replacing AeS-128-gCm with AES-128-GCM
          */
         const cipher_kt_t *ktc = cipher_kt_get(token);
-        if (!ktc)
+        if (strcmp(token, "none") == 0)
+        {
+            msg(M_WARN, "WARNING: cipher 'none' specified for --data-ciphers. "
+                        "This allows negotiation of NO encryption and "
+                        "tunnelled data WILL then be transmitted in clear text "
+                        "over the network! "
+                        "PLEASE DO RECONSIDER THIS SETTING!");
+        }
+        if (!ktc && strcmp(token, "none")!= 0)
         {
             msg(M_WARN, "Unsupported cipher in --data-ciphers: %s", token);
             error_found = true;
@@ -118,6 +126,12 @@  mutate_ncp_cipher_list(const char *list, struct gc_arena *gc)
         else
         {
             const char *ovpn_cipher_name = cipher_kt_name(ktc);
+            if (ktc == NULL)
+            {
+                /* NULL resolves to [null-cipher] but we need none for
+                 * data-ciphers */
+                ovpn_cipher_name = "none";
+            }
 
             if (buf_len(&new_list)> 0)
             {
diff --git a/tests/unit_tests/openvpn/test_ncp.c b/tests/unit_tests/openvpn/test_ncp.c
index a4334c89..046c6876 100644
--- a/tests/unit_tests/openvpn/test_ncp.c
+++ b/tests/unit_tests/openvpn/test_ncp.c
@@ -50,7 +50,9 @@  test_check_ncp_ciphers_list(void **state)
     struct gc_arena gc = gc_new();
     bool have_chacha = cipher_kt_get("CHACHA20-POLY1305");
 
-
+    assert_string_equal(mutate_ncp_cipher_list("none", &gc), "none");
+    assert_string_equal(mutate_ncp_cipher_list("AES-256-GCM:none", &gc),
+                        "AES-256-GCM:none");
 
     assert_string_equal(mutate_ncp_cipher_list(aes_ciphers, &gc), aes_ciphers);
 
@@ -139,7 +141,7 @@  test_poor_man(void **state)
     char *best_cipher;
 
     const char *serverlist = "CHACHA20_POLY1305:AES-128-GCM";
-    const char *serverlistbfcbc = "CHACHA20_POLY1305:AES-128-GCM:BF-CBC";
+    const char *serverlistbfcbc = "CHACHA20_POLY1305:AES-128-GCM:BF-CBC:none";
 
     best_cipher = ncp_get_best_cipher(serverlist,
                                       "IV_YOLO=NO\nIV_BAR=7",
@@ -166,6 +168,10 @@  test_poor_man(void **state)
 
     assert_string_equal(best_cipher, "AES-128-GCM");
 
+    best_cipher = ncp_get_best_cipher(serverlist, NULL,
+                                      "none", &gc);
+    assert_string_equal(best_cipher, "none");
+
     best_cipher = ncp_get_best_cipher(serverlist, NULL,NULL, &gc);
     assert_ptr_equal(best_cipher, NULL);