找不到有效的 gem 'rhc'。 SSL_connect Windows 服务器证书验证失败,无法连接 OpenShift 服务器

Could not find a valid gem 'rhc'. SSL_connect server certificate verify failed on Windows, Unable to connect OpenShift Server

C:\>gem install rhc

ERROR: Could not find a valid gem 'rhc' (>= 0), here is why: Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://rubygems.org/latest_specs.4.8.gz)

尝试了以下命令:

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

但是在尝试设置 rhc 时仍然存在同样的错误。

rhc setup

按照these steps rhc gem 安装成功,但是执行"rhc setup" 连接openshift 时这里是错误信息,而不是连接到openshift server

问题是您的 Windows 机器无法将 ruby​​gems 服务器证书识别为受信任的证书,因为 Windows 其受信任的证书库中没有其授权证书。

作为快速修复,您需要删除 ruby​​gems 源的 HTTPS 版本 URL(不像您那样删除 HTTP):

gem sources -r https://rubygems.org

此快速修复应使 ruby​​gems 使用不涉及证书检查的 HTTP 版本。

但是这不应该是最终的解决方法。相反,您应该添加回 HTTPS 源(使用 -a 选项)并将 ruby​​gems 服务器证书的正确 CA 证书安装到您的 windows 受信任的 CA 证书存储中。

网上有很多页面介绍此过程(google this), e.g. the post here 有从 curl 命令下载和安装所有 CA 证书的步骤,到您的Windows 台机器,可永久解决问题且不会降低安全性。

说明了问题的原因和解决方法here

Previously, this certificate was provided by one Certificate Authority, but the new certificate is provided by a different one.

Because of this, verions of RubyGems with both certificates were released, in an attempt to simplify the change.

However, at the scale RubyGems operates at, it’s impossible to make sure everybody updates the software. There are also operating systems shipping with old versions. As such, sometimes manual intervention (as described above) is required.

This has been described on Issue #1050

要解决此问题,请按照下列步骤操作:

  1. 下载rubygems-update-2.6.7.gem。下载应保存在您以后可以轻松指向的位置。让我们使用 C:\rubygems-update-2.6.7.gem

  2. 在命令行中,运行以下命令:
    C:\>gem install --local C:\rubygems-update-2.6.7.gem

    C:\>update_rubygems --no-ri --no-rdoc

  3. 运行 卸载rubygems-update的命令如下:
    C:\>gem uninstall rubygems-update -x

这应该可以解决问题。