2

I want to create a certificate from a string. Why does this not work:

OpenSSL::X509::Certificate.new(OpenSSL::X509::Certificate.new.to_pem)

It returns: OpenSSL::X509::CertificateError: nested asn1 error

zarathustra
  • 1,898
  • 3
  • 18
  • 38
  • [Getting OpenSSL::X509::CertificateError nested asn1 error on Ruby](http://stackoverflow.com/q/24263835), [Ruby OpenSSL nested asn1 error](http://stackoverflow.com/q/27645249), [Ruby Error reading in Certificate File with OpenSSL](http://stackoverflow.com/q/8720981), etc ... – jww Jan 20 '17 at 16:59

1 Answers1

3

So I got the answer myself. The certificate needs at least these information:

cert = OpenSSL::X509::Certificate.new
cert.version = 2
cert.serial = 0
cert.not_before = Time.now
cert.not_after = Time.now + 3600
cert.public_key = key.public_key
cert.sign key, OpenSSL::Digest::SHA1.new

Then this is possible:

OpenSSL::X509::Certificate.new(cert.to_pem) => returns

zarathustra
  • 1,898
  • 3
  • 18
  • 38