OpenSSL::SSL::Server
Inherits Socket::Server / Reference / Object
This class wraps another ::Socket::Server in an SSL layer.
require "socket"
require "openssl"
tcp_server = TCPServer.new(0)
ssl_context = OpenSSL::SSL::Context::Server.new
ssl_context.certificate_chain = "openssl.crt"
ssl_context.private_key = "openssl.key"
ssl_server = OpenSSL::SSL::Server.new(tcp_server, ssl_context)
puts "SSL Server listening on #{tcp_server.local_address}"
while connection = ssl_server.accept?
connection.puts "secure message"
connection.close
end
Constructors
Creates a new SSL server wrapping wrapped.
context configures the SSL options, see OpenSSL::SSL::Context::Server for details
Class methods
Creates a new SSL server wrapping wrapped and yields it to the block.
context configures the SSL options, see OpenSSL::SSL::Context::Server for details
The server is closed after the block returns.
Instance methods
Implements ::Socket::Server#accept.
This method calls @wrapped.accept and wraps the resulting IO in a SSL socket (OpenSSL::SSL::Socket::Server) with context configuration.
Implements ::Socket::Server#accept?.
This method calls @wrapped.accept? and wraps the resulting IO in a SSL socket (OpenSSL::SSL::Socket::Server) with context configuration.
When true a call to #accept will also initiate the SSL handshake.