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
7374# #verify_callback :: For server certificate verification
7475# #verify_depth :: Depth of certificate verification
7576# #verify_mode :: How connections should be verified
77+ # #verify_hostname :: Use hostname verification for server certificate
78+ # during the handshake
7679#
7780# == Proxies
7881#
@@ -179,7 +182,7 @@ class Net::HTTP::Persistent
179182 ##
180183 # The version of Net::HTTP::Persistent you are using
181184
182- VERSION = '4.0.1 '
185+ VERSION = '4.0.5 '
183186
184187 ##
185188 # Error class for errors raised by Net::HTTP::Persistent. Various
@@ -270,6 +273,11 @@ def self.detect_idle_timeout uri, max = 10
270273
271274 attr_reader :ciphers
272275
276+ ##
277+ # Extra certificates to be added to the certificate chain
278+
279+ attr_reader :extra_chain_cert
280+
273281 ##
274282 # Sends debug_output to this IO via Net::HTTP#set_debug_output.
275283 #
@@ -454,6 +462,21 @@ def self.detect_idle_timeout uri, max = 10
454462
455463 attr_reader :verify_mode
456464
465+ ##
466+ # HTTPS verify_hostname.
467+ #
468+ # If a client sets this to true and enables SNI with SSLSocket#hostname=,
469+ # the hostname verification on the server certificate is performed
470+ # automatically during the handshake using
471+ # OpenSSL::SSL.verify_certificate_identity().
472+ #
473+ # You can set +verify_hostname+ as true to use hostname verification
474+ # during the handshake.
475+ #
476+ # NOTE: This works with Ruby > 3.0.
477+
478+ attr_reader :verify_hostname
479+
457480 ##
458481 # Creates a new Net::HTTP::Persistent.
459482 #
@@ -513,6 +536,7 @@ def initialize name: nil, proxy: nil, pool_size: DEFAULT_POOL_SIZE
513536 @verify_callback = nil
514537 @verify_depth = nil
515538 @verify_mode = nil
539+ @verify_hostname = nil
516540 @cert_store = nil
517541
518542 @generation = 0 # incremented when proxy URI changes
@@ -574,6 +598,21 @@ def ciphers= ciphers
574598 reconnect_ssl
575599 end
576600
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+
577616 ##
578617 # Creates a new connection for +uri+
579618
@@ -612,13 +651,23 @@ def connection_for uri
612651
613652 return yield connection
614653 rescue Errno ::ECONNREFUSED
615- address = http . proxy_address || http . address
616- port = http . proxy_port || http . port
654+ if http . proxy?
655+ address = http . proxy_address
656+ port = http . proxy_port
657+ else
658+ address = http . address
659+ port = http . port
660+ end
617661
618662 raise Error , "connection refused: #{ address } :#{ port } "
619663 rescue Errno ::EHOSTDOWN
620- address = http . proxy_address || http . address
621- port = http . proxy_port || http . port
664+ if http . proxy?
665+ address = http . proxy_address
666+ port = http . proxy_port
667+ else
668+ address = http . address
669+ port = http . port
670+ end
622671
623672 raise Error , "host down: #{ address } :#{ port } "
624673 ensure
@@ -982,8 +1031,10 @@ def ssl connection
9821031 connection . min_version = @min_version if @min_version
9831032 connection . max_version = @max_version if @max_version
9841033
985- connection . verify_depth = @verify_depth
986- connection . verify_mode = @verify_mode
1034+ connection . verify_depth = @verify_depth
1035+ connection . verify_mode = @verify_mode
1036+ connection . verify_hostname = @verify_hostname if
1037+ @verify_hostname != nil && connection . respond_to? ( :verify_hostname= )
9871038
9881039 if OpenSSL ::SSL ::VERIFY_PEER == OpenSSL ::SSL ::VERIFY_NONE and
9891040 not Object . const_defined? ( :I_KNOW_THAT_OPENSSL_VERIFY_PEER_EQUALS_VERIFY_NONE_IS_WRONG ) then
@@ -1025,6 +1076,10 @@ def ssl connection
10251076 connection . key = @private_key
10261077 end
10271078
1079+ if defined? ( @extra_chain_cert ) and @extra_chain_cert
1080+ connection . extra_chain_cert = @extra_chain_cert
1081+ end
1082+
10281083 connection . cert_store = if @cert_store then
10291084 @cert_store
10301085 else
@@ -1092,6 +1147,15 @@ def verify_mode= verify_mode
10921147 reconnect_ssl
10931148 end
10941149
1150+ ##
1151+ # Sets the HTTPS verify_hostname.
1152+
1153+ def verify_hostname = verify_hostname
1154+ @verify_hostname = verify_hostname
1155+
1156+ reconnect_ssl
1157+ end
1158+
10951159 ##
10961160 # SSL verification callback.
10971161
@@ -1104,4 +1168,3 @@ def verify_callback= callback
11041168
11051169require_relative 'persistent/connection'
11061170require_relative 'persistent/pool'
1107-
0 commit comments