perl 客户端 SSL 警告:对等证书未验证

2024-01-31

我在使用 Perl 屏幕抓取程序访问 HTTPS 站点时遇到问题。 在调试过程中,我运行了以下命令:

print $res->headers_as_string;

在输出中,我有以下行:

Client-SSL-Warning: Peer certificate not verified

有没有办法让我自动接受此证书,或者这不是问题所在?

#!/usr/bin/perl 
use LWP::UserAgent; 
use Crypt::SSLeay::CTX; 
use Crypt::SSLeay::Conn; 
use Crypt::SSLeay::X509; 
use LWP::Simple qw(get);

my $ua  = LWP::UserAgent->new; 
my $req = HTTP::Request->new(GET => 'https://vzw-cat.sun4.lightsurf.net/vzwcampaignadmin/');
my $res = $ua->request($req);

print $res->headers_as_string;

output:

Cache-Control: no-cache
Connection: close
Date: Tue, 01 Jun 2010 19:28:08 GMT
Pragma: No-cache
Server: Apache
Content-Type: text/html
Expires: Wed, 31 Dec 1969 16:00:00 PST
Client-Date: Tue, 01 Jun 2010 19:28:09 GMT
Client-Peer: 64.152.68.114:443
Client-Response-Num: 1
Client-SSL-Cert-Issuer: /O=VeriSign Trust Network/OU=VeriSign, Inc./OU=VeriSign International Server CA - Class 3/OU=www.verisign.com/CPS Incorp.by Ref. LIABILITY LTD.(c)97 VeriSign
Client-SSL-Cert-Subject: /C=US/ST=Massachusetts/L=Boston/O=verizon wireless/OU=TERMS OF USE AT WWW.VERISIGN.COM/RPA (C)00/CN=PSMSADMIN.VZW.COM
Client-SSL-Cipher: DHE-RSA-AES256-SHA
Client-SSL-Warning: Peer certificate not verified
Client-Transfer-Encoding: chunked
Link: <css/vtext_style.css>; rel="stylesheet"; type="text/css"
Set-Cookie: JSESSIONID=DE6C99EA2F3DD1D4DF31456B94F16C90.vz3; Path=/vzwcampaignadmin; Secure
Title: Verizon Wireless - Campaign Administrator

更新: 我添加了

$ENV{HTTPS_CA_FILE}   = 'certs/PSMSADMIN.VZW.COM';
$ENV{HTTPS_CA_DIR}    = 'certs/';

如下所示。我还打开了调试:

$ENV{HTTPS_DEBUG} = 1;

这是我的输出:

SSL_connect:before/connect initialization
SSL_connect:SSLv3 write client hello A
SSL_connect:SSLv3 read server hello A
SSL3 alert write:fatal:bad certificate
SSL_connect:error in SSLv3 read server certificate B
SSL_connect:before/connect initialization
SSL_connect:SSLv2 write client hello A
SSL_connect:error in SSLv2 read server hello B
content: 500 SSL negotiation failed: error:1407E086:SSL routines:SSL2_SET_CERTIFICATE:certificate verify failed

我尝试忽略失败,但问题是这是页面上现在唯一的内容,因此没有登录表单或任何内容。


据我所知,这只是一个警告。该站点上的证书与域不匹配,因此 perl (理所当然地)抱怨它。如果您确实像这样打开对等证书验证:

# CA cert peer verification
$ENV{HTTPS_CA_FILE}   = 'certs/ca-bundle.crt';
$ENV{HTTPS_CA_DIR}    = 'certs/';

您将得到以下输出:

Content-Type: text/plain
Client-Date: Tue, 01 Jun 2010 19:32:51 GMT
Client-Warning: Internal response
500 SSL negotiation failed: error:1407E086:SSL
      routines:SSL2_SET_CERTIFICATE:certificate verify failed
Content-Type: text/plain
Client-Date: Tue, 01 Jun 2010 19:32:51 GMT
Client-Warning: Internal response

有一个方法叫get_peer_verify http://search.cpan.org/~dland/Crypt-SSLeay-0.57/lib/Net/SSL.pm#get_peer_verify in Net::SSL (which Crypt::SSLeay提供),返回是否需要对等验证。我相信它被添加了in 2001 http://kobesearch.cpan.org/htdocs/Crypt-SSLeay/Changes.html或以此类推,以便隐藏此消息。这个补丁 http://www.mail-archive.com/libwww@perl.org/msg03129.html从 2002 年起,它声称在不需要同行验证时关闭警告,但我认为它从未被应用过。

简而言之,您可能可以忽略警告,除非您打算进行验证,在这种情况下,我会说将根证书添加到您的CA_DIR and CA_FILE。但由于证书的域与服务器的域不匹配,我什至不确定这是否有帮助。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

perl 客户端 SSL 警告:对等证书未验证 的相关文章

随机推荐