OpenSSL 验证来自自己 CA 的证书
大家好,感谢您花时间阅读本文。
我需要验证我自己的 CA 颁发的证书,为此我有一个 证书。 如何
执行与 openssl 的openssl verify -CAfile
在 Ruby 代码中 等效的操作? OpenSSL 的 RDoc 在这方面不是很有帮助。 我已经尝试过:
require 'openssl' ca = OpenSSL::X509::Certificate.new(File.read('ca-cert.pem')) lic = OpenSSL::X509::Certificate.new(File.read('cert.pem')) puts lic.verify( ca )
但我得到:
test.rb:7:in `verify': wrong argument (OpenSSL::X509::Certificate)! (Expected kind of OpenSSL::PKey::PKey) (TypeError) from test.rb:7
我什至无法在 OpenSSL Rdoc 中找到“验证” http://www.ruby-doc.org/stdlib/libdoc /openssl/rdoc/index.html。
任何帮助表示赞赏。 再次感谢!
Hello all and thanks for your time reading this.
I need to verify certificates issued by my own CA, for which I have a
certificate. How can I do the equivalent to openssl's
openssl verify -CAfile
in Ruby code? The RDoc for OpenSSL is not very helpful in this regard.
I've tried:
require 'openssl' ca = OpenSSL::X509::Certificate.new(File.read('ca-cert.pem')) lic = OpenSSL::X509::Certificate.new(File.read('cert.pem')) puts lic.verify( ca )
but I get:
test.rb:7:in `verify': wrong argument (OpenSSL::X509::Certificate)! (Expected kind of OpenSSL::PKey::PKey) (TypeError) from test.rb:7
I can't even find "verify" in the OpenSSL Rdoc at
http://www.ruby-doc.org/stdlib/libdoc/openssl/rdoc/index.html.
Any help is appreciated. Thanks again!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要
另外进行验证,然后才能验证证书颁发者,
我使用了一个 日语帮助页面以获取可用方法的列表:)
You need to validate with
in addition before that you can verify certificate issuer with
I used one Japanese help page to get the list of available methods :)
lic.verify()
仅验证签署 lic 的证书中的密钥。 商业根 CA 不直接签署最终用户证书。 通常涉及一到两个中间签名证书。所以如果
CA -> 签名者-> 用户证书
则lic.verify(signer.public_key)
和signer.verify(CA.public_key)
将返回true,但lic.verify(CA .public_key )
将返回 false。lic.verify()
only verify the key from the certificate that signed lic. Ccommercial root CAs do not sign end user certificates directly. Usually there is one or 2 intermediate signing certificates involved.So if
CA -> signer -> user cert
thenlic.verify( signer.public_key)
andsigner.verify( CA.public_key)
will return true butlic.verify( CA.public_key )
will return false.