Ruby error in certificate file with OpenSSL

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

Is this a ruby ​​problem, or does it mean that the certificate itself is defective? I have found several similar reports that revolve around the amazon certificate, demonstrating such errors that turned out to be the certificates themselves. However, it works in a browser. Suggestions on how to resolve this?

+6
source share
1 answer

"testuser.p12" is represented by the PKCS # 12 file according to the postfix message. Reading PKCS # 12 as an X.509 certificate format causes an ASN.1 decoding error.

Instead, you should do OpenSSL::PKCS12.new(File.read("testuser.p12")) . If the file is password protected (this is normal), enter the passphrase as the second parameter for PKCS12.new, as OpenSSL::PKCS12.new(File.read("testuser.p12"), "pass")

You can extract certificate certificates and CA certificates using the PKCS12#certificate and PKCS12#ca_certs .

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

Source: https://habr.com/ru/post/905036/


All Articles