Skip to content

Commit 2958067

Browse files
committed
Add fips_mode_get to return fips_mode
1 parent c24bae3 commit 2958067

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

ext/openssl/ossl.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,23 @@ ossl_debug_set(VALUE self, VALUE val)
409409
return val;
410410
}
411411

412+
/*
413+
* call-seq
414+
* OpenSSL.fips_mode -> true | false
415+
*/
416+
static VALUE
417+
ossl_fips_mode_get(VALUE self)
418+
{
419+
420+
#ifdef OPENSSL_FIPS
421+
VALUE enabled;
422+
enabled = FIPS_mode() ? Qtrue : Qfalse;
423+
return enabled;
424+
#else
425+
return Qfalse;
426+
#endif
427+
}
428+
412429
/*
413430
* call-seq:
414431
* OpenSSL.fips_mode = boolean -> boolean
@@ -1139,7 +1156,7 @@ Init_openssl(void)
11391156
rb_define_const(mOSSL, "OPENSSL_VERSION_NUMBER", INT2NUM(OPENSSL_VERSION_NUMBER));
11401157

11411158
/*
1142-
* Boolean indicating whether OpenSSL is FIPS-enabled or not
1159+
* Boolean indicating whether OpenSSL is FIPS-capable or not
11431160
*/
11441161
rb_define_const(mOSSL, "OPENSSL_FIPS",
11451162
#ifdef OPENSSL_FIPS
@@ -1149,6 +1166,7 @@ Init_openssl(void)
11491166
#endif
11501167
);
11511168

1169+
rb_define_module_function(mOSSL, "fips_mode", ossl_fips_mode_get, 0);
11521170
rb_define_module_function(mOSSL, "fips_mode=", ossl_fips_mode_set, 1);
11531171

11541172
/*

test/test_fips.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,13 @@ def test_fips_mode_is_reentrant
88
OpenSSL.fips_mode = false
99
end
1010

11+
def test_fips_mode_get
12+
if OpenSSL::OPENSSL_FIPS
13+
OpenSSL.fips_mode = true
14+
assert OpenSSL.fips_mode == true, ".fips_mode returns true when .fips_mode=true"
15+
16+
OpenSSL.fips_mode = false
17+
assert OpenSSL.fips_mode == false, ".fips_mode returns false when .fips_mode=false"
18+
end
19+
end
1120
end

0 commit comments

Comments
 (0)