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

ruby-changes:20152

From: nahi <ko1@a...>
Date: Wed, 22 Jun 2011 18:24:45 +0900 (JST)
Subject: [ruby-changes:20152] nahi:r32200 (trunk): * ext/openssl/ossl_ssl.c (ossl_sslctx_session_remove_cb):

nahi	2011-06-22 18:24:31 +0900 (Wed, 22 Jun 2011)

  New Revision: 32200

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

  Log:
    * ext/openssl/ossl_ssl.c (ossl_sslctx_session_remove_cb):
      OpenSSL::SSL::SSLContext#session_remove_cb was broken. It wrongly 
      tried to call the session_*new*_cb callback.
    
    * test/openssl/test_ssl_session.rb (class OpenSSL): Test it.

  Modified files:
    trunk/ChangeLog
    trunk/ext/openssl/ossl_ssl.c
    trunk/test/openssl/test_ssl_session.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 32199)
+++ ChangeLog	(revision 32200)
@@ -1,3 +1,11 @@
+Wed Jun 22 18:20:46 2011  Hiroshi Nakamura  <nahi@r...>
+
+	* ext/openssl/ossl_ssl.c (ossl_sslctx_session_remove_cb):
+	  OpenSSL::SSL::SSLContext#session_remove_cb was broken. It wrongly
+	  tried to call the session_*new*_cb callback.
+
+	* test/openssl/test_ssl_session.rb (class OpenSSL): Test it.
+
 Wed Jun 22 17:37:49 2011  Martin Bosslet  <Martin.Bosslet@g...>
 
 	* ext/openssl/ossl.h: Introduced OSSL_BIO_reset macro for PEM/DER
Index: ext/openssl/ossl_ssl.c
===================================================================
--- ext/openssl/ossl_ssl.c	(revision 32199)
+++ ext/openssl/ossl_ssl.c	(revision 32200)
@@ -406,7 +406,6 @@
     return RTEST(ret_obj) ? 1 : 0;
 }
 
-#if 0				/* unused */
 static VALUE
 ossl_call_session_remove_cb(VALUE ary)
 {
@@ -420,7 +419,6 @@
 
     return rb_funcall(cb, rb_intern("call"), 1, ary);
 }
-#endif
 
 static void
 ossl_sslctx_session_remove_cb(SSL_CTX *ctx, SSL_SESSION *sess)
@@ -442,7 +440,7 @@
     rb_ary_push(ary, sslctx_obj);
     rb_ary_push(ary, sess_obj);
 
-    ret_obj = rb_protect((VALUE(*)_((VALUE)))ossl_call_session_new_cb, ary, &state);
+    ret_obj = rb_protect((VALUE(*)_((VALUE)))ossl_call_session_remove_cb, ary, &state);
     if (state) {
 /*
   the SSL_CTX is frozen, nowhere to save state.
Index: test/openssl/test_ssl_session.rb
===================================================================
--- test/openssl/test_ssl_session.rb	(revision 32199)
+++ test/openssl/test_ssl_session.rb	(revision 32200)
@@ -28,6 +28,7 @@
       assert_match(/-----END SSL SESSION PARAMETERS-----\Z/, pem)
       pem.gsub!(/-----(BEGIN|END) SSL SESSION PARAMETERS-----/, '').gsub!(/[\r\n]+/m, '')
       assert_equal(session.to_der, pem.unpack('m*')[0])
+      assert_not_nil(session.to_text)
       ssl.close
     end
   end
@@ -153,6 +154,35 @@
       end
     end
   end
+
+  def test_ctx_client_session_cb
+    called = {}
+    ctx = OpenSSL::SSL::SSLContext.new("SSLv3")
+    ctx.session_cache_mode = OpenSSL::SSL::SSLContext::SESSION_CACHE_CLIENT
+    ctx.session_new_cb = lambda { |ary|
+      sock, sess = ary
+      called[:new] = [sock, sess]
+      true
+    }
+    ctx.session_remove_cb = lambda { |ary|
+      ctx, sess = ary
+      called[:remove] = [ctx, sess]
+      # any resulting value is OK (ignored)
+    }
+    start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true) do |server, port|
+      sock = TCPSocket.new("127.0.0.1", port)
+      ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
+      ssl.sync_close = true
+      ssl.connect
+      assert_equal(1, ctx.session_cache_stats[:cache_num])
+      assert_equal(1, ctx.session_cache_stats[:connect_good])
+      assert_equal([ssl, ssl.session], called[:new])
+      assert(ctx.session_remove(ssl.session))
+      assert(!ctx.session_remove(ssl.session))
+      assert_equal([ctx, ssl.session], called[:remove])
+      ssl.close
+    end
+  end
 end
 
 end

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

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