# Net::HTTP using SSL certificate

**URL:** <https://www.ruby-forum.com/t/net-http-using-ssl-certificate/127660>\
**Category:** Ruby\
**Created:** [January 31, 2008, 4:45am UTC](https://www.ruby-forum.com/t/net-http-using-ssl-certificate/127660 "2008-01-31T04:45:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![julianparry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ab097/32.png) [@julianparry](https://www.ruby-forum.com/u/julianparry)\
**Post date:** [January 31, 2008, 4:45am UTC](https://www.ruby-forum.com/t/net-http-using-ssl-certificate/127660/1 "2008-01-31T04:45:29Z")

</div>

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](http://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

---

<div class="post-metadata">

**Author:** ![julianparry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ab097/32.png) [@julianparry](https://www.ruby-forum.com/u/julianparry)\
**Post date:** [January 31, 2008, 4:25pm UTC](https://www.ruby-forum.com/t/net-http-using-ssl-certificate/127660/2 "2008-01-31T16:25:41Z")

</div>

On Jan 30, 9:41 pm, julianparry [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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.
