gpt4 book ai didi

Ruby Net::HTTP#ca_file 似乎没有用

转载 作者:太空宇宙 更新时间:2023-11-03 14:08:31 25 4
gpt4 key购买 nike

我的站点使用 StartCom ssl 证书,无法通过 ruby​​ 的 Net::HTTP 验证。我设置了ruby的Net::HTTP#ca_file,还是不行。

这是我的代码:

irb(main):007:0> uri = URI('https://blog.a1ex.wang')
=> #<URI::HTTPS https://blog.a1ex.wang>
irb(main):008:0> h=Net::HTTP.new(uri.host,uri.port)
=> #<Net::HTTP blog.a1ex.wang:443 open=false>
irb(main):009:0> h.use_ssl=true
=> true
irb(main):010:0> h.ca_file="/home/alexwang/keys/blog/ca.pem"
=> "/home/alexwang/keys/blog/ca.pem"
irb(main):011:0> h.start
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=error: certificate verify failed
from /home/alexwang/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:933:in `connect_nonblock'
from /home/alexwang/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:933:in `connect'
from /home/alexwang/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
from /home/alexwang/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:858:in `start'
from (irb):11
from /home/alexwang/.rvm/rubies/ruby-2.3.0/bin/irb:11:in `<main>'
irb(main):012:0>

但是使用 curl,SSL 验证似乎没问题。

> curl "https://blog.a1ex.wang" -I
curl: (60) server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn't adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you\'d like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.
[16:53:12] alexwang@alexwang-surbuntu /home/alexwang (60)
> curl "https://blog.a1ex.wang" --cacert keys/blog/ca.pem -I
HTTP/1.1 200 OK
Server: nginx/1.9.3 (Ubuntu)
Date: Sun, 20 Mar 2016 08:53:18 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Link: <https://blog.a1ex.wang/wp-json/>; rel="https://api.w.org/"

最佳答案

您必须在 ca.pem 中拥有链中的所有证书,而不仅仅是根证书。您的站点在链中有两个权限:

  • CN=StartCom 证书颁发机构
  • CN=StartCom 1 类 DV 服务器 CA

如果你在 ca.pem 中拥有两个权限,它就会起作用.

关于Ruby Net::HTTP#ca_file 似乎没有用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36111877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com