Skip to content

Commit 3cd2e2c

Browse files
committed
openssl: Make fips_mode option work with OpenSSL 3
1 parent f556fce commit 3cd2e2c

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

conf/plugins/openssl.opt

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ charon.plugins.openssl.engine_id = pkcs11
44
charon.plugins.openssl.fips_mode = 0
55
Set OpenSSL FIPS mode: disabled(0), enabled(1), Suite B enabled(2).
66

7+
Set OpenSSL FIPS mode. With OpenSSL before 3.0, the supported values are
8+
disabled(0), enabled(1) and Suite B enabled(2). With OpenSSL 3+, any value
9+
other than 0 will explicitly load the fips and base providers (_load_legacy_
10+
will be ignored). The latter still requires the config in fipsmodule.cnf
11+
(e.g. for the module's MAC), but allows explicitly loading the provider if
12+
it's not activated in that config.
13+
714
charon.plugins.openssl.load_legacy = yes
815
Load the legacy provider in OpenSSL 3+ for algorithms like MD4, DES, or
916
Blowfish (the first two are required for EAP-MSCHAPv2). If disabled, the
10-
default provider is loaded, or those configured in the OpenSSL config.
17+
default provider is loaded, or those configured in the OpenSSL config (e.g.
18+
the fips provider).

src/libstrongswan/plugins/openssl/openssl_plugin.c

+22-6
Original file line numberDiff line numberDiff line change
@@ -931,15 +931,16 @@ plugin_t *openssl_plugin_create()
931931
{
932932
if (FIPS_mode() != fips_mode && !FIPS_mode_set(fips_mode))
933933
{
934-
DBG1(DBG_LIB, "unable to set openssl FIPS mode(%d) from (%d)",
934+
DBG1(DBG_LIB, "unable to set OpenSSL FIPS mode(%d) from (%d)",
935935
fips_mode, FIPS_mode());
936936
return NULL;
937937
}
938938
}
939-
#else
939+
#elif OPENSSL_VERSION_NUMBER < 0x30000000L
940+
/* OpenSSL 3.0+ is handled below */
940941
if (fips_mode)
941942
{
942-
DBG1(DBG_LIB, "openssl FIPS mode(%d) unavailable", fips_mode);
943+
DBG1(DBG_LIB, "OpenSSL FIPS mode(%d) unavailable", fips_mode);
943944
return NULL;
944945
}
945946
#endif
@@ -973,8 +974,23 @@ plugin_t *openssl_plugin_create()
973974
#endif /* OPENSSL_VERSION_NUMBER */
974975

975976
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
976-
if (lib->settings->get_bool(lib->settings, "%s.plugins.openssl.load_legacy",
977-
TRUE, lib->ns))
977+
if (fips_mode)
978+
{
979+
OSSL_PROVIDER *fips;
980+
981+
fips = OSSL_PROVIDER_load(NULL, "fips");
982+
if (!fips)
983+
{
984+
DBG1(DBG_LIB, "unable to load OpenSSL FIPS provider");
985+
return NULL;
986+
}
987+
array_insert_create(&this->providers, ARRAY_TAIL, fips);
988+
/* explicitly load the base provider containing encoding functions */
989+
array_insert_create(&this->providers, ARRAY_TAIL,
990+
OSSL_PROVIDER_load(NULL, "base"));
991+
}
992+
else if (lib->settings->get_bool(lib->settings, "%s.plugins.openssl.load_legacy",
993+
TRUE, lib->ns))
978994
{
979995
/* load the legacy provider for algorithms like MD4, DES, BF etc. */
980996
array_insert_create(&this->providers, ARRAY_TAIL,
@@ -989,7 +1005,7 @@ plugin_t *openssl_plugin_create()
9891005
/* we do this here as it may have been enabled via openssl.conf */
9901006
fips_mode = FIPS_mode();
9911007
dbg(DBG_LIB, strpfx(lib->ns, "charon") ? 1 : 2,
992-
"openssl FIPS mode(%d) - %sabled ", fips_mode, fips_mode ? "en" : "dis");
1008+
"OpenSSL FIPS mode(%d) - %sabled ", fips_mode, fips_mode ? "en" : "dis");
9931009
#endif /* OPENSSL_FIPS */
9941010

9951011
#if OPENSSL_VERSION_NUMBER < 0x1010100fL

0 commit comments

Comments
 (0)