例えば以下のようなエラーがでる。
$ lwp-download "https://github.com/" lwp-download: 500 Can't verify SSL peers without knowning which Certificate Authorities to trust
こんな場合はrootになって、cpanからMozilla::CAをインストールする。
# cpan cpan shell -- CPAN exploration and modules installation (v1.9600) Enter 'h' for help. cpan[1]> install Mozilla::CA CPAN: Storable loaded ok (v2.25) Going to read '/root/.cpan/Metadata' Database was generated on Mon, 14 Mar 2011 14:36:20 GMT CPAN: LWP::UserAgent loaded ok (v6.00) CPAN: Time::HiRes loaded ok (v1.9721) Fetching with LWP: ftp://ftp.jaist.ac.jp/pub/CPAN/authors/01mailrc.txt.gz CPAN: YAML loaded ok (v0.72) Going to read '/root/.cpan/sources/authors/01mailrc.txt.gz' CPAN: Compress::Zlib loaded ok (v2.033) ............................................................................DONE Fetching with LWP: ftp://ftp.jaist.ac.jp/pub/CPAN/modules/02packages.details.txt.gz Going to read '/root/.cpan/sources/modules/02packages.details.txt.gz' Database was generated on Sat, 19 Mar 2011 08:36:52 GMT ............................................................................DONE Fetching with LWP: ftp://ftp.jaist.ac.jp/pub/CPAN/modules/03modlist.data.gz Going to read '/root/.cpan/sources/modules/03modlist.data.gz' ............................................................................DONE Going to write /root/.cpan/Metadata Running install for module 'Mozilla::CA' Running make for A/AB/ABH/Mozilla-CA-20110301.tar.gz Fetching with LWP: ftp://ftp.jaist.ac.jp/pub/CPAN/authors/id/A/AB/ABH/Mozilla-CA-20110301.tar.gz CPAN: Digest::SHA loaded ok (v5.61) Fetching with LWP: ftp://ftp.jaist.ac.jp/pub/CPAN/authors/id/A/AB/ABH/CHECKSUMS Checksum for /root/.cpan/sources/authors/id/A/AB/ABH/Mozilla-CA-20110301.tar.gz ok Scanning cache /root/.cpan/build for sizes ...-------------------------------------------------------------------------DONE CPAN: Archive::Tar loaded ok (v1.76) Mozilla-CA-20110301/ Mozilla-CA-20110301/lib/ Mozilla-CA-20110301/Makefile.PL Mozilla-CA-20110301/MANIFEST Mozilla-CA-20110301/META.yml Mozilla-CA-20110301/README Mozilla-CA-20110301/t/ Mozilla-CA-20110301/update-cacert-file Mozilla-CA-20110301/t/locate-file.t Mozilla-CA-20110301/lib/Mozilla/ Mozilla-CA-20110301/lib/Mozilla/CA/ Mozilla-CA-20110301/lib/Mozilla/CA.pm Mozilla-CA-20110301/lib/Mozilla/CA/cacert.pem CPAN: File::Temp loaded ok (v0.22) CPAN: Parse::CPAN::Meta loaded ok (v1.4401) CPAN: CPAN::Meta loaded ok (v2.110580) CPAN: Module::CoreList loaded ok (v2.45) CPAN.pm: Going to build A/AB/ABH/Mozilla-CA-20110301.tar.gz Checking if your kit is complete... Looks good Writing Makefile for Mozilla::CA Could not read metadata file. Falling back to other methods to determine prerequisites cp lib/Mozilla/CA.pm blib/lib/Mozilla/CA.pm cp lib/Mozilla/CA/cacert.pem blib/lib/Mozilla/CA/cacert.pem Manifying blib/man3/Mozilla::CA.3pm ABH/Mozilla-CA-20110301.tar.gz /usr/bin/make -- OK Running make test PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t t/locate-file.t .. ok All tests successful. Files=1, Tests=3, 1 wallclock secs ( 0.07 usr 0.02 sys + 0.06 cusr 0.01 csys = 0.16 CPU) Result: PASS ABH/Mozilla-CA-20110301.tar.gz /usr/bin/make test -- OK Running make install Prepending /root/.cpan/build/Mozilla-CA-20110301-A0nA1R/blib/arch /root/.cpan/build/Mozilla-CA-20110301-A0nA1R/blib/lib to PERL5LIB for 'install' Installing /usr/local/share/perl/5.10.1/Mozilla/CA.pm Installing /usr/local/share/perl/5.10.1/Mozilla/CA/cacert.pem Installing /usr/local/man/man3/Mozilla::CA.3pm Appending installation info to /usr/lib/perl/5.10/perllocal.pod ABH/Mozilla-CA-20110301.tar.gz /usr/bin/make install -- OK cpan[2]> quit Lockfile removed.
Mozilla::CAをインストールした後はlwpを使って正しくダウンロードできる。
$ lwp-download "https://github.com/" Saving to 'index.htm'... 19.4 KB received
lwp 6.00のChangesを参照すると以下の記述がある。新バージョンのデフォルトで必要なのはIO::Socket::SSLとMozilla::CAモジュール。環境変数PERL_LWP_SSL_VERIFY_HOSTNAMEを0にセットすれば古い挙動(コネクションの検証を行わない)を踏襲するということだ。
For https://... default to verified connections with require IO::Socket::SSL and Mozilla::CA modules to be installed. Old behaviour can be requested by setting the PERL_LWP_SSL_VERIFY_HOSTNAME environment variable to 0. The LWP::UserAgent got new ssl_opts method to control this as well.
https://... のようなコンテンツに関しては、IO::Socket::SSLとMozilla::CAモジュールを使ってコネクションを検証する。 古い挙動を踏襲するには、環境変数PERL_LWP_SSL_VERIFY_HOSTNAMEを0にする。 LWP::UserAgentでは新しいssl_optsメソッドでこれをコントロール出来る。