Class: Anorexic::SSLService

Inherits:
BasicService show all
Defined in:
lib/anorexic/server/services/ssl_service.rb

Overview

this class is a basic TCP socket service with SSL.

a protocol should be assigned, or the service will fall back to an echo service.

to-do: fix self certificate issue (fails).

Instance Attribute Summary collapse

Attributes inherited from BasicService

#active_time, #closed, #handler, #locker, #out_que, #parameters, #protocol, #socket, #timeout

Instance Method Summary collapse

Methods inherited from BasicService

#<<, #close, create_service, #disconnect, #disconnected?, #flush, #has_incoming_data?, #on_disconnect, #on_message, #send, #send_nonblock, #send_unsafe_interrupt, #timedout?, #touch

Constructor Details

#initialize(soc, parameters = {}) ⇒ SSLService

creates a new connection wrapper object for the new socket that was recieved from the `accept_nonblock` method call.


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/anorexic/server/services/ssl_service.rb', line 17

def initialize soc, parameters = {}
	context = OpenSSL::SSL::SSLContext.new
	context.set_params verify_mode: OpenSSL::SSL::VERIFY_NONE# OpenSSL::SSL::VERIFY_PEER #OpenSSL::SSL::VERIFY_NONE
	# context.options DoNotReverseLookup: true
	if parameters[:ssl_cert] && parameters[:ssl_key]
		context.cert = parameters[:ssl_cert]
		context.key = parameters[:ssl_key]
	else
		context.cert, context.key = self.class.self_cert
	end
	context.cert_store = OpenSSL::X509::Store.new
	context.cert_store.set_default_paths
	@ssl_socket = OpenSSL::SSL::SSLSocket.new(soc, context)
	@ssl_socket.sync_close = true
	@socket = soc
	@ssl_socket.accept
	super
end

Instance Attribute Details

#ssl_socketObject (readonly)

instance methods


14
15
16
# File 'lib/anorexic/server/services/ssl_service.rb', line 14

def ssl_socket
  @ssl_socket
end

Instance Method Details

#ioObject

returns an IO-like object used for reading/writing (unlike the original IO object, this can be an SSL layer or any other wrapper object).


47
48
49
50
# File 'lib/anorexic/server/services/ssl_service.rb', line 47

def io
	touch
	@ssl_socket
end

#read(size = 1048576) ⇒ Object

reads from the connection


53
54
55
56
57
58
59
60
61
62
# File 'lib/anorexic/server/services/ssl_service.rb', line 53

def read size = 1048576
	data = ''
	begin
		loop { data << ssl_socket.read_nonblock( size) }
	rescue Exception => e
		
	end
	touch unless data.empty?
	data
end

#service_typeObject

returns the service type - set to normal


38
39
40
# File 'lib/anorexic/server/services/ssl_service.rb', line 38

def service_type
	'encrypted'
end

#ssl?Boolean

returns true if the service is encrypted using the OpenSSL library.

Returns:

  • (Boolean)

42
43
44
# File 'lib/anorexic/server/services/ssl_service.rb', line 42

def ssl?
	true
end