ruby-on-rails - 如何使用带密码的 PEM 证书?

标签 ruby-on-rails ruby curl openssl rest-client

我在尝试使用在 ruby​​ 上有密码的证书时遇到了很多麻烦。我正在使用 rest-client,但这不是必需的。

这是我需要进行的调用的 cURL 等价物:

curl -E certificate.pem:PASSWORD -d ident=language -d data="test" "https://theurl" 

我尝试了很多东西,但我无法让密码部分正常工作。这是我到目前为止所拥有的:

cert = OpenSSL::X509::Certificate.new(File.read("#{RAILS_ROOT}/certificate.pem"))

reply = RestClient.post("https://theurl", {:ident => 'language', :data => 'test'}, {:ssl_client_cert => cert})

我试过将密码放在各处,如 :password 和 :ssl_client_key,我查看了我能找到的所有文档,但没有任何地方可以接受此密码。

这是我经常遇到的错误:

SSL_connect returned=1 errno=0 state=SSLv3 read finished A: sslv3 alert handshake failure

我错过了什么?

最佳答案

将 curl 与选项 -E 结合使用的方式,就是指定带有证书的私钥。

(来自 cURL 手册页)

-E/--cert

(SSL) Tells curl to use the specified client certificate file when getting a file with HTTPS, FTPS or another SSL-based protocol. The certificate must be in PEM format. If the optional password isn't specified, it will be queried for on the terminal. Note that this option assumes a "certificate" file that is the private key and the private certificate concatenated! See --cert and --key to specify them independently.

所以为了用 RestClient 做同样的事情,你可以尝试使用 ssl_client_key 选项。喜欢:

:ssl_client_key   =>  OpenSSL::PKey::RSA.new(File.read("key.pem"), "passphrase, if any"),

关于ruby-on-rails - 如何使用带密码的 PEM 证书?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5837972/

相关文章:

ruby-on-rails - 如何从 Redis 缓存中获取对象而不是哈希?

ruby-on-rails - Rails Time.zone 解析没有按预期工作

ruby 1.9.2 uniq 方法不适用于自定义类数组

php - PHP 中的谷歌反向图像查找

curl - 如何避免Elasticsearch Bulk API中每个文档的索引

ruby-on-rails - Ruby on Rails 集成测试期间间歇性 ActiveRecord::RecordNotFound

sql - 如何在 SQL 中编写以下 Rails 查询?

ruby-on-rails - 我可以记录未处理的 VCR 请求正文吗?

html - 在 HTML 中调用 Ruby 脚本的正确方法

linux - 如何使用wget下载具有最新时间戳的目录