LWP::UserAgent or LWPx::ParanoidAgent + Crypt::SSLeay ã§ãªã¬ãªã¬è¨¼ææ¸ã®æ¤åº
çµè«ããè¨ãã¨ããªã¬ãªã¬è¨¼ææ¸ã使ã£ãå ´åã« LWP::UserAgent + Crypt::SSLeay ã¯æ示çãªã¨ã©ã¼ãåãåºãã®ã§ã¯ãªããã¬ã¹ãã³ã¹ããã Client-SSL-Warning ãä»ä¸ãã¦ã¢ã¯ã»ã¹çµæãè¿ãã¾ãã*1
ç°¡åã«ãã¹ãããå ´å
$ lwp-request -e -d https://badcert.example.com/
ã®ããã«ããã¨ã
Client-SSL-Warning: Peer certificate not verified
ããã°ã©ã ã§ç¢ºèª
use Carp; use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $res = $ua->get("https://badcert.example.com/"); unless ($res->is_success) { croak $res->status_line; } elsif (defined $res->header("Client-SSL-Warning")) { croak "Bad certs"; } else { print $res->content; }
ã¨ããããããæãã«ãªãã
LWPx::ParanoidAgent ã®å ´å
ã¦ã£ãããã§ãã¯ãã¦ãããã®ãã¨æããã LWP::UserAgent ã¨åãæ¹å¼ã ã£ã件ï¼ï¼
対ç
ãã¨ã§çé¢ç®ã«æ¸ã
ãããªæãããªã¼ããã¼ã£ã¨ãNet::OpenID::* ãªã¢ã¸ã¥ã¼ã«ã¯çµå±ã®æ HTTP::Response::is_success() ã§ã®ã¿ãã§ãã¯ãã¦ããã®ã§ãããããã±ã¼ã¹ãè½ã¨ãããå ´åã¯ä»¥ä¸ã®ãããªã³ã¼ãã«ããã°ããããããªããã¨æãã¾ãã
ã¹ãã¼ã¿ã¹ã³ã¼ãã¯ã ãã¶é©å½ã§ãã
#!/usr/bin/perl use strict; use warnings; use Carp; use Data::Dump qw(dump); use Hook::WrapSub; use HTTP::Date; use HTTP::Response; use LWPx::ParanoidAgent; use Perl6::Say; Hook::WrapSub::wrap_subs( 'LWPx::ParanoidAgent::send_request', sub { my ($self, $req, $arg, $size) = @_; my $res = shift @Hook::WrapSub::result; if ($res->header('Client-SSL-Warning')) { my $err_res = HTTP::Response->new(403, 'Unauthorized access to no verified certification'); $err_res->header("Client-Date" => HTTP::Date::time2str(time)); $err_res->header("Client-Warning" => "Internal response"); $err_res->header("Content-Type" => "text/plain"); $err_res->content("403 Unauthorized access to blocked host\n"); @Hook::WrapSub::result = ($err_res); } } ); my $url = $ARGV[0]; my $ua = LWPx::ParanoidAgent->new( blocked_hosts => [], whitelisted_hosts => [], ); my $res = $ua->get($url); unless ($res->is_success) { say dump($res->headers); carp $res->status_line; } else { say dump $res; }
ã¾ã¨ã
Client-SSL-Warning ããã§ãã¯ãã¦ãªã㨠SSL/TLS ã«ããæå³ãã»ã¨ãã©ç¡ããªãã®ã§ããã®ãããå¤ãå«ã¾ãããä¸æ£ãªã¢ã¯ã»ã¹ã ã¨æãã¹ãã
*1: ã¨è¨ãã®ã id:kazuhooku ããã«æãã¦è²°ãã¾ãã^^ï¼