Class: RaptorIO::Socket::TCP::SSL
- Inherits:
-
RaptorIO::Socket::TCP
- Object
- RaptorIO::Socket
- RaptorIO::Socket::TCP
- RaptorIO::Socket::TCP::SSL
- Defined in:
- lib/raptor-io/socket/tcp/ssl.rb
Overview
TCP client with SSL encryption.
Constant Summary
Constants inherited from RaptorIO::Socket::TCP
DEFAULT_OPTIONS, DEFAULT_SSL_OPTIONS
Instance Attribute Summary
Attributes inherited from RaptorIO::Socket::TCP
Attributes inherited from RaptorIO::Socket
Class Method Summary collapse
-
.from_openssl(openssl_socket) ⇒ SSL
Create a new SSL from an already-connected ‘OpenSSL::SSL::SSLSocket`.
Instance Method Summary collapse
-
#initialize(socket, options = {}) ⇒ SSL
constructor
A new instance of SSL.
-
#ssl_context ⇒ OpenSSL::SSL::Context
The SSL context for this encrypted stream.
-
#verify_mode ⇒ Fixnum
One of the ‘OpenSSL::SSL::VERIFY_*` constants.
-
#version ⇒ Symbol
SSL version.
Methods inherited from RaptorIO::Socket::TCP
#close, #getpeername, #gets, #read, #read_nonblock, #readpartial, #remote_address, #ssl?, #ssl_version, #to_io, #to_ssl, #ungetc, #write, #write_nonblock
Methods inherited from RaptorIO::Socket
#close, #closed?, getaddrinfo, method_missing, respond_to_missing?, select, #ssl?, #to_io, translate_errors
Constructor Details
#initialize(socket, options = {}) ⇒ SSL
Returns a new instance of SSL.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/raptor-io/socket/tcp/ssl.rb', line 45 def initialize( socket, = {} ) = DEFAULT_SSL_OPTIONS.merge( ) super @context = [:context] || [:ssl_context] if @context.nil? @context = OpenSSL::SSL::SSLContext.new( [:ssl_version] ) @context.verify_mode = [:ssl_verify_mode] end @socket = OpenSSL::SSL::SSLSocket.new(socket.to_io, @context) begin #$stderr.puts("#{self.class}#initialize connecting") @socket.connect_nonblock rescue IO::WaitReadable, IO::WaitWritable => e #$stderr.puts("Wait*able #{e}, #{options[:connect_timeout].inspect}") if e.kind_of? IO::WaitReadable r,w,_ = IO.select([@socket], nil, nil, [:connect_timeout]) else r,w,_ = IO.select(nil, [@socket], nil, [:connect_timeout]) end if r.nil? && w.nil? #$stderr.puts("timeout") raise RaptorIO::Socket::Error::ConnectionTimeout.new(e.to_s) end retry end end |
Class Method Details
.from_openssl(openssl_socket) ⇒ SSL
Create a new RaptorIO::Socket::TCP::SSL from an already-connected ‘OpenSSL::SSL::SSLSocket`.
18 19 20 21 22 23 24 25 26 |
# File 'lib/raptor-io/socket/tcp/ssl.rb', line 18 def self.from_openssl(openssl_socket) raptor = self.allocate raptor.__send__(:socket=, openssl_socket) raptor.__send__(:plaintext_socket=, openssl_socket.to_io) raptor. = {} raptor.[:ssl_context] = openssl_socket.context raptor end |
Instance Method Details
#ssl_context ⇒ OpenSSL::SSL::Context
The SSL context for this encrypted stream.
32 |
# File 'lib/raptor-io/socket/tcp/ssl.rb', line 32 def_delegator :@socket, :ssl_context, :context |
#verify_mode ⇒ Fixnum
Returns One of the ‘OpenSSL::SSL::VERIFY_*` constants.
36 |
# File 'lib/raptor-io/socket/tcp/ssl.rb', line 36 def_delegator :@socket, :ssl_verify_mode, :verify_mode |
#version ⇒ Symbol
Returns SSL version.
40 |
# File 'lib/raptor-io/socket/tcp/ssl.rb', line 40 def_delegator :@socket, :ssl_version, :version |