Class: NetworkFacade::SSL::Client

Inherits:
Base::Client show all
Defined in:
lib/network-facade/ssl.rb

Instance Method Summary collapse

Methods inherited from Base::Client

#__read__, #__write__, inherited, #method_missing, uri=

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/network-facade/ssl.rb', line 14

def initialize(options = {})
	[: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
	super
	@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]
	@client = TCPSocket.new(@uri.host || 'localhost', @uri.port || PORT)
	@client = OpenSSL::SSL::SSLSocket.new(@client, @ctx)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NetworkFacade::Base::Client