Class: NetworkFacade::SSL::Server

Inherits:
TCP::Server show all
Defined in:
lib/network-facade/ssl.rb

Instance Method Summary collapse

Methods inherited from TCP::Server

#accept, #client_id

Methods inherited from Base::Server

#accept, #add, #client_id, #read, #start, #write

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/network-facade/ssl.rb', line 31

def initialize(options = {})
	if options[:server].nil?
		[:key, :cert, :ca].each do |o|
			raise "Missing option #{o}" if options[o].nil?
			raise "File does not exists #{options[o]}" unless File.exists?(options[o])
		end
		options[:port] ||= PORT
		options[:host] ||= '0.0.0.0'
		@ctx = OpenSSL::SSL::SSLContext.new
		@ctx.key = OpenSSL::PKey::RSA.new File.read(options[:key])
		@ctx.cert = OpenSSL::X509::Certificate.new File.read(options[:cert])
		@ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT
		@ctx.ca_file = options[:ca]
		options[:server] = TCPServer.new(options[:host], options[:port])
		@ssl = OpenSSL::SSL::SSLSocket.new(options[:server], @ctx)
		options[:server] = @ssl.to_io
	end
	super(options)
end