【发布时间】:2010-10-27 23:49:39
【问题描述】:
我正在尝试使用 Ruby EventMachine 访问使用 SSL 证书身份验证的 HTTPS Web 服务,但我没有让它工作。
我编写了以下简单的代码块来对其进行端到端测试:
require 'rubygems'
require 'em-http'
EventMachine.run do
url = 'https://foobar.com/'
ssl_opts = {:private_key_file => '/tmp/private.key',
:cert_chain_file => '/tmp/ca.pem',
:verify_peer => false}
http = EventMachine::HttpRequest.new(url).get :ssl => ssl_opts
http.callback do
p http.response_header.status
p http.response_header
p http.response
EventMachine.stop
end
http.errback do
EventMachine.stop
fail "Request failed"
end
end
运行上述输出 <SSL_incomp> 后跟引发的 RuntimeError 消息。我尝试将 :verify_peer 设置为 true 和 false 运行,它给了我同样的错误。在没有 :ssl 选项的情况下运行 EventMachine::HttpRequest#get 也是如此。
我还尝试在没有 :ssl 选项(即没有证书的普通 HTTPS)的情况下向 GMail (https://mail.google.com) 发送请求,并且可以输出状态代码 200、标题和正文。
我尝试使用 curl 对 Web 服务执行相同的请求,并且效果很好:
curl --silent --cert /tmp/private.key --cacert /tmp/ca.pem https://foobar.com/
我认为我错误地使用了 em-http-request gem 或 EventMachine,或者 SSL 文件的格式适用于 curl 但不适用于 EventMachine。
如果有人知道如何解决上述示例或直接使用 EventMachine 提供类似示例,将不胜感激!
【问题讨论】:
标签: ruby ssl-certificate eventmachine