如何解决“证书验证失败”的问题在 Windows 上?

发布于 2024-11-02 11:10:58 字数 727 浏览 2 评论 0原文

我正在尝试使用 Signet 进行 Google 服务的 OAuth。并收到此错误:

SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

遵循以下问题:

看来解决方案是修复ca_path为SSL 设置VERIFY_NONE

发布的 ca_path 修复仅适用于 Linux(端口安装),而 VERIFY_NONE 的修复似乎适用于法拉第。

Windows/signet gem 有解决方案吗?

I am trying to use signet for OAuth to Google services. And get this error:

SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

Following these questions:

Seems the solution is either to fix ca_path or to set VERIFY_NONE for SSL.

The ca_path fix posted only works on Linux (port install) and the fix for VERIFY_NONE seems to be for faraday.

Is there a solution for Windows/signet gem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(15

绳情 2024-11-09 11:10:58

实际上,我发现在 Windows 中为 Ruby 本身(而不仅仅是一个 gem)解决此问题的最佳方法是执行以下操作:

  1. 下载 https://curl.haxx.se/ca/cacert.pem 进入 c:\railsinstaller\cacert.pem。确保将其保存为 .pem 文件,而不是文本文件。
  2. 转到您的计算机 ->高级设置->环境变量
  3. 创建一个新的系统变量:

    变量:SSL_CERT_FILE
    值:C:\RailsInstaller\cacert.pem

  4. 关闭所有命令提示符,包括 Rails 服务器命令提示符等。

  5. 启动新的 ruby​​ irb 提示符,然后尝试以下操作:

    $irb>需要“open-uri”
    $irb>open('https://www.gmail.com')
    

现在应该一切正常了。

Actually the best way I found to solve this in windows for Ruby itself, not just one gem, is to do the following:

  1. Download https://curl.haxx.se/ca/cacert.pem into c:\railsinstaller\cacert.pem. Make sure you save it as a .pem file, rather than a text file.
  2. Go to your Computer -> Advanced Settings -> Environment Variables
  3. Create a new System Variable:

    Variable: SSL_CERT_FILE
    Value: C:\RailsInstaller\cacert.pem

  4. Close all your command prompts, including your Rails server command prompt, etc.

  5. Start a new ruby irb prompt, and try the following:

    $irb>require 'open-uri'
    $irb>open('https://www.gmail.com')
    

It should all work now just fine.

得不到的就毁灭 2024-11-09 11:10:58

Windows 解决方案,我从几个不同的答案中拼凑而成:

  1. 下载 https://curl.haxx。 se/ca/cacert.pem 并将其放入 YOUR_APP/lib/assets (或任何位置)
  2. config/initializers/omniauth.rb

    <块引用>
    <前><代码>#config/initializers/omniauth.rb
    Rails.application.config.middleware.use OmniAuth::Builder 做
    提供商:facebook,CUSTOMER_KEY,CUSTOMER_SECRET,{client_options:{ssl:{ca_file:Rails.root.join('lib/assets/cacert.pem').to_s}}}
    结尾

  3. 显然,重新启动您的服务器。

脚注:
您也许可以删除 cacert.pem 文件中的许多不必要的证书以减小大小。如果您只需要此解决方案进行开发,则可以将该文件保存在项目之外,并使用 client_options hash_ else _provider 执行 if Rails.env.development? _provider 行没有 client_options hash_ end 的行

Solution for Windows, which I cobbled together from a few different answers:

  1. Download https://curl.haxx.se/ca/cacert.pem and put it in YOUR_APP/lib/assets (or wherever)
  2. In config/initializers/omniauth.rb:

     #config/initializers/omniauth.rb
    Rails.application.config.middleware.use OmniAuth::Builder do
      provider :facebook, CUSTOMER_KEY, CUSTOMER_SECRET, {client_options: {ssl: {ca_file: Rails.root.join('lib/assets/cacert.pem').to_s}}}
    end
    
  3. Obviously, restart your server.

Footnotes:
You might be able to cut out a lot of the unnecessary certificates in the cacert.pem file to reduce the size. If you only need this solution for development, you could save the file outside of your project and do a if Rails.env.development? _provider line with the client_options hash_ else _provider line without client_options hash_ end

萤火眠眠 2024-11-09 11:10:58

经过大量搜索和浪费时间后,我找到了一个非常简单的解决方案来解决 Windows 中的 Ruby 中的这个问题。

两个简单的步骤:

  1. 在命令提示符中写入:C:\gem install Certified

  2. 在您的 rb 文件中添加:require 'certified'

就是这样。

After too much searching and wasted time, I found a very simple solution to fix this issue in Ruby with Windows.

Two simple steps:

  1. In command prompt write: C:\gem install certified

  2. In your rb file add: require 'certified'

That's it.

叹沉浮 2024-11-09 11:10:58

更新 ruby​​gems 包管理框架在 Windows 7 上为我解决了这个问题。

https://rubygems.org/pages/download

gem update --system          # may need to be administrator or root

Updating the rubygems package management framework solved this issue for me on Windows 7.

https://rubygems.org/pages/download

gem update --system          # may need to be administrator or root
小草泠泠 2024-11-09 11:10:58

是的,我已将初始化程序文件夹中的omniouth.rb 文件设置为:

provider :facebook, FACEBOOK_KEY, FACEBOOK_SECRET, {:client_options => {:ssl => {:verify => false}}}

现在这似乎工作正常。但不要将其用于生产

yes, I've set the omniouth.rb file in the initializers folder to this:

provider :facebook, FACEBOOK_KEY, FACEBOOK_SECRET, {:client_options => {:ssl => {:verify => false}}}

and this seems to work fine now. But don't use this for production.

心碎的声音 2024-11-09 11:10:58

使用 http:// URL 而不是 https:// 可以让您更轻松地

将 gem 源更改为 http://rubygems.org / 通过在 ruby​​ 命令行上使用以下命令行

gem sources -a http://rubygems.org/

Using the http:// URL instead of https:// make this easier to you

Change the gem source to http://rubygems.org/ by using the following line of command on your ruby command line

gem sources -a http://rubygems.org/
吻风 2024-11-09 11:10:58

添加到 DevDude 的解决方案,但使用 Windows Powershell:

下载http://curl.haxx.se/ca/cacert.pem进入 c:\railsinstaller\cacert.pem

在 powershell 提示符下:

$env:SSL_CERT_FILE = 'c:\RailsInstaller\cacert.pem'

然后我就能够成功运行 gem update

注意:您可以简单地在您的配置文件 notepad $profile 中定义该环境变量

Adding onto DevDude's solution, but using Windows Powershell:

Download http://curl.haxx.se/ca/cacert.pem into c:\railsinstaller\cacert.pem

At the powershell prompt:

$env:SSL_CERT_FILE = 'c:\RailsInstaller\cacert.pem'

I was then able to run gem update successfully

Note: you can simply define that environment variable in your profile notepad $profile

究竟谁懂我的在乎 2024-11-09 11:10:58

转到 ruby​​gems-update 下载页面:https://rubygems.org/gems/rubygems-update

单击“下载”链接,您将下载一个名为 ruby​​gems-update-2.6.7.gem 的文件。在命令行中,导航到您下载 .gem 文件的目录并输入:(

gem install rubygems-update-2.6.7.gem

如果是较新的版本,则为任何文件名)

然后输入:

update_rubygems

您可以使用以下命令验证它是否已更新:

gem --version

Go to the rubygems-update download page: https://rubygems.org/gems/rubygems-update

Click on the Download link, and you'll download a file called rubygems-update-2.6.7.gem. At the command line, navigate to the directory you downloaded the .gem file to and type:

gem install rubygems-update-2.6.7.gem

(or whatever the filename was, if a newer version)

Then type:

update_rubygems

You can verify it's updated with:

gem --version
痴情换悲伤 2024-11-09 11:10:58

我在尝试在 Windows 机器上设置 Rails 5 时遇到此错误,结果我必须将 ruby​​gem 版本更新到 2.6.7,然后它就可以工作了。

第 1 步从下面下载 ruby​​gem

https://rubygems.org/downloads/rubygems-update-2.6.7.gem

第 2 步 - 通过指向下载的 ruby​​gem 进行安装

gem install --local C:\rubygems-update-2.6.7.gem

第 3 步 - 检查新版本是 2.6.7

gem --version

步骤4 - 现在安全地卸载 ruby​​gems-update gem

gem uninstall rubygems-update -x

第 5 步尝试再次安装 Rails 5

gem install rails --version 5.0.0

效果非常好!

我从以下地方得到信息:
http://guides.rubygems.org/ssl-certificate -update/#安装使用更新包

I had this error whilst trying to setup rails 5 on a windows machine, turns out I had to update the rubygem version to 2.6.7 and then it worked.

step 1 download rubygem from below

https://rubygems.org/downloads/rubygems-update-2.6.7.gem

step 2 - install by pointing to downloaded rubygems

gem install --local C:\rubygems-update-2.6.7.gem

step 3 - check new version is 2.6.7

gem --version

step 4 - now safely un-install rubygems-update gem

gem uninstall rubygems-update -x

step 5 tried to install rails 5 again

gem install rails --version 5.0.0

worked like a charm!

I got info from:
http://guides.rubygems.org/ssl-certificate-update/#installing-using-update-packages

怀里藏娇 2024-11-09 11:10:58

通过将证书导入为受信任的机构,我能够消除上面提到的路径或系统变量设置。

  1. 调用 certmgr.msc
  2. 右键单击​​受信任的根证书颁发机构文件夹。
  3. 选择“所有任务”
  4. 选择“导入”
  5. 在文件类型下拉列表中选择所有文件,然后选择 cacert.pem 文件。
  6. 您应该收到一条消息“导入成功”

I was able to eliminate the PATH or SYSTEM VARIABLE setting mentioned above by importing the certificate as a Trusted Authority.

  1. Invoke certmgr.msc
  2. Right-click the Trusted Root Certificate Authority folder.
  3. Select "All Tasks"
  4. Select "Import"
  5. Select All Files in file type dropdown and select the cacert.pem file.
  6. You should receive a message "Import Successful"
寂寞清仓 2024-11-09 11:10:58

我相信正确的答案是更新您的 gem 安装程序:rubygems-update。关于为什么需要这样做的解释可以在以下位置找到:Ssl 证书更新

I believe the correct answer is to update your gem installer: rubygems-update. The explanation for why this is needed is found at: Ssl Certificate Updates

錯遇了你 2024-11-09 11:10:58

https://curl.haxx.se/ca/cacert.pem 保存 cacert.pmp 文件 然后将此文件添加到 ruby​​ 安装文件夹\lib\ruby\2.3.0\rubygems\ssl_certs 的位置

,例如:C:\Ruby23\lib\ruby\2.3.0\rubygems\ssl_certs

save your cacert.pmp file from https://curl.haxx.se/ca/cacert.pem and then add this file to location yourruby-installation folder\lib\ruby\2.3.0\rubygems\ssl_certs

for example:C:\Ruby23\lib\ruby\2.3.0\rubygems\ssl_certs

寒冷纷飞旳雪 2024-11-09 11:10:58

这帮助了我:
https://coderwall.com/p/ubl6iw/fix-ssl_connect-returned-1-errno-0-state-sslv3-read-server-certificate-b-certificate-verify-失败-openssl-ssl-ssl错误
我的 ruby​​ on Rails 项目正在内部将数据发布到 api,并且无法验证内部证书。
这些线路有帮助:

require 'https'

http = Net::HTTP.new('example.com', 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER

http.cert_store = OpenSSL::X509::Store.new
http.cert_store.set_default_paths
http.cert_store.add_file('/path/to/internal.cert.pem')

希望这能有所帮助。

This helped me:
https://coderwall.com/p/ubl6iw/fix-ssl_connect-returned-1-errno-0-state-sslv3-read-server-certificate-b-certificate-verify-failed-openssl-ssl-sslerror
My ruby on rails project is posting data to an api internally, and it cannot verify the internal certificate.
These lines helped:

require 'https'

http = Net::HTTP.new('example.com', 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER

http.cert_store = OpenSSL::X509::Store.new
http.cert_store.set_default_paths
http.cert_store.add_file('/path/to/internal.cert.pem')

Hope this can help.

梦一生花开无言 2024-11-09 11:10:58

当我安装旧版本的 ruby​​ 时,我也遇到了这个问题。当我安装最新的 Ruby 版本时,这个问题就消失了。所以基本上 SSL 证书需要更新。

I was also facing this issue when I installed older ruby versions. When I installed the latest Ruby version this problem went away. So basically the SSL certificate needed to be updated.

划一舟意中人 2024-11-09 11:10:58

对于使用 Rails 4 的人。

将其添加到 devise.rb 中

require "omniauth-google-oauth2"
config.omniauth :google_oauth2, "CLIENT_ID", "CLIENT_SECRET", { access_type: "offline", approval_prompt: "", :client_options => {:ssl => {:verify => false}} }

For people who are using rails 4.

Add this in devise.rb

require "omniauth-google-oauth2"
config.omniauth :google_oauth2, "CLIENT_ID", "CLIENT_SECRET", { access_type: "offline", approval_prompt: "", :client_options => {:ssl => {:verify => false}} }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文