Reading pem file in ruby on rails

hi,
i have a certificate file in pem format. i need to read the pem file.
Need help on how to read the certificate in ruby on rails

Thanks

hi,
i have a certificate file in pem format. i need to read the pem file.
Need help on how to read the certificate in ruby on rails

The ruby openssl library can do that - it's basically a straight
mapping of the openssl library.

Fred

Frederick Cheung wrote:

You should be able to do something like
OpenSSL::X509::Certificate.new(File.read(path_to_certificate))
(OpenSSL::PKey::RSA.new(File.read(path_to_key)) if it's just a key in
the pem file)

Fred

Frederick Cheung wrote:

Frederick Cheung wrote:

Hi Fred,
thanks for the reply. i am already using open SSL library, can you help
me with any example or code snippet on how to read the pem file in ruby?

You should be able to do something like
OpenSSL::X509::Certificate.new(File.read(path_to_certificate))
(OpenSSL::PKey::RSA.new(File.read(path_to_key)) if it's just a key in
the pem file)

Fred

Hi Fred,
I did the same with the follwing line of code, but i am getting
"certificate verify failed" error

Code snippet:
     cert = File.read("sdk-seller_cert_key.pem")
     pem = File.read("sdk-seller.pem")
     http.use_ssl = true
     http.cert = OpenSSL::X509::Certificate.new(cert)
     http.key = OpenSSL::PKey::RSA.new(pem)
     http.verify_mode = OpenSSL::SSL::VERIFY_PEER

Where am i going wrrong?

Thanks

Sreevarshini Kuppuraj wrote:

Frederick Cheung wrote:

Frederick Cheung wrote:

Hi Fred,
thanks for the reply. i am already using open SSL library, can you help
me with any example or code snippet on how to read the pem file in ruby?

You should be able to do something like
OpenSSL::X509::Certificate.new(File.read(path_to_certificate))
(OpenSSL::PKey::RSA.new(File.read(path_to_key)) if it's just a key in
the pem file)

Fred

Hi Fred,
I did the same with the follwing line of code, but i am getting
"certificate verify failed" error

Code snippet:
     cert = File.read("sdk-seller_cert_key.pem")
     pem = File.read("sdk-seller.pem")
     http.use_ssl = true
     http.cert = OpenSSL::X509::Certificate.new(cert)
     http.key = OpenSSL::PKey::RSA.new(pem)
     http.verify_mode = OpenSSL::SSL::VERIFY_PEER

Where am i going wrrong?

Thanks

Hi,
any work arround for this issue?

Thanks