500 error with LWP:UserAgent

三世轮回 提交于 2019-12-04 21:08:13

(Based on my answer from http://www.perlmonks.org/?node_id=1106240)

... sis-t.redsys.es:25443

This server has some serious issues. The default cipher set for the version of IO::Socket::SSL you use (1.76) is "ALL:!LOW". If this cipher set is used together with TLS1.0 or higher the connection simply hangs. You can verify this with s_client:

$ openssl s_client -cipher 'ALL:!LOW' -connect  sis-t.redsys.es:25443 -servername sis-t.redsys.es
CONNECTED(00000004)
... and there it hangs ...

This kind of problem is often seen in connection with older F5 load balancers in front of the server, which simply drop ClientHello packets greater than 255 bytes. If you would not add the servername option in the s_client call the request would magically succeed, because the packet is now smaller than 255 byte. Since version 1.962 (about a year ago) IO::Socket::SSL will use a smaller (and more secure) cipher set to work around such problems.

Crypt::SSLeay instead uses the default cipher set of OpenSSL, which makes the packet in this case just 248 bytes and thus small enough. That's why it works with Crypt::SSLeay. But please note, that Crypt::SSLeay does not make any verification of the hostname against the servers certificate and is thus open to man-in-the-middle attacks.

With current versions of IO::Socket::SSL the problem should be fixed, that is you should not need any special settings and you can leave verification enabled etc. Your latest code works thus without problems on my machine with IO::Socket::SSL 2.002.

But, since you are using a proxy you should use the latest versions of LWP::UserAgent and LWP::Protocol::https too, because proper proxy support with IO::Socket::SSL backend was only added to version 6.06 (it might be in 6.04 already if you use Debian or a spinoff like Ubuntu). While it looks like you are using LWP::UserAgent 6.06 you do not show the version of LWP::Protocol::https. This separate module must be version 6.06 too to have working proxy support.

First off, given that the site's certificate is not self-signed, there is no good reason for:

LWP::UserAgent->new(ssl_opts => { verify_hostname => 0});

This made me suspect that your problem may be related to Crypt::SSLeay, but I do not have a proxy set up to test this.

In any case, unless you find out the problem is either due to your crawler being blocked, or soemthing related to your proxy set up, I would ask that you run the following code:

#!/usr/bin/env perl

use strict;
use warnings;

use LWP::UserAgent;
use Net::HTTPS;
my $sc = $Net::HTTPS::SSL_SOCKET_CLASS;
my $v = eval "require $sc; \${${sc}::VERSION}";
print "$_\n" for $sc, $v;

and report the information here, along with your perl and LWP versions.

According to your comment, you are using:

  • IO::Socket::SSL 1.955
  • perl 5.14.2
  • LWP::UserAgent 6.06

Please add

use Net::SSLeay;
$Net::SSLeay::trace = 2;

to the top of your original script, and update your question with the debugging output.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!