mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
26cb830df9
commit
d8af9c854d
3 changed files with 39 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue