我正在尝试使用Ruby EventMachine访问使用SSL cert身份验证的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选项的情况下将请求发送到GMail (https://mail.google.com) (例如,没有证书的普通HTTPS ),并且可以正常工作,输出状态代码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将不胜感激!
发布于 2010-10-31 13:17:52
传递给curl的--cert的文件包含证书和密钥(除非单独传入--key )。只需将/tmp/private.key用作:private_key_file和:cert_chain_file的参数
有关该问题的更多详细信息,请参阅http://github.com/eventmachine/eventmachine/issues/#issue/115,以及可暴露潜在错误的补丁(而不仅仅是打印出SSL_incomp)。
https://stackoverflow.com/questions/4038636
复制相似问题