OpenSSL::SSL::SSLError on Heroku [duplicate]

大憨熊 提交于 2019-11-26 07:28:59

问题


This question already has an answer here:

  • SSL Error When installing rubygems, Unable to pull data from 'https://rubygems.org/ 24 answers

I\'m trying to authenticate a user via Facebook or Twitter, get them to fill out their information, and then click save (thus creating a user record). I\'m getting an OpenSSL error on that final step -- after clicking save. This happens at the Devise RegistrationsController#create method.

So I\'m getting this error in my Rails application, hosted on Heroku:

2012-07-28T18:25:13+00:00 app[web.1]: OpenSSL::SSL::SSLError (SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed)

I\'ve seen plenty of solutions, none of them work. Here are some things I\'ve tried:

1) Installing the certified gem

2) Upgrading the Heroku gem to v2.30, pushing again

3) This:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :twitter, TWITTER_KEY, TWITTER_SECRET, {:client_options => {:ssl => {:ca_file => \"/usr/lib/ssl/certs/ca-certificates.crt\"}}}
  provider :facebook, FACEBOOK_KEY, FACEBOOK_SECRET, {:scope => \"publish_actions,user_location,email\", :client_options => {:ssl => {:ca_file => \"/usr/lib/ssl/certs/ca-certificates.crt\"}}}
end

It seems like one problem could be that this cert file doesn\'t actually exist -- I\'ve seen it in several places, and it seems like that is the default path to the ca_cert file for Heroku, but I could be wrong.

Oddly enough, this is happening after I\'ve already authenticated via FB/Twitter, and am trying to create a user\'s account. Why would this be, and how can I solve/debug this? Sincerely confused.

Update: I added this line to the Omniauth initializer, and now it \"works\". Thus I\'ve diagnosed the problem is with Omniauth. However, I\'d like to still have the SSL verification... this obviously leaves a security gap.

OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE


回答1:


After some searching here is what I found:

If you’re using Ruby to open connections to an external server over https, eg. the Facebook Graph API, you may run into the following error:

OpenSSL::SSL::SSLError:SSL_connectreturned=1errno=0state=SSLv3readservercertificateB:certificateverifyfailed

This error is due to Ruby not being able to find the certification authority certificates (CA Certs) used to verify the authenticity of secured web servers. The solution is to download the this ca-bundle.crt into your application’s lib/ directory: Then add the following code to config/initializers/fix_ssl.rb:

require 'open-uri'
require 'net/https'

module Net
  class HTTP
    alias_method :original_use_ssl=, :use_ssl=

    def use_ssl=(flag)
      self.ca_file = Rails.root.join('lib/ca-bundle.crt').to_s
      self.verify_mode = OpenSSL::SSL::VERIFY_PEER
      self.original_use_ssl = flag
    end
  end
end

This should force ruby to use the CA bundle from your application’s lib/ directory.

Taken from: http://jimneath.org/2011/10/19/ruby-ssl-certificate-verify-failed.html

UPDATE:

You may need to use self.ca_path= instead of self.ca_file= depending on your system.




回答2:


It sounds like you've got the right openssl configuration in OmniAuth, but perhaps your CA certs path isn't correct?

You can check that on your heroku servers by running:

heroku run bash

... and then running openssl to display the proper path:

$ openssl version -a
OpenSSL 1.0.0e 6 Sep 2011
OPENSSLDIR: "/usr/lib/ssl"

... You should find the ca_certificates.crt file at $OPENSSLDIR/certs/ca-certificates.crt

I would confirm that path an update your code to match.



来源:https://stackoverflow.com/questions/11703679/opensslsslsslerror-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!