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

Auto-reconnection does not work on SNI #62

Open
dissolve opened this issue Nov 1, 2014 · 5 comments
Open

Auto-reconnection does not work on SNI #62

dissolve opened this issue Nov 1, 2014 · 5 comments
Labels

Comments

@dissolve
Copy link

dissolve commented Nov 1, 2014

When I establish a connection to a site that uses SNI (and the key returned by the request is not usable) and then try to re-use that connection after 300 seconds, I get an error that the certificate does not match the hostname. Watching from wireshark confirmed, that on the initial request the certificate for *.shanske.com is returned, however after 5 minutes, the certificate for weneca.com is returned (the server's main key, same as would be returned without SNI). So it would seem that the reconnection is not including the hostname.

To reproduce

require 'net/http/persistent'
http = Net::HTTP::Persistent.new
uri = URI 'https://david.shanske.com'
response = http.request uri
sleep 310 
response = http.request uri
OpenSSL::SSL::SSLError: hostname "david.shanske.com" does not match the server certificate
        from /usr/lib64/ruby/2.1.0/openssl/ssl.rb:139:in `post_connection_check'
        from /usr/lib64/ruby/2.1.0/net/http.rb:922:in `connect'
        from /usr/lib64/ruby/2.1.0/net/http.rb:863:in `do_start'
        from /usr/lib64/ruby/2.1.0/net/http.rb:858:in `start'
        from /usr/lib64/ruby/gems/2.1.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:700:in `start'
        from /usr/lib64/ruby/gems/2.1.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:965:in `reset'
        from /usr/lib64/ruby/gems/2.1.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:628:in `connection_for'
        from /usr/lib64/ruby/gems/2.1.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:994:in `request'
@drbrain
Copy link
Owner

drbrain commented Nov 21, 2014

This is a ruby bug:

require 'net/http'
uri = URI 'https://david.shanske.com'

Net::HTTP.start uri.hostname, uri.port, use_ssl: true do |http|
  req = Net::HTTP::Get.new uri
  response = http.request req
  p response.code
  sleep 310
  req = Net::HTTP::Get.new uri
  response = http.request req
  p response.code
end
$ ruby test.rb
"200"
/usr/local/lib/ruby/2.1.0/openssl/ssl.rb:139:in `post_connection_check': hostname "david.shanske.com" does not match the server certificate (OpenSSL::SSL::SSLError)
        from /usr/local/lib/ruby/2.1.0/net/http.rb:922:in `connect'
        from /usr/local/lib/ruby/2.1.0/net/http.rb:1447:in `begin_transport'
        from /usr/local/lib/ruby/2.1.0/net/http.rb:1404:in `transport_request'
        from /usr/local/lib/ruby/2.1.0/net/http.rb:1378:in `request'
        from test.rb:10:in `block in <main>'
        from /usr/local/lib/ruby/2.1.0/net/http.rb:853:in `start'
        from /usr/local/lib/ruby/2.1.0/net/http.rb:583:in `start'
        from test.rb:4:in `<main>'

@drbrain drbrain added the Bug label Nov 21, 2014
@drbrain
Copy link
Owner

drbrain commented Nov 21, 2014

I have created Bug #10533 and will work on a fix there.

@drbrain
Copy link
Owner

drbrain commented Nov 21, 2014

The bug is due to session resumption. I'll see what I can do to patch it via net-http-persistent until a release with the patch to Net::HTTP is available.

@mariusmarais
Copy link

Just got bitten hard by this issue :) Any progress on a workaround?

@lukad03
Copy link

lukad03 commented Jul 19, 2016

Any progress on this issue?

EDIT: This issue may no longer be relevant: https://github.com/drbrain/net-http-persistent/blob/master/lib/net/http/persistent/ssl_reuse.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants