gpt4 book ai didi

Ruby 和 OpenSSL 证书验证失败

转载 作者:太空宇宙 更新时间:2023-11-03 16:00:59 33 4
gpt4 key购买 nike

我很确定我已经尝试了一切。这是我要运行的代码

require 'rubygems'
require 'rest-client'
require 'json'

def vipr_session(viprurl, username, password)
vipr_session_link = RestClient::Resource.new(viprurl + '/login', username, password)
vipr_session_response = vipr_session_link.get
myvar = 'x_sds_auth_token'
@mysession = vipr_session_link.headers[myvar.to_sym]
end

@username = 'root'
@password = 'mypw'
@viprurl = 'https://192.168.50.141:4443'

print " Logging into ViPR..."
vipr_session(@viprurl, @username, @password)
print "Success! \n\n\n"
puts @mysession
storagesystems = JSON.parse(RestClient.get(@viprurl + '/vdc/storage-systems', :x_sds_auth_token => @mysession, :content_type => :json, :accept => :json))
puts storagesystems

这里是错误

kcoleman-mbp:vipr_scripts kcoleman$ ruby storage_systems.rb
Logging into ViPR.../Users/kcoleman/.rvm/gems/ruby-2.1.2/gems/rest-client-1.7.2/lib/restclient/request.rb:445:in `rescue in transmit': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (RestClient::SSLCertificateNotVerified)
from /Users/kcoleman/.rvm/gems/ruby-2.1.2/gems/rest-client-1.7.2/lib/restclient/request.rb:350:in `transmit'
from /Users/kcoleman/.rvm/gems/ruby-2.1.2/gems/rest-client-1.7.2/lib/restclient/request.rb:176:in `execute'
from /Users/kcoleman/.rvm/gems/ruby-2.1.2/gems/rest-client-1.7.2/lib/restclient/request.rb:41:in `execute'
from /Users/kcoleman/.rvm/gems/ruby-2.1.2/gems/rest-client-1.7.2/lib/restclient/resource.rb:51:in `get'
from storage_systems.rb:8:in `vipr_session'
from storage_systems.rb:18:in `<main>'

我可以通过在 RestClient 中设置 verify_ssl: false 来完成这项工作,但这段代码之前一直有效,但突然间它不再有效了。

这是我尝试修复的方法:

rvm osx-ssl-certs update all
brew install openssl
brew link openssl --force
brew tap raggi/ale
brew install openssl-osx-ca
rvm pkg install openssl
curl http://curl.haxx.se/ca/cacert.pem -o /usr/local/etc/openssl/cert.pem

这是我当前的配置

kcoleman$ which openssl
/usr/local/bin/openssl
kcoleman$ openssl version
OpenSSL 1.0.1i 6 Aug 2014

我遇到了这篇文章 SSLError and Rubyist, sitting in a tree这是 doctor.rb 脚本的输出。

kcoleman-mbp:ssl-tools kcoleman$ ruby doctor.rb 192.168.50.141:4443
/Users/kcoleman/.rvm/rubies/ruby-2.1.2/bin/ruby (2.1.2-p95)
OpenSSL 1.0.1g 7 Apr 2014: /etc/openssl
SSL_CERT_DIR=""
SSL_CERT_FILE=""

HEAD https://192.168.50.141:4443
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

The server presented a certificate that could not be verified:
subject: /CN=192.168.50.140
issuer: /CN=192.168.50.140
error code 18: self signed certificate

看起来 ruby​​ 使用的是与 RVM 打包在一起的不同版本的 OpenSSL。通过在 rvm 上运行 openssl install 进行验证。

kcoleman-mbp:vipr_scripts kcoleman$ rvm pkg install openssl

Beware, 'rvm pkg ...' is deprecated, read about the new autolibs feature: 'rvm help autolibs'.

Checking requirements for osx.
Certificates in '/usr/local/etc/openssl/cert.pem' are already up to date.
Requirements installation successful.
Fetching openssl-1.0.1g.tar.gz to /Users/kcoleman/.rvm/archives
Extracting openssl to /Users/kcoleman/.rvm/src/openssl-1.0.1g....
Configuring openssl in /Users/kcoleman/.rvm/src/openssl-1.0.1g.......................
Compiling openssl in /Users/kcoleman/.rvm/src/openssl-1.0.1g...........................................................................................-
Installing openssl to /Users/kcoleman/.rvm/usr

如果您对尝试什么有任何想法,我们将不胜感激。

最佳答案

HEAD https://192.168.50.141:4443OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failedThe server presented a certificate that could not be verified:  subject: /CN=192.168.50.140  issuer: /CN=192.168.50.140  error code 18: self signed certificate

您的证书有几个问题导致验证失败:

  • 该证书是自签名的,因此无法根据本地信任 anchor 进行检查。接受此类证书等同于接受某人为自己创建的任何护照,而不仅仅是受信任的政府颁发的护照。
  • 证书主题与您用来连接它的名称不匹配。该证书适用于 192.168.50.140,但您以 192.168.50.141 访问主机(证书中可能还有更多 IP 作为主题备用名称,此处未显示)。不核对证件上的姓名等同于不核对护照上的照片与护照出示人。

关于Ruby 和 OpenSSL 证书验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25395964/

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