Skip to contentSkip to conversation

Detect unusable ciphers on patched OpenSSL of RHEL/Centos

PATCH In review Arne Schwabe 4 participants 6 messages Aug 18, 2021 – Sep 10, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Detect unusable ciphers on patched OpenSSL of RHEL/Centos

OpenSSL on RHEL 8 and CentOS 8 system when these system are put into FIPS mode need extra code to figure out if a specific cipher algorithm is usable on these system. This is particularly problem in data-ciphers as the errors might occur much later when a client connects and as these cipher are not caught during config initialisation.

This also prepares for adding Chacha20-Poly1305 when available to data-ciphers by making the detection logic used to check if cipher_kt_get returns non-NULL work on these systems.

---
 src/openvpn/crypto.c         |  6 ++++++
 src/openvpn/crypto_openssl.c | 10 ++++++++++
 2 files changed, 16 insertions(+)
src/openvpn/crypto.c +6 -0
index b9c95225a..1dfc760f9 100644
@@ -1806,6 +1806,12 @@ print_cipher(const cipher_kt_t *cipher)
     {
         printf(", TLS client/server mode only");
     }
+#ifdef OPENSSL_FIPS
+    if (FIPS_mode() && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_FIPS))
+    {
+        printf(", disabled by FIPS mode");
+    }
+#endif
 
     printf(")\n");
 }
src/openvpn/crypto_openssl.c +10 -0
index b55d32b2c..419265a51 100644
@@ -599,7 +599,17 @@ cipher_kt_get(const char *ciphername)
         return NULL;
     }
 
+#ifdef OPENSSL_FIPS
+    /* Rhel 8/CentOS 8 have a patched OpenSSL version that return a cipher
+     * here that is actually not usable if in FIPS mode */
 
+    if (FIPS_mode() && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_FIPS))
+    {
+        msg(D_LOW, "Cipher algorithm '%s' is known by OpenSSL library but "
+                    "currently disabled by running in FIPS mode.", ciphername);
+        return NULL;
+    }
+#endif
     if (EVP_CIPHER_key_length(cipher) > MAX_CIPHER_KEY_LENGTH)
     {
         msg(D_LOW, "Cipher algorithm '%s' uses a default key size (%d bytes) "
Signature · 1 line
2.32.0
#1 lore raw

PATCH 2/2 Include Chacha20-Poly1305 into default --data-ciphers when available

Most TLS 1.3 libraries inlcude the Chacha20-Poly1305 based cipher suite beside the AES-GCM based ones int he list of default ciphers suites. Chacha20-Poly1305 is accepted as good alternative AEAD algorithm to the AES-GCM algorithm by crypto community.

Follow this and include Chacha20-Poly1305 by default in data-ciphers when available. This makes picking Chacha20-Poly1305 easier as it only requires to change server (by changing priority) or client side (removing AES-GCM from data-ciphers) to change to Chacha20-Poly1305.

---
 Changes.rst                             |  5 +++++
 doc/man-sections/cipher-negotiation.rst |  3 ++-
 doc/man-sections/protocol-options.rst   |  3 ++-
 src/openvpn/options.c                   | 25 ++++++++++++++++++++++++-
 4 files changed, 33 insertions(+), 3 deletions(-)
Changes.rst +5 -0
index 0323a7f7a..637ed97a6 100644
@@ -65,6 +65,11 @@ Deprecated features
     This option mainly served a role as debug option when NCP was first
     introduced. It should now no longer be necessary.
 
+
+User-visible Changes
+--------------------
+- CHACHA20-POLY1305 is included in the default of ``--data-ciphers`` when available.
+
 Overview of changes in 2.5
 ==========================
 
doc/man-sections/cipher-negotiation.rst +2 -1
index a2feb5f9c..423b5ab6a 100644
@@ -18,7 +18,8 @@ with a AUTH_FAILED message (as seen in client log):
 OpenVPN 2.5 will only allow the ciphers specified in ``--data-ciphers``. To ensure
 backwards compatibility also if a cipher is specified using the ``--cipher`` option
 it is automatically added to this list. If both options are unset the default is
-:code:`AES-256-GCM:AES-128-GCM`.
+:code:`AES-256-GCM:AES-128-GCM`. In 2.6 and later the default is changed to
+:code:`AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305` when Chacha20-Poly1305 is available.
 
 OpenVPN 2.4 clients
 -------------------
doc/man-sections/protocol-options.rst +2 -1
index 5ae780e1f..0fef90f7b 100644
@@ -192,7 +192,8 @@ configured in a compatible way between both the local and remote side.
 --data-ciphers cipher-list
   Restrict the allowed ciphers to be negotiated to the ciphers in
   ``cipher-list``. ``cipher-list`` is a colon-separated list of ciphers,
-  and defaults to :code:`AES-256-GCM:AES-128-GCM`.
+  and defaults to :code:`AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305` when
+  Chacha20-Poly1305 is available and otherwise :code:`AES-256-GCM:AES-128-GCM`.
 
   For servers, the first cipher from ``cipher-list`` that is also
   supported by the client will be pushed to clients that support cipher
src/openvpn/options.c +24 -1
index 7e146db90..9c01d6a1d 100644
@@ -842,7 +842,6 @@ init_options(struct options *o, const bool init_gc)
     o->stale_routes_check_interval = 0;
     o->ifconfig_pool_persist_refresh_freq = 600;
     o->scheduled_exit_interval = 5;
-    o->ncp_ciphers = "AES-256-GCM:AES-128-GCM";
     o->authname = "SHA1";
     o->prng_hash = "SHA1";
     o->prng_nonce_secret_len = 16;
@@ -3077,6 +3076,29 @@ options_postprocess_verify(const struct options *o)
     }
 }
 
+/**
+ * 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;
+    }
+    else if (cipher_kt_get("CHACHA20-POLY1305"))
+    {
+        o->ncp_ciphers = "AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305";
+    }
+    else
+    {
+        o->ncp_ciphers = "AES-256-GCM:AES-128-GCM";
+    }
+}
+
 static void
 options_postprocess_cipher(struct options *o)
 {
@@ -3137,6 +3159,7 @@ options_postprocess_mutate(struct options *o)
     helper_keepalive(o);
     helper_tcp_nodelay(o);
 
+    options_postprocess_setdefault_ncpciphers(o);
     options_postprocess_cipher(o);
     options_postprocess_mutate_invariant(o);
 
Signature · 1 line
2.32.0
Acked-by on v1 2/2
#2 lore raw

Re: [Openvpn-devel] [PATCH 2/2] Include Chacha20-Poly1305 into default --data-ciphers when available

Hi,

Quoted 11 lines · Arne Schwabe

Most TLS 1.3 libraries inlcude the Chacha20-Poly1305 based cipher suite beside the AES-GCM based ones int he list of default ciphers suites. Chacha20-Poly1305 is accepted as good alternative AEAD algorithm to the AES-GCM algorithm by crypto community.

Follow this and include Chacha20-Poly1305 by default in data-ciphers when available. This makes picking Chacha20-Poly1305 easier as it only requires to change server (by changing priority) or client side (removing AES-GCM from data-ciphers) to change to Chacha20-Poly1305.

Not sure why this is 2/2 as it seems unrelated to 1/2. Indeed I applied and reviewed this patch alone.

It does what it says and imho it is pretty clean.

Tested with a client that connects against a server having default ciphers. The client, if willing, can specify chacha20poly1305 only and connect with it.

This is a sensible change which IMHO will make a lot of people happy.

Signature · 1 line
Antonio Quartulli
#3 lore raw

[Openvpn-devel] [PATCH applied] Re: Include Chacha20-Poly1305 into default --data-ciphers when available

In reply to Arne Schwabe

I have not tested this "in-depth", but the code looks good, and the result passes my t_client rig with various OpenSSL and mbedTLS versions.

(I have not actually tested "both server and client have CHACHA-POLY active and using that works" but I trust Antonio there :-) )

Your patch has been applied to the master branch.

commit a38a377fd524d0e14a23ed17487ea3e3d3ad3fe7

Author: Arne Schwabe
Date:   Wed Aug 18 23:33:54 2021 +0200
     Include Chacha20-Poly1305 into default --data-ciphers when available

     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]/msg22745.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

Acked-by on v1 1/2
#4 lore raw
In reply to Arne Schwabe
Quoted 10 lines · Arne Schwabe

OpenSSL on RHEL 8 and CentOS 8 system when these system are put into FIPS mode need extra code to figure out if a specific cipher algorithm is usable on these system. This is particularly problem in data-ciphers as the errors might occur much later when a client connects and as these cipher are not caught during config initialisation.

This also prepares for adding Chacha20-Poly1305 when available to data-ciphers by making the detection logic used to check if cipher_kt_get returns non-NULL work on these systems.

Quoted 6 lines
---
  src/openvpn/crypto.c         |  6 ++++++
  src/openvpn/crypto_openssl.c | 10 ++++++++++
  2 files changed, 16 insertions(+)

I've Looked at the code, built it on a RHEL-8.4 box with FIPS enabled and tested the binary with FIPS both enabled and disabled. It works smoothly there.

The OPENSSL_FIPS macro is defined in /usr/include/openssl/opensslconf-x86_64.h. So is handled outside of OpenVPN, and without that macro we don't need to be concerned about the FIPS_mode() function.

As mentioned in the community developer meeting today, there are some concerns about the recently released OpenSSL 3.0 and FIPS - but lets tackle that further down the road once we have distributions with the latest OpenSSL library more easily available.

The bottom line is ...

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#5 lore raw
In reply to Arne Schwabe

Thanks for the test on CentOS 8. I have skimmed the code, but since I have no FIPS enabled OpenSSL around, haven't tested anything.

Your patch has been applied to the master branch.

commit 8f25cefea15481cc0338bca40a89d96fbe745b9f

Author: Arne Schwabe
Date:   Wed Aug 18 23:33:53 2021 +0200
     Detect unusable ciphers on patched OpenSSL of RHEL/Centos

     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]/msg22746.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering