使用 OpenSSL 读取证书文件时出现 Ruby 错误
我正在尝试做一个简单的 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 simpleOpenSSL::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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据后缀,“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#certificate
和PKCS12#ca_certs
方法提取证书和CA证书。"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 likeOpenSSL::PKCS12.new(File.read("testuser.p12"), "pass")
You can extract certificate and CA certificates by
PKCS12#certificate
andPKCS12#ca_certs
methods.