# Can't connect to securied host by ssl certificate

**URL:** <https://www.ruby-forum.com/t/cant-connect-to-securied-host-by-ssl-certificate/229279>\
**Category:** Ruby\
**Created:** [January 23, 2013, 10:26pm UTC](https://www.ruby-forum.com/t/cant-connect-to-securied-host-by-ssl-certificate/229279 "2013-01-23T22:26:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kyku](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/34f0e0/32.png) [@kyku](https://www.ruby-forum.com/u/kyku)\
**Post date:** [January 23, 2013, 10:26pm UTC](https://www.ruby-forum.com/t/cant-connect-to-securied-host-by-ssl-certificate/229279/1 "2013-01-23T22:26:19Z")

</div>

I must connect with some server which need SSL certificates, but I am  
not able to write working code, I have:

- CA certificate
- X509 certificate
- Private key

when I wrote:

require ‘net/https’  
https = Net::HTTP.new(‘host’, port)  
https.use\_ssl = true  
https.ca\_file = ‘/…/ca.pem’  
https.verify\_mode = OpenSSL::SSL::VERIFY\_PEER  
https.verify\_depth = 5  
https.cert = OpenSSL::X509::Certificate.new  
File.open(‘/…/cert/cert.crt’)  
https.key = OpenSSL::PKey::RSA.new File.open(‘/…/private/key.pem’)  
https.request\_get(‘/…/test.txt’)

I got:

OpenSSL::SSL::SSLError: SSL\_connect returned=1 errno=0 state=SSLv3 read  
server hello B: serverhello tlsext  
from /…/lib/ruby/1.9.1/net/http.rb:799:in `connect' from /.../lib/ruby/1.9.1/net/http.rb:799:in `block in connect’  
from /…/lib/ruby/1.9.1/timeout.rb:54:in `timeout' from /.../lib/ruby/1.9.1/timeout.rb:99:in `timeout’  
from /…/lib/ruby/1.9.1/net/http.rb:799:in `connect' from /.../lib/ruby/1.9.1/net/http.rb:755:in `do\_start’  
from /…/lib/ruby/1.9.1/net/http.rb:744:in `start' from /.../lib/ruby/1.9.1/net/http.rb:1284:in `request’  
from /…/lib/ruby/1.9.1/net/http.rb:1195:in `request\_get’

But I can connect to this sever by wget without any problems:

wget --certificate=/…/cert/cert.crt --private-key=/…/private/key.pem  
–ca-certificate=/…/ca.pem -O /tmp/x [https://host/.../test.txt](https://host/.../test.txt)

I found that tlsext in SSL error message is some info about TLS  
Extension, but I don’t know what exactly what it mean and how it fix.

---

<div class="post-metadata">

**Author:** ![kyku](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/34f0e0/32.png) [@kyku](https://www.ruby-forum.com/u/kyku)\
**Post date:** [January 24, 2013, 11:39am UTC](https://www.ruby-forum.com/t/cant-connect-to-securied-host-by-ssl-certificate/229279/2 "2013-01-24T11:39:36Z")

</div>

Krzysztof Wawer wrote in post #1093400:

> I must connect with some server which need SSL certificates, but I am  
> not able to write working code, I have:
> 
> - CA certificate
> - X509 certificate
> - Private key
> 
> when I wrote:
> 
> require ‘net/https’  
> https = Net::HTTP.new(‘host’, port)  
> https.use\_ssl = true  
> https.ca\_file = ‘/../ca.pem’  
> https.verify\_mode = OpenSSL::SSL::VERIFY\_PEER  
> https.verify\_depth = 5  
> https.cert = OpenSSL::X509::Certificate.new  
> File.open(‘/…/cert/cert.crt’)  
> https.key = OpenSSL::PKey::RSA.new File.open(‘/…/private/key.pem’)  
> https.request\_get(‘/…/test.txt’)

I am also having the same issues with ‘mechanize’ ruby-gem. But I tried  
huge,But failed. Thus I am adding my name to this list,to have the  
update how to handle such situations.

Thanks
