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.c (ossl_call_tmp_dh_callback): change callback

to return the Ruby dh (or ecdh) object that the caller cares about
  instead of doing rb_iv_get / set to communicate.  This means we can
  remove an rb_iv_get call, and only use the set calls for their
  intended purpose (to prevent the object from being GC'd).

* ext/openssl/ossl_ssl.c (ossl_tmp_dh_callback): ditto
* ext/openssl/ossl_ssl.c (ossl_call_tmp_ecdh_callback): ditto
* ext/openssl/ossl_ssl.c (ossl_tmp_ecdh_callback): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51460 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tenderlove 2015-07-31 19:08:40 +00:00
parent 2abc873732
commit 9fefa60637
2 changed files with 24 additions and 14 deletions

View file

@ -1,3 +1,15 @@
Sat Aug 1 04:06:29 2015 Aaron Patterson <tenderlove@ruby-lang.org>
* ext/openssl/ossl_ssl.c (ossl_call_tmp_dh_callback): change callback
to return the Ruby dh (or ecdh) object that the caller cares about
instead of doing rb_iv_get / set to communicate. This means we can
remove an rb_iv_get call, and only use the set calls for their
intended purpose (to prevent the object from being GC'd).
* ext/openssl/ossl_ssl.c (ossl_tmp_dh_callback): ditto
* ext/openssl/ossl_ssl.c (ossl_call_tmp_ecdh_callback): ditto
* ext/openssl/ossl_ssl.c (ossl_tmp_ecdh_callback): ditto
Sat Aug 1 03:49:31 2015 Aaron Patterson <tenderlove@ruby-lang.org>
* ext/openssl/ossl_ssl.c (ossl_call_tmp_dh_callback): Similarly to the

View file

@ -72,8 +72,6 @@ static VALUE eSSLErrorWaitWritable;
#define ossl_ssl_get_sync_close(o) rb_iv_get((o),"@sync_close")
#define ossl_ssl_get_x509(o) rb_iv_get((o),"@x509")
#define ossl_ssl_get_key(o) rb_iv_get((o),"@key")
#define ossl_ssl_get_tmp_dh(o) rb_iv_get((o),"@tmp_dh")
#define ossl_ssl_get_tmp_ecdh(o) rb_iv_get((o),"@tmp_ecdh")
#define ossl_ssl_set_io(o,v) rb_iv_set((o),"@io",(v))
#define ossl_ssl_set_ctx(o,v) rb_iv_set((o),"@context",(v))
@ -260,24 +258,24 @@ ossl_call_tmp_dh_callback(VALUE args)
dh = rb_apply(cb, rb_intern("call"), args);
pkey = GetPKeyPtr(dh);
if (EVP_PKEY_type(pkey->type) != EVP_PKEY_DH) return Qfalse;
ossl_ssl_set_tmp_dh(rb_ary_entry(args, 0), dh);
return Qtrue;
return dh;
}
static DH*
ossl_tmp_dh_callback(SSL *ssl, int is_export, int keylength)
{
VALUE args, success, rb_ssl;
VALUE args, dh, rb_ssl;
rb_ssl = (VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx);
args = rb_ary_new_from_args(3, rb_ssl, INT2FIX(is_export), INT2FIX(keylength));
success = rb_protect(ossl_call_tmp_dh_callback, args, NULL);
if (!RTEST(success)) return NULL;
dh = rb_protect(ossl_call_tmp_dh_callback, args, NULL);
if (!RTEST(dh)) return NULL;
ossl_ssl_set_tmp_dh(rb_ssl, dh);
return GetPKeyPtr(ossl_ssl_get_tmp_dh(rb_ssl))->pkey.dh;
return GetPKeyPtr(dh)->pkey.dh;
}
#endif /* OPENSSL_NO_DH */
@ -295,24 +293,24 @@ ossl_call_tmp_ecdh_callback(VALUE args)
ecdh = rb_apply(cb, rb_intern("call"), args);
pkey = GetPKeyPtr(ecdh);
if (EVP_PKEY_type(pkey->type) != EVP_PKEY_EC) return Qfalse;
ossl_ssl_set_tmp_ecdh(rb_ary_entry(args, 0), ecdh);
return Qtrue;
return ecdh;
}
static EC_KEY*
ossl_tmp_ecdh_callback(SSL *ssl, int is_export, int keylength)
{
VALUE args, success, rb_ssl;
VALUE args, ecdh, rb_ssl;
rb_ssl = (VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx);
args = rb_ary_new_from_args(3, rb_ssl, INT2FIX(is_export), INT2FIX(keylength));
success = rb_protect(ossl_call_tmp_ecdh_callback, args, NULL);
if (!RTEST(success)) return NULL;
ecdh = rb_protect(ossl_call_tmp_ecdh_callback, args, NULL);
if (!RTEST(ecdh)) return NULL;
ossl_ssl_set_tmp_ecdh(rb_ssl, ecdh);
return GetPKeyPtr(ossl_ssl_get_tmp_ecdh(rb_ssl))->pkey.ec;
return GetPKeyPtr(ecdh)->pkey.ec;
}
#endif