title: How to connect to an https server with an invalid certificate using the latest versions of Ruby
body: <p>Consider the following code:</p>
  
  <pre><code>require 'net/https'
  uri = URI.parse("https://host/index.html")
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  request = Net::HTTP::Get.new(uri.path)
  response = http.request(request)
  </code></pre>
  
  <p>where <code>https://host/index.html</code> is a valid address with an invalid certificate on the server.</p>
  
  <p>On older versions of ruby (specifically 1.8.7-p334 and 1.9.2-p180) this code works fine. On all recent versions (1.8.7-p352, 1.9.2-p290 and 1.9.3-p0) it throws the following exception:</p>
  
  <pre><code>OpenSSL::SSL::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=unknown state
  </code></pre>
  
  <p>on the last line.</p>
  
  <p>Changing verify_mode to <code>OpenSSL::SSL::VERIFY_PEER</code> gives exactly the error suggesting it is attempting to verify the certificate in spite of the setting.</p>
  
  <p>How can I convince ruby to ignore the invalid certificate and connect?</p>