具有HTTPS,SSL客户端证书和Keep-Alive支持的Ruby的HTTP库? [英] HTTP library for Ruby with HTTPS, SSL Client Certificate and Keep-Alive support?

查看:145
本文介绍了具有HTTPS,SSL客户端证书和Keep-Alive支持的Ruby的HTTP库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Ruby中编写HTTPS客户端。它将使用HTTPS连接到服务器,传递身份验证令牌(通过单独的登录过程获得)和SSL客户端证书。

I'm trying to write an HTTPS client in Ruby. It will connect to the server using HTTPS, passing an authentication token (obtained through a separate login process) and an SSL client certificate.

我正在执行以下操作< a href =https://github.com/rest-client/rest-client/ =noreferrer> rest-client :

client = RestClient::Resource.new(url,
                         :ssl_client_cert  =>  OpenSSL::X509::Certificate.new(File.read('./certificate/client-2048.pem')),
                         :ssl_client_key   =>  OpenSSL::PKey::RSA.new(File.read('./certificate/client-2048.key'), ''),
                         :verify_ssl       =>  OpenSSL::SSL::VERIFY_NONE)

# ...

headers = {
  'X-Application' => APP_KEY,
  'X-Authentication' => @session_token,
  'content-type' => 'application/json',
  'Accept' => 'application/json'
}

response = client.post(request, headers)

这样可行,但我想做的是使用keep-alive,以避免每次我想提出请求时都要完成启动连接的整个过程。所涉及的延迟使我正在编写的监控应用程序的用处不那么有用。

This works, but what I'd like to do is use keep-alive to avoid having to go through the whole process of bringing up the connection each time I want to make a request. The delay involved makes the monitoring application I'm writing much less useful.

然而,我无法似乎找到的是Ruby提供以下内容的库:

However, what I can't seem to find is a Ruby library that offers the following:


  • HTTPS支持

  • SSL客户端证书支持

  • Keep-Alive

有一个拉取请求正在为应该提供它的休息客户而苦苦挣扎。 httparty persistent_httparty 但如果它支持SSL客户端证书,则没有相关文档

There's a pull request languishing for rest-client that should provide it. httparty has persistent_httparty but if it supports SSL Client Certificates, there's no documentation for it.

我可以分叉rest-client,合并现在已经过位的pull-request,并使用它。但是我肯定在这里遗漏了一些东西......是否有现有的图书馆提供我正在寻找的东西?或者一些httparty的文档解释了使用该库的SSL客户端证书?

I could fork rest-client, merge the pull-request which has by now bit-rotted, and use that. But surely I'm missing something here ... is there an existing library that offers what I'm looking for? Or some documentation for httparty which explains SSL Client Certificate use with that library?

任何帮助将不胜感激。

推荐答案

有没有可行的东西?



我相信HTTP客户端库法拉第是目前更多Ruby社区行动的焦点。

Is there something that already works?

I believe the HTTP client library Faraday is focus of more Ruby community action is these days.

附带 :net_http_persistent 适配器,它支持SSL客户端证书。您可以这样做:

It comes with a :net_http_persistent adapter, which supports SSL client certificates. You can probably do something like this:

ssl_options = {
  cert: OpenSSL::X509::Certificate.new(File.read('./certificate/client-2048.pem')),
  key:  OpenSSL::PKey::RSA.new(File.read('./certificate/client-2048.key'), 'mypassword')
}
conn = Faraday.new(url: 'https://example.com', ssl: ssl_options) do |faraday|
  faraday.adapter = Faraday::Adapter::NetHttpPersistent
end

conn.get '/my-resource'



HTTParty



根据规格:

HTTParty

According to the specs:

...当方案为https时提供PEM证书时产生的连接

... the resulting connection when providing PEM certificates when scheme is https


  • 使用提供的PEM证书

  • 将验证证书

您可以使用 pem classmethod 提供PEM格式的客户证书。

You can use the pem classmethod to provide a client certificate in PEM format.

它没有那么死 - Larry Gilbert( @L2G 仍在合并拉取请求并保持指示灯亮起。他在问题跟踪器中点头表示了他的普遍认可。我怀疑它目前不在他的优先级队列的顶部。

It's not as dead as all that -- Larry Gilbert (@L2G) is still merging in pull requests and keeping the lights on. He's nodded his general approval in the issue tracker. I suspect it's just not at the top of his priority queue at the moment.

发送该拉取请求的人, @byroot 一直保持他的代码更新所以你在等待的时候根本不需要做太多。

The guy who sent in that pull request, @byroot, has been keeping his code up to date so you shouldn't need to do much at all while you wait.

这篇关于具有HTTPS,SSL客户端证书和Keep-Alive支持的Ruby的HTTP库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆