Class: DRab::DRabSSLSocket
- Inherits:
-
DRabTCPSocket
- Object
- DRabTCPSocket
- DRab::DRabSSLSocket
- Defined in:
- lib/drab/ssl.rb
Overview
The protocol for DRab over an SSL socket
The URI for a DRab socket over SSL is: drabssl://<host>:<port>?<option>. The option is optional
Defined Under Namespace
Classes: SSLConfig
Instance Attribute Summary
Attributes inherited from DRabTCPSocket
Class Method Summary collapse
-
.open(uri, config) ⇒ Object
Return an DRab::DRabSSLSocket instance as a client-side connection, with the SSL connected.
-
.open_server(uri, config) ⇒ Object
Returns a DRab::DRabSSLSocket instance as a server-side connection, with the SSL connected.
-
.parse_uri(uri) ⇒ Object
Parse the dRuby
urifor an SSL connection. -
.uri_option(uri, config) ⇒ Object
This is a convenience method to parse
uriand separate out any additional options appended in theuri.
Instance Method Summary collapse
-
#accept ⇒ Object
:nodoc:.
-
#close ⇒ Object
Closes the SSL stream before closing the dRuby connection.
-
#initialize(uri, soc, config, is_established) ⇒ DRabSSLSocket
constructor
Create a DRab::DRabSSLSocket instance.
-
#stream ⇒ Object
Returns the SSL stream.
Methods inherited from DRabTCPSocket
#alive?, getservername, open_server_inaddr_any, #peeraddr, #recv_reply, #recv_request, #send_reply, #send_request, #set_sockopt, #shutdown
Constructor Details
#initialize(uri, soc, config, is_established) ⇒ DRabSSLSocket
Create a DRab::DRabSSLSocket instance.
uri is the URI we are connected to. soc is the tcp socket we are bound to. config is our configuration. Either a Hash or SSLConfig is_established is a boolean of whether soc is currently established
This is called automatically based on the DRab protocol.
306 307 308 309 |
# File 'lib/drab/ssl.rb', line 306 def initialize(uri, soc, config, is_established) @ssl = is_established ? soc : nil super(uri, soc.to_io, config) end |
Class Method Details
.open(uri, config) ⇒ Object
Return an DRab::DRabSSLSocket instance as a client-side connection, with the SSL connected. This is called from DRab::start_service or while connecting to a remote object:
DRab.start_service 'drabssl://localhost:0', front, config
uri is the URI we are connected to, 'drabssl://localhost:0' above, config is our configuration. Either a Hash or DRab::DRabSSLSocket::SSLConfig
249 250 251 252 253 254 255 256 257 258 |
# File 'lib/drab/ssl.rb', line 249 def self.open(uri, config) host, port, = parse_uri(uri) host.untaint port.untaint soc = TCPSocket.open(host, port) ssl_conf = SSLConfig::new(config) ssl_conf.setup_ssl_context ssl = ssl_conf.connect(soc) self.new(uri, ssl, ssl_conf, true) end |
.open_server(uri, config) ⇒ Object
Returns a DRab::DRabSSLSocket instance as a server-side connection, with the SSL connected. This is called from DRab::start_service or while connecting to a remote object:
DRab.start_service 'drabssl://localhost:0', front, config
uri is the URI we are connected to, 'drabssl://localhost:0' above, config is our configuration. Either a Hash or DRab::DRabSSLSocket::SSLConfig
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/drab/ssl.rb', line 269 def self.open_server(uri, config) uri = 'drabssl://:0' unless uri host, port, = parse_uri(uri) if host.size == 0 host = getservername soc = open_server_inaddr_any(host, port) else soc = TCPServer.open(host, port) end port = soc.addr[1] if port == 0 @uri = "drabssl://#{host}:#{port}" ssl_conf = SSLConfig.new(config) ssl_conf.setup_certificate ssl_conf.setup_ssl_context self.new(@uri, soc, ssl_conf, false) end |
.parse_uri(uri) ⇒ Object
Parse the dRuby uri for an SSL connection.
Expects drabssl://…
Raises DRabBadScheme or DRabBadURI if uri is not matching or malformed
228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/drab/ssl.rb', line 228 def self.parse_uri(uri) # :nodoc: if uri =~ /^drabssl:\/\/(.*?):(\d+)(\?(.*))?$/ host = $1 port = $2.to_i option = $4 [host, port, option] else raise(DRabBadScheme, uri) unless uri =~ /^drabssl:/ raise(DRabBadURI, 'can\'t parse uri:' + uri) end end |
.uri_option(uri, config) ⇒ Object
This is a convenience method to parse uri and separate out any additional options appended in the uri.
Returns an option-less uri and the option => [uri,option]
The config is completely unused, so passing nil is sufficient.
293 294 295 296 |
# File 'lib/drab/ssl.rb', line 293 def self.uri_option(uri, config) # :nodoc: host, port, option = parse_uri(uri) return "drabssl://#{host}:#{port}", option end |
Instance Method Details
#accept ⇒ Object
:nodoc:
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/drab/ssl.rb', line 323 def accept # :nodoc: begin while true soc = accept_or_shutdown return nil unless soc break if (@acl ? @acl.allow_socket?(soc) : true) soc.close end begin ssl = @config.accept(soc) rescue Exception soc.close raise end self.class.new(uri, ssl, @config, true) rescue OpenSSL::SSL::SSLError warn("#{__FILE__}:#{__LINE__}: warning: #{$!.message} (#{$!.class})") if @config[:verbose] retry end end |
#close ⇒ Object
Closes the SSL stream before closing the dRuby connection.
315 316 317 318 319 320 321 |
# File 'lib/drab/ssl.rb', line 315 def close # :nodoc: if @ssl @ssl.close @ssl = nil end super end |
#stream ⇒ Object
Returns the SSL stream
312 |
# File 'lib/drab/ssl.rb', line 312 def stream; @ssl; end |