Class: DRb::DRbSSLSocket
- Inherits:
-
DRbTCPSocket
- Object
- DRbTCPSocket
- DRb::DRbSSLSocket
- Defined in:
- lib/drb/ssl.rb
Overview
The protocol for DRb over an SSL socket
The URI for a DRb socket over SSL is: drbssl://<host>:<port>?<option>
. The option is optional
Defined Under Namespace
Classes: SSLConfig
Instance Attribute Summary
Attributes inherited from DRbTCPSocket
Class Method Summary collapse
-
.open(uri, config) ⇒ Object
Return an DRb::DRbSSLSocket instance as a client-side connection, with the SSL connected.
-
.open_server(uri, config) ⇒ Object
Returns a DRb::DRbSSLSocket instance as a server-side connection, with the SSL connected.
-
.parse_uri(uri) ⇒ Object
Parse the dRuby
uri
for an SSL connection. -
.uri_option(uri, config) ⇒ Object
This is a convenience method to parse
uri
and 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) ⇒ DRbSSLSocket
constructor
Create a DRb::DRbSSLSocket instance.
-
#stream ⇒ Object
Returns the SSL stream.
Methods inherited from DRbTCPSocket
#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) ⇒ DRbSSLSocket
Create a DRb::DRbSSLSocket 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 DRb protocol.
306 307 308 309 |
# File 'lib/drb/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 DRb::DRbSSLSocket instance as a client-side connection, with the SSL connected. This is called from DRb::start_service or while connecting to a remote object:
DRb.start_service 'drbssl://localhost:0', front, config
uri
is the URI we are connected to, 'drbssl://localhost:0'
above, config
is our configuration. Either a Hash or DRb::DRbSSLSocket::SSLConfig
249 250 251 252 253 254 255 256 257 258 |
# File 'lib/drb/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 DRb::DRbSSLSocket instance as a server-side connection, with the SSL connected. This is called from DRb::start_service or while connecting to a remote object:
DRb.start_service 'drbssl://localhost:0', front, config
uri
is the URI we are connected to, 'drbssl://localhost:0'
above, config
is our configuration. Either a Hash or DRb::DRbSSLSocket::SSLConfig
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/drb/ssl.rb', line 269 def self.open_server(uri, config) uri = 'drbssl://: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 = "drbssl://#{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 drbssl://…
Raises DRbBadScheme or DRbBadURI if uri
is not matching or malformed
228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/drb/ssl.rb', line 228 def self.parse_uri(uri) # :nodoc: if uri =~ /^drbssl:\/\/(.*?):(\d+)(\?(.*))?$/ host = $1 port = $2.to_i option = $4 [host, port, option] else raise(DRbBadScheme, uri) unless uri =~ /^drbssl:/ raise(DRbBadURI, '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/drb/ssl.rb', line 293 def self.uri_option(uri, config) # :nodoc: host, port, option = parse_uri(uri) return "drbssl://#{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/drb/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: #{$!.} (#{$!.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/drb/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/drb/ssl.rb', line 312 def stream; @ssl; end |