Class: NetworkFacade::SSL::Server
- Inherits:
-
TCP::Server
- Object
- Base::Server
- TCP::Server
- NetworkFacade::SSL::Server
- Defined in:
- lib/network-facade/ssl.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Server
constructor
A new instance of Server.
Methods inherited from TCP::Server
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( = {}) if [:server].nil? [:key, :cert, :ca].each do |o| raise "Missing option #{o}" if [o].nil? raise "File does not exists #{[o]}" unless File.exists?([o]) end [:port] ||= PORT [:host] ||= '0.0.0.0' @ctx = OpenSSL::SSL::SSLContext.new @ctx.key = OpenSSL::PKey::RSA.new File.read([:key]) @ctx.cert = OpenSSL::X509::Certificate.new File.read([:cert]) @ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT @ctx.ca_file = [:ca] [:server] = TCPServer.new([:host], [:port]) @ssl = OpenSSL::SSL::SSLSocket.new([:server], @ctx) [:server] = @ssl.to_io end super() end |