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

Introduce client_extra_certs option to SSLConfig #414

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 12 additions & 1 deletion lib/httpclient/ssl_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ def attr_config(symbol)
# OpenSSL::PKey::PKey:: private key pass phrase for client_key.
# nil by default. (no pass phrase)
attr_config :client_key_pass
# Array:: Extra certificates of OpenSSL::X509::Certificate to be presented
# along with the client certificate to the server.
# nil by default (no extra certificates)
attr_config :client_extra_certs

# A number which represents OpenSSL's verify mode. Default value is
# OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT.
Expand Down Expand Up @@ -147,7 +151,7 @@ def initialize(client)
@client = client
@cert_store = X509::Store.new
@cert_store_crl_items = []
@client_cert = @client_key = @client_key_pass = @client_ca = nil
@client_cert = @client_key = @client_key_pass = @client_ca = @client_extra_certs = nil
@verify_mode = SSL::VERIFY_PEER | SSL::VERIFY_FAIL_IF_NO_PEER_CERT
@verify_depth = nil
@verify_callback = nil
Expand Down Expand Up @@ -298,6 +302,13 @@ def set_context(ctx) # :nodoc:
ctx.key = @client_key.is_a?(PKey::PKey) ? @client_key :
PKey::RSA.new(File.open(@client_key) { |f| f.read }, @client_key_pass)
end
if @client_extra_certs
ctx.extra_chain_cert = Array(client_extra_certs).
map do |cert|
cert.is_a?(X509::Certificate) ? cert :
X509::Certificate.new(File.open(cert)) { |f| f.read }
end
end
ctx.client_ca = @client_ca
ctx.timeout = @timeout
ctx.options = @options
Expand Down