Skip to content

Commit

Permalink
Merge pull request #722 from cosmo0920/support-verify-hostname-parame…
Browse files Browse the repository at this point in the history
…ter-on-ssl_context

Support ssl_verify_hostname parameter to use OpenSSL::SSL::SSLContext#verify_hostname=
  • Loading branch information
geemus committed Jul 22, 2020
2 parents bd13540 + fa3ec51 commit c838a28
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/excon/constants.rb
Expand Up @@ -95,6 +95,7 @@ module Excon
:ssl_verify_callback,
:ssl_verify_peer,
:ssl_verify_peer_host,
:ssl_verify_hostname,
:ssl_version,
:ssl_min_version,
:ssl_max_version,
Expand Down
3 changes: 3 additions & 0 deletions lib/excon/ssl_socket.rb
Expand Up @@ -73,6 +73,9 @@ def initialize(data = {})
ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
end

# Verify certificate hostname if supported (ruby >= 2.4.0)
ssl_context.verify_hostname = @data[:ssl_verify_hostname] if ssl_context.respond_to?(:verify_hostname=)

if client_cert_data && client_key_data
ssl_context.cert = OpenSSL::X509::Certificate.new client_cert_data
if OpenSSL::PKey.respond_to? :read
Expand Down
17 changes: 17 additions & 0 deletions tests/basic_tests.rb
Expand Up @@ -138,6 +138,23 @@ def timed_streaming_test(endpoint, timeout)
end
end

Shindo.tests('Excon basics verify_hostname (ssl)') do
with_rackup('ssl.ru') do
connection = nil
test do
ssl_ca_file = File.join(File.dirname(__FILE__), 'data', '127.0.0.1.cert.crt')
connection = Excon.new('https://127.0.0.1:9443', :ssl_verify_peer => true, :ssl_ca_file => ssl_ca_file, :ssl_verify_hostname => true )
true
end

tests('response.status').returns(200) do
response = connection.request(:method => :get, :path => '/content-length/100')

response.status
end
end
end

Shindo.tests('Excon ssl verify peer (ssl)') do
with_rackup('ssl.ru') do
connection = nil
Expand Down

0 comments on commit c838a28

Please sign in to comment.