diff --git a/ChangeLog b/ChangeLog index 0ebd63ef37..ecec958b62 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sat May 7 22:22:37 2016 SHIBATA Hiroshi + + * lib/webrick/ssl.rb: Accept string value for SSLCertName. It is used + to invoke ssl server with command line. + [fix GH-1329] Patch by @kerlin + * test/webrick/test_ssl_server.rb: Added test for GH-1329 + Sat May 7 21:55:12 2016 SHIBATA Hiroshi * test/webrick/test_ssl_server.rb: Added basic test for `webrick/ssl` diff --git a/lib/webrick/ssl.rb b/lib/webrick/ssl.rb index b072546948..d626e149ec 100644 --- a/lib/webrick/ssl.rb +++ b/lib/webrick/ssl.rb @@ -108,7 +108,8 @@ module WEBrick cert = OpenSSL::X509::Certificate.new cert.version = 2 cert.serial = 1 - name = OpenSSL::X509::Name.new(cn) + name = (cn.kind_of? String) ? OpenSSL::X509::Name.parse(cn) + : OpenSSL::X509::Name.new(cn) cert.subject = name cert.issuer = name cert.not_before = Time.now diff --git a/test/webrick/test_ssl_server.rb b/test/webrick/test_ssl_server.rb index bbc30cf6d4..de685bb6d3 100644 --- a/test/webrick/test_ssl_server.rb +++ b/test/webrick/test_ssl_server.rb @@ -25,4 +25,18 @@ class TestWEBrickSSLServer < Test::Unit::TestCase sock.close } end + + def test_self_signed_cert_server_with_string + config = { + :SSLEnable => true, + :SSLCertName => "/C=JP/O=www.ruby-lang.org/CN=Ruby" + } + TestWEBrick.start_server(Echo, config){|server, addr, port, log| + sock = OpenSSL::SSL::SSLSocket.new(TCPSocket.new(addr, port)) + sock.connect + sock.puts(server.ssl_context.cert.subject.to_s) + assert_equal("/C=JP/O=www.ruby-lang.org/CN=Ruby\n", sock.gets, log.call) + sock.close + } + end end