简体   繁体   中英

WWW::Mechanize ignore SSL

I'm using the following code, with the following snippet:

my $mech = WWW::Mechanize->new( 'ssl_opts' => { 'verify_hostname' => 0 } );

the following error is still being thrown:

Error GETing https://www.1031exchangeinc.com/ : Can't connect to www.1031exchangeinc.com:443 (SSL connect attempt failed error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure) at crawl.pl line 29.

I want to ignore the SSL handshake.

#!/usr/bin/perl

use Modern::Perl;
use WWW::Mechanize;
use IO::Socket::SSL;

my $root = 'https://www.1031exchangeinc.com/';
my $domain = 'https://www.1031exchangeinc.com';
#my $mech = WWW::Mechanize->new;
my $mech = WWW::Mechanize->new( 'ssl_opts' => { 'verify_hostname' => 0 } );

sub visit {
   my $url = shift;
   my $indent = shift || 0;
   my $visited = shift || {};
   my $tab = ' ' x $indent;

# Already seen that.
return if $visited->{$url}++;

# Leaves domain.
if ($url !~ /^$domain/) {
    say $tab, "-> $url";
    return;
}

# Not seen yet.
say $tab, "- $url ";
$mech->get($url);
visit($_, $indent+2, $visited) for
    map {$_->url_abs} $mech->links;
}

visit($root);

I want to ignore the SSL handshake.

The SSL handshake can not be ignored with https since it is an integral part of a TLS connection (and thus https). At most you could try to skip validation of the certificate (bad idea) which is what you are trying. But, this does not make handshake failures vanish.

Such handshake errors are instead caused for example by non overlapping cipher suites between client and server, unsupported protocol versions or missing but required TLS extensions.

It is unclear what exactly is the problem in your case. But given that the server requires SNI according to the SSLLabs report and that it requires modern ciphers (ECDHE and/or GCM or ChaCha20) my guess is that you are using a too old version of OpenSSL. This is typically the case on MacOS X which ships with a very old version of OpenSSL, ie version 0.9.8.

You can check the version you use with

perl -MNet::SSLeay -e 'warn Net::SSLeay::SSLeay_version(0)'

If this reports anything like 0.9.8 then you've found the reason on why it is failing and you need to upgrade to a newer version of OpenSSL and recompile Net::SSLeay against this.
If you instead have at least OpenSSL 1.0.1 then it is a different problem and you should add the versions of Net::SSLeay and IO::Socket::SSL to your question and also the output when running with perl -MIO::Socket::SSL=debug4 your-program.pl .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM