Skip to content

Commit 8fb912f

Browse files
authored
Merge pull request #147 from marshall-lee/extra_chain_cert
Support extra_chain_cert= setting
2 parents 409b0c7 + 455426e commit 8fb912f

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-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
@@ -272,6 +273,11 @@ def self.detect_idle_timeout uri, max = 10
272273

273274
attr_reader :ciphers
274275

276+
##
277+
# Extra certificates to be added to the certificate chain
278+
279+
attr_reader :extra_chain_cert
280+
275281
##
276282
# Sends debug_output to this IO via Net::HTTP#set_debug_output.
277283
#
@@ -592,6 +598,21 @@ def ciphers= ciphers
592598
reconnect_ssl
593599
end
594600

601+
if Net::HTTP.method_defined?(:extra_chain_cert=)
602+
##
603+
# Extra certificates to be added to the certificate chain.
604+
# It is only supported starting from Net::HTTP version 0.1.1
605+
def extra_chain_cert= extra_chain_cert
606+
@extra_chain_cert = extra_chain_cert
607+
608+
reconnect_ssl
609+
end
610+
else
611+
def extra_chain_cert= _extra_chain_cert
612+
raise "extra_chain_cert= is not supported by this version of Net::HTTP"
613+
end
614+
end
615+
595616
##
596617
# Creates a new connection for +uri+
597618

@@ -1043,6 +1064,10 @@ def ssl connection
10431064
connection.key = @private_key
10441065
end
10451066

1067+
if defined?(@extra_chain_cert) and @extra_chain_cert
1068+
connection.extra_chain_cert = @extra_chain_cert
1069+
end
1070+
10461071
connection.cert_store = if @cert_store then
10471072
@cert_store
10481073
else

test/test_net_http_persistent.rb

Lines changed: 20 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
@@ -1373,6 +1381,18 @@ def test_ssl_disable_verify_hostname
13731381
assert c.verify_hostname == false
13741382
end
13751383

1384+
def test_ssl_extra_chain_cert
1385+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
1386+
skip 'extra_chain_cert is not supported by Net::HTTP' unless Net::HTTP.method_defined?(:extra_chain_cert)
1387+
1388+
@http.extra_chain_cert = :extra_chain_cert
1389+
c = Net::HTTP.new 'localhost', 80
1390+
1391+
@http.ssl c
1392+
1393+
assert c.use_ssl?
1394+
assert_equal :extra_chain_cert, c.extra_chain_cert
1395+
end
13761396

13771397
def test_ssl_warning
13781398
skip 'OpenSSL is missing' unless HAVE_OPENSSL

0 commit comments

Comments
 (0)