1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/openssl/ossl_ssl_session.c (ossl_ssl_session_set_time): Check

argument type with NUM2LONG if the arg is not a Time object.
  See #4919.

* ext/openssl/ossl_ssl_session.c (ossl_ssl_session_set_timeout): Check
  type with NUM2LONG. Time as an arg is not allowed. See #4919.

* test/openssl/test_ssl_session.rb (test_session_time,
  test_session_timeout): Test it.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32211 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nahi 2011-06-23 10:36:09 +00:00
parent a02504ba84
commit 544daf1f7a
3 changed files with 105 additions and 25 deletions

View file

@ -1,3 +1,15 @@
Thu Jun 23 19:30:53 2011 Hiroshi Nakamura <nahi@ruby-lang.org>
* ext/openssl/ossl_ssl_session.c (ossl_ssl_session_set_time): Check
argument type with NUM2LONG if the arg is not a Time object.
See #4919.
* ext/openssl/ossl_ssl_session.c (ossl_ssl_session_set_timeout): Check
type with NUM2LONG. Time as an arg is not allowed. See #4919.
* test/openssl/test_ssl_session.rb (test_session_time,
test_session_timeout): Test it.
Wed Jun 23 13:30:30 2011 Shota Fukumori <sorah@tubusu.net>
* signal.c(ruby_atomic_exchange): Fix definition style.

View file

@ -104,6 +104,8 @@ static VALUE ossl_ssl_session_eq(VALUE val1, VALUE val2)
* call-seq:
* session.time -> Time
*
* Gets start time of the session.
*
*/
static VALUE ossl_ssl_session_get_time(VALUE self)
{
@ -124,7 +126,7 @@ static VALUE ossl_ssl_session_get_time(VALUE self)
* call-seq:
* session.timeout -> integer
*
* How long until the session expires in seconds.
* Gets how long until the session expires in seconds.
*
*/
static VALUE ossl_ssl_session_get_timeout(VALUE self)
@ -139,31 +141,45 @@ static VALUE ossl_ssl_session_get_timeout(VALUE self)
return TIMET2NUM(t);
}
#define SSLSESSION_SET_TIME(func) \
static VALUE ossl_ssl_session_set_##func(VALUE self, VALUE time_v) \
{ \
SSL_SESSION *ctx; \
unsigned long t; \
\
GetSSLSession(self, ctx); \
\
if (rb_obj_is_instance_of(time_v, rb_cTime)) { \
time_v = rb_funcall(time_v, rb_intern("to_i"), 0); \
} else if (FIXNUM_P(time_v) || TYPE(time_v) == T_BIGNUM) { \
; \
} else { \
ossl_raise(rb_eArgError, "unknown type"); \
} \
\
t = NUM2ULONG(time_v); \
\
SSL_SESSION_set_##func(ctx, t); \
\
return ossl_ssl_session_get_##func(self); \
}
/*
* call-seq:
* session.time=(Time) -> Time
* session.time=(integer) -> Time
*
* Sets start time of the session. Time resolution is in seconds.
*
*/
static VALUE ossl_ssl_session_set_time(VALUE self, VALUE time_v)
{
SSL_SESSION *ctx;
long t;
SSLSESSION_SET_TIME(time)
SSLSESSION_SET_TIME(timeout)
GetSSLSession(self, ctx);
if (rb_obj_is_instance_of(time_v, rb_cTime)) {
time_v = rb_funcall(time_v, rb_intern("to_i"), 0);
}
t = NUM2LONG(time_v);
SSL_SESSION_set_time(ctx, t);
return ossl_ssl_session_get_time(self);
}
/*
* call-seq:
* session.timeout=(integer) -> integer
*
* Sets how long until the session expires in seconds.
*
*/
static VALUE ossl_ssl_session_set_timeout(VALUE self, VALUE time_v)
{
SSL_SESSION *ctx;
long t;
GetSSLSession(self, ctx);
t = NUM2LONG(time_v);
SSL_SESSION_set_timeout(ctx, t);
return ossl_ssl_session_get_timeout(self);
}
#ifdef HAVE_SSL_SESSION_GET_ID
/*

View file

@ -33,6 +33,58 @@ class OpenSSL::TestSSLSession < OpenSSL::SSLTestCase
end
end
DUMMY_SESSION = <<__EOS__
-----BEGIN SSL SESSION PARAMETERS-----
MIIDzQIBAQICAwEEAgA5BCAF219w9ZEV8dNA60cpEGOI34hJtIFbf3bkfzSgMyad
MQQwyGLbkCxE4OiMLdKKem+pyh8V7ifoP7tCxhdmwoDlJxI1v6nVCjai+FGYuncy
NNSWoQYCBE4DDWuiAwIBCqOCAo4wggKKMIIBcqADAgECAgECMA0GCSqGSIb3DQEB
BQUAMD0xE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ASI5XoqAHwGezhLodZuvJEfsVyCF9y
j+RBGfCFrrQbBdnkFI/ztgM=
-----END SSL SESSION PARAMETERS-----
__EOS__
def test_session_time
sess = OpenSSL::SSL::Session.new(DUMMY_SESSION)
sess.time = (now = Time.now)
assert_equal(now.to_i, sess.time.to_i)
sess.time = 1
assert_equal(1, sess.time.to_i)
sess.time = 1.2345
assert_equal(1, sess.time.to_i)
# Can OpenSSL handle t>2038y correctly? Version?
sess.time = 2**31
assert_equal(2**31, sess.time.to_i)
end
def test_session_timeout
sess = OpenSSL::SSL::Session.new(DUMMY_SESSION)
assert_raise(TypeError) do
sess.timeout = (now = Time.now)
end
sess.timeout = 1
assert_equal(1, sess.timeout.to_i)
sess.timeout = 1.2345
assert_equal(1, sess.timeout.to_i)
sess.timeout = 2**31
assert_equal(2**31, sess.timeout.to_i)
end
def test_client_session
last_session = nil
start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true) do |server, port|