mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
4d3d6f6898
commit
08bdbef5ca
3 changed files with 143 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue