061f384
From: Michele Baldessari <michele@acksyn.org>
061f384
Date: Tue, 28 Sep 2021 17:26:16 +0200
061f384
Subject: [PATCH] Allow openssl-3.0.0 FIPS compilation
061f384
061f384
Openssl 3.0.0 dropped support for the old way of adding fips
061f384
and in particular it dropped support for FIPS_mode() and
061f384
FIPS_mode_set().
061f384
061f384
In RHEL9, openssl-3.0.0 ships a compat macro for FIPS_mode(), so
061f384
this change focuses on replacing FIPS_mode_set()
061f384
061f384
Compiled erlang-erts-24.1-1.el9.x86_64 with this patch and then tested as follows:
061f384
A. Booted the system with fips enabled:
061f384
[root@rhel9 ~]# fips-mode-setup --check
061f384
FIPS mode is enabled.
061f384
061f384
B. Set up a fips config file:
061f384
cat > fips.config<
061f384
[{crypto, [{fips_mode, true}]}]
061f384
.
061f384
EOF
061f384
061f384
C. Ran the following:
061f384
$ erl -config fips
061f384
1> crypto:info_fips().
061f384
not_enabled
061f384
2> crypto:enable_fips_mode(true).
061f384
true
061f384
3> crypto:info_fips().
061f384
enabled
061f384
061f384
D. Verified that the ciphers when using fips are a subset of the usual
061f384
ciphers:
061f384
061f384
4> crypto:supports().
061f384
[{hashs,[sha,sha224,sha256,sha384,sha512,sha3_224,sha3_256,
061f384
         sha3_384,sha3_512,blake2b,blake2s]},
061f384
 {ciphers,[aes_cbc,aes_ccm,aes_cfb128,aes_cfb8,aes_ctr,
061f384
           aes_ecb,aes_gcm,des_ede3_cfb,aes_128_cbc,aes_192_cbc,
061f384
           aes_256_cbc,aes_128_cfb128,aes_192_cfb128,aes_256_cfb128,
061f384
           aes_128_cfb8,aes_192_cfb8,aes_256_cfb8,aes_128_ecb,
061f384
           aes_192_ecb,aes_256_ecb,aes_256_gcm,aes_256_ccm,aes_192_gcm,
061f384
           aes_192_ccm,aes_128_gcm|...]},
061f384
 {public_keys,[rsa,dss,dh,ecdsa,ecdh]},
061f384
 {macs,[cmac,hmac,poly1305]},
061f384
 {curves,[]},
061f384
 {rsa_opts,[rsa_pkcs1_pss_padding,rsa_pss_saltlen,
061f384
            rsa_mgf1_md,rsa_pkcs1_oaep_padding,rsa_oaep_label,
061f384
            rsa_oaep_md,signature_md,rsa_pkcs1_padding,rsa_x931_padding,
061f384
            rsa_no_padding]}]
061f384
061f384
Note that we could probably just have patched out the FIPS_mode_set()
061f384
calls as FIPS gets enforced on the system. The automatism is going to
061f384
come with a version of openssl that is later than > openssl-3.0.0-2.
061f384
061f384
Co-Authored-By: John Eckersberg <jeckersb@redhat.com>
061f384
Co-Authored-By: Damien Ciabrini <dciabrin@redhat.com>
061f384
061f384
[1] https://wiki.openssl.org/index.php/OpenSSL_3.0#Upgrading_from_the_OpenSSL_2.0_FIPS_Object_Module
061f384
061f384
diff --git a/lib/crypto/c_src/openssl_config.h b/lib/crypto/c_src/openssl_config.h
b606ec2
index 49627f17e7..1d12174e3e 100644
061f384
--- a/lib/crypto/c_src/openssl_config.h
061f384
+++ b/lib/crypto/c_src/openssl_config.h
b606ec2
@@ -438,6 +438,10 @@ do {                                                    \
061f384
 # undef FIPS_SUPPORT
061f384
 #endif
061f384
 
061f384
+#if defined(FIPS_SUPPORT) \
061f384
+    && OPENSSL_VERSION_NUMBER  >= (PACKED_OPENSSL_VERSION_PLAIN(3,0,0) & ~0xff)
061f384
+#define FIPS_mode_set(fips_mode) EVP_default_properties_enable_fips(NULL, fips_mode)
061f384
+#endif
061f384
 
b606ec2
 /* This is not the final FIPS adaptation for 3.0, just making it compilable */
b606ec2
 #if OPENSSL_VERSION_NUMBER >= PACKED_OPENSSL_VERSION_PLAIN(3,0,0)