* ext/openssl/lib/openssl/ssl.rb (module OpenSSL): move
OpenSSL::SSL::SSLSocket#initialize to Ruby. * ext/openssl/ossl_ssl.c: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
46bd8e86a5
commit
b830786f2d
@ -1,3 +1,10 @@
|
|||||||
|
Thu Aug 6 07:53:47 2015 Aaron Patterson <tenderlove@ruby-lang.org>
|
||||||
|
|
||||||
|
* ext/openssl/lib/openssl/ssl.rb (module OpenSSL): move
|
||||||
|
OpenSSL::SSL::SSLSocket#initialize to Ruby.
|
||||||
|
|
||||||
|
* ext/openssl/ossl_ssl.c: ditto
|
||||||
|
|
||||||
Thu Aug 6 02:25:31 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Thu Aug 6 02:25:31 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* node.c (rb_alloc_tmp_buffer): use NODE_ALLOCA to mark locations
|
* node.c (rb_alloc_tmp_buffer): use NODE_ALLOCA to mark locations
|
||||||
|
@ -94,6 +94,15 @@ module OpenSSL
|
|||||||
|
|
||||||
attr_accessor :tmp_dh_callback
|
attr_accessor :tmp_dh_callback
|
||||||
|
|
||||||
|
if ExtConfig::HAVE_TLSEXT_HOST_NAME
|
||||||
|
# A callback invoked at connect time to distinguish between multiple
|
||||||
|
# server names.
|
||||||
|
#
|
||||||
|
# The callback is invoked with an SSLSocket and a server name. The
|
||||||
|
# callback must return an SSLContext for the server name or nil.
|
||||||
|
attr_accessor :servername_cb
|
||||||
|
end
|
||||||
|
|
||||||
# call-seq:
|
# call-seq:
|
||||||
# SSLContext.new => ctx
|
# SSLContext.new => ctx
|
||||||
# SSLContext.new(:TLSv1) => ctx
|
# SSLContext.new(:TLSv1) => ctx
|
||||||
@ -253,6 +262,42 @@ module OpenSSL
|
|||||||
include SocketForwarder
|
include SocketForwarder
|
||||||
include Nonblock
|
include Nonblock
|
||||||
|
|
||||||
|
if ExtConfig::OPENSSL_NO_SOCK
|
||||||
|
def initialize(io, ctx = nil); raise NotImplmentedError; end
|
||||||
|
else
|
||||||
|
if ExtConfig::HAVE_TLSEXT_HOST_NAME
|
||||||
|
attr_accessor :hostname
|
||||||
|
end
|
||||||
|
|
||||||
|
attr_reader :io, :context
|
||||||
|
attr_accessor :sync_close
|
||||||
|
alias :to_io :io
|
||||||
|
|
||||||
|
# call-seq:
|
||||||
|
# SSLSocket.new(io) => aSSLSocket
|
||||||
|
# SSLSocket.new(io, ctx) => aSSLSocket
|
||||||
|
#
|
||||||
|
# Creates a new SSL socket from +io+ which must be a real ruby object (not an
|
||||||
|
# IO-like object that responds to read/write).
|
||||||
|
#
|
||||||
|
# If +ctx+ is provided the SSL Sockets initial params will be taken from
|
||||||
|
# the context.
|
||||||
|
#
|
||||||
|
# The OpenSSL::Buffering module provides additional IO methods.
|
||||||
|
#
|
||||||
|
# This method will freeze the SSLContext if one is provided;
|
||||||
|
# however, session management is still allowed in the frozen SSLContext.
|
||||||
|
|
||||||
|
def initialize(io, context = OpenSSL::SSL::SSLContext.new)
|
||||||
|
@io = io
|
||||||
|
@context = context
|
||||||
|
@sync_close = false
|
||||||
|
@hostname = nil
|
||||||
|
context.setup
|
||||||
|
super()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Perform hostname verification after an SSL connection is established
|
# Perform hostname verification after an SSL connection is established
|
||||||
#
|
#
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
VALUE mSSL;
|
VALUE mSSL;
|
||||||
|
VALUE mSSLExtConfig;
|
||||||
VALUE eSSLError;
|
VALUE eSSLError;
|
||||||
VALUE cSSLContext;
|
VALUE cSSLContext;
|
||||||
VALUE cSSLSocket;
|
VALUE cSSLSocket;
|
||||||
@ -71,22 +72,11 @@ static VALUE eSSLErrorWaitWritable;
|
|||||||
#define ossl_ssl_get_x509(o) rb_iv_get((o),"@x509")
|
#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_key(o) rb_iv_get((o),"@key")
|
||||||
|
|
||||||
#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))
|
|
||||||
#define ossl_ssl_set_sync_close(o,v) rb_iv_set((o),"@sync_close",(v))
|
|
||||||
#define ossl_ssl_set_x509(o,v) rb_iv_set((o),"@x509",(v))
|
#define ossl_ssl_set_x509(o,v) rb_iv_set((o),"@x509",(v))
|
||||||
#define ossl_ssl_set_key(o,v) rb_iv_set((o),"@key",(v))
|
#define ossl_ssl_set_key(o,v) rb_iv_set((o),"@key",(v))
|
||||||
#define ossl_ssl_set_tmp_dh(o,v) rb_iv_set((o),"@tmp_dh",(v))
|
#define ossl_ssl_set_tmp_dh(o,v) rb_iv_set((o),"@tmp_dh",(v))
|
||||||
#define ossl_ssl_set_tmp_ecdh(o,v) rb_iv_set((o),"@tmp_ecdh",(v))
|
#define ossl_ssl_set_tmp_ecdh(o,v) rb_iv_set((o),"@tmp_ecdh",(v))
|
||||||
|
|
||||||
static const char *ossl_ssl_attr_readers[] = { "io", "context", };
|
|
||||||
static const char *ossl_ssl_attrs[] = {
|
|
||||||
#ifdef HAVE_SSL_SET_TLSEXT_HOST_NAME
|
|
||||||
"hostname",
|
|
||||||
#endif
|
|
||||||
"sync_close",
|
|
||||||
};
|
|
||||||
|
|
||||||
ID ID_callback_state;
|
ID ID_callback_state;
|
||||||
|
|
||||||
static VALUE sym_exception, sym_wait_readable, sym_wait_writable;
|
static VALUE sym_exception, sym_wait_readable, sym_wait_writable;
|
||||||
@ -1189,44 +1179,6 @@ ossl_ssl_s_alloc(VALUE klass)
|
|||||||
return TypedData_Wrap_Struct(klass, &ossl_ssl_type, NULL);
|
return TypedData_Wrap_Struct(klass, &ossl_ssl_type, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* call-seq:
|
|
||||||
* SSLSocket.new(io) => aSSLSocket
|
|
||||||
* SSLSocket.new(io, ctx) => aSSLSocket
|
|
||||||
*
|
|
||||||
* Creates a new SSL socket from +io+ which must be a real ruby object (not an
|
|
||||||
* IO-like object that responds to read/write).
|
|
||||||
*
|
|
||||||
* If +ctx+ is provided the SSL Sockets initial params will be taken from
|
|
||||||
* the context.
|
|
||||||
*
|
|
||||||
* The OpenSSL::Buffering module provides additional IO methods.
|
|
||||||
*
|
|
||||||
* This method will freeze the SSLContext if one is provided;
|
|
||||||
* however, session management is still allowed in the frozen SSLContext.
|
|
||||||
*/
|
|
||||||
static VALUE
|
|
||||||
ossl_ssl_initialize(int argc, VALUE *argv, VALUE self)
|
|
||||||
{
|
|
||||||
VALUE io, ctx;
|
|
||||||
|
|
||||||
if (rb_scan_args(argc, argv, "11", &io, &ctx) == 1) {
|
|
||||||
ctx = rb_funcall(cSSLContext, rb_intern("new"), 0);
|
|
||||||
}
|
|
||||||
OSSL_Check_Kind(ctx, cSSLContext);
|
|
||||||
Check_Type(io, T_FILE);
|
|
||||||
ossl_ssl_set_io(self, io);
|
|
||||||
ossl_ssl_set_ctx(self, ctx);
|
|
||||||
ossl_ssl_set_sync_close(self, Qfalse);
|
|
||||||
ossl_sslctx_setup(ctx);
|
|
||||||
|
|
||||||
rb_iv_set(self, "@hostname", Qnil);
|
|
||||||
|
|
||||||
rb_call_super(0, 0);
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
ossl_ssl_setup(VALUE self)
|
ossl_ssl_setup(VALUE self)
|
||||||
{
|
{
|
||||||
@ -1986,6 +1938,17 @@ Init_ossl_ssl(void)
|
|||||||
* of SSLContext to set up connections.
|
* of SSLContext to set up connections.
|
||||||
*/
|
*/
|
||||||
mSSL = rb_define_module_under(mOSSL, "SSL");
|
mSSL = rb_define_module_under(mOSSL, "SSL");
|
||||||
|
|
||||||
|
/* Document-module: OpenSSL::ExtConfig
|
||||||
|
*
|
||||||
|
* This module contains configuration information about the SSL extension,
|
||||||
|
* for example if socket support is enabled, or the host name TLS extension
|
||||||
|
* is enabled. Constants in this module will always be defined, but contain
|
||||||
|
* `true` or `false` values depending on the configuration of your OpenSSL
|
||||||
|
* installation.
|
||||||
|
*/
|
||||||
|
mSSLExtConfig = rb_define_module_under(mOSSL, "ExtConfig");
|
||||||
|
|
||||||
/* Document-class: OpenSSL::SSL::SSLError
|
/* Document-class: OpenSSL::SSL::SSLError
|
||||||
*
|
*
|
||||||
* Generic error class raised by SSLSocket and SSLContext.
|
* Generic error class raised by SSLSocket and SSLContext.
|
||||||
@ -2138,15 +2101,11 @@ Init_ossl_ssl(void)
|
|||||||
rb_attr(cSSLContext, rb_intern("session_remove_cb"), 1, 1, Qfalse);
|
rb_attr(cSSLContext, rb_intern("session_remove_cb"), 1, 1, Qfalse);
|
||||||
|
|
||||||
#ifdef HAVE_SSL_SET_TLSEXT_HOST_NAME
|
#ifdef HAVE_SSL_SET_TLSEXT_HOST_NAME
|
||||||
/*
|
rb_define_const(mSSLExtConfig, "HAVE_TLSEXT_HOST_NAME", Qtrue);
|
||||||
* A callback invoked at connect time to distinguish between multiple
|
#else
|
||||||
* server names.
|
rb_define_const(mSSLExtConfig, "HAVE_TLSEXT_HOST_NAME", Qfalse);
|
||||||
*
|
|
||||||
* The callback is invoked with an SSLSocket and a server name. The
|
|
||||||
* callback must return an SSLContext for the server name or nil.
|
|
||||||
*/
|
|
||||||
rb_attr(cSSLContext, rb_intern("servername_cb"), 1, 1, Qfalse);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A callback invoked whenever a new handshake is initiated. May be used
|
* A callback invoked whenever a new handshake is initiated. May be used
|
||||||
* to disable renegotiation entirely.
|
* to disable renegotiation entirely.
|
||||||
@ -2316,15 +2275,10 @@ Init_ossl_ssl(void)
|
|||||||
*/
|
*/
|
||||||
cSSLSocket = rb_define_class_under(mSSL, "SSLSocket", rb_cObject);
|
cSSLSocket = rb_define_class_under(mSSL, "SSLSocket", rb_cObject);
|
||||||
#ifdef OPENSSL_NO_SOCK
|
#ifdef OPENSSL_NO_SOCK
|
||||||
rb_define_method(cSSLSocket, "initialize", rb_notimplement, -1);
|
rb_define_const(mSSLExtConfig, "OPENSSL_NO_SOCK", Qtrue);
|
||||||
#else
|
#else
|
||||||
|
rb_define_const(mSSLExtConfig, "OPENSSL_NO_SOCK", Qfalse);
|
||||||
rb_define_alloc_func(cSSLSocket, ossl_ssl_s_alloc);
|
rb_define_alloc_func(cSSLSocket, ossl_ssl_s_alloc);
|
||||||
for(i = 0; i < numberof(ossl_ssl_attr_readers); i++)
|
|
||||||
rb_attr(cSSLSocket, rb_intern(ossl_ssl_attr_readers[i]), 1, 0, Qfalse);
|
|
||||||
for(i = 0; i < numberof(ossl_ssl_attrs); i++)
|
|
||||||
rb_attr(cSSLSocket, rb_intern(ossl_ssl_attrs[i]), 1, 1, Qfalse);
|
|
||||||
rb_define_alias(cSSLSocket, "to_io", "io");
|
|
||||||
rb_define_method(cSSLSocket, "initialize", ossl_ssl_initialize, -1);
|
|
||||||
rb_define_method(cSSLSocket, "connect", ossl_ssl_connect, 0);
|
rb_define_method(cSSLSocket, "connect", ossl_ssl_connect, 0);
|
||||||
rb_define_method(cSSLSocket, "connect_nonblock", ossl_ssl_connect_nonblock, -1);
|
rb_define_method(cSSLSocket, "connect_nonblock", ossl_ssl_connect_nonblock, -1);
|
||||||
rb_define_method(cSSLSocket, "accept", ossl_ssl_accept, 0);
|
rb_define_method(cSSLSocket, "accept", ossl_ssl_accept, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user