Skip to contentSkip to conversation

Always save/restore pull options

PATCH In review Arne Schwabe 3 participants 7 messages Apr 8, 2021 – Apr 17, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 Always save/restore pull options

The makes the code path for pull and non-pull more aligned and even though this might do extra work for non-pull scenarios, saving the few bytes of memory is not a worthwhile optimisation here.

Additionally with the upcoming P2P mode NCP, the client needs to save/restore a subset of these options anyway.

---
 src/openvpn/init.c    |  6 ++--
 src/openvpn/options.c | 66 +++++++++++++++++++++----------------------
 src/openvpn/options.h |  8 +++---
 3 files changed, 38 insertions(+), 42 deletions(-)
src/openvpn/init.c +2 -4
index fb3d6beaa..e62aace51 100644
@@ -4052,10 +4052,8 @@ init_instance(struct context *c, const struct env_set *env, const unsigned int f
         }
     }
 
-    if (c->options.pull)
-    {
-        pre_pull_restore(&c->options, &c->c2.gc);
-    }
+    /* Resets all values to the initial values from the config where needed */
+    pre_connect_restore(&c->options, &c->c2.gc);
 
     /* map in current connection entry */
     next_connection_entry(c);
src/openvpn/options.c +32 -34

87 lines not on this page · raw message

src/openvpn/options.h +4 -4
index d3db33ece..078bed75b 100644
@@ -59,7 +59,7 @@
 extern const char title_string[];
 
 /* certain options are saved before --pull modifications are applied */
-struct options_pre_pull
+struct options_pre_connect
 {
     bool tuntap_options_defined;
     struct tuntap_options tuntap_options;
@@ -493,7 +493,7 @@ struct options
     int push_continuation;
     unsigned int push_option_types_found;
     const char *auth_user_pass_file;
-    struct options_pre_pull *pre_pull;
+    struct options_pre_connect *pre_connect;
 
     int scheduled_exit_interval;
 
@@ -787,9 +787,9 @@ char *options_string_extract_option(const char *options_string,
 
 void options_postprocess(struct options *options);
 
-void pre_pull_save(struct options *o);
+void pre_connect_save(struct options *o);
 
-void pre_pull_restore(struct options *o, struct gc_arena *gc);
+void pre_connect_restore(struct options *o, struct gc_arena *gc);
 
 bool apply_push_options(struct options *options,
                         struct buffer *buf,
Signature · 1 line
2.31.1
#1 lore raw

PATCH 2/3 Also restore/save compress related options in reconnects

---
 src/openvpn/options.c | 11 +++++++++++
 src/openvpn/options.h |  3 +++
 2 files changed, 14 insertions(+)
src/openvpn/options.c +11 -0
index a72e1b9ae..00ad98f15 100644
@@ -3595,9 +3595,15 @@ pre_connect_save(struct options *o)
     o->pre_connect->authname = o->authname;
 
     /* Ping related options should be reset to the config values on reconnect */
+
     o->pre_connect->ping_rec_timeout = o->ping_rec_timeout;
     o->pre_connect->ping_rec_timeout_action = o->ping_rec_timeout_action;
     o->pre_connect->ping_send_timeout = o->ping_send_timeout;
+
+    /* Miscellaneous Options */
+#ifdef USE_COMP
+    o->pre_connect->comp = o->comp;
+#endif
 }
 
 void
@@ -3650,6 +3656,11 @@ pre_connect_restore(struct options *o, struct gc_arena *gc)
         o->ping_rec_timeout = pp->ping_rec_timeout;
         o->ping_rec_timeout_action = pp->ping_rec_timeout_action;
         o->ping_send_timeout = pp->ping_send_timeout;
+
+        /* Miscellaneous Options */
+#ifdef USE_COMP
+        o->comp = pp->comp;
+#endif
     }
 
     o->push_continuation = 0;
src/openvpn/options.h +3 -0
index 078bed75b..f52768680 100644
@@ -81,6 +81,9 @@ struct options_pre_connect
     int ping_rec_timeout_action;
 
     int foreign_option_index;
+#ifdef USE_COMP
+    struct compress_options comp;
+#endif
 };
 
 #if !defined(ENABLE_CRYPTO_OPENSSL) && !defined(ENABLE_CRYPTO_MBEDTLS)
Signature · 1 line
2.31.1
Acked-by on v1 2/3
#2 lore raw

[Openvpn-devel] [PATCH applied] Re: Also restore/save compress related options in reconnects

Stared-at-code (looks good), client side tested with the usual parcours (good), and also tested with my two known-weird/broken test cases for "compress not restored" (fixed!).

Your patch has been applied to the master branch.

I tried to apply it to release/2.5, but the resulting binary did not behave - I can see that it restored the comp settings, but it does so *after* OCC handshake (so the OCC warning is still there) *and* it does not re-init compression - so the case "config has comp-lzo, server A pushes compress lz4, server B pushes nothing" (so it should do LZO) still fails. I think I need one of the other patches that changes the "when are options saved/restored" as prerequisite here.

Will come back...

commit 2a414c3c79bba089183a517a2d355b5aaae0b4a4 (master)

Author: Arne Schwabe
Date:   Thu Apr 8 14:00:28 2021 +0200
     Also restore/save compress related options in reconnects

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg22078.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#3 lore raw

PATCH 3/3 Allow all GCM ciphers

In reply to Arne Schwabe

OpenSSL also allows ARIA-GCM and that works well with our implementation While the handpicked list was needed for earlier OpenSSL versions (and is still needed for Chacha20-Poly1305), the API nowadays with OpenSSL 1.0.2 and 1.1.x works as expected.

---
 src/openvpn/crypto_openssl.c | 5 +++++
 1 file changed, 5 insertions(+)
src/openvpn/crypto_openssl.c +5 -0
index f8b36bf85..235d0c321 100644
@@ -728,6 +728,11 @@ cipher_kt_mode_aead(const cipher_kt_t *cipher)
 {
     if (cipher)
     {
+        if (EVP_CIPHER_mode(cipher) == OPENVPN_MODE_GCM)
+        {
+            return true;
+        }
+
         switch (EVP_CIPHER_nid(cipher))
         {
             case NID_aes_128_gcm:
Signature · 1 line
2.31.1
#4 lore raw

Re: [Openvpn-devel] [PATCH 3/3] Allow all GCM ciphers

Hi,

Quoted 16 lines · Arne Schwabe

OpenSSL also allows ARIA-GCM and that works well with our implementation While the handpicked list was needed for earlier OpenSSL versions (and is still needed for Chacha20-Poly1305), the API nowadays with OpenSSL 1.0.2 and 1.1.x works as expected.

---
 src/openvpn/crypto_openssl.c | 5 +++++
 1 file changed, 5 insertions(+)
src/openvpn/crypto_openssl.c +0 -0
index f8b36bf85..235d0c321 100644
@@ -728,6 +728,11 @@ cipher_kt_mode_aead(const cipher_kt_t *cipher)
 {

src/openvpn/crypto_openssl.c cipher_kt_mode_aead(const cipher_kt_t *cipher) · line 738

Quoted 10 lines
src/openvpn/crypto_openssl.c +5 -0
     if (cipher)
     {
+        if (EVP_CIPHER_mode(cipher) == OPENVPN_MODE_GCM)
+        {
+            return true;
+        }
+
         switch (EVP_CIPHER_nid(cipher))
         {
             case NID_aes_128_gcm:

If the hand-picked list is required only for chacha-poly1305, why not removing all the AES variants from this list?

I tested ossl 1.0.2 and indeed EVP_CIPHER_mode(*aes-gcm*) returns GCM, so this list should not be required.

Regards,

Signature · 1 line
Antonio Quartulli
#5 lore raw

Re: [Openvpn-devel] [PATCH 3/3] Allow all GCM ciphers

Am 16.04.21 um 00:22 schrieb Antonio Quartulli:

Quoted 33 lines

Hi,

Quoted 16 lines · Arne Schwabe

OpenSSL also allows ARIA-GCM and that works well with our implementation While the handpicked list was needed for earlier OpenSSL versions (and is still needed for Chacha20-Poly1305), the API nowadays with OpenSSL 1.0.2 and 1.1.x works as expected.

---
 src/openvpn/crypto_openssl.c | 5 +++++
 1 file changed, 5 insertions(+)
src/openvpn/crypto_openssl.c +0 -0
index f8b36bf85..235d0c321 100644
@@ -728,6 +728,11 @@ cipher_kt_mode_aead(const cipher_kt_t *cipher)
 {

src/openvpn/crypto_openssl.c cipher_kt_mode_aead(const cipher_kt_t *cipher) · line 738

Quoted 10 lines
src/openvpn/crypto_openssl.c +5 -0
     if (cipher)
     {
+        if (EVP_CIPHER_mode(cipher) == OPENVPN_MODE_GCM)
+        {
+            return true;
+        }
+
         switch (EVP_CIPHER_nid(cipher))
         {
             case NID_aes_128_gcm:

If the hand-picked list is required only for chacha-poly1305, why not removing all the AES variants from this list?

Quoted 2 lines

I tested ossl 1.0.2 and indeed EVP_CIPHER_mode(*aes-gcm*) returns GCM, so this list should not be required.

I was a chicken and did not test libreSSL but I can test it and then send an updated patch. %)

Arne

Acked-by on v1 1/3
#6 lore raw
In reply to Arne Schwabe

The code looks good, and the local test for the "pull" case works, unsurprisingly (as it does the very same things in that case). It might trigger different behaviour for the "non pull" case - but then, it puts everything back to where it was before (if saved), so I do not expect surprises. Client side testing and "break the things we know are broken on save/restore today" (compress etc) works as expected.

This is a (fairly light) refactoring patch, but as it is prerequisite for two further patches (and maybe more) that are actual bugfixes, I considered putting into 2.5 as well. It does not want to go in (#ifdef P2MP, and conflicts with the NCP saving patch), so I'll backport the "compress" and "route-*gateway" patch manually. Those are trivial enough.

Your patch has been applied to the master branch.

commit c1150e5b95b63a95ee4f157d8870d3214099d8a0

Author: Arne Schwabe
Date:   Thu Apr 8 14:00:27 2021 +0200
     Always save/restore pull options

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg22079.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering