Move extract_iv_proto to ssl_util.c/h
PATCH 1/2 Move extract_iv_proto to ssl_util.c/h
This function is used by both NCP and push, so move it to a more proper place.
--- src/openvpn/multi.c | 1 + src/openvpn/push.c | 18 +----------------- src/openvpn/push.h | 10 ---------- src/openvpn/ssl_util.c | 16 ++++++++++++++++ src/openvpn/ssl_util.h | 8 ++++++++ 5 files changed, 26 insertions(+), 27 deletions(-)
src/openvpn/multi.c +1 -0
@@ -51,6 +51,7 @@#include "crypto_backend.h" +#include "ssl_util.h" /*#define MULTI_DEBUG_EVENT_LOOP*/
src/openvpn/push.c +1 -17
@@ -37,6 +37,7 @@#include "manage.h" #include "memdbg.h" +#include "ssl_util.h" #if P2MP
@@ -1057,21 +1058,4 @@ remove_iroutes_from_push_route_list(struct options *o) gc_free(&gc); } } - -unsigned int -extract_iv_proto (const char *peer_info) -{ -const char *optstr = peer_info ?strstr (peer_info,"IV_PROTO=" ) :NULL ; -if (optstr) - { -int proto =0 ; -int r =sscanf (optstr,"IV_PROTO=%d" , &proto); -if (r ==1 && proto >0 ) - { -return proto; - } - } -return 0 ; -} -#endif /* if P2MP */
src/openvpn/push.h +0 -10
@@ -91,16 +91,6 @@ void send_restart(struct context *c, const char *kill_msg);*/ void send_push_reply_auth_token (struct tls_multi *multi); - -/** -* Extracts the IV_PROTO variable and returns its value or 0 -* if it cannot be extracted. -* -* @param peer_info peer info string to search for IV_PROTO -*/ -unsigned int -extract_iv_proto (const char *peer_info); -/** * Parses an AUTH_PENDING message and if in pull mode extends the timeout *
src/openvpn/ssl_util.c +16 -0
@@ -59,3 +59,19 @@ extract_var_peer_info(const char *peer_info, const char *var, var_value[var_end - var_start] ='\0' ;return var_value; } + +unsigned int +extract_iv_proto (const char *peer_info) +{ +const char *optstr = peer_info ?strstr (peer_info,"IV_PROTO=" ) :NULL ; +if (optstr) + { +int proto =0 ; +int r =sscanf (optstr,"IV_PROTO=%d" , &proto); +if (r ==1 && proto >0 ) + { +return proto; + } + } +return 0 ; +}
src/openvpn/ssl_util.h +8 -0
@@ -46,4 +46,12 @@ extract_var_peer_info(const char *peer_info,const char *var, struct gc_arena *gc); +/** +* Extracts the IV_PROTO variable and returns its value or 0 +* if it cannot be extracted. +* +* @param peer_info peer info string to search for IV_PROTO +*/ +unsigned int +extract_iv_proto (const char *peer_info);#endif
Signature · 1 line
2.30.1
PATCH 2/2 Implement '--compress migrate' to migrate to non-compression setup
This option allow migration to a non compression server config while still retraining compatibility with client that have a compression setting in their config.
For existing setups that used to have comp-lzo no or another compression setting in their configs it is a difficult to migrate to a setup without compression without replacing all client configs at once especially if OpenVPN 2.3 or earlier clients are in the mix that do not support pushing stub-v2. Even with OpenVPN 2.4 and later clients that support pushing this is not a satisfying solution as the clients log occ mismatches and the "push stub-v2" needs to be in the server config "forever".
--- doc/man-sections/protocol-options.rst | 12 +++- src/openvpn/comp.h | 1 + src/openvpn/multi.c | 41 +++++++++++++ src/openvpn/options.c | 6 ++ src/openvpn/ssl.c | 34 ++++++++++- src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_util.c | 43 ++++++++++++++ src/openvpn/ssl_util.h | 15 +++++ tests/unit_tests/openvpn/Makefile.am | 14 ++++- tests/unit_tests/openvpn/test_misc.c | 83 +++++++++++++++++++++++++++ 10 files changed, 245 insertions(+), 5 deletions(-) create mode 100644 tests/unit_tests/openvpn/test_misc.c
doc/man-sections/protocol-options.rst +10 -2
@@ -84,10 +84,10 @@ configured in a compatible way between both the local and remote side. --compress algorithm **DEPRECATED** Enable a compression algorithm. Compression is generally not recommended. VPN tunnels which use compression are susceptible to - the VORALCE attack vector. + the VORALCE attack vector. See also the :code:`migrate` parameter below. The ``algorithm`` parameter may be :code:`lzo`, :code:`lz4`, - :code:`lz4-v2`, :code:`stub`, :code:`stub-v2` or empty. + :code:`lz4-v2`, :code:`stub`, :code:`stub-v2`, :code:`migrate` or empty. LZO and LZ4 are different compression algorithms, with LZ4 generally offering the best performance with least CPU usage.
@@ -106,6 +106,14 @@ configured in a compatible way between both the local and remote side. Note: the :code:`stub` (or empty) option is NOT compatible with the older option ``--comp-lzo no``. + The :code:`migrate` algorithm is a special and is intended to allow + migration away from ``--compress``/``--comp-lzo`` options to no compression. + This options set the server to no compression mode. If a client + is detected that indicates that compression is used the will automatically + add ``--push compress stub-v2`` to the client specific configuration + if supported by the client and otherwise switch to ``comp-lzo no`` + and also ``--push comp-lzo`` to the client specific configuration. + ***Security Considerations*** Compression and encryption is a tricky combination. If an attacker knows
src/openvpn/comp.h +1 -0
@@ -58,6 +58,7 @@#define COMP_F_ADVERTISE_STUBS_ONLY (1<<3)/* tell server that we only support compression stubs */ #define COMP_F_ALLOW_STUB_ONLY (1<<4)/* Only accept stub compression, even with COMP_F_ADVERTISE_STUBS_ONLY * we still accept other compressions to be pushed */ +#define COMP_F_MIGRATE (1<<5)/* push stub-v2 or comp-lzo no when we see a client with comp-lzo in occ */ /*
src/openvpn/multi.c +41 -0
53 lines not on this page · raw message
src/openvpn/options.c +6 -0
@@ -7692,6 +7692,12 @@ add_option(struct options *options, options->comp.alg =COMP_ALGV2_UNCOMPRESSED ; options->comp.flags |=COMP_F_ADVERTISE_STUBS_ONLY ; } +else if (streq (p[1 ],"migrate" )) + { + options->comp.alg =COMP_ALG_UNDEF ; + options->comp.flags =COMP_F_MIGRATE ; + + }else if (options->comp.flags &COMP_F_ALLOW_STUB_ONLY ) {/* Also printed on a push to hint at configuration problems */
src/openvpn/ssl.c +32 -2
@@ -60,6 +60,7 @@#include "ssl_verify.h" #include "ssl_backend.h" #include "ssl_ncp.h" +#include "ssl_util.h" #include "auth_token.h" #include "memdbg.h"
@@ -2235,6 +2236,16 @@ error:return ret; } +static bool +write_compat_local_options (struct buffer *buf,const char *options) +{ +struct gc_arena gc =gc_new (); +const char * local_options =options_string_compat_lzo (options, &gc); +bool ret =write_string (buf, local_options,TLS_OPTIONS_LEN ); +gc_free (&gc); +return ret; +} +/** * Handle the writing of key data, peer-info, username/password, OCC * to the TLS control channel (cleartext).
@@ -2266,7 +2277,15 @@ key_method_2_write(struct buffer *buf, struct tls_session *session)/* write options string */ { -if (!write_string (buf, session->opt->local_options,TLS_OPTIONS_LEN )) +if (multi->remote_usescomp && session->opt->mode ==MODE_SERVER + && multi->opt.comp_options.flags &COMP_F_MIGRATE ) + { +if (!write_compat_local_options (buf, session->opt->local_options)) + { + goto error; + } + } +else if (!write_string (buf, session->opt->local_options,TLS_OPTIONS_LEN )) { goto error; }
@@ -2460,6 +2479,7 @@ key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_sessiofree (multi->remote_ciphername); multi->remote_ciphername =options_string_extract_option (options,"cipher" ,NULL ); + multi->remote_usescomp =strstr (options,",comp-lzo," ) !=NULL ;/* In OCC we send '[null-cipher]' instead 'none' */ if (multi->remote_ciphername
@@ -2509,7 +2529,17 @@ key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_sessioif (!session->opt->disable_occ && !options_cmp_equal (options, session->opt->remote_options)) { -options_warning (options, session->opt->remote_options); +const char *remote_options = session->opt->remote_options; +if (multi->opt.comp_options.flags &COMP_F_MIGRATE && multi->remote_usescomp) + { +msg (D_SHOW_OCC ,"Note: --comp-lzo migrate is enabled and remote " +"announces comp-lzo, consider removing " +"compress/comp-lzo options from remote config." ); + remote_options =options_string_compat_lzo (remote_options, &gc); + } + +options_warning (options, remote_options); +if (session->opt->ssl_flags &SSLF_OPT_VERIFY ) {msg (D_TLS_ERRORS ,"Option inconsistency warnings triggering disconnect due to --opt-verify" );
src/openvpn/ssl_common.h +1 -0
@@ -574,6 +574,7 @@ struct tls_multibool use_peer_id;char *remote_ciphername;/**< cipher specified in peer's config file */ +bool remote_usescomp;/**< remote announced comp-lzo in OCC string */ /* * Our session objects.
src/openvpn/ssl_util.c +43 -0
46 lines not on this page · raw message
src/openvpn/ssl_util.h +15 -0
@@ -54,4 +54,19 @@ extract_var_peer_info(const char *peer_info,*/ unsigned int extract_iv_proto (const char *peer_info); + +/** +* Takes a locally produced OCC string for TLS server mode and modifies as +* if the option comp-lzo was enabled. This is to send a client in +* comp-lzo migrate mode the expected OCC string. +* +* Note: This function excpets the string to be in the locally generated +* format and does not accept arbitrary strings. +* +* @param options the locally generated OCC string +* @param gc gc_arena to allocate the returned string in +* @return the modified string or options on error +*/ +const char * +options_string_compat_lzo (const char *options,struct gc_arena *gc);#endif
tests/unit_tests/openvpn/Makefile.am +13 -1
@@ -6,7 +6,7 @@ if HAVE_LD_WRAP_SUPPORT test_binaries += argv_testdriver buffer_testdriver endif -test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver +test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver misc_testdriver if HAVE_LD_WRAP_SUPPORT test_binaries += tls_crypt_testdriver endif
@@ -127,3 +127,15 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(openvpn_srcdir)/packet_id.c \ $(openvpn_srcdir)/platform.c \ $(openvpn_srcdir)/ssl_util.c + + +misc_testdriver_CFLAGS = @TEST_CFLAGS@ \ + -I$(openvpn_includedir) -I$(compat_srcdir) -I$(openvpn_srcdir) + +misc_testdriver_LDFLAGS = @TEST_LDFLAGS@ + +misc_testdriver_SOURCES = test_misc.c mock_msg.c \ + mock_get_random.c \ + $(openvpn_srcdir)/buffer.c \ + $(openvpn_srcdir)/ssl_util.c \ + $(openvpn_srcdir)/platform.c
tests/unit_tests/openvpn/test_misc.c new file +83 -0
83 lines not on this page · raw message
Signature · 1 line
2.30.1
Quoted 12 lines · Arne Schwabe
This function is used by both NCP and push, so move it to a more proper place.
Signed-off-by Arne Schwabe <[email protected]...>--- src/openvpn/multi.c | 1 + src/openvpn/push.c | 18 +----------------- src/openvpn/push.h | 10 ---------- src/openvpn/ssl_util.c | 16 ++++++++++++++++ src/openvpn/ssl_util.h | 8 ++++++++ 5 files changed, 26 insertions(+), 27 deletions(-)
Glared at code, compared the move. All good. Compile tested on RHEL-8 just fine with no warnings.
Signature · 4 lines
kind regards, David Sommerseth OpenVPN Inc
Re: [Openvpn-devel] [PATCH 2/2] Implement '--compress migrate' to migrate to non-compression setup
In reply to Arne SchwabeQuoted 26 lines · Arne Schwabe
This option allow migration to a non compression server config while still retraining compatibility with client that have a compression setting in their config.
For existing setups that used to have comp-lzo no or another compression setting in their configs it is a difficult to migrate to a setup without compression without replacing all client configs at once especially if OpenVPN 2.3 or earlier clients are in the mix that do not support pushing stub-v2. Even with OpenVPN 2.4 and later clients that support pushing this is not a satisfying solution as the clients log occ mismatches and the "push stub-v2" needs to be in the server config "forever".
Signed-off-by Arne Schwabe <[email protected]...>--- doc/man-sections/protocol-options.rst | 12 +++- src/openvpn/comp.h | 1 + src/openvpn/multi.c | 41 +++++++++++++ src/openvpn/options.c | 6 ++ src/openvpn/ssl.c | 34 ++++++++++- src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_util.c | 43 ++++++++++++++ src/openvpn/ssl_util.h | 15 +++++ tests/unit_tests/openvpn/Makefile.am | 14 ++++- tests/unit_tests/openvpn/test_misc.c | 83 +++++++++++++++++++++++++++ 10 files changed, 245 insertions(+), 5 deletions(-)
Quoted 2 lines
create mode 100644
tests/unit_tests/openvpn/test_misc.c
This fails compiling:
../../../src/openvpn/ssl.c: In function ‘key_method_2_write’:../../../src/openvpn/ssl.c:2280:13: error: ‘multi’ undeclared (first use in this function)
if (multi->remote_usescomp && session->opt->mode == MODE_SERVER
^~~~~../../../src/openvpn/ssl.c:2280:13: note: each undeclared identifier is reported only once for each function it appears in make[3]: *** [Makefile:742: ssl.o] Error 1
Signature · 4 lines
kind regards, David Sommerseth OpenVPN Inc
David beat me to ACKing it :-)
Your patch has been applied to the master branch.
commit f9d9fe55754dd019bb4c4add180dd780f9102b44
Author: Arne Schwabe Date: Fri Mar 19 16:31:28 2021 +0100
Move extract_iv_proto to ssl_util.c/h
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: David Sommerseth <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg21732.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH 2/2] Implement '--compress migrate' to migrate to non-compression setup
In reply to David SommersethAm 20.03.21 um 14:20 schrieb David Sommerseth:
Quoted 32 lines · Arne Schwabe
Quoted 25 lines
This option allow migration to a non compression server config while still retraining compatibility with client that have a compression setting in their config.
For existing setups that used to have comp-lzo no or another compression setting in their configs it is a difficult to migrate to a setup without compression without replacing all client configs at once especially if OpenVPN 2.3 or earlier clients are in the mix that do not support pushing stub-v2. Even with OpenVPN 2.4 and later clients that support pushing this is not a satisfying solution as the clients log occ mismatches and the "push stub-v2" needs to be in the server config "forever".
Signed-off-by Arne Schwabe <[email protected]...>---
doc/man-sections/protocol-options.rst| 12 +++- src/openvpn/comp.h | 1 + src/openvpn/multi.c | 41 +++++++++++++ src/openvpn/options.c | 6 ++ src/openvpn/ssl.c | 34 ++++++++++- src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_util.c | 43 ++++++++++++++ src/openvpn/ssl_util.h | 15 +++++ tests/unit_tests/openvpn/Makefile.am | 14 ++++- tests/unit_tests/openvpn/test_misc.c | 83 +++++++++++++++++++++++++++Quoted 3 lines
10 files changed, 245 insertions(+), 5 deletions(-)create mode 100644
tests/unit_tests/openvpn/test_misc.cThis fails compiling:
Quoted 8 lines
../../../src/openvpn/ssl.c: In function ‘key_method_2_write’:../../../src/openvpn/ssl.c:2280:13: error: ‘multi’ undeclared (first use in this function)
if (multi->remote_usescomp&&session->opt->mode==MODE_SERVER^~~~~../../../src/openvpn/ssl.c:2280:13: note: each undeclared identifier is reported only once for each function it appears in
make[3]: *** [Makefile:742: ssl.o] Error 1
Oh the fun of rebasing. The multi argument was added by another patch. Can you just the small patch to review the rest of the patch?:
static bool
-key_method_2_write(struct buffer *buf, struct tls_session *session) +key_method_2_write(struct buffer *buf, struct tls_multi *multi, struct tls_session *session)
{
struct key_state *ks = &session->key[KS_PRIMARY]; /* primarykey */
@@ -2856,7 +2856,7 @@ tls_process(struct tls_multi *multi,
if (!buf->len && ((ks->state == S_START && !session->opt->server)
|| (ks->state == S_GOT_KEY &&
session->opt->server)))
{
- if (!key_method_2_write(buf, session))
+ if (!key_method_2_write(buf, multi, session))
{
goto error;
}Re: [Openvpn-devel] [PATCH 2/2] Implement '--compress migrate' to migrate to non-compression setup
Quoted 62 lines · Arne Schwabe
Am 20.03.21 um 14:20 schrieb David Sommerseth:
Quoted 32 lines · Arne Schwabe
Quoted 26 lines
This option allow migration to a non compression server config while still retraining compatibility with client that have a compression setting in their config.
For existing setups that used to have comp-lzo no or another compression setting in their configs it is a difficult to migrate to a setup without compression without replacing all client configs at once especially if OpenVPN 2.3 or earlier clients are in the mix that do not support pushing stub-v2. Even with OpenVPN 2.4 and later clients that support pushing this is not a satisfying solution as the clients log occ mismatches and the "push stub-v2" needs to be in the server config "forever".
Signed-off-by Arne Schwabe <[email protected]...>--- doc/man-sections/protocol-options.rst | 12 +++- src/openvpn/comp.h | 1 + src/openvpn/multi.c | 41 +++++++++++++ src/openvpn/options.c | 6 ++ src/openvpn/ssl.c | 34 ++++++++++- src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_util.c | 43 ++++++++++++++ src/openvpn/ssl_util.h | 15 +++++ tests/unit_tests/openvpn/Makefile.am | 14 ++++- tests/unit_tests/openvpn/test_misc.c | 83 +++++++++++++++++++++++++++ 10 files changed, 245 insertions(+), 5 deletions(-)Quoted 2 lines
create mode 100644
tests/unit_tests/openvpn/test_misc.cThis fails compiling:
Quoted 8 lines
../../../src/openvpn/ssl.c: In function ‘key_method_2_write’:../../../src/openvpn/ssl.c:2280:13: error: ‘multi’ undeclared (first use in this function)
if (multi->remote_usescomp&&session->opt->mode==MODE_SERVER^~~~~../../../src/openvpn/ssl.c:2280:13: note: each undeclared identifier is reported only once for each function it appears in
make[3]: *** [Makefile:742: ssl.o] Error 1Oh the fun of rebasing. The multi argument was added by another patch. Can you just the small patch to review the rest of the patch?:
static bool
(quoted diff) +1
-1-key_method_2_write(struct buffer *buf, struct tls_session *session) +key_method_2_write(struct buffer *buf, struct tls_multi *multi, struct
tls_session*session){ struct key_state *ks = &session->key[KS_PRIMARY]; /* primarykey */
(quoted diff) +1
-1@@ -2856,7 +2856,7 @@ tls_process(struct tls_multi *multi, if (!buf->len && ((ks->state == S_START && !session->opt->server) || (ks->state == S_GOT_KEY && session->opt->server))) { - if (!key_method_2_write(buf, session)) + if (!key_method_2_write(buf, multi, session)) { goto error;
Quoted 2 lines
}
I'll give this a spin and continue the review. Thx!
Signature · 4 lines
kind regards, David Sommerseth OpenVPN Inc
Re: [Openvpn-devel] [PATCH 2/2] Implement '--compress migrate' to migrate to non-compression setup
In reply to Arne SchwabeHi,
Quoted 4 lines · Arne Schwabe
This option allow migration to a non compression server config while still retraining compatibility with client that have a compression setting in their config.
Quoted 8 lines
For existing setups that used to have comp-lzo no or another compression setting in their configs it is a difficult to migrate to a setup without compression without replacing all client configs at once especially if OpenVPN 2.3 or earlier clients are in the mix that do not support pushing stub-v2. Even with OpenVPN 2.4 and later clients that support pushing this is not a satisfying solution as the clients log occ mismatches and the "push stub-v2" needs to be in the server config "forever".
As discussed on other channels, I think it would be beneficial to report in the commit message also the "what is this patch doing to achieve this goal?".
Basically a shorter version of what you are already putting in the manpage.
Quoted 34 lines
Signed-off-by Arne Schwabe <[email protected]...>--- doc/man-sections/protocol-options.rst | 12 +++- src/openvpn/comp.h | 1 + src/openvpn/multi.c | 41 +++++++++++++ src/openvpn/options.c | 6 ++ src/openvpn/ssl.c | 34 ++++++++++- src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_util.c | 43 ++++++++++++++ src/openvpn/ssl_util.h | 15 +++++ tests/unit_tests/openvpn/Makefile.am | 14 ++++- tests/unit_tests/openvpn/test_misc.c | 83 +++++++++++++++++++++++++++ 10 files changed, 245 insertions(+), 5 deletions(-) create mode 100644 tests/unit_tests/openvpn/test_misc.cdoc/man-sections/protocol-options.rst +2
-2@@ -84,10 +84,10 @@ configured in a compatible way between both the local and remote side. --compress algorithm **DEPRECATED** Enable a compression algorithm. Compression is generally not recommended. VPN tunnels which use compression are susceptible to - the VORALCE attack vector. + the VORALCE attack vector. See also the :code:`migrate` parameter below. The ``algorithm`` parameter may be :code:`lzo`, :code:`lz4`, - :code:`lz4-v2`, :code:`stub`, :code:`stub-v2` or empty. + :code:`lz4-v2`, :code:`stub`, :code:`stub-v2`, :code:`migrate` or empty. LZO and LZ4 are different compression algorithms, with LZ4 generally offering the best performance with least CPU usage.
doc/man-sections/protocol-options.rst configured in a compatible way between both the local and remote side. · line 112
Quoted 7 lines
doc/man-sections/protocol-options.rst +4
-0@@ -106,6 +106,14 @@ configured in a compatible way between both the local and remote side. Note: the :code:`stub` (or empty) option is NOT compatible with the older option ``--comp-lzo no``. + The :code:`migrate` algorithm is a special and is intended to allow + migration away from ``--compress``/``--comp-lzo`` options to no compression. + This options set the server to no compression mode. If a client + is detected that indicates that compression is used the will automatically
typ0 - missing $something after 'the'
Quoted 24 lines
doc/man-sections/protocol-options.rst +4
-0+ add ``--push compress stub-v2`` to the client specific configuration + if supported by the client and otherwise switch to ``comp-lzo no`` + and also ``--push comp-lzo`` to the client specific configuration. + ***Security Considerations*** Compression and encryption is a tricky combination. If an attacker knowssrc/openvpn/comp.h +1
-0@@ -58,6 +58,7 @@#define COMP_F_ADVERTISE_STUBS_ONLY (1<<3)/* tell server that we only support compression stubs */ #define COMP_F_ALLOW_STUB_ONLY (1<<4)/* Only accept stub compression, even with COMP_F_ADVERTISE_STUBS_ONLY * we still accept other compressions to be pushed */ +#define COMP_F_MIGRATE (1<<5)/* push stub-v2 or comp-lzo no when we see a client with comp-lzo in occ */ /* src/openvpn/multi.c +0
-0
src/openvpn/multi.c multi_client_connect_early_setup(struct multi_context *m, · line 2473
Quoted 5 lines
src/openvpn/multi.c +2
-0@@ -2469,6 +2469,46 @@ multi_client_connect_early_setup(struct multi_context *m,multi_client_connect_setenv (m, mi); } +/** +* Do the necessary modification for doing the compress mitigrate. This is
typ0: mitigrate
src/openvpn/multi.c multi_client_connect_early_setup(struct multi_context *m, · line 2485
Quoted 12 lines
src/openvpn/multi.c +12
-0+* implemented as a connect handler as it fits the modify config for a client +* paradigm and also is early enough in the chain to be overwritten by another +* ccd/script to do compression on a special client. +*/ +static enum client_connect_return +multi_client_connect_compress_migrate (struct multi_context *m, +struct multi_instance *mi, +bool deferred, +unsigned int *option_types_found) +{ +struct options *o = &mi->context.options; +const char *const peer_info =mi->context.c2.tls_multi->peer_info;
space after =
Quoted 8 lines
src/openvpn/multi.c +8
-0+ +if (!peer_info) + { +return CC_RET_SUCCEEDED ; + } + + +if (o->comp.flags &COMP_F_MIGRATE && mi->context.c2.tls_multi->remote_usescomp)
src/openvpn/multi.c multi_client_connect_early_setup(struct multi_context *m, · line 2503
Quoted 10 lines
src/openvpn/multi.c +10
-0+ { +if (strstr (peer_info,"IV_COMP_STUBv2=1" )) + { +push_option (o,"compress stub-v2" ,M_USAGE ); + } +else + { +/* Client is old and does not support STUBv2 but since it +* announced comp-lzo via OCC we assume it uses comp-lzo, so +* switch to that and pushed the uncompressed variant. */
pushed -> push ?
Quoted 49 lines
src/openvpn/multi.c +9
-0+push_option (o,"comp-lzo no" ,M_USAGE ); + o->comp.alg =COMP_ALG_STUB ; + *option_types_found |=OPT_P_COMP ; + } + } +return CC_RET_SUCCEEDED ; +} +/** * Try to source a dynamic config file from the * --client-config-dir directory. @@ -2537,6 +2577,7 @@ typedef enum client_connect_return (*multi_client_connect_handler) bool from_deferred, unsigned int *option_types_found);static const multi_client_connect_handler client_connect_handlers[] = { + multi_client_connect_compress_migrate, multi_client_connect_source_ccd, multi_client_connect_call_plugin_v1, multi_client_connect_call_plugin_v2,src/openvpn/options.c +6
-0@@ -7692,6 +7692,12 @@ add_option(struct options *options, options->comp.alg =COMP_ALGV2_UNCOMPRESSED ; options->comp.flags |=COMP_F_ADVERTISE_STUBS_ONLY ; } +else if (streq (p[1 ],"migrate" )) + { + options->comp.alg =COMP_ALG_UNDEF ; + options->comp.flags =COMP_F_MIGRATE ; + + }else if (options->comp.flags &COMP_F_ALLOW_STUB_ONLY ) {/* Also printed on a push to hint at configuration problems */ src/openvpn/ssl.c +1
-0@@ -60,6 +60,7 @@#include "ssl_verify.h" #include "ssl_backend.h" #include "ssl_ncp.h" +#include "ssl_util.h" #include "auth_token.h" #include "memdbg.h"
src/openvpn/ssl.c error: · line 2243
Quoted 8 lines
src/openvpn/ssl.c +5
-0@@ -2235,6 +2236,16 @@ error:return ret; } +static bool +write_compat_local_options (struct buffer *buf,const char *options) +{ +struct gc_arena gc =gc_new (); +const char * local_options =options_string_compat_lzo (options, &gc);
space should go before * and not after.
Quoted 26 lines
src/openvpn/ssl.c +14
-1+bool ret =write_string (buf, local_options,TLS_OPTIONS_LEN ); +gc_free (&gc); +return ret; +} +/** * Handle the writing of key data, peer-info, username/password, OCC * to the TLS control channel (cleartext). @@ -2266,7 +2277,15 @@ key_method_2_write(struct buffer *buf, struct tls_session *session)/* write options string */ { -if (!write_string (buf, session->opt->local_options,TLS_OPTIONS_LEN )) +if (multi->remote_usescomp && session->opt->mode ==MODE_SERVER + && multi->opt.comp_options.flags &COMP_F_MIGRATE ) + { +if (!write_compat_local_options (buf, session->opt->local_options)) + { + goto error; + } + } +else if (!write_string (buf, session->opt->local_options,TLS_OPTIONS_LEN )) { goto error; }
src/openvpn/ssl.c key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_sessio · line 2482
Quoted 4 lines
src/openvpn/ssl.c +1
-0@@ -2460,6 +2479,7 @@ key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_sessiofree (multi->remote_ciphername); multi->remote_ciphername =options_string_extract_option (options,"cipher" ,NULL ); + multi->remote_usescomp =strstr (options,",comp-lzo," ) !=NULL ;
remote_usescomp is bool - we never do "strstr() != NULL" when we need a boolean result.
Quoted 4 lines
src/openvpn/ssl.c +0
-0/* In OCC we send '[null-cipher]' instead 'none' */ if (multi->remote_ciphername
src/openvpn/ssl.c key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_sessio · line 2537
Quoted 10 lines
src/openvpn/ssl.c +6
-1@@ -2509,7 +2529,17 @@ key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_sessioif (!session->opt->disable_occ && !options_cmp_equal (options, session->opt->remote_options)) { -options_warning (options, session->opt->remote_options); +const char *remote_options = session->opt->remote_options; +if (multi->opt.comp_options.flags &COMP_F_MIGRATE && multi->remote_usescomp) + { +msg (D_SHOW_OCC ,"Note: --comp-lzo migrate is enabled and remote " +"announces comp-lzo, consider removing " +"compress/comp-lzo options from remote config." );
should we explain a bit more what is happening? i.e. compression is being forcefully disabled?
Quoted 25 lines
src/openvpn/ssl.c +5
-0+ remote_options =options_string_compat_lzo (remote_options, &gc); + } + +options_warning (options, remote_options); +if (session->opt->ssl_flags &SSLF_OPT_VERIFY ) {msg (D_TLS_ERRORS ,"Option inconsistency warnings triggering disconnect due to --opt-verify" );src/openvpn/ssl_common.h +1
-0@@ -574,6 +574,7 @@ struct tls_multibool use_peer_id;char *remote_ciphername;/**< cipher specified in peer's config file */ +bool remote_usescomp;/**< remote announced comp-lzo in OCC string */ /* * Our session objects. src/openvpn/ssl_util.c +0
-0
src/openvpn/ssl_util.c extract_iv_proto(const char *peer_info) · line 81
Quoted 7 lines
src/openvpn/ssl_util.c +4
-0@@ -75,3 +75,46 @@ extract_iv_proto(const char *peer_info) }return 0 ; } + +const char * +options_string_compat_lzo(const char *options, struct gc_arena *gc> +{ +
no need for this empty line?
src/openvpn/ssl_util.c extract_iv_proto(const char *peer_info) · line 85
Quoted 3 lines
src/openvpn/ssl_util.c +3
-0+/* comp-lzo: 'V4,dev-type tun,link-mtu 1458,tun-mtu 1400,proto UDPv4,comp-lzo,auth SHA1,keysize 128,key-method 2,tls-server' */ +/* w/o comp: 'V4,dev-type tun,link-mtu 1457,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server' */ +
maybe this comment could be articulated a bit more? just to explain that this is also a sample input/output for this function.
src/openvpn/ssl_util.c extract_iv_proto(const char *peer_info) · line 93
Quoted 8 lines
src/openvpn/ssl_util.c +8
-0+ +/* Note: since this function is used only in a very limited scope it makes +* assumptions how the string looks. Since we locally generated the string +* we can make these assumptions */ + + +/* Check that the link-mtu string is in options */ +const char * tmp =strstr (options,",link-mtu" );
space before the * and not after.
src/openvpn/ssl_util.c extract_iv_proto(const char *peer_info) · line 101
Quoted 8 lines
src/openvpn/ssl_util.c +8
-0+if (!tmp) + { +return options; + } + +/* Get old link_mtu size */ +int link_mtu; +if (sscanf (tmp,",link-mtu %d," , &link_mtu) !=1 || link_mtu <100 || link_mtu >9000 )
- 9000 is sometimes used in some setups. How about having 9900 as upper bound?
- space after if
- space after !=
src/openvpn/ssl_util.c extract_iv_proto(const char *peer_info) · line 106
Quoted 5 lines
src/openvpn/ssl_util.c +5
-0+ { +return options; + } + +struct buffer buf =alloc_buf_gc (strlen (options) +strlen (",comp-lzo" ) +2 , gc);
as suggested, please add a comment to explain why +2 is needed
src/openvpn/ssl_util.c extract_iv_proto(const char *peer_info) · line 107
Quoted 2 lines
src/openvpn/ssl_util.c +2
-0+ +
no need for double empty line?
src/openvpn/ssl_util.c extract_iv_proto(const char *peer_info) · line 119
Quoted 11 lines
src/openvpn/ssl_util.c +11
-0+buf_write (&buf, options, (int )(tmp - options)); + +/* Increase link-mtu by one for the comp-lzo opcode */ +buf_printf (&buf,",link-mtu %d" , link_mtu +1 ); + + tmp +=strlen (",link-mtu " ) + (link_mtu <1000 ?3 :4 ); + +buf_printf (&buf,"%s,comp-lzo" , tmp); + +return BSTR (&buf); +
no need for this empty line
Quoted 39 lines
src/openvpn/ssl_util.c +1
-0+}src/openvpn/ssl_util.h +15
-0@@ -54,4 +54,19 @@ extract_var_peer_info(const char *peer_info,*/ unsigned int extract_iv_proto (const char *peer_info); + +/** +* Takes a locally produced OCC string for TLS server mode and modifies as +* if the option comp-lzo was enabled. This is to send a client in +* comp-lzo migrate mode the expected OCC string. +* +* Note: This function excpets the string to be in the locally generated +* format and does not accept arbitrary strings. +* +* @param options the locally generated OCC string +* @param gc gc_arena to allocate the returned string in +* @return the modified string or options on error +*/ +const char * +options_string_compat_lzo (const char *options,struct gc_arena *gc);#endif tests/unit_tests/openvpn/Makefile.am +1
-1@@ -6,7 +6,7 @@ if HAVE_LD_WRAP_SUPPORT test_binaries += argv_testdriver buffer_testdriver endif -test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver +test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver misc_testdriver if HAVE_LD_WRAP_SUPPORT test_binaries += tls_crypt_testdriver endif
tests/unit_tests/openvpn/Makefile.am ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ · line 131
Quoted 5 lines
tests/unit_tests/openvpn/Makefile.am +2
-0@@ -127,3 +127,15 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(openvpn_srcdir)/packet_id.c \ $(openvpn_srcdir)/platform.c \ $(openvpn_srcdir)/ssl_util.c + +
no need for double empty line
Quoted 17 lines
tests/unit_tests/openvpn/Makefile.am +10
-0+misc_testdriver_CFLAGS = @TEST_CFLAGS@ \ + -I$(openvpn_includedir) -I$(compat_srcdir) -I$(openvpn_srcdir) + +misc_testdriver_LDFLAGS = @TEST_LDFLAGS@ + +misc_testdriver_SOURCES = test_misc.c mock_msg.c \ + mock_get_random.c \ + $(openvpn_srcdir)/buffer.c \ + $(openvpn_srcdir)/ssl_util.c \ + $(openvpn_srcdir)/platform.ctests/unit_tests/openvpn/test_misc.c new file +0
-0
tests/unit_tests/openvpn/test_misc.c line 8
Quoted 8 lines
tests/unit_tests/openvpn/test_misc.c new file +8
-0@@ -0,0 +1,83 @@ +/* +* OpenVPN -- An application to securely tunnel IP networks +* over a single UDP port, with support for SSL/TLS-based +* session authentication and key exchange, +* packet encryption, packet authentication, and +* packet compression. +* +* Copyright (C) 2019 Arne Schwabe <[email protected]...>
since the file is being introduced now, maybe it should carry a more recent copyright year?
Quoted 66 lines
tests/unit_tests/openvpn/test_misc.c new file +65
-0+* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#elif defined(_MSC_VER) +#include "config-msvc.h" +#endif + +#include "syshead.h" + +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> +#include <setjmp.h> +#include <cmocka.h> + +#include "ssl_util.h" + +static void +test_compat_lzo_string (void **state) +{ +struct gc_arena gc =gc_new (); + +const char * input ="V4,dev-type tun,link-mtu 1457,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server" ; + +const char * output =options_string_compat_lzo (input, &gc); + +assert_string_equal (output,"V4,dev-type tun,link-mtu 1458,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server,comp-lzo" ); + +/* This string is has a much too small link-mtu so we should fail on it" */ + input ="V4,dev-type tun,link-mtu 2,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server" ; + + output =options_string_compat_lzo (input, &gc); + +assert_string_equal (input, output); + +/* not matching at all */ + input ="V4,dev-type tun" ; + output =options_string_compat_lzo (input, &gc); + +assert_string_equal (input, output); + + + input ="V4,dev-type tun,link-mtu 999,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server" ; + output =options_string_compat_lzo (input, &gc); + +/* 999 -> 1000, 3 to 4 chars */ +assert_string_equal (output,"V4,dev-type tun,link-mtu 1000,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server,comp-lzo" ); + +};
tests/unit_tests/openvpn/test_misc.c line 83
Quoted 10 lines
tests/unit_tests/openvpn/test_misc.c new file +10
-0+ +const struct CMUnitTest misc_tests[] = { +cmocka_unit_test (test_compat_lzo_string), +}; + +int +main (void ) +{ +return cmocka_run_group_tests (misc_tests,NULL ,NULL ); +}
My comments are all basically about style only, because there is nothing else to report.
The patch was discussed with Arne in a meeting and it represent a an important milestone that will allow people to migrate away from having compression enabled.
This is very important, especially after it was realized that compression on the outer side of a VPN link can be dangerous.
I tested this patch (after manually applying the fix as per Arne's suggestion) in the following scenarios:
* server with --compress migrate
1) client without any compression enabled -> data flows;
2) client with --compress lzo/lz4 -> server pushes compress stub-v2 -> data flows;
3) client with --comp-lzo -> server pushes compress stub-v2 -> data flows;
4) client does not announce IV_COMP_STUBv2=1 and with --comp-lzo -> server pushes comp-lzo no -> data flows;
5) client does not announce IV_COMP_STUBv2=1 and with --compress lzo/lz4 (I don't think any client can do this) -> server pushes comp-lzo no -> data flows;
Cheers,
Signature · 1 line
Antonio Quartulli
PATCH v2 1/1 Implement '--compress migrate' to migrate to non-compression setup
In reply to Arne SchwabeThis option allow migration to a non compression server config while still retraining compatibility with client that have a compression setting in their config.
For existing setups that used to have comp-lzo no or another compression setting in their configs it is a difficult to migrate to a setup without compression without replacing all client configs at once especially if OpenVPN 2.3 or earlier clients are in the mix that do not support pushing stub-v2. Even with OpenVPN 2.4 and later clients that support pushing this is not a satisfying solution as the clients log occ mismatches and the "push stub-v2" needs to be in the server config "forever".
If the new migrate option to compress is set and a client is detected that indicates that compression is used (via OCC), the server will automatically add ``--push compress stub-v2`` to the client specific configuration if stub-v2 is supported by the client and otherwise switch to ``comp-lzo no`` and add ``--push comp-lzo`` to the client specific configuration.
Patch v2: better commit message/man page, add USE_COMP ifdefs, various style
fixes
--- doc/man-sections/protocol-options.rst | 13 ++++- src/openvpn/comp.h | 1 + src/openvpn/multi.c | 42 ++++++++++++++ src/openvpn/options.c | 6 ++ src/openvpn/ssl.c | 43 +++++++++++++- src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_util.c | 41 +++++++++++++ src/openvpn/ssl_util.h | 15 +++++ tests/unit_tests/openvpn/Makefile.am | 13 ++++- tests/unit_tests/openvpn/test_misc.c | 83 +++++++++++++++++++++++++++ 10 files changed, 252 insertions(+), 6 deletions(-) create mode 100644 tests/unit_tests/openvpn/test_misc.c
doc/man-sections/protocol-options.rst +11 -2
@@ -84,10 +84,10 @@ configured in a compatible way between both the local and remote side. --compress algorithm **DEPRECATED** Enable a compression algorithm. Compression is generally not recommended. VPN tunnels which use compression are susceptible to - the VORALCE attack vector. + the VORALCE attack vector. See also the :code:`migrate` parameter below. The ``algorithm`` parameter may be :code:`lzo`, :code:`lz4`, - :code:`lz4-v2`, :code:`stub`, :code:`stub-v2` or empty. + :code:`lz4-v2`, :code:`stub`, :code:`stub-v2`, :code:`migrate` or empty. LZO and LZ4 are different compression algorithms, with LZ4 generally offering the best performance with least CPU usage.
@@ -106,6 +106,15 @@ configured in a compatible way between both the local and remote side. Note: the :code:`stub` (or empty) option is NOT compatible with the older option ``--comp-lzo no``. + Using :code:`migrate` as compression algorithm enables a special migration mode. + It allows migration away from the ``--compress``/``--comp-lzo`` options to no compression. + This option sets the server to no compression mode and the server behaves identical to + a server without a compression option for all clients without a compression in their + config. However, if a client is detected that indicates that compression is used (via OCC), + the server will automatically add ``--push compress stub-v2`` to the client specific + configuration if supported by the client and otherwise switch to ``comp-lzo no`` + and add ``--push comp-lzo`` to the client specific configuration. + ***Security Considerations*** Compression and encryption is a tricky combination. If an attacker knows
src/openvpn/comp.h +1 -0
@@ -58,6 +58,7 @@#define COMP_F_ADVERTISE_STUBS_ONLY (1<<3)/* tell server that we only support compression stubs */ #define COMP_F_ALLOW_STUB_ONLY (1<<4)/* Only accept stub compression, even with COMP_F_ADVERTISE_STUBS_ONLY * we still accept other compressions to be pushed */ +#define COMP_F_MIGRATE (1<<5)/* push stub-v2 or comp-lzo no when we see a client with comp-lzo in occ */ /*
src/openvpn/multi.c +42 -0
54 lines not on this page · raw message
src/openvpn/options.c +6 -0
@@ -7783,6 +7783,12 @@ add_option(struct options *options, options->comp.alg =COMP_ALGV2_UNCOMPRESSED ; options->comp.flags |=COMP_F_ADVERTISE_STUBS_ONLY ; } +else if (streq (p[1 ],"migrate" )) + { + options->comp.alg =COMP_ALG_UNDEF ; + options->comp.flags =COMP_F_MIGRATE ; + + }else if (options->comp.flags &COMP_F_ALLOW_STUB_ONLY ) {/* Also printed on a push to hint at configuration problems */
src/openvpn/ssl.c +40 -3
85 lines not on this page · raw message
src/openvpn/ssl_common.h +1 -0
@@ -576,6 +576,7 @@ struct tls_multibool use_peer_id;char *remote_ciphername;/**< cipher specified in peer's config file */ +bool remote_usescomp;/**< remote announced comp-lzo in OCC string */ /* * Our session objects.
src/openvpn/ssl_util.c +41 -0
44 lines not on this page · raw message
src/openvpn/ssl_util.h +15 -0
@@ -54,4 +54,19 @@ extract_var_peer_info(const char *peer_info,*/ unsigned int extract_iv_proto (const char *peer_info); + +/** +* Takes a locally produced OCC string for TLS server mode and modifies as +* if the option comp-lzo was enabled. This is to send a client in +* comp-lzo migrate mode the expected OCC string. +* +* Note: This function excpets the string to be in the locally generated +* format and does not accept arbitrary strings. +* +* @param options the locally generated OCC string +* @param gc gc_arena to allocate the returned string in +* @return the modified string or options on error +*/ +const char * +options_string_compat_lzo (const char *options,struct gc_arena *gc);#endif
tests/unit_tests/openvpn/Makefile.am +12 -1
@@ -6,7 +6,7 @@ if HAVE_LD_WRAP_SUPPORT test_binaries += argv_testdriver buffer_testdriver endif -test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver +test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver misc_testdriver if HAVE_LD_WRAP_SUPPORT test_binaries += tls_crypt_testdriver endif
@@ -127,3 +127,14 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(openvpn_srcdir)/packet_id.c \ $(openvpn_srcdir)/platform.c \ $(openvpn_srcdir)/ssl_util.c + +misc_testdriver_CFLAGS = @TEST_CFLAGS@ \ + -I$(openvpn_includedir) -I$(compat_srcdir) -I$(openvpn_srcdir) + +misc_testdriver_LDFLAGS = @TEST_LDFLAGS@ + +misc_testdriver_SOURCES = test_misc.c mock_msg.c \ + mock_get_random.c \ + $(openvpn_srcdir)/buffer.c \ + $(openvpn_srcdir)/ssl_util.c \ + $(openvpn_srcdir)/platform.c
tests/unit_tests/openvpn/test_misc.c new file +83 -0
83 lines not on this page · raw message
Signature · 1 line
2.30.1
Re: [Openvpn-devel] [PATCH v2] Implement '--compress migrate' to migrate to non-compression setup
I found a typo, so I double checked every comment.
On 24/03/2021 22:08, Arne Schwabe wrote:
<snipped and reviewed - AOK>
Quoted 5 lines
src/openvpn/ssl_util.h +0
-0
src/openvpn/ssl_util.h extract_var_peer_info(const char *peer_info, · line 63
Quoted 10 lines
src/openvpn/ssl_util.h +7
-0@@ -54,4 +54,19 @@ extract_var_peer_info(const char *peer_info,*/ unsigned int extract_iv_proto (const char *peer_info); + +/** +* Takes a locally produced OCC string for TLS server mode and modifies as +* if the option comp-lzo was enabled. This is to send a client in +* comp-lzo migrate mode the expected OCC string. +* +* Note: This function excpets the string to be in the locally generated
typo: excpets
tests/unit_tests/openvpn/Makefile.am
Quoted 13 lines
src/openvpn/ssl_util.h +8
-0+* format and does not accept arbitrary strings. +* +* @param options the locally generated OCC string +* @param gc gc_arena to allocate the returned string in +* @return the modified string or options on error +*/ +const char * +options_string_compat_lzo (const char *options,struct gc_arena *gc);#endif tests/unit_tests/openvpn/Makefile.am +0
-0
<snipped and reviewed - AOK>
Re: [Openvpn-devel] [PATCH v2] Implement '--compress migrate' to migrate to non-compression setup
Am 25.03.21 um 00:12 schrieb tincanteksup:
Quoted 2 lines
I found a typo, so I double checked every comment.
Thanks. I think Gert can fix that on the fly on the merge.
Arne
Re: [Openvpn-devel] [PATCH v2] Implement '--compress migrate' to migrate to non-compression setup
In reply to Arne SchwabeHi,
Quoted 287 lines · Arne Schwabe
This option allow migration to a non compression server config while still retraining compatibility with client that have a compression setting in their config.
For existing setups that used to have comp-lzo no or another compression setting in their configs it is a difficult to migrate to a setup without compression without replacing all client configs at once especially if OpenVPN 2.3 or earlier clients are in the mix that do not support pushing stub-v2. Even with OpenVPN 2.4 and later clients that support pushing this is not a satisfying solution as the clients log occ mismatches and the "push stub-v2" needs to be in the server config "forever".
If the new migrate option to compress is set and a client is detected that indicates that compression is used (via OCC), the server will automatically add ``--push compress stub-v2`` to the client specific configuration if stub-v2 is supported by the client and otherwise switch to ``comp-lzo no`` and add ``--push comp-lzo`` to the client specific configuration.
Patch v2: better commit message/man page, add
USE_COMPifdefs, various style
fixesSigned-off-by Arne Schwabe <[email protected]...>--- doc/man-sections/protocol-options.rst | 13 ++++- src/openvpn/comp.h | 1 + src/openvpn/multi.c | 42 ++++++++++++++ src/openvpn/options.c | 6 ++ src/openvpn/ssl.c | 43 +++++++++++++- src/openvpn/ssl_common.h | 1 + src/openvpn/ssl_util.c | 41 +++++++++++++ src/openvpn/ssl_util.h | 15 +++++ tests/unit_tests/openvpn/Makefile.am | 13 ++++- tests/unit_tests/openvpn/test_misc.c | 83 +++++++++++++++++++++++++++ 10 files changed, 252 insertions(+), 6 deletions(-) create mode 100644 tests/unit_tests/openvpn/test_misc.cdoc/man-sections/protocol-options.rst +11
-2@@ -84,10 +84,10 @@ configured in a compatible way between both the local and remote side. --compress algorithm **DEPRECATED** Enable a compression algorithm. Compression is generally not recommended. VPN tunnels which use compression are susceptible to - the VORALCE attack vector. + the VORALCE attack vector. See also the :code:`migrate` parameter below. The ``algorithm`` parameter may be :code:`lzo`, :code:`lz4`, - :code:`lz4-v2`, :code:`stub`, :code:`stub-v2` or empty. + :code:`lz4-v2`, :code:`stub`, :code:`stub-v2`, :code:`migrate` or empty. LZO and LZ4 are different compression algorithms, with LZ4 generally offering the best performance with least CPU usage.@@ -106,6 +106,15 @@ configured in a compatible way between both the local and remote side. Note: the :code:`stub` (or empty) option is NOT compatible with the older option ``--comp-lzo no``. + Using :code:`migrate` as compression algorithm enables a special migration mode. + It allows migration away from the ``--compress``/``--comp-lzo`` options to no compression. + This option sets the server to no compression mode and the server behaves identical to + a server without a compression option for all clients without a compression in their + config. However, if a client is detected that indicates that compression is used (via OCC), + the server will automatically add ``--push compress stub-v2`` to the client specific + configuration if supported by the client and otherwise switch to ``comp-lzo no`` + and add ``--push comp-lzo`` to the client specific configuration. + ***Security Considerations*** Compression and encryption is a tricky combination. If an attacker knowssrc/openvpn/comp.h +1
-0@@ -58,6 +58,7 @@#define COMP_F_ADVERTISE_STUBS_ONLY (1<<3)/* tell server that we only support compression stubs */ #define COMP_F_ALLOW_STUB_ONLY (1<<4)/* Only accept stub compression, even with COMP_F_ADVERTISE_STUBS_ONLY * we still accept other compressions to be pushed */ +#define COMP_F_MIGRATE (1<<5)/* push stub-v2 or comp-lzo no when we see a client with comp-lzo in occ */ /* src/openvpn/multi.c +42
-0@@ -2469,6 +2469,47 @@ multi_client_connect_early_setup(struct multi_context *m,multi_client_connect_setenv (m, mi); } +/** +* Do the necessary modification for doing the compress migrate. This is +* implemented as a connect handler as it fits the modify config for a client +* paradigm and also is early enough in the chain to be overwritten by another +* ccd/script to do compression on a special client. +*/ +static enum client_connect_return +multi_client_connect_compress_migrate (struct multi_context *m, +struct multi_instance *mi, +bool deferred, +unsigned int *option_types_found) +{ +#ifdef USE_COMP +struct options *o = &mi->context.options; +const char *const peer_info = mi->context.c2.tls_multi->peer_info; + +if (!peer_info) + { +return CC_RET_SUCCEEDED ; + } + +if (o->comp.flags &COMP_F_MIGRATE && mi->context.c2.tls_multi->remote_usescomp) + { +if (strstr (peer_info,"IV_COMP_STUBv2=1" )) + { +push_option (o,"compress stub-v2" ,M_USAGE ); + } +else + { +/* Client is old and does not support STUBv2 but since it +* announced comp-lzo via OCC we assume it uses comp-lzo, so +* switch to that and push the uncompressed variant. */ +push_option (o,"comp-lzo no" ,M_USAGE ); + o->comp.alg =COMP_ALG_STUB ; + *option_types_found |=OPT_P_COMP ; + } + } +#endif +return CC_RET_SUCCEEDED ; +} +/** * Try to source a dynamic config file from the * --client-config-dir directory. @@ -2537,6 +2578,7 @@ typedef enum client_connect_return (*multi_client_connect_handler) bool from_deferred, unsigned int *option_types_found);static const multi_client_connect_handler client_connect_handlers[] = { + multi_client_connect_compress_migrate, multi_client_connect_source_ccd, multi_client_connect_call_plugin_v1, multi_client_connect_call_plugin_v2,src/openvpn/options.c +6
-0@@ -7783,6 +7783,12 @@ add_option(struct options *options, options->comp.alg =COMP_ALGV2_UNCOMPRESSED ; options->comp.flags |=COMP_F_ADVERTISE_STUBS_ONLY ; } +else if (streq (p[1 ],"migrate" )) + { + options->comp.alg =COMP_ALG_UNDEF ; + options->comp.flags =COMP_F_MIGRATE ; + + }else if (options->comp.flags &COMP_F_ALLOW_STUB_ONLY ) {/* Also printed on a push to hint at configuration problems */ src/openvpn/ssl.c +40
-3@@ -60,6 +60,7 @@#include "ssl_verify.h" #include "ssl_backend.h" #include "ssl_ncp.h" +#include "ssl_util.h" #include "auth_token.h" #include "memdbg.h" @@ -2235,12 +2236,24 @@ error:return ret; } +#ifdef USE_COMP +static bool +write_compat_local_options (struct buffer *buf,const char *options) +{ +struct gc_arena gc =gc_new (); +const char *local_options =options_string_compat_lzo (options, &gc); +bool ret =write_string (buf, local_options,TLS_OPTIONS_LEN ); +gc_free (&gc); +return ret; +} +#endif +/** * Handle the writing of key data, peer-info, username/password, OCC * to the TLS control channel (cleartext). */ static bool -key_method_2_write (struct buffer *buf,struct tls_session *session) +key_method_2_write (struct buffer *buf,struct tls_multi *multi,struct tls_session *session) {struct key_state *ks = &session->key[KS_PRIMARY ];/* primary key */ @@ -2266,7 +2279,19 @@ key_method_2_write(struct buffer *buf, struct tls_session *session)/* write options string */ { +#ifdef USE_COMP +if (multi->remote_usescomp && session->opt->mode ==MODE_SERVER + && multi->opt.comp_options.flags &COMP_F_MIGRATE ) + { +if (!write_compat_local_options (buf, session->opt->local_options)) + { + goto error; + } + } + else +#endif if (!write_string (buf, session->opt->local_options,TLS_OPTIONS_LEN )) + { goto error; }@@ -2460,6 +2485,7 @@ key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_sessiofree (multi->remote_ciphername); multi->remote_ciphername =options_string_extract_option (options,"cipher" ,NULL ); + multi->remote_usescomp =strstr (options,",comp-lzo," );/* In OCC we send '[null-cipher]' instead 'none' */ if (multi->remote_ciphername@@ -2509,7 +2535,18 @@ key_method_2_read(struct buffer *buf, struct tls_multi *multi, struct tls_sessioif (!session->opt->disable_occ && !options_cmp_equal (options, session->opt->remote_options)) { -options_warning (options, session->opt->remote_options); +const char *remote_options = session->opt->remote_options; +#ifdef USE_COMP +if (multi->opt.comp_options.flags &COMP_F_MIGRATE && multi->remote_usescomp) + { +msg (D_SHOW_OCC ,"Note: 'compress migrate' detected remote peer " +"with compression enabled." ); + remote_options =options_string_compat_lzo (remote_options, &gc); + } +#endif + +options_warning (options, remote_options); +if (session->opt->ssl_flags &SSLF_OPT_VERIFY ) {msg (D_TLS_ERRORS ,"Option inconsistency warnings triggering disconnect due to --opt-verify" );@@ -2826,7 +2863,7 @@ tls_process(struct tls_multi *multi,if (!buf->len && ((ks->state ==S_START && !session->opt->server) || (ks->state ==S_GOT_KEY && session->opt->server))) { -if (!key_method_2_write (buf, session)) +if (!key_method_2_write (buf, multi, session)) { goto error; }src/openvpn/ssl_common.h +1
-0@@ -576,6 +576,7 @@ struct tls_multibool use_peer_id;char *remote_ciphername;/**< cipher specified in peer's config file */ +bool remote_usescomp;/**< remote announced comp-lzo in OCC string */ /* * Our session objects. src/openvpn/ssl_util.c +12
-0@@ -75,3 +75,44 @@ extract_iv_proto(const char *peer_info) }return 0 ; } + +const char * +options_string_compat_lzo (const char *options,struct gc_arena *gc) +{ +/* Example string without and with comp-lzo, i.e. input/output of this function */ +/* w/o comp: 'V4,dev-type tun,link-mtu 1457,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server' */ +/* comp-lzo: 'V4,dev-type tun,link-mtu 1458,tun-mtu 1400,proto UDPv4,comp-lzo,auth SHA1,keysize 128,key-method 2,tls-server' */ + +/* Note: since this function is used only in a very limited scope it makes +* assumptions how the string looks. Since we locally generated the string +* we can make these assumptions */ +
src/openvpn/ssl_util.c extract_iv_proto(const char *peer_info) · line 99
Quoted 10 lines
src/openvpn/ssl_util.c +10
-0+/* Check that the link-mtu string is in options */ +const char *tmp =strstr (options,",link-mtu" ); +if (!tmp) + { +return options; + } + +/* Get old link_mtu size */ +int link_mtu; +if (sscanf (tmp,",link-mtu %d," , &link_mtu) !=1 || link_mtu <100 || link_mtu >9900 )
missing space after if
Quoted 152 lines
src/openvpn/ssl_util.c +19
-0+ { +return options; + } + +/* 1 byte for the possibility of 999 to 1000 and 1 byte for the null +* terminator */ +struct buffer buf =alloc_buf_gc (strlen (options) +strlen (",comp-lzo" ) +2 , gc); + +buf_write (&buf, options, (int )(tmp - options)); + +/* Increase link-mtu by one for the comp-lzo opcode */ +buf_printf (&buf,",link-mtu %d" , link_mtu +1 ); + + tmp +=strlen (",link-mtu " ) + (link_mtu <1000 ?3 :4 ); + +buf_printf (&buf,"%s,comp-lzo" , tmp); + +return BSTR (&buf); +}src/openvpn/ssl_util.h +15
-0@@ -54,4 +54,19 @@ extract_var_peer_info(const char *peer_info,*/ unsigned int extract_iv_proto (const char *peer_info); + +/** +* Takes a locally produced OCC string for TLS server mode and modifies as +* if the option comp-lzo was enabled. This is to send a client in +* comp-lzo migrate mode the expected OCC string. +* +* Note: This function excpets the string to be in the locally generated +* format and does not accept arbitrary strings. +* +* @param options the locally generated OCC string +* @param gc gc_arena to allocate the returned string in +* @return the modified string or options on error +*/ +const char * +options_string_compat_lzo (const char *options,struct gc_arena *gc);#endif tests/unit_tests/openvpn/Makefile.am +12
-1@@ -6,7 +6,7 @@ if HAVE_LD_WRAP_SUPPORT test_binaries += argv_testdriver buffer_testdriver endif -test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver +test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver ncp_testdriver misc_testdriver if HAVE_LD_WRAP_SUPPORT test_binaries += tls_crypt_testdriver endif@@ -127,3 +127,14 @@ ncp_testdriver_SOURCES = test_ncp.c mock_msg.c \ $(openvpn_srcdir)/packet_id.c \ $(openvpn_srcdir)/platform.c \ $(openvpn_srcdir)/ssl_util.c + +misc_testdriver_CFLAGS = @TEST_CFLAGS@ \ + -I$(openvpn_includedir) -I$(compat_srcdir) -I$(openvpn_srcdir) + +misc_testdriver_LDFLAGS = @TEST_LDFLAGS@ + +misc_testdriver_SOURCES = test_misc.c mock_msg.c \ + mock_get_random.c \ + $(openvpn_srcdir)/buffer.c \ + $(openvpn_srcdir)/ssl_util.c \ + $(openvpn_srcdir)/platform.ctests/unit_tests/openvpn/test_misc.c new file +73
-0@@ -0,0 +1,83 @@ +/* +* OpenVPN -- An application to securely tunnel IP networks +* over a single UDP port, with support for SSL/TLS-based +* session authentication and key exchange, +* packet encryption, packet authentication, and +* packet compression. +* +* Copyright (C) 2021 Arne Schwabe <[email protected]...> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#elif defined(_MSC_VER) +#include "config-msvc.h" +#endif + +#include "syshead.h" + +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> +#include <setjmp.h> +#include <cmocka.h> + +#include "ssl_util.h" + +static void +test_compat_lzo_string (void **state) +{ +struct gc_arena gc =gc_new (); + +const char * input ="V4,dev-type tun,link-mtu 1457,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server" ; + +const char * output =options_string_compat_lzo (input, &gc); + +assert_string_equal (output,"V4,dev-type tun,link-mtu 1458,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server,comp-lzo" ); + +/* This string is has a much too small link-mtu so we should fail on it" */ + input ="V4,dev-type tun,link-mtu 2,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server" ; + + output =options_string_compat_lzo (input, &gc); + +assert_string_equal (input, output); + +/* not matching at all */ + input ="V4,dev-type tun" ; + output =options_string_compat_lzo (input, &gc); + +assert_string_equal (input, output); + + + input ="V4,dev-type tun,link-mtu 999,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server" ; + output =options_string_compat_lzo (input, &gc); + +/* 999 -> 1000, 3 to 4 chars */ +assert_string_equal (output,"V4,dev-type tun,link-mtu 1000,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server,comp-lzo" ); + +};
tests/unit_tests/openvpn/test_misc.c line 83
Quoted 10 lines
tests/unit_tests/openvpn/test_misc.c new file +10
-0+ +const struct CMUnitTest misc_tests[] = { +cmocka_unit_test (test_compat_lzo_string), +}; + +int +main (void ) +{ +return cmocka_run_group_tests (misc_tests,NULL ,NULL ); +}
Except for the minor style issue (that can be fixed as commit time), this patch looks good and passes my tests with client announcing various combinations of compress/comp and IV_COMP_STUBv2.
Signature · 1 line
Antonio Quartulli
Re: [Openvpn-devel] [PATCH v2] Implement '--compress migrate' to migrate to non-compression setup
Hi,
On Thu, Mar 25, 2021 at 09:13:13PM +0100, Antonio Quartulli wrote:
[..]
Quoted 1 line
I see your ACK, and find myself wanting to be convinced that this is really the best possible approach.
The code change in multi.c is nice, but the effects on ssl.c are ugly, and will be with us "forever".
So I wonder if un-rushing the part about "make compression go away" slightly (since even with "comp-lzo set", both ends do not actually compress anymore, already today), and rushing "remove all/most OCC warnings" instead (including 2.5.x) - so, when 2.5.x and 2.6.x just do not warn on OCC mismatches anymore, we could have the nice part of this patch, and skip the ugly one.
For everything that can be pushed, OCC warnings seem to just get in the way these days.
I'm not adamant on this, just want a bit more discussion on "best strategy" and timeline. I've put it on wednesday's meeting agenda - more brains around, then :-)
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...[Openvpn-devel] [PATCH applied] Re: Implement '--compress migrate' to migrate to non-compression setup
In reply to Arne SchwabeYour patch has been applied to the master branch.
As discussed extensively I do not like having to rewrite OCC strings in the middle of the session handshake - the code is complex enough as it is. OTOH I've let myself be convinced that the alternative approaches ("use management interface", "wait for de-fused OCC on all clients encountered") are not really better - so we go with this, and I've opened a Trac ticket as reminder for "get rid of this again" (#1397).
WRT testing: I have extended one of my server instances to include "compress migrate", and then thrown a few client test cases with and without "comp-lzo", "compress lz4", ... against it (2.2 .. master).
As expected it fails to handle a 2.3 client compiled with --enable-small
(because that disables OCC). 2.3 + 2.4 + master succeed.
Somewhat unexpectedly it also fails for the 2.2 client with comp-lzo - the server recognizes that it it has an OCC client with compression
Note: 'compress migrate' detected remote peer with compression enabled
but fails to send "comp-lzo no". This is due to this code part
+ if (!peer_info)
+ {
+ return CC_RET_SUCCEEDED;
+ }
which only acts if the client pushes any sort of peer info, which is not default in 2.2 - if I tell the 2.2 client to do "--push-peer-info", it works.
Since the whole point of this patch is to "make crappy clients work" I'd suggest to move the "peer_info" check inside the
+ if (o->comp.flags & COMP_F_MIGRATE && mi->context.c2.tls_multi->remote_usescomp)
clause (-> if (peerinfo && strstr(peer_info, "IV_COMP...") ) which will make the server behave for 2.2 clients as well.
Since this is more of a nuisance than a showstopper, I will proceed with merging, and have sent a fix patch to the list.
commit 8fa8a17528c001abc7d5f45e9c2ffa3ed2f6af43 (master)
Author: Arne Schwabe Date: Wed Mar 24 23:08:53 2021 +0100
Implement '--compress migrate' to migrate to non-compression setup
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Antonio Quartulli <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg21801.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering