diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-07-18 01:59:28 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-07-18 01:59:28 +0000 |
commit | a6c13d08d7d2035a22855c8f412694d13ba2faa0 (patch) | |
tree | a23aa08bf77dc5c81b79b99093883db7f5380fb2 /lib/webrick | |
parent | 23e9a4ec1691ef7d3054c9c39108acb5cca4bce9 (diff) | |
download | ruby-a6c13d08d7d2035a22855c8f412694d13ba2faa0.tar.gz |
webrick: fix SNI support
* lib/webrick/https.rb: check ssl context of virtual host.
* lib/webrick/ssl.rb: ensure to return ssl context.
* test/webrick/test_https.rb: test returned cert is correct.
[Feature #13729][ruby-dev:50173]
Author: Tietew <tietew@gmail.com>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59351 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/webrick')
-rw-r--r-- | lib/webrick/https.rb | 17 | ||||
-rw-r--r-- | lib/webrick/ssl.rb | 12 |
2 files changed, 24 insertions, 5 deletions
diff --git a/lib/webrick/https.rb b/lib/webrick/https.rb index 1494973e74..4826654d3a 100644 --- a/lib/webrick/https.rb +++ b/lib/webrick/https.rb @@ -131,5 +131,22 @@ module WEBrick server = lookup_server(req) server ? server.ssl_context : nil end + + # :stopdoc: + + ## + # Check whether +server+ is also SSL server. + # Also +server+'s SSL context will be created. + + alias orig_virtual_host virtual_host + + def virtual_host(server) + if @config[:SSLEnable] && !server.ssl_context + raise ArgumentError, "virtual host must set SSLEnable to true" + end + orig_virtual_host(server) + end + + # :startdoc: end end diff --git a/lib/webrick/ssl.rb b/lib/webrick/ssl.rb index a30cbc3699..8a334eaff1 100644 --- a/lib/webrick/ssl.rb +++ b/lib/webrick/ssl.rb @@ -147,7 +147,13 @@ module WEBrick # SSL context for the server when run in SSL mode def ssl_context # :nodoc: - @ssl_context ||= nil + @ssl_context ||= begin + if @config[:SSLEnable] + ssl_context = setup_ssl_context(@config) + @logger.info("\n" + @config[:SSLCertificate].to_text) + ssl_context + end + end end undef listen @@ -158,10 +164,6 @@ module WEBrick def listen(address, port) # :nodoc: listeners = Utils::create_listeners(address, port) if @config[:SSLEnable] - unless ssl_context - @ssl_context = setup_ssl_context(@config) - @logger.info("\n" + @config[:SSLCertificate].to_text) - end listeners.collect!{|svr| ssvr = ::OpenSSL::SSL::SSLServer.new(svr, ssl_context) ssvr.start_immediately = @config[:SSLStartImmediately] |