Net::HTTP using SSL certificate


J

julianparry

Hi,

I'm attempting to login to a URL over SSL using Net:HTTP.

CERT_FILE = 'cert.pem'
http = Net::HTTP.new('dev.company.com, 443)
http.use_ssl = true

http.cert = OpenSSL::X509::Certificate.new( File.read(CERT_FILE) )
http.key = OpenSSL::pKey::RSA.new( File.read(CERT_FILE) )
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

path = '/login.form'

response, body = http.post(path, data, headers)

puts "Code = #{response.code}"
puts "Message = #{response.message}"
puts "Body= #{body}"

but I get the following error message:

C:/rubydev/olb/olb.rb:59:in `initialize': Neither PUB key nor PRIV
key:: nested
asn1 error (OpenSSL::pKey::RSAError)
from C:/rubydev/olb/olb.rb:59:in `new'
from C:/rubydev/olb/olb.rb:59

Does anyone have an idea of what is going on here?

Thanks,
Jules
 
Ad

Advertisements

Y

yermej

C:/rubydev/olb/olb.rb:59:in `initialize': Neither PUB key nor PRIV
key:: nested
asn1 error (OpenSSL::pKey::RSAError)

This message is telling you that the file you passed to
OpenSSL::pKey.new isn't a key file. That is correct since the
certificate is not a key. You'll need to pass it the private key file
that was used to create the certificate you're using.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top