我在尝试使用在 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/