diff options
author | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-07-25 18:44:54 +0000 |
---|---|---|
committer | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-07-25 18:44:54 +0000 |
commit | c8884ebfe4e30123de67df90f5d566d6fd0f2ec3 (patch) | |
tree | dbe5cc616b10d9368290efc3b482242a71a6639c /ext | |
parent | e02186f5263ebecea941cf8554206c6ac5b04ab3 (diff) |
* ext/openssl/lib/openssl/ssl.rb (module OpenSSL): move
OpenSSL::SSL::SSLContext#initialize implementation to pure Ruby.
* ext/openssl/ossl_ssl.c (ossl_sslctx_initialize): ditto
* ext/openssl/ossl_ssl.c (Init_ossl_ssl): ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51375 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/openssl/lib/openssl/ssl.rb | 20 | ||||
-rw-r--r-- | ext/openssl/ossl_ssl.c | 44 |
2 files changed, 20 insertions, 44 deletions
diff --git a/ext/openssl/lib/openssl/ssl.rb b/ext/openssl/lib/openssl/ssl.rb index cc956fa6b5..0caa033e5d 100644 --- a/ext/openssl/lib/openssl/ssl.rb +++ b/ext/openssl/lib/openssl/ssl.rb @@ -74,6 +74,26 @@ module OpenSSL DEFAULT_CERT_STORE.flags = OpenSSL::X509::V_FLAG_CRL_CHECK_ALL end + INIT_VARS = ["cert", "key", "client_ca", "ca_file", "ca_path", + "timeout", "verify_mode", "verify_depth", "renegotiation_cb", + "verify_callback", "options", "cert_store", "extra_chain_cert", + "client_cert_cb", "tmp_dh_callback", "session_id_context", + "session_get_cb", "session_new_cb", "session_remove_cb", + "tmp_ecdh_callback", "servername_cb", "npn_protocols", + "npn_select_cb"].map { |x| "@#{x}" } + + # call-seq: + # SSLContext.new => ctx + # SSLContext.new(:TLSv1) => ctx + # SSLContext.new("SSLv23_client") => ctx + # + # You can get a list of valid methods with OpenSSL::SSL::SSLContext::METHODS + def initialize(version = nil) + INIT_VARS.each { |v| instance_variable_set v, nil } + return unless version + self.ssl_version = version + end + ## # Sets the parameters for this SSL context to the values in +params+. # The keys in +params+ must be assignment methods on SSLContext. diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c index 81b5a40157..205b196647 100644 --- a/ext/openssl/ossl_ssl.c +++ b/ext/openssl/ossl_ssl.c @@ -69,22 +69,6 @@ static VALUE eSSLErrorWaitWritable; #define ossl_sslctx_get_tmp_dh_cb(o) rb_iv_get((o),"@tmp_dh_callback") #define ossl_sslctx_get_sess_id_ctx(o) rb_iv_get((o),"@session_id_context") -static const char *ossl_sslctx_attrs[] = { - "cert", "key", "client_ca", "ca_file", "ca_path", - "timeout", "verify_mode", "verify_depth", "renegotiation_cb", - "verify_callback", "options", "cert_store", "extra_chain_cert", - "client_cert_cb", "tmp_dh_callback", "session_id_context", - "session_get_cb", "session_new_cb", "session_remove_cb", - "tmp_ecdh_callback", -#ifdef HAVE_SSL_SET_TLSEXT_HOST_NAME - "servername_cb", -#endif -#ifdef HAVE_OPENSSL_NPN_NEGOTIATED - "npn_protocols", - "npn_select_cb", -#endif -}; - #define ossl_ssl_get_io(o) rb_iv_get((o),"@io") #define ossl_ssl_get_ctx(o) rb_iv_get((o),"@context") #define ossl_ssl_get_sync_close(o) rb_iv_get((o),"@sync_close") @@ -232,33 +216,6 @@ ossl_sslctx_set_ssl_version(VALUE self, VALUE ssl_method) return ssl_method; } -/* - * call-seq: - * SSLContext.new => ctx - * SSLContext.new(:TLSv1) => ctx - * SSLContext.new("SSLv23_client") => ctx - * - * You can get a list of valid methods with OpenSSL::SSL::SSLContext::METHODS - */ -static VALUE -ossl_sslctx_initialize(int argc, VALUE *argv, VALUE self) -{ - VALUE ssl_method; - int i; - - for(i = 0; i < numberof(ossl_sslctx_attrs); i++){ - char buf[32]; - snprintf(buf, sizeof(buf), "@%s", ossl_sslctx_attrs[i]); - rb_iv_set(self, buf, Qnil); - } - if (rb_scan_args(argc, argv, "01", &ssl_method) == 0){ - return self; - } - ossl_sslctx_set_ssl_version(self, ssl_method); - - return self; -} - static VALUE ossl_call_client_cert_cb(VALUE obj) { @@ -2315,7 +2272,6 @@ Init_ossl_ssl(void) rb_define_alias(cSSLContext, "ssl_timeout", "timeout"); rb_define_alias(cSSLContext, "ssl_timeout=", "timeout="); - rb_define_method(cSSLContext, "initialize", ossl_sslctx_initialize, -1); rb_define_method(cSSLContext, "ssl_version=", ossl_sslctx_set_ssl_version, 1); rb_define_method(cSSLContext, "ciphers", ossl_sslctx_get_ciphers, 0); rb_define_method(cSSLContext, "ciphers=", ossl_sslctx_set_ciphers, 1); |