[英]How do I get an HTTPS request with SSL client cert to work with Ruby EventMachine?
我试图访问使用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,它给了我相同的错误。 运行EventMachine::HttpRequest#get
而不使用:ssl
选项也是如此。
我也尝试将请求发送到GMail( https://mail.google.com ),而不使用:ssl
选项(即没有证书的普通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提供类似的例子将非常感激!
传递给curl的--cert
的文件包含cert和key(除非你单独传入一个--key
)。 只需使用/tmp/private.key
作为参数:private_key_file
和:cert_chain_file
有关该问题的详细信息以及公开基础错误的补丁(而不是仅打印出SSL_incomp),请参阅http://github.com/eventmachine/eventmachine/issues/#issue/115 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.