Skip to content

Commit 9acb9b5

Browse files
committed
Fix the fips_mode_get on OpenSSL 3.
This commit only fixes the issue that the `OpenSSL.fips_mode` returns `false` on OpenSSL 3 FIPS mode enabled environment, while other tests fail on the environment. I believe that this minimal fix is a good start to make Ruby OpenSSL work on the OpenSSL 3 FIPS mode enabled environment with the CI case. It seems that the `OPENSSL_FIPS` macro is not used on the FIPS mode case any more on OpenSSL 3. The API `FIPS_mode` also was removed in OpenSSL 3. See the document <https://github.com/openssl/openssl/blob/master/doc/man7/migration_guide.pod#removed-fips_mode-and-fips_mode_set> the section OPENSSL 3.0 > Main Changes from OpenSSL 1.1.1 > Other notable deprecations and changes - Removed FIPS_mode() and FIPS_mode_set() . The `TEST_RUBY_OPENSSL_FIPS_ENABLED` is set on the FIPS mode case on the CI. Because I want to test that the `OpenSSL.fips_mode` returning the `true` or 'false' in the CI. Right now we don't find a reliable way to get the capability of OpenSSL 3 for the FIPS mode.
1 parent f4c0fc2 commit 9acb9b5

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

ext/openssl/ossl.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,11 @@ static VALUE
418418
ossl_fips_mode_get(VALUE self)
419419
{
420420

421-
#ifdef OPENSSL_FIPS
421+
#if OSSL_OPENSSL_PREREQ(3, 0, 0)
422+
VALUE enabled;
423+
enabled = EVP_default_properties_is_fips_enabled(NULL) ? Qtrue : Qfalse;
424+
return enabled;
425+
#elif OPENSSL_FIPS
422426
VALUE enabled;
423427
enabled = FIPS_mode() ? Qtrue : Qfalse;
424428
return enabled;

test/openssl/test_fips.rb

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,37 @@
44
if defined?(OpenSSL)
55

66
class OpenSSL::TestFIPS < OpenSSL::TestCase
7+
def test_fips_mode_get_is_true_on_fips_mode_enabled
8+
unless ENV["CI"] && ENV["TEST_RUBY_OPENSSL_FIPS_ENABLED"]
9+
omit "Only for on FIPS mode environment on CI"
10+
end
11+
12+
assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;")
13+
assert OpenSSL.fips_mode == true, ".fips_mode returns true on FIPS mode enabled"
14+
end;
15+
end
16+
17+
def test_fips_mode_get_is_false_on_fips_mode_disabled
18+
unless ENV["CI"] && !ENV["TEST_RUBY_OPENSSL_FIPS_ENABLED"]
19+
omit "Only for non-FIPS mode environment on CI"
20+
end
21+
22+
assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;")
23+
assert OpenSSL.fips_mode == false, ".fips_mode returns false on FIPS mode disabled"
24+
end;
25+
end
26+
727
def test_fips_mode_is_reentrant
828
OpenSSL.fips_mode = false
929
OpenSSL.fips_mode = false
1030
end
1131

12-
def test_fips_mode_get
32+
def test_fips_mode_get_with_fips_mode_set
33+
if openssl?(3, 0, 0)
34+
pend('OpenSSL::OPENSSL_FIPS and fips_mode_set are not properly ' \
35+
'implemented in OpenSSL 3')
36+
end
37+
1338
return unless OpenSSL::OPENSSL_FIPS
1439
assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;")
1540
begin

0 commit comments

Comments
 (0)