Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ssl_ca_cert_file_path support an array of files #905

Merged
merged 1 commit into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/kafka/client.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# coding: utf-8
# frozen_string_literal: true

require "kafka/ssl_context"
Expand Down Expand Up @@ -38,8 +39,8 @@ class Client
# @param ssl_ca_cert [String, Array<String>, nil] a PEM encoded CA cert, or an Array of
# PEM encoded CA certs, to use with an SSL connection.
#
# @param ssl_ca_cert_file_path [String, nil] a path on the filesystem to a PEM encoded CA cert
# to use with an SSL connection.
# @param ssl_ca_cert_file_path [String, Array<String>, nil] a path on the filesystem, or an
# Array of paths, to PEM encoded CA cert(s) to use with an SSL connection.
#
# @param ssl_client_cert [String, nil] a PEM encoded client cert to use with an
# SSL connection. Must be used in combination with ssl_client_cert_key.
Expand Down
4 changes: 2 additions & 2 deletions lib/kafka/ssl_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def self.build(ca_cert_file_path: nil, ca_cert: nil, client_cert: nil, client_ce
Array(ca_cert).each do |cert|
store.add_cert(OpenSSL::X509::Certificate.new(cert))
end
if ca_cert_file_path
store.add_file(ca_cert_file_path)
Array(ca_cert_file_path).each do |cert_file_path|
store.add_file(cert_file_path)
end
if ca_certs_from_system
store.set_default_paths
Expand Down
6 changes: 6 additions & 0 deletions spec/ssl_context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
}.to raise_exception(ArgumentError)
end

it "raises an OpenSSL::X509::StoreError if an array of non-existing files is passed for ca_cert_file_path" do
expect {
Kafka::SslContext.build(ca_cert_file_path: ["no_such_file", "no_such_file_either"])
}.to raise_exception(OpenSSL::X509::StoreError)
end

context "with self signed cert fixtures" do
# How the certificates were generated, they are not actually in a chain
# openssl req -newkey rsa:2048 -nodes -keyout spec/fixtures/client_cert_key.pem -x509 -days 365 -out spec/fixtures/client_cert.pem
Expand Down