1

I'm getting this error:

Not a duplicated SSL_connect returned=1 errno=0 state=error: certificate verify failed OS El Capitan

While using this code to make API calls:

require 'json'
require 'net/http'
url = 'https://touch-rate.com/o/analytics/dashboard?api_key='+ENV["API_KEY"]+'&app_id='+ENV["APP_ID"]%>
resp = Net::HTTP.get_response(URI.parse(url))
dashboard = JSON.parse(resp.body)

My server was recently changed to a secure server and since then it has been throwing the above error.

I've have tried every multiple options on Stackoverflow, but nothing seems to work, can somebody help me with why I'm getting this error?

Thank you

13aal
  • 1,634
  • 1
  • 21
  • 47
Andy
  • 29
  • 6

1 Answers1

-1

You will have to basically bypass the SSL ceritificate validation while connecting to a webservice running on SSL. You can do so by using the following snippet of code

 uri = URI.parse(url)
 http = Net::HTTP.new(uri.host, uri.port)
 http.use_ssl = (uri.scheme == 'https')
 http.verify_mode = OpenSSL::SSL::VERIFY_NONE
 request = Net::HTTP::Post.new(uri.request_uri)
 response = http.request(request)
 dashboard = JSON.parse(resp.body)

So basically http.verify_mode = OpenSSL::SSL::VERIFY_NONE is the line of code that bypasses the certificate validation. I hope it helps

Ankush
  • 146
  • 8
  • Thanks a lot! that worked for me :) – Andy Nov 17 '15 at 05:33
  • Could you please accept the answer so that others would come to know that this solution works. – Ankush Nov 18 '15 at 06:38
  • Disabling SSL is a dangerous option -- you're basically opening yourself up to man in the middle attacks. These problems are likely related to an OSX upgrade, see here for more: http://stackoverflow.com/questions/4528101/ssl-connect-returned-1-errno-0-state-sslv3-read-server-certificate-b-certificat – Alex Sharp Nov 25 '15 at 19:37