Skip to content

Commit

Permalink
Merge pull request #379 from lmars/ssl-verify-callback
Browse files Browse the repository at this point in the history
Support setting ssl_verify_callback
  • Loading branch information
geemus committed Apr 24, 2014
2 parents 383341a + 12437b7 commit 206677d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/excon/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ module Excon
:scheme,
:socket,
:ssl_ca_file,
:ssl_verify_callback,
:ssl_verify_peer,
:ssl_version,
:tcp_nodelay,
Expand Down
2 changes: 1 addition & 1 deletion lib/excon/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SocketError < Error

def initialize(socket_error=nil)
if socket_error.message =~ /certificate verify failed/
super("Unable to verify certificate, please set `Excon.defaults[:ssl_ca_path] = path_to_certs`, `ENV['SSL_CERT_DIR'] = path_to_certs`, `Excon.defaults[:ssl_ca_file] = path_to_file`, `ENV['SSL_CERT_FILE'] = path_to_file` or `Excon.defaults[:ssl_verify_peer] = false` (less secure).")
super("Unable to verify certificate, please set `Excon.defaults[:ssl_ca_path] = path_to_certs`, `ENV['SSL_CERT_DIR'] = path_to_certs`, `Excon.defaults[:ssl_ca_file] = path_to_file`, `ENV['SSL_CERT_FILE'] = path_to_file`, `Excon.defaults[:ssl_verify_callback] = callback` (see OpenSSL::SSL::SSLContext#verify_callback), or `Excon.defaults[:ssl_verify_peer] = false` (less secure).")
else
super("#{socket_error.message} (#{socket_error.class})")
end
Expand Down
4 changes: 4 additions & 0 deletions lib/excon/ssl_socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def initialize(data = {})
Excon.display_warning("Excon unable to add file to cert store, ignoring: #{ca_file}\n[#{e.class}] #{e.message}")
end
end

if verify_callback = @data[:ssl_verify_callback]
ssl_context.verify_callback = verify_callback
end
else
# turn verification off
ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
Expand Down

0 comments on commit 206677d

Please sign in to comment.