From: tadanori kojima Date: 2011-08-11T12:19:40+09:00 Subject: [ruby-dev:44377] Re: [Ruby 1.9 - Feature #5180] net/http の接続時に用いる IP アドレスの指定 On Wed, 10 Aug 2011 18:33:08 +0900 "NARUSE, Yui" wrote: > 2011年8月10日18:21 tadanori kojima : > > > > load balancer利用時のreal IPへの接続などのユースケースは理解できますが > > ----- > > Net::HTTP.start("127.0.0.1") {|h| > > print h.request_get( '/index.html' , {"host"=>"ruby-lang.org"}).body > > } > > > > ※startはIP指定、リクエスト時のhostヘッダにホスト名 > > ----- > > > > というのがHTTP的なふつうの対処な気がします > > 基本的な HTTP に対する理屈としては同意するところなんですが、 > https だと connection 張る時点でホスト名が必要なため、それだとまずいんです。 意味がわかりました でもsslってcommon nameの検証までやってたっけ? と、net/http.rbのソースをみるとconnect内に −・−・−・−・−・− s.connect if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE s.post_connection_check(@address) end −・−・−・−・−・− とあるので、1.8.5だと(手元のマシンがcent5なので。。。) −・−・−・−・−・− diff -u net/http.rb.orig net/http.rb --- net/http.rb.orig 2011-08-11 11:09:21.000000000 +0900 +++ net/http.rb 2011-08-11 11:39:08.000000000 +0900 @@ -470,6 +470,7 @@ @debug_output = nil @use_ssl = false @ssl_context = nil + @common_name = nil end def inspect @@ -526,6 +527,8 @@ false # redefined in net/https end + attr_accessor :common_name + # Opens TCP connection and HTTP session. # # When this method is called with block, gives a HTTP object @@ -585,7 +588,7 @@ end s.connect if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE - s.post_connection_check(@address) + s.post_connection_check( @common_name || @address) end end on_connect −・−・−・−・−・− で、 −・−・−・−・−・− require 'net/http' addrs = %w/192.168.0.1 192.168.0.2 192.168.0.3/ addrs.each do |addr| Net::HTTP.start(addr, use_ssl: true, common_name: 'example.org'){|h| p h.get('/')} end −・−・−・−・−・− とcommon nameを指定するほうが好みです:-) おおもとの問題は  接続サーバの指定(IP/Hostname)、  HTTPのHostヘッダ(IP/Hostname、VirtualHostなどで利用)  SSLのCN検証(IP/Hostnameとは別にCNAMEもあり得る) と、レイヤを意識したパケットの組み立て方が必要なことでしょうか すっきりした解決方法は浮かばないですね。。。 > > ホストがv4/v6の両アドレスを持つ場合などにv4で接続したい、 > > となるときも同じような感じでしょうか > > そうですね。 > > -- > NARUSE, Yui -- End of mail