aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-07-07 17:09:39 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-07-07 17:09:39 +0000
commit8e4ce1b3868bb45c26e758fccc7a710e21a6f9a0 (patch)
tree08d3fde5ac95f98c6caafcf4e6479b367eec72d3 /lib
parent2a8dacb7de0b301b00cde67b4ccf469d492bd67d (diff)
downloadruby-8e4ce1b3868bb45c26e758fccc7a710e21a6f9a0.tar.gz
webrick: add Server Name Indication (SNI)
* lib/webrick/https.rb: servername_cb implementation. * lib/webrick/ssl.rb: abstract servername_cb. * test/webrick/test_https.rb: test. [ruby-dev:50165] [Feature #13729] Author: Tietew <tietew@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59281 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/webrick/https.rb48
-rw-r--r--lib/webrick/ssl.rb11
2 files changed, 59 insertions, 0 deletions
diff --git a/lib/webrick/https.rb b/lib/webrick/https.rb
index 73875d7326..1494973e74 100644
--- a/lib/webrick/https.rb
+++ b/lib/webrick/https.rb
@@ -10,6 +10,7 @@
# $IPR: https.rb,v 1.15 2003/07/22 19:20:42 gotoyuzo Exp $
require 'webrick/ssl'
+require 'webrick/httpserver'
module WEBrick
module Config
@@ -84,4 +85,51 @@ module WEBrick
# :startdoc:
end
+
+ ##
+ #--
+ # Fake WEBrick::HTTPRequest for lookup_server
+
+ class SNIRequest
+
+ ##
+ # The SNI hostname
+
+ attr_reader :host
+
+ ##
+ # The socket address of the server
+
+ attr_reader :addr
+
+ ##
+ # The port this request is for
+
+ attr_reader :port
+
+ ##
+ # Creates a new SNIRequest.
+
+ def initialize(sslsocket, hostname)
+ @host = hostname
+ @addr = sslsocket.addr
+ @port = @addr[1]
+ end
+ end
+
+
+ ##
+ #--
+ # Adds SSL functionality to WEBrick::HTTPServer
+
+ class HTTPServer < ::WEBrick::GenericServer
+ ##
+ # ServerNameIndication callback
+
+ def ssl_servername_callback(sslsocket, hostname = nil)
+ req = SNIRequest.new(sslsocket, hostname)
+ server = lookup_server(req)
+ server ? server.ssl_context : nil
+ end
+ end
end
diff --git a/lib/webrick/ssl.rb b/lib/webrick/ssl.rb
index d626e149ec..a30cbc3699 100644
--- a/lib/webrick/ssl.rb
+++ b/lib/webrick/ssl.rb
@@ -48,6 +48,8 @@ module WEBrick
# Number of CA certificates to walk when verifying a certificate chain
# :SSLVerifyCallback ::
# Custom certificate verification callback
+ # :SSLServerNameCallback::
+ # Custom servername indication callback
# :SSLTimeout ::
# Maximum session lifetime
# :SSLOptions ::
@@ -193,10 +195,19 @@ module WEBrick
ctx.verify_mode = config[:SSLVerifyClient]
ctx.verify_depth = config[:SSLVerifyDepth]
ctx.verify_callback = config[:SSLVerifyCallback]
+ ctx.servername_cb = config[:SSLServerNameCallback] || proc { |args| ssl_servername_callback(*args) }
ctx.timeout = config[:SSLTimeout]
ctx.options = config[:SSLOptions]
ctx.ciphers = config[:SSLCiphers]
ctx
end
+
+ ##
+ # ServerNameIndication callback
+
+ def ssl_servername_callback(sslsocket, hostname = nil)
+ # default
+ end
+
end
end