Ruby-on-rails 如何解决 Windows 上的“证书验证失败”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5720484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 00:57:52  来源:igfitidea点击:

How to solve "certificate verify failed" on Windows?

ruby-on-railsssl

提问by mbdev

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

我正在尝试将签名用于 OAuth 到 Google 服务。并得到这个错误:

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_pathor to set VERIFY_NONEfor SSL.

似乎解决方案是修复ca_path设置VERIFY_NONESSL

The ca_pathfix posted only works on Linux (port install) and the fix for VERIFY_NONEseems to be for faraday.

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

Is there a solution for Windows/signet gem?

Windows/signet gem 有解决方案吗?

回答by SomeDudeSomewhere

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

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

  1. Download https://curl.haxx.se/ca/cacert.peminto 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')
    
  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>require 'open-uri'
    $irb>open('https://www.gmail.com')
    

It should all work now just fine.

现在应该一切正常。

回答by Arcolye

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

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

  1. Download https://curl.haxx.se/ca/cacert.pemand 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.

  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 do
      provider :facebook, CUSTOMER_KEY, CUSTOMER_SECRET, {client_options: {ssl: {ca_file: Rails.root.join('lib/assets/cacert.pem').to_s}}}
    end
    
  3. 显然,重新启动您的服务器。

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

脚注:您可能可以在 cacert.pem 文件中删除大量不必要的证书以减小大小。如果您只需要此解决方案进行开发,您可以将文件保存在您的项目之外,并if Rails.env.development?使用 client_options hash_else_provider 行执行_provider 行而不使用 client_options hash_end

回答by Abdelrahman Farag

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

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

Two simple steps:

两个简单的步骤:

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

  2. In your rbfile add: require 'certified'

  1. 在命令提示符下写: C:\gem install certified

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

That's it.

就是这样。

回答by Aaron Robertson

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

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

https://rubygems.org/pages/download

https://rubygems.org/pages/download

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

回答by Tom

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

是的,我已将 initializers 文件夹中的 omniouth.rb 文件设置为:

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.

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

回答by nifCody

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

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

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

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

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

回答by nifCody

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

进入 ruby​​gems-update 下载页面: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:

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

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

回答by Kingsley Ijomah

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.

我在尝试在 Windows 机器上设置 rails 5 时遇到了这个错误,结果我不得不将 ruby​​gem 版本更新到 2.6.7 然后它工作了。

step 1 download rubygem from below

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

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

step 2 - install by pointing to downloaded rubygems

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

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

step 3 - check new version is 2.6.7

第 3 步 - 检查新版本是 2.6.7

gem --version

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

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

gem uninstall rubygems-update -x

step 5 tried to install rails 5 again

第 5 步尝试再次安装导轨 5

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

我从以下位置获得信息:http: //guides.rubygems.org/ssl-certificate-update/#installing-using-update-packages

回答by df2k2

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

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

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

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

At the powershell prompt:

在 powershell 提示符下:

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

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

I was then able to run gem updatesuccessfully

然后我就可以gem update成功运行了

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

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

回答by Charles Owen

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

通过将证书作为受信任的机构导入,我能够消除上面提到的 PATH 或 SYSTEM VARIABLE 设置。

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