Skip to contentSkip to conversation

crypto: Fix OPENSSL_FIPS enabled builds

PATCH In review David Sommerseth 3 participants 4 messages Jan 19, 2022 – Jan 21, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 crypto: Fix OPENSSL_FIPS enabled builds

From: David Sommerseth <[email protected]...>

On Fedora and RHEL/CentOS, the standard OpenSSL library has the FIPS module enabled by default. On these platforms, the OPENSSL_FIPS macro is always defined via /usr/include/openssl/opensslconf-*.h.

Without this fix, the following compilation error appears:

./src/openvpn/crypto.c: In function ‘print_cipher’:
./src/openvpn/crypto.c:1707:43: error: ‘cipher’ undeclared (first use in this function); did you mean ‘iphdr’?

       if (FIPS_mode() && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_FIPS))
                                           ^~~~~~

The EVP_CIPHER_fetch() and EVP_CIPHER_free() methods are also provided via the openssl_compat.h for older than OpenSSL 3.0.

---
 src/openvpn/crypto.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
src/openvpn/crypto.c +7 -1
index 5626e2b6..eb0b1254 100644
@@ -34,6 +34,7 @@
 #include "error.h"
 #include "integer.h"
 #include "platform.h"
+#include "openssl_compat.h"
 
 #include "memdbg.h"
 
@@ -1704,10 +1705,15 @@ print_cipher(const char *ciphername)
         printf(", TLS client/server mode only");
     }
 #ifdef OPENSSL_FIPS
-    if (FIPS_mode() && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_FIPS))
+    evp_cipher_type *cipher = EVP_CIPHER_fetch(NULL, ciphername, NULL);
+
+    if (FIPS_mode()
+        && (NULL != cipher)
+        && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_FIPS))
     {
         printf(", disabled by FIPS mode");
     }
+    EVP_CIPHER_free(cipher);
 #endif
 
     printf(")\n");
Signature · 1 line
2.27.0
Acked-by on v3 1/1
#1 lore raw

We'll add build tests on Fedora / CentOS, as soon as September brings the new buildbot infrastructure... so we get the "looks like FIPS but isn't" stuff tested as well. (cipher) changed as instructed on IRC.

Your patch has been applied to the master branch.

commit 544330fefedc87a74b4e17e105ad9151b8ad1dc9

Author: David Sommerseth
Date:   Wed Jan 19 19:21:26 2022 +0100
     crypto: Fix OPENSSL_FIPS enabled builds

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

--
kind regards,

Gert Doering

#2 lore raw
In reply to David Sommerseth

Hi,

src/openvpn/crypto.c line 39

Quoted 10 lines · David Sommerseth

index 5626e2b6..eb0b1254 100644

src/openvpn/crypto.c +1 -0
@@ -34,6 +34,7 @@
 #include "error.h"
 #include "integer.h"
 #include "platform.h"
+#include "openssl_compat.h"
 
 #include "memdbg.h"

This breaks compilation for mbedtls builds, depending on which version of OpenSSL happens to be installed on the system (if any).

In this particular case, mbedtls build with a system openssl of 0.9.8, it blows up with

In file included from crypto.c:37:
openssl_compat.h: In function 'SSL_CTX_get_min_proto_version':
openssl_compat.h:635: error: 'SSL_OP_NO_TLSv1_1' undeclared
(first use in this

(and more of this)

which is unsurprising - it's not supposed to pull in these headers in the first place.

I wondered about this header, but did not wonder enough to verify that it indeed must not be included for non-openssl-builds.

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]...
#3 lore raw

Hi

Quoted 25 lines · Gert Doering

Hi,

src/openvpn/crypto.c line 39

Quoted 10 lines · David Sommerseth

index 5626e2b6..eb0b1254 100644

src/openvpn/crypto.c +1 -0
@@ -34,6 +34,7 @@
 #include "error.h"
 #include "integer.h"
 #include "platform.h"
+#include "openssl_compat.h"
 
 #include "memdbg.h"

This breaks compilation for mbedtls builds, depending on which version of OpenSSL happens to be installed on the system (if any).

In this particular case, mbedtls build with a system openssl of 0.9.8, it blows up with

In file included from crypto.c:37:
openssl_compat.h: In function 'SSL_CTX_get_min_proto_version':
openssl_compat.h:635: error: 'SSL_OP_NO_TLSv1_1' undeclared
(first use in this

Quoted 5 lines

(and more of this)

which is unsurprising - it's not supposed to pull in these headers in the first place.

Looking back at it, the patch and the problem it's trying to solve are both misplaced in crypto.c. That file should be ssl-lib agnostic and openssl related bits should go to crypto_openssl.c...

I think we need to remove that OPENSSL_FIPS clause and think of providing that extra info somewhere else if possible.

Selva