Attention is currently required from: Arne Schwabe.

Hello Arne Schwabe,

I'd like you to do a code review.
Please visit

    https://gerrit.openvpn.net/c/openvpn/+/2408?usp=email

to review the following change.


Change subject: ssl_ncp: match IV_CIPHERS and IV_COMP_STUBv2 only at the start 
of a line
......................................................................

ssl_ncp: match IV_CIPHERS and IV_COMP_STUBv2 only at the start of a line

Commit 06ced3fd made the peer info helpers look for a variable only at
the start of a line, so that UV_IV_NCP is no longer taken for IV_NCP.
Three checks still run strstr() over the whole peer info:
tls_peer_supports_ncp() and ncp_get_best_cipher() for "IV_CIPHERS="
and multi_client_connect_compress_migrate() for "IV_COMP_STUBv2=1".
They also match UV_IV_CIPHERS=... and the value of any other variable
that contains the string.

In ncp_get_best_cipher() the check disagrees with tls_peer_ncp_list()
a few lines above it. For a client that sends UV_IV_CIPHERS without
IV_CIPHERS or IV_NCP=2 the cipher list is empty, but the OCC cipher is
ignored as well, so the function returns NULL even if that cipher is
in --data-ciphers.

Add peer_info_has_var() for the two IV_CIPHERS checks and read
IV_COMP_STUBv2 with peer_info_extract_uint().

Change-Id: Ie0f44579359d735c9a903185024f1cfb1e976dcf
Signed-off-by: Nexory <[email protected]>
---
M src/openvpn/multi.c
M src/openvpn/ssl_ncp.c
M src/openvpn/ssl_util.c
M src/openvpn/ssl_util.h
M tests/unit_tests/openvpn/test_ncp.c
5 files changed, 37 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/08/2408/1

diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c
index 8dbde76..eec69d1 100644
--- a/src/openvpn/multi.c
+++ b/src/openvpn/multi.c
@@ -2569,7 +2569,7 @@

     if (o->comp.flags & COMP_F_MIGRATE && 
mi->context.c2.tls_multi->remote_usescomp)
     {
-        if (peer_info && strstr(peer_info, "IV_COMP_STUBv2=1"))
+        if (peer_info_extract_uint(peer_info, "IV_COMP_STUBv2=") == 1)
         {
             push_option(o, "compress stub-v2", M_USAGE);
         }
diff --git a/src/openvpn/ssl_ncp.c b/src/openvpn/ssl_ncp.c
index 7b15f5f..ec1332a 100644
--- a/src/openvpn/ssl_ncp.c
+++ b/src/openvpn/ssl_ncp.c
@@ -72,7 +72,7 @@
     {
         return false;
     }
-    else if (tls_peer_info_ncp_ver(peer_info) >= 2 || strstr(peer_info, 
"IV_CIPHERS="))
+    else if (tls_peer_info_ncp_ver(peer_info) >= 2 || 
peer_info_has_var(peer_info, "IV_CIPHERS="))
     {
         return true;
     }
@@ -251,7 +251,7 @@
     /* non-NCP clients without OCC?  "assume nothing" */
     /* For client doing the newer version of NCP (that send IV_CIPHERS)
      * we cannot assume that they will accept remote_cipher */
-    if (remote_cipher == NULL || (peer_info && strstr(peer_info, 
"IV_CIPHERS=")))
+    if (remote_cipher == NULL || peer_info_has_var(peer_info, "IV_CIPHERS="))
     {
         remote_cipher = "";
     }
diff --git a/src/openvpn/ssl_util.c b/src/openvpn/ssl_util.c
index 6c17fe5..58b2b8d 100644
--- a/src/openvpn/ssl_util.c
+++ b/src/openvpn/ssl_util.c
@@ -86,6 +86,12 @@
     return var_value;
 }

+bool
+peer_info_has_var(const char *peer_info, const char *var)
+{
+    return peer_info_extract_varstr(peer_info, var) != NULL;
+}
+
 #if defined(__GNUC__) || defined(__clang__)
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wsign-conversion"
diff --git a/src/openvpn/ssl_util.h b/src/openvpn/ssl_util.h
index db5e17c..d9e8359 100644
--- a/src/openvpn/ssl_util.h
+++ b/src/openvpn/ssl_util.h
@@ -68,6 +68,16 @@
 char *extract_var_peer_info(const char *peer_info, const char *var, struct 
gc_arena *gc);

 /**
+ * Checks whether a variable is present in peer info
+ *
+ * @param peer_info     The peer's peer_info
+ * @param var           The variable including =, e.g. IV_CIPHERS=
+ *
+ * @return  true if a line of peer_info starts with var, false otherwise
+ */
+bool peer_info_has_var(const char *peer_info, const char *var);
+
+/**
  * Extracts the IV_PROTO variable and returns its value or 0
  * if it cannot be extracted.
  *
diff --git a/tests/unit_tests/openvpn/test_ncp.c 
b/tests/unit_tests/openvpn/test_ncp.c
index 99e1aac..4ca4f3a 100644
--- a/tests/unit_tests/openvpn/test_ncp.c
+++ b/tests/unit_tests/openvpn/test_ncp.c
@@ -181,6 +181,17 @@
     assert_string_equal("BF-CBC:FOO-BAR", peer_list);
     assert_true(tls_peer_supports_ncp(client_peer_info));

+    /* IV_CIPHERS in the name or the value of another variable is not 
IV_CIPHERS */
+    client_peer_info = "UV_IV_CIPHERS=BF-CBC:FOO-BAR\nIV_BAR=7";
+    peer_list = tls_peer_ncp_list(client_peer_info, &gc);
+    assert_string_equal("", peer_list);
+    assert_false(tls_peer_supports_ncp(client_peer_info));
+
+    client_peer_info = "IV_GUI_VER=IV_CIPHERS=BF-CBC\nIV_BAR=7";
+    peer_list = tls_peer_ncp_list(client_peer_info, &gc);
+    assert_string_equal("", peer_list);
+    assert_false(tls_peer_supports_ncp(client_peer_info));
+
     client_peer_info = "IV_YOLO=NO\nIV_BAR=7";
     peer_list = tls_peer_ncp_list(client_peer_info, &gc);
     assert_string_equal("", peer_list);
@@ -211,6 +222,13 @@

     assert_string_equal(best_cipher, "BF-CBC");

+    /* UV_IV_CIPHERS does not make the client a NCP client, its OCC cipher is 
still used */
+    best_cipher = ncp_get_best_cipher(serverlistbfcbc, 
"UV_IV_CIPHERS=AES-128-GCM\nIV_BAR=7",
+                                      "BF-CBC", &gc);
+
+    assert_non_null(best_cipher);
+    assert_string_equal(best_cipher, "BF-CBC");
+

     best_cipher = ncp_get_best_cipher(serverlist, "IV_NCP=1\nIV_BAR=7", 
"AES-128-GCM", &gc);


--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2408?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie0f44579359d735c9a903185024f1cfb1e976dcf
Gerrit-Change-Number: 2408
Gerrit-PatchSet: 1
Gerrit-Owner: Nexory <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to