我在使用perl screenscraper到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;
输出:
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
我试图忽略失败,但问题是这是页面上唯一的东西,所以没有登录表单或任何东西。
答案 0 :(得分:4)
尽我所知,这只是一个警告。该站点上的证书与域名不匹配,因此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
Net::SSL
中有一个名为get_peer_verify
的方法(Crypt::SSLeay
提供),它返回是否需要进行对等验证。我相信它已添加in 2001左右,以便隐藏此消息。 2002年This patch声称在不需要同行验证时关闭警告,但我认为它从未被应用过。
简而言之,除非您打算进行验证,否则您可能会忽略该警告,在这种情况下,我会将根证书添加到您的CA_DIR
和CA_FILE
。但由于证书的域与服务器的域不匹配,我甚至不确定这会有所帮助。