Skip to content

Commit df3d0c4

Browse files
authored
Ensure FIPS compliant mode by ensure_fips option (#4720)
ensure_fips option checks whether FIPS mode is enabled by OpenSSL side. If FIPS is not enabled in OpenSSL side, it raise an error when ensure_fips true. NOTE: If FIPS mode is enabled, ensure_fips does nothing. Closes: #3121 Signed-off-by: Kentaro Hayashi <hayashi@clear-code.com>
1 parent d102527 commit df3d0c4

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

lib/fluent/plugin_helper/cert_option.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ def cert_option_create_context(version, insecure, ciphers, conf)
3737
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
3838
end
3939

40+
if conf.ensure_fips
41+
unless OpenSSL.fips_mode
42+
raise Fluent::ConfigError, "Cannot enable FIPS compliant mode. OpenSSL FIPS configuration is disabled"
43+
end
44+
end
45+
4046
ctx.ca_file = conf.ca_path
4147
ctx.cert = cert
4248
ctx.key = key

lib/fluent/plugin_helper/server.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ def server_create_for_tls_connection(shared, bind, port, conf, backlog, socket_o
251251
:generate_cert_country, :generate_cert_state, :generate_cert_state,
252252
:generate_cert_locality, :generate_cert_common_name,
253253
:generate_cert_expiration, :generate_cert_digest,
254+
:ensure_fips,
254255
]
255256

256257
def server_create_transport_section_object(opts)
@@ -294,6 +295,7 @@ module ServerTransportParams
294295
config_param :max_version, :enum, list: Fluent::TLS::SUPPORTED_VERSIONS, default: nil
295296
config_param :ciphers, :string, default: Fluent::TLS::CIPHERS_DEFAULT
296297
config_param :insecure, :bool, default: false
298+
config_param :ensure_fips, :bool, default: false
297299

298300
# Cert signed by public CA
299301
config_param :ca_path, :string, default: nil

test/plugin_helper/test_cert_option.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
require_relative '../helper'
2+
require 'fluent/plugin_helper/server'
23
require 'fluent/plugin_helper/cert_option'
34

45
class CertOptionPluginHelperTest < Test::Unit::TestCase
56
class Dummy < Fluent::Plugin::TestBase
67
helpers :cert_option
78
end
89

10+
class DummyServer < Fluent::Plugin::TestBase
11+
helpers :server
12+
end
13+
914
test 'can load PEM encoded certificate file' do
1015
d = Dummy.new
1116
certs = d.cert_option_certificates_from_file("test/plugin_helper/data/cert/cert.pem")
@@ -22,4 +27,42 @@ class Dummy < Fluent::Plugin::TestBase
2227
d.cert_option_certificates_from_file("test/plugin_helper/data/cert/empty.pem")
2328
end
2429
end
30+
31+
sub_test_case "ensure OpenSSL FIPS mode" do
32+
setup do
33+
cert_dir = File.expand_path(File.join(File.dirname(__FILE__), "../plugin_helper/data/cert/"))
34+
@tls_options = {
35+
cert_path: File.join(cert_dir, "cert.pem"),
36+
private_key_path: File.join(cert_dir, "cert-key.pem"),
37+
}
38+
@d = DummyServer.new
39+
end
40+
41+
data(
42+
enabled_fips_mode: [true, true, nil],
43+
skip_checking_fips_mode: [true, false, nil],
44+
block_incompatible_fips_mode: [false, true,
45+
Fluent::ConfigError.new("Cannot enable FIPS compliant mode. OpenSSL FIPS configuration is disabled")],
46+
not_care_fips_mode: [false, false, nil]
47+
)
48+
test 'ensure FIPS error' do |(fips_mode, ensure_fips, expected)|
49+
stub(OpenSSL).fips_mode { fips_mode }
50+
conf = @d.server_create_transport_section_object(@tls_options.merge({ensure_fips: ensure_fips}))
51+
if expected
52+
assert_raise(expected) do
53+
@d.cert_option_create_context(Fluent::TLS::DEFAULT_VERSION,
54+
false,
55+
Fluent::TLS::CIPHERS_DEFAULT,
56+
conf)
57+
end
58+
else
59+
assert_nothing_raised do
60+
@d.cert_option_create_context(Fluent::TLS::DEFAULT_VERSION,
61+
false,
62+
Fluent::TLS::CIPHERS_DEFAULT,
63+
conf)
64+
end
65+
end
66+
end
67+
end
2568
end

0 commit comments

Comments
 (0)