我只是试图了解SSL.
我在localhost上设置了一个Jetty服务器,并使用Keytool生成了我自己的证书.
现在,当我去https:// localhost:8443 /我得到的不能相信这个证书错误.
我用
keytool -export -alias pongus -keystore keystore -file certfile.cer
创建我认为是客户端需要对服务器进行身份验证的证书.(这是我可能非常错的地方!)
我有以下ruby代码:
require 'net/https'
require 'openssl'
require 'open-uri'
puts 'yay' if File.exists?('certfile.cer')
uri = URI.parse("https://localhost:8443/")
http_session = Net::HTTP.new(uri.host, uri.port)
http_session.use_ssl = true
http_session.verify_mode = OpenSSL::SSL::VERIFY_PEER
http_session.ca_file = 'certfile.cer'
res = http_session.start do |http|
# do some requests here
http.get('/')
end
Run Code Online (Sandbox Code Playgroud)
这会打印'yay',因此certfile.cer文件确实存在.
但是我得到了错误
/Applications/NetBeans/NetBeans 6.8.app/Contents/Resources/NetBeans/ruby2/jruby-1.4.0/lib/ruby/1.8/net/http.rb:586 warning: can't set verify locations
/Applications/NetBeans/NetBeans 6.8.app/Contents/Resources/NetBeans/ruby2/jruby-1.4.0/lib/ruby/1.8/net/http.rb:586:in `connect': certificate verify failed (OpenSSL::SSL::SSLError)
Run Code Online (Sandbox Code Playgroud)
我有什么想法我做错了吗?
编辑
我想得到它所以我保证我连接到正确的服务器,服务器可以保证我连接到它,没有任何篡改.我正在开发服务器和客户端.