[前][次][番号順一覧][スレッド一覧]

ruby-changes:33782

From: akr <ko1@a...>
Date: Wed, 7 May 2014 21:48:36 +0900 (JST)
Subject: [ruby-changes:33782] akr:r45863 (trunk): * ext/openssl/lib/openssl/ssl.rb (OpenSSL::SSL::SSLServer#accept):

akr	2014-05-07 21:48:27 +0900 (Wed, 07 May 2014)

  New Revision: 45863

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45863

  Log:
    * ext/openssl/lib/openssl/ssl.rb (OpenSSL::SSL::SSLServer#accept):
      Consider Socket#accept as well as TCPServer#accept.
      Reported by Sam Stelfox.  [ruby-core:62064] [Bug #9750]

  Modified files:
    trunk/ChangeLog
    trunk/ext/openssl/lib/openssl/ssl.rb
    trunk/test/openssl/test_pair.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45862)
+++ ChangeLog	(revision 45863)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed May  7 21:45:00 2014  Tanaka Akira  <akr@f...>
+
+	* ext/openssl/lib/openssl/ssl.rb (OpenSSL::SSL::SSLServer#accept):
+	  Consider Socket#accept as well as TCPServer#accept.
+	  Reported by Sam Stelfox.  [ruby-core:62064] [Bug #9750]
+
 Wed May  7 17:24:07 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* numeric.c (num_step_scan_args): check keyword arguments and fail
Index: ext/openssl/lib/openssl/ssl.rb
===================================================================
--- ext/openssl/lib/openssl/ssl.rb	(revision 45862)
+++ ext/openssl/lib/openssl/ssl.rb	(revision 45863)
@@ -225,7 +225,10 @@ module OpenSSL https://github.com/ruby/ruby/blob/trunk/ext/openssl/lib/openssl/ssl.rb#L225
 
       # Works similar to TCPServer#accept.
       def accept
-        sock = @svr.accept
+        # Socket#accept returns [socket, addrinfo].
+        # TCPServer#accept returns a socket.
+        # The following comma strips addrinfo.
+        sock, = @svr.accept
         begin
           ssl = OpenSSL::SSL::SSLSocket.new(sock, @ctx)
           ssl.sync_close = true
Index: test/openssl/test_pair.rb
===================================================================
--- test/openssl/test_pair.rb	(revision 45862)
+++ test/openssl/test_pair.rb	(revision 45863)
@@ -56,6 +56,64 @@ module SSLPair https://github.com/ruby/ruby/blob/trunk/test/openssl/test_pair.rb#L56
   end
 end
 
+module SSLPairLowlevelSocket
+  def server
+    host = "127.0.0.1"
+    port = 0
+    ctx = OpenSSL::SSL::SSLContext.new()
+    ctx.ciphers = "ADH"
+    ctx.tmp_dh_callback = proc { OpenSSL::TestUtils::TEST_KEY_DH1024 }
+    tcps = Addrinfo.tcp(host, port).listen
+    ssls = OpenSSL::SSL::SSLServer.new(tcps, ctx)
+    return ssls
+  end
+
+  def client(port)
+    host = "127.0.0.1"
+    ctx = OpenSSL::SSL::SSLContext.new()
+    ctx.ciphers = "ADH"
+    s = Addrinfo.tcp(host, port).connect
+    ssl = OpenSSL::SSL::SSLSocket.new(s, ctx)
+    ssl.connect
+    ssl.sync_close = true
+    ssl
+  end
+
+  def ssl_pair
+    ssls = server
+    ths = Thread.new {
+      ns = ssls.accept
+      ssls.close
+      ns
+    }
+    port = ssls.to_io.connect_address.ip_port
+    thc = Thread.new {
+      client(port)
+    }
+    s = ths.value
+    c = thc.value
+    if block_given?
+      begin
+        yield c, s
+      ensure
+        c.close unless c.closed?
+        s.close unless s.closed?
+      end
+    else
+      return c, s
+    end
+  ensure
+    if ths && ths.alive?
+      ths.kill
+      ths.join
+    end
+    if thc && thc.alive?
+      thc.kill
+      thc.join
+    end
+  end
+end
+
 class OpenSSL::TestEOF1 < Test::Unit::TestCase
   include TestEOF
   include SSLPair
@@ -309,4 +367,15 @@ class OpenSSL::TestPair < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/openssl/test_pair.rb#L367
 
 end
 
+class OpenSSL::TestPairLowlevelSocket < Test::Unit::TestCase
+  include SSLPairLowlevelSocket
+
+  def test_getc
+    ssl_pair {|s1, s2|
+      s1 << "a"
+      assert_equal(?a, s2.getc)
+    }
+  end
+end
+
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]