OpenSSL 验证来自自己 CA 的证书

发布于 2024-07-16 17:07:49 字数 744 浏览 3 评论 0原文

大家好,感谢您花时间阅读本文。

我需要验证我自己的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨曦慕雪 2024-07-23 17:07:49

您需要

lic.verify(ca.public_key)

另外进行验证,然后才能验证证书颁发者,

lic.issuer.to_s == ca.subject.to_s

我使用了一个 日语帮助页面以获取可用方法的列表:)

You need to validate with

lic.verify(ca.public_key)

in addition before that you can verify certificate issuer with

lic.issuer.to_s == ca.subject.to_s

I used one Japanese help page to get the list of available methods :)

久隐师 2024-07-23 17:07:49

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 then

lic.verify( signer.public_key) and signer.verify( CA.public_key) will return true but lic.verify( CA.public_key ) will return false.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文