Appreciate it's not your exact same scenario, but I was attempting to read in a PEM file (PKCS7) in my instance. OpenSSL CLI would decode it fine, but ruby kept throwing the same nested asn1 error that you describe when I tried to load it into an object.
In my case it needed a new line i.e. '
' at the end of the PEM file for it to accept it.
I worked it out only when I created an empty object and compared the generated PEM output to the file I was trying to load.
So with a X509 cert maybe try:
cert = OpenSSL::X509::Certificate.new
cert.to_pem
=> "-----BEGIN CERTIFICATE-----
MCUwGwIAMAMGAQAwADAEHwAfADAAMAgwAwYBAAMBADADBgEAAwEA
-----END CERTIFICATE-----
"
And compare it to your PEM file
As you can see it's terminated with a new line and that was missing in the file that I was trying to import.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…