From: "cron2 (Code Review)"
Date: Tue, 31 Dec 2024 16:51:13 +0000
In-Reply-To:
References:
Reply-To: gert@...1296..., arne-openvpn@...1227...,
openvpn-devel@lists.sourceforge.net, frank@...2641...
Message-ID:
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Content-Type: multipart/alternative; boundary="JGjh1ZVQUnY="; charset=UTF-8
Subject: [Openvpn-devel] [L] Change in openvpn[master]: Allow DEFAULT in
data-ciphers and report both expanded and user set o...
List-Id:
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
To: plaisthos , flichtenheld
Cc: openvpn-devel
--JGjh1ZVQUnY=
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
cron2 has uploaded a new patch set (#4) to the change originally created by=
plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/828?usp=3Demail )
The following approvals got outdated and were removed:
Code-Review+2 by flichtenheld
Change subject: Allow DEFAULT in data-ciphers and report both expanded and =
user set option
......................................................................
Allow DEFAULT in data-ciphers and report both expanded and user set option
This adds support for parsing DEFAULT in data-ciphers, the idea is that peo=
ple
can modify the default without repeating the default ciphers.
In the past we have seem that people will use data-ciphers BF-CBC or
data-ciphers AES-128-CBC when getting the warning that the cipher is not
supported by the server. This commit aims to provide a better way for
these situation as we still want people to rely on default cipher selection
from OpenVPN when possible.
Change-Id: Ia1c5209022d3ab4c0dac6438c41891c7d059f812
Signed-off-by: Arne Schwabe
Acked-by: Frank Lichtenheld
Message-Id: <20241227124632.110920-1-frank@...2641...>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg30=
245.html
Signed-off-by: Gert Doering
---
M Changes.rst
M doc/man-sections/protocol-options.rst
M src/openvpn/multi.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/ssl_ncp.c
M src/openvpn/ssl_ncp.h
M tests/unit_tests/openvpn/test_ncp.c
8 files changed, 284 insertions(+), 48 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/28/828/4
diff --git a/Changes.rst b/Changes.rst
index 34542a5..16ae6fc 100644
--- a/Changes.rst
+++ b/Changes.rst
@@ -30,6 +30,12 @@
=20
https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits/
+Default ciphers in ``--data-ciphers``
+ Ciphers in ``--data-ciphers`` can contain the string DEFAULT that is
+ replaced by the default ciphers used by OpenVPN, making it easier to
+ add an allowed cipher without having to spell out the default ciphers.
+
+
Deprecated features
-------------------
``secret`` support has been removed by default.
diff --git a/doc/man-sections/protocol-options.rst b/doc/man-sections/proto=
col-options.rst
index 05f87cc..d04ace8 100644
--- a/doc/man-sections/protocol-options.rst
+++ b/doc/man-sections/protocol-options.rst
@@ -178,6 +178,12 @@
Chacha20-Poly1305 if the underlying SSL library (and its configuration)
supports it.
+ Starting with OpenVPN 2.7 the special keyword :code:`DEFAULT` can be used
+ in the string and is replaced by the default ciphers. This can be used =
to
+ add an additional allowed cipher to the allowed ciphers, e.g.
+ :code:`DEFAULT:AES-192-CBC` to use the default ciphers but also allow
+ :code:`AES-192-CBC`.
+
Cipher negotiation is enabled in client-server mode only. I.e. if
``--mode`` is set to `server` (server-side, implied by setting
``--server`` ), or if ``--pull`` is specified (client-side, implied by
diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c
index 67bb58f..f426b46 100644
--- a/src/openvpn/multi.c
+++ b/src/openvpn/multi.c
@@ -1897,14 +1897,15 @@
if (strlen(peer_ciphers) > 0)
{
msg(M_INFO, "PUSH: No common cipher between server and client. "
- "Server data-ciphers: '%s', client supported ciphers '%s'",
- o->ncp_ciphers, peer_ciphers);
+ "Server data-ciphers: '%s'%s, client supported ciphers '%s'",
+ o->ncp_ciphers_conf, ncp_expanded_ciphers(o, &gc), peer_cipher=
s);
}
else if (tls_multi->remote_ciphername)
{
msg(M_INFO, "PUSH: No common cipher between server and client. "
- "Server data-ciphers: '%s', client supports cipher '%s'",
- o->ncp_ciphers, tls_multi->remote_ciphername);
+ "Server data-ciphers: '%s'%s, client supports cipher '%s'",
+ o->ncp_ciphers_conf, ncp_expanded_ciphers(o, &gc),
+ tls_multi->remote_ciphername);
}
else
{
diff --git a/src/openvpn/options.c b/src/openvpn/options.c
index 20e8d55..1c35d67 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -3486,40 +3486,6 @@
}
}
-
-/**
- * Checks for availibility of Chacha20-Poly1305 and sets
- * the ncp_cipher to either AES-256-GCM:AES-128-GCM or
- * AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305.
- */
-static void
-options_postprocess_setdefault_ncpciphers(struct options *o)
-{
- if (o->ncp_ciphers)
- {
- /* custom --data-ciphers set, keep list */
- return;
- }
-
- /* check if crypto library supports chacha */
- bool can_do_chacha =3D cipher_valid("CHACHA20-POLY1305");
-
- if (can_do_chacha && dco_enabled(o))
- {
- /* also make sure that dco supports chacha */
- can_do_chacha =3D tls_item_in_cipher_list("CHACHA20-POLY1305", dco=
_get_supported_ciphers());
- }
-
- if (can_do_chacha)
- {
- o->ncp_ciphers =3D "AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305";
- }
- else
- {
- o->ncp_ciphers =3D "AES-256-GCM:AES-128-GCM";
- }
-}
-
static void
options_postprocess_cipher(struct options *o)
{
@@ -3550,7 +3516,8 @@
"defaulted to BF-CBC as fallback when cipher negotiation "
"failed in this case. If you need this fallback please add "
"'--data-ciphers-fallback BF-CBC' to your configuration "
- "and/or add BF-CBC to --data-ciphers.");
+ "and/or add BF-CBC to --data-ciphers. E.g. "
+ "--data-ciphers %s:BF-CBC", o->ncp_ciphers_conf);
}
else if (!o->enable_ncp_fallback
&& !tls_item_in_cipher_list(o->ciphername, o->ncp_ciphers))
@@ -3558,7 +3525,7 @@
msg(M_WARN, "DEPRECATED OPTION: --cipher set to '%s' but missing i=
n "
"--data-ciphers (%s). OpenVPN ignores --cipher for cipher "
"negotiations. ",
- o->ciphername, o->ncp_ciphers);
+ o->ciphername, o->ncp_ciphers_conf);
}
}
diff --git a/src/openvpn/options.h b/src/openvpn/options.h
index 6ab92e2..55f12dd 100644
--- a/src/openvpn/options.h
+++ b/src/openvpn/options.h
@@ -559,6 +559,8 @@
const char *ciphername;
bool enable_ncp_fallback; /**< If defined fall back to
* ciphername if NCP fails */
+ /** The original ncp_ciphers specified by the user in the configuratio=
n*/
+ const char *ncp_ciphers_conf;
const char *ncp_ciphers;
const char *authname;
const char *engine;
diff --git a/src/openvpn/ssl_ncp.c b/src/openvpn/ssl_ncp.c
index 167bdb2..b238fc0 100644
--- a/src/openvpn/ssl_ncp.c
+++ b/src/openvpn/ssl_ncp.c
@@ -40,6 +40,8 @@
#include "config.h"
#endif
+#include
+
#include "syshead.h"
#include "win32.h"
@@ -223,7 +225,6 @@
return token !=3D NULL;
}
-
const char *
tls_peer_ncp_list(const char *peer_info, struct gc_arena *gc)
{
@@ -335,15 +336,16 @@
return true;
}
- /* We failed negotiation, give appropiate error message */
+ /* We failed negotiation, give appropriate error message */
if (c->c2.tls_multi->remote_ciphername)
{
msg(D_TLS_ERRORS, "OPTIONS ERROR: failed to negotiate "
"cipher with server. Add the server's "
- "cipher ('%s') to --data-ciphers (currently '%s') if "
- "you want to connect to this server.",
+ "cipher ('%s') to --data-ciphers (currently '%s'), e.g."
+ "--data-ciphers %s:%s if you want to connect to this server.",
c->c2.tls_multi->remote_ciphername,
- c->options.ncp_ciphers);
+ c->options.ncp_ciphers_conf, c->options.ncp_ciphers_conf,
+ c->c2.tls_multi->remote_ciphername);
return false;
}
@@ -517,10 +519,13 @@
if (!session->opt->server && !cipher_allowed_as_fallback
&& !tls_item_in_cipher_list(options->ciphername, options->ncp_ciph=
ers))
{
- msg(D_TLS_ERRORS, "Error: negotiated cipher not allowed - %s not i=
n %s",
- options->ciphername, options->ncp_ciphers);
+ struct gc_arena gc =3D gc_new();
+ msg(D_TLS_ERRORS, "Error: negotiated cipher not allowed - %s not i=
n %s%s",
+ options->ciphername, options->ncp_ciphers_conf,
+ ncp_expanded_ciphers(options, &gc));
/* undo cipher push, abort connection setup */
options->ciphername =3D session->opt->config_ciphername;
+ gc_free(&gc);
return false;
}
else
@@ -528,3 +533,100 @@
return true;
}
}
+
+/**
+ * Replaces the string DEFAULT with the string \c replace.
+ *
+ * @param o Options struct to modify and to use the gc from
+ * @param replace string used to replace the DEFAULT string
+ */
+static void
+replace_default_in_ncp_ciphers_option(struct options *o, const char *repla=
ce)
+{
+ const char *search =3D "DEFAULT";
+ const int ncp_ciphers_len =3D strlen(o->ncp_ciphers) + strlen(replace)=
- strlen(search) + 1;
+
+ uint8_t *ncp_ciphers =3D gc_malloc(ncp_ciphers_len, true, &o->gc);
+
+ struct buffer ncp_ciphers_buf;
+ buf_set_write(&ncp_ciphers_buf, ncp_ciphers, ncp_ciphers_len);
+
+ const char *def =3D strstr(o->ncp_ciphers, search);
+
+ /* Copy everything before the DEFAULT string */
+ buf_write(&ncp_ciphers_buf, o->ncp_ciphers, def - o->ncp_ciphers);
+
+ /* copy the default string. */
+ buf_write(&ncp_ciphers_buf, replace, strlen(replace));
+
+ /* copy the rest of the ncp cipher string */
+ const char *after_default =3D def + strlen(search);
+ buf_write(&ncp_ciphers_buf, after_default, strlen(after_default));
+
+ o->ncp_ciphers =3D (char *) ncp_ciphers;
+}
+
+/**
+ * Checks for availibility of Chacha20-Poly1305 and sets
+ * the ncp_cipher to either AES-256-GCM:AES-128-GCM or
+ * AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305.
+ */
+void
+options_postprocess_setdefault_ncpciphers(struct options *o)
+{
+ bool default_in_cipher_list =3D o->ncp_ciphers
+ && tls_item_in_cipher_list("DEFAULT", o-=
>ncp_ciphers);
+
+ /* preserve the values that the user put into the configuration */
+ o->ncp_ciphers_conf =3D o->ncp_ciphers;
+
+ /* check if crypto library supports chacha */
+ bool can_do_chacha =3D cipher_valid("CHACHA20-POLY1305");
+
+ if (can_do_chacha && dco_enabled(o))
+ {
+ /* also make sure that dco supports chacha */
+ can_do_chacha =3D tls_item_in_cipher_list("CHACHA20-POLY1305", dco=
_get_supported_ciphers());
+ }
+
+ const char *default_ciphers =3D "AES-256-GCM:AES-128-GCM:CHACHA20-POLY=
1305";
+
+ if (!can_do_chacha)
+ {
+ default_ciphers =3D "AES-256-GCM:AES-128-GCM";
+ }
+
+ /* want to rather print DEFAULT instead of a manually set default list=
*/
+ if (!o->ncp_ciphers_conf || !strcmp(default_ciphers, o->ncp_ciphers_co=
nf))
+ {
+ o->ncp_ciphers =3D default_ciphers;
+ o->ncp_ciphers_conf =3D "DEFAULT";
+ }
+ else if (!default_in_cipher_list)
+ {
+ /* custom cipher list without DEFAULT string in it,
+ * nothing to replace/mutate */
+ return;
+ }
+ else
+ {
+ replace_default_in_ncp_ciphers_option(o, default_ciphers);
+ }
+}
+
+const char *
+ncp_expanded_ciphers(struct options *o, struct gc_arena *gc)
+{
+ if (!strcmp(o->ncp_ciphers, o->ncp_ciphers_conf))
+ {
+ /* expanded ciphers and user set ciphers are identical, no need to
+ * add an expanded version */
+ return "";
+ }
+
+ /* two extra brackets, one space, NUL byte */
+ struct buffer expanded_ciphers_buf =3D alloc_buf_gc(strlen(o->ncp_ciph=
ers) + 4, gc);
+
+ buf_printf(&expanded_ciphers_buf, " (%s)", o->ncp_ciphers);
+ return BSTR(&expanded_ciphers_buf);
+}
diff --git a/src/openvpn/ssl_ncp.h b/src/openvpn/ssl_ncp.h
index 0bdb6a0..36be65b 100644
--- a/src/openvpn/ssl_ncp.h
+++ b/src/openvpn/ssl_ncp.h
@@ -157,4 +157,23 @@
bool
check_session_cipher(struct tls_session *session, struct options *options);
+/**
+ * Checks for availability of Chacha20-Poly1305 and sets
+ * the ncp_cipher to either AES-256-GCM:AES-128-GCM or
+ * AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305 if not set.
+ *
+ * If DEFAULT is in the ncp_cipher string, it will be replaced
+ * by the default cipher string as defined above.
+ */
+void
+options_postprocess_setdefault_ncpciphers(struct options *o);
+
+/** returns the o->ncp_ciphers in brackets, e.g.
+ * (AES-256-GCM:CHACHA20-POLY1305) if o->ncp_ciphers_conf
+ * and o->ncp_ciphers differ, otherwise an empty string
+ *
+ * The returned string will be allocated in the passed \c gc
+ */
+const char *
+ncp_expanded_ciphers(struct options *o, struct gc_arena *gc);
#endif /* ifndef OPENVPN_SSL_NCP_H */
diff --git a/tests/unit_tests/openvpn/test_ncp.c b/tests/unit_tests/openvpn=
/test_ncp.c
index a8e1021..b744e96 100644
--- a/tests/unit_tests/openvpn/test_ncp.c
+++ b/tests/unit_tests/openvpn/test_ncp.c
@@ -54,6 +54,17 @@
ASSERT(0);
}
+
+/* Define a dummy dco cipher option to avoid linking against all the DCO
+ * units */
+#if defined(ENABLE_DCO)
+const char *
+dco_get_supported_ciphers(void)
+{
+ return "AES-192-GCM:AES-128-CBC:AES-256-GCM:AES-128-GCM:CHACHA20-POLY1=
305";
+}
+#endif
+
static void
test_check_ncp_ciphers_list(void **state)
{
@@ -260,13 +271,135 @@
gc_free(&gc);
}
+static void
+test_ncp_default(void **state)
+{
+ bool have_chacha =3D cipher_valid("CHACHA20-POLY1305");
+
+ struct options o =3D { 0 };
+
+ o.gc =3D gc_new();
+
+ /* no user specified string */
+ o.ncp_ciphers =3D NULL;
+ options_postprocess_setdefault_ncpciphers(&o);
+
+ if (have_chacha)
+ {
+ assert_string_equal(o.ncp_ciphers, "AES-256-GCM:AES-128-GCM:CHACHA=
20-POLY1305");
+ }
+ else
+ {
+ assert_string_equal(o.ncp_ciphers, "AES-256-GCM:AES-128-GCM");
+ }
+ assert_string_equal(o.ncp_ciphers_conf, "DEFAULT");
+
+ /* check that a default string is replaced with DEFAULT */
+ if (have_chacha)
+ {
+ o.ncp_ciphers =3D "AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305";
+ }
+ else
+ {
+ o.ncp_ciphers =3D "AES-256-GCM:AES-128-GCM";
+ }
+
+ options_postprocess_setdefault_ncpciphers(&o);
+ assert_string_equal(o.ncp_ciphers_conf, "DEFAULT");
+
+ /* test default in the middle of the string */
+ o.ncp_ciphers =3D "BF-CBC:DEFAULT:AES-128-CBC:AES-256-CBC";
+ options_postprocess_setdefault_ncpciphers(&o);
+
+ if (have_chacha)
+ {
+ assert_string_equal(o.ncp_ciphers, "BF-CBC:AES-256-GCM:AES-128-GCM=
:CHACHA20-POLY1305:AES-128-CBC:AES-256-CBC");
+ }
+ else
+ {
+ assert_string_equal(o.ncp_ciphers, "BF-CBC:AES-256-GCM:AES-128-GCM=
:AES-128-CBC:AES-256-CBC");
+ }
+ assert_string_equal(o.ncp_ciphers_conf, "BF-CBC:DEFAULT:AES-128-CBC:AE=
S-256-CBC");
+
+ /* string at the beginning */
+ o.ncp_ciphers =3D "DEFAULT:AES-128-CBC:AES-192-CBC";
+ options_postprocess_setdefault_ncpciphers(&o);
+
+ if (have_chacha)
+ {
+ assert_string_equal(o.ncp_ciphers, "AES-256-GCM:AES-128-GCM:CHACHA=
20-POLY1305:AES-128-CBC:AES-192-CBC");
+ }
+ else
+ {
+ assert_string_equal(o.ncp_ciphers, "AES-256-GCM:AES-128-GCM:AES-12=
8-CBC:AES-192-CBC");
+ }
+ assert_string_equal(o.ncp_ciphers_conf, "DEFAULT:AES-128-CBC:AES-192-C=
BC");
+
+ /* DEFAULT at the end */
+ o.ncp_ciphers =3D "AES-192-GCM:AES-128-CBC:DEFAULT";
+ options_postprocess_setdefault_ncpciphers(&o);
+
+ if (have_chacha)
+ {
+ assert_string_equal(o.ncp_ciphers, "AES-192-GCM:AES-128-CBC:AES-25=
6-GCM:AES-128-GCM:CHACHA20-POLY1305");
+ }
+ else
+ {
+ assert_string_equal(o.ncp_ciphers, "AES-192-GCM:AES-128-CBC:AES-25=
6-GCM:AES-128-GCM");
+ }
+ assert_string_equal(o.ncp_ciphers_conf, "AES-192-GCM:AES-128-CBC:DEFAU=
LT");
+
+ gc_free(&o.gc);
+}
+
+static void
+test_ncp_expand(void **state)
+{
+ bool have_chacha =3D cipher_valid("CHACHA20-POLY1305");
+ struct options o =3D {0};
+
+ o.gc =3D gc_new();
+ struct gc_arena gc =3D gc_new();
+
+ /* no user specified string */
+ o.ncp_ciphers =3D NULL;
+ options_postprocess_setdefault_ncpciphers(&o);
+
+ const char *expanded =3D ncp_expanded_ciphers(&o, &gc);
+
+ /* user specificed string with DEFAULT in it */
+ o.ncp_ciphers =3D "AES-192-GCM:DEFAULT";
+ options_postprocess_setdefault_ncpciphers(&o);
+ const char *expanded2 =3D ncp_expanded_ciphers(&o, &gc);
+
+ if (have_chacha)
+ {
+ assert_string_equal(expanded, " (AES-256-GCM:AES-128-GCM:CHACHA20-=
POLY1305)");
+ assert_string_equal(expanded2, " (AES-192-GCM:AES-256-GCM:AES-128-=
GCM:CHACHA20-POLY1305)");
+ }
+ else
+ {
+ assert_string_equal(expanded, " (AES-256-GCM:AES-128-GCM)");
+ assert_string_equal(expanded2, " (AES-192-GCM:AES-256-GCM:AES-128-=
GCM)");
+ }
+
+ o.ncp_ciphers =3D "AES-192-GCM:BF-CBC";
+ options_postprocess_setdefault_ncpciphers(&o);
+
+ assert_string_equal(ncp_expanded_ciphers(&o, &gc), "");
+
+ gc_free(&o.gc);
+ gc_free(&gc);
+}
const struct CMUnitTest ncp_tests[] =3D {
cmocka_unit_test(test_check_ncp_ciphers_list),
cmocka_unit_test(test_extract_client_ciphers),
cmocka_unit_test(test_poor_man),
- cmocka_unit_test(test_ncp_best)
+ cmocka_unit_test(test_ncp_best),
+ cmocka_unit_test(test_ncp_default),
+ cmocka_unit_test(test_ncp_expand),
};
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/828?usp=3Demail
To unsubscribe, or for help writing mail filters, visit http://gerrit.openv=
pn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia1c5209022d3ab4c0dac6438c41891c7d059f812
Gerrit-Change-Number: 828
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos
Gerrit-Reviewer: flichtenheld
Gerrit-CC: openvpn-devel
Gerrit-MessageType: newpatchset
--JGjh1ZVQUnY=
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
cron2 uploaded patch set #4 to the change originally cr=
eated by plaisthos.
View Change
The following approvals got outdated=
and were removed:
Code-Review+2 by flichtenheld
Allow DEFAULT in data-ciphers and report both=
expanded and user set option
This adds support for parsing DEFAULT =
in data-ciphers, the idea is that people
can modify the default without =
repeating the default ciphers.
In the past we have seem that people =
will use data-ciphers BF-CBC or
data-ciphers AES-128-CBC when getting th=
e warning that the cipher is not
supported by the server. This commit a=
ims to provide a better way for
these situation as we still want people =
to rely on default cipher selection
from OpenVPN when possible.
C=
hange-Id: Ia1c5209022d3ab4c0dac6438c41891c7d059f812
Signed-off-by: Arne =
Schwabe <arne@...1227...>
Acked-by: Frank Lichtenheld <frank@...1186...=
.2641...>
Message-Id: <20241227124632.110920-1-frank@...2641...>=
;
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/=
msg30245.html
Signed-off-by: Gert Doering <gert@...1296...>
---=
M Changes.rst
M doc/man-sections/protocol-options.rst
M src/openv=
pn/multi.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/o=
penvpn/ssl_ncp.c
M src/openvpn/ssl_ncp.h
M tests/unit_tests/openvpn/t=
est_ncp.c
8 files changed, 284 insertions(+), 48 deletions(-)
=
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/28/828/4
=
diff --git a/Changes.rst b/Changes.rst
index 34542a5..16=
ae6fc 100644
--- a/Changes.rst
+++ b/Change=
s.rst
@@ -30,6 +30,12 @@
=
https://datatracker.ietf.org/doc/draft-irtf-cfrg-aead-limits/
+Default ci=
phers in ``--data-ciphers``
+ Ciphers in ``--data-ciphers`` can contain the string DEFAULT th=
at is
+ replaced b=
y the default ciphers used by OpenVPN, making it easier to
+ add an allowed cipher without ha=
ving to spell out the default ciphers.
+
+=
Deprecated features
-------------------<=
/span>
``secret`` support has been removed by default.
=
diff --git a/doc/man-sections/protocol-options.rst b/doc/man-sections=
/protocol-options.rst
index 05f87cc..d04ace8 100644<=
br>--- a/doc/man-sections/protocol-options.rst
+++ b/=
doc/man-sections/protocol-options.rst
@@ -178,6 +178,12 @@<=
/span>
Chacha20-Poly1305 if the underlying SSL library (and its=
configuration)
supports it.
+ Starting with OpenVPN 2.7 t=
he special keyword :code:`DEFAULT` can be used
+ in the string and is replaced by the default c=
iphers. This can be used to
+ add an additional allowed cipher to the allowed ciphers, e.g.
+ :code:`DEFAULT:AES-1=
92-CBC` to use the default ciphers but also allow
+ :code:`AES-192-CBC`.
+
Cipher negotiation is=
enabled in client-server mode only. I.e. if
``--mode`` =
is set to `server` (server-side, implied by setting
``--=
server`` ), or if ``--pull`` is specified (client-side, implied bydiff --git a/src/openvpn/multi.c b/src/openvpn/multi.c
index 67bb58f..f426b46 100644
--- a/src/openvpn/multi.c=
+++ b/src/openvpn/multi.c
@@ -1897,14 +189=
7,15 @@
if (strlen(peer_ciphers) > 0)
{
msg(M_INFO, "PUSH: No common cipher=
between server and client. "
- "Server data-ciphers: '%s', client su=
pported ciphers '%s'",
- o->ncp_ciphers, peer_ciphers);
+ "Server data-ciphe=
rs: '%s'%s, client supported ciphers '%s'",
=
+ o->ncp_ciphers_=
conf, ncp_expanded_ciphers(o, &gc), peer_ciphers);
=
}
else if (tls_multi->remote_ciphername)
{
msg(M_INFO, "PUSH: No common ci=
pher between server and client. "
- "Server data-ciphers: '%s', clien=
t supports cipher '%s'",
- o->ncp_ciphers, tls_multi->remote_ciphern=
ame);
+ &q=
uot;Server data-ciphers: '%s'%s, client supports cipher '%s'=
;",
+ =
o->ncp_ciphers_conf, ncp_expanded_ciphers(o, &gc),
+ tls_multi->remote_cip=
hername);
}
else
=
{
diff --git a/src/openvpn/options.c b/src/openvpn/opt=
ions.c
index 20e8d55..1c35d67 100644
--- a/=
src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -3486,40 +3486,6 @@
}
}
-=
-/**
- * Checks for availibility of Chacha20-Poly130=
5 and sets
- * the ncp_=
cipher to either AES-256-GCM:AES-128-GCM or
- * AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305.<=
br>- */
-static void
-options_postprocess_setdefault_ncpciphers(struct options =
*o)
-{
- if (o->ncp_ciphers)
<=
span style=3D"color: hsl(0, 100%, 40%);">- {
- /* custom --data-ciphers set, keep list *=
/
- return;
- }
-
- /* check if crypto library supports chacha */
- bool can_do_chacha =3D cipher_v=
alid("CHACHA20-POLY1305");
-
- if=
(can_do_chacha && dco_enabled(o))
- {
- /* also make sure that dco supports chacha */
- can_do_chacha =3D tls_item_in_=
cipher_list("CHACHA20-POLY1305", dco_get_supported_ciphers());
- }
-
- if (can_do_chacha)
- {
- =
o->ncp_ciphers =3D "AES-256-GCM:AES-128-GCM:CHACHA20-POLY130=
5";
- }<=
br>- else
- {
- o->ncp_ciphers =3D "AES-256-GCM:AES-128-GC=
M";
- }<=
br>-}
-
static void
op=
tions_postprocess_cipher(struct options *o)
{
@@ -3550,7 +3516,8 @@
"defaulted to B=
F-CBC as fallback when cipher negotiation "
=
"failed in this case. If you need this fallback please add "=
span>
"'--data-ciphers-fallback BF-CBC' =
to your configuration "
- "and/or add BF-CBC to --data-ciphers.");
+ "and/or =
add BF-CBC to --data-ciphers. E.g. "
+ "--data-ciphers %s:BF-CBC", o-&=
gt;ncp_ciphers_conf);
}
else if (=
!o->enable_ncp_fallback
&& !tls_it=
em_in_cipher_list(o->ciphername, o->ncp_ciphers))
@@ =
-3558,7 +3525,7 @@
msg(M_WARN, "DEPRECATED OP=
TION: --cipher set to '%s' but missing in "
=
"--data-ciphers (%s). OpenVPN ignores --cipher for cipher &=
quot;
"negotiations. ",
- o->ciphername, o-&g=
t;ncp_ciphers);
+ =
o->ciphername, o->ncp_ciphers_conf);
}=
span>
}
diff --git a/src/openvp=
n/options.h b/src/openvpn/options.h
index 6ab92e2..55f12dd =
100644
--- a/src/openvpn/options.h
+++ b/sr=
c/openvpn/options.h
@@ -559,6 +559,8 @@
=
const char *ciphername;
bool enable_ncp_fallback; =
/**< If defined fall back to
=
* ciphername if NCP fails */
+ /** The original ncp_ciphers specified by the user=
in the configuration*/
+ const char *ncp_ciphers_conf;
const char *ncp_=
ciphers;
const char *authname;
co=
nst char *engine;
diff --git a/src/openvpn/ssl_ncp.c b/src/=
openvpn/ssl_ncp.c
index 167bdb2..b238fc0 100644
<=
span>--- a/src/openvpn/ssl_ncp.c
+++ b/src/openvpn/ssl_ncp.=
c
@@ -40,6 +40,8 @@
#include "config.=
h"
#endif
+#include <string.h>
+
#include "syshea=
d.h"
#include "win32.h"
=
span>
@@ -223,7 +225,6 @@
r=
eturn token !=3D NULL;
}
-
const char *
tls_pee=
r_ncp_list(const char *peer_info, struct gc_arena *gc)
{=
span>
@@ -335,15 +336,16 @@
return true;<=
/span>
}
- /* We failed negotiation, give appropiate error mess=
age */
+ /* We fai=
led negotiation, give appropriate error message */
if =
(c->c2.tls_multi->remote_ciphername)
{
msg(D_TLS_ERRORS, "OPTIONS ERROR: failed to negotiate =
"
"cipher with server. Add the serv=
er's "
- =
"cipher ('%s') to --data-ciphers (currently '%s'=
) if "
- =
"you want to connect to this server.",
+ "cipher ('%s') to -=
-data-ciphers (currently '%s'), e.g."
+ "--data-ciphers %s:%s if yo=
u want to connect to this server.",
c->=
;c2.tls_multi->remote_ciphername,
- c->options.ncp_ciphers);
+ c->options.ncp_ciphers_co=
nf, c->options.ncp_ciphers_conf,
+ c->c2.tls_multi->remote_ciphername);
return false;
}=
@@ -517,10 +519,13 @@
if (!session-&g=
t;opt->server && !cipher_allowed_as_fallback
=
&& !tls_item_in_cipher_list(options->ciphername, options-&=
gt;ncp_ciphers))
{
- msg(D_TLS_ERRORS, "Error: negotiated cipher =
not allowed - %s not in %s",
- options->ciphername, options->ncp_ciphers);=
span>
+ struct gc_are=
na gc =3D gc_new();
+=
msg(D_TLS_ERRORS, "Error: negotiated cipher not allowed - %s n=
ot in %s%s",
+ =
options->ciphername, options->ncp_ciphers_conf,
<=
span style=3D"color: hsl(120, 100%, 40%);">+ ncp_expanded_cipher=
s(options, &gc));
/* undo cipher push, abort c=
onnection setup */
options->ciphername =3D sess=
ion->opt->config_ciphername;
+ gc_free(&gc);
return fa=
lse;
}
else
@@ -5=
28,3 +533,100 @@
return true;
=
}
}
+
+/**
+ * Replaces the string DEFAULT wi=
th the string \c replace.
+ *
+ * @param o=
Options struct to modify and to use the gc from
+ * @param replace string used to rep=
lace the DEFAULT string
+ */
+static void<=
/span>
+replace_default_in_n=
cp_ciphers_option(struct options *o, const char *replace)
+{
+ const char *search =3D "DEFAULT";<=
br>+ const int ncp_ciphers_l=
en =3D strlen(o->ncp_ciphers) + strlen(replace) - strlen(search) + 1;
+
+ uint8_t *ncp_ciphers =3D gc_malloc(nc=
p_ciphers_len, true, &o->gc);
+
+ =
struct buffer ncp_ciphers_buf;
+ buf_set_write(&ncp_ciphers_buf, ncp_ciphers, ncp_ciphe=
rs_len);
+
=
+ const char *def =3D strstr=
(o->ncp_ciphers, search);
+
+ /* Cop=
y everything before the DEFAULT string */
+ buf_write(&ncp_ciphers_buf, o->ncp_ciphers=
, def - o->ncp_ciphers);
+
+ /* copy=
the default string. */
+ buf_write(&ncp_ciphers_buf, replace, strlen(replace));+
+ /* copy the rest of the ncp cipher string *=
/
+ const char *af=
ter_default =3D def + strlen(search);
+ buf_write(&ncp_ciphers_buf, after_default, strlen=
(after_default));
+=
span>
+ o->ncp_ciphers=
=3D (char *) ncp_ciphers;
+}
+
=
+/**
+ * Checks for availibility of Chacha20-Poly130=
5 and sets
+ * the nc=
p_cipher to either AES-256-GCM:AES-128-GCM or
+ * AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305.
+ */
+void
+options_postprocess_setdefault_ncpciphers(struct optio=
ns *o)
+{
<=
span style=3D"color: hsl(120, 100%, 40%);">+ bool default_in_cipher_list=
=3D o->ncp_ciphers
+ && tls_item_in_cipher_list(&qu=
ot;DEFAULT", o->ncp_ciphers);
+
+ =
/* preserve the values that the user put into the configuration */
+ o->ncp_ciphers_con=
f =3D o->ncp_ciphers;
+
+ /* check i=
f crypto library supports chacha */
+ bool can_do_chacha =3D cipher_valid("CHACHA20-POLY=
1305");
+=
+ if (can_do_chacha &=
;& dco_enabled(o))
+ {
+ /* =
also make sure that dco supports chacha */
+ can_do_chacha =3D tls_item_in_cipher_list(&q=
uot;CHACHA20-POLY1305", dco_get_supported_ciphers());
+ }
+
+ const char *default_ciphers =3D "AES-256-GCM:AES-128-GCM:CHA=
CHA20-POLY1305";
+
+ if (!can_do_c=
hacha)
+ {<=
br>+ default_ciphers =3D=
"AES-256-GCM:AES-128-GCM";
+ }
+
+ /* want to =
rather print DEFAULT instead of a manually set default list */
+ if (!o->ncp_ciphers_conf =
|| !strcmp(default_ciphers, o->ncp_ciphers_conf))
+ {
+ o->ncp_ciphers =3D default_ciphers;+ o->ncp_ciphers_co=
nf =3D "DEFAULT";
+ }
+ el=
se if (!default_in_cipher_list)
+ {
+ =
/* custom cipher list without DEFAULT string in it,
+ * nothing to replace/mutate =
*/
+ return;=
span>
+ }
+ else
+ {
+ replace_default_in_ncp_ciphers_option(o, default_cip=
hers);
+ }<=
br>+}
+
+const char *
+ncp_expanded_ciphers(struct options *o, struct gc_arena *gc)
=
+{
+ if (!strcmp(o->ncp_ciphers, o->ncp_cip=
hers_conf))
+ {
+ /* expanded ci=
phers and user set ciphers are identical, no need to
+ * add an expanded version */
+ return "&q=
uot;;
+ }+
+ /* two extra brackets, one space, NUL byte =
*/
+ struct buffer=
expanded_ciphers_buf =3D alloc_buf_gc(strlen(o->ncp_ciphers) + 4, gc);<=
/span>
+
+ buf_printf(&expanded_ciphers_bu=
f, " (%s)", o->ncp_ciphers);
+ return BSTR(&expanded_ciphers_buf);
+}
diff --git =
a/src/openvpn/ssl_ncp.h b/src/openvpn/ssl_ncp.h
index 0bdb6=
a0..36be65b 100644
--- a/src/openvpn/ssl_ncp.h
+++ b/src/openvpn/ssl_ncp.h
@@ -157,4 +157,23 @@=
bool
check_session_cipher(struct tls_session *s=
ession, struct options *options);
+/**
+ * Checks for availability of Chacha20-Poly1305 and sets<=
/span>
+ * the ncp_cipher to=
either AES-256-GCM:AES-128-GCM or
+ * AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305 if not set.
+ *
+ * If DEFAULT is in the ncp_cipher strin=
g, it will be replaced
+ * by the default cipher string as defined above.
+ */
+void
+options_postprocess_setdefault_ncpciphers(struct options *o);
=
+
+/** returns the o->ncp_ciphers in brackets, e.=
g.
+ * (AES-256-GCM:=
CHACHA20-POLY1305) if o->ncp_ciphers_conf
+ * and o->ncp_ciphers differ, otherwise an emp=
ty string
+ *<=
br>+ * The returned string wil=
l be allocated in the passed \c gc
+ */
+c=
onst char *
+ncp_expa=
nded_ciphers(struct options *o, struct gc_arena *gc);
#end=
if /* ifndef OPENVPN_SSL_NCP_H */
diff --git a/tests/unit_t=
ests/openvpn/test_ncp.c b/tests/unit_tests/openvpn/test_ncp.c
index a8e1021..b744e96 100644
--- a/tests/unit_tests/ope=
nvpn/test_ncp.c
+++ b/tests/unit_tests/openvpn/test_ncp.c=
span>
@@ -54,6 +54,17 @@
ASSERT(0);
}
+
+/* Define a=
dummy dco cipher option to avoid linking against all the DCO
+ * units */
+#if defined(ENABLE_DCO)
+const char *
+dco_get_supported_ciphers(void)
+{
+ return "AES-192-GCM:AES-128-CBC:AES-256-G=
CM:AES-128-GCM:CHACHA20-POLY1305";
+}
+#endif
+
=
static void
test_check_ncp_ciphers_list(void **stat=
e)
{
@@ -260,13 +271,135 @@
gc_free(&gc);
}
+static void
+test_ncp_default(void **state)
=
+{
+ bool have_chacha =3D cipher_valid("CHAC=
HA20-POLY1305");
+
+ struct option=
s o =3D { 0 };
+
+ o.gc =3D gc_new();=
span>
+
+ /* no user specified string */
+ o.ncp_ciphers =3D NUL=
L;
+ options_postp=
rocess_setdefault_ncpciphers(&o);
+
+ =
if (have_chacha)
+=
{
+ assert=
_string_equal(o.ncp_ciphers, "AES-256-GCM:AES-128-GCM:CHACHA20-POLY130=
5");
+ }
+ else
+ {
+ assert_string_equal(o.ncp_ciphers, "=
AES-256-GCM:AES-128-GCM");
+ }
+ =
assert_string_equal(o.ncp_ciphers_conf, "DEFAULT");
<=
span style=3D"color: hsl(120, 100%, 40%);">+
+ /* check that a default string is replaced wit=
h DEFAULT */
+ if =
(have_chacha)
+ {<=
/span>
+ o.ncp_cipher=
s =3D "AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305";
+ }
+ else
+ {
+ o.ncp_ciphers =3D "AES-256-GCM:AES-128-GCM";
=
+ }
+
+ options_postprocess_setdefault_ncpciphers(&o);+ assert_string_equal(o.nc=
p_ciphers_conf, "DEFAULT");
+
+ =
/* test default in the middle of the string */
+ o.ncp_ciphers =3D "BF-CBC:DEFAULT:AE=
S-128-CBC:AES-256-CBC";
+ options_postprocess_setdefault_ncpciphers(&o);
<=
span style=3D"color: hsl(120, 100%, 40%);">+
+ if (have_chacha)
+ {
+ assert_string_equal(o.ncp_ciphers, "BF-CBC:AES-256=
-GCM:AES-128-GCM:CHACHA20-POLY1305:AES-128-CBC:AES-256-CBC");+ }
+ else
+ {
+ assert_string_equal(o.ncp_ciphers, "BF-CBC:AES-256-GC=
M:AES-128-GCM:AES-128-CBC:AES-256-CBC");
+ }
+ assert_string_equal(o.ncp_ciphers_conf, "BF-CBC:DEFAUL=
T:AES-128-CBC:AES-256-CBC");
+
+ /=
* string at the beginning */
+ o.ncp_ciphers =3D "DEFAULT:AES-128-CBC:AES-192-CBC";=
+ options_postpro=
cess_setdefault_ncpciphers(&o);
+
+ =
if (have_chacha)
+ =
{
+ assert_s=
tring_equal(o.ncp_ciphers, "AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305:=
AES-128-CBC:AES-192-CBC");
+ }
+ =
else
+ {<=
br>+ assert_string_equal=
(o.ncp_ciphers, "AES-256-GCM:AES-128-GCM:AES-128-CBC:AES-192-CBC"=
);
+ }
<=
span style=3D"color: hsl(120, 100%, 40%);">+ assert_string_equal(o.ncp_c=
iphers_conf, "DEFAULT:AES-128-CBC:AES-192-CBC");
+
+ /* DEFAULT at the end */
+ o.ncp_ciphers =3D "AES-192-GCM:AES-12=
8-CBC:DEFAULT";
=
+ options_postprocess_setdefault_ncpciphers(&o);
+
+ if (have_chacha)
+ {
+ assert_string_equal(o.ncp_ciphers, "AES-192-GCM:AES-128-CB=
C:AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305");
+ }
+ else
+ {
+ =
assert_string_equal(o.ncp_ciphers, "AES-192-GCM:AES-128-CBC:AES-256=
-GCM:AES-128-GCM");
+ }
+ asser=
t_string_equal(o.ncp_ciphers_conf, "AES-192-GCM:AES-128-CBC:DEFAULT&qu=
ot;);
+
+ gc_free(&o.gc);
+}
+
+static void
=
+test_ncp_expand(void **state)
+{
+ boo=
l have_chacha =3D cipher_valid("CHACHA20-POLY1305");
+ struct options o =3D {0};
+
+ o.gc =3D gc_new();
+ struct gc_arena gc =3D gc_new();=
span>
+
+ /* no user specified string */
+ o.ncp_ciphers =3D NUL=
L;
+ options_postp=
rocess_setdefault_ncpciphers(&o);
+
+ =
const char *expanded =3D ncp_expanded_ciphers(&o, &gc);+
+ /* user specificed string with DEFAULT in i=
t */
+ o.ncp_ciphe=
rs =3D "AES-192-GCM:DEFAULT";
+ options_postprocess_setdefault_ncpciphers(&o);<=
/span>
+ const char *expa=
nded2 =3D ncp_expanded_ciphers(&o, &gc);
+
+ if (have_chacha)
+ {
+ =
assert_string_equal(expanded, " (AES-256-GCM:AES-128-GCM:CHACHA20=
-POLY1305)");
+ =
assert_string_equal(expanded2, " (AES-192-GCM:AES-256-GCM:AES-1=
28-GCM:CHACHA20-POLY1305)");
+ }
+=
else
+ {
+ assert_string_equ=
al(expanded, " (AES-256-GCM:AES-128-GCM)");
+ assert_string_equal(expanded2, &q=
uot; (AES-192-GCM:AES-256-GCM:AES-128-GCM)");
+ }
+
+ =
o.ncp_ciphers =3D "AES-192-GCM:BF-CBC";
+ options_postprocess_setdefault_ncpcip=
hers(&o);
+
+ assert_string_equal(n=
cp_expanded_ciphers(&o, &gc), "");
+
+ gc_free(&o.gc);
+ gc_free(&gc);
+}
=
const struct CMUnitTest ncp_tests[] =3D {
cmocka_unit=
_test(test_check_ncp_ciphers_list),
cmocka_unit_test(t=
est_extract_client_ciphers),
cmocka_unit_test(test_poo=
r_man),
- cmocka_uni=
t_test(test_ncp_best)
+ cmocka_unit_test(test_ncp_best),
+ cmocka_unit_test(test_ncp_default),
+ cmocka_unit_test(test_ncp_expand=
),
};
=
To view, visit change 828. To unsubscribe, or for help writi=
ng mail filters, visit setti=
ngs.
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia1c5209022d3ab4c0dac6438c41=
891c7d059f812
Gerrit-Change-Number: 828
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <arne-openvpn@...1711...=
27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...=
1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...=
ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--JGjh1ZVQUnY=--