aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-22 09:24:31 +0000
committernahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-22 09:24:31 +0000
commitd8af9c854d4c6723afb4a3295b8a21bdce8cc06e (patch)
tree7fca32a0d012e3e0b6bb3a00f5ba684a5f096fb1
parent26cb830df918614b4d734d187b7b65aba39f4d8e (diff)
downloadruby-d8af9c854d4c6723afb4a3295b8a21bdce8cc06e.tar.gz
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32200 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--ext/openssl/ossl_ssl.c4
-rw-r--r--test/openssl/test_ssl_session.rb30
3 files changed, 39 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index e7282d1735..6cd6a2919c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Wed Jun 22 18:20:46 2011 Hiroshi Nakamura <nahi@ruby-lang.org>
+
+ * 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@googlemail.com>
* ext/openssl/ossl.h: Introduced OSSL_BIO_reset macro for PEM/DER
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
index 112077ac7f..fd7b9f5e44 100644
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -406,7 +406,6 @@ ossl_sslctx_session_new_cb(SSL *ssl, SSL_SESSION *sess)
return RTEST(ret_obj) ? 1 : 0;
}
-#if 0 /* unused */
static VALUE
ossl_call_session_remove_cb(VALUE ary)
{
@@ -420,7 +419,6 @@ ossl_call_session_remove_cb(VALUE ary)
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 @@ ossl_sslctx_session_remove_cb(SSL_CTX *ctx, SSL_SESSION *sess)
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.
diff --git a/test/openssl/test_ssl_session.rb b/test/openssl/test_ssl_session.rb
index 00513670b2..b4563bb126 100644
--- a/test/openssl/test_ssl_session.rb
+++ b/test/openssl/test_ssl_session.rb
@@ -28,6 +28,7 @@ class OpenSSL::TestSSLSession < OpenSSL::SSLTestCase
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 @@ class OpenSSL::TestSSLSession < OpenSSL::SSLTestCase
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