我很确定我已经在阳光下尝试过一切。这是我要运行的代码
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 和 Rubyist,坐在一棵树上,这是医生.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
如果您对尝试什么有任何想法,我们将不胜感激。