Class: OpenSSL::SSL::SSLServer

Inherits:
Object
  • Object
show all
Includes:
SocketForwarder
Defined in:
lib/jopenssl22/openssl/ssl.rb,
lib/jopenssl18/openssl/ssl-internal.rb,
lib/jopenssl19/openssl/ssl-internal.rb

Overview

SSLServer represents a TCP/IP server socket with Secure Sockets Layer.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(svr, ctx) ⇒ SSLServer

Creates a new instance of SSLServer.

  • srv is an instance of TCPServer.

  • ctx is an instance of OpenSSL::SSL::SSLContext.


143
144
145
146
147
148
149
150
151
152
153
# File 'lib/jopenssl22/openssl/ssl.rb', line 143

def initialize(svr, ctx)
  @svr = svr
  @ctx = ctx
  unless ctx.session_id_context
    # see #6137 - session id may not exceed 32 bytes
    prng = ::Random.new($0.hash)
    session_id = prng.bytes(16).unpack('H*')[0]
    @ctx.session_id_context = session_id
  end
  @start_immediately = true
end

Instance Attribute Details

#start_immediatelyObject

When true then #accept works exactly the same as TCPServer#accept


138
139
140
# File 'lib/jopenssl22/openssl/ssl.rb', line 138

def start_immediately
  @start_immediately
end

Instance Method Details

#acceptObject

Works similar to TCPServer#accept.


171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/jopenssl22/openssl/ssl.rb', line 171

def accept
  # Socket#accept returns [socket, addrinfo].
  # TCPServer#accept returns a socket.
  # The following comma strips addrinfo.
  sock, = @svr.accept
  begin
    ssl = OpenSSL::SSL::SSLSocket.new(sock, @ctx)
    ssl.sync_close = true
    ssl.accept if @start_immediately
    ssl
  rescue SSLError => ex
    sock.close
    raise ex
  end
end

#closeObject

See IO#close for details.


188
189
190
# File 'lib/jopenssl22/openssl/ssl.rb', line 188

def close
  @svr.close
end

#listen(backlog = 5) ⇒ Object

See TCPServer#listen for details.


161
162
163
# File 'lib/jopenssl22/openssl/ssl.rb', line 161

def listen(backlog=5)
  @svr.listen(backlog)
end

#shutdown(how = Socket::SHUT_RDWR) ⇒ Object

See BasicSocket#shutdown for details.


166
167
168
# File 'lib/jopenssl22/openssl/ssl.rb', line 166

def shutdown(how=Socket::SHUT_RDWR)
  @svr.shutdown(how)
end

#to_ioObject

Returns the TCPServer passed to the SSLServer when initialized.


156
157
158
# File 'lib/jopenssl22/openssl/ssl.rb', line 156

def to_io
  @svr
end