Skip to content

Commit 8435d9f

Browse files
committed
Support extra_chain_cert= setting
Reference: https://bugs.ruby-lang.org/issues/9758
1 parent 12a9230 commit 8435d9f

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

lib/net/http/persistent.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
# #ca_path :: Directory with certificate-authorities
6666
# #cert_store :: An SSL certificate store
6767
# #ciphers :: List of SSl ciphers allowed
68+
# #extra_chain_cert :: Extra certificates to be added to the certificate chain
6869
# #private_key :: The client's SSL private key
6970
# #reuse_ssl_sessions :: Reuse a previously opened SSL session for a new
7071
# connection
@@ -270,6 +271,11 @@ def self.detect_idle_timeout uri, max = 10
270271

271272
attr_reader :ciphers
272273

274+
##
275+
# Extra certificates to be added to the certificate chain
276+
277+
attr_reader :extra_chain_cert
278+
273279
##
274280
# Sends debug_output to this IO via Net::HTTP#set_debug_output.
275281
#
@@ -574,6 +580,21 @@ def ciphers= ciphers
574580
reconnect_ssl
575581
end
576582

583+
if Net::HTTP.method_defined?(:extra_chain_cert=)
584+
##
585+
# Extra certificates to be added to the certificate chain.
586+
# It is only supported starting from Net::HTTP version 0.1.1
587+
def extra_chain_cert= extra_chain_cert
588+
@extra_chain_cert = extra_chain_cert
589+
590+
reconnect_ssl
591+
end
592+
else
593+
def extra_chain_cert= _extra_chain_cert
594+
raise "extra_chain_cert= is not supported by this version of Net::HTTP"
595+
end
596+
end
597+
577598
##
578599
# Creates a new connection for +uri+
579600

@@ -1023,6 +1044,10 @@ def ssl connection
10231044
connection.key = @private_key
10241045
end
10251046

1047+
if defined?(@extra_chain_cert) and @extra_chain_cert
1048+
connection.extra_chain_cert = @extra_chain_cert
1049+
end
1050+
10261051
connection.cert_store = if @cert_store then
10271052
@cert_store
10281053
else

test/test_net_http_persistent.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,14 @@ def test_ciphers_equals
247247
assert_equal 1, @http.ssl_generation
248248
end
249249

250+
def test_extra_chain_cert_equals
251+
skip 'extra_chain_cert is not supported by Net::HTTP' unless Net::HTTP.method_defined?(:extra_chain_cert)
252+
@http.extra_chain_cert = :extra_chain_cert
253+
254+
assert_equal :extra_chain_cert, @http.extra_chain_cert
255+
assert_equal 1, @http.ssl_generation
256+
end
257+
250258
def test_connection_for
251259
@http.open_timeout = 123
252260
@http.read_timeout = 321
@@ -1342,6 +1350,19 @@ def test_ssl_verify_mode
13421350
assert_equal OpenSSL::SSL::VERIFY_NONE, c.verify_mode
13431351
end
13441352

1353+
def test_ssl_extra_chain_cert
1354+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
1355+
skip 'extra_chain_cert is not supported by Net::HTTP' unless Net::HTTP.method_defined?(:extra_chain_cert)
1356+
1357+
@http.extra_chain_cert = :extra_chain_cert
1358+
c = Net::HTTP.new 'localhost', 80
1359+
1360+
@http.ssl c
1361+
1362+
assert c.use_ssl?
1363+
assert_equal :extra_chain_cert, c.extra_chain_cert
1364+
end
1365+
13451366
def test_ssl_warning
13461367
skip 'OpenSSL is missing' unless HAVE_OPENSSL
13471368

0 commit comments

Comments
 (0)