[Openvpn-devel,v2,1/4] Only announce IV_NCP=2 when we are willing to support these ciphers

Message ID 20200213104551.25165-1-arne@rfc2549.org
State Superseded
Headers show
Series [Openvpn-devel,v2,1/4] Only announce IV_NCP=2 when we are willing to support these ciphers | expand

Commit Message

Arne Schwabe Feb. 12, 2020, 11:45 p.m. UTC
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

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
---
 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(-)

Comments

Lev Stipakov Feb. 16, 2020, 10:58 p.m. UTC | #1
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
> +    c->c1.ncp_ciphers = c->options.ncp_ciphers;

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

can be changed to
> +    to.config_ncp_ciphers = options->ncp_ciphers

Those are not needed:
> +    dest->c1.ncp_ciphers = src->c1.ncp_ciphers;
<skip>
> +    const char *ncp_ciphers;    /**< NCP Ciphers */

-Lev
Arne Schwabe Feb. 16, 2020, 11:03 p.m. UTC | #2
Am 17.02.20 um 10:58 schrieb Lev Stipakov:
> 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
Lev Stipakov Feb. 16, 2020, 11:23 p.m. UTC | #3
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

Patch

diff --git a/doc/openvpn.8 b/doc/openvpn.8
index 8feb3b9c..b8f2f042 100644
--- a/doc/openvpn.8
+++ b/doc/openvpn.8
@@ -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
diff --git a/src/openvpn/init.c b/src/openvpn/init.c
index 04207b61..d83b42b0 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -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;
diff --git a/src/openvpn/openvpn.h b/src/openvpn/openvpn.h
index 900db7e1..9e46ad6c 100644
--- a/src/openvpn/openvpn.h
+++ b/src/openvpn/openvpn.h
@@ -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
 };
diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c
index e708fc93..b8351737 100644
--- a/src/openvpn/ssl.c
+++ b/src/openvpn/ssl.c
@@ -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");
         }
diff --git a/src/openvpn/ssl_common.h b/src/openvpn/ssl_common.h
index 8dd08862..fb82f610 100644
--- a/src/openvpn/ssl_common.h
+++ b/src/openvpn/ssl_common.h
@@ -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;