Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Merge 9983f68 into 2d92a6b
Browse files Browse the repository at this point in the history
  • Loading branch information
thijsc committed Aug 25, 2014
2 parents 2d92a6b + 9983f68 commit a525ad3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/moped/connection.rb
Expand Up @@ -47,7 +47,7 @@ def alive?
# @since 1.0.0
def connect
@sock = if !!options[:ssl]
Socket::SSL.connect(host, port, timeout)
Socket::SSL.connect(host, port, timeout, options[:ssl])
else
Socket::TCP.connect(host, port, timeout)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/moped/connection/socket/connectable.rb
Expand Up @@ -139,10 +139,10 @@ module ClassMethods
# @return [ TCPSocket ] The socket.
#
# @since 1.0.0
def connect(host, port, timeout)
def connect(host, port, timeout, options=nil)
begin
Timeout::timeout(timeout) do
sock = new(host, port)
sock = new(host, port, options)
sock.set_encoding('binary')
timeout_val = [ timeout, 0 ].pack("l_2")
sock.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
Expand Down
23 changes: 21 additions & 2 deletions lib/moped/connection/socket/ssl.rb
Expand Up @@ -19,11 +19,30 @@ class SSL < OpenSSL::SSL::SSLSocket
# @param [ Integer ] port The port.
#
# @since 1.2.0
def initialize(host, port)
def initialize(host, port, options)
@host, @port = host, port
handle_socket_errors do
@socket = TCPSocket.new(host, port)
super(socket)

context = OpenSSL::SSL::SSLContext.new
if options.is_a?(Hash)
if options['ca_path']
context.ca_path = options['ca_path']
elsif options['ca_file']
context.ca_file = options['ca_file']
else
store = OpenSSL::X509::Store.new
store.set_default_paths
context.cert_store = store
end

if options.has_key?('client_cert') && options.has_key?('client_key')
context.cert = OpenSSL::X509::Certificate.new(File.read(options['client_cert']))
context.key = OpenSSL::PKey::RSA.new(File.read(options['client_key']))
end
end

super(socket, context)
self.sync_close = true
connect
end
Expand Down
2 changes: 1 addition & 1 deletion lib/moped/connection/socket/tcp.rb
Expand Up @@ -15,7 +15,7 @@ class TCP < ::TCPSocket
# @param [ Integer ] port The port.
#
# @since 1.2.0
def initialize(host, port)
def initialize(host, port, options)
@host, @port = host, port
handle_socket_errors { super }
end
Expand Down
3 changes: 2 additions & 1 deletion lib/moped/session.rb
Expand Up @@ -225,10 +225,11 @@ def logout
# @since 2.0.0
option(:down_interval).allow(Optionable.any(Numeric))

# Setup validation of allowed ssl options. (Any boolean)
# Setup validation of allowed ssl options. (Any boolean or Hash)
#
# @since 2.0.0
option(:ssl).allow(true, false)
option(:ssl).allow(Optionable.any(Hash))

# Setup validation of allowed timeout options. (Any numeric)
#
Expand Down

0 comments on commit a525ad3

Please sign in to comment.