使用 OpenSSL 读取证书文件时出现 Ruby 错误

发布于 2024-12-24 17:17:44 字数 296 浏览 7 评论 0原文

我正在尝试做一个简单的 OpenSSL::X509::Certificate.new(File.read("testuser.p12")) 来自 irb 和 ruby​​ 1.8.7(或 1.9.2),两者结果相同。我得到的错误是 OpenSSL::X509::CertificateError:nested asn1 error

这是一个 ruby​​ 问题,还是表明证书本身格式错误?我发现一些类似的报告围绕亚马逊证书展示了此类错误,结果证明是证书本身。但它可以在浏览器中运行。关于如何解决这个问题的建议?

I am trying to do a simple
OpenSSL::X509::Certificate.new(File.read("testuser.p12"))
from irb with ruby 1.8.7 (or 1.9.2), same result for both. The error I get back is OpenSSL::X509::CertificateError: nested asn1 error

Is this a ruby issue, or does this suggest the cert itself is malformed? I've found some similar reports revolving around an amazon cert demonstrating such errors, which turned out to be the cert itself. It works in the browser though. Suggestions on how to resolve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

归途 2024-12-31 17:17:44

根据后缀,“testuser.p12”似乎是一个 PKCS#12 文件。将 PKCS#12 格式读取为 X.509 证书格式会导致 ASN.1 解码错误。

您应该改为 OpenSSL::PKCS12.new(File.read("testuser.p12")) 。如果文件受密码保护(这是正常的),请将密码作为 PKCS12.new 的第二个参数,如 OpenSSL::PKCS12.new(File.read("testuser.p12"), "pass")< /code>

您可以通过PKCS12#certificatePKCS12#ca_certs方法提取证书和CA证书。

p12 = OpenSSL::PKCS12.new(File.read("testuser.p12"), "pass")
p p12.certificate
p p12.ca_certs

"testuser.p12" seems to be a PKCS#12 file according to the postfix. Reading PKCS#12 format as X.509 certificate format causes ASN.1 decoding error.

You should do OpenSSL::PKCS12.new(File.read("testuser.p12")) instead. If the file is protected with passphrase (it's normal), give the passphrase as the second parameter for PKCS12.new like OpenSSL::PKCS12.new(File.read("testuser.p12"), "pass")

You can extract certificate and CA certificates by PKCS12#certificate and PKCS12#ca_certs methods.

p12 = OpenSSL::PKCS12.new(File.read("testuser.p12"), "pass")
p p12.certificate
p p12.ca_certs
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文