title: How to use TLS 1.2 in Ruby Http client
body: <p>I'm trying to access third party api using TLS 1.2, but getting SSL error event with valid certificates</p>
  
  <p><strong>Ruby Version:</strong> </p>
  
  <pre><code> ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
  </code></pre>
  
  <p><strong>Rails Version:</strong> </p>
  
  <pre><code>Rails 4.2.5
  </code></pre>
  
  <p><strong>CODE:</strong></p>
  
  <pre><code>    ua = Net::HTTP.new(SERVER, 443)
      ua.instance_eval {
        @ssl_context = OpenSSL::SSL::SSLContext.new
        options = OpenSSL::SSL::OP_NO_SSLv2 | OpenSSL::SSL::OP_NO_SSLv3
        if OpenSSL::SSL.const_defined?('OP_NO_COMPRESSION')
          options |= OpenSSL::SSL::OP_NO_COMPRESSION
        end
        @ssl_context.set_params({options: options})
      }
     # ua.instance_eval { @ssl_context = OpenSSL::SSL::SSLContext.new(:TLSv1_2) }
      ua.use_ssl = true
  
      # Checks presence of CA certificate
      if File.directory?(RootCA)
        ua.ca_path = RootCA
        ua.verify_mode = OpenSSL::SSL::VERIFY_PEER
        ua.verify_depth = 3
      else
        puts "Invalid CA certificates directory. Exiting..."
        exit
      end
  </code></pre>
  
  <p><strong>ERROR:</strong></p>
  
  <pre><code>OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
      from /home/cp/.rbenv/versions/2.3.0/lib/ruby/2.3.0/net/http.rb:933:in `connect_nonblock'
      from /home/cp/.rbenv/versions/2.3.0/lib/ruby/2.3.0/net/http.rb:933:in `connect'
      from /home/cp/.rbenv/versions/2.3.0/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
      from /home/cp/.rbenv/versions/2.3.0/lib/ruby/2.3.0/net/http.rb:852:in `start'
      from /home/cp/.rbenv/versions/2.3.0/lib/ruby/2.3.0/net/http.rb:1398:in `request'
      from /home/cp/.rbenv/versions/2.3.0/lib/ruby/2.3.0/net/http.rb:1421:in `send_entity'
      from /home/cp/.rbenv/versions/2.3.0/lib/ruby/2.3.0/net/http.rb:1209:in `post'
  </code></pre>