トップページへ

PerlのLWPで「Can't verify SSL peers without knowing which Certificate Authorities to trust」というエラーになったときの対処

小粋空間 » Programming Language » Perl » PerlのLWPで「Can't verify SSL peers without knowing which Certificate Authorities to trust」というエラーになったときの対処

PerlのLWPで「Can't verify SSL peers without knowing which Certificate Authorities to trust」というエラーになったときの対処について紹介します。

1.問題点

Movable TypeのプラグインでFacebookのOAuth認証部分をPerlで実装し、実行したところ次のようなエラーが発生しました。

Can't verify SSL peers without knowing which Certificate Authorities to trust This problem can be fixed by either setting the PERL_LWP_SSL_CA_FILE envirionment variable or by installing the Mozilla::CA module. To disable verification of SSL peers set the PERL_LWP_SSL_VERIFY_HOSTNAME envirionment variable to 0. If you do this you can't be sure that you communicate with the expected peer.

2.原因と対処

原因はメッセージに書いているとおり、信頼出来るCAを見つけられなくてSSL接続先を検証できなかったためです。

もう少し書くと、LWPで"https"で開始するサイトにアクセスするとこのようなエラーになることがあるようです。

use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $res = $ua->get('https://~/');
if ( $res->is_success ) {
    print $res->content;
}

対処は、エラーメッセージに書かれているMozilla::CAをインストールしました。

$ sudo cpanm Mozilla::CA

PERL_LWP_SSL_VERIFY_HOSTNAMEを無効にしてSSL接続先を検証しない方法もあるようですが、おすすめできません。

3.参考サイト

参考サイトは下記です。ありがとうございました。

« 前の記事へ

次の記事へ »

トップページへ