Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow an ssl_context to be passed via :ssl_context in options to connect #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions lib/websocket-client-simple/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ def connect(url, options={})
@socket = TCPSocket.new(uri.host,
uri.port || (uri.scheme == 'wss' ? 443 : 80))
if ['https', 'wss'].include? uri.scheme
ctx = OpenSSL::SSL::SSLContext.new
ctx.ssl_version = options[:ssl_version] || 'SSLv23'
ctx.verify_mode = options[:verify_mode] || OpenSSL::SSL::VERIFY_NONE #use VERIFY_PEER for verification
cert_store = OpenSSL::X509::Store.new
cert_store.set_default_paths
ctx.cert_store = cert_store
@socket = ::OpenSSL::SSL::SSLSocket.new(@socket, ctx)
ssl_context = options[:ssl_context] || begin
ctx = OpenSSL::SSL::SSLContext.new
ctx.ssl_version = options[:ssl_version] || 'SSLv23'
ctx.verify_mode = options[:verify_mode] || OpenSSL::SSL::VERIFY_NONE #use VERIFY_PEER for verification
cert_store = OpenSSL::X509::Store.new
cert_store.set_default_paths
ctx.cert_store = cert_store
ctx
end

@socket = ::OpenSSL::SSL::SSLSocket.new(@socket, ssl_context)
@socket.connect
end
@handshake = ::WebSocket::Handshake::Client.new :url => url, :headers => options[:headers]
Expand Down