Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
OpenSSL::SSL::SSLSocket.new
(*untyped) -> ::OpenSSL::SSL::SSLSocket
SSLSocket.new(io) => aSSLSocket
SSLSocket.new(io, ctx) => aSSLSocket
SSLSocket.new(io, ctx, sync_close:) => aSSLSocket
ext/openssl/ossl_ssl.c
View on GitHub ↗
static VALUE
ossl_ssl_initialize(int argc, VALUE *argv, VALUE self)
{
static ID kw_ids[1];
VALUE kw_args[1];
VALUE opts;
VALUE io, v_ctx;
SSL *ssl;
SSL_CTX *ctx;
argc = rb_scan_args(argc, argv, "11:", &io, &v_ctx, &opts);
if (!kw_ids[0]) {
kw_ids[0] = rb_intern_const("sync_close");
}
rb_get_kwargs(opts, kw_ids, 0, 1, kw_args);
ossl_want_uninitialized(self, &ossl_ssl_type);
if (argc == 1)
v_ctx = rb_funcall(cSSLContext, rb_intern("new"), 0);
if (kw_args[0] != Qundef) {
rb_ivar_set(self, id_i_sync_close, kw_args[0]);
}
GetSSLCTX(v_ctx, ctx);
rb_ivar_set(self, id_i_context, v_ctx);
rb_ivar_set(self, id_original_context, v_ctx);
ossl_sslctx_setup(v_ctx);
if (rb_respond_to(io, rb_intern("nonblock=")))
rb_funcall(io, rb_intern("nonblock="), 1, Qtrue);
Check_Type(io, T_FILE);
rb_ivar_set(self, id_i_io, io);
ssl = SSL_new(ctx);
if (!ssl)
ossl_raise(eSSLError, NULL);
RTYPEDDATA_DATA(self) = ssl;
if (!SSL_set_ex_data(ssl, ossl_ssl_ex_ptr_idx, (void *)self))
ossl_raise(eSSLError, "SSL_set_ex_data");
SSL_set_info_callback(ssl, ssl_info_cb);
rb_call_super(0, NULL);
return self;
}
Creates a new SSL socket from io which must be a real IO 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 optional sync_close keyword parameter sets the sync_close instance variable. Setting this to true will cause the underlying socket to be closed when the SSL/TLS connection is shut down.
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.