Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't bypass OpenSSL verification - certificate verify failed (OpenSSL::SSL::SSLError)

I am trying to parse an HTTPS XML feed via Nokogiri but I get this OpenSSL error:

SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)

I can also see the SSL_CERT_FILE:

echo $SSL_CERT_FILE
/home/user/certs/cacert.pem

This is how I am trying to parse:

@feed = "https://example.com/feed1.xml"
doc =  Nokogiri::XML(open(@feed)

I tried to bypass the OpenSSL verification, but I still get the same error:

doc =  Nokogiri::XML(open(@feed,{ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE}))

Can anyone help?

like image 431
tokhi Avatar asked Jul 09 '14 11:07

tokhi


1 Answers

This problem usually appears on Windows.

One quick solution is to pass ssl_verify_mode to open

require 'open-uri'
require 'openssl'
open(some_url, ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE)

Another quick one is overriding OpenSSL::SSL::VERIFY_PEER in the beginning of your script by doing

require 'openssl'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

Those who want real solution can try method described on https://gist.github.com/fnichol/867550

like image 186
Rene Avatar answered Nov 14 '22 22:11

Rene