Why does accessing the SSL site with Windows Mechanization fail, but it works on a Mac?

This is the code that I use to connect to the SSL site.

require 'mechanize'
a = Mechanize.new
page = a.get 'https://site.com'

I am using the Ruby 1.9.3 and Mechanize 2.1pre1 + dependencies. On Mac, the above code works and returns the page. On Windows 7 with the same versions, it causes the following error:

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

Reverting to Mechanize 2.0.1 seems to solve this problem, but after that I succeed in the problem too many connections reset by peer. So this is not a solution.

I tried to do it a.verify_mode = false, but it does nothing. I read that you can turn off SSL verification using:

open(uri,:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE)

How can I disable it in Mechanize? Why am I getting this error only on Windows?

+23
2

OpenSSL (, Net::HTTPS), .

, OpenSSL Windows , - .

:

a.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE

, (- )

(, curl):

http://curl.haxx.se/ca

- :

require "rbconfig"
require "mechanize"

a = Mechanize.new

# conditionally set certificate under Windows
# http://blog.emptyway.com/2009/11/03/proper-way-to-detect-windows-platform-in-ruby/
if RbConfig::CONFIG["host_os"] =~ /mingw|mswin/
  # http://curl.haxx.se/ca
  ca_path = File.expand_path "~/Tools/bin/curl-ca-bundle.crt"

  a.agent.http.ca_file = ca_path
end

page = a.get "https://github.com/"

, , Ruby 1.9.3-p0 (i386-mingw32), Windows 7 x64 mechanize 2.1.pre.1

, .

+38

, :

OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
+6

Source: https://habr.com/ru/post/1623965/


All Articles