From a6e805f75e308d2b29450b1eb5c0fe960aa412de Mon Sep 17 00:00:00 2001 From: hsbt Date: Sat, 7 May 2016 13:37:18 +0000 Subject: [PATCH] * 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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54941 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ lib/webrick/ssl.rb | 3 ++- test/webrick/test_ssl_server.rb | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) 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