|
73 | 73 | # #verify_callback :: For server certificate verification
|
74 | 74 | # #verify_depth :: Depth of certificate verification
|
75 | 75 | # #verify_mode :: How connections should be verified
|
| 76 | +# #verify_hostname :: Use hostname verification for server certificate |
| 77 | +# during the handshake |
76 | 78 | #
|
77 | 79 | # == Proxies
|
78 | 80 | #
|
@@ -454,6 +456,21 @@ def self.detect_idle_timeout uri, max = 10
|
454 | 456 |
|
455 | 457 | attr_reader :verify_mode
|
456 | 458 |
|
| 459 | + ## |
| 460 | + # HTTPS verify_hostname. |
| 461 | + # |
| 462 | + # If a client sets this to true and enables SNI with SSLSocket#hostname=, |
| 463 | + # the hostname verification on the server certificate is performed |
| 464 | + # automatically during the handshake using |
| 465 | + # OpenSSL::SSL.verify_certificate_identity(). |
| 466 | + # |
| 467 | + # You can set +verify_hostname+ as true to use hostname verification |
| 468 | + # during the handshake. |
| 469 | + # |
| 470 | + # NOTE: This works with Ruby > 3.0. |
| 471 | + |
| 472 | + attr_reader :verify_hostname |
| 473 | + |
457 | 474 | ##
|
458 | 475 | # Creates a new Net::HTTP::Persistent.
|
459 | 476 | #
|
@@ -513,6 +530,7 @@ def initialize name: nil, proxy: nil, pool_size: DEFAULT_POOL_SIZE
|
513 | 530 | @verify_callback = nil
|
514 | 531 | @verify_depth = nil
|
515 | 532 | @verify_mode = nil
|
| 533 | + @verify_hostname = nil |
516 | 534 | @cert_store = nil
|
517 | 535 |
|
518 | 536 | @generation = 0 # incremented when proxy URI changes
|
@@ -980,8 +998,10 @@ def ssl connection
|
980 | 998 | connection.min_version = @min_version if @min_version
|
981 | 999 | connection.max_version = @max_version if @max_version
|
982 | 1000 |
|
983 |
| - connection.verify_depth = @verify_depth |
984 |
| - connection.verify_mode = @verify_mode |
| 1001 | + connection.verify_depth = @verify_depth |
| 1002 | + connection.verify_mode = @verify_mode |
| 1003 | + connection.verify_hostname = @verify_hostname if |
| 1004 | + @verify_hostname && connection.respond_to?(:verify_hostname=) |
985 | 1005 |
|
986 | 1006 | if OpenSSL::SSL::VERIFY_PEER == OpenSSL::SSL::VERIFY_NONE and
|
987 | 1007 | not Object.const_defined?(:I_KNOW_THAT_OPENSSL_VERIFY_PEER_EQUALS_VERIFY_NONE_IS_WRONG) then
|
@@ -1090,6 +1110,15 @@ def verify_mode= verify_mode
|
1090 | 1110 | reconnect_ssl
|
1091 | 1111 | end
|
1092 | 1112 |
|
| 1113 | + ## |
| 1114 | + # Sets the HTTPS verify_hostname. Defaults to false. |
| 1115 | + |
| 1116 | + def verify_hostname= verify_hostname |
| 1117 | + @verify_hostname = verify_hostname |
| 1118 | + |
| 1119 | + reconnect_ssl |
| 1120 | + end |
| 1121 | + |
1093 | 1122 | ##
|
1094 | 1123 | # SSL verification callback.
|
1095 | 1124 |
|
|
0 commit comments