簡體   English   中英

OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate)

[英]OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate)

有很多關於這個的帖子。 我看過很多。 零個修復程序似乎有效。

(main)> PayPal::SDK::Subscriptions::Plan.all
Request[post]: https://api.sandbox.paypal.com/v1/oauth2/token
Request.body=grant_type=client_credentials  request.header={"User-Agent"=>"PayPalSDK/PayPal-Subscriptions-Ruby-SDK 0.3.1 (paypal-sdk-core 1.7.4; ruby 2.6.6p146-x86_64-linux;OpenSSL 1.1.1d  10 Sep 2019)", "Content-Type"=>"application/x-www-form-urlencoded", "Authorization"=>"Basic xxx"}
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate)
from /usr/local/lib/ruby/2.6.0/net/protocol.rb:44:in `connect_nonblock'

我試過 rvm 2.6.6、2.7.0 和 Debian Buster 系統 ruby。

我遵循了所有這些: https://bundler.io/v2.0/guides/rubygems_tls_ssl_troubleshooting_guide.html#troubleshooting-certificate-errors

我運行了自動 SSL 檢查,一切順利: https://bundler.io/v2.0/guides/rubygems_tls_ssl_troubleshooting_guide.html#automated-ssl-check

root@19ab47f15632:/usr/src/app# curl -Lks 'https://git.io/rg-ssl' | ruby
Here's your Ruby and OpenSSL environment:

Ruby:           2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]
RubyGems:       3.0.3
Bundler:        2.1.2
Compiled with:  OpenSSL 1.1.1d  10 Sep 2019
Loaded version: OpenSSL 1.1.1d  10 Sep 2019
SSL_CERT_FILE:  /usr/lib/ssl/cert.pem
SSL_CERT_DIR:   /usr/lib/ssl/certs

With that out of the way, let's see if you can connect to rubygems.org...

Bundler connection to rubygems.org:       success ✅
RubyGems connection to rubygems.org:      success ✅
Ruby net/http connection to rubygems.org: success ✅

Hooray! This Ruby can connect to rubygems.org. You are all set to use Bundler and RubyGems. 👌

我試過gem update --system ,捆綁器已更新。

我嘗試將新 CA 卷曲到 ruby 的默認 SSL 文件的位置:

curl -fsSL curl.haxx.se/ca/cacert.pem -o "$(ruby -ropenssl -e 'puts OpenSSL::X509::DEFAULT_CERT_FILE')"

我檢查了我的系統時間是否准確(准確到 UTC)。

我不知道從這里做什么。 PayPal SDK 訂閱 gem 在幕后使用 .net/http,因為它依賴於核心 PayPal SDK gem。 我嘗試將日志級別提高到 DEBUG,但它沒有打印出任何額外的詳細信息,因為它似乎在同一個確切的地方失敗了,而且我無法弄清楚那個失敗到底在哪里。

我不知所措。 除了禁用 SSL 驗證,我不知道該怎么做。 有沒有辦法在此處獲得更多回溯/更多錯誤以進一步排除故障? 直接對 PayPal API 使用 .net/http 工作正常(沒有 SSL 錯誤)。 所以這是在初始請求之后發生的事情

可以通過使用服務器自己的 CA 文件來修復此問題。

嘗試設置ssl_options: { ca_file: nil }

這會導致與 paypal-sdk gem 捆綁在一起的paypal.crt CA 文件被忽略。

對於使用 PayPal::SDK.configure(...) 的應用

PayPal::SDK.configure(
  mode: ...,
  client_id: ...,
  client_secret: ...,

  # Deliberately set ca_file to nil so the system's Cert Authority is used,
  # instead of the bundled paypal.crt file which is out-of-date due to:
  # https://www.paypal.com/va/smarthelp/article/discontinue-use-of-verisign-g5-root-certificates-ts2240
  ssl_options: { ca_file: nil }
)

對於使用 YAML 配置文件的應用程序

config/paypal.yml或您的配置文件所在的任何位置:

ssl_options:
  ca_file: null

我把它留在這里,但 RidingRails 的回答是我認為“正確”的。 這是處理這種長期問題的正確解決方案,盡管真正的解決方案是轉移到 PayPal 的更新 gem。

我在下面的回答是為了幫助您快速使 PayPal 重新工作,而無需推出代碼更新。


這真的很難看,因為 PayPal 將證書與他們的 gem 打包在一起。 要啟動並運行,您需要在您的包中找到 gem,特別是找到文件“paypal.crt”。 最后,您需要添加缺少的兩個證書。 我不打算在這里復制/粘貼它們,但它們很容易找到。 實際上,它們已經在我的 Ubuntu 系統的 /etc/ssl/certs 中:

DigiCert_Global_Root_G2.pem

DigiCert_High_Assurance_EV_Root_CA.pem

PayPal 在這里提供鏈接:

https://www.paypal.com/va/smarthelp/article/discontinue-use-of-verisign-g5-root-certificates-ts2240

修復步驟:

  1. 在您使用的 gem 版本中找到 paypal.crt 文件。 這對我來說是這樣的:

    cd 應用程序/生產/共享/捆綁包

    尋找。 -名稱 paypal.crt

    此時,我在 gem 的 1.7.3 和 1.7.4 版本中有一個文件。 我使用的是 1.7.4 版本,所以我編輯了那個文件。

  2. 將這兩個證書添加到底部。 您應該將證書的名稱放在一行中,一行重復“=”以形成一個很好的分隔符,然后是包括 BEGIN 和 END 行的整個證書。

  3. 重新啟動您的應用程序。

這不是一個長期的解決方案,但可以讓您快速恢復運行。 長期 - 升級到新的寶石。

這是我們最終在我的團隊中所做的事情。

我們添加了 Michael 在中提到的 2 個證書

config/api.paypal.com.crt

然后在 paypal.yml

 ssl_options:
    ca_file: config/api.paypal.com.crt

我們按原樣離開了寶石。 最初我們通過 gem 來尋找答案,但最終我們保留了 gem 並添加了 crt 並更新了 yaml,如上所示。

如果您不使用PayPal::SDK.configure 在paypal.yml中添加

  ssl_options:
    ca_file: null

由於 PayPal 已更改 TLS,因此最簡單(最快)的方法是解析為猴子補丁。 這個補丁說要使用所有默認設置

module PayPal::SDK::Core
  module Util
    module HTTPHelper
      def configure_ssl(http)
        http.tap do |https|
          https.use_ssl = true
          https.verify_mode = OpenSSL::SSL::VERIFY_PEER
          add_certificate(https)
        end
      end
    end
  end
end

與@kritik 類似但侵入性略小的解決方案

module PayPal::SDK::Core::Util::HTTPHelper
  def default_ca_file
    nil # packaged CA file was out of date, use the system file
  end
end

這仍然允許您更改初始化程序中的其他 SSL 設置,並且僅刪除默認的 CA 文件。

你想在config/initializers中創建一個文件,並將上面的代碼放入其中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM