Skip to content

Commit d9e59fb

Browse files
committed
Introduce client_extra_certs option to SSLConfig
Some websites relying on client certificate authentication reject requests with proper client certificate unless authority chain is presented with the certificate as well. New `client_extra_certs` tunable allows adding CA certificates to the `extra_chain_cert` option of SSL connection context, thus providing a way of supplying the authority chain together with request.
1 parent 4d60d8b commit d9e59fb

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/httpclient/ssl_config.rb

+12-1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ def attr_config(symbol)
104104
# OpenSSL::PKey::PKey:: private key pass phrase for client_key.
105105
# nil by default. (no pass phrase)
106106
attr_config :client_key_pass
107+
# Array:: Extra certificates of OpenSSL::X509::Certificate to be presented
108+
# along with the client certificate to the server.
109+
# nil by default (no extra certificates)
110+
attr_config :client_extra_certs
107111

108112
# A number which represents OpenSSL's verify mode. Default value is
109113
# OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT.
@@ -147,7 +151,7 @@ def initialize(client)
147151
@client = client
148152
@cert_store = X509::Store.new
149153
@cert_store_crl_items = []
150-
@client_cert = @client_key = @client_key_pass = @client_ca = nil
154+
@client_cert = @client_key = @client_key_pass = @client_ca = @client_extra_certs = @nil
151155
@verify_mode = SSL::VERIFY_PEER | SSL::VERIFY_FAIL_IF_NO_PEER_CERT
152156
@verify_depth = nil
153157
@verify_callback = nil
@@ -298,6 +302,13 @@ def set_context(ctx) # :nodoc:
298302
ctx.key = @client_key.is_a?(PKey::PKey) ? @client_key :
299303
PKey::RSA.new(File.open(@client_key) { |f| f.read }, @client_key_pass)
300304
end
305+
if @client_extra_certs
306+
ctx.extra_chain_cert = Array(client_extra_certs).
307+
map do |cert|
308+
cert.is_a?(X509::Certificate) ? cert :
309+
X509::Certificate.new(File.open(cert)) { |f| f.read }
310+
end
311+
end
301312
ctx.client_ca = @client_ca
302313
ctx.timeout = @timeout
303314
ctx.options = @options

0 commit comments

Comments
 (0)