mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/openssl/ossl_ssl.c: Server Name Indication support.
new methods SSLContext#server_name_cb=, SSLSocket#hostname=. * test/openssl/test_ssl.rb: Tests for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21761 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b9170351da
commit
7361a2ecb3
4 changed files with 151 additions and 6 deletions
|
@ -570,6 +570,50 @@ class OpenSSL::TestSSL < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_tlsext_hostname
|
||||
return unless OpenSSL::SSL::SSLSocket.instance_methods.include?(:hostname)
|
||||
|
||||
ctx_proc = Proc.new do |ctx, ssl|
|
||||
foo_ctx = ctx.dup
|
||||
|
||||
ctx.servername_cb = Proc.new do |ssl, hostname|
|
||||
case hostname
|
||||
when 'foo.example.com'
|
||||
foo_ctx
|
||||
when 'bar.example.com'
|
||||
nil
|
||||
else
|
||||
raise "unknown hostname #{hostname.inspect}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
server_proc = Proc.new do |ctx, ssl|
|
||||
readwrite_loop(ctx, ssl)
|
||||
end
|
||||
|
||||
start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true, :ctx_proc => ctx_proc, :server_proc => server_proc) do |server, port|
|
||||
2.times do |i|
|
||||
sock = TCPSocket.new("127.0.0.1", port)
|
||||
ctx = OpenSSL::SSL::SSLContext.new
|
||||
if defined?(OpenSSL::SSL::OP_NO_TICKET)
|
||||
# disable RFC4507 support
|
||||
ctx.options = OpenSSL::SSL::OP_NO_TICKET
|
||||
end
|
||||
ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
|
||||
ssl.sync_close = true
|
||||
ssl.hostname = (i & 1 == 0) ? 'foo.example.com' : 'bar.example.com'
|
||||
ssl.connect
|
||||
|
||||
str = "x" * 100 + "\n"
|
||||
ssl.puts(str)
|
||||
assert_equal(str, ssl.gets)
|
||||
|
||||
ssl.close
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue