简体   繁体   English

为什么LWP无法与“ 500 SSL协商失败”连接?

[英]Why does LWP fail to connect with “500 SSL negotiation failed”?

My Perl script sends some information to a remote server. 我的Perl脚本将一些信息发送到远程服务器。

Below is a portion of the code 以下是部分代码

#!/var/hvmail/libexec/perl

use strict;

use HTTP::Request::Common qw(POST);
use LWP::UserAgent;

use constant HANDLER_URL => "https://www.website.com/handler.php";

$ENV{HTTPS_DEBUG} = 1;

my $ua = LWP::UserAgent->new;

# Some DB stuff, not applicable
my $row; # This is a DB row ($sth->fetchrow_hashref())   

my $req = POST ''.HANDLER_URL, [ %$row ]; 
my $res = $ua->request($req);

$res->is_success is false with $res->status_line being $res->is_successfalse,其中$res->status_line

500 SSL negotiation failed

We are running CentOS 6.4, Perl 5.10.1, OpenSSL 1.0.1e-fips. 我们正在运行CentOS 6.4,Perl 5.10.1,OpenSSL 1.0.1e-fips。

Update 更新

Here's the full output: 这是完整的输出:

SSL_connect:before/connect initialization
SSL_connect:SSLv2/v3 write client hello A
SSL3 alert read:fatal:handshake failure
SSL_connect:error in SSLv2/v3 read server hello A
SSL_connect:before/connect initialization
SSL_connect:SSLv3 write client hello A
SSL3 alert read:fatal:handshake failure
SSL_connect:failed in SSLv3 read server hello A
SSL_connect:before/connect initialization
SSL_connect:SSLv2 write client hello A
SSL_connect:failed in SSLv2 read server hello A
Error: [ 500 SSL negotiation failed:  ]

Requested Command Output 请求的命令输出

Can't locate Net/SSLeay.pm
Can't locate LWP/Protocol/https.pm

You seem to be relying on Crypt::SSLeay . 您似乎依赖Crypt :: SSLeay You shouldn't. 你不应该 It's outdated and incomplete. 它已经过时且不完整。

Install the latest LWP::Protocol::https which will upgrade your LWP and install the preferred SSL/TLS stack consisting of the IO::Socket::SSL and Net::SSLeay . 安装最新的LWP :: Protocol :: https ,它将升级您的LWP并安装由IO :: Socket :: SSLNet :: SSLeay组成的首选SSL / TLS堆栈。

A web search shows there are CentOS6 repositories with RPM packages for LWP::Protocol::https . 网上搜索显示存在带有LWP::Protocol::https RPM软件包的CentOS6存储库。

The server has disabled SSLv3 support which means the negotiation fails. 服务器已禁用SSLv3支持,这意味着协商失败。

Once you install the package, if you are still seeing the same error, make sure your script is not forcing the use of Crypt::SSLeay . 安装软件包后,如果仍然看到相同的错误,请确保您的脚本没有强制使用Crypt::SSLeay That is, make sure none of the following appears anywhere in your script: 也就是说,请确保以下所有内容均未出现在脚本中:

use Net::HTTPS;
$Net::HTTPS::SSL_SOCKET_CLASS = 'Net::SSL';

or 要么

local $ENV{PERL_NET_HTTPS_SSL_SOCKET_CLASS} = 'Net::SSL';

or 要么

use Net::SSL;

If you are still running into problems, make sure there is no PERL_NET_HTTPS_SSL_SOCKET_CLASS environment variable in the script's run time environment. 如果仍然遇到问题,请确保脚本的运行时环境中没有PERL_NET_HTTPS_SSL_SOCKET_CLASS环境变量。

Also, try 另外,尝试

$ /var/hvmail/libexec/perl -MNet::SSLeay -le 'print $Net::SSLeay::VERSION'

and

$ /var/hvmail/libexec/perl -MLWP::Protocol::https -le 'print $LWP::Protocol::https::VERSION`'

and report the output. 并报告输出。

I suspect the issue is that the new packages were installed for the system's perl whereas it seems you may have a separate perl . 我怀疑问题在于为系统的perl安装了新软件包,而您似乎有一个单独的perl

If that is the case, you should install each package individually using /var/hvmail/libexec/perl . 在这种情况下,您应该使用/var/hvmail/libexec/perl分别安装每个软件包。 For example: 例如:

$ curl -O https://cpan.metacpan.org/authors/id/M/MI/MIYAGAWA/App-cpanminus-1.7043.tar.gz
$ tar xvf App-cpanminus-1.7043.tar.gz
$ cd App-cpanminus-1.7043
$ /var/hvmail/libexec/perl Makefile.PL
$ make install

Figure out where cpanm was installed. 找出cpanm安装位置。 I am hoping /var/hvmail/libexec . 我希望/var/hvmail/libexec

$ /var/hvmail/libexec/cpanm LWP::Protocol::https

See also Updating all outdated Perl modules , but that may be risky on a production. 另请参阅更新所有过时的Perl模块 ,但这可能会对生产产生风险。 Still, installing App::cpanoutdated , and seeing how outdated your Perl modules are might be useful 不过,安装App :: cpanoutdated并查看Perl模块的过时程度可能会很有用。

Now, keep in mind that tinkering with a production install like this is risky. 现在,请记住,像这样修改生产安装是有风险的。 Make sure you have a way to undo changes in case something goes wrong. 确保您有一种方法来撤消更改,以防出现问题。

Finally, note that OpenSSL 1.0.1 versions are no longer supported : 最后,请注意, 不再支持OpenSSL 1.0.1版本

With regards to current and future releases the OpenSSL project has adopted the following policy: 关于当前和将来的版本,OpenSSL项目已采用以下策略:

  • Version 1.1.0 will be supported until 2018-08-31. 在2018年8月31日之前,将支持1.1.0版。
  • Version 1.0.2 will be supported until 2019-12-31 (LTS). 在2019年12月31日之前,将支持1.0.2版。
  • Version 1.0.1 is no longer supported. 不再支持1.0.1版。
  • Version 1.0.0 is no longer supported. 不再支持1.0.0版。
  • Version 0.9.8 is no longer supported. 不再支持0.9.8版。

There is no need for ''.HANDLER_URL . 不需要''.HANDLER_URL It looks ugly, and HANDLER_URL is fine 看起来很丑, HANDLER_URL很好

You don't explain what is in $row or what the POST call requires, but it looks like this 您无需解释$rowPOST调用的要求,但是看起来像这样

my $req = POST ''.HANDLER_URL, [ %$row ]; 
my $res = $ua->request($req);

should be 应该

my $res = $ua->post(HANDLER_URL, $row);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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